diff --git a/src/Mod/PartDesign/App/FeatureTransformed.cpp b/src/Mod/PartDesign/App/FeatureTransformed.cpp index 0156affa06..ac518d9da8 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.cpp +++ b/src/Mod/PartDesign/App/FeatureTransformed.cpp @@ -282,38 +282,15 @@ App::DocumentObjectExecReturn* Transformed::execute() gp_Trsf trsfInv = supportShape.getShape().Location().Transformation().Inverted(); supportShape.setTransform(Base::Matrix4D()); - TopoDS_Shape support = supportShape.getShape(); auto getTransformedCompShape = [&](const auto& origShape) { - TopTools_ListOfShape shapeTools; - std::vector shapes; - + std::vector shapes; + TopoShape shape = origShape; auto transformIter = transformations.cbegin(); - - // First transformation is skipped since it should not be part of the toolShape. - ++transformIter; - for (; transformIter != transformations.end(); ++transformIter) { - // Make an explicit copy of the shape because the "true" parameter to - // BRepBuilderAPI_Transform seems to be pretty broken - BRepBuilderAPI_Copy copy(origShape); - - TopoDS_Shape shape = copy.Shape(); - - BRepBuilderAPI_Transform mkTrf(shape, *transformIter, false); // No need to copy, now - if (!mkTrf.IsDone()) { - throw Base::CADKernelError(QT_TRANSLATE_NOOP("Exception", "Transformation failed")); - } - shape = mkTrf.Shape(); - - shapes.emplace_back(shape); + shapes.emplace_back(shape.makeElementTransform(*transformIter)); } - - for (const auto& shape : shapes) { - shapeTools.Append(shape); - } - - return shapeTools; + return shapes; }; switch (mode) { @@ -360,74 +337,41 @@ App::DocumentObjectExecReturn* Transformed::execute() #endif - TopoDS_Shape current = support; if (!fuseShape.isNull()) { - TopTools_ListOfShape shapeArguments; - shapeArguments.Append(current); - TopTools_ListOfShape shapeTools = getTransformedCompShape(fuseShape.getShape()); - if (!shapeTools.IsEmpty()) { - BRepAlgoAPI_Fuse mkBool; - mkBool.SetArguments(shapeArguments); - mkBool.SetTools(shapeTools); - mkBool.Build(); - if (!mkBool.IsDone()) { - return new App::DocumentObjectExecReturn( - QT_TRANSLATE_NOOP("Exception", "Boolean operation failed")); - } - current = mkBool.Shape(); - } + supportShape = supportShape.makeElementFuse(getTransformedCompShape(fuseShape.getShape())); } if (!cutShape.isNull()) { - TopTools_ListOfShape shapeArguments; - shapeArguments.Append(current); - TopTools_ListOfShape shapeTools = getTransformedCompShape(cutShape.getShape()); - if (!shapeTools.IsEmpty()) { - BRepAlgoAPI_Cut mkBool; - mkBool.SetArguments(shapeArguments); - mkBool.SetTools(shapeTools); - mkBool.Build(); - if (!mkBool.IsDone()) { - return new App::DocumentObjectExecReturn( - QT_TRANSLATE_NOOP("Exception", "Boolean operation failed")); - } - current = mkBool.Shape(); - } + supportShape = supportShape.makeElementCut(getTransformedCompShape(cutShape.getShape())); } - - support = current; // Use result of this operation for fuse/cut of next original } break; case Mode::TransformBody: { - TopTools_ListOfShape shapeArguments; - shapeArguments.Append(support); - TopTools_ListOfShape shapeTools = getTransformedCompShape(support); - if (!shapeTools.IsEmpty()) { - BRepAlgoAPI_Fuse mkBool; - mkBool.SetArguments(shapeArguments); - mkBool.SetTools(shapeTools); - mkBool.Build(); - if (!mkBool.IsDone()) { - return new App::DocumentObjectExecReturn( - QT_TRANSLATE_NOOP("Exception", "Boolean operation failed")); - } - support = mkBool.Shape(); - } + supportShape = supportShape.makeElementFuse(getTransformedCompShape(supportShape)); break; } } - support = refineShapeIfActive(support); - - if (!isSingleSolidRuleSatisfied(support)) { + supportShape = refineShapeIfActive((supportShape)); + if (!isSingleSolidRuleSatisfied(supportShape.getShape())) { Base::Console().Warning("Transformed: Result has multiple solids. Only keeping the first.\n"); } - this->Shape.setValue(getSolid(support)); // picking the first solid - rejected = getRemainingSolids(support); + this->Shape.setValue(getSolid(supportShape)); // picking the first solid + rejected = getRemainingSolids(supportShape.getShape()); return App::DocumentObject::StdReturn; } + +TopoShape Transformed::refineShapeIfActive(const TopoShape& oldShape) const +{ + if (this->Refine.getValue()) { + return oldShape.makeElementRefine(); + } + return oldShape; +} + +// Deprecated, prefer the TopoShape method TopoDS_Shape Transformed::refineShapeIfActive(const TopoDS_Shape& oldShape) const { if (this->Refine.getValue()) { diff --git a/src/Mod/PartDesign/App/FeatureTransformed.h b/src/Mod/PartDesign/App/FeatureTransformed.h index 18c93e8194..81ac61786f 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.h +++ b/src/Mod/PartDesign/App/FeatureTransformed.h @@ -106,6 +106,7 @@ protected: App::Property* prop) override; virtual void positionBySupport(); + TopoShape refineShapeIfActive(const TopoShape&) const; TopoDS_Shape refineShapeIfActive(const TopoDS_Shape&) const; static TopoDS_Shape getRemainingSolids(const TopoDS_Shape&); diff --git a/src/Mod/PartDesign/PartDesignTests/TestLinearPattern.py b/src/Mod/PartDesign/PartDesignTests/TestLinearPattern.py index e5a3c9f059..6e46e6dd44 100644 --- a/src/Mod/PartDesign/PartDesignTests/TestLinearPattern.py +++ b/src/Mod/PartDesign/PartDesignTests/TestLinearPattern.py @@ -44,6 +44,7 @@ class TestLinearPattern(unittest.TestCase): self.Body.addObject(self.LinearPattern) self.Doc.recompute() self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4) + self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26) def testYAxisLinearPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -61,6 +62,7 @@ class TestLinearPattern(unittest.TestCase): self.Body.addObject(self.LinearPattern) self.Doc.recompute() self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4) + self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26) def testZAxisLinearPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -78,6 +80,7 @@ class TestLinearPattern(unittest.TestCase): self.Body.addObject(self.LinearPattern) self.Doc.recompute() self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4) + self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26) def testNormalSketchAxisLinearPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -98,6 +101,7 @@ class TestLinearPattern(unittest.TestCase): self.Body.addObject(self.LinearPattern) self.Doc.recompute() self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4) + self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26) def testVerticalSketchAxisLinearPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -118,6 +122,7 @@ class TestLinearPattern(unittest.TestCase): self.Body.addObject(self.LinearPattern) self.Doc.recompute() self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4) + self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26) def testHorizontalSketchAxisLinearPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -138,6 +143,7 @@ class TestLinearPattern(unittest.TestCase): self.Body.addObject(self.LinearPattern) self.Doc.recompute() self.assertAlmostEqual(self.LinearPattern.Shape.Volume, 1e4) + self.assertEqual(self.LinearPattern.Shape.ElementMapSize,26) def tearDown(self): #closing doc diff --git a/src/Mod/PartDesign/PartDesignTests/TestPolarPattern.py b/src/Mod/PartDesign/PartDesignTests/TestPolarPattern.py index 6086a86204..afddf7cb57 100644 --- a/src/Mod/PartDesign/PartDesignTests/TestPolarPattern.py +++ b/src/Mod/PartDesign/PartDesignTests/TestPolarPattern.py @@ -44,6 +44,7 @@ class TestPolarPattern(unittest.TestCase): self.Body.addObject(self.PolarPattern) self.Doc.recompute() self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000) + self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26) def testYAxisPolarPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -61,6 +62,7 @@ class TestPolarPattern(unittest.TestCase): self.Body.addObject(self.PolarPattern) self.Doc.recompute() self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000) + self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26) def testZAxisPolarPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -78,6 +80,7 @@ class TestPolarPattern(unittest.TestCase): self.Body.addObject(self.PolarPattern) self.Doc.recompute() self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000) + self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26) def testNormalSketchAxisPolarPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -98,6 +101,7 @@ class TestPolarPattern(unittest.TestCase): self.Body.addObject(self.PolarPattern) self.Doc.recompute() self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000) + self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26) def testVerticalSketchAxisPolarPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -118,6 +122,7 @@ class TestPolarPattern(unittest.TestCase): self.Body.addObject(self.PolarPattern) self.Doc.recompute() self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000) + self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26) def testHorizontalSketchAxisPolarPattern(self): self.Body = self.Doc.addObject('PartDesign::Body','Body') @@ -138,6 +143,7 @@ class TestPolarPattern(unittest.TestCase): self.Body.addObject(self.PolarPattern) self.Doc.recompute() self.assertAlmostEqual(self.PolarPattern.Shape.Volume, 4000) + self.assertEqual(self.PolarPattern.Shape.ElementMapSize,26) def tearDown(self): #closing doc diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index f4d6f0fc0b..d4ed2daba1 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -11384,7 +11384,6 @@ App::ElementNamePair SketchObject::getElementName( index.appendToStringBuffer(ret.oldName); if (auto realName = convertInternalName(ret.oldName.c_str())) { Data::MappedElement mappedElement; - (void)realName; if (mapped) mappedElement = InternalShape.getShape().getElementName(name); else if (type == ElementNameType::Export)