FreeCAD

Форк
0
/
TopoShapeTest.py 
759 строк · 31.5 Кб
1
import FreeCAD as App
2
import Part
3

4
import unittest
5

6

7
class TopoShapeAssertions:
8

9
    def assertAttrEqual(self, toposhape, attr_value_list, msg=None):
10
        for attr, value in attr_value_list:
11
            result = toposhape.__getattribute__(
12
                attr
13
            )  # Look up each attribute by string name
14
            if result.__str__() != value.__str__():
15
                if msg == None:
16
                    msg = f"TopoShape {attr} is incorrect:  {result} should be {value}",
17
                raise AssertionError(msg)
18

19
    def assertAttrAlmostEqual(self, toposhape, attr_value_list, places=5, msg=None):
20
        range = 1 / 10 ** places
21
        for attr, value in attr_value_list:
22
            result = toposhape.__getattribute__(
23
                attr
24
            )  # Look up each attribute by string name
25
            if abs(result - value) > range:
26
                if msg == None:
27
                    msg = f"TopoShape {attr} is incorrect:  {result} should be {value}"
28
                raise AssertionError(msg)
29

30
    def assertAttrCount(self, toposhape, attr_value_list, msg=None):
31
        for attr, value in attr_value_list:
32
            result = toposhape.__getattribute__(
33
                attr
34
            )  # Look up each attribute by string name
35
            if len(result) != value:
36
                if msg == None:
37
                    msg = f"TopoShape {attr} is incorrect:  {result} should have {value} elements"
38
                raise AssertionError(msg)
39

40
    def assertKeysInMap(self, map, keys, msg=None):
41
        for key in keys:
42
            if not key in map:
43
                if msg == None:
44
                    msg = f"Key {key} not found in map:  {map}"
45
                raise AssertionError(msg)
46

47
    def assertBounds(self, shape, bounds, msg=None, precision=App.Base.Precision.confusion() * 100):
48
        shape_bounds = shape.BoundBox
49
        shape_bounds_max = App.BoundBox(shape_bounds)
50
        shape_bounds_max.enlarge(precision)
51
        bounds_max = App.BoundBox(bounds)
52
        bounds_max.enlarge(precision)
53
        if not (shape_bounds_max.isInside(bounds) and bounds_max.isInside(shape_bounds)):
54
            if msg == None:
55
                msg = f"Bounds {shape_bounds} doesn't match {bounds}"
56
            raise AssertionError(msg)
57

58

59
class TopoShapeTest(unittest.TestCase, TopoShapeAssertions):
60
    def setUp(self):
61
        """Create a document and some TopoShapes of various types"""
62
        self.doc = App.newDocument("TopoShape")
63
        # self.box = Part.makeBox(1, 2, 2)
64
        # Part.show(self.box, "Box1")
65
        # self.box2 = Part.makeBox(2, 1, 2)
66
        # Part.show(self.box2, "Box2")
67
        # Even on LS3 these boxes have no element maps.
68
        self.doc.addObject("Part::Box", "Box1")
69
        self.doc.Box1.Length = 1
70
        self.doc.Box1.Width = 2
71
        self.doc.Box1.Height = 2
72
        self.doc.addObject("Part::Box", "Box2")
73
        self.doc.Box2.Length = 2
74
        self.doc.Box2.Width = 1
75
        self.doc.Box2.Height = 2
76
        self.doc.recompute()
77
        self.box = self.doc.Box1.Shape
78
        self.box2 = self.doc.Box2.Shape
79

80
    def tearDown(self):
81
        App.closeDocument("TopoShape")
82

83
    def testTopoShapeBox(self):
84
        # Arrange our test TopoShape
85
        box2_toposhape = self.doc.Box2.Shape
86
        # Arrange list of attributes and values to string match
