-
Notifications
You must be signed in to change notification settings - Fork 17
feat: grpc named selection stub implementation #1899
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 all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
201c960
move named selection stub to common location
b47617f
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] a2dfcf4
Merge branch 'main' into feat/named_selection_stub_relocation
jacobrkerstetter 8681ee4
chore: adding changelog file 1899.added.md [dependabot-skip]
pyansys-ci-bot 8b69dc8
chore: adding changelog file 1899.added.md [dependabot-skip]
pyansys-ci-bot 7c28c2f
- removed unused grpc methods
61639bd
altered stub to return only id's of members
a94198e
Merge branch 'feat/named_selection_stub_relocation' of https://github…
00f2a27
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] 4acf063
fixed DP creation
6ff46bf
Merge branch 'feat/named_selection_stub_relocation' of https://github…
b44e9f8
resolving comments
df6bdb1
removing unnecessary protect_grpc decorators
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 named selection 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
55 changes: 55 additions & 0 deletions
55
src/ansys/geometry/core/_grpc/_services/base/named_selection.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,55 @@ | ||
# 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 Named Selection service implementation (abstraction layer).""" | ||
|
||
from abc import ABC, abstractmethod | ||
|
||
import grpc | ||
|
||
|
||
class GRPCNamedSelectionService(ABC): | ||
"""Named Selection 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 GRPCNamedSelectionService class.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def get_named_selection(self, **kwargs) -> dict: | ||
"""Get the named selection by its id.""" | ||
pass # pragma: no cover | ||
|
||
@abstractmethod | ||
def create_named_selection(self, **kwargs) -> dict: | ||
"""Create a named selection.""" | ||
pass | ||
|
||
@abstractmethod | ||
def delete_named_selection(self, **kwargs) -> dict: | ||
"""Delete a named selection by id.""" | ||
pass |
106 changes: 106 additions & 0 deletions
106
src/ansys/geometry/core/_grpc/_services/v0/named_selection.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,106 @@ | ||
# 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 Named Selection service implementation for v0.""" | ||
|
||
import grpc | ||
|
||
from ansys.geometry.core.errors import protect_grpc | ||
|
||
from ..base.named_selection import GRPCNamedSelectionService | ||
|
||
|
||
class GRPCNamedSelectionServiceV0(GRPCNamedSelectionService): | ||
"""Named Selection service for gRPC communication with the Geometry server. | ||
|
||
This class provides methods to interact with the Geometry server's | ||
Named Selection 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.namedselections_pb2_grpc import NamedSelectionsStub | ||
|
||
self.stub = NamedSelectionsStub(channel) | ||
|
||
@protect_grpc | ||
def get_named_selection(self, **kwargs): # noqa: D102 | ||
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = EntityIdentifier(id=kwargs["id"]) | ||
|
||
# Call the gRPC service | ||
response = self.stub.Get(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"id": response.id, | ||
"name": response.name, | ||
"bodies": [body.id for body in response.bodies], | ||
"faces": [face.id for face in response.faces], | ||
"edges": [edge.id for edge in response.edges], | ||
"beams": [beam.id.id for beam in response.beams], | ||
"design_points": [(dp.id, dp.points[0]) for dp in response.design_points], | ||
} | ||
|
||
@protect_grpc | ||
def create_named_selection(self, **kwargs): # noqa: D102 | ||
from ansys.api.geometry.v0.namedselections_pb2 import CreateRequest | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = CreateRequest( | ||
name=kwargs["name"], | ||
members=kwargs["members"], | ||
) | ||
|
||
# Call the gRPC service | ||
response = self.stub.Create(request) | ||
|
||
# Return the response - formatted as a dictionary | ||
return { | ||
"id": response.id, | ||
"name": response.name, | ||
"bodies": [body.id for body in response.bodies], | ||
"faces": [face.id for face in response.faces], | ||
"edges": [edge.id for edge in response.edges], | ||
"beams": [beam.id.id for beam in response.beams], | ||
"design_points": [dp.id for dp in response.design_points], | ||
} | ||
|
||
@protect_grpc | ||
def delete_named_selection(self, **kwargs): # noqa: D102 | ||
from ansys.api.dbu.v0.dbumodels_pb2 import EntityIdentifier | ||
|
||
# Create the request - assumes all inputs are valid and of the proper type | ||
request = EntityIdentifier(id=kwargs["id"]) | ||
|
||
# Call the gRPC service | ||
self.stub.Delete(request) | ||
|
||
# Return the response - empty dictionary | ||
return {} |
60 changes: 60 additions & 0 deletions
60
src/ansys/geometry/core/_grpc/_services/v1/named_selection.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,60 @@ | ||
# 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 Named Selection service implementation for v1.""" | ||
|
||
import grpc | ||
|
||
from ansys.geometry.core.errors import protect_grpc | ||
|
||
from ..base.named_selection import GRPCNamedSelectionService | ||
|
||
|
||
class GRPCNamedSelectionServiceV1(GRPCNamedSelectionService): | ||
"""Named Selection service for gRPC communication with the Geometry server. | ||
|
||
This class provides methods to interact with the Geometry server's | ||
Named Selection service. It is specifically designed for the v1 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.v1.namedselections_pb2_grpc import NamedSelectionsStub | ||
|
||
self.stub = NamedSelectionsStub(channel) | ||
|
||
@protect_grpc | ||
def get_named_selection(self, **kwargs): # noqa: D102 | ||
raise NotImplementedError | ||
|
||
@protect_grpc | ||
def create_named_selection(self, **kwargs): # noqa: D102 | ||
raise NotImplementedError | ||
|
||
@protect_grpc | ||
def delete_named_selection(self, **kwargs): # noqa: D102 | ||
raise NotImplementedError |
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
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
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.