Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
883db3c
Update shapes.py
bragostin Dec 13, 2019
3b210fe
Merge pull request #1 from bragostin/bragostin-assembledEdges
bragostin Dec 13, 2019
46c2375
Update shapes.py
bragostin Dec 15, 2019
23f2ba6
Update shapes.py
bragostin Dec 15, 2019
b19b8ff
Update shapes.py
bragostin Dec 15, 2019
a7ca48e
Add files via upload
bragostin Dec 15, 2019
fd1e959
Update shapes.py
bragostin Dec 15, 2019
80b93da
Update TestAssembleEdgesWarnings.py
bragostin Dec 16, 2019
fc4e921
Add files via upload
bragostin Dec 21, 2019
5765e24
Add files via upload
bragostin Dec 21, 2019
ef49b6f
Delete TestInterpPlate.py
bragostin Dec 21, 2019
d9893eb
Delete Ex101_InterpPlate.py
bragostin Dec 21, 2019
f9eeb12
Delete TestAssembleEdgesWarnings.py
bragostin Dec 23, 2019
bb2eb06
Add files via upload
bragostin Dec 23, 2019
9b2c8da
Update TestAssembleEdges.py
bragostin Dec 23, 2019
57c4c99
Update TestAssembleEdges.py
bragostin Dec 23, 2019
84775d4
Add files via upload
bragostin Dec 23, 2019
b0c9f1b
Add files via upload
bragostin Dec 23, 2019
e64ac5d
Delete runtests.py
bragostin Dec 24, 2019
a1df7a4
Merge pull request #2 from CadQuery/master
bragostin Dec 24, 2019
10a7299
Update test_cadquery.py
bragostin Dec 24, 2019
cdb1658
Delete TestAssembleEdges.py
bragostin Dec 24, 2019
38c3d27
Update test_cadquery.py
bragostin Dec 24, 2019
be3ad42
Update test_cadquery.py
bragostin Dec 24, 2019
81b3f57
Update test_cadquery.py
bragostin Dec 24, 2019
707dac5
Update test_cadquery.py
bragostin Dec 24, 2019
3ab5b51
Update test_cadquery.py
bragostin Dec 24, 2019
a26766a
Update test_cadquery.py
bragostin Dec 24, 2019
428a8d5
Update test_cadquery.py
bragostin Dec 24, 2019
d2c029c
Update test_cadquery.py
bragostin Dec 24, 2019
6196729
Update shapes.py
bragostin Dec 24, 2019
1d7b11b
Add files via upload
bragostin Dec 24, 2019
42c35b7
Update test_cadquery.py
bragostin Dec 25, 2019
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
22 changes: 18 additions & 4 deletions cadquery/occ_impl/shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@

from math import pi, sqrt
from functools import reduce
import warnings

TOLERANCE = 1e-6
DEG2RAD = 2 * pi / 360.
Expand Down Expand Up @@ -809,13 +810,26 @@ def assembleEdges(cls, listOfEdges):
"""
Attempts to build a wire that consists of the edges in the provided list
:param cls:
:param listOfEdges: a list of Edge objects
:param listOfEdges: a list of Edge objects. The edges are not to be consecutive.
:return: a wire with the edges assembled
:BRepBuilderAPI_MakeWire::Error() values
:BRepBuilderAPI_WireDone = 0
:BRepBuilderAPI_EmptyWire = 1
:BRepBuilderAPI_DisconnectedWire = 2
:BRepBuilderAPI_NonManifoldWire = 3
"""
wire_builder = BRepBuilderAPI_MakeWire()
for edge in listOfEdges:
wire_builder.Add(edge.wrapped)


edges_list = TopTools_ListOfShape()
for e in listOfEdges:
edges_list.Append(e.wrapped)
wire_builder.Add(edges_list)
if wire_builder.Error()!=0:
w1 = 'BRepBuilderAPI_MakeWire::IsDone(): returns true if this algorithm contains a valid wire. IsDone returns false if: there are no edges in the wire, or the last edge which you tried to add was not connectable = '+ str(wire_builder.IsDone())
w2 = 'BRepBuilderAPI_MakeWire::Error(): returns the construction status. BRepBuilderAPI_WireDone if the wire is built, or another value of the BRepBuilderAPI_WireError enumeration indicating why the construction failed = ' + str(wire_builder.Error())
warnings.warn(w1)
warnings.warn(w2)