87
        attr_value_list = [
88
            ["BoundBox", App.BoundBox(0, 0, 0, 2, 1, 2)],
89
            ["CenterOfGravity", App.Vector(1, 0.5, 1)],
90
            ["CenterOfMass", App.Vector(1, 0.5, 1)],
91
            ["CompSolids", []],
92
            ["Compounds", []],
93
            ["Content", "<ElementMap/>\n"], # Our element map is empty, or there would be more here.
94
            ["ElementMap", {}],
95
            ["ElementReverseMap", {}],
96
            ['Hasher', None],
97
            [
98
                "MatrixOfInertia",
99
                App.Matrix(
100
                    1.66667, 0, 0, 0, 0, 2.66667, 0, 0, 0, 0, 1.66667, 0, 0, 0, 0, 1
101
                ),
102
            ],
103
            ["Module", "Part"],
104
            ["Orientation", "Forward"],
105
            # ['OuterShell', {}],    # Todo: Could verify that a Shell Object is returned
106
            ["Placement", App.Placement()],
107
            [
108
                "PrincipalProperties",
109
                {
110
                    "SymmetryAxis": True,
111
                    "SymmetryPoint": False,
112
                    "Moments": (
113
                        2.666666666666666,
114
                        1.666666666666667,
115
                        1.666666666666667,
116
                    ),
117
                    "FirstAxisOfInertia": App.Vector(0.0, 1.0, 0.0),
118
                    "SecondAxisOfInertia": App.Vector(0.0, 0.0, 1.0),
119
                    "ThirdAxisOfInertia": App.Vector(1.0, 0.0, 0.0),
120
                    "RadiusOfGyration": (
121
                        0.816496580927726,
122
                        0.6454972243679029,
123
                        0.6454972243679029,
124
                    ),
125
                },
126
            ],
127
            ["ShapeType", "Solid"],
128
            [
129
                "StaticMoments",
130
                (3.999999999999999, 1.9999999999999996, 3.999999999999999),
131
            ],
132
            # ['Tag', 0],    # Gonna vary, so can't really assert, except maybe != 0?
133
            ["TypeId", "Part::TopoShape"],
134
        ]
135
        # Assert all the expected values match when converted to strings.
136
        self.assertAttrEqual(box2_toposhape, attr_value_list)
137

138
        # Arrange list of attributes and values to match within 5 decimal places
139
        attr_value_list = [
140
            ["Area", 16.0],
141
            ["ElementMapSize", 0],
142
            # ['ElementMapVersion', 4 ], # Todo: Not until TNP on.
143
            ["Length", 40.0],  # Sum of all edges of each face, so some redundancy.
144
            ["Mass", 4.0],
145
            # ['MemSize', 13824],  # Platform variations in this size.
146
            ["Volume", 4.0],
147
        ]
148
        # Assert all the expected values match
149
        self.assertAttrAlmostEqual(box2_toposhape, attr_value_list, 5)
150

151
        # Arrange list of attributes to check list lengths
152
        attr_value_list = [
153
            ["Edges", 12],
154
            ["Faces", 6],
155
            ["Shells", 1],
156
            ["Solids", 1],
157
            ["SubShapes", 1],
158
            ["Vertexes", 8],
159
            ["Wires", 6],
160
        ]
161
        # Assert all the expected values match
162
        self.assertAttrCount(box2_toposhape, attr_value_list)
163

164
    def testTopoShapeElementMap(self):
165
        """Tests TopoShape elementMap"""
166
        # Arrange
167
        # Act No elementMaps exist in base shapes until we perform an operation.
168
        compound1 = Part.Compound(
169
            [self.doc.Objects[-1].Shape, self.doc.Objects[-2].Shape]
170
        )
171
        self.doc.addObject("Part::Compound", "Compound")
172
        self.doc.Compound.Links = [
173
            App.activeDocument().Box1,
174
            App.activeDocument().Box2,
175
        ]
176
        self.doc.recompute()
177
        compound2 = self.doc.Compound.Shape
178
        # Assert elementMap
179
        # This flag indicates that ElementMaps are supported under the current C++ build:
180
        if compound1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
181
            # 52 is 2 cubes of 26 each: 6 Faces, 12 Edges, 8 Vertexes
182
            # Todo: This should contain something as soon as the Python interface
183
            #  for Part.Compound TNP exists
184
            # self.assertEqual(len(compound1.ElementMap), 52,
185
            #                  "ElementMap is Incorrect:  {0}".format(compound1.ElementMap))
186
            self.assertEqual(
187
                compound2.ElementMapSize,
188
                52,
189
                "ElementMap is Incorrect:  {0}".format(compound2.ElementMap),
190
            )
191
        # Assert Shape
192
        self.assertBounds(compound2, App.BoundBox(0, 0, 0, 2, 2, 2))
193

194
    def testPartCommon(self):
195
        # Arrange
196
        self.doc.addObject("Part::MultiCommon", "Common")
197
        self.doc.Common.Shapes = [self.doc.Box1, self.doc.Box2]
