@ -1261,7 +1261,7 @@ class Workplane(CQ):
|
|||||||
#attempt to consolidate wires together.
|
#attempt to consolidate wires together.
|
||||||
consolidated = n.consolidateWires()
|
consolidated = n.consolidateWires()
|
||||||
|
|
||||||
rotatedWires = self.plane.rotateShapes(consolidated.wires().vals(),matrix)
|
rotatedWires = self.plane.rotateShapes(consolidated.wires().vals(), matrix)
|
||||||
|
|
||||||
for w in rotatedWires:
|
for w in rotatedWires:
|
||||||
consolidated.objects.append(w)
|
consolidated.objects.append(w)
|
||||||
@ -1269,6 +1269,7 @@ class Workplane(CQ):
|
|||||||
|
|
||||||
#attempt again to consolidate all of the wires
|
#attempt again to consolidate all of the wires
|
||||||
c = consolidated.consolidateWires()
|
c = consolidated.consolidateWires()
|
||||||
|
|
||||||
return c
|
return c
|
||||||
|
|
||||||
def mirrorY(self):
|
def mirrorY(self):
|
||||||
@ -1288,7 +1289,6 @@ class Workplane(CQ):
|
|||||||
|
|
||||||
Future Enhancements:
|
Future Enhancements:
|
||||||
mirrorX().mirrorY() should work but doesnt, due to some FreeCAD weirdness
|
mirrorX().mirrorY() should work but doesnt, due to some FreeCAD weirdness
|
||||||
|
|
||||||
"""
|
"""
|
||||||
tm = Matrix()
|
tm = Matrix()
|
||||||
tm.rotateY(math.pi)
|
tm.rotateY(math.pi)
|
||||||
@ -1307,7 +1307,6 @@ class Workplane(CQ):
|
|||||||
|
|
||||||
Future Enhancements:
|
Future Enhancements:
|
||||||
mirrorX().mirrorY() should work but doesnt, due to some FreeCAD weirdness
|
mirrorX().mirrorY() should work but doesnt, due to some FreeCAD weirdness
|
||||||
|
|
||||||
"""
|
"""
|
||||||
tm = Matrix()
|
tm = Matrix()
|
||||||
tm.rotateX(math.pi)
|
tm.rotateX(math.pi)
|
||||||
@ -1349,11 +1348,9 @@ class Workplane(CQ):
|
|||||||
If possible, a new object with the results are returned.
|
If possible, a new object with the results are returned.
|
||||||
if not possible, the wires remain separated
|
if not possible, the wires remain separated
|
||||||
|
|
||||||
FreeCAD has a bug in Part.Wire([]) which does not create wires/edges properly somtimes
|
FreeCAD has a bug in Part.Wire([]) which does not create wires/edges properly sometimes
|
||||||
Additionally, it has a bug where a profile compose of two wires ( rathre than one )
|
Additionally, it has a bug where a profile compose of two wires ( rather than one )
|
||||||
also does not work properly
|
also does not work properly. Together these are a real problem.
|
||||||
|
|
||||||
together these are a real problem.
|
|
||||||
"""
|
"""
|
||||||
wires = self.wires().vals()
|
wires = self.wires().vals()
|
||||||
if len(wires) < 2:
|
if len(wires) < 2:
|
||||||
|
@ -17,9 +17,10 @@
|
|||||||
License along with this library; If not, see <http://www.gnu.org/licenses/>
|
License along with this library; If not, see <http://www.gnu.org/licenses/>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import math,sys
|
import math
|
||||||
|
import cadquery
|
||||||
import FreeCAD
|
import FreeCAD
|
||||||
#Turns out we don't need the Part module here.
|
import Part as FreeCADPart
|
||||||
|
|
||||||
def sortWiresByBuildOrder(wireList,plane,result=[]):
|
def sortWiresByBuildOrder(wireList,plane,result=[]):
|
||||||
"""
|
"""
|
||||||
@ -403,9 +404,9 @@ class Plane:
|
|||||||
correctly.
|
correctly.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(obj,Vector):
|
if isinstance(obj, Vector):
|
||||||
return Vector(self.fG.multiply(obj.wrapped))
|
return Vector(self.fG.multiply(obj.wrapped))
|
||||||
elif isinstance(obj,Shape):
|
elif isinstance(obj, cadquery.Shape):
|
||||||
return obj.transformShape(self.rG)
|
return obj.transformShape(self.rG)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Dont know how to convert type %s to local coordinates" % str(type(obj)))
|
raise ValueError("Dont know how to convert type %s to local coordinates" % str(type(obj)))
|
||||||
@ -464,7 +465,7 @@ class Plane:
|
|||||||
newP= Plane(self.origin,newXdir,newZdir)
|
newP= Plane(self.origin,newXdir,newZdir)
|
||||||
return newP
|
return newP
|
||||||
|
|
||||||
def rotateShapes(self,listOfShapes,rotationMatrix):
|
def rotateShapes(self, listOfShapes, rotationMatrix):
|
||||||
"""
|
"""
|
||||||
rotate the listOfShapes by the rotationMatrix supplied.
|
rotate the listOfShapes by the rotationMatrix supplied.
|
||||||
@param listOfShapes is a list of shape objects
|
@param listOfShapes is a list of shape objects
|
||||||
@ -480,24 +481,42 @@ class Plane:
|
|||||||
#There might be a better way, but to do this rotation takes 3 steps
|
#There might be a better way, but to do this rotation takes 3 steps
|
||||||
#transform geometry to local coordinates
|
#transform geometry to local coordinates
|
||||||
#then rotate about x
|
#then rotate about x
|
||||||
#then transform back to global coordiante
|
#then transform back to global coordinates
|
||||||
|
|
||||||
resultWires = []
|
resultWires = []
|
||||||
for w in listOfShapes:
|
for w in listOfShapes:
|
||||||
mirrored = w.transformGeometry(rotationMatrix.wrapped)
|
mirrored = w.transformGeometry(rotationMatrix.wrapped)
|
||||||
resultWires.append(mirrored)
|
|
||||||
|
# If the first vertex of the second wire is not coincident with the first or last vertices of the first wire
|
||||||
|
# we have to fix the wire so that it will mirror correctly
|
||||||
|
if (mirrored.wrapped.Vertexes[0].X == w.wrapped.Vertexes[0].X and
|
||||||
|
mirrored.wrapped.Vertexes[0].Y == w.wrapped.Vertexes[0].Y and
|
||||||
|
mirrored.wrapped.Vertexes[0].Z == w.wrapped.Vertexes[0].Z) or \
|
||||||
|
(mirrored.wrapped.Vertexes[0].X == w.wrapped.Vertexes[-1].X and
|
||||||
|
mirrored.wrapped.Vertexes[0].Y == w.wrapped.Vertexes[-1].Y and
|
||||||
|
mirrored.wrapped.Vertexes[0].Z == w.wrapped.Vertexes[-1].Z):
|
||||||
|
|
||||||
|
resultWires.append(mirrored)
|
||||||
|
else:
|
||||||
|
# Make sure that our mirrored edges meet up and are ordered properly
|
||||||
|
aEdges = w.wrapped.Edges
|
||||||
|
aEdges.extend(mirrored.wrapped.Edges)
|
||||||
|
comp = FreeCADPart.Compound(aEdges)
|
||||||
|
mirroredWire = comp.connectEdgesToWires(False).Wires[0]
|
||||||
|
|
||||||
|
resultWires.append(cadquery.Shape.cast(mirroredWire))
|
||||||
|
|
||||||
return resultWires
|
return resultWires
|
||||||
|
|
||||||
|
|
||||||
def _calcTransforms(self):
|
def _calcTransforms(self):
|
||||||
"""
|
"""
|
||||||
Computes transformation martrices to convert betwene local and global coordinates
|
Computes transformation martrices to convert between local and global coordinates
|
||||||
"""
|
"""
|
||||||
#r is the forward transformation matrix from world to local coordinates
|
#r is the forward transformation matrix from world to local coordinates
|
||||||
#ok i will be really honest-- i cannot understand exactly why this works
|
#ok i will be really honest-- i cannot understand exactly why this works
|
||||||
#something bout the order of the transaltion and the rotation.
|
#something bout the order of the translation and the rotation.
|
||||||
# the double-inverting is strange, and i dont understand it.
|
# the double-inverting is strange, and I don't understand it.
|
||||||
r = FreeCAD.Base.Matrix()
|
r = FreeCAD.Base.Matrix()
|
||||||
|
|
||||||
#forward transform must rotate and adjust for origin
|
#forward transform must rotate and adjust for origin
|
||||||
|
@ -607,11 +607,64 @@ class TestCadQuery(BaseTest):
|
|||||||
"""
|
"""
|
||||||
Tests a simple mirroring operation
|
Tests a simple mirroring operation
|
||||||
"""
|
"""
|
||||||
s = Workplane("XY").lineTo(2,2).threePointArc((3,1),(2,0)) \
|
s = Workplane("XY").lineTo(2, 2).threePointArc((3, 1), (2, 0)) \
|
||||||
.mirrorX().extrude(0.25)
|
.mirrorX().extrude(0.25)
|
||||||
self.assertEquals(6,s.faces().size())
|
self.assertEquals(6, s.faces().size())
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
|
|
||||||
|
def testUnorderedMirror(self):
|
||||||
|
"""
|
||||||
|
Tests whether or not a wire can be mirrored if its mirror won't connect to it
|
||||||
|
"""
|
||||||
|
r = 20
|
||||||
|
s = 7
|
||||||
|
t = 1.5
|
||||||
|
|
||||||
|
points = [
|
||||||
|
(0, t/2),
|
||||||
|
(r/2-1.5*t, r/2-t),
|
||||||
|
(s/2, r/2-t),
|
||||||
|
(s/2, r/2),
|
||||||
|
(r/2, r/2),
|
||||||
|
(r/2, s/2),
|
||||||
|
(r/2-t, s/2),
|
||||||
|
(r/2-t, r/2-1.5*t),
|
||||||
|
(t/2, 0)
|
||||||
|
]
|
||||||
|
|
||||||
|
r = Workplane("XY").polyline(points).mirrorX()
|
||||||
|
|
||||||
|
self.assertEquals(1, r.wires().size())
|
||||||
|
self.assertEquals(16, r.edges().size())
|
||||||
|
|
||||||
|
# def testChainedMirror(self):
|
||||||
|
# """
|
||||||
|
# Tests whether or not calling mirrorX().mirrorY() works correctly
|
||||||
|
# """
|
||||||
|
# r = 20
|
||||||
|
# s = 7
|
||||||
|
# t = 1.5
|
||||||
|
#
|
||||||
|
# points = [
|
||||||
|
# (0, t/2),
|
||||||
|
# (r/2-1.5*t, r/2-t),
|
||||||
|
# (s/2, r/2-t),
|
||||||
|
# (s/2, r/2),
|
||||||
|
# (r/2, r/2),
|
||||||
|
# (r/2, s/2),
|
||||||
|
# (r/2-t, s/2),
|
||||||
|
# (r/2-t, r/2-1.5*t),
|
||||||
|
# (t/2, 0)
|
||||||
|
# ]
|
||||||
|
#
|
||||||
|
# r = Workplane("XY").polyline(points).mirrorX().mirrorY()
|
||||||
|
#
|
||||||
|
# self.assertEquals(1, r.wires().size())
|
||||||
|
# self.assertEquals(32, r.edges().size())
|
||||||
|
|
||||||
|
#TODO: Re-work testIbeam test below now that chaining works
|
||||||
|
#TODO: Add toLocalCoords and toWorldCoords tests
|
||||||
|
|
||||||
def testIbeam(self):
|
def testIbeam(self):
|
||||||
"""
|
"""
|
||||||
Make an ibeam. demonstrates fancy mirroring
|
Make an ibeam. demonstrates fancy mirroring
|
||||||
@ -623,44 +676,50 @@ class TestCadQuery(BaseTest):
|
|||||||
|
|
||||||
t = 1.0
|
t = 1.0
|
||||||
#TODO: for some reason doing 1/4 of the profile and mirroring twice ( .mirrorX().mirrorY() )
|
#TODO: for some reason doing 1/4 of the profile and mirroring twice ( .mirrorX().mirrorY() )
|
||||||
#did not work, due to a bug in freecad-- it was losing edges when createing a composite wire.
|
#did not work, due to a bug in freecad-- it was losing edges when creating a composite wire.
|
||||||
#i just side-stepped it for now
|
#i just side-stepped it for now
|
||||||
|
|
||||||
pts = [
|
pts = [
|
||||||
(0,H/2.0),
|
(0, H/2.0),
|
||||||
(W/2.0,H/2.0),
|
(W/2.0, H/2.0),
|
||||||
(W/2.0,(H/2.0 - t)),
|
(W/2.0, (H/2.0 - t)),
|
||||||
(t/2.0,(H/2.0-t)),
|
(t/2.0, (H/2.0-t)),
|
||||||
(t/2.0,(t - H/2.0)),
|
(t/2.0, (t - H/2.0)),
|
||||||
(W/2.0,(t -H/2.0)),
|
(W/2.0, (t - H/2.0)),
|
||||||
(W/2.0,H/-2.0),
|
(W/2.0, H / -2.0),
|
||||||
(0,H/-2.0)
|
(0, H/-2.0)
|
||||||
]
|
]
|
||||||
r = s.polyline(pts).mirrorY() #these other forms also work
|
r = s.polyline(pts).mirrorY() #these other forms also work
|
||||||
res = r.extrude(L)
|
res = r.extrude(L)
|
||||||
self.saveModel(res)
|
self.saveModel(res)
|
||||||
|
|
||||||
def testCone(self):
|
def testCone(self):
|
||||||
"test that a simple sphere works"
|
"""
|
||||||
s = Solid.makeCone(0,1.0,2.0)
|
Tests that a simple cone works
|
||||||
|
"""
|
||||||
|
s = Solid.makeCone(0, 1.0, 2.0)
|
||||||
t = CQ(s)
|
t = CQ(s)
|
||||||
self.saveModel(t)
|
self.saveModel(t)
|
||||||
self.assertEqual(2,t.faces().size())
|
self.assertEqual(2, t.faces().size())
|
||||||
|
|
||||||
def testFillet(self):
|
def testFillet(self):
|
||||||
"Tests filleting edges on a solid"
|
"""
|
||||||
|
Tests filleting edges on a solid
|
||||||
|
"""
|
||||||
c = CQ( makeUnitCube()).faces(">Z").workplane().circle(0.25).extrude(0.25,True).edges("|Z").fillet(0.2)
|
c = CQ( makeUnitCube()).faces(">Z").workplane().circle(0.25).extrude(0.25,True).edges("|Z").fillet(0.2)
|
||||||
self.saveModel(c)
|
self.saveModel(c)
|
||||||
self.assertEqual(12,c.faces().size() )
|
self.assertEqual(12,c.faces().size() )
|
||||||
|
|
||||||
def testCounterBores(self):
|
def testCounterBores(self):
|
||||||
"""Tests making a set of counterbored holes in a face"""
|
"""
|
||||||
|
Tests making a set of counterbored holes in a face
|
||||||
|
"""
|
||||||
c = CQ(makeCube(3.0))
|
c = CQ(makeCube(3.0))
|
||||||
pnts=[
|
pnts = [
|
||||||
(-1.0,-1.0),(0.0,0.0),(1.0,1.0)
|
(-1.0, -1.0), (0.0, 0.0), (1.0, 1.0)
|
||||||
]
|
]
|
||||||
c.faces(">Z").workplane().pushPoints(pnts).cboreHole(0.1,0.25,0.25,.75)
|
c.faces(">Z").workplane().pushPoints(pnts).cboreHole(0.1, 0.25, 0.25, 0.75)
|
||||||
self.assertEquals(18,c.faces().size() )
|
self.assertEquals(18, c.faces().size() )
|
||||||
self.saveModel(c)
|
self.saveModel(c)
|
||||||
|
|
||||||
def testCounterSinks(self):
|
def testCounterSinks(self):
|
||||||
@ -668,63 +727,67 @@ class TestCadQuery(BaseTest):
|
|||||||
Tests countersinks
|
Tests countersinks
|
||||||
"""
|
"""
|
||||||
s = Workplane(Plane.XY())
|
s = Workplane(Plane.XY())
|
||||||
result = s.rect(2.0,4.0).extrude(0.5).faces(">Z").workplane()\
|
result = s.rect(2.0, 4.0).extrude(0.5).faces(">Z").workplane()\
|
||||||
.rect(1.5,3.5,forConstruction=True).vertices().cskHole(0.125, 0.25,82,depth=None)
|
.rect(1.5, 3.5, forConstruction=True).vertices().cskHole(0.125, 0.25, 82, depth=None)
|
||||||
self.saveModel(result)
|
self.saveModel(result)
|
||||||
|
|
||||||
def testSplitKeepingHalf(self):
|
def testSplitKeepingHalf(self):
|
||||||
"Tests splitting a solid"
|
"""
|
||||||
|
Tests splitting a solid
|
||||||
|
"""
|
||||||
|
|
||||||
#drill a hole in the side
|
#drill a hole in the side
|
||||||
c = CQ(makeUnitCube()).faces(">Z").workplane().circle(0.25).cutThruAll()
|
c = CQ(makeUnitCube()).faces(">Z").workplane().circle(0.25).cutThruAll()
|
||||||
|
|
||||||
self.assertEqual(7,c.faces().size() )
|
self.assertEqual(7, c.faces().size())
|
||||||
|
|
||||||
#now cut it in half sideways
|
#now cut it in half sideways
|
||||||
c.faces(">Y").workplane(-0.5).split(keepTop=True)
|
c.faces(">Y").workplane(-0.5).split(keepTop=True)
|
||||||
self.saveModel(c)
|
self.saveModel(c)
|
||||||
self.assertEqual(8,c.faces().size())
|
self.assertEqual(8, c.faces().size())
|
||||||
|
|
||||||
def testSplitKeepingBoth(self):
|
def testSplitKeepingBoth(self):
|
||||||
"Tests splitting a solid"
|
"""
|
||||||
|
Tests splitting a solid
|
||||||
|
"""
|
||||||
|
|
||||||
#drill a hole in the side
|
#drill a hole in the side
|
||||||
c = CQ(makeUnitCube()).faces(">Z").workplane().circle(0.25).cutThruAll()
|
c = CQ(makeUnitCube()).faces(">Z").workplane().circle(0.25).cutThruAll()
|
||||||
self.assertEqual(7,c.faces().size() )
|
self.assertEqual(7, c.faces().size())
|
||||||
|
|
||||||
#now cut it in half sideways
|
#now cut it in half sideways
|
||||||
result = c.faces(">Y").workplane(-0.5).split(keepTop=True,keepBottom=True)
|
result = c.faces(">Y").workplane(-0.5).split(keepTop=True, keepBottom=True)
|
||||||
|
|
||||||
#stack will have both halves, original will be unchanged
|
#stack will have both halves, original will be unchanged
|
||||||
self.assertEqual(2, result.solids().size()) #two solids are on the stack, eac
|
self.assertEqual(2, result.solids().size()) # two solids are on the stack, eac
|
||||||
self.assertEqual(8,result.solids().item(0).faces().size())
|
self.assertEqual(8, result.solids().item(0).faces().size())
|
||||||
self.assertEqual(8,result.solids().item(1).faces().size())
|
self.assertEqual(8, result.solids().item(1).faces().size())
|
||||||
|
|
||||||
def testBoxDefaults(self):
|
def testBoxDefaults(self):
|
||||||
"""
|
"""
|
||||||
Tests creating a single box
|
Tests creating a single box
|
||||||
"""
|
"""
|
||||||
s = Workplane("XY").box(2,3,4)
|
s = Workplane("XY").box(2, 3, 4)
|
||||||
self.assertEquals(1,s.solids().size() )
|
self.assertEquals(1, s.solids().size())
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
|
|
||||||
def testSimpleShell(self):
|
def testSimpleShell(self):
|
||||||
"""
|
"""
|
||||||
Create s simple box
|
Create s simple box
|
||||||
"""
|
"""
|
||||||
s = Workplane("XY").box(2,2,2).faces("+Z").shell(0.05)
|
s = Workplane("XY").box(2, 2, 2).faces("+Z").shell(0.05)
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
self.assertEquals(23,s.faces().size() )
|
self.assertEquals(23, s.faces().size())
|
||||||
|
|
||||||
|
|
||||||
def testOpenCornerShell(self):
|
def testOpenCornerShell(self):
|
||||||
s = Workplane("XY").box(1,1,1)
|
s = Workplane("XY").box(1, 1, 1)
|
||||||
s1 = s.faces("+Z")
|
s1 = s.faces("+Z")
|
||||||
s1.add(s.faces("+Y")).add(s.faces("+X"))
|
s1.add(s.faces("+Y")).add(s.faces("+X"))
|
||||||
self.saveModel(s1.shell(0.2))
|
self.saveModel(s1.shell(0.2))
|
||||||
|
|
||||||
def testTopFaceFillet(self):
|
def testTopFaceFillet(self):
|
||||||
s = Workplane("XY").box(1,1,1).faces("+Z").edges().fillet(0.1)
|
s = Workplane("XY").box(1, 1, 1).faces("+Z").edges().fillet(0.1)
|
||||||
self.assertEquals(s.faces().size(), 10)
|
self.assertEquals(s.faces().size(), 10)
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
|
|
||||||
@ -732,23 +795,23 @@ class TestCadQuery(BaseTest):
|
|||||||
"""
|
"""
|
||||||
Tests creating an array of boxes
|
Tests creating an array of boxes
|
||||||
"""
|
"""
|
||||||
s = Workplane("XY").rect(4.0,4.0,forConstruction=True).vertices().box(0.25,0.25,0.25,combine=True)
|
s = Workplane("XY").rect(4.0, 4.0, forConstruction=True).vertices().box(0.25, 0.25, 0.25, combine=True)
|
||||||
#1 object, 4 solids beause the object is a compound
|
#1 object, 4 solids because the object is a compound
|
||||||
self.assertEquals(1,s.solids().size() )
|
self.assertEquals(1, s.solids().size())
|
||||||
self.assertEquals(1,s.size())
|
self.assertEquals(1, s.size())
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
|
|
||||||
s = Workplane("XY").rect(4.0,4.0,forConstruction=True).vertices().box(0.25,0.25,0.25,combine=False)
|
s = Workplane("XY").rect(4.0, 4.0, forConstruction=True).vertices().box(0.25, 0.25, 0.25, combine=False)
|
||||||
#4 objects, 4 solids, becaue each is a separate solid
|
#4 objects, 4 solids, because each is a separate solid
|
||||||
self.assertEquals(4,s.size())
|
self.assertEquals(4, s.size())
|
||||||
self.assertEquals(4,s.solids().size() )
|
self.assertEquals(4, s.solids().size())
|
||||||
|
|
||||||
def testBoxCombine(self):
|
def testBoxCombine(self):
|
||||||
s = Workplane("XY").box(4,4,0.5).faces(">Z").workplane().rect(3,3,forConstruction=True).vertices().box(0.25,0.25,0.25,combine=True)
|
s = Workplane("XY").box(4, 4, 0.5).faces(">Z").workplane().rect(3, 3, forConstruction=True).vertices().box(0.25, 0.25, 0.25, combine=True)
|
||||||
|
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
self.assertEquals(1,s.solids().size()) # we should have one big solid
|
self.assertEquals(1, s.solids().size()) # we should have one big solid
|
||||||
self.assertEquals(26,s.faces().size()) # should have 26 faces. 6 for the box, and 4x5 for the smaller cubes
|
self.assertEquals(26, s.faces().size()) # should have 26 faces. 6 for the box, and 4x5 for the smaller cubes
|
||||||
|
|
||||||
def testSphereDefaults(self):
|
def testSphereDefaults(self):
|
||||||
s = Workplane("XY").sphere(10)
|
s = Workplane("XY").sphere(10)
|
||||||
@ -775,29 +838,29 @@ class TestCadQuery(BaseTest):
|
|||||||
self.assertEquals(4, s.faces().size())
|
self.assertEquals(4, s.faces().size())
|
||||||
|
|
||||||
def testQuickStartXY(self):
|
def testQuickStartXY(self):
|
||||||
s = Workplane(Plane.XY()).box(2,4,0.5).faces(">Z").workplane().rect(1.5,3.5,forConstruction=True)\
|
s = Workplane(Plane.XY()).box(2, 4, 0.5).faces(">Z").workplane().rect(1.5, 3.5, forConstruction=True)\
|
||||||
.vertices().cskHole(0.125, 0.25,82,depth=None)
|
.vertices().cskHole(0.125, 0.25, 82, depth=None)
|
||||||
self.assertEquals(1,s.solids().size())
|
self.assertEquals(1, s.solids().size())
|
||||||
self.assertEquals(14,s.faces().size())
|
self.assertEquals(14, s.faces().size())
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
|
|
||||||
def testQuickStartYZ(self):
|
def testQuickStartYZ(self):
|
||||||
s = Workplane(Plane.YZ()).box(2,4,0.5).faces(">X").workplane().rect(1.5,3.5,forConstruction=True)\
|
s = Workplane(Plane.YZ()).box(2, 4, 0.5).faces(">X").workplane().rect(1.5, 3.5, forConstruction=True)\
|
||||||
.vertices().cskHole(0.125, 0.25,82,depth=None)
|
.vertices().cskHole(0.125, 0.25, 82, depth=None)
|
||||||
self.assertEquals(1,s.solids().size())
|
self.assertEquals(1, s.solids().size())
|
||||||
self.assertEquals(14,s.faces().size())
|
self.assertEquals(14, s.faces().size())
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
|
|
||||||
def testQuickStartXZ(self):
|
def testQuickStartXZ(self):
|
||||||
s = Workplane(Plane.XZ()).box(2,4,0.5).faces(">Y").workplane().rect(1.5,3.5,forConstruction=True)\
|
s = Workplane(Plane.XZ()).box(2, 4, 0.5).faces(">Y").workplane().rect(1.5, 3.5, forConstruction=True)\
|
||||||
.vertices().cskHole(0.125, 0.25,82,depth=None)
|
.vertices().cskHole(0.125, 0.25, 82, depth=None)
|
||||||
self.assertEquals(1,s.solids().size())
|
self.assertEquals(1, s.solids().size())
|
||||||
self.assertEquals(14,s.faces().size())
|
self.assertEquals(14, s.faces().size())
|
||||||
self.saveModel(s)
|
self.saveModel(s)
|
||||||
|
|
||||||
def testDoubleTwistedLoft(self):
|
def testDoubleTwistedLoft(self):
|
||||||
s = Workplane("XY").polygon(8,20.0).workplane(offset=4.0).transformed(rotate=Vector(0,0,15.0)).polygon(8,20).loft()
|
s = Workplane("XY").polygon(8, 20.0).workplane(offset=4.0).transformed(rotate=Vector(0, 0, 15.0)).polygon(8, 20).loft()
|
||||||
s2 = Workplane("XY").polygon(8,20.0).workplane(offset=-4.0).transformed(rotate=Vector(0,0,15.0)).polygon(8,20).loft()
|
s2 = Workplane("XY").polygon(8, 20.0).workplane(offset=-4.0).transformed(rotate=Vector(0, 0, 15.0)).polygon(8, 20).loft()
|
||||||
#self.assertEquals(10,s.faces().size())
|
#self.assertEquals(10,s.faces().size())
|
||||||
#self.assertEquals(1,s.solids().size())
|
#self.assertEquals(1,s.solids().size())
|
||||||
s3 = s.combineSolids(s2)
|
s3 = s.combineSolids(s2)
|
||||||
|
@ -3,43 +3,42 @@ import unittest
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
|
||||||
#from cadquery.freecad_impl.verutil import fc_import
|
|
||||||
#FreeCAD = fc_import("FreeCAD")
|
|
||||||
#import cadquery.freecad_impl
|
|
||||||
import FreeCAD
|
import FreeCAD
|
||||||
|
|
||||||
# P = fc_import("FreeCAD.Part")
|
|
||||||
# V = fc_import("FreeCAD").Base.Vector
|
|
||||||
|
|
||||||
import Part as P
|
import Part as P
|
||||||
from FreeCAD import Vector as V
|
from FreeCAD import Vector as V
|
||||||
|
|
||||||
|
|
||||||
def readFileAsString(fileName):
|
def readFileAsString(fileName):
|
||||||
f= open(fileName,'r')
|
f= open(fileName, 'r')
|
||||||
s = f.read()
|
s = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def writeStringToFile(strToWrite,fileName):
|
|
||||||
f = open(fileName,'w')
|
def writeStringToFile(strToWrite, fileName):
|
||||||
|
f = open(fileName, 'w')
|
||||||
f.write(strToWrite)
|
f.write(strToWrite)
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def makeUnitSquareWire():
|
def makeUnitSquareWire():
|
||||||
return Solid.cast(P.makePolygon([V(0,0,0),V(1,0,0),V(1,1,0),V(0,1,0),V(0,0,0)]))
|
return Solid.cast(P.makePolygon([V(0, 0, 0), V(1, 0, 0), V(1, 1, 0), V(0, 1, 0), V(0, 0, 0)]))
|
||||||
|
|
||||||
|
|
||||||
def makeUnitCube():
|
def makeUnitCube():
|
||||||
return makeCube(1.0)
|
return makeCube(1.0)
|
||||||
|
|
||||||
|
|
||||||
def makeCube(size):
|
def makeCube(size):
|
||||||
return Solid.makeBox(size,size,size)
|
return Solid.makeBox(size, size, size)
|
||||||
|
|
||||||
|
|
||||||
def toTuple(v):
|
def toTuple(v):
|
||||||
"convert a vector or a vertex to a 3-tuple: x,y,z"
|
"""convert a vector or a vertex to a 3-tuple: x,y,z"""
|
||||||
pnt = v
|
pnt = v
|
||||||
if type(v) == FreeCAD.Base.Vector:
|
if type(v) == FreeCAD.Base.Vector:
|
||||||
return (v.Point.x,v.Point.y,v.Point.z)
|
return (v.Point.x, v.Point.y, v.Point.z)
|
||||||
elif type(v) == Vector:
|
elif type(v) == Vector:
|
||||||
return v.toTuple()
|
return v.toTuple()
|
||||||
else:
|
else:
|
||||||
@ -48,8 +47,8 @@ def toTuple(v):
|
|||||||
|
|
||||||
class BaseTest(unittest.TestCase):
|
class BaseTest(unittest.TestCase):
|
||||||
|
|
||||||
def assertTupleAlmostEquals(self,expected,actual,places):
|
def assertTupleAlmostEquals(self, expected, actual, places):
|
||||||
for i,j in zip(actual,expected):
|
for i, j in zip(actual, expected):
|
||||||
self.assertAlmostEquals(i,j,places)
|
self.assertAlmostEquals(i, j, places)
|
||||||
|
|
||||||
__all__ = [ 'TestCadObjects','TestCadQuery','TestCQSelectors','TestWorkplanes','TestExporters','TestCQSelectors','TestImporters']
|
__all__ = ['TestCadObjects', 'TestCadQuery', 'TestCQSelectors', 'TestWorkplanes', 'TestExporters', 'TestCQSelectors', 'TestImporters']
|
||||||
|
Reference in New Issue
Block a user