Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: improved the way wires are mapped and managed in Circuit #4679

Merged
merged 3 commits into from
May 17, 2024
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
4 changes: 3 additions & 1 deletion _unittest/test_21_Circuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,9 +756,11 @@ def test_42_create_wire(self):

def test_43_display_wire_properties(self):
self.aedtapp.set_active_design("CreateWireTest")
assert self.aedtapp.modeler.wire.display_wire_properties(
wire = self.aedtapp.modeler.components.get_wire_by_name("wire_name_test")
assert wire.display_wire_properties(
name="wire_name_test", property_to_display="NetName", visibility="Value", location="Top"
)

assert not self.aedtapp.modeler.wire.display_wire_properties(
name="invalid", property_to_display="NetName", visibility="Value", location="Top"
)
Expand Down
2 changes: 1 addition & 1 deletion pyaedt/application/Analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def materials(self):
Materials in the project.
"""
if not self._materials:
if self._materials is None:
self.logger.reset_timer()
from pyaedt.modules.MaterialLib import Materials

Expand Down
52 changes: 44 additions & 8 deletions pyaedt/modeler/circuits/PrimitivesCircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,54 @@ def __init__(self, modeler):
self.oeditor = self._modeler.oeditor
self._currentId = 0
self.components = {}
self.wires = {}
self.refresh_all_ids()
self.current_position = [0, 0]
self.increment_mils = [1000, 1000]
self.limits_mils = 20000

@pyaedt_function_handler()
def get_wire_by_name(self, name):
"""Wire class by name.
Parameters
----------
name : str
Wire name.
Returns
-------
:class:`pyaedt.modeler.circuits.object3dcircuit.Wire`
`
"""
for _, w in self.wires.items():
if w.name == name:
return w
wname = w.name.split(";")[0].split("@")[0]
if name == wname:
return w

@property
def wires(self):
"""All schematic wires in the design.
Returns
dict
Wires.
"""
wire_names = {}
for wire in self.oeditor.GetAllElements():
if "Wire" in wire:
w = Wire(self, composed_name=wire)
if ":" in wire.split(";")[1]:
wire_id = int(wire.split(";")[1].split(":")[0])
else:
wire_id = int(wire.split(";")[1])
name = wire.split(";")[0].split("@")[1]
w.id = wire_id
w.name = name
wire_names[wire_id] = w
return wire_names

@property
def o_definition_manager(self):
"""Aedt oDefinitionManager.
Expand Down Expand Up @@ -1180,12 +1222,7 @@ def create_wire(self, points, name=""):
arg2 = ["NAME:Attributes", "Page:=", 1]
try:
wire_id = self.oeditor.CreateWire(arg1, arg2)
w = Wire(self._modeler)
for segment in self._app.oeditor.GetWireSegments(wire_id):
key = "SegmentID_{}".format(segment.split(" ")[3])
point1 = [float(x) for x in segment.split(" ")[1].split(",")]
point2 = [float(x) for x in segment.split(" ")[2].split(",")]
w.points_in_segment[key] = [point1, point2]
w = Wire(self._modeler, composed_name=wire_id)
if ":" in wire_id.split(";")[1]:
wire_id = int(wire_id.split(";")[1].split(":")[0])
else:
Expand All @@ -1194,7 +1231,6 @@ def create_wire(self, points, name=""):
name = generate_unique_name("Wire")
w.name = name
w.id = int(wire_id)
self.wires[w.id] = w
return w
except Exception:
return False
Expand Down
44 changes: 30 additions & 14 deletions pyaedt/modeler/circuits/object3dcircuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,12 +908,25 @@ def enforce_touchstone_model_passive(self):
class Wire(object):
"""Creates and manipulates a wire."""

def __init__(self, modeler):
def __init__(self, modeler, composed_name=None):
self.composed_name = composed_name
self._app = modeler._app
self._modeler = modeler
self.name = ""
self.id = 0
self.points_in_segment = {}
self._points_in_segment = {}

@property
def points_in_segment(self):
"""Points in segment."""
if not self.composed_name:
return {}
for segment in self._app.oeditor.GetWireSegments(self.composed_name):
key = int(segment.split(" ")[3])
point1 = [float(x) for x in segment.split(" ")[1].split(",")]
point2 = [float(x) for x in segment.split(" ")[2].split(",")]
self._points_in_segment[key] = [point1, point2]
return self._points_in_segment

@property
def _oeditor(self):
Expand Down Expand Up @@ -961,23 +974,26 @@ def display_wire_properties(self, name="", property_to_display="NetName", visibi
``True`` when successful, ``False`` when failed.
"""
try:
wire_exists = False
for wire in self.wires:
if name == wire.split("@")[1].split(";")[0]:
wire_id = wire.split("@")[1].split(";")[1].split(":")[0]
wire_exists = True
break
else:
continue
if not wire_exists:
raise ValueError("Invalid wire name provided.")

if name:
wire_exists = False
for wire in self.wires:
if name == wire.split("@")[1].split(";")[0]:
wire_id = wire.split("@")[1].split(";")[1].split(":")[0]
wire_exists = True
break
else:
continue
if not wire_exists:
raise ValueError("Invalid wire name provided.")
composed_name = "Wire@{};{};{}".format(name, wire_id, 1)
else:
composed_name = self.composed_name
self._oeditor.ChangeProperty(
[
"NAME:AllTabs",
[
"NAME:PropDisplayPropTab",
["NAME:PropServers", "Wire@{};{};{}".format(name, wire_id, 1)],
["NAME:PropServers", composed_name],
[
"NAME:NewProps",
["NAME:" + property_to_display, "Format:=", visibility, "Location:=", location],
Expand Down
Loading