198
        # Act
199
        self.doc.recompute()
200
        common1 = self.doc.Common.Shape
201
        # Assert elementMap
202
        if common1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
203
            self.assertKeysInMap(common1.ElementReverseMap,
204
                                 [
205
                                     "Edge1",
206
                                     "Edge2",
207
                                     "Edge3",
208
                                     "Edge4",
209
                                     "Edge5",
210
                                     "Edge6",
211
                                     "Edge7",
212
                                     "Edge8",
213
                                     "Edge9",
214
                                     "Edge10",
215
                                     "Edge11",
216
                                     "Edge12",
217
                                     "Face1",
218
                                     "Face2",
219
                                     "Face3",
220
                                     "Face4",
221
                                     "Face5",
222
                                     "Face6",
223
                                     "Vertex1",
224
                                     "Vertex2",
225
                                     "Vertex3",
226
                                     "Vertex4",
227
                                     "Vertex5",
228
                                     "Vertex6",
229
                                     "Vertex7",
230
                                     "Vertex8",
231
                                 ],
232
                                 )
233
        # Assert Shape
234
        self.assertBounds(common1, App.BoundBox(0, 0, 0, 1, 1, 2))
235

236
    def testPartCut(self):
237
        # Arrange
238
        self.doc.addObject("Part::Cut", "Cut")
239
        self.doc.Cut.Base = self.doc.Box1
240
        self.doc.Cut.Tool = self.doc.Box2
241
        # Act
242
        self.doc.recompute()
243
        cut1 = self.doc.Cut.Shape
244
        # Assert elementMap
245
        if cut1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
246
            self.assertKeysInMap(cut1.ElementReverseMap,
247
                                 [
248
                                     "Edge1",
249
                                     "Edge2",
250
                                     "Edge3",
251
                                     "Edge4",
252
                                     "Edge5",
253
                                     "Edge6",
254
                                     "Edge7",
255
                                     "Edge8",
256
                                     "Edge9",
257
                                     "Edge10",
258
                                     "Edge11",
259
                                     "Edge12",
260
                                     "Face1",
261
                                     "Face2",
262
                                     "Face3",
263
                                     "Face4",
264
                                     "Face5",
265
                                     "Face6",
266
                                     "Vertex1",
267
                                     "Vertex2",
268
                                     "Vertex3",
269
                                     "Vertex4",
270
                                     "Vertex5",
271
                                     "Vertex6",
272
                                     "Vertex7",
273
                                     "Vertex8",
274
                                 ],
275
                                 )
276
        # Assert Shape
277
        self.assertBounds(cut1, App.BoundBox(0, 1, 0, 1, 2, 2))
278

279
    def testPartFuse(self):
280
        # Arrange
281
        self.doc.addObject("Part::Fuse", "Fuse")
282
        self.doc.Fuse.Refine = False
283
        self.doc.Fuse.Base = self.doc.Box1
284
        self.doc.Fuse.Tool = self.doc.Box2
285
        # Act
286
        self.doc.recompute()
287
        fuse1 = self.doc.Fuse.Shape
288
        # Assert elementMap
289
        if fuse1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
290
            self.assertEqual(fuse1.ElementMapSize, 58)
291
            self.doc.Fuse.Refine = True
292
            self.doc.recompute()
293
            self.assertEqual(fuse1.ElementMapSize, 58)
294
        # Shape is an extruded L, with 8 Faces, 12 Vertexes, 18 Edges
295
        # Assert Shape
296
        self.assertBounds(fuse1, App.BoundBox(0, 0, 0, 2, 2, 2))
297

298
    def testAppPartMakeCompound(self):
299
        # This doesn't do element maps.
300
        # compound1 = Part.Compound([self.doc.Box1.Shape, self.doc.Box2.Shape])
301
        # Act
302
        compound1 = Part.makeCompound([self.doc.Box1.Shape, self.doc.Box2.Shape])
303
        # Assert elementMap
304
        if compound1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
305
            self.assertEqual(compound1.ElementMapSize, 52)
306
        # Assert Shape
307
        self.assertBounds(compound1, App.BoundBox(0, 0, 0, 2, 2, 2))
308

309
    def testAppPartMakeShell(self):
310
        # Act
311
        shell1 = Part.makeShell(self.doc.Box1.Shape.Faces)
312
        # Assert elementMap
313
        if shell1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
314
            self.assertEqual(shell1.ElementMapSize, 26)
