Skip to content

Commit ee41af8

Browse files
- rename from assembly_controls to assembly_condition to match protos
- fully implement v1 assembly condition and test
1 parent e5396d9 commit ee41af8

File tree

7 files changed

+190
-93
lines changed

7 files changed

+190
-93
lines changed

src/ansys/geometry/core/_grpc/_services/_service.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from .._version import GeometryApiProtos, set_proto_version
2626
from .base.admin import GRPCAdminService
27-
from .base.assembly_controls import GRPCAssemblyControlsService
27+
from .base.assembly_condition import GRPCAssemblyConditionService
2828
from .base.beams import GRPCBeamsService
2929
from .base.bodies import GRPCBodyService
3030
from .base.commands import GRPCCommandsService
@@ -87,7 +87,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
8787

8888
# Lazy load all the services
8989
self._admin = None
90-
self._assembly_controls = None
90+
self._assembly_condition = None
9191
self._beams = None
9292
self._bodies = None
9393
self._commands = None
@@ -137,30 +137,29 @@ def admin(self) -> GRPCAdminService:
137137
return self._admin
138138

139139
@property
140-
def assembly_controls(self) -> GRPCAssemblyControlsService:
140+
def assembly_condition(self) -> GRPCAssemblyConditionService:
141141
"""
142-
Get the assembly controls service for the specified version.
142+
Get the assembly condition service for the specified version.
143143
144144
Returns
145145
-------
146-
GRPCAssemblyControlsService
147-
The assembly controls service for the specified version.
146+
GRPCAssemblyConditionService
147+
The assembly condition service for the specified version.
148148
"""
149-
if not self._assembly_controls:
150-
# Import the appropriate assembly controls service based on the version
151-
from .v0.assembly_controls import GRPCAssemblyControlsServiceV0
152-
from .v1.assembly_controls import GRPCAssemblyControlsServiceV1
153-
149+
if not self._assembly_condition:
150+
# Import the appropriate assembly condition service based on the version
151+
from .v0.assembly_condition import GRPCAssemblyConditionServiceV0
152+
from .v1.assembly_condition import GRPCAssemblyConditionServiceV1
154153
if self.version == GeometryApiProtos.V0:
155-
self._assembly_controls = GRPCAssemblyControlsServiceV0(self.channel)
154+
self._assembly_condition = GRPCAssemblyConditionServiceV0(self.channel)
156155
elif self.version == GeometryApiProtos.V1: # pragma: no cover
157156
# V1 is not implemented yet
158-
self._assembly_controls = GRPCAssemblyControlsServiceV1(self.channel)
157+
self._assembly_condition = GRPCAssemblyConditionServiceV1(self.channel)
159158
else: # pragma: no cover
160159
# This should never happen as the version is set in the constructor
161160
raise ValueError(f"Unsupported version: {self.version}")
162161

163-
return self._assembly_controls
162+
return self._assembly_condition
164163

165164
@property
166165
def beams(self) -> GRPCBeamsService:

src/ansys/geometry/core/_grpc/_services/base/assembly_controls.py renamed to src/ansys/geometry/core/_grpc/_services/base/assembly_condition.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22-
"""Module containing the assembly controls service implementation (abstraction layer)."""
22+
"""Module containing the assembly condition service implementation (abstraction layer)."""
2323

2424
from abc import ABC, abstractmethod
2525

2626
import grpc
2727

2828

