23
import FreeCAD, unittest, Part
26
from FreeCAD import Units
27
from FreeCAD import Base
30
from parttests.BRep_tests import BRepTests
31
from parttests.Geom2d_tests import Geom2dTests
32
from parttests.regression_tests import RegressionTests
33
from parttests.TopoShapeListTest import TopoShapeListTest
34
from parttests.TopoShapeTest import TopoShapeTest
39
def getCoincidentVertexes(vtx1, vtx2):
41
tol = Part.Precision.confusion()
44
if i.Point.distanceToPoint(j.Point) < tol:
50
class PartTestCases(unittest.TestCase):
52
self.Doc = FreeCAD.newDocument("PartTest")
54
def testBoxCase(self):
55
self.Box = self.Doc.addObject("Part::Box","Box")
57
self.assertEqual(len(self.Box.Shape.Faces), 6)
59
def testIssue2985(self):
60
v1 = App.Vector(0.0,0.0,0.0)
61
v2 = App.Vector(10.0,0.0,0.0)
62
v3 = App.Vector(10.0,0.0,10.0)
63
v4 = App.Vector(0.0,0.0,10.0)
64
edge1 = Part.makeLine(v1, v2)
65
edge2 = Part.makeLine(v2, v3)
66
edge3 = Part.makeLine(v3, v4)
67
edge4 = Part.makeLine(v4, v1)
75
FreeCAD.closeDocument("PartTest")
78
class PartTestBSplineCurve(unittest.TestCase):
80
self.Doc = FreeCAD.newDocument("PartTest")
82
poles = [[0, 0, 0], [1, 1, 0], [2, 0, 0]]
83
self.spline = Part.BSplineCurve()
84
self.spline.buildFromPoles(poles)
86
poles = [[0, 0, 0], [1, 1, 0], [2, 0, 0], [1, -1, 0]]
87
self.nurbs = Part.BSplineCurve()
88
self.nurbs.buildFromPolesMultsKnots(poles, (3, 1, 3),(0, 0.5, 1), False, 2)
90
def testProperties(self):
91
self.assertEqual(self.spline.Continuity, 'CN')
92
self.assertEqual(self.spline.Degree, 2)
93
self.assertEqual(self.spline.EndPoint, App.Vector(2, 0, 0))
94
self.assertEqual(self.spline.FirstParameter, 0.0)
95
self.assertEqual(self.spline.FirstUKnotIndex, 1)
96
self.assertEqual(self.spline.KnotSequence, [0.0, 0.0, 0.0, 1.0, 1.0, 1.0])
97
self.assertEqual(self.spline.LastParameter, 1.0)
98
self.assertEqual(self.spline.LastUKnotIndex, 2)
99
max_degree = self.spline.MaxDegree
100
self.assertEqual(self.spline.NbKnots, 2)
101
self.assertEqual(self.spline.NbPoles, 3)
102
self.assertEqual(self.spline.StartPoint, App.Vector(0.0, 0.0, 0.0))
104
def testGetters(self):
105
'''only check if the function doesn't crash'''
106
self.spline.getKnot(1)
107
self.spline.getKnots()
108
self.spline.getMultiplicities()
109
self.spline.getMultiplicity(1)
110
self.spline.getPole(1)
111
self.spline.getPoles()
112
self.spline.getPolesAndWeights()
113
self.spline.getResolution(0.5)
114
self.spline.getWeight(1)
115
self.spline.getWeights()
117
def testSetters(self):
118
spline = copy.copy(self.spline)
119
spline.setKnot(1, 0.1)
121
spline.setNotPeriodic()
124
self.spline.setPole(1, App.Vector([1, 0, 0]))
126
def testIssue2671(self):
127
self.Doc = App.newDocument("Issue2671")
128
Box = self.Doc.addObject("Part::Box","Box")
129
Mirroring = self.Doc.addObject("Part::Mirroring", 'Mirroring')
130
Spreadsheet = self.Doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
131
Mirroring.Source = Box
132
Mirroring.Base = (8, 5, 25)
133
Mirroring.Normal = (0.5, 0.2, 0.9)
134
Spreadsheet.set('A1', '=Mirroring.Base.x')
135
Spreadsheet.set('B1', '=Mirroring.Base.y')
136
Spreadsheet.set('C1', '=Mirroring.Base.z')
137
Spreadsheet.set('A2', '=Mirroring.Normal.x')
138
Spreadsheet.set('B2', '=Mirroring.Normal.y')
139
Spreadsheet.set('C2', '=Mirroring.Normal.z')
141
self.assertEqual(Spreadsheet.A1, Units.Quantity('8 mm'))
142
self.assertEqual(Spreadsheet.B1, Units.Quantity('5 mm'))
143
self.assertEqual(Spreadsheet.C1, Units.Quantity('25 mm'))
144
self.assertEqual(Spreadsheet.A2, Units.Quantity('0.5 mm'))
145
self.assertEqual(Spreadsheet.B2, Units.Quantity('0.2 mm'))
146
self.assertEqual(Spreadsheet.C2, Units.Quantity('0.9 mm'))
147
App.closeDocument("Issue2671")
149
def testIssue2876(self):
150
self.Doc = App.newDocument("Issue2876")
151
Cylinder = self.Doc.addObject("Part::Cylinder", "Cylinder")
153
Pipe = self.Doc.addObject("Part::Thickness", "Pipe")
154
Pipe.Faces = (Cylinder, ["Face2", "Face3"])
157
Spreadsheet = self.Doc.addObject('Spreadsheet::Sheet', 'Spreadsheet')
158
Spreadsheet.set('A1', 'Pipe OD')
159
Spreadsheet.set('B1', 'Pipe WT')
160
Spreadsheet.set('C1', 'Pipe ID')
161
Spreadsheet.set('A2', '=2*Cylinder.Radius')
162
Spreadsheet.set('B2', '=-Pipe.Value')
163
Spreadsheet.set('C2', '=2*(Cylinder.Radius + Pipe.Value)')
165
self.assertEqual(Spreadsheet.B2, Units.Quantity('1 mm'))
166
self.assertEqual(Spreadsheet.C2, Units.Quantity('8 mm'))
167
App.closeDocument("Issue2876")
169
def testSubElements(self):
170
box = Part.makeBox(1, 1, 1)
171
with self.assertRaises(ValueError):
172
box.getElement("InvalidName")
173
with self.assertRaises(ValueError):
174
box.getElement("Face6_abc")
177
with self.assertRaises(IndexError):
178
box.getElement("Face7")
182
FreeCAD.closeDocument("PartTest")
184
class PartTestCurveToNurbs(unittest.TestCase):
185
def testCircleToNurbs(self):
191
circle = Part.Circle()
194
circle.transform(mat)
195
nurbs = circle.toNurbs()
196
self.assertEqual(circle.value(0), nurbs.value(0))
198
arc = circle.trim(0, 2)
199
nurbs = arc.toNurbs()
200
self.assertEqual(circle.value(0), nurbs.value(0))
202
spline = circle.toBSpline()
203
self.assertAlmostEqual(circle.value(0).distanceToPoint(spline.value(0)), 0)
205
def testEllipseToNurbs(self):
211
ellipse = Part.Ellipse()
212
ellipse.MajorRadius = 5
213
ellipse.MinorRadius = 3
215
ellipse.transform(mat)
216
nurbs = ellipse.toNurbs()
217
self.assertEqual(ellipse.value(0), nurbs.value(0))
219
arc = ellipse.trim(0, 2)
220
nurbs = arc.toNurbs()
221
self.assertEqual(ellipse.value(0), nurbs.value(0))
223
spline = ellipse.toBSpline()
224
self.assertAlmostEqual(ellipse.value(0).distanceToPoint(spline.value(0)), 0)
226
class PartTestBSplineSurface(unittest.TestCase):
227
def testTorusToSpline(self):
232
self.assertGreater(len(bs.UKnotSequence), 0)
233
self.assertGreater(len(bs.VKnotSequence), 0)
235
def testBounds(self):
238
self.assertAlmostEqual(bs.bounds()[1], 2 * math.pi)
239
self.assertAlmostEqual(bs.bounds()[3], 2 * math.pi)
240
bs.scaleKnotsToBounds(0.0, 1.0, 0.0, 1.0)
241
self.assertAlmostEqual(bs.bounds()[1], 1.0)
242
self.assertAlmostEqual(bs.bounds()[3], 1.0)
244
class PartTestNormals(unittest.TestCase):
246
self.face = Part.makePlane(1, 1)
248
def testFaceNormal(self):
249
self.assertEqual(self.face.normalAt(0, 0), Base.Vector(0, 0, 1))
250
self.assertEqual(self.face.Surface.normal(0, 0), Base.Vector(0, 0, 1))
252
def testReverseOrientation(self):
254
self.assertEqual(self.face.normalAt(0, 0), Base.Vector(0, 0, -1))
255
self.assertEqual(self.face.Surface.normal(0, 0), Base.Vector(0, 0, 1))
257
def testPlacement(self):
259
self.face.Placement.Rotation.Angle = 1
260
self.face.Placement.Rotation.Axis = (1,1,1)
261
vec = Base.Vector(-0.63905, 0.33259, -0.69353)
262
self.assertGreater(self.face.normalAt(0, 0).dot(vec), 0.9999)
263
self.assertLess(self.face.Surface.normal(0, 0).dot(vec), -0.9999)
268
class PartTestShapeRotate(unittest.TestCase):
269
def testPlacement(self):
272
box = Part.makeBox(1, 1, 1)
273
box.Placement.Base = Base.Vector(10, 10, 10)
274
box.rotate((0, 0, 0), (0, 0, 1), 90)
276
p1 = Base.Placement()
277
p1.Base = Base.Vector(10, 10, 10)
279
p2 = Base.Placement()
280
p2.Rotation.Angle = math.radians(90)
281
self.assertTrue(box.Placement.isSame(p2 * p1, tol))
284
p3.rotate((0, 0, 0), (0, 0, 1), 90)
285
self.assertTrue(p3.isSame(p1 * p2, tol))
286
self.assertFalse(box.Placement.isSame(p3, tol))
289
p4.rotate((0, 0, 0), (0, 0, 1), 90, True)
290
self.assertTrue(p4.isSame(p2 * p1, tol))
291
self.assertTrue(box.Placement.isSame(p4, tol))
293
class PartTestCircle2D(unittest.TestCase):
294
def testValidCircle(self):
295
p1 = App.Base.Vector2d(0.01, 0.01)
296
p2 = App.Base.Vector2d(0.02, 0.02)
297
p3 = App.Base.Vector2d(0.01, -0.01)
298
Part.Geom2d.Circle2d.getCircleCenter(p1, p2, p3)
300
def testCollinearPoints(self):
301
p1 = App.Base.Vector2d(0.01, 0.01)
302
p2 = App.Base.Vector2d(0.02, 0.02)
303
p3 = App.Base.Vector2d(0.04, 0.0399)
304
with self.assertRaises(ValueError):
305
Part.Geom2d.Circle2d.getCircleCenter(p1, p2, p3)
307
class PartTestCone(unittest.TestCase):
308
def testderivatives(self):
309
def get_dn(surface, u, v):
310
pos = surface.value(u, v)
311
v10 = surface.getDN(u, v, 1, 0)
312
v01 = surface.getDN(u, v, 0, 1)
313
v11 = surface.getDN(u, v, 1, 1)
314
return (pos, v10, v01, v11)
321
vp, v1, v2, v3 = get_dn(cone, u, v)
323
shape = cone.toShape(0, 2*math.pi, 0, 10)
324
shape = shape.toNurbs()
325
spline = shape.Face1.Surface
327
u, v = spline.parameter(vp)
328
wp, w1, w2, w3 = get_dn(spline, u, v)
330
self.assertAlmostEqual(vp.distanceToPoint(wp), 0)
331
self.assertAlmostEqual(v1.getAngle(w1), 0)
332
self.assertAlmostEqual(v2.getAngle(w2), 0)
333
self.assertAlmostEqual(v3.getAngle(w3), 0)
335
class PartTestChFi2dAlgos(unittest.TestCase):
336
def testChFi2d_FilletAlgo(self):
338
edge1 = Part.makeLine(v(0,0,0), v(0,10,0))
339
edge2 = Part.makeLine(v(0,10,0), v(10,10,0))
340
wire = Part.Wire([edge1, edge2])
343
with self.assertRaises(TypeError):
344
alg = Part.ChFi2d.FilletAlgo(pln)
346
alg = Part.ChFi2d.FilletAlgo()
347
with self.assertRaises(TypeError):
352
with self.assertRaises(Base.CADKernelError):
355
with self.assertRaises(TypeError):
358
alg = Part.ChFi2d.FilletAlgo(wire, pln)
359
alg.init(edge1, edge2, pln)
362
alg = Part.ChFi2d.FilletAlgo(edge1, edge2, pln)
365
with self.assertRaises(TypeError):
366
alg.numberOfResults()
368
with self.assertRaises(TypeError):
371
self.assertEqual(alg.numberOfResults(Base.Vector(0,10,0)), 1)
372
result = alg.result(Base.Vector(0,10,0))
373
curve = result[0].Curve
374
self.assertEqual(type(curve), Part.Circle)
375
self.assertEqual(curve.Axis, pln.Axis)
376
self.assertEqual(curve.Radius, 1.0)
378
def testChFi2d_AnaFilletAlgo(self):
380
edge1 = Part.makeLine(v(0,0,0), v(0,10,0))
381
edge2 = Part.makeLine(v(0,10,0), v(10,10,0))
382
wire = Part.Wire([edge1, edge2])
385
with self.assertRaises(TypeError):
386
alg = Part.ChFi2d.AnaFilletAlgo(pln)
388
alg = Part.ChFi2d.AnaFilletAlgo()
389
with self.assertRaises(TypeError):
394
self.assertFalse(alg.perform(1))
396
with self.assertRaises(TypeError):
399
alg = Part.ChFi2d.AnaFilletAlgo(wire, pln)
400
alg.init(edge1, edge2, pln)
403
alg = Part.ChFi2d.AnaFilletAlgo(edge1, edge2, pln)
406
with self.assertRaises(TypeError):
409
result = alg.result()
410
curve = result[0].Curve
411
self.assertEqual(type(curve), Part.Circle)
412
self.assertEqual(curve.Radius, 1.0)
414
def testChFi2d_ChamferAPI(self):
416
edge1 = Part.makeLine(v(0,0,0), v(0,10,0))
417
edge2 = Part.makeLine(v(0,10,0), v(10,10,0))
418
wire = Part.Wire([edge1, edge2])
420
with self.assertRaises(TypeError):
421
alg = Part.ChFi2d.ChamferAPI(edge1)
423
alg = Part.ChFi2d.ChamferAPI(wire)
424
with self.assertRaises(TypeError):
429
with self.assertRaises(TypeError):
432
alg = Part.ChFi2d.ChamferAPI(wire)
433
alg.init(edge1, edge2)
436
alg = Part.ChFi2d.ChamferAPI(edge1, edge2)
439
with self.assertRaises(TypeError):
442
result = alg.result(1.0, 1.0)
443
curve = result[0].Curve
444
self.assertEqual(type(curve), Part.Line)
446
class PartTestRuledSurface(unittest.TestCase):
448
self.Doc = FreeCAD.newDocument()
450
def testRuledSurfaceFromTwoObjects(self):
451
line1 = Part.makeLine(FreeCAD.Vector(-70,-30,0), FreeCAD.Vector(-50,40,0))
452
line2 = Part.makeLine(FreeCAD.Vector(-40,-30,0), FreeCAD.Vector(-40,10,0))
453
plm1 = FreeCAD.Placement()
454
plm1.Rotation = FreeCAD.Rotation(0.7071067811865476, 0.0, 0.0, 0.7071067811865475)
455
line1.Placement = plm1
456
fea1 = self.Doc.addObject("Part::Feature")
457
fea2 = self.Doc.addObject("Part::Feature")
460
ruled = self.Doc.addObject("Part::RuledSurface")
466
same1 = getCoincidentVertexes(fea1.Shape.Vertexes, ruled.Shape.Vertexes)
467
same2 = getCoincidentVertexes(fea2.Shape.Vertexes, ruled.Shape.Vertexes)
468
self.assertEqual(len(same1), 2)
469
self.assertEqual(len(same2), 2)
471
def testRuledSurfaceFromTwoObjectsWithSharedVertexs(self):
472
"""Test reproducing issue #15539"""
475
line = Part.makeLine(FreeCAD.Vector(0, 0, 50), FreeCAD.Vector(0, -50, 0))
476
line1 = Part.makeLine(FreeCAD.Vector(0, 0, 50), FreeCAD.Vector(50, 0, 0))
477
line2 = Part.makeLine(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(0, -50, 0))
478
line3 = Part.makeLine(FreeCAD.Vector(0, 0, 0), FreeCAD.Vector(50, 0, 0))
479
fea = self.Doc.addObject("Part::Feature")
480
fea1 = self.Doc.addObject("Part::Feature")
481
fea2 = self.Doc.addObject("Part::Feature")
482
fea3 = self.Doc.addObject("Part::Feature")
489
ruled = self.Doc.addObject("Part::RuledSurface")
493
ruled1 = self.Doc.addObject("Part::RuledSurface")
497
ruled2 = self.Doc.addObject("Part::RuledSurface")
501
ruled3 = self.Doc.addObject("Part::RuledSurface")
509
same00 = getCoincidentVertexes(fea.Shape.Vertexes, ruled.Shape.Vertexes)
510
same03 = getCoincidentVertexes(fea.Shape.Vertexes, ruled3.Shape.Vertexes)
511
same10 = getCoincidentVertexes(fea1.Shape.Vertexes, ruled.Shape.Vertexes)
512
same11 = getCoincidentVertexes(fea1.Shape.Vertexes, ruled1.Shape.Vertexes)
513
same22 = getCoincidentVertexes(fea2.Shape.Vertexes, ruled2.Shape.Vertexes)
514
same23 = getCoincidentVertexes(fea2.Shape.Vertexes, ruled3.Shape.Vertexes)
515
same31 = getCoincidentVertexes(fea3.Shape.Vertexes, ruled1.Shape.Vertexes)
516
same32 = getCoincidentVertexes(fea3.Shape.Vertexes, ruled2.Shape.Vertexes)
520
self.assertEqual(len(same00), 3)
521
self.assertEqual(len(same03), 3)
522
self.assertEqual(len(same10), 3)
523
self.assertEqual(len(same11), 3)
524
self.assertEqual(len(same22), 3)
525
self.assertEqual(len(same23), 3)
526
self.assertEqual(len(same31), 3)
527
self.assertEqual(len(same32), 3)
529
def testRuledSurfaceFromOneObject(self):
530
sketch = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
531
sketch.Placement = FreeCAD.Placement(FreeCAD.Vector(0.000000, 0.000000, 0.000000), App.Rotation(0.707107, 0.000000, 0.000000, 0.707107))
532
sketch.MapMode = "Deactivated"
534
sketch.addGeometry(Part.LineSegment(App.Vector(-43.475811,34.364464,0),App.Vector(-65.860519,-20.078733,0)),False)
535
sketch.addGeometry(Part.LineSegment(App.Vector(14.004498,27.390331,0),App.Vector(33.577049,-27.952749,0)),False)
537
ruled = self.Doc.addObject('Part::RuledSurface', 'Ruled Surface')
538
ruled.Curve1 = (sketch,['Edge1'])
539
ruled.Curve2 = (sketch,['Edge2'])
542
same = getCoincidentVertexes(sketch.Shape.Vertexes, ruled.Shape.Vertexes)
543
self.assertEqual(len(same), 4)
546
FreeCAD.closeDocument(self.Doc.Name)
548
class PartTestShapeFix(unittest.TestCase):
549
def testShapeFix_Root(self):
550
with self.assertRaises(TypeError):
551
Part.ShapeFix.Root([])
553
fix = Part.ShapeFix.Root()
557
self.assertEqual(fix.Precision, 0.0)
559
fix.MinTolerance = 0.0
560
self.assertEqual(fix.MinTolerance, 0.0)
562
fix.MaxTolerance = 0.5
563
self.assertEqual(fix.MaxTolerance, 0.5)
565
self.assertEqual(fix.limitTolerance(0.25), 0.25)
567
def testShapeFix_Shape(self):
568
surface = Part.Plane()
569
face = surface.toShape(-1, 1, -1, 1)
571
with self.assertRaises(TypeError):
572
Part.ShapeFix.Shape([])
574
fix = Part.ShapeFix.Shape(face)
584
fix.FixSolidMode = True
585
self.assertEqual(fix.FixSolidMode, True)
587
fix.FixFreeShellMode = True
588
self.assertEqual(fix.FixFreeShellMode, True)
590
fix.FixFreeFaceMode = True
591
self.assertEqual(fix.FixFreeFaceMode, True)
593
fix.FixFreeWireMode = True
594
self.assertEqual(fix.FixFreeWireMode, True)
596
fix.FixSameParameterMode = True
597
self.assertEqual(fix.FixSameParameterMode, True)
599
fix.FixVertexPositionMode = True
600
self.assertEqual(fix.FixVertexPositionMode, True)
602
fix.FixVertexTolMode = True
603
self.assertEqual(fix.FixVertexTolMode, True)
607
def testShapeFix_Edge(self):
608
surface = Part.Plane()
609
face = surface.toShape(-1, 1, -1, 1)
611
with self.assertRaises(TypeError):
612
Part.ShapeFix.Edge([])
614
wirefix = Part.ShapeFix.Wire(face.OuterWire, face, 1e-7)
615
fix = wirefix.fixEdgeTool()
618
fix.fixRemovePCurve(face.Edge1, face)
619
fix.fixRemovePCurve(face.Edge1, face.Surface, face.Placement)
620
with self.assertRaises(TypeError):
621
fix.fixRemovePCurve(face)
623
fix.fixRemoveCurve3d(face.Edge1)
624
fix.fixAddCurve3d(face.Edge1)
626
fix.fixAddPCurve(face.Edge1, face, False)
627
fix.fixAddPCurve(face.Edge1, face.Surface, face.Placement, False)
628
with self.assertRaises(TypeError):
629
fix.fixAddPCurve(face)
631
fix.fixVertexTolerance(face.Edge1)
632
fix.fixVertexTolerance(face.Edge1, face)
634
fix.fixReversed2d(face.Edge1, face)
635
fix.fixReversed2d(face.Edge1, face.Surface, face.Placement)
636
with self.assertRaises(TypeError):
637
fix.fixReversed2d(face)
639
fix.fixSameParameter(face.Edge1)
640
fix.fixSameParameter(face.Edge1, face)
641
with self.assertRaises(TypeError):
642
fix.fixSameParameter(face)
644
def testShapeFix_Face(self):
645
surface = Part.Plane()
646
face = surface.toShape(-1, 1, -1, 1)
649
Part.ShapeFix.Face(surface, 0.00001, True)
650
with self.assertRaises(TypeError):
651
Part.ShapeFix.Face([])
653
fix = Part.ShapeFix.Face(face)
657
fix.fixAddNaturalBound()
659
fix.fixSmallAreaWire(True)
661
fix.fixIntersectingWires()
662
fix.fixWiresTwoCoincidentEdges()
663
fix.fixPeriodicDegenerated()
666
fix.add(face.OuterWire)
668
result = fix.result()
671
fix.FixWireMode = True
672
self.assertEqual(fix.FixWireMode, True)
674
fix.FixOrientationMode = True
675
self.assertEqual(fix.FixOrientationMode, True)
677
fix.FixAddNaturalBoundMode = True
678
self.assertEqual(fix.FixAddNaturalBoundMode, True)
680
fix.FixMissingSeamMode = True
681
self.assertEqual(fix.FixMissingSeamMode, True)
683
fix.FixSmallAreaWireMode = True
684
self.assertEqual(fix.FixSmallAreaWireMode, True)
686
fix.RemoveSmallAreaFaceMode = True
687
self.assertEqual(fix.RemoveSmallAreaFaceMode, True)
689
fix.FixIntersectingWiresMode = True
690
self.assertEqual(fix.FixIntersectingWiresMode, True)
692
fix.FixLoopWiresMode = True
693
self.assertEqual(fix.FixLoopWiresMode, True)
695
fix.FixSplitFaceMode = True
696
self.assertEqual(fix.FixSplitFaceMode, True)
698
fix.AutoCorrectPrecisionMode = True
699
self.assertEqual(fix.AutoCorrectPrecisionMode, True)
701
fix.FixPeriodicDegeneratedMode = True
702
self.assertEqual(fix.FixPeriodicDegeneratedMode, True)
706
def testShapeFix_Shell(self):
707
surface = Part.Plane()
708
face = surface.toShape(-1, 1, -1, 1)
709
shell = Part.Shell([face])
711
Part.ShapeFix.Shell()
712
with self.assertRaises(TypeError):
713
Part.ShapeFix.Face([])
715
fix = Part.ShapeFix.Shell(shell)
723
fix.setNonManifoldFlag(True)
724
fix.fixFaceOrientation(shell)
726
self.assertEqual(len(fix.errorFaces().Faces), 0)
728
self.assertEqual(fix.numberOfShells(), 1)
730
fix.FixFaceMode = True
731
self.assertEqual(fix.FixFaceMode, True)
733
fix.FixOrientationMode = True
734
self.assertEqual(fix.FixOrientationMode, True)
736
def testShapeFix_Solid(self):
737
box = Part.makeBox(1, 1, 1)
738
with self.assertRaises(TypeError):
739
Part.ShapeFix.Solid([])
741
fix = Part.ShapeFix.Solid()
749
fix.solidFromShell(box.Shells[0])
751
fix.FixShellMode = True
752
self.assertEqual(fix.FixShellMode, True)
754
fix.FixShellOrientationMode = True
755
self.assertEqual(fix.FixShellOrientationMode, True)
757
fix.CreateOpenSolidMode = True
758
self.assertEqual(fix.CreateOpenSolidMode, True)
760
def testShapeFix_Wire(self):
761
with self.assertRaises(TypeError):
762
Part.ShapeFix.Wire([])
764
surface = Part.Plane()
765
face = surface.toShape(-1, 1, -1, 1)
766
Part.ShapeFix.Wire(face.OuterWire, face, 1e-7)
767
fix = Part.ShapeFix.Wire()
768
fix.init(face.OuterWire, face, 1e-7)
769
fix.load(face.OuterWire)
770
fix.setSurface(surface)
771
fix.setSurface(surface, face.Placement)
773
fix.setMaxTailAngle(math.pi)
774
fix.setMaxTailWidth(10.0)
777
self.assertEqual(fix.isLoaded(), True)
778
self.assertEqual(fix.isReady(), True)
779
self.assertEqual(fix.numberOfEdges(), 4)
789
fix.ModifyTopologyMode = True
790
self.assertEqual(fix.ModifyTopologyMode, True)
792
fix.ModifyGeometryMode = True
793
self.assertEqual(fix.ModifyGeometryMode, True)
795
fix.ModifyRemoveLoopMode = True
796
self.assertEqual(fix.ModifyRemoveLoopMode, True)
798
fix.ClosedWireMode = True
799
self.assertEqual(fix.ClosedWireMode, True)
801
fix.PreferencePCurveMode = True
802
self.assertEqual(fix.PreferencePCurveMode, True)
804
fix.FixGapsByRangesMode = True
805
self.assertEqual(fix.FixGapsByRangesMode, True)
807
fix.FixReorderMode = True
808
self.assertEqual(fix.FixReorderMode, True)
810
fix.FixSmallMode = True
811
self.assertEqual(fix.FixSmallMode, True)
813
fix.FixConnectedMode = True
814
self.assertEqual(fix.FixConnectedMode, True)
816
fix.FixEdgeCurvesMode = True
817
self.assertEqual(fix.FixEdgeCurvesMode, True)
819
fix.FixDegeneratedMode = True
820
self.assertEqual(fix.FixDegeneratedMode, True)
822
fix.FixSelfIntersectionMode = True
823
self.assertEqual(fix.FixSelfIntersectionMode, True)
825
fix.FixLackingMode = True
826
self.assertEqual(fix.FixLackingMode, True)
828
fix.FixGaps3dMode = True
829
self.assertEqual(fix.FixGaps3dMode, True)
831
fix.FixGaps2dMode = True
832
self.assertEqual(fix.FixGaps2dMode, True)
834
fix.FixReversed2dMode = True
835
self.assertEqual(fix.FixReversed2dMode, True)
837
fix.FixRemovePCurveMode = True
838
self.assertEqual(fix.FixRemovePCurveMode, True)
840
fix.FixAddPCurveMode = True
841
self.assertEqual(fix.FixAddPCurveMode, True)
843
fix.FixRemoveCurve3dMode = True
844
self.assertEqual(fix.FixRemoveCurve3dMode, True)
846
fix.FixAddCurve3dMode = True
847
self.assertEqual(fix.FixAddCurve3dMode, True)
849
fix.FixSeamMode = True
850
self.assertEqual(fix.FixSeamMode, True)
852
fix.FixShiftedMode = True
853
self.assertEqual(fix.FixShiftedMode, True)
855
fix.FixSameParameterMode = True
856
self.assertEqual(fix.FixSameParameterMode, True)
858
fix.FixVertexToleranceMode = True
859
self.assertEqual(fix.FixVertexToleranceMode, True)
861
fix.FixNotchedEdgesMode = True
862
self.assertEqual(fix.FixNotchedEdgesMode, True)
864
fix.FixSelfIntersectingEdgeMode = True
865
self.assertEqual(fix.FixSelfIntersectingEdgeMode, True)
867
fix.FixIntersectingEdgesMode = True
868
self.assertEqual(fix.FixIntersectingEdgesMode, True)
870
fix.FixNonAdjacentIntersectingEdgesMode = True
871
self.assertEqual(fix.FixNonAdjacentIntersectingEdgesMode, True)
873
fix.FixTailMode = True
874
self.assertEqual(fix.FixTailMode, True)
879
fix.fixSmall(1, True, 1e-7)
881
fix.fixConnected(1, True)
884
fix.fixDegenerated(1)
885
fix.fixSelfIntersection()
887
fix.fixLacking(1, False)
893
fix.fixNotchedEdges()
894
fix.fixGap3d(1, False)
895
fix.fixGap2d(1, False)
898
class PartBOPTestContainer(unittest.TestCase):
900
self.Doc = FreeCAD.newDocument()
902
def testMakeFuse(self):
903
box = self.Doc.addObject("Part::Box", "Box")
904
cyl = self.Doc.addObject("Part::Cylinder", "Cylinder")
905
part = self.Doc.addObject("App::Part", "Part")
908
from BOPTools import BOPFeatures
909
bp = BOPFeatures.BOPFeatures(self.Doc)
910
fuse = bp.make_multi_fuse([cyl.Name, box.Name])
911
self.assertEqual(part, fuse.getParent())
913
def testMakeCut(self):
914
box = self.Doc.addObject("Part::Box", "Box")
915
cyl = self.Doc.addObject("Part::Cylinder", "Cylinder")
916
part = self.Doc.addObject("App::Part", "Part")
919
from BOPTools import BOPFeatures
920
bp = BOPFeatures.BOPFeatures(self.Doc)
921
fuse = bp.make_cut([cyl.Name, box.Name])
922
self.assertEqual(part, fuse.getParent())
924
def testMakeCommon(self):
925
box = self.Doc.addObject("Part::Box", "Box")
926
cyl = self.Doc.addObject("Part::Cylinder", "Cylinder")
927
part = self.Doc.addObject("App::Part", "Part")
930
from BOPTools import BOPFeatures
931
bp = BOPFeatures.BOPFeatures(self.Doc)
932
fuse = bp.make_multi_common([cyl.Name, box.Name])
933
self.assertEqual(part, fuse.getParent())
936
FreeCAD.closeDocument(self.Doc.Name)
938
class BSplineCurve2d(unittest.TestCase):
940
vec2 = FreeCAD.Base.Vector2d
941
self.pts = [vec2(0, 0), vec2(1, 0)]
942
self.bs = Part.Geom2d.BSplineCurve2d()
944
def testInterpolate(self):
945
self.bs.interpolate(Points=self.pts)
947
def testApproximate(self):
948
self.bs.approximate(Points=self.pts)
950
class GeometryCurve(unittest.TestCase):
951
def testProject(self):
953
line.projectPoint(FreeCAD.Vector())
955
class EmptyEdge(unittest.TestCase):
956
def testParameterByLength(self):
957
with self.assertRaises(ValueError):
959
edge.getParameterByLength(0)
961
def testValueAt(self):
962
with self.assertRaises(ValueError):
966
def testParameters(self):
967
with self.assertRaises(ValueError):
970
edge.parameters(face)
972
def testParameterAt(self):
973
with self.assertRaises(ValueError):
975
vertex = Part.Vertex(0, 0, 0)
976
edge.parameterAt(vertex)
978
def testTangentAt(self):
979
with self.assertRaises(ValueError):
983
def testCurvatureAt(self):
984
with self.assertRaises(ValueError):
988
def testCenterOfCurvatureAt(self):
989
with self.assertRaises(ValueError):
991
edge.centerOfCurvatureAt(0)
993
def testDerivative1At(self):
994
with self.assertRaises(ValueError):
996
edge.derivative1At(0)
998
def testDerivative2At(self):
999
with self.assertRaises(ValueError):
1001
edge.derivative2At(0)
1003
def testDerivative3At(self):
1004
with self.assertRaises(ValueError):
1006
edge.derivative3At(0)
1008
def testNormalAt(self):
1009
with self.assertRaises(ValueError):
1013
def testFirstVertex(self):
1014
with self.assertRaises(ValueError):
1018
def testLastVertex(self):
1019
with self.assertRaises(ValueError):
1023
def testGetTolerance(self):
1024
with self.assertRaises(ValueError):
1028
def testSetTolerance(self):
1029
with self.assertRaises(ValueError):
1031
edge.Tolerance = 0.01
1033
def testLength(self):
1034
with self.assertRaises(ValueError):
1038
def testCurve(self):
1039
with self.assertRaises(ValueError):
1043
def testParameterRange(self):
1044
with self.assertRaises(ValueError):
1048
def testFirstParameter(self):
1049
with self.assertRaises(ValueError):
1053
def testLastParameter(self):
1054
with self.assertRaises(ValueError):
1058
class EmptyFace(unittest.TestCase):
1059
def testMakeOffset(self):
1060
with self.assertRaises(ValueError):
1064
def testValueAt(self):
1065
with self.assertRaises(ValueError):
1069
def testNormalAt(self):
1070
with self.assertRaises(ValueError):
1074
def testTangentAt(self):
1075
with self.assertRaises(ValueError):
1077
face.tangentAt(0, 0)
1079
def testCurvatureAt(self):
1080
with self.assertRaises(ValueError):
1082
face.curvatureAt(0, 0)
1084
def testDerivative1At(self):
1085
with self.assertRaises(ValueError):
1087
face.derivative1At(0, 0)
1089
def testDerivative2At(self):
1090
with self.assertRaises(ValueError):
1092
face.derivative2At(0, 0)
1094
def testCutHoles(self):
1095
with self.assertRaises(ValueError):
1097
circle = Part.Circle()
1098
wire = Part.Wire(Part.Edge(circle))
1099
face.cutHoles([wire])
1101
def testUVNodes(self):
1102
with self.assertRaises(ValueError):
1106
def testGetTolerance(self):
1107
with self.assertRaises(ValueError):
1111
def testSetTolerance(self):
1112
with self.assertRaises(ValueError):
1114
face.Tolerance = 0.01
1116
def testParameterRange(self):
1117
with self.assertRaises(ValueError):