From ca17b806fffe6861974f23e68398144f5e12d482 Mon Sep 17 00:00:00 2001 From: gmalinve <103059376+gmalinve@users.noreply.github.com> Date: Tue, 13 Aug 2024 11:17:15 +0200 Subject: [PATCH] FEAT: Get coordinate system (#5039) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alex Pham --- _unittest/test_02_3D_modeler.py | 15 +++++++++++++++ pyaedt/hfss.py | 2 +- pyaedt/icepak.py | 2 +- pyaedt/modeler/cad/Primitives.py | 17 +++++++++++++++++ pyaedt/modeler/cad/Primitives3D.py | 2 +- 5 files changed, 35 insertions(+), 3 deletions(-) diff --git a/_unittest/test_02_3D_modeler.py b/_unittest/test_02_3D_modeler.py index 54f23cb82d9..013ec0e3c98 100644 --- a/_unittest/test_02_3D_modeler.py +++ b/_unittest/test_02_3D_modeler.py @@ -681,18 +681,33 @@ def test_43c_set_as_working_object_cs(self): def test_43_set_working_coordinate_system(self): cs1 = self.aedtapp.modeler.create_coordinate_system(name="new1") assert self.aedtapp.modeler.set_working_coordinate_system("Global") + assert self.aedtapp.modeler.get_working_coordinate_system() == "Global" + assert self.aedtapp.modeler.set_working_coordinate_system("new1") + assert self.aedtapp.modeler.get_working_coordinate_system() == "new1" + assert self.aedtapp.modeler.set_working_coordinate_system("Global") + assert self.aedtapp.modeler.get_working_coordinate_system() == "Global" + assert self.aedtapp.modeler.set_working_coordinate_system(cs1) + assert self.aedtapp.modeler.get_working_coordinate_system() == cs1.name def test_43_set_working_face_coordinate_system(self): box = self.aedtapp.modeler.create_box([0, 0, 0], [2, 2, 2]) face = box.faces[0] fcs = self.aedtapp.modeler.create_face_coordinate_system(face, face, face.edges[1], name="new2") + assert self.aedtapp.modeler.set_working_coordinate_system("Global") + assert self.aedtapp.modeler.get_working_coordinate_system() == "Global" + assert self.aedtapp.modeler.set_working_coordinate_system("new2") + assert self.aedtapp.modeler.get_working_coordinate_system() == "new2" + assert self.aedtapp.modeler.set_working_coordinate_system("Global") + assert self.aedtapp.modeler.get_working_coordinate_system() == "Global" + assert self.aedtapp.modeler.set_working_coordinate_system(fcs) + assert self.aedtapp.modeler.get_working_coordinate_system() == fcs.name def test_44_sweep_around_axis(self): rect1 = self.aedtapp.modeler.create_rectangle(self.aedtapp.PLANE.YZ, [0, 0, 0], [20, 20], "rectangle_to_split") diff --git a/pyaedt/hfss.py b/pyaedt/hfss.py index 67e480fcb19..95951ab92ca 100644 --- a/pyaedt/hfss.py +++ b/pyaedt/hfss.py @@ -1531,7 +1531,7 @@ def create_sbr_antenna( self.logger.error("This native component only applies to a SBR+ solution.") return False if target_cs is None: - target_cs = self.modeler.oeditor.GetActiveCoordinateSystem() + target_cs = self.modeler.get_working_coordinate_system() parameters_defaults = self.SBRAntennaDefaults.parameters[antenna_type].copy() if use_current_source_representation and antenna_type in [ "Conical Horn", diff --git a/pyaedt/icepak.py b/pyaedt/icepak.py index 96bb3d369bf..5972c65a4bb 100644 --- a/pyaedt/icepak.py +++ b/pyaedt/icepak.py @@ -1585,7 +1585,7 @@ def create_parametric_heatsink_on_face( name_map["NumColumnsPerSide"], True, ) - cs = self.modeler.oeditor.GetActiveCoordinateSystem() + cs = self.modeler.get_working_coordinate_system() cs_ymax = self.modeler.create_coordinate_system( self.Position(0, name_map["HSHeight"] + "/2", 0), mode="view", diff --git a/pyaedt/modeler/cad/Primitives.py b/pyaedt/modeler/cad/Primitives.py index b61784b380e..06687484e39 100644 --- a/pyaedt/modeler/cad/Primitives.py +++ b/pyaedt/modeler/cad/Primitives.py @@ -1785,6 +1785,23 @@ def set_working_coordinate_system(self, name): ) return True + @pyaedt_function_handler() + def get_working_coordinate_system(self): + """Get the active coordinate system. + + Returns + ------- + str + Name of the active coordinate system. + + References + ---------- + + >>> oEditor.GetActiveCoordinateSystem + """ + + return self.oeditor.GetActiveCoordinateSystem() + @pyaedt_function_handler() def invert_cs(self, coordinate_system, to_global=False): """Get the inverse translation and the conjugate quaternion of the input coordinate system. diff --git a/pyaedt/modeler/cad/Primitives3D.py b/pyaedt/modeler/cad/Primitives3D.py index 5e3ba8b39cc..e843eaa3ba3 100644 --- a/pyaedt/modeler/cad/Primitives3D.py +++ b/pyaedt/modeler/cad/Primitives3D.py @@ -1432,7 +1432,7 @@ def _create_reference_cs_from_3dcomp(self, assignment, password): 3d component. """ app = assignment.edit_definition(password=password) - wcs = app.modeler.oeditor.GetActiveCoordinateSystem() + wcs = app.modeler.get_working_coordinate_system() if wcs != "Global": temp_folder = os.path.join( self._app.toolkit_directory, self._app.design_name, generate_unique_name("temp_folder")