315
        # Assert Shape
316
        self.assertBounds(shell1, App.BoundBox(0, 0, 0, 1, 2, 2))
317

318
    def testAppPartMakeFace(self):
319
        # Act
320
        face1 = Part.makeFace(self.doc.Box1.Shape.Faces[0], "Part::FaceMakerCheese")
321
        # Assert elementMap
322
        if face1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
323
            self.assertEqual(face1.ElementMapSize, 10)
324
        # Assert Shape
325
        self.assertBounds(face1, App.BoundBox(0, 0, 0, 0, 2, 2))
326

327
    def testAppPartmakeFilledFace(self):
328
        face1 = Part.makeFilledFace(self.doc.Box1.Shape.Faces[3].Edges)
329
        # Assert elementMap
330
        if face1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
331
            self.assertEqual(face1.ElementMapSize, 9)
332
        # Assert Shape
333
        self.assertBounds(face1, App.BoundBox(-0.05, 2, -0.1, 1.05, 2, 2.1))
334

335
    def testAppPartMakeSolid(self):
336
        # Act
337
        solid1 = Part.makeSolid(self.doc.Box1.Shape.Shells[0])
338
        # Assert elementMap
339
        if solid1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
340
            self.assertEqual(solid1.ElementMapSize, 26)
341
        # Assert Shape
342
        self.assertBounds(solid1, App.BoundBox(0, 0, 0, 1, 2, 2))
343

344
    def testAppPartMakeRuled(self):
345
        # Act
346
        surface1 = Part.makeRuledSurface(*self.doc.Box1.Shape.Edges[3:5])
347
        # Assert elementMap
348
        if surface1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
349
            self.assertEqual(surface1.ElementMapSize, 9)
350
        # Assert Shape
351
        self.assertBounds(surface1, App.BoundBox(0, 0, 0, 1, 2, 2))
352

353
    def testAppPartMakeShellFromWires(self):
354
        # Arrange
355
        wire1 = self.doc.Box1.Shape.Wires[0]  # .copy() Todo: prints 2 gen/mod warn because
356
        wire2 = self.doc.Box1.Shape.Wires[1]  # Todo: copy() isn't TNP yet.  Fix when it is.
357
        # Act
358
        shell1 = Part.makeShellFromWires([wire1, wire2])
359
        # Assert elementMap
360
        if shell1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
361
            self.assertEqual(shell1.ElementMapSize, 24)
362
        # Assert Shape
363
        self.assertBounds(shell1, App.BoundBox(0, 0, 0, 1, 2, 2))
364

365
    def testAppPartMakeSweepSurface(self):
366
        # Arrange
367
        circle = Part.makeCircle(5, App.Vector(0, 0, 0))
368
        path = Part.makeLine(App.Vector(), App.Vector(0, 0, 10))
369
        Part.show(circle, "Circle")  # Trigger the elementMapping
370
        Part.show(path, "Path")  # Trigger the elementMapping
371
        del circle
372
        # Act
373
        surface1 = Part.makeSweepSurface(self.doc.Path.Shape, self.doc.Circle.Shape, 0.001, 0)
374
        Part.show(surface1, "Sweep")
375
        self.doc.recompute()
376
        # Assert elementMap
377
        if surface1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
378
            self.assertEqual(surface1.ElementMapSize, 6)
379
            self.assertBounds(surface1, App.BoundBox(-5, -5, 0, 5, 5, 10), precision=2)
380
        else:
381
            # Todo: WHY is the actual sweep different?  That's BAD.  However, the "New" approach
382
            #       above, which uses BRepOffsetAPI_MakePipe appears to be correct over the older
383
            #       code which uses Geom_Curve.  This is done ostensibly because Geom_Curve is so
384
            #       old that it doesn't even support history, which toponaming needs, but also,
385
            #       the result is just wrong:  If you look at the resulting shape after Sweeping
386
            #       a circle along a line, you do not get a circular pipe:  you get a circular
387
            #       pipe with About a third of it removed.  More specifically, an angle of
388
            #       math.radians(math.degrees(360)%180) * 2 appears to have been applied, which
389
            #       looks suspiciously like a substantial bug in OCCT.
390
            # Assert Shape
391
            self.assertBounds(surface1, App.BoundBox(-5, -2.72011, 0, 5, 5, 6.28319), precision=2)
392
        del surface1
393

394
    def testAppPartMakeLoft(self):
