|
| 1 | +# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | +"""Module containing the Prepare Tools service implementation for v0.""" |
| 23 | + |
| 24 | +import grpc |
| 25 | + |
| 26 | +from ansys.geometry.core.errors import protect_grpc |
| 27 | + |
| 28 | +from ..base.prepare_tools import GRPCPrepareToolsService |
| 29 | + |
| 30 | + |
| 31 | +class GRPCPrepareToolsServiceV0(GRPCPrepareToolsService): |
| 32 | + """Prepare tools service for gRPC communication with the Geometry server. |
| 33 | +
|
| 34 | + This class provides methods to interact with the Geometry server's |
| 35 | + Prepare Tools service. It is specifically designed for the v0 version |
| 36 | + of the Geometry API. |
| 37 | +
|
| 38 | + Parameters |
| 39 | + ---------- |
| 40 | + channel : grpc.Channel |
| 41 | + The gRPC channel to the server. |
| 42 | + """ |
| 43 | + |
| 44 | + @protect_grpc |
| 45 | + def __init__(self, channel: grpc.Channel): # noqa: D102 |
| 46 | + from ansys.api.geometry.v0.preparetools_pb2_grpc import PrepareToolsStub |
| 47 | + |
| 48 | + self.stub = PrepareToolsStub(channel) |
| 49 | + |
| 50 | + @protect_grpc |
| 51 | + def extract_volume_from_faces(self, **kwargs) -> dict: # noqa: D102 |
| 52 | + from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier |
| 53 | + from ansys.api.geometry.v0.preparetools_pb2 import ExtractVolumeFromFacesRequest |
| 54 | + |
| 55 | + # Create the request - assumes all inputs are valid and of the proper type |
| 56 | + request = ExtractVolumeFromFacesRequest( |
| 57 | + sealing_faces=[EntityIdentifier(id=face.id) for face in kwargs["sealing_faces"]], |
| 58 | + inside_faces=[EntityIdentifier(id=face.id) for face in kwargs["inside_faces"]], |
| 59 | + ) |
| 60 | + |
| 61 | + # Call the gRPC service |
| 62 | + response = self.stub.ExtractVolumeFromFaces(request) |
| 63 | + |
| 64 | + # Return the response - formatted as a dictionary |
| 65 | + return { |
| 66 | + "success": response.success, |
| 67 | + "created_bodies": [body.id for body in response.created_bodies], |
| 68 | + } |
| 69 | + |
| 70 | + @protect_grpc |
| 71 | + def extract_volume_from_edge_loops(self, **kwargs) -> dict: # noqa: D102 |
| 72 | + from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier |
| 73 | + from ansys.api.geometry.v0.preparetools_pb2 import ExtractVolumeFromEdgeLoopsRequest |
| 74 | + |
| 75 | + # Create the request - assumes all inputs are valid and of the proper type |
| 76 | + request = ExtractVolumeFromEdgeLoopsRequest( |
| 77 | + sealing_edges=[EntityIdentifier(id=face.id) for face in kwargs["sealing_edges"]], |
| 78 | + inside_faces=[EntityIdentifier(id=face.id) for face in kwargs["inside_faces"]], |
| 79 | + ) |
| 80 | + |
| 81 | + # Call the gRPC service |
| 82 | + response = self.stub.ExtractVolumeFromEdgeLoops(request) |
| 83 | + |
| 84 | + # Return the response - formatted as a dictionary |
| 85 | + return { |
| 86 | + "success": response.success, |
| 87 | + "created_bodies": [body.id for body in response.created_bodies], |
| 88 | + } |
| 89 | + |
| 90 | + @protect_grpc |
| 91 | + def remove_rounds(self, **kwargs) -> dict: # noqa: D102 |
| 92 | + from google.protobuf.wrappers_pb2 import BoolValue |
| 93 | + |
| 94 | + from ansys.api.geometry.v0.models_pb2 import Face |
| 95 | + from ansys.api.geometry.v0.preparetools_pb2 import RemoveRoundsRequest |
| 96 | + |
| 97 | + # Create the request - assumes all inputs are valid and of the proper type |
| 98 | + request = RemoveRoundsRequest( |
| 99 | + selection=[Face(id=round.id) for round in kwargs["rounds"]], |
| 100 | + auto_shrink=BoolValue(value=kwargs["auto_shrink"]), |
| 101 | + ) |
| 102 | + |
| 103 | + # Call the gRPC service |
| 104 | + response = self.stub.RemoveRounds(request) |
| 105 | + |
| 106 | + # Return the response - formatted as a dictionary |
| 107 | + return { |
| 108 | + "success": response.result, |
| 109 | + } |
| 110 | + |
| 111 | + @protect_grpc |
| 112 | + def share_topology(self, **kwargs) -> dict: # noqa: D102 |
| 113 | + from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue |
| 114 | + |
| 115 | + from ansys.api.geometry.v0.models_pb2 import Body |
| 116 | + from ansys.api.geometry.v0.preparetools_pb2 import ShareTopologyRequest |
| 117 | + |
| 118 | + # Create the request - assumes all inputs are valid and of the proper type |
| 119 | + request = ShareTopologyRequest( |
| 120 | + selection=[Body(id=body.id) for body in kwargs["bodies"]], |
| 121 | + tolerance=DoubleValue(value=kwargs["tolerance"]), |
| 122 | + preserve_instances=BoolValue(value=kwargs["preserve_instances"]), |
| 123 | + ) |
| 124 | + |
| 125 | + # Call the gRPC service |
| 126 | + response = self.stub.ShareTopology(request) |
| 127 | + |
| 128 | + # Return the response - formatted as a dictionary |
| 129 | + return { |
| 130 | + "success": response.result, |
| 131 | + } |
| 132 | + |
| 133 | + @protect_grpc |
| 134 | + def enhanced_share_topology(self, **kwargs) -> dict: # noqa: D102 |
| 135 | + from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue |
| 136 | + |
| 137 | + from ansys.api.geometry.v0.models_pb2 import Body |
| 138 | + from ansys.api.geometry.v0.preparetools_pb2 import ShareTopologyRequest |
| 139 | + |
| 140 | + # Create the request - assumes all inputs are valid and of the proper type |
| 141 | + request = ShareTopologyRequest( |
| 142 | + selection=[Body(id=body.id) for body in kwargs["bodies"]], |
| 143 | + tolerance=DoubleValue(value=kwargs["tolerance"]), |
| 144 | + preserve_instances=BoolValue(value=kwargs["preserve_instances"]), |
| 145 | + ) |
| 146 | + |
| 147 | + # Call the gRPC service |
| 148 | + response = self.stub.EnhancedShareTopology(request) |
| 149 | + |
| 150 | + # Return the response - formatted as a dictionary |
| 151 | + return { |
| 152 | + "success": response.success, |
| 153 | + "found": response.found, |
| 154 | + "repaired": response.repaired, |
| 155 | + "created_bodies_monikers": response.created_bodies_monikers, |
| 156 | + "modified_bodies_monikers": response.modified_bodies_monikers, |
| 157 | + "deleted_bodies_monikers": response.deleted_bodies_monikers, |
| 158 | + } |
| 159 | + |
| 160 | + @protect_grpc |
| 161 | + def find_logos(self, **kwargs) -> dict: # noqa: D102 |
| 162 | + from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier |
| 163 | + from ansys.api.geometry.v0.models_pb2 import FindLogoOptions |
| 164 | + from ansys.api.geometry.v0.preparetools_pb2 import FindLogosRequest |
| 165 | + |
| 166 | + # Create the request - assumes all inputs are valid and of the proper type |
| 167 | + request = FindLogosRequest( |
| 168 | + bodies=[EntityIdentifier(id=body.id) for body in kwargs["bodies"]], |
| 169 | + options=FindLogoOptions( |
| 170 | + min_height=kwargs["min_height"], |
| 171 | + max_height=kwargs["max_height"], |
| 172 | + ), |
| 173 | + ) |
| 174 | + |
| 175 | + # Call the gRPC service |
| 176 | + response = self.stub.FindLogos(request) |
| 177 | + |
| 178 | + # Return the response - formatted as a dictionary |
| 179 | + return { |
| 180 | + "id": response.id, |
| 181 | + "face_ids": [face.id for face in response.logo_faces], |
| 182 | + } |
| 183 | + |
| 184 | + @protect_grpc |
| 185 | + def find_and_remove_logos(self, **kwargs) -> dict: # noqa: D102 |
| 186 | + from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier |
| 187 | + from ansys.api.geometry.v0.models_pb2 import FindLogoOptions |
| 188 | + from ansys.api.geometry.v0.preparetools_pb2 import FindLogosRequest |
| 189 | + |
| 190 | + # Create the request - assumes all inputs are valid and of the proper type |
| 191 | + request = FindLogosRequest( |
| 192 | + bodies=[EntityIdentifier(id=body.id) for body in kwargs["bodies"]], |
| 193 | + options=FindLogoOptions( |
| 194 | + min_height=kwargs["min_height"], |
| 195 | + max_height=kwargs["max_height"], |
| 196 | + ), |
| 197 | + ) |
| 198 | + |
| 199 | + # Call the gRPC service |
| 200 | + response = self.stub.FindAndRemoveLogos(request) |
| 201 | + |
| 202 | + # Return the response - formatted as a dictionary |
| 203 | + return {"success": response.success} |
| 204 | + |
| 205 | + @protect_grpc |
| 206 | + def remove_logo(self, **kwargs): # noqa: D102 |
| 207 | + from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier |
| 208 | + from ansys.api.geometry.v0.preparetools_pb2 import RemoveLogoRequest |
| 209 | + |
| 210 | + # Create the request - assumes all inputs are valid and of the proper type |
| 211 | + request = RemoveLogoRequest( |
| 212 | + face_ids=[EntityIdentifier(id=id) for id in kwargs["face_ids"]], |
| 213 | + ) |
| 214 | + |
| 215 | + # Call the gRPC service |
| 216 | + response = self.stub.RemoveLogo(request) |
| 217 | + |
| 218 | + # Return the response - formatted as a dictionary |
| 219 | + return {"success": response.success} |
0 commit comments