-
Notifications
You must be signed in to change notification settings - Fork 17
feat: grpc prepare tools stub implementation #1914
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 23 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
ca1deb6
implemented versioning for measurement tools stub
faeebf7
chore: adding changelog file 1909.added.md [dependabot-skip]
pyansys-ci-bot edca0a3
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] 4b6e33f
resolving comments
de2f595
Merge branch 'feat/measurement_tools_relocation' of https://github.co…
4c2a2cd
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] 32b4137
removing measurement tools stub from modeler, can be accessed through…
71a5a4f
Merge branch 'feat/measurement_tools_relocation' of https://github.co…
fb526ec
reverting unnecessary changes
e8a0019
wip
6feed75
Merge branch 'feat/measurement_tools_relocation' of https://github.co…
74eb796
finished implementing prepare tools v0
2239d8c
Merge branch 'main' into feat/prepare_tools_migration
jacobrkerstetter d43a223
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] 1d5052a
chore: adding changelog file 1914.added.md [dependabot-skip]
pyansys-ci-bot 47579a1
add BoolValue and DoubleValue as needed by server
e6a9cc9
Merge branch 'main' into feat/prepare_tools_migration
jacobrkerstetter 6891c52
Merge branch 'feat/prepare_tools_migration' of https://github.com/ans…
b2a71e1
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] d18f00b
Merge branch 'main' into feat/prepare_tools_migration
RobPasMue 45ef136
adding remove_logo impl
e4dc5c8
Merge branch 'feat/prepare_tools_migration' of https://github.com/ans…
a57bcd8
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] 4976646
Apply suggestions from code review
RobPasMue 3a008a5
fixing str used as id
5a45b99
Merge branch 'feat/prepare_tools_migration' of https://github.com/ans…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
grpc prepare tools stub implementation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
src/ansys/geometry/core/_grpc/_services/base/prepare_tools.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
"""Module containing the prepare tools service implementation (abstraction layer).""" | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
import grpc | ||
|
||
|
||
class GRPCPrepareToolsService(ABC): | ||
"""Prepare tools service for gRPC communication with the Geometry server. | ||
|
||
Parameters | ||
---------- | ||
channel : grpc.Channel | ||
The gRPC channel to the server. | ||
""" | ||
|
||
def __init__(self, channel: grpc.Channel): | ||
"""Initialize the PrepareToolsService class.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def extract_volume_from_faces(self, **kwargs) -> dict: | ||
"""Extract a volume from input faces.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def extract_volume_from_edge_loops(self, **kwargs) -> dict: | ||
"""Extract a volume from input edge loop.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def remove_rounds(self, **kwargs) -> dict: | ||
"""Remove rounds from geometry.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def share_topology(self, **kwargs) -> dict: | ||
"""Share topology between the given bodies.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def enhanced_share_topology(self, **kwargs) -> dict: | ||
"""Share topology between the given bodies.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def find_logos(self, **kwargs) -> dict: | ||
"""Detect logos in geometry.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def find_and_remove_logos(self, **kwargs) -> dict: | ||
"""Detect and remove logos in geometry.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def remove_logo(self, **kwargs) -> dict: | ||
"""Remove logos in geometry.""" | ||
pass # pragma: no cover |
221 changes: 221 additions & 0 deletions
221
src/ansys/geometry/core/_grpc/_services/v0/prepare_tools.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. | ||
# SPDX-License-Identifier: MIT | ||
# | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in all | ||
# copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
# SOFTWARE. | ||
"""Module containing the Prepare Tools service implementation for v0.""" | ||
|
||
import grpc | ||
|
||
from ansys.geometry.core.errors import protect_grpc | ||
|
||
from ..base.prepare_tools import GRPCPrepareToolsService | ||
|
||
|
||
class GRPCPrepareToolsServiceV0(GRPCPrepareToolsService): | ||
"""Prepare tools service for gRPC communication with the Geometry server. | ||
|
||
This class provides methods to interact with the Geometry server's | ||
Prepare Tools service. It is specifically designed for the v0 version | ||
of the Geometry API. | ||
|
||
Parameters | ||
---------- | ||
channel : grpc.Channel | ||
The gRPC channel to the server. | ||
""" | ||
|
||
@protect_grpc | ||
def __init__(self, channel: grpc.Channel): # noqa: D102 | ||
from ansys.api.geometry.v0.preparetools_pb2_grpc import PrepareToolsStub | ||
|
||
self.stub = PrepareToolsStub(channel) | ||
|
||
@protect_grpc | ||
def extract_volume_from_faces(self, **kwargs) -> dict: # noqa: D102 | ||
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier | ||
from ansys.api.geometry.v0.preparetools_pb2 import ExtractVolumeFromFacesRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = ExtractVolumeFromFacesRequest( | ||
sealing_faces=[EntityIdentifier(id=face.id) for face in kwargs["sealing_faces"]], | ||
inside_faces=[EntityIdentifier(id=face.id) for face in kwargs["inside_faces"]], | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.ExtractVolumeFromFaces(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"success": response.success, | ||
"created_bodies": [body.id for body in response.created_bodies], | ||
} | ||
|
||
@protect_grpc | ||
def extract_volume_from_edge_loops(self, **kwargs) -> dict: # noqa: D102 | ||
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier | ||
from ansys.api.geometry.v0.preparetools_pb2 import ExtractVolumeFromEdgeLoopsRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = ExtractVolumeFromEdgeLoopsRequest( | ||
sealing_edges=[EntityIdentifier(id=face.id) for face in kwargs["sealing_edges"]], | ||
inside_faces=[EntityIdentifier(id=face.id) for face in kwargs["inside_faces"]], | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.ExtractVolumeFromEdgeLoops(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"success": response.success, | ||
"created_bodies": [body.id for body in response.created_bodies], | ||
} | ||
|
||
@protect_grpc | ||
def remove_rounds(self, **kwargs) -> dict: # noqa: D102 | ||
from google.protobuf.wrappers_pb2 import BoolValue | ||
|
||
from ansys.api.geometry.v0.models_pb2 import Face | ||
from ansys.api.geometry.v0.preparetools_pb2 import RemoveRoundsRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = RemoveRoundsRequest( | ||
selection=[Face(id=round.id) for round in kwargs["rounds"]], | ||
auto_shrink=BoolValue(value=kwargs["auto_shrink"]), | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.RemoveRounds(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"success": response.result, | ||
} | ||
|
||
@protect_grpc | ||
def share_topology(self, **kwargs) -> dict: # noqa: D102 | ||
from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue | ||
|
||
from ansys.api.geometry.v0.models_pb2 import Body | ||
from ansys.api.geometry.v0.preparetools_pb2 import ShareTopologyRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = ShareTopologyRequest( | ||
selection=[Body(id=body.id) for body in kwargs["bodies"]], | ||
tolerance=DoubleValue(value=kwargs["tolerance"]), | ||
preserve_instances=BoolValue(value=kwargs["preserve_instances"]), | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.ShareTopology(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"success": response.result, | ||
} | ||
|
||
@protect_grpc | ||
def enhanced_share_topology(self, **kwargs) -> dict: # noqa: D102 | ||
from google.protobuf.wrappers_pb2 import BoolValue, DoubleValue | ||
|
||
from ansys.api.geometry.v0.models_pb2 import Body | ||
from ansys.api.geometry.v0.preparetools_pb2 import ShareTopologyRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = ShareTopologyRequest( | ||
selection=[Body(id=body.id) for body in kwargs["bodies"]], | ||
tolerance=DoubleValue(value=kwargs["tolerance"]), | ||
preserve_instances=BoolValue(value=kwargs["preserve_instances"]), | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.EnhancedShareTopology(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"success": response.success, | ||
"found": response.found, | ||
"repaired": response.repaired, | ||
"created_bodies_monikers": response.created_bodies_monikers, | ||
"modified_bodies_monikers": response.modified_bodies_monikers, | ||
"deleted_bodies_monikers": response.deleted_bodies_monikers, | ||
} | ||
|
||
@protect_grpc | ||
def find_logos(self, **kwargs) -> dict: # noqa: D102 | ||
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier | ||
from ansys.api.geometry.v0.models_pb2 import FindLogoOptions | ||
from ansys.api.geometry.v0.preparetools_pb2 import FindLogosRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = FindLogosRequest( | ||
bodies=[EntityIdentifier(id=body.id) for body in kwargs["bodies"]], | ||
options=FindLogoOptions( | ||
min_height=kwargs["min_height"], | ||
max_height=kwargs["max_height"], | ||
), | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.FindLogos(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"id": response.id, | ||
"face_ids": [face.id for face in response.logo_faces], | ||
} | ||
|
||
@protect_grpc | ||
def find_and_remove_logos(self, **kwargs) -> dict: # noqa: D102 | ||
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier | ||
from ansys.api.geometry.v0.models_pb2 import FindLogoOptions | ||
from ansys.api.geometry.v0.preparetools_pb2 import FindLogosRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = FindLogosRequest( | ||
bodies=[EntityIdentifier(id=body.id) for body in kwargs["bodies"]], | ||
options=FindLogoOptions( | ||
min_height=kwargs["min_height"], | ||
max_height=kwargs["max_height"], | ||
), | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.FindAndRemoveLogos(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return {"success": response.success} | ||
|
||
@protect_grpc | ||
def remove_logo(self, **kwargs): # noqa: D102 | ||
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier | ||
from ansys.api.geometry.v0.preparetools_pb2 import RemoveLogoRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = RemoveLogoRequest( | ||
face_ids=[EntityIdentifier(id=face.id) for face in kwargs["face_ids"]], | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.RemoveLogo(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"success": response.success, | ||
} | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.