395
        # Act
396
        solid1 = Part.makeLoft(self.doc.Box1.Shape.Wires[0:2])
397
        # Assert elementMap
398
        if solid1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
399
            self.assertEqual(solid1.ElementMapSize, 24)
400
        # Assert Shape
401
        self.assertBounds(solid1, App.BoundBox(0, 0, 0, 1, 2, 2))
402

403
    def testAppPartMakeSplitShape(self):
404
        # Todo: Refine this test after all TNP code in place to eliminate warnings.
405
        # Arrange
406
        edge1 = self.doc.Box1.Shape.Faces[0].Edges[0].translated(App.Vector(0, 0.5, 0))
407
        face1 = self.doc.Box1.Shape.Faces[0]
408
        # Act
409
        solids1 = Part.makeSplitShape(face1, [(edge1, face1)])
410
        # Assert elementMap
411
        self.assertEqual(len(solids1), 2)
412
        self.assertEqual(len(solids1[0]), 1)
413
        if solids1[0][0].ElementMapVersion != "":  # Should be '4' as of Mar 2023.
414
            self.assertEqual(solids1[0][0].ElementMapSize, 9)
415
            self.assertEqual(solids1[1][0].ElementMapSize, 9)
416
        # Assert Shape
417
        self.assertBounds(solids1[0][0], App.BoundBox(0, 0.5, 0, 0, 2, 2))
418
        self.assertBounds(solids1[1][0], App.BoundBox(0, 0.5, 0, 0, 2, 2))
419

420
    def testTopoShapePyInit(self):
421
        # Arrange
422
        self.doc.addObject("Part::Compound", "Compound")
423
        self.doc.Compound.Links = [
424
            App.activeDocument().Box1,
425
            App.activeDocument().Box2,
426
        ]
427
        self.doc.recompute()
428
        compound = self.doc.Compound.Shape
429
        # Act
430
        new_toposhape = Part.Shape(compound)
431
        new_empty_toposhape = Part.Shape()
432
        # Assert elementMap
433
        if compound.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
434
            self.assertEqual(compound.ElementMapSize, 52)
435
            self.assertEqual(new_toposhape.ElementMapSize, 52)
436

437
    def testTopoShapeCopy(self):
438
        # Arrange
439
        self.doc.addObject("Part::Compound", "Compound")
440
        self.doc.Compound.Links = [
441
            App.activeDocument().Box1,
442
            App.activeDocument().Box2,
443
        ]
444
        self.doc.recompute()
445
        compound = self.doc.Compound.Shape
446
        # Act
447
        compound_copy = compound.copy()
448
        # Assert elementMap
449
        if compound.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
450
            self.assertEqual(compound.ElementMapSize, 52)
451
            self.assertEqual(compound_copy.ElementMapSize, 52)
452

453
    def testTopoShapeCleaned(self):
454
        # Arrange
455
        self.doc.addObject("Part::Compound", "Compound")
456
        self.doc.Compound.Links = [
457
            App.activeDocument().Box1,
458
            App.activeDocument().Box2,
459
        ]
460
        self.doc.recompute()
461
        compound = self.doc.Compound.Shape
462
        # Act
463
        compound_cleaned = compound.cleaned()
464
        # Assert elementMap
465
        if compound.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
466
            self.assertEqual(compound.ElementMapSize, 52)
467
            self.assertEqual(compound_cleaned.ElementMapSize, 52)
468

469
    def testTopoShapeReplaceShape(self):
470
        # Arrange
471
        self.doc.addObject("Part::Compound", "Compound")
472
        self.doc.Compound.Links = [
473
            App.activeDocument().Box1,
474
            App.activeDocument().Box2,
475
        ]
476
        self.doc.recompute()
477
        compound = self.doc.Compound.Shape
478
        # Act
479
        compound_replaced = compound.replaceShape([(App.activeDocument().Box2.Shape,
480
                                                    App.activeDocument().Box1.Shape)])
481
        # Assert elementMap
482
        if compound.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
483
            self.assertEqual(compound.ElementMapSize, 52)
484
            self.assertEqual(compound_replaced.ElementMapSize, 52)
485

486
    def testTopoShapeRemoveShape(self):
487
        # Arrange
488
        self.doc.addObject("Part::Compound", "Compound")
489
        self.doc.Compound.Links = [
490
            App.activeDocument().Box1,
491
            App.activeDocument().Box2,
492
        ]
