From 5ea943654e12403a47d7fac959575f4ec027e92e Mon Sep 17 00:00:00 2001 From: Samuel Lopez <85613111+Samuelopez-ansys@users.noreply.github.com> Date: Fri, 20 Dec 2024 14:01:06 +0100 Subject: [PATCH] FIX: Icepak Mesh Binary Tree (#5600) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/ansys/aedt/core/application/design.py | 2 +- .../aedt/core/modules/boundary/common.py | 6 +- .../core/modules/boundary/hfss_boundary.py | 4 +- .../core/modules/boundary/layout_boundary.py | 6 +- .../core/modules/boundary/maxwell_boundary.py | 4 +- src/ansys/aedt/core/modules/mesh.py | 6 +- src/ansys/aedt/core/modules/mesh_icepak.py | 103 +++++++++++++----- src/ansys/aedt/core/modules/solve_setup.py | 10 +- .../aedt/core/visualization/report/common.py | 4 + 9 files changed, 97 insertions(+), 48 deletions(-) diff --git a/src/ansys/aedt/core/application/design.py b/src/ansys/aedt/core/application/design.py index 54795763700..8bd231884eb 100644 --- a/src/ansys/aedt/core/application/design.py +++ b/src/ansys/aedt/core/application/design.py @@ -479,7 +479,7 @@ def boundaries(self) -> List[BoundaryObject]: del self._boundaries[k] for boundary, boundarytype in zip(current_boundaries, current_types): if boundary in self._boundaries: - self._boundaries[boundary]._initialize_bynary_tree() + self._boundaries[boundary]._initialize_tree_node() continue if boundarytype == "MaxwellParameters": maxwell_parameter_type = self.get_oo_property_value(self.odesign, f"Parameters\\{boundary}", "Type") diff --git a/src/ansys/aedt/core/modules/boundary/common.py b/src/ansys/aedt/core/modules/boundary/common.py index b6cb0e6872f..adeeb9ff1a6 100644 --- a/src/ansys/aedt/core/modules/boundary/common.py +++ b/src/ansys/aedt/core/modules/boundary/common.py @@ -93,7 +93,7 @@ def _get_args(self, props=None): return arg @pyaedt_function_handler() - def _initialize_bynary_tree(self): + def _initialize_tree_node(self): if self._child_object: BinaryTreeNode.__init__(self, self._name, self._child_object, False) return True @@ -222,7 +222,7 @@ def __init__(self, app, name, props=None, boundarytype=None, auto_update=True): self.__props = BoundaryProps(self, props) if props else {} self._type = boundarytype self.auto_update = auto_update - self._initialize_bynary_tree() + self._initialize_tree_node() @property def _child_object(self): @@ -542,7 +542,7 @@ def create(self): else: return False - return self._initialize_bynary_tree() + return self._initialize_tree_node() @pyaedt_function_handler() def update(self): diff --git a/src/ansys/aedt/core/modules/boundary/hfss_boundary.py b/src/ansys/aedt/core/modules/boundary/hfss_boundary.py index 3932aec0fd3..decad53ed56 100644 --- a/src/ansys/aedt/core/modules/boundary/hfss_boundary.py +++ b/src/ansys/aedt/core/modules/boundary/hfss_boundary.py @@ -52,7 +52,7 @@ def __init__(self, app, component_name, props, component_type): self._name = component_name self.__props = BoundaryProps(self, props) if props else {} self.auto_update = True - self._initialize_bynary_tree() + self._initialize_tree_node() @property def _child_object(self): @@ -138,7 +138,7 @@ def create(self): self._app.oradfield.AddAntennaOverlay(self._get_args()) elif self.type == "FieldSourceGroup": self._app.oradfield.AddRadFieldSourceGroup(self._get_args()) - return self._initialize_bynary_tree() + return self._initialize_tree_node() @pyaedt_function_handler() def update(self): diff --git a/src/ansys/aedt/core/modules/boundary/layout_boundary.py b/src/ansys/aedt/core/modules/boundary/layout_boundary.py index 18a77b1fa40..775c12195eb 100644 --- a/src/ansys/aedt/core/modules/boundary/layout_boundary.py +++ b/src/ansys/aedt/core/modules/boundary/layout_boundary.py @@ -106,7 +106,7 @@ def __init__(self, app, component_type, component_name, props): self.native_properties = self.__props["NativeComponentDefinitionProvider"] self.auto_update = True - self._initialize_bynary_tree() + self._initialize_tree_node() @property def _child_object(self): @@ -218,7 +218,7 @@ def create(self): self.excitation_name = a[0].split(":")[0] except (GrpcApiError, IndexError): self.excitation_name = self._name - return self._initialize_bynary_tree() + return self._initialize_tree_node() @pyaedt_function_handler() def update(self): @@ -295,7 +295,7 @@ def __init__(self, app, name, props=None, boundarytype="Port"): self.__props = BoundaryProps(self, props) self.type = boundarytype self.auto_update = True - self._initialize_bynary_tree() + self._initialize_tree_node() @property def _child_object(self): diff --git a/src/ansys/aedt/core/modules/boundary/maxwell_boundary.py b/src/ansys/aedt/core/modules/boundary/maxwell_boundary.py index b21f8c8697b..8658dc55c85 100644 --- a/src/ansys/aedt/core/modules/boundary/maxwell_boundary.py +++ b/src/ansys/aedt/core/modules/boundary/maxwell_boundary.py @@ -65,7 +65,7 @@ def __init__(self, app, name, props=None, boundarytype=None): self.auto_update = True self.__reduced_matrices = None self.matrix_assignment = None - self._initialize_bynary_tree() + self._initialize_tree_node() @property def reduced_matrices(self): @@ -177,7 +177,7 @@ def create(self): self._app.o_maxwell_parameters.AssignLayoutForce(self._get_args()) else: return False - return self._initialize_bynary_tree() + return self._initialize_tree_node() @pyaedt_function_handler() def update(self): diff --git a/src/ansys/aedt/core/modules/mesh.py b/src/ansys/aedt/core/modules/mesh.py index 7c5fbcf5772..fa432c43661 100644 --- a/src/ansys/aedt/core/modules/mesh.py +++ b/src/ansys/aedt/core/modules/mesh.py @@ -125,7 +125,7 @@ def __init__(self, mesh, name, props, meshoptype): self._type = meshoptype self._name = name self.auto_update = True - self._initialize_bynary_tree() + self._initialize_tree_node() @property def _child_object(self): @@ -259,7 +259,7 @@ def create(self): self._mesh.omeshmodule.AssignCylindricalGapOp(self._get_args()) else: return False - return self._initialize_bynary_tree() + return self._initialize_tree_node() @pyaedt_function_handler() def update(self, key_name=None, value=None): @@ -405,7 +405,7 @@ def delete(self): return True @pyaedt_function_handler() - def _initialize_bynary_tree(self): + def _initialize_tree_node(self): if self._child_object: BinaryTreeNode.__init__(self, self._name, self._child_object, False) return True diff --git a/src/ansys/aedt/core/modules/mesh_icepak.py b/src/ansys/aedt/core/modules/mesh_icepak.py index b719f12ba01..217d2937e09 100644 --- a/src/ansys/aedt/core/modules/mesh_icepak.py +++ b/src/ansys/aedt/core/modules/mesh_icepak.py @@ -607,7 +607,7 @@ def __contains__(self, x): return x in self.keys() -class MeshRegionCommon(object): +class MeshRegionCommon(BinaryTreeNode): """ Manages Icepak mesh region settings. @@ -626,10 +626,26 @@ def __init__(self, units, app, name): self._name = name self._model_units = units self._app = app - child_object = self._app.get_oo_object(self._app.odesign, f"Mesh/{self._name}") + self._initialize_tree_node() - if child_object: - BinaryTreeNode.__init__(self, self._name, child_object, False) + @property + def _child_object(self): + """Object-oriented properties. + + Returns + ------- + class:`ansys.aedt.core.modeler.cad.elements_3d.BinaryTreeNode` + + """ + child_object = None + design_childs = self._app.get_oo_name(self._app.odesign) + + if "Mesh" in design_childs: + cc = self._app.get_oo_object(self._app.odesign, "Mesh") + cc_names = self._app.get_oo_name(cc) + if self._name in cc_names: + child_object = cc.GetChildObject(self._name) + return child_object @abstractmethod def update(self): @@ -643,26 +659,58 @@ def delete(self): def create(self): """Create the mesh region object.""" + @pyaedt_function_handler() + def _initialize_tree_node(self): + if self._name == "Settings": + return True + + if self._child_object: + child_object = self._app.get_oo_object(self._app.odesign, f"Mesh/{self._name}") + if child_object: + BinaryTreeNode.__init__(self, self._name, child_object, False) + return True + return False + # backward compatibility def __getattr__(self, name): - if "settings" in self.__dict__ and name in self.__dict__["settings"]: - return self.__dict__["settings"][name] - elif name == "UserSpecifiedSettings": - return self.__dict__["manual_settings"] - else: - return self.__dict__[name] + try: + self.__getattribute__(name) + except AttributeError: + if "settings" in self.__dict__ and name in self.__dict__["settings"]: + return self.__dict__["settings"][name] + elif name == "UserSpecifiedSettings": + return self.__dict__["manual_settings"] + else: + return self.__dict__[name] def __setattr__(self, name, value): + skip_properties = [ + "manual_settings", + "settings", + "_name", + "_model_units", + "_app", + "_assignment", + "enable", + "name", + ] + skip_properties_binary = [ + "_props", + "_saved_root_name", + "_get_child_obj_arg", + "_node", + "child_object", + "auto_update", + "_children", + "_BinaryTreeNode__first_level", + ] if ("settings" in self.__dict__) and (name in self.settings): self.settings[name] = value elif name == "UserSpecifiedSettings": self.__dict__["manual_settings"] = value - elif ( - ("settings" in self.__dict__) - and not (name in self.settings) - and name - not in ["manual_settings", "settings", "_name", "_model_units", "_app", "_assignment", "enable", "name"] - ): + elif name in skip_properties_binary: + super(BinaryTreeNode, self).__setattr__(name, value) + elif ("settings" in self.__dict__) and not (name in self.settings) and name not in skip_properties: self._app.logger.error( f"Setting name {name} is not available. Available parameters are: {', '.join(self.settings.keys())}." ) @@ -725,10 +773,7 @@ def create(self): self.delete() self.global_region = Region(self._app) self.global_region.create(self.padding_types, self.padding_values) - child_object = self._app.get_oo_object(self._app.odesign, f"Mesh/{self._name}") - - if child_object: - BinaryTreeNode.__init__(self, self._name, child_object, False) + return self._initialize_tree_node() class MeshRegion(MeshRegionCommon): @@ -796,6 +841,8 @@ def name(self): ------- str """ + if self._child_object: + self._name = str(self.properties["Name"]) return self._name @name.setter @@ -812,7 +859,8 @@ def name(self, value): ) self._app.modeler.refresh() self._name = value - if isinstance(self.assignment, SubRegion): + result = self._initialize_tree_node() + if isinstance(self.assignment, SubRegion) and result: self._assignment = self.assignment @pyaedt_function_handler @@ -834,7 +882,7 @@ def update(self): args += ["UserSpecifiedSettings:=", self.manual_settings] try: self._app.omeshmodule.EditMeshRegion(self.name, args) - return True + return self._initialize_tree_node() except GrpcApiError: # pragma : no cover return False @@ -934,13 +982,10 @@ def create(self): self._app.omeshmodule.AssignMeshRegion(args) self._app.mesh.meshregions.append(self) self._app.modeler.refresh_all_ids() - self._assignment = self.assignment - child_object = self._app.get_oo_object(self._app.odesign, f"Mesh/{self._name}") - - if child_object: - BinaryTreeNode.__init__(self, self._name, child_object, False) - - return True + result = self._initialize_tree_node() + if result: + self._assignment = self.assignment + return result # backward compatibility @property diff --git a/src/ansys/aedt/core/modules/solve_setup.py b/src/ansys/aedt/core/modules/solve_setup.py index f27e155f0e3..c19d96fdaec 100644 --- a/src/ansys/aedt/core/modules/solve_setup.py +++ b/src/ansys/aedt/core/modules/solve_setup.py @@ -72,7 +72,7 @@ def __init__(self, app, solution_type, name="MySetupAuto", is_new_setup=True): self._is_new_setup = is_new_setup # self._init_props(is_new_setup) self.auto_update = True - self._initialize_bynary_tree() + self._initialize_tree_node() @property def _child_object(self): @@ -94,7 +94,7 @@ def _child_object(self): return child_object @pyaedt_function_handler() - def _initialize_bynary_tree(self): + def _initialize_tree_node(self): if self._child_object: BinaryTreeNode.__init__(self, self._name, self._child_object, False) return True @@ -569,7 +569,7 @@ def create(self): arg = ["NAME:" + self._name] _dict2arg(self.props, arg) self.omodule.InsertSetup(soltype, arg) - return self._initialize_bynary_tree() + return self._initialize_tree_node() @pyaedt_function_handler(update_dictionary="properties") def update(self, properties=None): @@ -1172,7 +1172,7 @@ def create(self): arg = ["NAME:SimSetup"] _dict2arg(self.props, arg) self._setup(soltype, arg) - return self._initialize_bynary_tree() + return self._initialize_tree_node() @pyaedt_function_handler() def _setup(self, soltype, arg, newsetup=True): @@ -1913,7 +1913,7 @@ def create(self): arg = ["NAME:" + self.name] _dict2arg(self.props, arg) self.omodule.Add(arg) - return self._initialize_bynary_tree() + return self._initialize_tree_node() @pyaedt_function_handler(update_dictionary="properties") def update(self, properties=None): diff --git a/src/ansys/aedt/core/visualization/report/common.py b/src/ansys/aedt/core/visualization/report/common.py index b4365ce54f9..4889d1a187b 100644 --- a/src/ansys/aedt/core/visualization/report/common.py +++ b/src/ansys/aedt/core/visualization/report/common.py @@ -49,6 +49,7 @@ def __init__(self, report_setup, trace_name, oo=None): @pyaedt_function_handler() def _initialize_tree_node(self): BinaryTreeNode.__init__(self, self.line_name, self._oo, False) + return True @pyaedt_function_handler() def _change_property(self, props_value): @@ -259,6 +260,7 @@ def __init__( @pyaedt_function_handler() def _initialize_tree_node(self): BinaryTreeNode.__init__(self, self.aedt_name, self._oo, False) + return True @property def curve_properties(self): @@ -419,6 +421,8 @@ def _initialize_tree_node(self): oo = self._post.oreportsetup.GetChildObject(self._legacy_props["plot_name"]) if oo: BinaryTreeNode.__init__(self, self._legacy_props["plot_name"], oo, False) + return True + return False @property def __all_props(self):