Toponaming/Part: Clean and add tests

This commit is contained in:
bgbsww
2024-04-11 10:22:27 -04:00
parent 7bc2b3688a
commit 5f2c412cfa
2 changed files with 105 additions and 2 deletions

View File

@@ -273,10 +273,18 @@ App::DocumentObjectExecReturn *Transformed::execute()
if (fuseShape.isNull() && cutShape.isNull())
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Shape of additive/subtractive feature is empty"));
gp_Trsf trsf = feature->getLocation().Transformation().Multiplied(trsfInv);
#ifdef FC_USE_TNP_FIX
if (!fuseShape.isNull())
fuseShape = fuseShape.makeElementTransform(trsf);
if (!cutShape.isNull())
cutShape = cutShape.makeElementTransform(trsf);
#else
if (!fuseShape.isNull())
fuseShape = fuseShape.makeTransform(trsf);
if (!cutShape.isNull())
cutShape = cutShape.makeTransform(trsf);
#endif
}
else {
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Only additive and subtractive features can be transformed"));

View File

@@ -532,6 +532,101 @@ class TestTopologicalNamingProblem(unittest.TestCase):
def testPartDesignElementMapSubHelix(self):
pass # TODO
def testPartDesignElementMapChamfer(self):
""" Test Chamfer ( and FeatureDressup )"""
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
box = self.Doc.addObject('PartDesign::AdditiveBox', 'Box')
if body.Shape.ElementMapVersion == "": # Skip without element maps.
return
chamfer = self.Doc.addObject('PartDesign::Chamfer', 'Chamfer')
chamfer.Base = (box, ['Edge1',
'Edge2',
'Edge3',
'Edge4',
'Edge5',
'Edge6',
'Edge7',
'Edge8',
'Edge9',
'Edge10',
'Edge11',
'Edge12',
])
chamfer.Size = 1
chamfer.UseAllEdges = True
# Act / Assert
body.addObject(box)
body.addObject(chamfer)
self.Doc.recompute()
reverseMap = body.Shape.childShapes()[0].ElementReverseMap
faces = [name for name in reverseMap.keys() if name.startswith("Face")]
edges = [name for name in reverseMap.keys() if name.startswith("Edge")]
vertexes = [name for name in reverseMap.keys() if name.startswith("Vertex")]
self.assertEqual(len(body.Shape.childShapes()), 1)
self.assertEqual(body.Shape.childShapes()[0].ElementMapSize, 98)
self.assertEqual(len(reverseMap),98)
self.assertEqual(len(faces),26) # 6 Faces become 26 ( +8 + 2*6 )
self.assertEqual(len(edges),48) # 12 Edges become 48
self.assertEqual(len(vertexes),24) # 8 Vertices become 24
def testPartDesignElementMapFillet(self):
""" Test Fillet ( and FeatureDressup )"""
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
box = self.Doc.addObject('PartDesign::AdditiveBox', 'Box')
if body.Shape.ElementMapVersion == "": # Skip without element maps.
return
fillet = self.Doc.addObject('PartDesign::Fillet', 'Fillet')
fillet.Base = (box, ['Edge1',
'Edge2',
'Edge3',
'Edge4',
'Edge5',
'Edge6',
'Edge7',
'Edge8',
'Edge9',
'Edge10',
'Edge11',
'Edge12',
])
# Act / Assert
body.addObject(box)
body.addObject(fillet)
self.Doc.recompute()
reverseMap = body.Shape.childShapes()[0].ElementReverseMap
faces = [name for name in reverseMap.keys() if name.startswith("Face")]
edges = [name for name in reverseMap.keys() if name.startswith("Edge")]
vertexes = [name for name in reverseMap.keys() if name.startswith("Vertex")]
self.assertEqual(len(body.Shape.childShapes()), 1)
self.assertEqual(body.Shape.childShapes()[0].ElementMapSize, 106)
self.assertEqual(len(reverseMap),106)
self.assertEqual(len(faces),26) # 6 Faces become 26 ( +8 + 2*6 )
self.assertEqual(len(edges),56) # 12 Edges become 56 Why?
self.assertEqual(len(vertexes),24) # 8 Vertices become 24
def testPartDesignElementMapTransform(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
box = self.Doc.addObject('PartDesign::AdditiveBox', 'Box')
if body.Shape.ElementMapVersion == "": # Skip without element maps.
return
multitransform = self.Doc.addObject('PartDesign::MultiTransform', 'MultiTransform')
scaled = self.Doc.addObject('PartDesign::Scaled', 'Scaled')
scaled.Factor = 2
scaled.Occurrences = 2
multitransform.Transformations = scaled
multitransform.Shape = box.Shape
# Act / Assert
self.Doc.recompute()
body.addObject(box)
body.addObject(multitransform)
self.assertEqual(len(body.Shape.childShapes()), 0)
self.Doc.recompute()
self.assertEqual(len(body.Shape.childShapes()), 1)
self.assertEqual(body.Shape.childShapes()[0].ElementMapSize, 26)
def testSketchElementMap(self):
body = self.Doc.addObject('PartDesign::Body', 'Body')
sketch = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
@@ -543,7 +638,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
pad.Profile = sketch
body.addObject(pad)
self.Doc.recompute()
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Skip without element maps.
return
# Assert
self.assertEqual(sketch.Shape.ElementMapSize, 12)
@@ -562,7 +657,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
pad = self.Doc.addObject('PartDesign::Pad', 'Pad')
pad.Profile = plane
self.Doc.recompute()
if not hasattr(pad,"ElementMapVersion"): # Skip without element maps.
if pad.Shape.ElementMapVersion == "": # Skip without element maps.
return
# Assert
self.assertEqual(plane.Shape.ElementMapSize, 0)