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 <chennes@pioneerlibrarysystem.org>
This commit is contained in:
bgbsww
2024-08-26 11:50:18 -04:00
committed by GitHub
parent f10a8b63d1
commit 8c08549f5a
6 changed files with 46 additions and 6 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -898,7 +898,7 @@ Reverse::Reverse()
App::DocumentObjectExecReturn* Reverse::execute()
{
App::DocumentObject* source = Source.getValue<App::DocumentObject*>();
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.");
}

View File

@@ -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<Part::Feature*>(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?

View File

@@ -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)

View File

@@ -225,7 +225,7 @@ std::vector<TopoDS_Shape> 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<const Part::Feature*>(docObj);
if (pf) {
shape.setPlacement(pf->globalPlacement());