From 8c08549f5a3ece2e41a91dc7bbd5247613d6251b Mon Sep 17 00:00:00 2001 From: bgbsww <120601209+bgbsww@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:50:18 -0400 Subject: [PATCH] Update to Toposhape versions and fix shapebinder references with test (#16036) * Update to Toposhape versions and fix shapebinder references with test * Update src/Mod/PartDesign/PartDesignTests/TestShapeBinder.py --------- Co-authored-by: Chris Hennes --- src/Mod/Part/App/FeatureRevolution.cpp | 2 +- src/Mod/Part/App/FeatureScale.cpp | 2 +- src/Mod/Part/App/PartFeatures.cpp | 2 +- src/Mod/PartDesign/App/FeatureSketchBased.cpp | 3 +- .../PartDesignTests/TestShapeBinder.py | 39 +++++++++++++++++++ src/Mod/TechDraw/App/ShapeExtractor.cpp | 4 +- 6 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/Mod/Part/App/FeatureRevolution.cpp b/src/Mod/Part/App/FeatureRevolution.cpp index 31abaa8d7b..7dded5eb62 100644 --- a/src/Mod/Part/App/FeatureRevolution.cpp +++ b/src/Mod/Part/App/FeatureRevolution.cpp @@ -148,7 +148,7 @@ App::DocumentObjectExecReturn *Revolution::execute() angle = angle_edge; //apply "midplane" symmetry - TopoShape sourceShape = Feature::getShape(link); + TopoShape sourceShape = Feature::getTopoShape(link); if (Symmetric.getValue()) { //rotate source shape backwards by half angle, to make resulting revolution symmetric to the profile gp_Trsf mov; diff --git a/src/Mod/Part/App/FeatureScale.cpp b/src/Mod/Part/App/FeatureScale.cpp index d29e8342c1..8e30efc9a5 100644 --- a/src/Mod/Part/App/FeatureScale.cpp +++ b/src/Mod/Part/App/FeatureScale.cpp @@ -151,7 +151,7 @@ App::DocumentObjectExecReturn* Scale::execute() try { Scale::ScaleParameters params = computeFinalParameters(); - TopoShape result = scaleShape(Feature::getShape(link), params); + TopoShape result = scaleShape(Feature::getTopoShape(link), params); this->Shape.setValue(result); return App::DocumentObject::StdReturn; } diff --git a/src/Mod/Part/App/PartFeatures.cpp b/src/Mod/Part/App/PartFeatures.cpp index 6992986bf8..b2360f9119 100644 --- a/src/Mod/Part/App/PartFeatures.cpp +++ b/src/Mod/Part/App/PartFeatures.cpp @@ -898,7 +898,7 @@ Reverse::Reverse() App::DocumentObjectExecReturn* Reverse::execute() { App::DocumentObject* source = Source.getValue(); - Part::TopoShape topoShape = Part::Feature::getShape(source); + Part::TopoShape topoShape = Part::Feature::getTopoShape(source); if (topoShape.isNull()) { return new App::DocumentObjectExecReturn("No part object linked."); } diff --git a/src/Mod/PartDesign/App/FeatureSketchBased.cpp b/src/Mod/PartDesign/App/FeatureSketchBased.cpp index 522edc0529..37b86ea1aa 100644 --- a/src/Mod/PartDesign/App/FeatureSketchBased.cpp +++ b/src/Mod/PartDesign/App/FeatureSketchBased.cpp @@ -758,7 +758,8 @@ void ProfileBased::getFaceFromLinkSub(TopoDS_Face& upToFace, const App::Property throw Base::TypeError("SketchBased: Must be face of a feature"); Part::TopoShape baseShape = static_cast(ref)->Shape.getShape(); - if (subStrings.empty() || subStrings[0].empty()) + // Allow an empty sub here - example is a sketch reference (no sub) that creates a face. + if (subStrings.empty() ) throw Base::ValueError("SketchBased: No face selected"); // TODO: Check for multiple UpToFaces? diff --git a/src/Mod/PartDesign/PartDesignTests/TestShapeBinder.py b/src/Mod/PartDesign/PartDesignTests/TestShapeBinder.py index 57fab4470b..87ab19b2b7 100644 --- a/src/Mod/PartDesign/PartDesignTests/TestShapeBinder.py +++ b/src/Mod/PartDesign/PartDesignTests/TestShapeBinder.py @@ -20,6 +20,7 @@ #*************************************************************************** import unittest +import math import FreeCAD from FreeCAD import Base @@ -132,3 +133,41 @@ class TestSubShapeBinder(unittest.TestCase): nor1 = binder1.Shape.Face1.normalAt(0,0) nor2 = binder2.Shape.Face1.normalAt(0,0) self.assertAlmostEqual(nor1.getAngle(nor2), 0.0, 2) + + def testBinderWithRevolution(self): + doc = self.Doc + body = doc.addObject('PartDesign::Body', 'Body') + doc.recompute() + sketch = body.newObject('Sketcher::SketchObject', 'Sketch') + geoList = [] + geoList.append(Part.LineSegment(Base.Vector(10, 10, 0), Base.Vector(30, 10, 0))) + geoList.append(Part.LineSegment(Base.Vector(30, 10, 0), Base.Vector(30, 15, 0))) + geoList.append(Part.LineSegment(Base.Vector(30, 15, 0), Base.Vector(10, 15, 0))) + geoList.append(Part.LineSegment(Base.Vector(10, 15, 0), Base.Vector(10, 10, 0))) + 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)) + sketch.addConstraint(constraintList) + del constraintList + doc.recompute() + binder = body.newObject('PartDesign::SubShapeBinder', 'Binder') + binder.Support = sketch + revolution = body.newObject('PartDesign::Revolution', 'Revolution') + revolution.Profile = (binder, ['', ]) + revolution.ReferenceAxis = (doc.getObject('Y_Axis'), ['']) + revolution.Angle = 360.0 + revolution.Reversed = 1 + doc.recompute() + revolution.Angle2 = 60.0 + doc.recompute() + self.assertAlmostEqual(binder.Shape.Area, 100) + volume = 100 * math.pi * 2 * 20 + self.assertAlmostEqual(revolution.Shape.Volume, volume) diff --git a/src/Mod/TechDraw/App/ShapeExtractor.cpp b/src/Mod/TechDraw/App/ShapeExtractor.cpp index 794bc71b66..5619139724 100644 --- a/src/Mod/TechDraw/App/ShapeExtractor.cpp +++ b/src/Mod/TechDraw/App/ShapeExtractor.cpp @@ -225,7 +225,7 @@ std::vector ShapeExtractor::getXShapes(const App::Link* xLink) childNeedsTransform = true; } } - auto shape = Part::Feature::getShape(l); + auto shape = Part::Feature::getShape(l); // TODO: getTopoShape() ? Part::TopoShape ts(shape); if (ts.isInfinite()) { shape = stripInfiniteShapes(shape); @@ -506,7 +506,7 @@ Base::Vector3d ShapeExtractor::getLocation3dFromFeat(const App::DocumentObject* //! get the located and oriented version of docObj shape TopoDS_Shape ShapeExtractor::getLocatedShape(const App::DocumentObject* docObj) { - Part::TopoShape shape = Part::Feature::getShape(docObj); + Part::TopoShape shape = Part::Feature::getTopoShape(docObj); const Part::Feature* pf = dynamic_cast(docObj); if (pf) { shape.setPlacement(pf->globalPlacement());