[PD Helix] allow refinement to fail

This commit is contained in:
Florian Foinant-Willig
2024-09-30 21:09:48 +02:00
committed by Chris Hennes
parent d1cdcd18bf
commit 8945971578
3 changed files with 19 additions and 6 deletions

View File

@@ -64,13 +64,21 @@ short FeatureAddSub::mustExecute() const
return PartDesign::Feature::mustExecute();
}
TopoShape FeatureAddSub::refineShapeIfActive(const TopoShape& oldShape) const
TopoShape FeatureAddSub::refineShapeIfActive(const TopoShape& oldShape, const RefineErrorPolicy onError) const
{
if (this->Refine.getValue()) {
TopoShape shape(oldShape);
// this->fixShape(shape); // Todo: Not clear that this is required
return shape.makeElementRefine();
try{
return shape.makeElementRefine();
}
catch (Standard_Failure& err) {
if(onError == RefineErrorPolicy::Warn){
Base::Console().Warning((std::string("Refine failed: ") + err.GetMessageString()).c_str());
} else {
throw;
}
}
}
return oldShape;
}

View File

@@ -40,6 +40,11 @@ public:
Subtractive
};
enum class RefineErrorPolicy {
Raise = 0,
Warn
};
FeatureAddSub();
Type getAddSubType();
@@ -54,7 +59,7 @@ public:
protected:
Type addSubType{Additive};
TopoShape refineShapeIfActive(const TopoShape&) const;
TopoShape refineShapeIfActive(const TopoShape& oldShape, const RefineErrorPolicy onError = RefineErrorPolicy::Raise) const;
};
using FeatureAddSubPython = App::FeaturePythonT<FeatureAddSub>;

View File

@@ -272,7 +272,7 @@ App::DocumentObjectExecReturn* Helix::execute()
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Error: Result has multiple solids"));
}
boolOp = refineShapeIfActive(boolOp);
boolOp = refineShapeIfActive(boolOp, RefineErrorPolicy::Warn);
Shape.setValue(getSolid(boolOp));
}
else if (getAddSubType() == FeatureAddSub::Subtractive) {
@@ -301,7 +301,7 @@ App::DocumentObjectExecReturn* Helix::execute()
return new App::DocumentObjectExecReturn(QT_TRANSLATE_NOOP("Exception", "Error: Result has multiple solids"));
}
boolOp = refineShapeIfActive(boolOp);
boolOp = refineShapeIfActive(boolOp, RefineErrorPolicy::Warn);
Shape.setValue(getSolid(boolOp));
}