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: Create chamfer #5419

Merged
merged 11 commits into from
Nov 14, 2024
20 changes: 14 additions & 6 deletions src/ansys/aedt/core/modeler/cad/elements_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,24 +183,32 @@
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:

Check warning on line 186 in src/ansys/aedt/core/modeler/cad/elements_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/elements_3d.py#L186

Added line #L186 was not covered by tests
right_distance = left_distance
if chamfer_type == 0:
if left_distance != right_distance:
self._object3d.logger.error(

Check warning on line 190 in src/ansys/aedt/core/modeler/cad/elements_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/elements_3d.py#L189-L190

Added lines #L189 - L190 were not covered by tests
"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))

Check warning on line 193 in src/ansys/aedt/core/modeler/cad/elements_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/elements_3d.py#L193

Added line #L193 was not covered by tests
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))

Check warning on line 197 in src/ansys/aedt/core/modeler/cad/elements_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/elements_3d.py#L197

Added line #L197 was not covered by tests
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))

Check warning on line 201 in src/ansys/aedt/core/modeler/cad/elements_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/elements_3d.py#L201

Added line #L201 was not covered by tests
# 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")

Check warning on line 204 in src/ansys/aedt/core/modeler/cad/elements_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/elements_3d.py#L203-L204

Added lines #L203 - L204 were not covered by tests
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")

Check warning on line 207 in src/ansys/aedt/core/modeler/cad/elements_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/elements_3d.py#L207

Added line #L207 was not covered by tests
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.")

Check warning on line 211 in src/ansys/aedt/core/modeler/cad/elements_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/elements_3d.py#L211

Added line #L211 was not covered by tests
return False
self._object3d._oeditor.Chamfer(vArg1, ["NAME:Parameters", vArg2])
if self._object3d.name in list(self._object3d._oeditor.GetObjectsInGroup("UnClassified")):
Expand Down
18 changes: 12 additions & 6 deletions src/ansys/aedt/core/modeler/cad/object_3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -2070,24 +2070,30 @@
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:

Check warning on line 2073 in src/ansys/aedt/core/modeler/cad/object_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/object_3d.py#L2073

Added line #L2073 was not covered by tests
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))

Check warning on line 2078 in src/ansys/aedt/core/modeler/cad/object_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/object_3d.py#L2076-L2078

Added lines #L2076 - L2078 were not covered by tests
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))

Check warning on line 2082 in src/ansys/aedt/core/modeler/cad/object_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/object_3d.py#L2082

Added line #L2082 was not covered by tests
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))

Check warning on line 2086 in src/ansys/aedt/core/modeler/cad/object_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/object_3d.py#L2086

Added line #L2086 was not covered by tests
# NOTE: Seems like there is a bug in the API as Angle can't be used
vArg2.append("RightDistance:="), vArg2.append(f"{angle}deg")
SMoraisAnsys marked this conversation as resolved.
Show resolved Hide resolved
vArg2.append("ChamferType:="), vArg2.append("Left Distance-Angle")

Check warning on line 2089 in src/ansys/aedt/core/modeler/cad/object_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/object_3d.py#L2088-L2089

Added lines #L2088 - L2089 were not covered by tests
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")

Check warning on line 2092 in src/ansys/aedt/core/modeler/cad/object_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/object_3d.py#L2092

Added line #L2092 was not covered by tests
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.")

Check warning on line 2096 in src/ansys/aedt/core/modeler/cad/object_3d.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/aedt/core/modeler/cad/object_3d.py#L2096

Added line #L2096 was not covered by tests
return False
self._oeditor.Chamfer(vArg1, ["NAME:Parameters", vArg2])
if self.name in list(self._oeditor.GetObjectsInGroup("UnClassified")):
Expand Down
91 changes: 67 additions & 24 deletions tests/system/general/test_07_Object3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 0 additions & 14 deletions tests/system/general/test_08_Primitives3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Loading