PD: Migrate onlyHasToRefine

This was a later addition that got missed when merging.
This commit is contained in:
Chris Hennes
2025-01-25 04:25:41 -06:00
parent 895d70b7f8
commit 9e70cac0be
3 changed files with 42 additions and 9 deletions

View File

@@ -40,11 +40,6 @@ public:
Subtractive
};
enum class RefineErrorPolicy {
Raise = 0,
Warn
};
FeatureAddSub();
Type getAddSubType();

View File

@@ -50,12 +50,40 @@ FeatureRefine::FeatureRefine()
this->Refine.setValue(hGrp->GetBool("RefineModel", true));
}
TopoShape FeatureRefine::refineShapeIfActive(const TopoShape& oldShape) const
bool FeatureRefine::onlyHasToRefine() const
{
if( ! Refine.isTouched()){
return false;
}
if (rawShape.isNull()){
return false;
}
std::vector<App::Property*> propList;
getPropertyList(propList);
for (auto prop : propList){
if (prop != &Refine
/*&& prop != &SuppressedShape*/
&& prop->isTouched()){
return false;
}
}
return true;
}
TopoShape FeatureRefine::refineShapeIfActive(const TopoShape& oldShape, const RefineErrorPolicy onError) const
{
if (this->Refine.getValue()) {
TopoShape shape(oldShape);
// Potentially also "fixShape" to repair it ( as a workaround to OCCT bugs? )
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

@@ -35,12 +35,22 @@ class PartDesignExport FeatureRefine : public PartDesign::Feature
PROPERTY_HEADER_WITH_OVERRIDE(PartDesign::FeatureRefine);
public:
enum class RefineErrorPolicy {
Raise = 0,
Warn
};
FeatureRefine();
App::PropertyBool Refine;
protected:
TopoShape refineShapeIfActive(const TopoShape&) const;
//store the shape before refinement
TopoShape rawShape;
bool onlyHasToRefine() const;
TopoShape refineShapeIfActive(const TopoShape& oldShape, const RefineErrorPolicy onError = RefineErrorPolicy::Raise) const;
};
using FeatureRefinePython = App::FeaturePythonT<FeatureRefine>;