diff --git a/src/Mod/PartDesign/App/Feature.cpp b/src/Mod/PartDesign/App/Feature.cpp index 45d53c5faf..0b283a3383 100644 --- a/src/Mod/PartDesign/App/Feature.cpp +++ b/src/Mod/PartDesign/App/Feature.cpp @@ -151,6 +151,12 @@ int Feature::countSolids(const TopoDS_Shape& shape, TopAbs_ShapeEnum type) return result; } +bool Feature::isSingleSolidRuleSatisfied(const TopoDS_Shape& shape, TopAbs_ShapeEnum type) +{ + int solidCount = countSolids(shape, type); + + return solidCount <= 1; +} const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f) diff --git a/src/Mod/PartDesign/App/Feature.h b/src/Mod/PartDesign/App/Feature.h index 05f860a0e6..91e1b9189a 100644 --- a/src/Mod/PartDesign/App/Feature.h +++ b/src/Mod/PartDesign/App/Feature.h @@ -100,6 +100,11 @@ protected: TopoShape getSolid(const TopoShape&); static int countSolids(const TopoDS_Shape&, TopAbs_ShapeEnum type = TopAbs_SOLID); + /** + * Checks if the single-solid body rule is fulfilled. + */ + static bool isSingleSolidRuleSatisfied(const TopoDS_Shape&, TopAbs_ShapeEnum type = TopAbs_SOLID); + /// Grab any point from the given face static const gp_Pnt getPointFromFace(const TopoDS_Face& f); /// Make a shape from a base plane (convenience method) diff --git a/src/Mod/PartDesign/App/FeatureBoolean.cpp b/src/Mod/PartDesign/App/FeatureBoolean.cpp index 50451cd2a7..d3e05d644d 100644 --- a/src/Mod/PartDesign/App/FeatureBoolean.cpp +++ b/src/Mod/PartDesign/App/FeatureBoolean.cpp @@ -153,8 +153,7 @@ App::DocumentObjectExecReturn *Boolean::execute() result = refineShapeIfActive(result); - int solidCount = countSolids(result); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(result)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index 9f9a956099..c2833871b5 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -270,10 +270,11 @@ App::DocumentObjectExecReturn *Chamfer::execute() return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is invalid")); } } - int solidCount = countSolids(shape); - if (solidCount > 1) { + + if (!isSingleSolidRuleSatisfied(shape)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } + shape = refineShapeIfActive(shape); this->Shape.setValue(getSolid(shape)); return App::DocumentObject::StdReturn; diff --git a/src/Mod/PartDesign/App/FeatureDraft.cpp b/src/Mod/PartDesign/App/FeatureDraft.cpp index cc2e32f394..a297f2c397 100644 --- a/src/Mod/PartDesign/App/FeatureDraft.cpp +++ b/src/Mod/PartDesign/App/FeatureDraft.cpp @@ -318,8 +318,7 @@ App::DocumentObjectExecReturn *Draft::execute() if (shape.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is null")); - int solidCount = countSolids(shape); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(shape)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/App/FeatureFillet.cpp b/src/Mod/PartDesign/App/FeatureFillet.cpp index e38f88b168..bf4d1e7453 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.cpp +++ b/src/Mod/PartDesign/App/FeatureFillet.cpp @@ -193,8 +193,7 @@ App::DocumentObjectExecReturn *Fillet::execute() } } - int solidCount = countSolids(shape); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(shape)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/App/FeatureGroove.cpp b/src/Mod/PartDesign/App/FeatureGroove.cpp index 8f15912f57..b1db6d5d8d 100644 --- a/src/Mod/PartDesign/App/FeatureGroove.cpp +++ b/src/Mod/PartDesign/App/FeatureGroove.cpp @@ -188,8 +188,7 @@ App::DocumentObjectExecReturn *Groove::execute() TopoDS_Shape subshape = refineShapeIfActive(mkCut.Shape()); this->AddSubShape.setValue(subshape); - int resultCount = countSolids(result); - if (resultCount > 1) { + if (!isSingleSolidRuleSatisfied(result)) { return new App::DocumentObjectExecReturn("Groove: Result has multiple solids. This is not supported at this time."); } @@ -221,8 +220,7 @@ App::DocumentObjectExecReturn *Groove::execute() solRes = refineShapeIfActive(solRes); this->Shape.setValue(getSolid(solRes)); - int solidCount = countSolids(solRes); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(solRes)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } } diff --git a/src/Mod/PartDesign/App/FeatureHelix.cpp b/src/Mod/PartDesign/App/FeatureHelix.cpp index 05a932e377..a50e2cdf31 100644 --- a/src/Mod/PartDesign/App/FeatureHelix.cpp +++ b/src/Mod/PartDesign/App/FeatureHelix.cpp @@ -251,10 +251,10 @@ App::DocumentObjectExecReturn* Helix::execute() if (getAddSubType() == FeatureAddSub::Subtractive) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Error: There is nothing to subtract")); - int solidCount = countSolids(result); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(result)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Error: Result has multiple solids")); } + Shape.setValue(getSolid(result)); return App::DocumentObject::StdReturn; } @@ -271,8 +271,8 @@ App::DocumentObjectExecReturn* Helix::execute() if (boolOp.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Error: Result is not a solid")); - int solidCount = countSolids(boolOp); - if (solidCount > 1) { + + if (!isSingleSolidRuleSatisfied(boolOp)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Error: Result has multiple solids")); } @@ -301,8 +301,7 @@ App::DocumentObjectExecReturn* Helix::execute() if (boolOp.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Error: Result is not a solid")); - int solidCount = countSolids(boolOp); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(boolOp)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Error: Result has multiple solids")); } diff --git a/src/Mod/PartDesign/App/FeatureHole.cpp b/src/Mod/PartDesign/App/FeatureHole.cpp index 2dd745a03c..dd5b6ba2a1 100644 --- a/src/Mod/PartDesign/App/FeatureHole.cpp +++ b/src/Mod/PartDesign/App/FeatureHole.cpp @@ -1900,10 +1900,7 @@ App::DocumentObjectExecReturn* Hole::execute() return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); base = refineShapeIfActive(base); - - - int solidCount = countSolids(base.getShape()); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(base.getShape())) { return new App::DocumentObjectExecReturn( QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/App/FeatureLoft.cpp b/src/Mod/PartDesign/App/FeatureLoft.cpp index 46958c5b43..121d294db7 100644 --- a/src/Mod/PartDesign/App/FeatureLoft.cpp +++ b/src/Mod/PartDesign/App/FeatureLoft.cpp @@ -288,13 +288,15 @@ App::DocumentObjectExecReturn *Loft::execute() BRepAlgoAPI_Fuse mkFuse(base, result); if (!mkFuse.IsDone()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Loft: Adding the loft failed")); + // we have to get the solids (fuse sometimes creates compounds) TopoDS_Shape boolOp = this->getSolid(mkFuse.Shape()); + // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); - int solidCount = countSolids(boolOp); - if (solidCount > 1) { + + if (!isSingleSolidRuleSatisfied(boolOp)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } @@ -306,13 +308,15 @@ App::DocumentObjectExecReturn *Loft::execute() BRepAlgoAPI_Cut mkCut(base, result); if (!mkCut.IsDone()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Loft: Subtracting the loft failed")); + // we have to get the solids (fuse sometimes creates compounds) TopoDS_Shape boolOp = this->getSolid(mkCut.Shape()); + // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); - int solidCount = countSolids(boolOp); - if (solidCount > 1) { + + if (!isSingleSolidRuleSatisfied(boolOp)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index cbff42e895..4a9d29bb0d 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -235,8 +235,7 @@ App::DocumentObjectExecReturn *Pad::execute() if (solRes.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); - int solidCount = countSolids(result); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(result)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } @@ -244,8 +243,7 @@ App::DocumentObjectExecReturn *Pad::execute() this->Shape.setValue(getSolid(solRes)); } else { - int solidCount = countSolids(prism); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(prism)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/App/FeaturePipe.cpp b/src/Mod/PartDesign/App/FeaturePipe.cpp index 42ff8c26d6..b4b9ccf5cb 100644 --- a/src/Mod/PartDesign/App/FeaturePipe.cpp +++ b/src/Mod/PartDesign/App/FeaturePipe.cpp @@ -398,8 +398,7 @@ App::DocumentObjectExecReturn *Pipe::execute() if (boolOp.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); - int solidCount = countSolids(boolOp); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(boolOp)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } @@ -418,8 +417,7 @@ App::DocumentObjectExecReturn *Pipe::execute() if (boolOp.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); - int solidCount = countSolids(boolOp); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(boolOp)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index aaae33f138..9183fe9551 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -194,8 +194,7 @@ App::DocumentObjectExecReturn *Pocket::execute() TopoDS_Shape result = refineShapeIfActive(mkCut.Shape()); this->AddSubShape.setValue(result); - int prismCount = countSolids(prism); - if (prismCount > 1) { + if (!isSingleSolidRuleSatisfied(result)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } @@ -229,8 +228,7 @@ App::DocumentObjectExecReturn *Pocket::execute() if (solRes.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); - int solidCount = countSolids(result); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(result)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } diff --git a/src/Mod/PartDesign/App/FeaturePrimitive.cpp b/src/Mod/PartDesign/App/FeaturePrimitive.cpp index 47b9ffe277..a0b07ba9b1 100644 --- a/src/Mod/PartDesign/App/FeaturePrimitive.cpp +++ b/src/Mod/PartDesign/App/FeaturePrimitive.cpp @@ -145,12 +145,12 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Adding the primitive failed")); // we have to get the solids (fuse sometimes creates compounds) boolOp = this->getSolid(mkFuse.Shape()); + // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); - int solidCount = countSolids(boolOp); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(boolOp)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } } @@ -165,8 +165,7 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri if (boolOp.IsNull()) return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Resulting shape is not a solid")); - int solidCount = countSolids(boolOp); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(boolOp)) { return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Result has multiple solids: that is not currently supported.")); } } diff --git a/src/Mod/PartDesign/App/FeatureTransformed.cpp b/src/Mod/PartDesign/App/FeatureTransformed.cpp index 5f3dbcce7f..7656e15d7d 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.cpp +++ b/src/Mod/PartDesign/App/FeatureTransformed.cpp @@ -327,8 +327,7 @@ App::DocumentObjectExecReturn *Transformed::execute() support = refineShapeIfActive(support); - int solidCount = countSolids(support); - if (solidCount > 1) { + if (!isSingleSolidRuleSatisfied(support)) { Base::Console().Warning("Transformed: Result has multiple solids. Only keeping the first.\n"); }