Skip to content

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 26 commits into from
Apr 16, 2025
Merged
Show file tree
Hide file tree
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
Apr 14, 2025
faeebf7
chore: adding changelog file 1909.added.md [dependabot-skip]
pyansys-ci-bot Apr 14, 2025
edca0a3
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Apr 14, 2025
4b6e33f
resolving comments
Apr 14, 2025
de2f595
Merge branch 'feat/measurement_tools_relocation' of https://github.co…
Apr 14, 2025
4c2a2cd
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Apr 14, 2025
32b4137
removing measurement tools stub from modeler, can be accessed through…
Apr 14, 2025
71a5a4f
Merge branch 'feat/measurement_tools_relocation' of https://github.co…
Apr 14, 2025
fb526ec
reverting unnecessary changes
Apr 14, 2025
e8a0019
wip
Apr 14, 2025
6feed75
Merge branch 'feat/measurement_tools_relocation' of https://github.co…
Apr 14, 2025
74eb796
finished implementing prepare tools v0
Apr 15, 2025
2239d8c
Merge branch 'main' into feat/prepare_tools_migration
jacobrkerstetter Apr 15, 2025
d43a223
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Apr 15, 2025
1d5052a
chore: adding changelog file 1914.added.md [dependabot-skip]
pyansys-ci-bot Apr 15, 2025
47579a1
add BoolValue and DoubleValue as needed by server
Apr 16, 2025
e6a9cc9
Merge branch 'main' into feat/prepare_tools_migration
jacobrkerstetter Apr 16, 2025
6891c52
Merge branch 'feat/prepare_tools_migration' of https://github.com/ans…
Apr 16, 2025
b2a71e1
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Apr 16, 2025
d18f00b
Merge branch 'main' into feat/prepare_tools_migration
RobPasMue Apr 16, 2025
45ef136
adding remove_logo impl
Apr 16, 2025
e4dc5c8
Merge branch 'feat/prepare_tools_migration' of https://github.com/ans…
Apr 16, 2025
a57bcd8
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] Apr 16, 2025
4976646
Apply suggestions from code review
RobPasMue Apr 16, 2025
3a008a5
fixing str used as id
Apr 16, 2025
5a45b99
Merge branch 'feat/prepare_tools_migration' of https://github.com/ans…
Apr 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/1914.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
grpc prepare tools stub implementation
28 changes: 28 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from .base.dbuapplication import GRPCDbuApplicationService
from .base.measurement_tools import GRPCMeasurementToolsService
from .base.named_selection import GRPCNamedSelectionService
from .base.prepare_tools import GRPCPrepareToolsService


class _GRPCServices:
Expand Down Expand Up @@ -73,6 +74,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
self._dbu_application = None
self._named_selection = None
self._measurement_tools = None
self._prepare_tools = None

@property
def bodies(self) -> GRPCBodyService:
Expand Down Expand Up @@ -203,3 +205,29 @@ def measurement_tools(self) -> GRPCMeasurementToolsService:
raise ValueError(f"Unsupported version: {self.version}")

return self._measurement_tools

@property
def prepare_tools(self) -> GRPCPrepareToolsService:
"""
Get the prepare tools service for the specified version.

Returns
-------
NamedSelectionServiceBase
The prepare tools service for the specified version.
"""
if not self._prepare_tools:
# Import the appropriate prepare tools service based on the version
from .v0.prepare_tools import GRPCPrepareToolsServiceV0
from .v1.prepare_tools import GRPCPrepareToolsServiceV1

if self.version == GeometryApiProtos.V0:
self._prepare_tools = GRPCPrepareToolsServiceV0(self.channel)
elif self.version == GeometryApiProtos.V1: # pragma: no cover
# V1 is not implemented yet
self._prepare_tools = GRPCPrepareToolsServiceV1(self.channel)
else: # pragma: no cover
# This should never happen as the version is set in the constructor
raise ValueError(f"Unsupported version: {self.version}")

return self._prepare_tools
80 changes: 80 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/base/prepare_tools.py
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 src/ansys/geometry/core/_grpc/_services/v0/prepare_tools.py
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,
}
Loading
Loading