Skip to content

Commit

Permalink
FIX: Object oriented name update (#5595)
Browse files Browse the repository at this point in the history
Co-authored-by: Devin <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Devin <[email protected]>
Co-authored-by: Sébastien Morais <[email protected]>
Co-authored-by: mcapodif <[email protected]>
  • Loading branch information
6 people authored Dec 20, 2024
1 parent d28b8d3 commit 1c9e725
Show file tree
Hide file tree
Showing 20 changed files with 392 additions and 240 deletions.
10 changes: 10 additions & 0 deletions src/ansys/aedt/core/application/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,16 @@ def excitation_objects(self):
if el.name in exc_names:
self._excitation_objects[el.name] = el

# Delete objects that are not anymore available
keys_to_remove = [
internal_excitation
for internal_excitation in self._excitation_objects
if internal_excitation not in self.excitations
]

for key in keys_to_remove:
del self._excitation_objects[key]

return self._excitation_objects

@pyaedt_function_handler()
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/aedt/core/application/analysis_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1377,7 +1377,7 @@ def import_gds_3d(self, input_file: str, mapping_layers: dict, units: str = "um"
input_file : str
Path to the GDS file.
mapping_layers : dict
Dictionary keys are GDS layer numbers, and the value is a tuple with the thickness and elevation.
Dictionary keys are GDS layer numbers, and the value is a tuple with the elevation and thickness.
units : str, optional
Length unit values. The default is ``"um"``.
import_method : integer, optional
Expand Down
7 changes: 6 additions & 1 deletion src/ansys/aedt/core/application/design.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
from ansys.aedt.core.generic.load_aedt_file import load_entire_aedt_file
from ansys.aedt.core.modules.boundary.common import BoundaryObject
from ansys.aedt.core.modules.boundary.icepak_boundary import NetworkObject
from ansys.aedt.core.modules.boundary.layout_boundary import BoundaryObject3dLayout
from ansys.aedt.core.modules.boundary.maxwell_boundary import MaxwellParameters

if sys.version_info.major > 2:
Expand Down Expand Up @@ -492,10 +493,14 @@ def boundaries(self) -> List[BoundaryObject]:
self._boundaries[boundary] = NetworkObject(self, boundary)
else:
self._boundaries[boundary] = BoundaryObject(self, boundary, boundarytype=boundarytype)

try:
for k, v in zip(current_excitations, current_excitation_types):
if k not in self._boundaries:
self._boundaries[k] = BoundaryObject(self, k, boundarytype=v)
if self.design_type == "HFSS 3D Layout Design" and v == "Port":
self._boundaries[k] = BoundaryObject3dLayout(self, k, props=None, boundarytype=v)
else:
self._boundaries[k] = BoundaryObject(self, k, boundarytype=v)
except Exception:
self.logger.info("Failed to design boundary object.")
return list(self._boundaries.values())
Expand Down
1 change: 1 addition & 0 deletions src/ansys/aedt/core/hfss.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def field_setups(self):
List of :class:`ansys.aedt.core.modules.boundary.hfss_boundary.FarFieldSetup` and
:class:`ansys.aedt.core.modules.hfss_boundary.NearFieldSetup`
"""
self._field_setups = []
for field in self.field_setup_names:
obj_field = self.odesign.GetChildObject("Radiation").GetChildObject(field)
type_field = obj_field.GetPropValue("Type")
Expand Down
69 changes: 49 additions & 20 deletions src/ansys/aedt/core/modeler/cad/elements_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1370,43 +1370,60 @@ def __init__(self, node, child_object, first_level=False, get_child_obj_arg=None
self._props = None
if not root_name:
root_name = node
saved_root_name = node if first_level else root_name
self.node = node
self._saved_root_name = node if first_level else root_name
self._get_child_obj_arg = get_child_obj_arg
self._node = node
self.child_object = child_object
self.children = {}
self.auto_update = True
self._children = {}
self.__first_level = first_level
if first_level:
self._update_children()

def _update_children(self):
self._children = {}
name = None
try:
if get_child_obj_arg is None:
child_names = [i for i in list(child_object.GetChildNames()) if not i.startswith("CachedBody")]
if self._get_child_obj_arg is None:
child_names = [i for i in list(self.child_object.GetChildNames()) if not i.startswith("CachedBody")]
else:
child_names = [
i for i in list(child_object.GetChildNames(get_child_obj_arg)) if not i.startswith("CachedBody")
i
for i in list(self.child_object.GetChildNames(self._get_child_obj_arg))
if not i.startswith("CachedBody")
]
except Exception: # pragma: no cover
child_names = []
for i in child_names:
if not name:
name = i
if i == "OperandPart_" + saved_root_name or i == "OperandPart_" + saved_root_name.split("_")[0]:
if i == "OperandPart_" + self._saved_root_name or i == "OperandPart_" + self._saved_root_name.split("_")[0]:
continue
elif not i.startswith("OperandPart_"):
try:
self.children[i] = BinaryTreeNode(i, self.child_object.GetChildObject(i), root_name=saved_root_name)
self._children[i] = BinaryTreeNode(
i, self.child_object.GetChildObject(i), root_name=self._saved_root_name
)
except Exception: # nosec
pass
else:
names = self.child_object.GetChildObject(i).GetChildNames()
for name in names:
self.children[name] = BinaryTreeNode(
name, self.child_object.GetChildObject(i).GetChildObject(name), root_name=saved_root_name
self._children[name] = BinaryTreeNode(
name, self.child_object.GetChildObject(i).GetChildObject(name), root_name=self._saved_root_name
)
if first_level:
self.child_object = self.children[name].child_object
self._props = self.children[name]._props
if name and self.__first_level:
self.child_object = self._children[name].child_object
self._props = self._children[name].properties
if name == "CreatePolyline:1":
self.segments = self.children[name].children
del self.children[name]
self.segments = self._children[name].children
del self._children[name]

@property
def children(self):
if not self._children:
self._update_children()
return self._children

@property
def properties(self):
Expand All @@ -1417,6 +1434,8 @@ def properties(self):
:class:``ansys.aedt.coree.modeler.cad.elements_3d.HistoryProps``
"""
self._props = {}
if not getattr(self, "child_object", None):
return self._props
if settings.aedt_version >= "2024.2":
try:
from ansys.aedt.core.application import _get_data_model
Expand Down Expand Up @@ -1464,18 +1483,28 @@ def update_property(self, prop_name, prop_value):
bool
``True`` when successful, ``False`` when failed.
"""
if prop_value is None:
settings.logger.warning(f"Property {prop_name} set to None ignored.")
return
try:
self.child_object.SetPropValue(prop_name, prop_value)
return True
result = self.child_object.SetPropValue(prop_name, prop_value)
if result:
if prop_name == "Name" and getattr(self, "_name", False):
setattr(self, "_name", prop_value)
else:
settings.logger.warning(f"Property {prop_name} is read-only.")
# Property Name duplicated
return
except Exception: # pragma: no cover
return False
# Property read-only
raise KeyError

@pyaedt_function_handler
def _jsonalize_tree(self, binary_tree_node):
childrend_dict = {}
for _, node in binary_tree_node.children.items():
childrend_dict.update(self._jsonalize_tree(node))
return {binary_tree_node.node: {"Props": binary_tree_node.properties, "Children": childrend_dict}}
return {binary_tree_node._node: {"Props": binary_tree_node.properties, "Children": childrend_dict}}

@pyaedt_function_handler
def jsonalize_tree(self):
Expand All @@ -1496,7 +1525,7 @@ def _suppress(self, node, app, suppress):
"NAME:AllTabs",
[
"NAME:Geometry3DCmdTab",
["NAME:PropServers", node.child_object.GetObjPath().split("/")[3] + ":" + node.node],
["NAME:PropServers", node.child_object.GetObjPath().split("/")[3] + ":" + node._node],
["NAME:ChangedProps", ["NAME:Suppress Command", "Value:=", suppress]],
],
]
Expand Down
Loading

0 comments on commit 1c9e725

Please sign in to comment.