Fix #3401 warning on multiple solid

- PartDesign only uses the first result shape
  of an operation and discards the rest without
  warning.

- this also fixes #1707
This commit is contained in:
wandererfan
2018-04-04 18:52:26 -04:00
committed by Yorik van Havre
parent 97932a25bc
commit 0d3008e4eb
14 changed files with 106 additions and 2 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -43,6 +43,7 @@
# include <BRepAlgoAPI_Common.hxx>
#endif
#include <Base/Console.h>
#include <Base/Exception.h>
#include <Base/Placement.h>
#include <App/Document.h>
@@ -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));

View File

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

View File

@@ -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<TopoDS_Shape>::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));