Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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/1882.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DbuApplication stub relocation
43 changes: 38 additions & 5 deletions src/ansys/geometry/core/_grpc/_services/_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
import grpc

from .._version import GeometryApiProtos, set_proto_version
from .base.admin import GRPCAdminService
from .base.bodies import GRPCBodyService
from .base.dbuapplication import GRPCDbuApplicationService


class _GRPCServices:
Expand Down Expand Up @@ -66,6 +68,7 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
# Lazy load all the services
self._admin = None
self._bodies = None
self._dbu_application = None

@property
def bodies(self) -> GRPCBodyService:
Expand All @@ -84,15 +87,17 @@ def bodies(self) -> GRPCBodyService:

if self.version == GeometryApiProtos.V0:
self._bodies = GRPCBodyServiceV0(self.channel)
elif self.version == GeometryApiProtos.V1:
elif self.version == GeometryApiProtos.V1: # pragma: no cover
# V1 is not implemented yet
self._bodies = GRPCBodyServiceV1(self.channel)
else:
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._bodies

@property
def admin(self):
def admin(self) -> GRPCAdminService:
"""
Get the admin service for the specified version.

Expand All @@ -108,9 +113,37 @@ def admin(self):

if self.version == GeometryApiProtos.V0:
self._admin = GRPCAdminServiceV0(self.channel)
elif self.version == GeometryApiProtos.V1:
elif self.version == GeometryApiProtos.V1: # pragma: no cover
# V1 is not implemented yet
self._admin = GRPCAdminServiceV1(self.channel)
else:
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._admin

@property
def dbu_application(self) -> GRPCDbuApplicationService:
"""
Get the DBU application service for the specified version.

Returns
-------
DbuApplicationServiceBase
The DBU application service for the specified version.
"""
if not self._dbu_application:
# Import the appropriate DBU application service based on the version
from .v0.dbuapplication import GRPCDbuApplicationServiceV0
from .v1.dbuapplication import GRPCDbuApplicationServiceV1

if self.version == GeometryApiProtos.V0:
self._dbu_application = GRPCDbuApplicationServiceV0(self.channel)
elif self.version == GeometryApiProtos.V1: # pragma: no cover
# V1 is not implemented yet
self._dbu_application = GRPCDbuApplicationServiceV1(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._dbu_application
45 changes: 45 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/base/dbuapplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 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 DBU Application service implementation (abstraction layer)."""

from abc import ABC, abstractmethod

import grpc


class GRPCDbuApplicationService(ABC):
"""DBU Application 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 GRPCDbuApplicationService class."""
pass # pragma: no cover

@abstractmethod
def run_script(self, **kwargs) -> dict:
"""Run a Scripting API script."""
pass # pragma: no cover
4 changes: 2 additions & 2 deletions src/ansys/geometry/core/_grpc/_services/v0/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class GRPCAdminServiceV0(GRPCAdminService):
The gRPC channel to the server.
"""

def __init__(self, channel: grpc.Channel):
"""Initialize the AdminServiceBase class."""
@protect_grpc
def __init__(self, channel: grpc.Channel): # noqa: D102
from ansys.api.dbu.v0.admin_pb2_grpc import AdminStub

self.stub = AdminStub(channel)
Expand Down
3 changes: 1 addition & 2 deletions src/ansys/geometry/core/_grpc/_services/v0/bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ class GRPCBodyServiceV0(GRPCBodyService):
"""

@protect_grpc
def __init__(self, channel: grpc.Channel):
"""Initialize the BodyService with the gRPC stub."""
def __init__(self, channel: grpc.Channel): # noqa: D102
from ansys.api.geometry.v0.bodies_pb2_grpc import BodiesStub

self.stub = BodiesStub(channel)
Expand Down
69 changes: 69 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/v0/dbuapplication.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# 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 DBU Application service implementation for v0."""

import grpc

from ansys.geometry.core.errors import protect_grpc

from ..base.dbuapplication import GRPCDbuApplicationService


class GRPCDbuApplicationServiceV0(GRPCDbuApplicationService):
"""DBU Application service for gRPC communication with the Geometry server.

This class provides methods to interact with the Geometry server's
DBU Application 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.dbu.v0.dbuapplication_pb2_grpc import DbuApplicationStub

self.stub = DbuApplicationStub(channel)

@protect_grpc
def run_script(self, **kwargs) -> dict: # noqa: D102
from ansys.api.dbu.v0.dbuapplication_pb2 import RunScriptFileRequest

# Create the request - assumes all inputs are valid and of the proper type
request = RunScriptFileRequest(
script_path=kwargs["script_path"],
script_args=kwargs["script_args"],
api_version=kwargs["api_version"],
)

# Call the gRPC service
response = self.stub.RunScriptFile(request)

# Return the response - formatted as a dictionary
return {
"success": response.success,
"message": response.message,
"values": None if not response.values else dict(response.values),
}
8 changes: 6 additions & 2 deletions src/ansys/geometry/core/_grpc/_services/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import grpc

from ansys.geometry.core.errors import protect_grpc

from ..base.admin import GRPCAdminService


Expand All @@ -39,14 +41,16 @@ class GRPCAdminServiceV1(GRPCAdminService): # pragma: no cover
The gRPC channel to the server.
"""

def __init__(self, channel: grpc.Channel):
"""Initialize the AdminServiceBase class."""
@protect_grpc
def __init__(self, channel: grpc.Channel): # noqa: D102
from ansys.api.dbu.v1.admin_pb2_grpc import AdminStub

self.stub = AdminStub(channel)

@protect_grpc
def get_backend(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_logs(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError
33 changes: 33 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/v1/bodies.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,101 +48,134 @@ def __init__(self, channel: grpc.Channel):

self.stub = BodiesStub(channel)

@protect_grpc
def create_sphere_body(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_extruded_body(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_sweeping_profile_body(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_sweeping_chain(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_extruded_body_from_face_profile(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_extruded_body_from_loft_profiles(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_planar_body(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_body_from_face(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_surface_body(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def create_surface_body_from_trimmed_curves(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def translate(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def delete(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def is_suppressed(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_color(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_faces(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_edges(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_volume(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_bounding_box(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def set_assigned_material(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_assigned_material(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def set_name(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def set_fill_style(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def set_suppressed(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def set_color(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def rotate(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def scale(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def mirror(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def map(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_collision(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def copy(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_tesellation(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def get_tesellation_with_options(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def boolean(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError
Loading
Loading