Skip to content
Draft
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
17 changes: 17 additions & 0 deletions src/ansys/edb/core/inner/ui_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""UI Manager."""

from ansys.api.edb.v1 import ui_manager_pb2_grpc
import google.protobuf.empty_pb2 as empty_pb2

from ansys.edb.core.session import StubAccessor, StubType


class UIManager:
"""Provides access to the UI Manager service."""

__stub: ui_manager_pb2_grpc.UIManagerServiceStub = StubAccessor(StubType.ui_manager)

@classmethod
def sync_3d_layout_ui(cls):
"""Synchronize the 3D layout UI."""
cls.__stub.Sync3DLayoutUI(empty_pb2.Empty())
35 changes: 35 additions & 0 deletions src/ansys/edb/core/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
from ansys.api.edb.v1.text_pb2_grpc import TextServiceStub
from ansys.api.edb.v1.transform_3d_pb2_grpc import Transform3DServiceStub
from ansys.api.edb.v1.transform_pb2_grpc import TransformServiceStub
from ansys.api.edb.v1.ui_manager_pb2_grpc import UIManagerServiceStub
from ansys.api.edb.v1.value_pb2_grpc import ValueServiceStub
from ansys.api.edb.v1.variable_server_pb2_grpc import VariableServerServiceStub
from ansys.api.edb.v1.via_group_pb2_grpc import ViaGroupServiceStub
Expand Down Expand Up @@ -476,6 +477,7 @@ class StubType(Enum):
q3d_dcrl_sim_settings = Q3DDCRLSettingsServiceStub
q3d_general_sim_settings = Q3DGeneralSettingsServiceStub
q3d_sim_settings = Q3DSettingsServiceStub
ui_manager = UIManagerServiceStub


def attach_session(
Expand Down Expand Up @@ -576,6 +578,39 @@ def session(
MOD.current_session.disconnect()


@contextmanager
def aedt_session(ip_address: str, port_num: int):
r"""Attach to an existing AEDT session in a context manager.

Parameters
----------
ip_address : str
IP address of the machine that is running the server.
port_num : int
Port number that the server is listening on.

Examples
--------
Attach to an existing AEDT session that automatically synchronizes the 3D layout UI
and disconnects when it goes out of scope.

>>> with aedt_session("localhost", 50051) as session:
>>> # program goes here
"""
try:
attach_session(ip_address, port_num)
yield
from ansys.edb.core.inner.ui_manager import UIManager

UIManager.sync_3d_layout_ui()
except EDBSessionException:
raise
except Exception as e: # noqa
raise
finally:
MOD.current_session.disconnect()


def get_layer_collection_stub() -> LayerCollectionServiceStub:
"""Get the layer collection stub.

Expand Down
Loading