From 8124967cc7d278fe07fcc5c6ef420b5576a3ea3a Mon Sep 17 00:00:00 2001 From: chenchienjacklin <104948990+chenchienjacklin@users.noreply.github.com> Date: Wed, 1 Nov 2023 12:34:39 -0700 Subject: [PATCH] D907066: Expose InstArray in pyedb. --- protos/ansys/api/edb/v1/inst_array.proto | 43 ++++++++ protos/ansys/api/edb/v1/layout_obj.proto | 1 + src/ansys/edb/core/messages.py | 14 +++ src/ansys/edb/edb_defs.py | 1 + src/ansys/edb/hierarchy/__init__.py | 1 + src/ansys/edb/hierarchy/inst_array.py | 125 +++++++++++++++++++++++ src/ansys/edb/session.py | 2 + 7 files changed, 187 insertions(+) create mode 100644 protos/ansys/api/edb/v1/inst_array.proto create mode 100644 src/ansys/edb/hierarchy/inst_array.py diff --git a/protos/ansys/api/edb/v1/inst_array.proto b/protos/ansys/api/edb/v1/inst_array.proto new file mode 100644 index 0000000000..de5ba64441 --- /dev/null +++ b/protos/ansys/api/edb/v1/inst_array.proto @@ -0,0 +1,43 @@ +// Proto file representing the EDB Instance Array class + +syntax = "proto3"; + +// Package +package ansys.api.edb.v1; + +// Imports +import "edb_messages.proto"; +import "point_data.proto"; + +// Instance Array service definition +service InstArrayService { + rpc Create(InstArrayCreationMessage) returns (EDBObjMessage) {} + + rpc FindByName(StringPropertyMessage) returns (EDBObjMessage) {} + + rpc GetOrig(EDBObjMessage) returns (PointMessage) {} + + rpc GetXAxis(EDBObjMessage) returns (PointMessage) {} + rpc SetXAxis(PointPropertyMessage) returns (google.protobuf.Empty) {} + + rpc GetYAxis(EDBObjMessage) returns (PointMessage) {} + rpc SetYAxis(PointPropertyMessage) returns (google.protobuf.Empty) {} + + rpc GetXCount(EDBObjMessage) returns (ValueMessage) {} + rpc SetXCount(ValuePropertyMessage) returns (google.protobuf.Empty) {} + + rpc GetYCount(EDBObjMessage) returns (ValueMessage) {} + rpc SetYCount(ValuePropertyMessage) returns (google.protobuf.Empty) {} + + rpc Decompose(EDBObjMessage) returns (google.protobuf.Empty) {} +} + +message InstArrayCreationMessage { + StringPropertyMessage layout = 1; + EDBObjMessage ref = 2; + PointMessage orig = 3; + PointMessage xaxis = 4; + PointMessage yaxis = 5; + ValueMessage xcount = 6; + ValueMessage ycount = 7; +} diff --git a/protos/ansys/api/edb/v1/layout_obj.proto b/protos/ansys/api/edb/v1/layout_obj.proto index 5ea9a0658f..dcf2848eb6 100644 --- a/protos/ansys/api/edb/v1/layout_obj.proto +++ b/protos/ansys/api/edb/v1/layout_obj.proto @@ -24,6 +24,7 @@ enum LayoutObjType { VOLTAGE_REGULATOR = 13; EXTENDED_NET = 14; LAYOUT_OBJ_TYPE_COUNT = 15; + INST_ARRAY = 16; INVALID_LAYOUT_OBJ = -1; } diff --git a/src/ansys/edb/core/messages.py b/src/ansys/edb/core/messages.py index 6be4eea73b..19aa07f0c6 100644 --- a/src/ansys/edb/core/messages.py +++ b/src/ansys/edb/core/messages.py @@ -82,6 +82,7 @@ SkinDepthMeshOperationMessage, ) from ansys.api.edb.v1.hierarchy_obj_pb2 import ObjectNameInLayoutMessage +from ansys.api.edb.v1.inst_array_pb2 import InstArrayCreationMessage from ansys.api.edb.v1.layout_pb2 import ( LayoutConvertP2VMessage, LayoutExpandedExtentMessage, @@ -444,6 +445,19 @@ def cell_instance_parameter_override_message(target, param_name, param_value): ) +def inst_array_creation_message(layout, name, ref, orig, xaxis, yaxis, xcount, ycount): + """Convert to InstArrayCreationMessage.""" + return InstArrayCreationMessage( + layout=string_property_message(layout, name), + ref=edb_obj_message(ref), + orig=point_message(orig), + xaxis=point_message(xaxis), + yaxis=point_message(yaxis), + xcount=value_message(xcount), + ycount=value_message(ycount), + ) + + def component_def_creation_message(db, comp_name, fp): """Convert to ComponentDefCreateMessage.""" return ComponentDefCreateMessage(db=db.msg, comp_name=comp_name, fp=fp.msg) diff --git a/src/ansys/edb/edb_defs.py b/src/ansys/edb/edb_defs.py index 6d4d16234e..7840129aba 100644 --- a/src/ansys/edb/edb_defs.py +++ b/src/ansys/edb/edb_defs.py @@ -15,6 +15,7 @@ class LayoutObjType(enum.Enum): TERMINAL = layout_obj_pb2.TERM TERMINAL_INSTANCE = layout_obj_pb2.TERM_INST CELL_INSTANCE = layout_obj_pb2.CELL_INST + INST_ARRAY = layout_obj_pb2.INST_ARRAY LAYER = layout_obj_pb2.LAYER NET = layout_obj_pb2.NET PADSTACK = layout_obj_pb2.PADSTACK diff --git a/src/ansys/edb/hierarchy/__init__.py b/src/ansys/edb/hierarchy/__init__.py index cf8f65d28e..74f8c74909 100644 --- a/src/ansys/edb/hierarchy/__init__.py +++ b/src/ansys/edb/hierarchy/__init__.py @@ -3,6 +3,7 @@ from ansys.edb.hierarchy.cell_instance import CellInstance from ansys.edb.hierarchy.component_group import ComponentGroup, ComponentType from ansys.edb.hierarchy.group import Group +from ansys.edb.hierarchy.inst_array import InstArray from ansys.edb.hierarchy.model import Model from ansys.edb.hierarchy.netlist_model import NetlistModel from ansys.edb.hierarchy.pin_group import PinGroup diff --git a/src/ansys/edb/hierarchy/inst_array.py b/src/ansys/edb/hierarchy/inst_array.py new file mode 100644 index 0000000000..ae8251887a --- /dev/null +++ b/src/ansys/edb/hierarchy/inst_array.py @@ -0,0 +1,125 @@ +"""Inst Array.""" + +from ansys.api.edb.v1.inst_array_pb2_grpc import InstArrayServiceStub + +from ansys.edb.core import messages +from ansys.edb.edb_defs import LayoutObjType +from ansys.edb.hierarchy import cell_instance +from ansys.edb.session import StubAccessor, StubType +from ansys.edb.utility import Value + + +class InstArray(cell_instance.CellInstance): + """Class representing an instance array object.""" + + __stub: InstArrayServiceStub = StubAccessor(StubType.inst_array) + layout_obj_type = LayoutObjType.INST_ARRAY + + @classmethod + def create(cls, layout, name, ref, orig, xaxis, yaxis, xcount, ycount): + """Create an instance array object with a layout. + + Parameters + ---------- + layout : :class:`Layout ` + Layout that owns the instance array. + name : str + Name of instance array to be created. + ref : :class:`Layout ` + Layout that the instance array refers to. + orig : :class:`PointData ` + PointData that represents the origin of the instanace array. + xaxis : :class:`PointData ` + PointData that represents the xaxis of the instanace array. + yaxis : :class:`PointData ` + PointData that represents the yaxis of the instanace array. + xcount : :class:`Value ` + Value of x count of the instance array. + ycount : :class:`Value ` + Value of y count of the instance array. + + Returns + ------- + InstArray + Newly created instance array. + """ + return InstArray( + cls.__stub.Create( + messages.inst_array_creation_message( + layout, name, ref, orig, xaxis, yaxis, xcount, ycount + ) + ) + ) + + @classmethod + def find(cls, layout, name): + """Find an instance array in layout by name. + + Parameters + ---------- + layout : :class:`Layout ` + Layout to search the instance array in. + name : str + Name of the instance array to be searched. + + Returns + ------- + InstArray + instance array that is found, None otherwise. + """ + return InstArray(cls.__stub.FindByName(messages.string_property_message(layout, name))) + + @property + def orig(self): + """:obj:`tuple` (:class:`Value `, :class:`Value `): \ + [x, y] origin of the instance array.""" + pnt_msg = self.__stub.GetOrig(self.msg) + return [Value(pnt_msg.x), Value(pnt_msg.y)] + + @property + def x_axis(self): + """:obj:`tuple` (:class:`Value `, :class:`Value `): \ + [x, y] x axis of the instance array.""" + pnt_msg = self.__stub.GetXAxis(self.msg) + return [Value(pnt_msg.x), Value(pnt_msg.y)] + + @x_axis.setter + def x_axis(self, value): + """Set the x axis of the instance array.""" + self.__stub.SetXAxis(messages.point_property_message(self, value)) + + @property + def y_axis(self): + """:obj:`tuple` (:class:`Value `, :class:`Value `): \ + [x, y] y axis of the instance array.""" + pnt_msg = self.__stub.GetYAxis(self.msg) + return [Value(pnt_msg.x), Value(pnt_msg.y)] + + @y_axis.setter + def y_axis(self, value): + """Set the y axis of the instance array.""" + self.__stub.SetYAxis(messages.point_property_message(self, value)) + + @property + def x_count(self): + """:class:`Value `: x count of the instance array.""" + return Value(self.__stub.GetXCount(self.msg)) + + @x_count.setter + def x_count(self, value): + """Get the x count of the instance array.""" + self.__stub.SetXCount(messages.value_property_message(self, messages.value_message(value))) + + @property + def y_count(self): + """:class:`Value `: y count of the instance array.""" + return Value(self.__stub.GetYCount(self.msg)) + + @y_count.setter + def y_count(self, value): + """Get the y count of the instance array.""" + self.__stub.SetYCount(messages.value_property_message(self, messages.value_message(value))) + + def decompose(self): + """Decompose the instance array.""" + self.__stub.Decompose(self.msg) diff --git a/src/ansys/edb/session.py b/src/ansys/edb/session.py index 77ab718356..95920e57c6 100644 --- a/src/ansys/edb/session.py +++ b/src/ansys/edb/session.py @@ -50,6 +50,7 @@ from ansys.api.edb.v1.hfss_simulation_setup_pb2_grpc import HfssSimulationSetupServiceStub from ansys.api.edb.v1.hierarchy_obj_pb2_grpc import HierarchyObjectServiceStub from ansys.api.edb.v1.ic_component_property_pb2_grpc import ICComponentPropertyServiceStub +from ansys.api.edb.v1.inst_array_pb2_grpc import InstArrayServiceStub from ansys.api.edb.v1.io_component_property_pb2_grpc import IOComponentPropertyServiceStub from ansys.api.edb.v1.layer_collection_pb2_grpc import LayerCollectionServiceStub from ansys.api.edb.v1.layer_map_pb2_grpc import LayerMapServiceStub @@ -354,6 +355,7 @@ class StubType(Enum): value = ValueServiceStub variable_server = VariableServerServiceStub cell_instance = CellInstanceServiceStub + inst_array = InstArrayServiceStub hierarchy_obj = HierarchyObjectServiceStub group = GroupServiceStub netclass = NetClassServiceStub