Merge branch 'main' into bgbsww-toponamingFeatureDressup10399

This commit is contained in:
bgbsww
2024-04-14 18:08:58 -04:00
committed by GitHub
107 changed files with 2529 additions and 665 deletions

View File

@@ -110,11 +110,38 @@ class TestTopologicalNamingProblem(unittest.TestCase):
else:
print("TOPOLOGICAL NAMING PROBLEM IS PRESENT.")
def testPartDesignElementMapPad(self):
""" Test that padding a sketch results in a correct element map. Note that comprehensive testing
of the geometric functionality of the Pad is in TestPad.py """
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
padSketch = self.Doc.addObject('Sketcher::SketchObject', 'SketchPad')
pad = self.Doc.addObject("PartDesign::Pad", "Pad")
body.addObject(padSketch)
body.addObject(pad)
TestSketcherApp.CreateRectangleSketch(padSketch, (0, 0), (1, 1))
pad.Profile = padSketch
pad.Length = 1
# Act
self.Doc.recompute()
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
reverseMap = pad.Shape.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")]
# Assert
self.assertEqual(pad.Shape.ElementMapSize,30) # 4 duplicated Vertexes in here
self.assertEqual(len(reverseMap),26)
self.assertEqual(len(faces),6)
self.assertEqual(len(edges),12)
self.assertEqual(len(vertexes),8)
def testPartDesignElementMapBox(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
box = self.Doc.addObject('PartDesign::AdditiveBox', 'Box')
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act / Assert
self.assertEqual(len(box.Shape.childShapes()), 0)
@@ -131,7 +158,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
cylinder = self.Doc.addObject('PartDesign::AdditiveCylinder', 'Cylinder')
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act / Assert
self.assertEqual(len(cylinder.Shape.childShapes()), 0)
@@ -141,14 +168,22 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body.addObject(cylinder)
self.assertEqual(len(body.Shape.childShapes()), 0)
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, 8)
self.assertEqual(len(reverseMap),8)
self.assertEqual(len(faces),3)
self.assertEqual(len(edges),3)
self.assertEqual(len(vertexes),2)
def testPartDesignElementMapSphere(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
sphere = self.Doc.addObject('PartDesign::AdditiveSphere', 'Sphere')
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act / Assert
self.assertEqual(len(sphere.Shape.childShapes()), 0)
@@ -158,14 +193,22 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body.addObject(sphere)
self.assertEqual(len(body.Shape.childShapes()), 0)
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, 6)
self.assertEqual(len(reverseMap),6)
self.assertEqual(len(faces),1)
self.assertEqual(len(edges),3)
self.assertEqual(len(vertexes),2)
def testPartDesignElementMapCone(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
cone = self.Doc.addObject('PartDesign::AdditiveCone', 'Cone')
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act / Assert
self.assertEqual(len(cone.Shape.childShapes()), 0)
@@ -175,14 +218,22 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body.addObject(cone)
self.assertEqual(len(body.Shape.childShapes()), 0)
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, 8)
self.assertEqual(len(reverseMap),8)
self.assertEqual(len(faces),3)
self.assertEqual(len(edges),3)
self.assertEqual(len(vertexes),2)
def testPartDesignElementMapEllipsoid(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
ellipsoid = self.Doc.addObject('PartDesign::AdditiveEllipsoid', 'Ellipsoid')
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act / Assert
self.assertEqual(len(ellipsoid.Shape.childShapes()), 0)
@@ -192,14 +243,22 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body.addObject(ellipsoid)
self.assertEqual(len(body.Shape.childShapes()), 0)
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, 6)
self.assertEqual(len(reverseMap),6)
self.assertEqual(len(faces),1)
self.assertEqual(len(edges),3)
self.assertEqual(len(vertexes),2)
def testPartDesignElementMapTorus(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
torus = self.Doc.addObject('PartDesign::AdditiveTorus', 'Torus')
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act / Assert
self.assertEqual(len(torus.Shape.childShapes()), 0)
@@ -209,14 +268,22 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body.addObject(torus)
self.assertEqual(len(body.Shape.childShapes()), 0)
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, 4)
self.assertEqual(len(reverseMap),4)
self.assertEqual(len(faces),1)
self.assertEqual(len(edges),2)
self.assertEqual(len(vertexes),1)
def testPartDesignElementMapPrism(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
prism = self.Doc.addObject('PartDesign::AdditivePrism', 'Prism')
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act / Assert
self.assertEqual(len(prism.Shape.childShapes()), 0)
@@ -226,14 +293,22 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body.addObject(prism)
self.assertEqual(len(body.Shape.childShapes()), 0)
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, 38)
self.assertEqual(len(reverseMap),38)
self.assertEqual(len(faces),8)
self.assertEqual(len(edges),18)
self.assertEqual(len(vertexes),12)
def testPartDesignElementMapWedge(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
wedge = self.Doc.addObject('PartDesign::AdditiveWedge', 'Wedge')
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act / Assert
self.assertEqual(len(wedge.Shape.childShapes()), 0)
@@ -243,8 +318,16 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body.addObject(wedge)
self.assertEqual(len(body.Shape.childShapes()), 0)
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, 26)
self.assertEqual(len(reverseMap),26)
self.assertEqual(len(faces),6)
self.assertEqual(len(edges),12)
self.assertEqual(len(vertexes),8)
# body.BaseFeature = box
@@ -256,7 +339,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
box.Width = 20
box.Height = 20
body.addObject(box)
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
subbox = self.Doc.addObject('PartDesign::SubtractiveBox', 'Box')
@@ -275,7 +358,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
box.Width = 20
box.Height = 20
body.addObject(box)
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
subcylinder = self.Doc.addObject('PartDesign::SubtractiveCylinder', 'Cylinder')
@@ -294,7 +377,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
box.Width = 20
box.Height = 20
body.addObject(box)
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
subsphere = self.Doc.addObject('PartDesign::SubtractiveSphere', 'Sphere')
@@ -313,7 +396,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
box.Width = 20
box.Height = 20
body.addObject(box)
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
subcone = self.Doc.addObject('PartDesign::SubtractiveCone', 'Cone')
@@ -332,7 +415,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
box.Width = 20
box.Height = 20
body.addObject(box)
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
subellipsoid = self.Doc.addObject('PartDesign::SubtractiveEllipsoid', 'Ellipsoid')
@@ -351,7 +434,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
box.Width = 20
box.Height = 20
body.addObject(box)
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
subtorus = self.Doc.addObject('PartDesign::SubtractiveTorus', 'Torus')
@@ -370,7 +453,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
box.Width = 20
box.Height = 20
body.addObject(box)
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
subprism = self.Doc.addObject('PartDesign::SubtractivePrism', 'Prism')
@@ -389,7 +472,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
box.Width = 20
box.Height = 20
body.addObject(box)
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
subwedge = self.Doc.addObject('PartDesign::SubtractiveWedge', 'Wedge')
@@ -405,25 +488,35 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body = self.Doc.addObject('PartDesign::Body', 'Body')
sketch = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
TestSketcherApp.CreateRectangleSketch(sketch, (0, 0), (1, 1))
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
pad = self.Doc.addObject('PartDesign::Pad', 'Pad')
pad.Profile = sketch
pad.BaseFeature = sketch
body.addObject(sketch)
body.addObject(pad)
self.Doc.recompute()
# Assert
self.assertEqual(len(body.Shape.childShapes()), 1)
self.assertEqual(body.Shape.childShapes()[0].ElementMapSize, 26)
# self.assertEqual(len(body.Shape.childShapes()), 1)
if App.GuiUp:
# Todo: This triggers a 'hasher mismatch' warning in TopoShape::mapSubElement as called by
# flushElementMap. This appears to be the case whenever you have a parent with a hasher
# that has children without hashmaps. The warning seems to be spurious in this case, but
# perhaps there is a solution involving setting hashmaps on all elements.
self.assertEqual(body.Shape.childShapes()[0].ElementMapSize, 30)
else:
self.assertEqual(body.Shape.childShapes()[0].ElementMapSize, 26)
self.assertEqual(body.Shape.ElementMapSize,30)
self.assertEqual(sketch.Shape.ElementMapSize,12)
self.assertEqual(pad.Shape.ElementMapSize,30)
# Todo: Assert that the names in the ElementMap are good; in particular that they are hashed with a # starting
def testPartDesignElementMapRevolution(self):
# Arrange
body = self.Doc.addObject('PartDesign::Body', 'Body')
sketch = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
TestSketcherApp.CreateRectangleSketch(sketch, (0, 0), (1, 1))
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
revolution = self.Doc.addObject('PartDesign::Revolution', 'Revolution')
@@ -444,7 +537,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
sketch2 = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
TestSketcherApp.CreateRectangleSketch(sketch2, (0, 0), (2, 2))
sketch2.Placement.move(App.Vector(0, 0, 3))
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
loft = self.Doc.addObject('PartDesign::AdditiveLoft', 'Loft')
@@ -465,7 +558,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
TestSketcherApp.CreateRectangleSketch(sketch, (0, 0), (1, 1))
sketch2 = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
TestSketcherApp.CreateRectangleSketch(sketch2, (0, 0), (2, 2))
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
pipe = self.Doc.addObject('PartDesign::AdditivePipe', 'Pipe')
@@ -484,7 +577,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
body = self.Doc.addObject('PartDesign::Body', 'Body')
sketch = self.Doc.addObject('Sketcher::SketchObject', 'Sketch')
TestSketcherApp.CreateRectangleSketch(sketch, (0, 0), (1, 1))
if not hasattr(body,"ElementMapVersion"): # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Act
helix = self.Doc.addObject('PartDesign::AdditiveHelix', 'Helix')
@@ -519,6 +612,8 @@ class TestTopologicalNamingProblem(unittest.TestCase):
groove.Reversed = 0
groove.Base = App.Vector(0, 0, 0)
self.Doc.recompute()
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Assert
# print(groove.Shape.childShapes()[0].ElementMap)
# TODO: Complete me as part of the subtractive features
@@ -638,14 +733,13 @@ class TestTopologicalNamingProblem(unittest.TestCase):
pad.Profile = sketch
body.addObject(pad)
self.Doc.recompute()
if body.Shape.ElementMapVersion == "": # Skip without element maps.
if body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Assert
self.assertEqual(sketch.Shape.ElementMapSize, 12)
self.assertEqual(pad.Shape.ElementMapSize, 30) # The sketch plus the pad in the map
# TODO: differing results between main and LS3 on these values. Does it matter?
# self.assertEqual(body.Shape.ElementMapSize,0) # 8?
# self.Doc.recompute()
# self.assertEqual(body.Shape.ElementMapSize,30) # 26
def testPlaneElementMap(self):
@@ -657,7 +751,7 @@ class TestTopologicalNamingProblem(unittest.TestCase):
pad = self.Doc.addObject('PartDesign::Pad', 'Pad')
pad.Profile = plane
self.Doc.recompute()
if pad.Shape.ElementMapVersion == "": # Skip without element maps.
if pad.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023.
return
# Assert
self.assertEqual(plane.Shape.ElementMapSize, 0)