|
23 | 23 |
|
24 | 24 | from typing import TYPE_CHECKING
|
25 | 25 |
|
| 26 | +from beartype import beartype as check_input_types |
26 | 27 | from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue
|
27 | 28 |
|
28 | 29 | from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier
|
29 |
| -from ansys.api.geometry.v0.models_pb2 import Body as GRPCBody, Face as GRPCFace |
| 30 | +from ansys.api.geometry.v0.models_pb2 import Body as GRPCBody, Face as GRPCFace, FindLogoOptions |
30 | 31 | from ansys.api.geometry.v0.preparetools_pb2 import (
|
31 | 32 | ExtractVolumeFromEdgeLoopsRequest,
|
32 | 33 | ExtractVolumeFromFacesRequest,
|
| 34 | + FindLogosRequest, |
33 | 35 | RemoveRoundsRequest,
|
34 | 36 | ShareTopologyRequest,
|
35 | 37 | )
|
36 | 38 | from ansys.api.geometry.v0.preparetools_pb2_grpc import PrepareToolsStub
|
37 | 39 | from ansys.geometry.core.connection import GrpcClient
|
| 40 | +from ansys.geometry.core.connection.backend import BackendType |
38 | 41 | from ansys.geometry.core.errors import protect_grpc
|
| 42 | +from ansys.geometry.core.logger import LOG |
39 | 43 | from ansys.geometry.core.misc.auxiliary import (
|
40 | 44 | get_bodies_from_ids,
|
41 | 45 | get_design_from_edge,
|
42 | 46 | get_design_from_face,
|
43 | 47 | )
|
44 | 48 | from ansys.geometry.core.misc.checks import check_type_all_elements_in_iterable, min_backend_version
|
| 49 | +from ansys.geometry.core.tools.problem_areas import LogoProblemArea |
45 | 50 | from ansys.geometry.core.tools.repair_tool_message import RepairToolMessage
|
46 | 51 | from ansys.geometry.core.typing import Real
|
47 | 52 |
|
@@ -295,3 +300,101 @@ def enhanced_share_topology(
|
295 | 300 | share_topo_response.repaired,
|
296 | 301 | )
|
297 | 302 | return message
|
| 303 | + |
| 304 | + @check_input_types |
| 305 | + @protect_grpc |
| 306 | + @min_backend_version(25, 2, 0) |
| 307 | + def find_logos( |
| 308 | + self, bodies: list["Body"] = None, min_height: Real = None, max_height: Real = None |
| 309 | + ) -> "LogoProblemArea": |
| 310 | + """Detect logos in geometry. |
| 311 | +
|
| 312 | + Detects logos, using a list of bodies if provided. |
| 313 | + The logos are returned as a list of faces. |
| 314 | +
|
| 315 | + Parameters |
| 316 | + ---------- |
| 317 | + bodies : list[Body], optional |
| 318 | + List of bodies where logos should be detected |
| 319 | + min_height : real, optional |
| 320 | + The minimum height when searching for logos |
| 321 | + max_height: real, optional |
| 322 | + The minimum height when searching for logos |
| 323 | +
|
| 324 | + Returns |
| 325 | + ------- |
| 326 | + LogoProblemArea |
| 327 | + Problem area with logo faces. |
| 328 | + """ |
| 329 | + from ansys.geometry.core.designer.body import Body |
| 330 | + |
| 331 | + if BackendType.is_linux_service(self._grpc_client.backend_type): |
| 332 | + # not yet available in Linux |
| 333 | + LOG.warning("Logo detection not available on Linux") |
| 334 | + return |
| 335 | + |
| 336 | + # Verify inputs |
| 337 | + if bodies and len(bodies) > 0: |
| 338 | + check_type_all_elements_in_iterable(bodies, Body) |
| 339 | + |
| 340 | + body_ids = [] if bodies is None else [body._grpc_id for body in bodies] |
| 341 | + find_logo_options = FindLogoOptions( |
| 342 | + min_height=min_height, |
| 343 | + max_height=max_height, |
| 344 | + ) |
| 345 | + |
| 346 | + response = self._prepare_stub.FindLogos( |
| 347 | + FindLogosRequest(bodies=body_ids, options=find_logo_options) |
| 348 | + ) |
| 349 | + |
| 350 | + return LogoProblemArea( |
| 351 | + id=response.id, |
| 352 | + grpc_client=self._grpc_client, |
| 353 | + face_ids=[grpc_face.id for grpc_face in response.logo_faces], |
| 354 | + ) |
| 355 | + |
| 356 | + @check_input_types |
| 357 | + @protect_grpc |
| 358 | + @min_backend_version(25, 2, 0) |
| 359 | + def find_and_remove_logos( |
| 360 | + self, bodies: list["Body"] = None, min_height: Real = None, max_height: Real = None |
| 361 | + ) -> bool: |
| 362 | + """Detect and remove logos in geometry. |
| 363 | +
|
| 364 | + Detects and remove logos, using a list of bodies if provided. |
| 365 | +
|
| 366 | + Parameters |
| 367 | + ---------- |
| 368 | + bodies : list[Body], optional |
| 369 | + List of bodies where logos should be detected and removed. |
| 370 | + min_height : real, optional |
| 371 | + The minimum height when searching for logos |
| 372 | + max_height: real, optional |
| 373 | + The minimum height when searching for logos |
| 374 | +
|
| 375 | + Returns |
| 376 | + ------- |
| 377 | + Boolean value indicating whether the operation was successful. |
| 378 | + """ |
| 379 | + from ansys.geometry.core.designer.body import Body |
| 380 | + |
| 381 | + if BackendType.is_linux_service(self._grpc_client.backend_type): |
| 382 | + # not yet available in Linux |
| 383 | + LOG.warning("Logo detection not available on Linux") |
| 384 | + return |
| 385 | + |
| 386 | + # Verify inputs |
| 387 | + if bodies and len(bodies) > 0: |
| 388 | + check_type_all_elements_in_iterable(bodies, Body) |
| 389 | + |
| 390 | + body_ids = [] if bodies is None else [body._grpc_id for body in bodies] |
| 391 | + find_logo_options = FindLogoOptions( |
| 392 | + min_height=min_height, |
| 393 | + max_height=max_height, |
| 394 | + ) |
| 395 | + |
| 396 | + response = self._prepare_stub.FindAndRemoveLogos( |
| 397 | + FindLogosRequest(bodies=body_ids, options=find_logo_options) |
| 398 | + ) |
| 399 | + |
| 400 | + return response.success |
0 commit comments