Skip to content

improved remove_vertex method #861

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

Merged
merged 5 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion _unittest/test_07_Object3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ def test_14_translate_delete_self(self):
assert v1[0] == v0[0] + 1.0
assert v1[1] == v0[1]
assert v1[2] == v0[2]
assert o.move([1, 0, 0])

def test_15_duplicate_around_axis_and_unite(self):
turn = self.create_example_coil("single_turn")
Expand All @@ -344,7 +345,6 @@ def test_16_duplicate_around_axis_and_unite(self):
assert len(added_objects) == 2
assert "single_turn" in self.aedtapp.modeler.line_names

# TODO: Finish asserts anc check the boolean inputs - they are not present in the GUI ??
def test_17_section_object(self):
o = self.aedtapp.modeler.create_box([-10, 0, 0], [10, 10, 5], "SectionBox", "Copper")
o.section(plane="YZ", create_new=True, section_cross_object=False)
Expand All @@ -354,3 +354,7 @@ def test_18_create_spiral(self):
assert sp1
assert sp1.name == "ind"
assert len(sp1.points) == 78

def test_19_rotate(self):
o = self.aedtapp.modeler.create_box([-10, 0, 0], [10, 10, 5], "RotateBox", "Copper")
assert o.rotate(cs_axis="Y", angle=180)
59 changes: 58 additions & 1 deletion pyaedt/modeler/Object3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import math
import os
import re
import warnings

from pyaedt import aedt_exception_handler, _retry_ntimes
from pyaedt.modeler.GeometryOperators import GeometryOperators
Expand Down Expand Up @@ -770,6 +771,7 @@ def __init__(self, primitives, name=None):
self._part_coordinate_system = None
self._model = None

@aedt_exception_handler
def _bounding_box_unmodel(self):
"""Bounding box of a part, unmodel/undo method.

Expand Down Expand Up @@ -804,6 +806,7 @@ def _bounding_box_unmodel(self):
)
return bounding

@aedt_exception_handler
def _bounding_box_sat(self):
"""Bounding box of a part.

Expand Down Expand Up @@ -1678,6 +1681,56 @@ def unite(self, object_list):
self._primitives.modeler.unite(unite_list)
return self

@aedt_exception_handler
def rotate(self, cs_axis, angle=90.0, unit="deg"):
"""Rotate the selection.

Parameters
----------
cs_axis
Coordinate system axis or the Application.CoordinateSystemAxis object.
angle : float
Angle of rotation. The units, defined by ``unit``, can be either
degrees or radians. The default is ``90.0``.
unit : text, optional
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
unit : text, optional
unit : str, optional

Units for the angle. Options are ``"deg"`` or ``"rad"``.
The default is ``"deg"``.

Returns
-------
bool
``True`` when successful, ``False`` when failed.

References
----------

>>> oEditor.Rotate
"""
return self._primitives.modeler.rotate(self.id, cs_axis=cs_axis, angle=angle, unit=unit)

@aedt_exception_handler
def move(self, vector):
"""Move objects from a list.

Parameters
----------
objid : list, Position object
List of object IDs.
Comment on lines +1717 to +1718
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxcapodi78 I don't think it is used anymore. It seems that you use self.id now. But just to be sure.

Suggested change
objid : list, Position object
List of object IDs.

vector : list
Vector of the direction move. It can be a list of the ``[x, y, z]``
coordinates or a Position object.

Returns
-------
bool
``True`` when successful, ``False`` when failed.

References
----------
>>> oEditor.Move
"""
return self._primitives.modeler.move(self.id, vector=vector)

def duplicate_around_axis(self, cs_axis, angle=90, nclones=2, create_new_objects=True):
"""Duplicate the object around the axis.

Expand Down Expand Up @@ -1739,6 +1792,9 @@ def duplicate_along_line(self, vector, nclones=2, attachObject=False):
def translate(self, vector):
"""Translate the object and return the 3D object.

.. deprecated:: 0.4.0
Use :func:`move` instead.

Returns
-------
pyaedt.modeler.Object3d.Object3d
Expand All @@ -1750,7 +1806,8 @@ def translate(self, vector):
>>> oEditor.Move

"""
self._primitives.modeler.translate(self.id, vector)
warnings.warn("`translate` is deprecated. Use `move` instead.", DeprecationWarning)
self.move(vector)
return self

@aedt_exception_handler
Expand Down
54 changes: 35 additions & 19 deletions pyaedt/modeler/Primitives.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ def start_point(self):
object.

"""
vertex_id = self._primitives.get_object_vertices(partID=self.id)[0]
return self._primitives.get_vertex_position(vertex_id)
return self.vertices[0].position

@property
def end_point(self):
Expand All @@ -252,8 +251,7 @@ def end_point(self):
>>> oEditor.GetVertexPosition

"""
end_vertex_id = self._primitives.get_object_vertices(partID=self.id)[-1]
return self._primitives.get_vertex_position(end_vertex_id)
return self.vertices[-1].position

@property
def points(self):
Expand Down Expand Up @@ -572,24 +570,42 @@ def remove_vertex(self, position, abstol=1e-9):
>>> P.remove_vertex(["0mm", "1mm", "2mm"], abstol=1e-6)
"""
found_vertex = False

# Search for position in the vertex data
pos_xyz = self._primitives.value_in_object_units(position)
for ind, vertex_pos in enumerate(self.vertex_positions):
# compare the specified point with the vertex data using an absolute tolerance
# (default of math.isclose is 1e-9 which should be ok in almost all cases)
found_vertex = GeometryOperators.points_distance(vertex_pos, pos_xyz) <= abstol
if found_vertex:
if ind == len(self.vertex_positions) - 1:
seg_id = ind - 1
at_start = False
else:
seg_id = ind
if self._primitives._app._is_object_oriented_enabled():
obj = self._primitives._oeditor.GetChildObject(self._m_name).GetChildObject("CreatePolyline:1")
segments = obj.GetChildNames()
seg_id = 0
for seg in segments:
point = obj.GetChildObject(seg).GetPropValue("Point1")
p = self._primitives.value_in_object_units([point[1], point[3], point[5]])
pos_xyz = self._primitives.value_in_object_units(position)
found_vertex = GeometryOperators.points_distance(p, pos_xyz) <= abstol
if found_vertex:
at_start = True
break
break
point = obj.GetChildObject(seg).GetPropValue("Point2")
p = self._primitives.value_in_object_units([point[1], point[3], point[5]])
found_vertex = GeometryOperators.points_distance(p, pos_xyz) <= abstol
if found_vertex:
at_start = False
break
seg_id += 1
else: # pragma: no cover
pos_xyz = self._primitives.value_in_object_units(position)
for ind, vertex_pos in enumerate(self.vertex_positions):
# compare the specified point with the vertex data using an absolute tolerance
# (default of math.isclose is 1e-9 which should be ok in almost all cases)
found_vertex = GeometryOperators.points_distance(vertex_pos, pos_xyz) <= abstol
if found_vertex:
if ind == len(self.vertex_positions) - 1:
seg_id = ind - 1
at_start = True
else:
seg_id = ind
at_start = False
break

assert found_vertex, "Specified vertex {} not found in polyline {}.".format(position, self._m_name)
self._primitives._oeditor.DeletePolylinePoint(
self._primitives.oeditor.DeletePolylinePoint(
[
"NAME:Delete Point",
"Selections:=",
Expand Down