From 9b3f5f62aa2ce365a113bcf776f15982b36e8444 Mon Sep 17 00:00:00 2001 From: vmartidis <103631676+vmartidis@users.noreply.github.com> Date: Sun, 4 Sep 2022 14:20:32 +0300 Subject: [PATCH] T698080: Change Hfss extent info to dict (#95) * T698080: Change Hfss extent info to dict * T698080: Change Hfss extent info to dict * T698080: Hfss Dict update * T698080: Hfss Dict update * T698080: typo * T698080: Fix documentation problem. --- doc/source/api/utility.rst | 1 - protos/ansys/api/edb/v1/edb_messages.proto | 11 ++--- src/ansys/edb/layout/cell.py | 53 ++++++++++++++++++---- src/ansys/edb/utility/__init__.py | 1 - src/ansys/edb/utility/hfss_extent_info.py | 8 ---- 5 files changed, 48 insertions(+), 26 deletions(-) delete mode 100644 src/ansys/edb/utility/hfss_extent_info.py diff --git a/doc/source/api/utility.rst b/doc/source/api/utility.rst index 772deacf80..08cb852350 100644 --- a/doc/source/api/utility.rst +++ b/doc/source/api/utility.rst @@ -9,7 +9,6 @@ Classes .. autosummary:: :toctree: _autosummary - HfssExtentInfo PortPostProcessingProp Rlc TemperatureSettings diff --git a/protos/ansys/api/edb/v1/edb_messages.proto b/protos/ansys/api/edb/v1/edb_messages.proto index 7816226fd2..e523461abe 100644 --- a/protos/ansys/api/edb/v1/edb_messages.proto +++ b/protos/ansys/api/edb/v1/edb_messages.proto @@ -61,12 +61,12 @@ message HfssExtentInfoMessage { EDBObjMessage base_polygon = 4; HfssExtentsType dielectric_extent_type = 5; EDBObjMessage dielectric_base_polygon = 6; - HfssExtentMessage extent_size = 7; + HfssExtentMessage dielectric = 7; bool honor_user_dielectric = 8; - bool truncate_airbox_at_ground = 9; - HfssExtentMessage airbox_horizontal_extent = 10; - HfssExtentMessage airbox_vertical_positive_extent = 11; - HfssExtentMessage airbox_vertical_negative_extent = 12; + bool airbox_truncate_at_ground = 9; + HfssExtentMessage airbox_horizontal = 10; + HfssExtentMessage airbox_vertical_positive = 11; + HfssExtentMessage airbox_vertical_negative = 12; bool sync_airbox_vertical_extent = 13; bool is_pml_visible = 14; ValueMessage operating_frequency = 15; @@ -167,4 +167,3 @@ message EDBObjPairMessage { EDBObjMessage edb_obj_0 = 1; EDBObjMessage edb_obj_1 = 2; } - diff --git a/src/ansys/edb/layout/cell.py b/src/ansys/edb/layout/cell.py index 9c8f29284a..b85159f76d 100644 --- a/src/ansys/edb/layout/cell.py +++ b/src/ansys/edb/layout/cell.py @@ -11,7 +11,7 @@ from ansys.edb.layout import layout from ansys.edb.session import StubAccessor, StubType from ansys.edb.simulation_setup import SimulationSetup -from ansys.edb.utility import HfssExtentInfo, TemperatureSettings +from ansys.edb.utility import TemperatureSettings class CellType(Enum): @@ -30,12 +30,34 @@ class DesignMode(Enum): # dict representing options of HFSS Extents available via API. HFSS_EXTENT_ARGS = { - "dielectric": messages.hfss_extent_message, - "airbox_horizontal": messages.hfss_extent_message, - "airbox_vertical": messages.hfss_extent_message, - "airbox_vertical_positive": messages.hfss_extent_message, - "airbox_vertical_negative": messages.hfss_extent_message, - "airbox_truncate_at_ground": messages.bool_message, + "dielectric": "HfssExtentMessage", + "airbox_horizontal": "HfssExtentMessage", + "airbox_vertical_positive": "HfssExtentMessage", + "airbox_vertical_negative": "HfssExtentMessage", + "airbox_truncate_at_ground": "BoolValueMessage", +} + + +def _translate_bool_value(bool_value): + """Convert BoolValue Message to tuple of expected values.""" + return bool_value.value + + +def _translate_hfss_extent(hfss_extent_msg): + """Convert HfssExtentMessage to tuple of expected values.""" + return hfss_extent_msg.value, hfss_extent_msg.absolute + + +# dictionary describing message type and functions to translate them +_HFSS_EXTENT_MESSAGE_HELPER = { + "HfssExtentMessage": { + "msg": messages.hfss_extent_message, + "val": _translate_hfss_extent, + }, + "BoolValueMessage": { + "msg": messages.bool_message, + "val": _translate_bool_value, + }, } @@ -44,11 +66,21 @@ class DesignMode(Enum): def sanitize_args(args): """Extract valid extent options and convert them into messages.""" return { - k: HFSS_EXTENT_ARGS[k](args[k]) + k: _HFSS_EXTENT_MESSAGE_HELPER[HFSS_EXTENT_ARGS[k]]["msg"](args[k]) for k in filter(lambda k: k in args, HFSS_EXTENT_ARGS.keys()) } +def parse_args(msg): + """Extract extent options values from Hfss Extent message and add them into a dictionary.""" + res = {} + for attribute in HFSS_EXTENT_ARGS.keys(): + value = getattr(msg, attribute) + msg_type = HFSS_EXTENT_ARGS[attribute] + res[attribute] = _HFSS_EXTENT_MESSAGE_HELPER[msg_type]["val"](value) + return res + + class _QueryBuilder: @staticmethod def create(db, cell_type, name): @@ -272,9 +304,10 @@ def hfss_extent_info(self): Returns ------- - HfssExtentInfo + dict """ - return HfssExtentInfo(self.__stub.GetHfssExtentInfo(self.msg)) + msg = self.__stub.GetHfssExtentInfo(self.msg) + return parse_args(msg) def set_hfss_extent_info(self, **extents): """Set HFSS Extents of this cell. diff --git a/src/ansys/edb/utility/__init__.py b/src/ansys/edb/utility/__init__.py index c091572c0d..d07f75c7bd 100644 --- a/src/ansys/edb/utility/__init__.py +++ b/src/ansys/edb/utility/__init__.py @@ -1,6 +1,5 @@ """This package contains utility classes and functions available to users.""" -from ansys.edb.utility.hfss_extent_info import HfssExtentInfo from ansys.edb.utility.port_post_processing_prop import PortPostProcessingProp from ansys.edb.utility.rlc import Rlc from ansys.edb.utility.temperature_settings import TemperatureSettings diff --git a/src/ansys/edb/utility/hfss_extent_info.py b/src/ansys/edb/utility/hfss_extent_info.py deleted file mode 100644 index 6d1df9a508..0000000000 --- a/src/ansys/edb/utility/hfss_extent_info.py +++ /dev/null @@ -1,8 +0,0 @@ -"""HFSS Extent Info.""" -from ansys.edb.core import ObjBase - - -class HfssExtentInfo(ObjBase): - """HFSS Extent info class.""" - - pass