493
        self.doc.recompute()
494
        compound = self.doc.Compound.Shape
495
        # Act
496
        compound_removed = compound.removeShape([App.ActiveDocument.Box2.Shape])
497
        # Assert elementMap
498
        if compound.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
499
            self.assertEqual(compound.ElementMapSize, 52)
500
            self.assertEqual(compound_removed.ElementMapSize, 52)
501

502
    def testTopoShapeExtrude(self):
503
        # Arrange
504
        face = self.doc.Box1.Shape.Faces[0]
505
        # Act
506
        extrude = face.extrude(App.Vector(2, 0, 0))
507
        self.doc.recompute()
508
        # Assert elementMap
509
        if extrude.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
510
            self.assertEqual(extrude.ElementMapSize, 26)
511

512
    def testTopoShapeRevolve(self):
513
        # Arrange
514
        face = self.doc.Box1.Shape.Faces[0]
515
        # Act
516
        face.revolve(App.Vector(), App.Vector(1, 0, 0), 45)
517
        self.doc.recompute()
518
        # Assert elementMap
519
        if face.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
520
            self.assertEqual(face.ElementMapSize, 9)
521

522
    def testTopoShapeFuse(self):
523
        # Act
524
        fused = self.doc.Box1.Shape.fuse(self.doc.Box2.Shape)
525
        self.doc.recompute()
526
        # Assert elementMap
527
        if fused.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
528
            self.assertEqual(fused.ElementMapSize, 58)
529

530
    def testTopoShapeMultiFuse(self):
531
        # Act
532
        fused = self.doc.Box1.Shape.multiFuse([self.doc.Box2.Shape])
533
        self.doc.recompute()
534
        # Assert elementMap
535
        if fused.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
536
            self.assertEqual(fused.ElementMapSize, 58)
537

538
    def testTopoShapeCommon(self):
539
        # Act
540
        common = self.doc.Box1.Shape.common(self.doc.Box2.Shape)
541
        self.doc.recompute()
542
        # Assert elementMap
543
        if common.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
544
            self.assertEqual(common.ElementMapSize, 26)
545

546
    def testTopoShapeSection(self):
547
        # Act
548
        section = self.doc.Box1.Shape.Faces[0].section(self.doc.Box2.Shape.Faces[3])
549
        self.doc.recompute()
550
        # Assert elementMap
551
        if section.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
552
            self.assertEqual(section.ElementMapSize, 3)
553

554
    def testTopoShapeSlice(self):
555
        # Act
556
        slice = self.doc.Box1.Shape.slice(App.Vector(10, 10, 0), 1)
557
        self.doc.recompute()
558
        # Assert elementMap
559
        self.assertEqual(len(slice), 1)
560
        if slice[0].ElementMapVersion != "":  # Should be '4' as of Mar 2023.
561
            self.assertEqual(slice[0].ElementMapSize, 8)
562

563
    def testTopoShapeSlices(self):
564
        # Act
565
        slices = self.doc.Box1.Shape.Faces[0].slices(App.Vector(10, 10, 0), [1, 2])
566
        self.doc.recompute()
567
        # Assert elementMap
568
        if slices.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
569
            self.assertEqual(slices.ElementMapSize, 6)
570

571
    def testTopoShapeCut(self):
572
        # Act
573
        cut = self.doc.Box1.Shape.cut(self.doc.Box2.Shape)
574
        self.doc.recompute()
575
        # Assert elementMap
576
        if cut.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
577
            self.assertEqual(cut.ElementMapSize, 26)
578

579
    def testTopoShapeGeneralFuse(self):
580
        # Act
581
        fuse = self.doc.Box1.Shape.generalFuse([self.doc.Box2.Shape])
582
        self.doc.recompute()
583
        # Assert elementMap
584
        self.assertEqual(len(fuse), 2)
585
        if fuse[0].ElementMapVersion != "":  # Should be '4' as of Mar 2023.
586
            self.assertEqual(fuse[0].ElementMapSize, 60)
587

588
    def testTopoShapeChildShapes(self):
589
        # Act
590
        childShapes = self.doc.Box1.Shape.childShapes()
591
        self.doc.recompute()
592
        # Assert elementMap
593
        self.assertEqual(len(childShapes), 1)
594
        if childShapes[0].ElementMapVersion != "":  # Should be '4' as of Mar 2023.
595
            self.assertEqual(childShapes[0].ElementMapSize, 26)
