diff --git a/src/ansys/aedt/core/modeler/cad/elements_3d.py b/src/ansys/aedt/core/modeler/cad/elements_3d.py index e618c35c414..ef457b915c5 100644 --- a/src/ansys/aedt/core/modeler/cad/elements_3d.py +++ b/src/ansys/aedt/core/modeler/cad/elements_3d.py @@ -183,24 +183,32 @@ def chamfer(self, left_distance=1, right_distance=None, angle=45, chamfer_type=0 vArg2 = ["NAME:ChamferParameters"] vArg2.append("Edges:="), vArg2.append(edge_id_list) vArg2.append("Vertices:="), vArg2.append(vertex_id_list) - vArg2.append("LeftDistance:="), vArg2.append(self._object3d._primitives._arg_with_dim(left_distance)) - if not right_distance: + if right_distance is None: right_distance = left_distance if chamfer_type == 0: + if left_distance != right_distance: + self._object3d.logger.error( + "Do not set right distance or ensure that left distance equals right distance." + ) + vArg2.append("LeftDistance:="), vArg2.append(self._object3d._primitives._arg_with_dim(left_distance)) vArg2.append("RightDistance:="), vArg2.append(self._object3d._primitives._arg_with_dim(right_distance)) vArg2.append("ChamferType:="), vArg2.append("Symmetric") elif chamfer_type == 1: + vArg2.append("LeftDistance:="), vArg2.append(self._object3d._primitives._arg_with_dim(left_distance)) vArg2.append("RightDistance:="), vArg2.append(self._object3d._primitives._arg_with_dim(right_distance)) vArg2.append("ChamferType:="), vArg2.append("Left Distance-Right Distance") elif chamfer_type == 2: - vArg2.append("Angle:="), vArg2.append(str(angle) + "deg") - vArg2.append("ChamferType:="), vArg2.append("Left Distance-Right Distance") + vArg2.append("LeftDistance:="), vArg2.append(self._object3d._primitives._arg_with_dim(left_distance)) + # NOTE: Seems like there is a bug in the API as Angle can't be used + vArg2.append("RightDistance:="), vArg2.append(f"{angle}deg") + vArg2.append("ChamferType:="), vArg2.append("Left Distance-Angle") elif chamfer_type == 3: - vArg2.append("LeftDistance:="), vArg2.append(str(angle) + "deg") + # NOTE: Seems like there is a bug in the API as Angle can't be used + vArg2.append("LeftDistance:="), vArg2.append(f"{angle}deg") vArg2.append("RightDistance:="), vArg2.append(self._object3d._primitives._arg_with_dim(right_distance)) vArg2.append("ChamferType:="), vArg2.append("Right Distance-Angle") else: - self._object3d.logger.error("Wrong Type Entered. Type must be integer from 0 to 3") + self._object3d.logger.error("Wrong chamfer_type provided. Value must be an integer from 0 to 3.") return False self._object3d._oeditor.Chamfer(vArg1, ["NAME:Parameters", vArg2]) if self._object3d.name in list(self._object3d._oeditor.GetObjectsInGroup("UnClassified")): diff --git a/src/ansys/aedt/core/modeler/cad/object_3d.py b/src/ansys/aedt/core/modeler/cad/object_3d.py index 364d4b56138..0872efde3ca 100644 --- a/src/ansys/aedt/core/modeler/cad/object_3d.py +++ b/src/ansys/aedt/core/modeler/cad/object_3d.py @@ -2070,24 +2070,30 @@ def chamfer(self, vertices=None, edges=None, left_distance=1, right_distance=Non vArg2 = ["NAME:ChamferParameters"] vArg2.append("Edges:="), vArg2.append(edge_id_list) vArg2.append("Vertices:="), vArg2.append(vertex_id_list) - vArg2.append("LeftDistance:="), vArg2.append(self._primitives._arg_with_dim(left_distance)) - if not right_distance: + if right_distance is None: right_distance = left_distance if chamfer_type == 0: + if left_distance != right_distance: + self.logger.error("Do not set right distance or ensure that left distance equals right distance.") + vArg2.append("LeftDistance:="), vArg2.append(self._primitives._arg_with_dim(left_distance)) vArg2.append("RightDistance:="), vArg2.append(self._primitives._arg_with_dim(right_distance)) vArg2.append("ChamferType:="), vArg2.append("Symmetric") elif chamfer_type == 1: + vArg2.append("LeftDistance:="), vArg2.append(self._primitives._arg_with_dim(left_distance)) vArg2.append("RightDistance:="), vArg2.append(self._primitives._arg_with_dim(right_distance)) vArg2.append("ChamferType:="), vArg2.append("Left Distance-Right Distance") elif chamfer_type == 2: - vArg2.append("Angle:="), vArg2.append(str(angle) + "deg") - vArg2.append("ChamferType:="), vArg2.append("Left Distance-Right Distance") + vArg2.append("LeftDistance:="), vArg2.append(self._primitives._arg_with_dim(left_distance)) + # NOTE: Seems like there is a bug in the API as Angle can't be used + vArg2.append("RightDistance:="), vArg2.append(f"{angle}deg") + vArg2.append("ChamferType:="), vArg2.append("Left Distance-Angle") elif chamfer_type == 3: - vArg2.append("LeftDistance:="), vArg2.append(str(angle) + "deg") + # NOTE: Seems like there is a bug in the API as Angle can't be used + vArg2.append("LeftDistance:="), vArg2.append(f"{angle}deg") vArg2.append("RightDistance:="), vArg2.append(self._primitives._arg_with_dim(right_distance)) vArg2.append("ChamferType:="), vArg2.append("Right Distance-Angle") else: - self.logger.error("Wrong Type Entered. Type must be integer from 0 to 3") + self.logger.error("Wrong chamfer_type provided. Value must be an integer from 0 to 3.") return False self._oeditor.Chamfer(vArg1, ["NAME:Parameters", vArg2]) if self.name in list(self._oeditor.GetObjectsInGroup("UnClassified")): diff --git a/tests/system/general/test_07_Object3D.py b/tests/system/general/test_07_Object3D.py index f40858e3a91..12965ac07bf 100644 --- a/tests/system/general/test_07_Object3D.py +++ b/tests/system/general/test_07_Object3D.py @@ -294,30 +294,73 @@ def test_09_to_boolean(self): assert not _to_boolean("f") assert not _to_boolean("no") - def test_10_chamfer(self): - initial_object = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "ChamferTest", "Copper") - object_edges = initial_object.edges - assert len(object_edges) == 12 - test = initial_object.edges[0].chamfer(left_distance=0.2) - assert test - test = initial_object.edges[1].chamfer(left_distance=0.2, right_distance=0.4, angle=34, chamfer_type=2) - assert test - test = initial_object.edges[2].chamfer(left_distance=0.2, right_distance=0.4, chamfer_type=1) - assert test - # TODO Angle as string - general refactor ! - test = initial_object.edges[6].chamfer(left_distance=1, angle=45, chamfer_type=3) - assert test - test = initial_object.edges[4].chamfer(chamfer_type=4) - assert not test - self.aedtapp.modeler.delete( - initial_object, - ) - initial_object = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "ChamferTest2", "Copper") - assert initial_object.chamfer(edges=initial_object.faces[0].edges[0], chamfer_type=3) - initial_object = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "ChamferTest3", "Copper") - assert initial_object.chamfer(edges=initial_object.faces[0].edges[0], chamfer_type=1) - initial_object = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "ChamferTest4", "Copper") - assert initial_object.chamfer(edges=initial_object.faces[2].edges[0], chamfer_type=2) + def test_10_chamfer_called_on_edge(self): + NEW_VERTICES_POSITION = [[10.0, 0.0, 3.0], [0.0, 0.0, 3.0], [0.0, 2.0, 5.0], [10.0, 2.0, 5.0]] + box = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "ChamferOnEdge", "Copper") + + # Chamfer type 0 (default) + assert not (any(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION)) + assert box.edges[0].chamfer(left_distance=2) + assert all(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION) + self.aedtapp._odesign.Undo() + + assert box.edges[0].chamfer(left_distance=2, right_distance=3) + self.aedtapp._odesign.Undo() + + # Chamfer type 1 + assert not (any(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION)) + assert box.edges[0].chamfer(left_distance=2, chamfer_type=1) + assert all(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION) + self.aedtapp._odesign.Undo() + + # Chamfer type 2 + assert not (any(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION)) + assert box.edges[0].chamfer(left_distance=2, angle=45, chamfer_type=2) + assert all(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION) + self.aedtapp._odesign.Undo() + + # Chamfer type 3 + assert not (any(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION)) + assert box.edges[0].chamfer(right_distance=2, angle=45, chamfer_type=3) + assert all(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION) + self.aedtapp._odesign.Undo() + + # Chamfer type 4 - not valid + assert not box.edges[0].chamfer(chamfer_type=4) + + def test_10_chamfer_called_on_box(self): + NEW_VERTICES_POSITION = [[10.0, 0.0, 3.0], [0.0, 0.0, 3.0], [0.0, 2.0, 5.0], [10.0, 2.0, 5.0]] + box = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "ChamferOnBox", "Copper") + + # Chamfer type 0 (default) + assert not (any(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION)) + box.chamfer(edges=box.faces[0].edges[0], left_distance=2) + assert all(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION) + self.aedtapp._odesign.Undo() + + assert box.chamfer(edges=box.faces[0].edges[0], left_distance=2, right_distance=3) + self.aedtapp._odesign.Undo() + + # Chamfer type 1 + assert not (any(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION)) + assert box.chamfer(edges=box.faces[0].edges[0], left_distance=2, chamfer_type=1) + assert all(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION) + self.aedtapp._odesign.Undo() + + # Chamfer type 2 + assert not (any(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION)) + assert box.chamfer(edges=box.faces[0].edges[0], left_distance=2, angle=45, chamfer_type=2) + assert all(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION) + self.aedtapp._odesign.Undo() + + # Chamfer type 3 + assert not (any(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION)) + assert box.chamfer(edges=box.faces[0].edges[0], right_distance=2, angle=45, chamfer_type=3) + assert all(position in (v.position for v in box.vertices) for position in NEW_VERTICES_POSITION) + self.aedtapp._odesign.Undo() + + # Chamfer type 4 - not valid + assert not box.chamfer(edges=box.faces[0].edges[0], right_distance=2, chamfer_type=4) def test_11_fillet(self): initial_object = self.aedtapp.modeler.create_box([0, 0, 0], [10, 10, 5], "FilletTest", "Copper") diff --git a/tests/system/general/test_08_Primitives3D.py b/tests/system/general/test_08_Primitives3D.py index 9fef8369acc..9261a4d9f17 100644 --- a/tests/system/general/test_08_Primitives3D.py +++ b/tests/system/general/test_08_Primitives3D.py @@ -716,20 +716,6 @@ def test_41c_get_edges_for_circuit_port(self): "MyGND", xy_plane=True, yz_plane=False, xz_plane=False, allow_perpendicular=True, tolerance=1e-6 ) - def test_42_chamfer(self): - o = self.create_copper_box(name="MyBox") - assert o.edges[0].chamfer() - self.aedtapp._odesign.Undo() - assert o.edges[0].chamfer(chamfer_type=1) - self.aedtapp._odesign.Undo() - assert o.edges[0].chamfer(chamfer_type=2) - self.aedtapp._odesign.Undo() - assert o.edges[0].chamfer(chamfer_type=3) - self.aedtapp._odesign.Undo() - assert not o.edges[0].chamfer(chamfer_type=4) - o2 = self.create_copper_box(name="MyBox2") - assert o2.chamfer(edges=o2.edges) - def test_43_fillet_and_undo(self): o = self.create_copper_box(name="MyBox") assert o.edges[0].fillet()