From 8fff92618cb075a71b712c10cd26ec3a5c4c55b8 Mon Sep 17 00:00:00 2001 From: bgbsww Date: Tue, 7 May 2024 09:40:48 -0400 Subject: [PATCH 1/2] Toponaming/Part: Fix fillet/pad bug, add tests --- src/App/ComplexGeoData.cpp | 15 + src/App/ComplexGeoData.h | 13 +- src/Mod/Part/App/TopoShapeExpansion.cpp | 2 +- .../TestTopologicalNamingProblem.py | 259 +++++++++++++++++- 4 files changed, 282 insertions(+), 7 deletions(-) diff --git a/src/App/ComplexGeoData.cpp b/src/App/ComplexGeoData.cpp index b2653b58e3..9de14332f7 100644 --- a/src/App/ComplexGeoData.cpp +++ b/src/App/ComplexGeoData.cpp @@ -681,5 +681,20 @@ bool ComplexGeoData::hasChildElementMap() const return _elementMap && _elementMap->hasChildElementMap(); } +void ComplexGeoData::dumpElementMap(std::ostream& stream) const +{ + auto map = getElementMap(); + std::sort(map.begin(), map.end()); + for ( auto element : map ) { + stream << element.index << " : " << element.name << std::endl; + } +} + +const std::string ComplexGeoData::dumpElementMap() const +{ + std::stringstream ss; + dumpElementMap(ss); + return ss.str(); +} // NOLINTEND(cppcoreguidelines-pro-bounds-pointer-arithmetic) diff --git a/src/App/ComplexGeoData.h b/src/App/ComplexGeoData.h index 504d3dbb93..2f6804432d 100644 --- a/src/App/ComplexGeoData.h +++ b/src/App/ComplexGeoData.h @@ -364,6 +364,17 @@ public: void resetRestoreFailure() const { _restoreFailed = true; } //@} + /** + * Debugging method to dump an entire element map in human readable form to a stream + * @param stream + */ + void dumpElementMap(std::ostream& stream) const; + /** + * Debugging method to dump an entire element map in human readable form into a string + * @return The string + */ + const std::string dumpElementMap() const; + protected: /// from local to outside @@ -424,8 +435,6 @@ protected: public: mutable long Tag{0}; - -public: /// String hasher for element name shortening mutable App::StringHasherRef Hasher; diff --git a/src/Mod/Part/App/TopoShapeExpansion.cpp b/src/Mod/Part/App/TopoShapeExpansion.cpp index 2a01402ff9..995d076198 100644 --- a/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -1313,7 +1313,7 @@ void checkForParallelOrCoplanar(const TopoDS_Shape& newShape, const ShapeInfo& newInfo, std::vector& newShapes, const gp_Pln& pln, - int parallelFace, + int& parallelFace, int& coplanarFace, int& checkParallel) { diff --git a/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py b/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py index a66113eb22..dbe1ad5269 100644 --- a/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py +++ b/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py @@ -933,11 +933,7 @@ class TestTopologicalNamingProblem(unittest.TestCase): # Act self.Doc.getObject('Sketch').fillet(2,3,App.Vector(6.673934,25.000000,0),App.Vector(0.000000,21.980343,0),4.740471,True,True,False) self.Doc.recompute() - # filleted = self.Pad001.Shape.makeFillet(1,self.Pad001.Shape.Edges[0:2]) - # self.filleted = Part.show(filleted,"Filleted") - # self.Body.addObject(self.filleted) area2 = self.Pad.Shape.Area - print(area1,area2) # Assert if self.Body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023. @@ -948,6 +944,261 @@ class TestTopologicalNamingProblem(unittest.TestCase): self.assertEqual(self.Body.Shape.BoundBox.XMax,31.37) self.assertEqual(self.Body.Shape.BoundBox.YMax,25.2) self.assertEqual(self.Body.Shape.BoundBox.ZMax,20) + self.assertNotEquals(area1, area2) + + def testShapeBinder(self): + doc = self.Doc + doc.addObject('PartDesign::Body','TNP_Test_Body_SubShape') + doc.getObject('TNP_Test_Body_SubShape').Label = 'TNP_Test_Body_SubShape' + + doc.recompute() + doc.getObject('TNP_Test_Body_SubShape').newObject('Sketcher::SketchObject','Sketch') + doc.Sketch.AttachmentSupport = (doc.getObject('XY_Plane'),['']) + doc.Sketch.MapMode = 'FlatFace' + doc.recompute() + + geoList = [] + geoList.append(Part.LineSegment(App.Vector(0.000000, 0.000000, 0.000000),App.Vector(35.000000, 0.000000, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(35.000000, 0.000000, 0.000000),App.Vector(35.000000, 25.000000, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(35.000000, 25.000000, 0.000000),App.Vector(0.000000, 25.000000, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(0.000000, 25.000000, 0.000000),App.Vector(0.000000, 0.000000, 0.000000))) + doc.Sketch.addGeometry(geoList,False) + del geoList + + constraintList = [] + constraintList.append(Sketcher.Constraint('Coincident', 0, 2, 1, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 1, 2, 2, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 2, 2, 3, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 3, 2, 0, 1)) + constraintList.append(Sketcher.Constraint('Horizontal', 0)) + constraintList.append(Sketcher.Constraint('Horizontal', 2)) + constraintList.append(Sketcher.Constraint('Vertical', 1)) + constraintList.append(Sketcher.Constraint('Vertical', 3)) + doc.Sketch.addConstraint(constraintList) + del constraintList + + doc.Sketch.addConstraint(Sketcher.Constraint('Distance',1,1,3,2,35.000000)) + doc.Sketch.addConstraint(Sketcher.Constraint('Distance',0,1,2,2,25.000000)) + doc.Sketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, -1, 1)) + + + doc.recompute() + + doc.getObject('TNP_Test_Body_SubShape').newObject('PartDesign::Pad','Pad') + doc.Pad.Profile = doc.Sketch + doc.Pad.Length = 10 + doc.recompute() + doc.Pad.ReferenceAxis = (doc.Sketch,['N_Axis']) + doc.Sketch.Visibility = False + doc.recompute() + doc.Pad.Length = 10.000000 + doc.Pad.TaperAngle = 0.000000 + doc.Pad.UseCustomVector = 0 + doc.Pad.Direction = (0, 0, 1) + doc.Pad.ReferenceAxis = (doc.Sketch, ['N_Axis']) + doc.Pad.AlongSketchNormal = 1 + doc.Pad.Type = 0 + doc.Pad.UpToFace = None + doc.Pad.Reversed = 0 + doc.Pad.Midplane = 0 + doc.Pad.Offset = 0 + doc.recompute() + doc.Sketch.Visibility = False + + doc.addObject('PartDesign::Body','TNP_Test_Body_Second') + doc.getObject('TNP_Test_Body_Second').Label = 'TNP_Test_Body_Second' + doc.recompute() + obj = doc.getObject('TNP_Test_Body_Second').newObject('PartDesign::ShapeBinder','ShapeBinder') + obj.Support = (doc.getObject("TNP_Test_Body_SubShape"), [u'Face6']) + doc.recompute() + doc.getObject('TNP_Test_Body_Second').newObject('Sketcher::SketchObject','Sketch001') + doc.getObject('Sketch001').AttachmentSupport = (doc.getObject('ShapeBinder'),['']) + doc.getObject('Sketch001').MapMode = 'FlatFace' + doc.recompute() + + geoList = [] + geoList.append(Part.Circle(App.Vector(14.725412, 16.666899, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 2.162720)) + doc.getObject('Sketch001').addGeometry(geoList,False) + del geoList + + doc.recompute() + doc.getObject('TNP_Test_Body_Second').newObject('PartDesign::Pad','Pad001') + doc.getObject('Pad001').Profile = doc.getObject('Sketch001') + doc.getObject('Pad001').Length = 10 + doc.recompute() + doc.getObject('Pad001').ReferenceAxis = (doc.getObject('Sketch001'),['N_Axis']) + doc.getObject('Sketch001').Visibility = False + doc.recompute() + doc.getObject('Pad001').Length = 10.000000 + doc.getObject('Pad001').TaperAngle = 0.000000 + doc.getObject('Pad001').UseCustomVector = 0 + doc.getObject('Pad001').Direction = (0, 0, 1) + doc.getObject('Pad001').ReferenceAxis = (doc.getObject('Sketch001'), ['N_Axis']) + doc.getObject('Pad001').AlongSketchNormal = 1 + doc.getObject('Pad001').Type = 0 + doc.getObject('Pad001').UpToFace = None + doc.getObject('Pad001').Reversed = 0 + doc.getObject('Pad001').Midplane = 0 + doc.getObject('Pad001').Offset = 0 + doc.recompute() + doc.getObject('ShapeBinder').Visibility = False + doc.getObject('Sketch001').Visibility = False + + geoList = [] + geoList.append(Part.LineSegment(App.Vector(28.380075, 21.486303, 0.000000),App.Vector(28.380075, 15.462212, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(28.380075, 15.462212, 0.000000),App.Vector(32.797741, 15.462212, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(32.797741, 15.462212, 0.000000),App.Vector(32.797741, 21.486303, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(32.797741, 21.486303, 0.000000),App.Vector(28.380075, 21.486303, 0.000000))) + doc.Sketch.addGeometry(geoList,False) + del geoList + + constraintList = [] + constraintList.append(Sketcher.Constraint('Coincident', 4, 2, 5, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 5, 2, 6, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 6, 2, 7, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 7, 2, 4, 1)) + constraintList.append(Sketcher.Constraint('Vertical', 4)) + constraintList.append(Sketcher.Constraint('Vertical', 6)) + constraintList.append(Sketcher.Constraint('Horizontal', 5)) + constraintList.append(Sketcher.Constraint('Horizontal', 7)) + doc.Sketch.addConstraint(constraintList) + del constraintList + + doc.recompute() + # Assert + if self.Body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023. + return + self.assertEqual(self.Body.Shape.BoundBox.XMin,0) + self.assertEqual(self.Body.Shape.BoundBox.YMin,0) + self.assertEqual(self.Body.Shape.BoundBox.ZMin,0) + self.assertEqual(self.Body.Shape.BoundBox.XMax,31.37) + self.assertEqual(self.Body.Shape.BoundBox.YMax,25.2) + self.assertEqual(self.Body.Shape.BoundBox.ZMax,20) + + def testSubShapeBinder(self): + doc = self.Doc + doc.addObject('PartDesign::Body','Body') + doc.Body.Label = 'Body' + doc.recompute() + doc.Body.newObject('Sketcher::SketchObject','Sketch') + doc.Sketch.AttachmentSupport = (doc.getObject('XY_Plane'),['']) + doc.Sketch.MapMode = 'FlatFace' + doc.recompute() + + geoList = [] + geoList.append(Part.LineSegment(App.Vector(0.000000, 0.000000, 0.000000),App.Vector(35.000000, 0.000000, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(35.000000, 0.000000, 0.000000),App.Vector(35.000000, 25.000000, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(35.000000, 25.000000, 0.000000),App.Vector(0.000000, 25.000000, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(0.000000, 25.000000, 0.000000),App.Vector(0.000000, 0.000000, 0.000000))) + doc.Sketch.addGeometry(geoList,False) + del geoList + + constraintList = [] + constraintList.append(Sketcher.Constraint('Coincident', 0, 2, 1, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 1, 2, 2, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 2, 2, 3, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 3, 2, 0, 1)) + constraintList.append(Sketcher.Constraint('Horizontal', 0)) + constraintList.append(Sketcher.Constraint('Horizontal', 2)) + constraintList.append(Sketcher.Constraint('Vertical', 1)) + constraintList.append(Sketcher.Constraint('Vertical', 3)) + doc.Sketch.addConstraint(constraintList) + del constraintList + + doc.Sketch.addConstraint(Sketcher.Constraint('Distance',1,1,3,2,35.000000)) + doc.Sketch.addConstraint(Sketcher.Constraint('Distance',0,1,2,2,25.000000)) + doc.Sketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, -1, 1)) + + + doc.recompute() + self.Body.newObject('PartDesign::Pad','Pad') + doc.Pad.Profile = doc.Sketch + doc.Pad.Length = 10 + doc.recompute() + doc.Pad.ReferenceAxis = (doc.Sketch,['N_Axis']) + doc.Sketch.Visibility = False + doc.Pad.Length = 10.000000 + doc.Pad.TaperAngle = 0.000000 + doc.Pad.UseCustomVector = 0 + doc.Pad.Direction = (0, 0, 1) + doc.Pad.ReferenceAxis = (doc.Sketch, ['N_Axis']) + doc.Pad.AlongSketchNormal = 1 + doc.Pad.Type = 0 + doc.Pad.UpToFace = None + doc.Pad.Reversed = 0 + doc.Pad.Midplane = 0 + doc.Pad.Offset = 0 + doc.recompute() + doc.Sketch.Visibility = False + doc.addObject('PartDesign::Body','Body001') + doc.getObject('Body001').Label = 'Body' + doc.recompute() + binder = doc.getObject('Body001').newObject('PartDesign::SubShapeBinder','Binder') + binder.Support = self.Body + doc.getObject('Body001').newObject('Sketcher::SketchObject','Sketch001') + doc.getObject('Sketch001').AttachmentSupport = (doc.getObject('Binder'),['Face6',]) + doc.getObject('Sketch001').MapMode = 'FlatFace' + doc.recompute() + + geoList = [] + geoList.append(Part.Circle(App.Vector(16.566162, 13.537925, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 2.197371)) + doc.getObject('Sketch001').addGeometry(geoList,False) + del geoList + + doc.recompute() + ### Begin command PartDesign_Pad + doc.getObject('Body001').newObject('PartDesign::Pad','Pad001') + doc.Pad001.Profile = doc.getObject('Sketch001') + doc.Pad001.Length = 10 + doc.recompute() + doc.Pad001.ReferenceAxis = (doc.getObject('Sketch001'),['N_Axis']) + doc.getObject('Sketch001').Visibility = False + doc.recompute() + doc.Pad001.Length = 10.000000 + doc.Pad001.TaperAngle = 0.000000 + doc.Pad001.UseCustomVector = 0 + doc.Pad001.Direction = (0, 0, 1) + doc.Pad001.ReferenceAxis = (doc.getObject('Sketch001'), ['N_Axis']) + doc.Pad001.AlongSketchNormal = 1 + doc.Pad001.Type = 0 + doc.Pad001.UpToFace = None + doc.Pad001.Reversed = 0 + doc.Pad001.Midplane = 0 + doc.Pad001.Offset = 0 + doc.recompute() + doc.getObject('Binder').Visibility = False + doc.getObject('Sketch001').Visibility = False + + geoList = [] + geoList.append(Part.LineSegment(App.Vector(30.009926, 21.026653, 0.000000),App.Vector(30.009926, 16.425089, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(30.009926, 16.425089, 0.000000),App.Vector(31.994911, 16.425089, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(31.994911, 16.425089, 0.000000),App.Vector(31.994911, 21.026653, 0.000000))) + geoList.append(Part.LineSegment(App.Vector(31.994911, 21.026653, 0.000000),App.Vector(30.009926, 21.026653, 0.000000))) + doc.Sketch.addGeometry(geoList,False) + del geoList + + constraintList = [] + constraintList.append(Sketcher.Constraint('Coincident', 4, 2, 5, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 5, 2, 6, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 6, 2, 7, 1)) + constraintList.append(Sketcher.Constraint('Coincident', 7, 2, 4, 1)) + constraintList.append(Sketcher.Constraint('Vertical', 4)) + constraintList.append(Sketcher.Constraint('Vertical', 6)) + constraintList.append(Sketcher.Constraint('Horizontal', 5)) + constraintList.append(Sketcher.Constraint('Horizontal', 7)) + doc.Sketch.addConstraint(constraintList) + del constraintList + + doc.recompute() + # Assert + if self.Body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023. + return + self.assertEqual(self.Body.Shape.BoundBox.XMin,0) + self.assertEqual(self.Body.Shape.BoundBox.YMin,0) + self.assertEqual(self.Body.Shape.BoundBox.ZMin,0) + self.assertEqual(self.Body.Shape.BoundBox.XMax,31.37) + self.assertEqual(self.Body.Shape.BoundBox.YMax,25.2) + self.assertEqual(self.Body.Shape.BoundBox.ZMax,20) def create_t_sketch(self): From 71d96bccaca0ecb11f74063843b6ab0a99a3049e Mon Sep 17 00:00:00 2001 From: bgbsww Date: Tue, 7 May 2024 11:50:08 -0400 Subject: [PATCH 2/2] Fix tests, slip in TNP defense --- src/App/ComplexGeoData.cpp | 2 +- src/Mod/Part/App/PartFeature.cpp | 3 +- .../TestTopologicalNamingProblem.py | 167 +++++++++++------- tests/src/Mod/Part/App/TopoShapeExpansion.cpp | 59 +++---- 4 files changed, 133 insertions(+), 98 deletions(-) diff --git a/src/App/ComplexGeoData.cpp b/src/App/ComplexGeoData.cpp index 9de14332f7..a085171c96 100644 --- a/src/App/ComplexGeoData.cpp +++ b/src/App/ComplexGeoData.cpp @@ -685,7 +685,7 @@ void ComplexGeoData::dumpElementMap(std::ostream& stream) const { auto map = getElementMap(); std::sort(map.begin(), map.end()); - for ( auto element : map ) { + for ( auto& element : map ) { stream << element.index << " : " << element.name << std::endl; } } diff --git a/src/Mod/Part/App/PartFeature.cpp b/src/Mod/Part/App/PartFeature.cpp index ad85d1b1ea..99341d5622 100644 --- a/src/Mod/Part/App/PartFeature.cpp +++ b/src/Mod/Part/App/PartFeature.cpp @@ -1014,7 +1014,7 @@ TopoShape Feature::getTopoShape(const App::DocumentObject* obj, noElementMap, hiddens, lastLink); - +#ifdef FC_USE_TNP_FIX if (needSubElement && shape.shapeType(true) == TopAbs_COMPOUND) { if (shape.countSubShapes(TopAbs_SOLID) == 1) shape = shape.getSubTopoShape(TopAbs_SOLID, 1); @@ -1031,6 +1031,7 @@ TopoShape Feature::getTopoShape(const App::DocumentObject* obj, else if (shape.countSubShapes(TopAbs_VERTEX) == 1) shape = shape.getSubTopoShape(TopAbs_VERTEX, 1); } +#endif Base::Matrix4D topMat; if (pmat || transform) { // Obtain top level transformation diff --git a/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py b/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py index dbe1ad5269..5324e60f5d 100644 --- a/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py +++ b/src/Mod/PartDesign/PartDesignTests/TestTopologicalNamingProblem.py @@ -931,7 +931,10 @@ class TestTopologicalNamingProblem(unittest.TestCase): area1 = self.Pad.Shape.Area # Act - self.Doc.getObject('Sketch').fillet(2,3,App.Vector(6.673934,25.000000,0),App.Vector(0.000000,21.980343,0),4.740471,True,True,False) + self.Doc.getObject('Sketch').fillet(2,3, + App.Vector(6.673934,25.000000,0), + App.Vector(0.000000,21.980343,0), + 4.740471,True,True,False) self.Doc.recompute() area2 = self.Pad.Shape.Area @@ -948,21 +951,29 @@ class TestTopologicalNamingProblem(unittest.TestCase): def testShapeBinder(self): doc = self.Doc - doc.addObject('PartDesign::Body','TNP_Test_Body_SubShape') + self.Body = doc.addObject('PartDesign::Body', 'TNP_Test_Body_SubShape') doc.getObject('TNP_Test_Body_SubShape').Label = 'TNP_Test_Body_SubShape' doc.recompute() - doc.getObject('TNP_Test_Body_SubShape').newObject('Sketcher::SketchObject','Sketch') - doc.Sketch.AttachmentSupport = (doc.getObject('XY_Plane'),['']) + doc.getObject('TNP_Test_Body_SubShape').newObject('Sketcher::SketchObject', 'Sketch') + doc.Sketch.AttachmentSupport = (doc.getObject('XY_Plane'), ['']) doc.Sketch.MapMode = 'FlatFace' doc.recompute() geoList = [] - geoList.append(Part.LineSegment(App.Vector(0.000000, 0.000000, 0.000000),App.Vector(35.000000, 0.000000, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(35.000000, 0.000000, 0.000000),App.Vector(35.000000, 25.000000, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(35.000000, 25.000000, 0.000000),App.Vector(0.000000, 25.000000, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(0.000000, 25.000000, 0.000000),App.Vector(0.000000, 0.000000, 0.000000))) - doc.Sketch.addGeometry(geoList,False) + geoList.append( + Part.LineSegment(App.Vector(0.000000, 0.000000, 0.000000), + App.Vector(35.000000, 0.000000, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(35.000000, 0.000000, 0.000000), + App.Vector(35.000000, 25.000000, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(35.000000, 25.000000, 0.000000), + App.Vector(0.000000, 25.000000, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(0.000000, 25.000000, 0.000000), + App.Vector(0.000000, 0.000000, 0.000000))) + doc.Sketch.addGeometry(geoList, False) del geoList constraintList = [] @@ -977,18 +988,17 @@ class TestTopologicalNamingProblem(unittest.TestCase): doc.Sketch.addConstraint(constraintList) del constraintList - doc.Sketch.addConstraint(Sketcher.Constraint('Distance',1,1,3,2,35.000000)) - doc.Sketch.addConstraint(Sketcher.Constraint('Distance',0,1,2,2,25.000000)) + doc.Sketch.addConstraint(Sketcher.Constraint('Distance', 1, 1, 3, 2, 35.000000)) + doc.Sketch.addConstraint(Sketcher.Constraint('Distance', 0, 1, 2, 2, 25.000000)) doc.Sketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, -1, 1)) - doc.recompute() - doc.getObject('TNP_Test_Body_SubShape').newObject('PartDesign::Pad','Pad') + doc.getObject('TNP_Test_Body_SubShape').newObject('PartDesign::Pad', 'Pad') doc.Pad.Profile = doc.Sketch doc.Pad.Length = 10 doc.recompute() - doc.Pad.ReferenceAxis = (doc.Sketch,['N_Axis']) + doc.Pad.ReferenceAxis = (doc.Sketch, ['N_Axis']) doc.Sketch.Visibility = False doc.recompute() doc.Pad.Length = 10.000000 @@ -1005,28 +1015,30 @@ class TestTopologicalNamingProblem(unittest.TestCase): doc.recompute() doc.Sketch.Visibility = False - doc.addObject('PartDesign::Body','TNP_Test_Body_Second') + doc.addObject('PartDesign::Body', 'TNP_Test_Body_Second') doc.getObject('TNP_Test_Body_Second').Label = 'TNP_Test_Body_Second' doc.recompute() - obj = doc.getObject('TNP_Test_Body_Second').newObject('PartDesign::ShapeBinder','ShapeBinder') + obj = doc.getObject('TNP_Test_Body_Second').newObject('PartDesign::ShapeBinder', 'ShapeBinder') obj.Support = (doc.getObject("TNP_Test_Body_SubShape"), [u'Face6']) doc.recompute() - doc.getObject('TNP_Test_Body_Second').newObject('Sketcher::SketchObject','Sketch001') - doc.getObject('Sketch001').AttachmentSupport = (doc.getObject('ShapeBinder'),['']) + doc.getObject('TNP_Test_Body_Second').newObject('Sketcher::SketchObject', 'Sketch001') + doc.getObject('Sketch001').AttachmentSupport = (doc.getObject('ShapeBinder'), ['']) doc.getObject('Sketch001').MapMode = 'FlatFace' doc.recompute() geoList = [] - geoList.append(Part.Circle(App.Vector(14.725412, 16.666899, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 2.162720)) - doc.getObject('Sketch001').addGeometry(geoList,False) + geoList.append( + Part.Circle(App.Vector(14.725412, 16.666899, 0.000000), + App.Vector(0.000000, 0.000000, 1.000000), 2.162720)) + doc.getObject('Sketch001').addGeometry(geoList, False) del geoList doc.recompute() - doc.getObject('TNP_Test_Body_Second').newObject('PartDesign::Pad','Pad001') + doc.getObject('TNP_Test_Body_Second').newObject('PartDesign::Pad', 'Pad001') doc.getObject('Pad001').Profile = doc.getObject('Sketch001') doc.getObject('Pad001').Length = 10 doc.recompute() - doc.getObject('Pad001').ReferenceAxis = (doc.getObject('Sketch001'),['N_Axis']) + doc.getObject('Pad001').ReferenceAxis = (doc.getObject('Sketch001'), ['N_Axis']) doc.getObject('Sketch001').Visibility = False doc.recompute() doc.getObject('Pad001').Length = 10.000000 @@ -1045,11 +1057,19 @@ class TestTopologicalNamingProblem(unittest.TestCase): doc.getObject('Sketch001').Visibility = False geoList = [] - geoList.append(Part.LineSegment(App.Vector(28.380075, 21.486303, 0.000000),App.Vector(28.380075, 15.462212, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(28.380075, 15.462212, 0.000000),App.Vector(32.797741, 15.462212, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(32.797741, 15.462212, 0.000000),App.Vector(32.797741, 21.486303, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(32.797741, 21.486303, 0.000000),App.Vector(28.380075, 21.486303, 0.000000))) - doc.Sketch.addGeometry(geoList,False) + geoList.append( + Part.LineSegment(App.Vector(28.380075, 21.486303, 0.000000), + App.Vector(28.380075, 15.462212, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(28.380075, 15.462212, 0.000000), + App.Vector(32.797741, 15.462212, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(32.797741, 15.462212, 0.000000), + App.Vector(32.797741, 21.486303, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(32.797741, 21.486303, 0.000000), + App.Vector(28.380075, 21.486303, 0.000000))) + doc.Sketch.addGeometry(geoList, False) del geoList constraintList = [] @@ -1068,29 +1088,37 @@ class TestTopologicalNamingProblem(unittest.TestCase): # Assert if self.Body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023. return - self.assertEqual(self.Body.Shape.BoundBox.XMin,0) - self.assertEqual(self.Body.Shape.BoundBox.YMin,0) - self.assertEqual(self.Body.Shape.BoundBox.ZMin,0) - self.assertEqual(self.Body.Shape.BoundBox.XMax,31.37) - self.assertEqual(self.Body.Shape.BoundBox.YMax,25.2) - self.assertEqual(self.Body.Shape.BoundBox.ZMax,20) + self.assertEqual(self.Body.Shape.BoundBox.XMin, 0) + self.assertEqual(self.Body.Shape.BoundBox.YMin, 0) + self.assertEqual(self.Body.Shape.BoundBox.ZMin, 0) + self.assertEqual(self.Body.Shape.BoundBox.XMax, 31.37) + self.assertEqual(self.Body.Shape.BoundBox.YMax, 25.2) + self.assertEqual(self.Body.Shape.BoundBox.ZMax, 20) def testSubShapeBinder(self): doc = self.Doc - doc.addObject('PartDesign::Body','Body') + self.Body = doc.addObject('PartDesign::Body', 'Body') doc.Body.Label = 'Body' doc.recompute() - doc.Body.newObject('Sketcher::SketchObject','Sketch') - doc.Sketch.AttachmentSupport = (doc.getObject('XY_Plane'),['']) + doc.Body.newObject('Sketcher::SketchObject', 'Sketch') + doc.Sketch.AttachmentSupport = (doc.getObject('XY_Plane'), ['']) doc.Sketch.MapMode = 'FlatFace' doc.recompute() geoList = [] - geoList.append(Part.LineSegment(App.Vector(0.000000, 0.000000, 0.000000),App.Vector(35.000000, 0.000000, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(35.000000, 0.000000, 0.000000),App.Vector(35.000000, 25.000000, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(35.000000, 25.000000, 0.000000),App.Vector(0.000000, 25.000000, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(0.000000, 25.000000, 0.000000),App.Vector(0.000000, 0.000000, 0.000000))) - doc.Sketch.addGeometry(geoList,False) + geoList.append( + Part.LineSegment(App.Vector(0.000000, 0.000000, 0.000000), + App.Vector(35.000000, 0.000000, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(35.000000, 0.000000, 0.000000), + App.Vector(35.000000, 25.000000, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(35.000000, 25.000000, 0.000000), + App.Vector(0.000000, 25.000000, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(0.000000, 25.000000, 0.000000), + App.Vector(0.000000, 0.000000, 0.000000))) + doc.Sketch.addGeometry(geoList, False) del geoList constraintList = [] @@ -1105,17 +1133,16 @@ class TestTopologicalNamingProblem(unittest.TestCase): doc.Sketch.addConstraint(constraintList) del constraintList - doc.Sketch.addConstraint(Sketcher.Constraint('Distance',1,1,3,2,35.000000)) - doc.Sketch.addConstraint(Sketcher.Constraint('Distance',0,1,2,2,25.000000)) + doc.Sketch.addConstraint(Sketcher.Constraint('Distance', 1, 1, 3, 2, 35.000000)) + doc.Sketch.addConstraint(Sketcher.Constraint('Distance', 0, 1, 2, 2, 25.000000)) doc.Sketch.addConstraint(Sketcher.Constraint('Coincident', 0, 1, -1, 1)) - doc.recompute() - self.Body.newObject('PartDesign::Pad','Pad') + doc.Body.newObject('PartDesign::Pad', 'Pad') doc.Pad.Profile = doc.Sketch doc.Pad.Length = 10 doc.recompute() - doc.Pad.ReferenceAxis = (doc.Sketch,['N_Axis']) + doc.Pad.ReferenceAxis = (doc.Sketch, ['N_Axis']) doc.Sketch.Visibility = False doc.Pad.Length = 10.000000 doc.Pad.TaperAngle = 0.000000 @@ -1130,28 +1157,30 @@ class TestTopologicalNamingProblem(unittest.TestCase): doc.Pad.Offset = 0 doc.recompute() doc.Sketch.Visibility = False - doc.addObject('PartDesign::Body','Body001') + doc.addObject('PartDesign::Body', 'Body001') doc.getObject('Body001').Label = 'Body' doc.recompute() - binder = doc.getObject('Body001').newObject('PartDesign::SubShapeBinder','Binder') + binder = doc.getObject('Body001').newObject('PartDesign::SubShapeBinder', 'Binder') binder.Support = self.Body - doc.getObject('Body001').newObject('Sketcher::SketchObject','Sketch001') - doc.getObject('Sketch001').AttachmentSupport = (doc.getObject('Binder'),['Face6',]) + doc.getObject('Body001').newObject('Sketcher::SketchObject', 'Sketch001') + doc.getObject('Sketch001').AttachmentSupport = (doc.getObject('Binder'), ['Face6', ]) doc.getObject('Sketch001').MapMode = 'FlatFace' doc.recompute() geoList = [] - geoList.append(Part.Circle(App.Vector(16.566162, 13.537925, 0.000000), App.Vector(0.000000, 0.000000, 1.000000), 2.197371)) - doc.getObject('Sketch001').addGeometry(geoList,False) + geoList.append( + Part.Circle(App.Vector(16.566162, 13.537925, 0.000000), + App.Vector(0.000000, 0.000000, 1.000000), 2.197371)) + doc.getObject('Sketch001').addGeometry(geoList, False) del geoList doc.recompute() ### Begin command PartDesign_Pad - doc.getObject('Body001').newObject('PartDesign::Pad','Pad001') + doc.getObject('Body001').newObject('PartDesign::Pad', 'Pad001') doc.Pad001.Profile = doc.getObject('Sketch001') doc.Pad001.Length = 10 doc.recompute() - doc.Pad001.ReferenceAxis = (doc.getObject('Sketch001'),['N_Axis']) + doc.Pad001.ReferenceAxis = (doc.getObject('Sketch001'), ['N_Axis']) doc.getObject('Sketch001').Visibility = False doc.recompute() doc.Pad001.Length = 10.000000 @@ -1170,11 +1199,19 @@ class TestTopologicalNamingProblem(unittest.TestCase): doc.getObject('Sketch001').Visibility = False geoList = [] - geoList.append(Part.LineSegment(App.Vector(30.009926, 21.026653, 0.000000),App.Vector(30.009926, 16.425089, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(30.009926, 16.425089, 0.000000),App.Vector(31.994911, 16.425089, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(31.994911, 16.425089, 0.000000),App.Vector(31.994911, 21.026653, 0.000000))) - geoList.append(Part.LineSegment(App.Vector(31.994911, 21.026653, 0.000000),App.Vector(30.009926, 21.026653, 0.000000))) - doc.Sketch.addGeometry(geoList,False) + geoList.append( + Part.LineSegment(App.Vector(30.009926, 21.026653, 0.000000), + App.Vector(30.009926, 16.425089, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(30.009926, 16.425089, 0.000000), + App.Vector(31.994911, 16.425089, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(31.994911, 16.425089, 0.000000), + App.Vector(31.994911, 21.026653, 0.000000))) + geoList.append( + Part.LineSegment(App.Vector(31.994911, 21.026653, 0.000000), + App.Vector(30.009926, 21.026653, 0.000000))) + doc.Sketch.addGeometry(geoList, False) del geoList constraintList = [] @@ -1193,12 +1230,12 @@ class TestTopologicalNamingProblem(unittest.TestCase): # Assert if self.Body.Shape.ElementMapVersion == "": # Should be '4' as of Mar 2023. return - self.assertEqual(self.Body.Shape.BoundBox.XMin,0) - self.assertEqual(self.Body.Shape.BoundBox.YMin,0) - self.assertEqual(self.Body.Shape.BoundBox.ZMin,0) - self.assertEqual(self.Body.Shape.BoundBox.XMax,31.37) - self.assertEqual(self.Body.Shape.BoundBox.YMax,25.2) - self.assertEqual(self.Body.Shape.BoundBox.ZMax,20) + self.assertEqual(self.Body.Shape.BoundBox.XMin, 0) + self.assertEqual(self.Body.Shape.BoundBox.YMin, 0) + self.assertEqual(self.Body.Shape.BoundBox.ZMin, 0) + self.assertEqual(self.Body.Shape.BoundBox.XMax, 31.37) + self.assertEqual(self.Body.Shape.BoundBox.YMax, 25.2) + self.assertEqual(self.Body.Shape.BoundBox.ZMax, 20) def create_t_sketch(self): diff --git a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp index 36ca66be35..810bea6c70 100644 --- a/tests/src/Mod/Part/App/TopoShapeExpansion.cpp +++ b/tests/src/Mod/Part/App/TopoShapeExpansion.cpp @@ -2794,37 +2794,34 @@ TEST_F(TopoShapeExpansionTest, makeElementPrism) EXPECT_TRUE(PartTestHelpers::boxesMatch(bb, Base::BoundBox3d(0.0, 0.0, 0.0, 0.75, 1.0, 1.0))); EXPECT_FLOAT_EQ(getVolume(result.getShape()), 0.75); // Assert elementMap is correct - EXPECT_TRUE(elementsMatch( - result, - { - "Edge1;:G;XTR;:H2:7,F", - "Edge1;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E", - "Edge1;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:L(Edge2;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E|Edge3;:G;" - "XTR;:H2:7,F;:U;XTR;:H2:7,E|Edge4;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E);XTR;:H2:74,F", - "Edge1;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:U2;XTR;:H2:8,V", - "Edge1;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:U;XTR;:H2:7,V", - "Edge1;:H2,E", - "Edge2;:G;XTR;:H2:7,F", - "Edge2;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E", - "Edge2;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:U;XTR;:H2:7,V", - "Edge2;:H2,E", - "Edge3;:G;XTR;:H2:7,F", - "Edge3;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E", - "Edge3;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:U2;XTR;:H2:8,V", - "Edge3;:H2,E", - "Edge4;:G;XTR;:H2:7,F", - "Edge4;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E", - "Edge4;:H2,E", - "Face1;:H2,F", - "Vertex1;:G;XTR;:H2:7,E", - "Vertex1;:H2,V", - "Vertex2;:G;XTR;:H2:7,E", - "Vertex2;:H2,V", - "Vertex3;:G;XTR;:H2:7,E", - "Vertex3;:H2,V", - "Vertex4;:G;XTR;:H2:7,E", - "Vertex4;:H2,V", - })); + EXPECT_TRUE(elementsMatch(result, + { + "Edge1;:G;XTR;:H2:7,F", + "Edge1;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E", + "Edge1;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:U2;XTR;:H2:8,V", + "Edge1;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:U;XTR;:H2:7,V", + "Edge1;:H2,E", + "Edge2;:G;XTR;:H2:7,F", + "Edge2;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E", + "Edge2;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:U;XTR;:H2:7,V", + "Edge2;:H2,E", + "Edge3;:G;XTR;:H2:7,F", + "Edge3;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E", + "Edge3;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E;:U2;XTR;:H2:8,V", + "Edge3;:H2,E", + "Edge4;:G;XTR;:H2:7,F", + "Edge4;:G;XTR;:H2:7,F;:U;XTR;:H2:7,E", + "Edge4;:H2,E", + "Face1;:H2,F", + "Vertex1;:G;XTR;:H2:7,E", + "Vertex1;:H2,V", + "Vertex2;:G;XTR;:H2:7,E", + "Vertex2;:H2,V", + "Vertex3;:G;XTR;:H2:7,E", + "Vertex3;:H2,V", + "Vertex4;:G;XTR;:H2:7,E", + "Vertex4;:H2,V", + })); } TEST_F(TopoShapeExpansionTest, makeElementPrismUntil)