diff --git a/protos/ansys/api/edb/v1/netclass.proto b/protos/ansys/api/edb/v1/netclass.proto new file mode 100644 index 0000000000..a7aa909f37 --- /dev/null +++ b/protos/ansys/api/edb/v1/netclass.proto @@ -0,0 +1,41 @@ +// Proto file representing the EDB NetClass + +syntax = "proto3"; + +package ansys.api.edb.v1; + +import "edb_messages.proto"; +import "refs.proto"; + +service NetClassService { + rpc Create (NetClassCreationMessage) returns (EDBObjMessage) {} + + rpc FindByName(EDBObjNameMessage) returns (EDBObjMessage) {} + + rpc GetName (EDBObjMessage) returns (google.protobuf.StringValue) {} + + rpc SetName(EDBObjNameMessage) returns (google.protobuf.Empty) {} + + rpc GetDescription (EDBObjMessage) returns (google.protobuf.StringValue) {} + + rpc SetDescription(StringPropertyMessage) returns (google.protobuf.Empty) {} + + rpc IsPowerGround(EDBObjMessage) returns (google.protobuf.BoolValue) {} + + rpc AddNet(NetClassEditMessage) returns (google.protobuf.Empty) {} + + rpc RemoveNet(NetClassEditMessage) returns (google.protobuf.Empty) {} + + rpc ContainsNet(NetClassEditMessage) returns (google.protobuf.BoolValue) {} +} + +// Message for Create +message NetClassCreationMessage { + EDBObjMessage layout = 1; + string name = 2; +} + +message NetClassEditMessage { + EDBObjMessage netclass = 1; + EDBObjMessage net = 2; +} diff --git a/src/ansys/edb/core/net/net_class.py b/src/ansys/edb/core/net/net_class.py index af6c94918b..613422c30c 100644 --- a/src/ansys/edb/core/net/net_class.py +++ b/src/ansys/edb/core/net/net_class.py @@ -1,8 +1,153 @@ """Net class.""" + +import ansys.api.edb.v1.netclass_pb2 as nc_pb2 + +import ansys.edb.core.interface.grpc.messages as messages from ansys.edb.core.layout.layout_obj import LayoutObj +from ansys.edb.core.session import StubAccessor, StubType +from ansys.edb.core.utility.edb_errors import handle_grpc_exception + + +class _QueryBuilder: + @staticmethod + def create(layout, name): + return nc_pb2.NetClassCreationMessage(layout=layout.msg, name=name) class NetClass(LayoutObj): """Net class.""" - pass + __stub = StubAccessor(StubType.netclass) + + @classmethod + @handle_grpc_exception + def create(cls, layout, name): + """ + Create net class. + + Parameters + ---------- + layout : Layout + name : str + + Returns + ------- + NetClass + """ + return NetClass(cls.__stub.Create(_QueryBuilder.create(layout, name))) + + @classmethod + @handle_grpc_exception + def find(cls, layout, name): + """ + Find net class by name. + + Parameters + ---------- + layout : Layout + name : str + + Returns + ------- + NetClass + """ + return NetClass(cls.__stub.FindByName(messages.edb_obj_name_message(layout, name))) + + @property + def name(self): + """ + Name of net class. + + Returns + ------- + str + """ + return self.__stub.GetName(self.msg).value + + @property + def description(self): + """ + Return description of net class. + + Returns + ------- + str + """ + return self.__stub.GetDescription(self.msg).value + + @name.setter + @handle_grpc_exception + def name(self, newname): + """ + Set name of net class. + + Parameters + ---------- + newname : str + + """ + return self.__stub.SetName(messages.edb_obj_name_message(self.msg, newname)) + + @description.setter + @handle_grpc_exception + def description(self, newdesc): + """ + Set description of net class. + + Parameters + ---------- + newdesc : str + + """ + return self.__stub.SetDescription(messages.string_property_message(self, newdesc)) + + @property + def is_power_ground(self): + """Return whether this netclass is power or ground. + + Returns + ------- + bool + """ + return self.__stub.IsPowerGround(messages.edb_obj_message(self.msg)).value + + @handle_grpc_exception + def add_net(self, net): + """ + Add net to netclass. + + Parameters + ---------- + net : Net + + """ + return self.__stub.AddNet(nc_pb2.NetClassEditMessage(netclass=self.msg, net=net.msg)) + + @handle_grpc_exception + def remove_net(self, net): + """ + Remove net from netclass. + + Parameters + ---------- + net : Net + + """ + self.__stub.RemoveNet(nc_pb2.NetClassEditMessage(netclass=self.msg, net=net.msg)) + + @handle_grpc_exception + def contains_net(self, net): + """ + Find if net exists in netclass. + + Parameters + ---------- + net : Net + + Returns + ------- + bool + """ + return self.__stub.ContainsNet( + nc_pb2.NetClassEditMessage(netclass=self.msg, net=net.msg) + ).value diff --git a/src/ansys/edb/core/session.py b/src/ansys/edb/core/session.py index 67f98e99ac..73166718bc 100644 --- a/src/ansys/edb/core/session.py +++ b/src/ansys/edb/core/session.py @@ -31,6 +31,7 @@ from ansys.api.edb.v1.layout_pb2_grpc import LayoutServiceStub from ansys.api.edb.v1.material_def_pb2_grpc import MaterialDefServiceStub from ansys.api.edb.v1.net_pb2_grpc import NetServiceStub +from ansys.api.edb.v1.netclass_pb2_grpc import NetClassServiceStub from ansys.api.edb.v1.padstack_def_pb2_grpc import PadstackDefServiceStub from ansys.api.edb.v1.padstack_inst_term_pb2_grpc import PadstackInstanceTerminalServiceStub from ansys.api.edb.v1.path_pb2_grpc import PathServiceStub @@ -269,6 +270,7 @@ class StubType(Enum): cell_instance = CellInstanceServiceStub hierarchy_obj = HierarchyObjectServiceStub group = GroupServiceStub + netclass = NetClassServiceStub layer_map = LayerMapServiceStub