596

597
    def testTopoShapeMirror(self):
598
        # Act
599
        mirror = self.doc.Box1.Shape.mirror(App.Vector(), App.Vector(1, 0, 0))
600
        self.doc.recompute()
601
        # Assert elementMap
602
        if mirror.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
603
            self.assertEqual(mirror.ElementMapSize, 26)
604

605
    def testTopoShapeScale(self):
606
        # Act
607
        scale = self.doc.Box1.Shape.scaled(2)
608
        self.doc.recompute()
609
        # Assert elementMap
610
        if scale.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
611
            self.assertEqual(scale.ElementMapSize, 26)
612

613
    def testTopoShapeMakeFillet(self):
614
        # Act
615
        fillet = self.doc.Box1.Shape.makeFillet(0.1, self.doc.Box1.Shape.Faces[0].Edges)
616
        self.doc.recompute()
617
        # Assert elementMap
618
        if fillet.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
619
            self.assertEqual(fillet.ElementMapSize, 42)
620

621
    def testTopoShapeMakeChamfer(self):
622
        # Act
623
        chamfer = self.doc.Box1.Shape.makeChamfer(0.1, self.doc.Box1.Shape.Faces[0].Edges)
624
        self.doc.recompute()
625
        # Assert elementMap
626
        if chamfer.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
627
            self.assertEqual(chamfer.ElementMapSize, 42)
628

629
    def testTopoShapeMakeThickness(self):
630
        # Act
631
        thickness = self.doc.Box1.Shape.makeThickness(self.doc.Box1.Shape.Faces[0:2], 0.1, 0.0001)
632
        self.doc.recompute()
633
        # Assert elementMap
634
        if thickness.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
635
            self.assertEqual(thickness.ElementMapSize, 74)
636

637
    def testTopoShapeMakeOffsetShape(self):
638
        # Act
639
        offset = self.doc.Box1.Shape.Faces[0].makeOffset(1)
640
        self.doc.recompute()
641
        # Assert elementMap
642
        if offset.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
643
            self.assertEqual(offset.ElementMapSize, 17)
644

645
    def testTopoShapeOffset2D(self):
646
        # Act
647
        offset = self.doc.Box1.Shape.Faces[0].makeOffset2D(1)
648
        self.doc.recompute()
649
        # Assert elementMap
650
        if offset.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
651
            self.assertEqual(offset.ElementMapSize, 17)
652

653
    def testTopoShapeRemoveSplitter(self):
654
        # Act
655
        fused = self.doc.Box1.Shape.fuse(self.doc.Box2.Shape)
656
        removed = fused.removeSplitter()
657
        self.doc.recompute()
658
        # Assert elementMap
659
        if removed.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
660
            self.assertEqual(removed.ElementMapSize, 38)
661

662
    def testTopoShapeCompSolid(self):
663
        # Act
664
        compSolid = Part.CompSolid([self.doc.Box1.Shape, self.doc.Box2.Shape])  # list of subobjects
665
        box1ts = self.doc.Box1.Shape
666
        compSolid.add(box1ts.Solids[0])
667
        # Assert elementMap
668
        if compSolid.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
669
            self.assertEqual(compSolid.ElementMapSize, 78)
670

671
    def testTopoShapeFaceOffset(self):
672
        # Arrange
673
        box_toposhape = self.doc.Box1.Shape
674
        # Act
675
        offset = box_toposhape.Faces[0].makeOffset(2.0)
676
        # Assert elementMap
677
        if box_toposhape.Faces[0].ElementMapVersion != "":  # Should be '4' as of Mar 2023.
678
            self.assertEqual(box_toposhape.Faces[0].ElementMapSize, 9)  # 1 Face, 4 Edges, 4 Vertexes
679
            self.assertEqual(offset.ElementMapSize, 17)  # 1 Face, 8 Edges, 8 Vertexes
680

681
    # Todo:  makeEvolved doesn't work right, probably due to missing c++ code.
682
    # def testTopoShapeFaceEvolve(self):
683
    #     # Arrange
684
    #     box_toposhape = self.doc.Box1.Shape
685
    #     # Act
686
    #     evolved = box_toposhape.Faces[0].makeEvolved(self.doc.Box1.Shape.Wires[1])  # 2,3,4,5 bad
687
    #     # Assert elementMap
688
    #     if box_toposhape.Faces[0].ElementMapVersion != "":  # Should be '4' as of Mar 2023.
