diff --git a/src/Mod/PartDesign/App/Feature.cpp b/src/Mod/PartDesign/App/Feature.cpp index 7f19a9516d..6a58a3915f 100644 --- a/src/Mod/PartDesign/App/Feature.cpp +++ b/src/Mod/PartDesign/App/Feature.cpp @@ -79,6 +79,21 @@ TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape) return TopoDS_Shape(); } +int Feature::countSolids(const TopoDS_Shape& shape, TopAbs_ShapeEnum type) +{ + int result = 0; + if (shape.IsNull()) + return result; + TopExp_Explorer xp; + xp.Init(shape,type); + for (; xp.More(); xp.Next()) { + result++; + } + return result; +} + + + const gp_Pnt Feature::getPointFromFace(const TopoDS_Face& f) { if (!f.Infinite()) { diff --git a/src/Mod/PartDesign/App/Feature.h b/src/Mod/PartDesign/App/Feature.h index 0689d849e4..ce393fbb2b 100644 --- a/src/Mod/PartDesign/App/Feature.h +++ b/src/Mod/PartDesign/App/Feature.h @@ -83,6 +83,7 @@ protected: * Get a solid of the given shape. If no solid is found an exception is raised. */ static TopoDS_Shape getSolid(const TopoDS_Shape&); + static int countSolids(const TopoDS_Shape&, TopAbs_ShapeEnum type = TopAbs_SOLID ); /// Grab any point from the given face static const gp_Pnt getPointFromFace(const TopoDS_Face& f); diff --git a/src/Mod/PartDesign/App/FeatureBoolean.cpp b/src/Mod/PartDesign/App/FeatureBoolean.cpp index af3eb0dda6..a1f7fbbea8 100644 --- a/src/Mod/PartDesign/App/FeatureBoolean.cpp +++ b/src/Mod/PartDesign/App/FeatureBoolean.cpp @@ -141,6 +141,11 @@ App::DocumentObjectExecReturn *Boolean::execute(void) result = boolOp; // Use result of this operation for fuse/cut of next body } + + int solidCount = countSolids(result); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Boolean: Result has multiple solids. Check parameters."); + } this->Shape.setValue(getSolid(result)); return App::DocumentObject::StdReturn; diff --git a/src/Mod/PartDesign/App/FeatureChamfer.cpp b/src/Mod/PartDesign/App/FeatureChamfer.cpp index 10bd843fef..8f39b18b05 100644 --- a/src/Mod/PartDesign/App/FeatureChamfer.cpp +++ b/src/Mod/PartDesign/App/FeatureChamfer.cpp @@ -125,6 +125,10 @@ App::DocumentObjectExecReturn *Chamfer::execute(void) return new App::DocumentObjectExecReturn("Resulting shape is invalid"); } } + int solidCount = countSolids(shape); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Chamfer: Result has multiple solids. Check parameters."); + } 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 9397a3e763..e94a230b37 100644 --- a/src/Mod/PartDesign/App/FeatureDraft.cpp +++ b/src/Mod/PartDesign/App/FeatureDraft.cpp @@ -304,6 +304,11 @@ App::DocumentObjectExecReturn *Draft::execute(void) if (shape.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is null"); + int solidCount = countSolids(shape); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Fuse: Result has multiple solids. Check parameters."); + } + this->Shape.setValue(getSolid(shape)); return App::DocumentObject::StdReturn; } diff --git a/src/Mod/PartDesign/App/FeatureFillet.cpp b/src/Mod/PartDesign/App/FeatureFillet.cpp index ad4f79e96c..66c01e02bf 100644 --- a/src/Mod/PartDesign/App/FeatureFillet.cpp +++ b/src/Mod/PartDesign/App/FeatureFillet.cpp @@ -118,6 +118,11 @@ App::DocumentObjectExecReturn *Fillet::execute(void) } } + int solidCount = countSolids(shape); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Fillet: Result has multiple solids. Check parameters."); + } + this->Shape.setValue(getSolid(shape)); return App::DocumentObject::StdReturn; } diff --git a/src/Mod/PartDesign/App/FeatureGroove.cpp b/src/Mod/PartDesign/App/FeatureGroove.cpp index b2af6fc91a..c27613aa80 100644 --- a/src/Mod/PartDesign/App/FeatureGroove.cpp +++ b/src/Mod/PartDesign/App/FeatureGroove.cpp @@ -155,6 +155,11 @@ App::DocumentObjectExecReturn *Groove::execute(void) TopoDS_Shape solRes = this->getSolid(mkCut.Shape()); if (solRes.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); + + int solidCount = countSolids(result); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Groove: Result has multiple solids. Check parameters."); + } solRes = refineShapeIfActive(solRes); this->Shape.setValue(getSolid(solRes)); diff --git a/src/Mod/PartDesign/App/FeatureHole.cpp b/src/Mod/PartDesign/App/FeatureHole.cpp index 88f821f61f..c1459337e6 100644 --- a/src/Mod/PartDesign/App/FeatureHole.cpp +++ b/src/Mod/PartDesign/App/FeatureHole.cpp @@ -1256,6 +1256,12 @@ App::DocumentObjectExecReturn *Hole::execute(void) this->AddSubShape.setValue( holes ); remapSupportShape(base); + + int solidCount = countSolids(base); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Hole: Result has multiple solids. Check parameters."); + } + this->Shape.setValue(base); return App::DocumentObject::StdReturn; diff --git a/src/Mod/PartDesign/App/FeatureLoft.cpp b/src/Mod/PartDesign/App/FeatureLoft.cpp index fbf080d07b..a8d3606e95 100644 --- a/src/Mod/PartDesign/App/FeatureLoft.cpp +++ b/src/Mod/PartDesign/App/FeatureLoft.cpp @@ -193,6 +193,10 @@ App::DocumentObjectExecReturn *Loft::execute(void) // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn("Loft: Resulting shape is not a solid"); + int solidCount = countSolids(boolOp); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Loft: Result has multiple solids. Check parameters."); + } boolOp = refineShapeIfActive(boolOp); Shape.setValue(getSolid(boolOp)); @@ -207,6 +211,10 @@ App::DocumentObjectExecReturn *Loft::execute(void) // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn("Loft: Resulting shape is not a solid"); + int solidCount = countSolids(boolOp); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Loft: Result has multiple solids. Check parameters."); + } boolOp = refineShapeIfActive(boolOp); Shape.setValue(getSolid(boolOp)); diff --git a/src/Mod/PartDesign/App/FeaturePad.cpp b/src/Mod/PartDesign/App/FeaturePad.cpp index 0762844cf8..f8e03716a2 100644 --- a/src/Mod/PartDesign/App/FeaturePad.cpp +++ b/src/Mod/PartDesign/App/FeaturePad.cpp @@ -225,10 +225,21 @@ App::DocumentObjectExecReturn *Pad::execute(void) // lets check if the result is a solid if (solRes.IsNull()) return new App::DocumentObjectExecReturn("Pad: Resulting shape is not a solid"); + + int solidCount = countSolids(result); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Pad: Result has multiple solids. Check parameters."); + } + solRes = refineShapeIfActive(solRes); this->Shape.setValue(getSolid(solRes)); } else { - this->Shape.setValue(getSolid(prism)); + int solidCount = countSolids(prism); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Pad: Result has multiple solids. Check parameters."); + } + + this->Shape.setValue(getSolid(prism)); } return App::DocumentObject::StdReturn; diff --git a/src/Mod/PartDesign/App/FeaturePipe.cpp b/src/Mod/PartDesign/App/FeaturePipe.cpp index ef4aed2a5c..3b27369e80 100644 --- a/src/Mod/PartDesign/App/FeaturePipe.cpp +++ b/src/Mod/PartDesign/App/FeaturePipe.cpp @@ -313,6 +313,11 @@ App::DocumentObjectExecReturn *Pipe::execute(void) // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); + + int solidCount = countSolids(boolOp); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Pipe: Result has multiple solids. Check parameters."); + } boolOp = refineShapeIfActive(boolOp); Shape.setValue(getSolid(boolOp)); @@ -327,6 +332,11 @@ App::DocumentObjectExecReturn *Pipe::execute(void) // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); + + int solidCount = countSolids(boolOp); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Pipe: Result has multiple solids. Check parameters."); + } boolOp = refineShapeIfActive(boolOp); Shape.setValue(getSolid(boolOp)); diff --git a/src/Mod/PartDesign/App/FeaturePocket.cpp b/src/Mod/PartDesign/App/FeaturePocket.cpp index 87267f1b47..f3d9dbfe09 100644 --- a/src/Mod/PartDesign/App/FeaturePocket.cpp +++ b/src/Mod/PartDesign/App/FeaturePocket.cpp @@ -43,6 +43,7 @@ # include #endif +#include #include #include #include @@ -181,6 +182,12 @@ App::DocumentObjectExecReturn *Pocket::execute(void) // FIXME: In some cases this affects the Shape property: It is set to the same shape as the SubShape!!!! TopoDS_Shape result = refineShapeIfActive(mkCut.Shape()); this->AddSubShape.setValue(result); + + int prismCount = countSolids(prism); + if (prismCount > 1) { + return new App::DocumentObjectExecReturn("Pocket: Result has multiple solids. Check parameters."); + } + this->Shape.setValue(getSolid(prism)); } else { TopoDS_Shape prism; @@ -203,6 +210,12 @@ App::DocumentObjectExecReturn *Pocket::execute(void) TopoDS_Shape solRes = this->getSolid(result); if (solRes.IsNull()) return new App::DocumentObjectExecReturn("Pocket: Resulting shape is not a solid"); + + int solidCount = countSolids(result); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Pocket: Result has multiple solids. Check parameters."); + + } solRes = refineShapeIfActive(solRes); remapSupportShape(solRes); this->Shape.setValue(getSolid(solRes)); diff --git a/src/Mod/PartDesign/App/FeaturePrimitive.cpp b/src/Mod/PartDesign/App/FeaturePrimitive.cpp index a60befb757..56638c69dd 100644 --- a/src/Mod/PartDesign/App/FeaturePrimitive.cpp +++ b/src/Mod/PartDesign/App/FeaturePrimitive.cpp @@ -124,7 +124,12 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); - + + int solidCount = countSolids(boolOp); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Additive: Result has multiple solids. Check parameters."); + } + boolOp = refineShapeIfActive(boolOp); Shape.setValue(getSolid(boolOp)); AddSubShape.setValue(primitiveShape); @@ -139,6 +144,11 @@ App::DocumentObjectExecReturn* FeaturePrimitive::execute(const TopoDS_Shape& pri // lets check if the result is a solid if (boolOp.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid"); + + int solidCount = countSolids(boolOp); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Subtractive: Result has multiple solids. Check parameters."); + } boolOp = refineShapeIfActive(boolOp); Shape.setValue(getSolid(boolOp)); diff --git a/src/Mod/PartDesign/App/FeatureTransformed.cpp b/src/Mod/PartDesign/App/FeatureTransformed.cpp index 02c2aa8fc4..008d1fda0f 100644 --- a/src/Mod/PartDesign/App/FeatureTransformed.cpp +++ b/src/Mod/PartDesign/App/FeatureTransformed.cpp @@ -331,6 +331,7 @@ App::DocumentObjectExecReturn *Transformed::execute(void) // lets check if the result is a solid if (current.IsNull()) return new App::DocumentObjectExecReturn("Resulting shape is not a solid", *o); + /*std::vector::const_iterator individualIt; for (individualIt = individualTools.begin(); individualIt != individualTools.end(); ++individualIt) { @@ -377,6 +378,11 @@ App::DocumentObjectExecReturn *Transformed::execute(void) for (rej_it_map::const_iterator it = nointersect_trsfms.begin(); it != nointersect_trsfms.end(); ++it) for (trsf_it::const_iterator it2 = it->second.begin(); it2 != it->second.end(); ++it2) rejected[it->first].push_back(**it2); + + int solidCount = countSolids(support); + if (solidCount > 1) { + return new App::DocumentObjectExecReturn("Transformed: Result has multiple solids. Check parameters."); + } this->Shape.setValue(getSolid(support));