29-
class GRPCAssemblyControlsService(ABC): # pragma: no cover
30-
"""Assembly controls service for gRPC communication with the Geometry server.
29+
class GRPCAssemblyConditionService(ABC): # pragma: no cover
30+
"""Assembly condition service for gRPC communication with the Geometry server.
3131
3232
Parameters
3333
----------
@@ -36,7 +36,7 @@ class GRPCAssemblyControlsService(ABC): # pragma: no cover
3636
"""
3737

3838
def __init__(self, channel: grpc.Channel):
39-
"""Initialize the GRPCAssemblyControls class."""
39+
"""Initialize the GRPCAssemblyCondition class."""
4040
pass
4141

4242
@abstractmethod

src/ansys/geometry/core/_grpc/_services/v0/assembly_controls.py renamed to src/ansys/geometry/core/_grpc/_services/v0/assembly_condition.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@
1919
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
22-
"""Module containing the assembly controls service implementation for v0."""
22+
"""Module containing the assembly condition service implementation for v0."""
2323

2424
import grpc
2525

2626
from ansys.geometry.core.errors import protect_grpc
2727

28-
from ..base.assembly_controls import GRPCAssemblyControlsService
28+
from ..base.assembly_condition import GRPCAssemblyConditionService
2929
from .conversions import build_grpc_id
3030

3131

32-
class GRPCAssemblyControlsServiceV0(GRPCAssemblyControlsService):
33-
"""Assembly controls service for gRPC communication with the Geometry server.
32+
class GRPCAssemblyConditionServiceV0(GRPCAssemblyConditionService):
33+
"""Assembly condition service for gRPC communication with the Geometry server.
3434
3535
This class provides methods to interact with the Geometry server's
36-
assembly controls service. It is specifically designed for the v0 version of the
36+
assembly condition service. It is specifically designed for the v0 version of the
3737
Geometry API.
3838
3939
Parameters
@@ -66,7 +66,7 @@ def create_align_condition(self, **kwargs) -> dict: # noqa: D102
6666

6767
# Return the response - formatted as a dictionary
6868
return {
69-
"moniker": resp.condition.moniker,
69+
"id": resp.condition.moniker,
7070
"is_deleted": resp.condition.is_deleted,
7171
"is_enabled": resp.condition.is_enabled,
7272
"is_satisfied": resp.condition.is_satisfied,
@@ -93,7 +93,7 @@ def create_tangent_condition(self, **kwargs) -> dict: # noqa: D102
9393

9494
# Return the response - formatted as a dictionary
9595
return {
96-
"moniker": resp.condition.moniker,
96+
"id": resp.condition.moniker,
9797
"is_deleted": resp.condition.is_deleted,
9898
"is_enabled": resp.condition.is_enabled,
9999
"is_satisfied": resp.condition.is_satisfied,
@@ -120,7 +120,7 @@ def create_orient_condition(self, **kwargs) -> dict: # noqa: D102
120120

121121
# Return the response - formatted as a dictionary
122122
return {
123-
"moniker": resp.condition.moniker,
123+
"id": resp.condition.moniker,
124124
"is_deleted": resp.condition.is_deleted,
125125
"is_enabled": resp.condition.is_enabled,
126126
"is_satisfied": resp.condition.is_satisfied,
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
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 assembly condition service implementation for v1."""
23+
24+
import grpc
25+
26+
from ansys.geometry.core.errors import protect_grpc
27+
28+
from ..base.assembly_condition import GRPCAssemblyConditionService
29+
from .conversions import build_grpc_id
30+
31+
32+
class GRPCAssemblyConditionServiceV1(GRPCAssemblyConditionService):
33+
"""Assembly condition service for gRPC communication with the Geometry server.
34+
35+
This class provides methods to interact with the Geometry server's
36+
assembly condition service. It is specifically designed for the v1 version of the
37+
Geometry API.
38+
39+
Parameters
40+
----------
41+
channel : grpc.Channel
42+
The gRPC channel to the server.
43+
"""
44+
45+
@protect_grpc
46+
def __init__(self, channel: grpc.Channel): # noqa: D102
47+
from ansys.api.discovery.v1.design.relationships.assemblycondition_pb2_grpc import (
48+
AssemblyConditionStub,
49+
)
50+
51+
self.stub = AssemblyConditionStub(channel)
52+
53+
@protect_grpc
54+
def create_align_condition(self, **kwargs) -> dict: # noqa: D102
55+
from ansys.api.discovery.v1.design.relationships.assemblycondition_pb2 import (
56+
CreateAlignRequest,
57+
CreateAlignRequestData,
58+
)
59+
60+
# Create the request - assumes all inputs are valid and of the proper type
61+
request = CreateAlignRequest(
62+
request_data=[CreateAlignRequestData(
63+
parent=build_grpc_id(kwargs["parent_id"]),
64+
geometric_a=build_grpc_id(kwargs["geometric_a_id"]),
65+
geometric_b=build_grpc_id(kwargs["geometric_b_id"]),
66+
)]
67+
)
68+
69+
# Call the gRPC service
70+
resp = self.stub.CreateAlign(request).response_data[0]
71+
72+
# Return the response - formatted as a dictionary
73+
return {
74+
"id": resp.align_condition.condition.id,
75+
"is_deleted": resp.align_condition.condition.is_deleted,
76+
"is_enabled": resp.align_condition.condition.is_enabled,
77+
"is_satisfied": resp.align_condition.condition.is_satisfied,
78+
"offset": resp.align_condition.offset,
79+
"is_reversed": resp.align_condition.is_reversed,
80+
"is_valid": resp.align_condition.is_valid,
81+
}
82+
83+
@protect_grpc
84+
def create_tangent_condition(self, **kwargs) -> dict: # noqa: D102
85+
from ansys.api.discovery.v1.design.relationships.assemblycondition_pb2 import (
86+
CreateTangentRequest,
87+
CreateTangentRequestData,
88+
)
89+
90+
# Create the request - assumes all inputs are valid and of the proper type
91+
request = CreateTangentRequest(
92+
request_data=[CreateTangentRequestData(
93+
parent=build_grpc_id(kwargs["parent_id"]),
94+
geometric_a=build_grpc_id(kwargs["geometric_a_id"]),
95+
geometric_b=build_grpc_id(kwargs["geometric_b_id"]),
96+
)]
97+
)
98+
99+
# Call the gRPC service
100+
resp = self.stub.CreateTangent(request).response_data[0]
101+
102+
# Return the response - formatted as a dictionary
103+
return {
104+
"id": resp.tangent_condition.condition.id,
105+
"is_deleted": resp.tangent_condition.condition.is_deleted,
106+
"is_enabled": resp.tangent_condition.condition.is_enabled,
107+
"is_satisfied": resp.tangent_condition.condition.is_satisfied,
108+
"offset": resp.tangent_condition.offset,
109+
"is_reversed": resp.tangent_condition.is_reversed,
110+
"is_valid": resp.tangent_condition.is_valid,
111+
}
112+
113+
@protect_grpc
114+
def create_orient_condition(self, **kwargs) -> dict: # noqa: D102
115+
from ansys.api.discovery.v1.design.relationships.assemblycondition_pb2 import (
116+
CreateOrientRequest,
117+
CreateOrientRequestData,
118+
)
119+
120+
# Create the request - assumes all inputs are valid and of the proper type
121+
request = CreateOrientRequest(
122+
request_data=[CreateOrientRequestData(
123+
parent=build_grpc_id(kwargs["parent_id"]),
124+
geometric_a=build_grpc_id(kwargs["geometric_a_id"]),
125+
geometric_b=build_grpc_id(kwargs["geometric_b_id"]),
126+
)]
127+
)
128+
129+
# Call the gRPC service
130+
resp = self.stub.CreateOrient(request).response_data[0]
131+
132+
# Return the response - formatted as a dictionary
133+
return {
134+
"id": resp.orient_condition.condition.id,
135+
"is_deleted": resp.orient_condition.condition.is_deleted,
136+
"is_enabled": resp.orient_condition.condition.is_enabled,
137+
"is_satisfied": resp.orient_condition.condition.is_satisfied,
138+
"offset": resp.orient_condition.offset,
139+
"is_reversed": resp.orient_condition.is_reversed,
140+
"is_valid": resp.orient_condition.is_valid,
141+
}

src/ansys/geometry/core/_grpc/_services/v1/assembly_controls.py

Lines changed: 0 additions & 60 deletions
This file was deleted.

src/ansys/geometry/core/_grpc/_services/v1/conversions.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from typing import TYPE_CHECKING
2525

2626
from ansys.api.discovery.v1.commonenums_pb2 import BackendType as GRPCBackendType
27+
from ansys.api.discovery.v1.commonmessages_pb2 import EntityIdentifier
2728

2829
if TYPE_CHECKING:
2930
from ansys.geometry.core.connection.backend import BackendType
@@ -65,4 +66,20 @@ def from_grpc_backend_type_to_backend_type(
6566
else:
6667
raise ValueError(f"Invalid backend type: {grpc_backend_type}")
6768

68-
return backend_type
69+
return backend_type
70+
71+
72+
def build_grpc_id(id: str) -> EntityIdentifier:
73+
"""Build an EntityIdentifier gRPC message.
74+
75+
Parameters
76+
----------
77+
id : str
78+
Source ID.
79+
80+
Returns
81+
-------
82+
EntityIdentifier
83+
Geometry service gRPC entity identifier message.
84+
"""
85+
return EntityIdentifier(id=id)

0 commit comments

Comments
 (0)