-
Notifications
You must be signed in to change notification settings - Fork 22
feat: grpc rearchitecutre - components model #2263
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
7 commits
Select commit
Hold shift + click to select a range
34aec8e
components stub implemented and passing all tests
jacobrkerstetter e4be521
fix beams grpc calls in core code
jacobrkerstetter 7d2644f
chore: auto fixes from pre-commit hooks
pre-commit-ci[bot] 434358d
chore: adding changelog file 2263.added.md [dependabot-skip]
pyansys-ci-bot 15fd4ec
Merge branch 'main' into feat/components_stub_refactoring
jacobrkerstetter 83a7469
skipping image cache test
jacobrkerstetter 5dffcd3
Merge branch 'main' into feat/components_stub_refactoring
RobPasMue 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 rearchitecutre - components model |
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
74 changes: 74 additions & 0 deletions
74
src/ansys/geometry/core/_grpc/_services/base/components.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,74 @@ | ||
| # 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 components service implementation (abstraction layer).""" | ||
|
|
||
| from abc import ABC, abstractmethod | ||
|
|
||
| import grpc | ||
|
|
||
|
|
||
| class GRPCComponentsService(ABC): # pragma: no cover | ||
| """Components 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 GRPCComponentsService class.""" | ||
|
|
||
| @abstractmethod | ||
| def create(self, **kwargs) -> dict: | ||
| """Create a component.""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def set_name(self, **kwargs) -> dict: | ||
| """Set the name of a component.""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def set_placement(self, **kwargs) -> dict: | ||
| """Set the placement of a component.""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def set_shared_topology(self, **kwargs) -> dict: | ||
| """Set the shared topology of a component.""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def delete(self, **kwargs) -> dict: | ||
| """Delete a component.""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def import_groups(self, **kwargs) -> dict: | ||
| """Import groups from a component.""" | ||
| pass | ||
|
|
||
| @abstractmethod | ||
| def make_independent(self, **kwargs) -> dict: | ||
| """Make a component independent.""" | ||
| pass |
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
183 changes: 183 additions & 0 deletions
183
src/ansys/geometry/core/_grpc/_services/v0/components.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,183 @@ | ||
| # 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 components service implementation for v0.""" | ||
|
|
||
| import grpc | ||
|
|
||
| from ansys.geometry.core.errors import protect_grpc | ||
|
|
||
| from ..base.components import GRPCComponentsService | ||
| from ..base.conversions import from_measurement_to_server_angle | ||
| from .conversions import ( | ||
| build_grpc_id, | ||
| from_grpc_matrix_to_matrix, | ||
| from_point3d_to_grpc_point, | ||
| from_unit_vector_to_grpc_direction, | ||
| ) | ||
|
|
||
|
|
||
| class GRPCComponentsServiceV0(GRPCComponentsService): | ||
| """Components service for gRPC communication with the Geometry server. | ||
|
|
||
| This class provides methods to call components in the | ||
| Geometry server using gRPC. 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.components_pb2_grpc import ComponentsStub | ||
|
|
||
| self.stub = ComponentsStub(channel) | ||
|
|
||
| @protect_grpc | ||
| def create(self, **kwargs) -> dict: # noqa: D102 | ||
| from ansys.api.geometry.v0.components_pb2 import CreateRequest | ||
|
|
||
| # Create the request - assumes all inputs are valid and of the proper type | ||
| request = CreateRequest( | ||
| name=kwargs["name"], | ||
| parent=kwargs["parent_id"], | ||
| template=kwargs["template_id"], | ||
| instance_name=kwargs["instance_name"], | ||
| ) | ||
|
|
||
| # Call the gRPC service | ||
| response = self.stub.Create(request) | ||
|
|
||
| # Return the response - formatted as a dictionary | ||
| return { | ||
| "id": response.component.id, | ||
| "name": response.component.name, | ||
| "instance_name": response.component.instance_name, | ||
| } | ||
|
|
||
| @protect_grpc | ||
| def set_name(self, **kwargs) -> dict: # noqa: D102 | ||
| from ansys.api.geometry.v0.models_pb2 import SetObjectNameRequest | ||
|
|
||
| # Create the request - assumes all inputs are valid and of the proper type | ||
| request = SetObjectNameRequest(id=build_grpc_id(kwargs["id"]), name=kwargs["name"]) | ||
|
|
||
| # Call the gRPC service | ||
| _ = self.stub.SetName(request) | ||
|
|
||
| # Return the response - formatted as a dictionary | ||
| return {} | ||
|
|
||
| @protect_grpc | ||
| def set_placement(self, **kwargs) -> dict: # noqa: D102 | ||
| from ansys.api.geometry.v0.components_pb2 import SetPlacementRequest | ||
|
|
||
| # Create the direction and point objects | ||
| translation = ( | ||
| from_unit_vector_to_grpc_direction(kwargs["translation"].normalize()) | ||
| if kwargs["translation"] is not None | ||
| else None | ||
| ) | ||
| origin = ( | ||
| from_point3d_to_grpc_point(kwargs["rotation_axis_origin"]) | ||
| if kwargs["rotation_axis_origin"] is not None | ||
| else None | ||
| ) | ||
| direction = ( | ||
| from_unit_vector_to_grpc_direction(kwargs["rotation_axis_direction"]) | ||
| if kwargs["rotation_axis_direction"] is not None | ||
| else None | ||
| ) | ||
|
|
||
| # Create the request - assumes all inputs are valid and of the proper type | ||
| request = SetPlacementRequest( | ||
| id=kwargs["id"], | ||
| translation=translation, | ||
| rotation_axis_origin=origin, | ||
| rotation_axis_direction=direction, | ||
| rotation_angle=from_measurement_to_server_angle(kwargs["rotation_angle"]), | ||
| ) | ||
|
|
||
| # Call the gRPC service | ||
| response = self.stub.SetPlacement(request) | ||
|
|
||
| # Return the response - formatted as a dictionary | ||
| return {"matrix": from_grpc_matrix_to_matrix(response.matrix)} | ||
|
|
||
| @protect_grpc | ||
| def set_shared_topology(self, **kwargs) -> dict: # noqa: D102 | ||
| from ansys.api.geometry.v0.components_pb2 import SetSharedTopologyRequest | ||
|
|
||
| # Create the request - assumes all inputs are valid and of the proper type | ||
| request = SetSharedTopologyRequest( | ||
| id=kwargs["id"], | ||
| share_type=kwargs["share_type"].value, | ||
| ) | ||
|
|
||
| # Call the gRPC service | ||
| _ = self.stub.SetSharedTopology(request) | ||
|
|
||
| # Return the response - formatted as a dictionary | ||
| return {} | ||
|
|
||
| @protect_grpc | ||
| def delete(self, **kwargs) -> dict: # noqa: D102 | ||
| # Create the request - assumes all inputs are valid and of the proper type | ||
| request = build_grpc_id(kwargs["id"]) | ||
|
|
||
| # Call the gRPC service | ||
| _ = self.stub.Delete(request) | ||
|
|
||
| # Return the response - formatted as a dictionary | ||
| return {} | ||
|
|
||
| @protect_grpc | ||
| def import_groups(self, **kwargs) -> dict: # noqa: D102 | ||
| from ansys.api.geometry.v0.components_pb2 import ImportGroupsRequest | ||
|
|
||
| # Create the request - assumes all inputs are valid and of the proper type | ||
| request = ImportGroupsRequest( | ||
| id=build_grpc_id(kwargs["id"]), | ||
| ) | ||
|
|
||
| # Call the gRPC service | ||
| _ = self.stub.ImportGroups(request) | ||
|
|
||
| # Return the response - formatted as a dictionary | ||
| return {} | ||
|
|
||
| @protect_grpc | ||
| def make_independent(self, **kwargs) -> dict: # noqa: D102 | ||
| from ansys.api.geometry.v0.components_pb2 import MakeIndependentRequest | ||
|
|
||
| # Create the request - assumes all inputs are valid and of the proper type | ||
| request = MakeIndependentRequest( | ||
| ids=[build_grpc_id(id) for id in kwargs["ids"]], | ||
| ) | ||
|
|
||
| # Call the gRPC service | ||
| _ = self.stub.MakeIndependent(request) | ||
|
|
||
| # Return the response - formatted as a dictionary | ||
| return {} |
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.