689
    #         self.assertEqual(box_toposhape.Faces[0].ElementMapSize, 9)  # 1 Face, 4 Edges, 4 Vertexes
690
    #         self.assertEqual(evolved.ElementMapSize, 0)  # Todo: This can't be correct.
691

692
    def testTopoShapePart(self):
693
        # Arrange
694
        box1ts = self.doc.Box1.Shape
695
        face1 = box1ts.Faces[0]
696
        box1ts2 = box1ts.copy()
697
        # Act
698
        face2 = box1ts.getElement("Face2")
699
        indexed_name = box1ts.findSubShape(face1)
700
        faces1 = box1ts.findSubShapesWithSharedVertex(face2)
701
        subshapes1 = box1ts.getChildShapes("Solid1")
702
        # box1ts.clearCache()   # Todo: no apparent way to see a result at this level
703
        # Assert
704
        self.assertTrue(face2.isSame(box1ts.Faces[1]))
705
        self.assertEqual(indexed_name[0], "Face")
706
        self.assertEqual(indexed_name[1], 1)
707
        self.assertEqual(len(faces1), 1)
708
        self.assertTrue(faces1[0].isSame(box1ts.Faces[1]))
709
        self.assertEqual(len(subshapes1), 1)
710
        self.assertTrue(subshapes1[0].isSame(box1ts.Solids[0]))
711

712
    def testTopoShapeMapSubElement(self):
713
        # Arrange
714
        box = Part.makeBox(1,2,3)
715
        # face = box.Faces[0]   # Do not do this.  Need the subelement call each usage.
716
        # Assert everything empty
717
        self.assertEqual(box.ElementMapSize,0)
718
        self.assertEqual(box.Faces[0].ElementMapSize,0)
719
        # Act
720
        box.mapSubElement(box.Faces[0])
721
        # Assert elementMaps created
722
        if box.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
723
            self.assertEqual(box.ElementMapSize,9)  # 1 Face, 4 Edges, 4 Vertexes
724
            self.assertEqual(box.Faces[0].ElementMapSize,9)
725

726
    def testTopoShapeGetElementHistory(self):
727
        self.doc.addObject("Part::Fuse", "Fuse")
728
        self.doc.Fuse.Base = self.doc.Box1
729
        self.doc.Fuse.Tool = self.doc.Box2
730
        # Act
731
        self.doc.recompute()
732
        fuse1 = self.doc.Fuse.Shape
733
        if fuse1.ElementMapVersion != "":  # Should be '4' as of Mar 2023.
734
            history1 = fuse1.getElementHistory(fuse1.ElementReverseMap["Vertex1"])
735
            # Assert
736
            self.assertEqual(len(history1),3)   # Just the Fuse operation
737

738
    # Todo:  Still broken, still can't find parms that consistently work to test this.
739
    #           However, the results with an empty elementMap are consistent with making the
740
    #           same calls on LS3.  So what this method is supposed to do remains a mystery;
741
    #           So far, it just wipes out the elementMap and returns the Toposhape.
742
    # def testTopoShapeMapShapes(self):
743
    #     self.doc.addObject("Part::Fuse", "Fuse")
744
    #     self.doc.Fuse.Base = self.doc.Box1
745
    #     self.doc.Fuse.Tool = self.doc.Box2
746
    #     # Act
747
    #     self.doc.recompute()
748
    #     fuse1 = self.doc.Fuse.Shape
749
    #     res = fuse1.copy()  # Make it mutable
750
    #     self.assertEqual(res.ElementMapSize,58)
751
    #     result = res.mapShapes([(fuse1, fuse1.Faces[0])], []) #[(res, res.Vertexes[0])])
752
    #     self.assertEqual(res.ElementMapSize,9)
753
    #     # result2 = fuse1.copy().mapShapes([],[(fuse1, fuse1.Edges[0]),(fuse1, fuse1.Edges[1])])
754
    #     self.assertEqual(fuse1.ElementMapSize,58) #
755
    #     self.assertEqual(fuse1.Faces[0].ElementMapSize,9)
756
    #     self.assertEqual(result.ElementMapSize,9)
757
    #     self.assertEqual(result.Faces[0].ElementMapSize,0)
758
    #     self.assertEqual(result2.ElementMapSize,9)
759
    #     self.assertEqual(result2.Faces[0].ElementMapSize,0)
760

761

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.