return cls(wire_builder.Wire())

@classmethod
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ def assertTupleAlmostEquals(self, expected, actual, places):
'TestImporters',
'TestJupyter',
'TestWorkplanes',
'TestAssembleEdges',
]
37 changes: 37 additions & 0 deletions tests/test_cadquery.py
Original file line number Diff line number Diff line change
Expand Up @@ -2139,3 +2139,40 @@ def testSlot2D(self):
point = result.faces(">Z").edges(">X").first().val().startPoint().toTuple()
self.assertTupleAlmostEquals(point, (0.707106781, 1.414213562, 1.0), decimal_places)

def test_assembleEdges(self):

# Plate with 5 sides and 2 bumps, one side is not co-planar with the other sides
# Passes an open wire to assembleEdges so that IsDone is true but Error returns 2 to test the warning functionality.
edge_points = [[-7.,-7.,0.], [-3.,-10.,3.], [7.,-7.,0.], [7.,7.,0.], [-7.,7.,0.]]
edge_wire = Workplane('XY').polyline([(-7.,-7.), (7.,-7.), (7.,7.), (-7.,7.)])
edge_wire = edge_wire.add(Workplane('YZ').workplane().transformed(offset=Vector(0, 0, -7), rotate=Vector(0, 45, 0)).spline([(-7.,0.), (3,-3), (7.,0.)]))
edge_wire = [o.vals()[0] for o in edge_wire.all()]
edge_wire = Wire.assembleEdges(edge_wire)

# Embossed star, need to change optional parameters to obtain nice looking result.
r1=3.
r2=10.
fn=6
edge_points = [[r1*math.cos(i * math.pi/fn), r1*math.sin(i * math.pi/fn)] if i%2==0 else [r2*math.cos(i * math.pi/fn), r2*math.sin(i * math.pi/fn)] for i in range(2*fn+1)]
edge_wire = Workplane('XY').polyline(edge_points)
edge_wire = [o.vals()[0] for o in edge_wire.all()]
edge_wire = Wire.assembleEdges(edge_wire)

# Points on hexagonal pattern coordinates, use of pushpoints.
r1 = 1.
fn = 6
edge_points = [[r1*math.cos(i * 2*math.pi/fn), r1*math.sin(i * 2*math.pi/fn)] for i in range(fn+1)]
surface_points = [[0.25,0,0.75], [-0.25,0,0.75], [0,0.25,0.75], [0,-0.25,0.75], [0,0,2]]
edge_wire = Workplane('XY').polyline(edge_points)
edge_wire = [o.vals()[0] for o in edge_wire.all()]
edge_wire = Wire.assembleEdges(edge_wire)

# Gyroïd, all edges are splines on different workplanes.
edge_points = [[[3.54, 3.54], [1.77, 0.0], [3.54, -3.54]], [[-3.54, -3.54], [0.0, -1.77], [3.54, -3.54]], [[-3.54, -3.54], [0.0, -1.77], [3.54, -3.54]], [[-3.54, -3.54], [-1.77, 0.0], [-3.54, 3.54]], [[3.54, 3.54], [0.0, 1.77], [-3.54, 3.54]], [[3.54, 3.54], [0.0, 1.77], [-3.54, 3.54]]]
plane_list = ['XZ', 'XY', 'YZ', 'XZ', 'YZ', 'XY']
offset_list = [-3.54, 3.54, 3.54, 3.54, -3.54, -3.54]
edge_wire = Workplane(plane_list[0]).workplane(offset=-offset_list[0]).spline(edge_points[0])
for i in range(len(edge_points)-1):
edge_wire = edge_wire.add(Workplane(plane_list[i+1]).workplane(offset=-offset_list[i+1]).spline(edge_points[i+1]))
edge_wire = [o.vals()[0] for o in edge_wire.all()]
edge_wire = Wire.assembleEdges(edge_wire)