Toponaming: Refactor refine to its own FeatureRefine class
This commit is contained in:
@@ -88,6 +88,8 @@ PyMOD_INIT_FUNC(_PartDesign)
|
||||
// clang-format off
|
||||
PartDesign::Feature ::init();
|
||||
PartDesign::FeaturePython ::init();
|
||||
PartDesign::FeatureRefine ::init();
|
||||
PartDesign::FeatureRefinePython ::init();
|
||||
PartDesign::Solid ::init();
|
||||
PartDesign::FeatureAddSub ::init();
|
||||
PartDesign::FeatureAddSubPython ::init();
|
||||
|
||||
@@ -94,6 +94,8 @@ SET(FeaturesSketchBased_SRCS
|
||||
FeatureRevolution.h
|
||||
FeatureGroove.cpp
|
||||
FeatureGroove.h
|
||||
FeatureRefine.cpp
|
||||
FeatureRefine.h
|
||||
FeatureAddSub.cpp
|
||||
FeatureAddSub.h
|
||||
FeatureHole.h
|
||||
|
||||
@@ -40,16 +40,11 @@ using namespace PartDesign;
|
||||
namespace PartDesign {
|
||||
|
||||
|
||||
PROPERTY_SOURCE(PartDesign::FeatureAddSub, PartDesign::Feature)
|
||||
PROPERTY_SOURCE(PartDesign::FeatureAddSub, PartDesign::FeatureRefine)
|
||||
|
||||
FeatureAddSub::FeatureAddSub()
|
||||
{
|
||||
ADD_PROPERTY(AddSubShape,(TopoDS_Shape()));
|
||||
ADD_PROPERTY_TYPE(Refine,(0),"Part Design",(App::PropertyType)(App::Prop_None),"Refine shape (clean up redundant edges) after adding/subtracting");
|
||||
//init Refine property
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/PartDesign");
|
||||
this->Refine.setValue(hGrp->GetBool("RefineModel", true));
|
||||
}
|
||||
|
||||
FeatureAddSub::Type FeatureAddSub::getAddSubType()
|
||||
@@ -64,17 +59,6 @@ short FeatureAddSub::mustExecute() const
|
||||
return PartDesign::Feature::mustExecute();
|
||||
}
|
||||
|
||||
|
||||
TopoShape FeatureAddSub::refineShapeIfActive(const TopoShape& oldShape) const
|
||||
{
|
||||
if (this->Refine.getValue()) {
|
||||
TopoShape shape(oldShape);
|
||||
// this->fixShape(shape); // Todo: Not clear that this is required
|
||||
return shape.makeElementRefine();
|
||||
}
|
||||
return oldShape;
|
||||
}
|
||||
|
||||
void FeatureAddSub::getAddSubShape(Part::TopoShape &addShape, Part::TopoShape &subShape)
|
||||
{
|
||||
if (addSubType == Additive)
|
||||
|
||||
@@ -24,13 +24,13 @@
|
||||
#ifndef PARTDESIGN_FeatureAdditive_H
|
||||
#define PARTDESIGN_FeatureAdditive_H
|
||||
|
||||
#include "Feature.h"
|
||||
#include "FeatureRefine.h"
|
||||
|
||||
/// Base class of all additive features in PartDesign
|
||||
namespace PartDesign
|
||||
{
|
||||
|
||||
class PartDesignExport FeatureAddSub : public PartDesign::Feature
|
||||
class PartDesignExport FeatureAddSub : public PartDesign::FeatureRefine
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(PartDesign::FeatureAddSub);
|
||||
|
||||
@@ -49,12 +49,10 @@ public:
|
||||
virtual void getAddSubShape(Part::TopoShape &addShape, Part::TopoShape &subShape);
|
||||
|
||||
Part::PropertyPartShape AddSubShape;
|
||||
App::PropertyBool Refine;
|
||||
|
||||
protected:
|
||||
Type addSubType{Additive};
|
||||
|
||||
TopoShape refineShapeIfActive(const TopoShape&) const;
|
||||
};
|
||||
|
||||
using FeatureAddSubPython = App::FeaturePythonT<FeatureAddSub>;
|
||||
|
||||
@@ -53,10 +53,6 @@ Boolean::Boolean()
|
||||
ADD_PROPERTY(Type,((long)0));
|
||||
Type.setEnums(TypeEnums);
|
||||
|
||||
ADD_PROPERTY_TYPE(Refine,(0),"Part Design",(App::PropertyType)(App::Prop_None),"Refine shape (clean up redundant edges) after adding/subtracting");
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/PartDesign");
|
||||
this->Refine.setValue(hGrp->GetBool("RefineModel", true));
|
||||
ADD_PROPERTY_TYPE(UsePlacement,(0),"Part Design",(App::PropertyType)(App::Prop_None),"Apply the placement of the second ( tool ) object");
|
||||
this->UsePlacement.setValue(false);
|
||||
|
||||
@@ -188,25 +184,4 @@ void Boolean::handleChangedPropertyName(Base::XMLReader &reader, const char * Ty
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// FIXME: This method ( and the Refine property it depends on ) is redundant with the exact same
|
||||
// thing in FeatureAddSub, but cannot reasonably be moved up an inheritance level to Feature as
|
||||
// there are inheritors like FeatureBox for which a refine Property does not make sense. A
|
||||
// solution like moving Refine and refineShapeIfActive to a new FeatureRefine class that sits
|
||||
// between Feature and FeatureBoolean / FeatureAddSub is a possibility, or maybe [ew!] hiding the
|
||||
// property in Feature and only enabling it in the places it is relevant.
|
||||
TopoShape Boolean::refineShapeIfActive(const TopoShape& oldShape) const
|
||||
{
|
||||
if (this->Refine.getValue()) {
|
||||
try {
|
||||
return oldShape.makeElementRefine();
|
||||
}
|
||||
catch (Standard_Failure&) {
|
||||
return oldShape;
|
||||
}
|
||||
}
|
||||
|
||||
return oldShape;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
#include <App/GeoFeatureGroupExtension.h>
|
||||
#include <App/PropertyStandard.h>
|
||||
#include "Feature.h"
|
||||
#include "FeatureRefine.h"
|
||||
|
||||
|
||||
namespace PartDesign
|
||||
@@ -36,7 +36,7 @@ namespace PartDesign
|
||||
* Abstract superclass of all features that are created by transformation of another feature
|
||||
* Transformations are translation, rotation and mirroring
|
||||
*/
|
||||
class PartDesignExport Boolean : public PartDesign::Feature, public App::GeoFeatureGroupExtension
|
||||
class PartDesignExport Boolean : public PartDesign::FeatureRefine, public App::GeoFeatureGroupExtension
|
||||
{
|
||||
PROPERTY_HEADER_WITH_EXTENSIONS(PartDesign::Boolean);
|
||||
|
||||
@@ -46,7 +46,6 @@ public:
|
||||
/// The type of the boolean operation
|
||||
App::PropertyEnumeration Type;
|
||||
|
||||
App::PropertyBool Refine;
|
||||
App::PropertyBool UsePlacement;
|
||||
|
||||
/** @name methods override feature */
|
||||
@@ -63,7 +62,6 @@ public:
|
||||
|
||||
protected:
|
||||
void handleChangedPropertyName(Base::XMLReader &reader, const char * TypeName, const char *PropName) override;
|
||||
TopoShape refineShapeIfActive(const TopoShape&) const;
|
||||
|
||||
|
||||
private:
|
||||
|
||||
85
src/Mod/PartDesign/App/FeatureRefine.cpp
Normal file
85
src/Mod/PartDesign/App/FeatureRefine.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024<bgbsww@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
# include <Standard_Failure.hxx>
|
||||
#endif
|
||||
|
||||
#include <App/Application.h>
|
||||
#include <App/FeaturePythonPyImp.h>
|
||||
#include <Base/Parameter.h>
|
||||
#include <Mod/Part/App/modelRefine.h>
|
||||
|
||||
#include "FeatureRefine.h"
|
||||
#include "FeaturePy.h"
|
||||
|
||||
|
||||
using namespace PartDesign;
|
||||
|
||||
namespace PartDesign
|
||||
{
|
||||
PROPERTY_SOURCE(PartDesign::FeatureRefine, PartDesign::Feature)
|
||||
|
||||
FeatureRefine::FeatureRefine()
|
||||
{
|
||||
ADD_PROPERTY_TYPE(Refine,(0),"Part Design",(App::PropertyType)(App::Prop_None),"Refine shape (clean up redundant edges) after operations");
|
||||
//init Refine property
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/PartDesign");
|
||||
this->Refine.setValue(hGrp->GetBool("RefineModel", true));
|
||||
}
|
||||
|
||||
TopoShape FeatureRefine::refineShapeIfActive(const TopoShape& oldShape) const
|
||||
{
|
||||
if (this->Refine.getValue()) {
|
||||
TopoShape shape(oldShape);
|
||||
// Potentially also "fixShape" to repair it ( as a workaround to OCCT bugs? )
|
||||
return shape.makeElementRefine();
|
||||
}
|
||||
return oldShape;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
namespace App {
|
||||
/// @cond DOXERR
|
||||
PROPERTY_SOURCE_TEMPLATE(PartDesign::FeatureRefinePython, PartDesign::FeatureRefine)
|
||||
template<> const char* PartDesign::FeatureRefinePython::getViewProviderName() const {
|
||||
return "PartDesignGui::ViewProviderPython";
|
||||
}
|
||||
template<> PyObject* PartDesign::FeatureRefinePython::getPyObject() {
|
||||
if (PythonObject.is(Py::_None())) {
|
||||
// ref counter is set to 1
|
||||
PythonObject = Py::Object(new FeaturePythonPyT<PartDesign::FeaturePy>(this),true);
|
||||
}
|
||||
return Py::new_reference_to(PythonObject);
|
||||
}
|
||||
/// @endcond
|
||||
|
||||
// explicit template instantiation
|
||||
template class PartDesignExport FeaturePythonT<PartDesign::FeatureRefine>;
|
||||
}
|
||||
|
||||
|
||||
51
src/Mod/PartDesign/App/FeatureRefine.h
Normal file
51
src/Mod/PartDesign/App/FeatureRefine.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2024 <bgbsww@gmail.com> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 of the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This library is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#ifndef PARTDESIGN_FeatureRefine_H
|
||||
#define PARTDESIGN_FeatureRefine_H
|
||||
|
||||
#include "Feature.h"
|
||||
|
||||
/// Base class of all features that can be refined PartDesign
|
||||
namespace PartDesign
|
||||
{
|
||||
|
||||
class PartDesignExport FeatureRefine : public PartDesign::Feature
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(PartDesign::FeatureRefine);
|
||||
|
||||
public:
|
||||
FeatureRefine();
|
||||
|
||||
App::PropertyBool Refine;
|
||||
|
||||
protected:
|
||||
TopoShape refineShapeIfActive(const TopoShape&) const;
|
||||
};
|
||||
|
||||
using FeatureRefinePython = App::FeaturePythonT<FeatureRefine>;
|
||||
|
||||
} //namespace PartDesign
|
||||
|
||||
|
||||
#endif // PARTDESIGN_FeatureRefine_H
|
||||
@@ -58,7 +58,7 @@ using namespace PartDesign;
|
||||
namespace PartDesign
|
||||
{
|
||||
|
||||
PROPERTY_SOURCE(PartDesign::Transformed, PartDesign::Feature)
|
||||
PROPERTY_SOURCE(PartDesign::Transformed, PartDesign::FeatureRefine)
|
||||
|
||||
std::array<char const*, 3> transformModeEnums = {"Transform tool shapes",
|
||||
"Transform body",
|
||||
@@ -72,17 +72,6 @@ Transformed::Transformed()
|
||||
|
||||
ADD_PROPERTY(TransformMode, (static_cast<long>(Mode::TransformToolShapes)));
|
||||
TransformMode.setEnums(transformModeEnums.data());
|
||||
|
||||
ADD_PROPERTY_TYPE(Refine,
|
||||
(0),
|
||||
"Part Design",
|
||||
(App::PropertyType)(App::Prop_None),
|
||||
"Refine shape (clean up redundant edges) after adding/subtracting");
|
||||
|
||||
//init Refine property
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/PartDesign");
|
||||
this->Refine.setValue(hGrp->GetBool("RefineModel", true));
|
||||
}
|
||||
|
||||
void Transformed::positionBySupport()
|
||||
@@ -355,15 +344,6 @@ App::DocumentObjectExecReturn* Transformed::execute()
|
||||
return App::DocumentObject::StdReturn;
|
||||
}
|
||||
|
||||
|
||||
TopoShape Transformed::refineShapeIfActive(const TopoShape& oldShape) const
|
||||
{
|
||||
if (this->Refine.getValue()) {
|
||||
return oldShape.makeElementRefine();
|
||||
}
|
||||
return oldShape;
|
||||
}
|
||||
|
||||
TopoDS_Shape Transformed::getRemainingSolids(const TopoDS_Shape& shape)
|
||||
{
|
||||
BRep_Builder builder;
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <gp_Trsf.hxx>
|
||||
|
||||
#include <App/PropertyStandard.h>
|
||||
#include "Feature.h"
|
||||
#include "FeatureRefine.h"
|
||||
|
||||
|
||||
namespace PartDesign
|
||||
@@ -37,7 +37,7 @@ namespace PartDesign
|
||||
* Abstract superclass of all features that are created by transformation of another feature
|
||||
* Transformations are translation, rotation and mirroring
|
||||
*/
|
||||
class PartDesignExport Transformed: public PartDesign::Feature
|
||||
class PartDesignExport Transformed: public PartDesign::FeatureRefine
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(PartDesign::Transformed);
|
||||
|
||||
@@ -106,8 +106,6 @@ protected:
|
||||
App::Property* prop) override;
|
||||
|
||||
virtual void positionBySupport();
|
||||
TopoShape refineShapeIfActive(const TopoShape&) const;
|
||||
TopoDS_Shape refineShapeIfActive(const TopoDS_Shape&) const;
|
||||
static TopoDS_Shape getRemainingSolids(const TopoDS_Shape&);
|
||||
|
||||
private:
|
||||
|
||||
@@ -384,10 +384,6 @@ SubShapeBinder::~SubShapeBinder() {
|
||||
void SubShapeBinder::setupObject() {
|
||||
_Version.setValue(2);
|
||||
checkPropertyStatus();
|
||||
|
||||
Base::Reference<ParameterGrp> hGrp = App::GetApplication().GetUserParameter()
|
||||
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("Mod/PartDesign");
|
||||
this->Refine.setValue(hGrp->GetBool("RefineModel", true));
|
||||
}
|
||||
|
||||
App::DocumentObject* SubShapeBinder::getSubObject(const char* subname, PyObject** pyObj,
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <App/FeaturePython.h>
|
||||
#include <Mod/Part/App/DatumFeature.h>
|
||||
#include <Mod/PartDesign/PartDesignGlobal.h>
|
||||
#include "FeatureRefine.h"
|
||||
|
||||
namespace PartDesign
|
||||
{
|
||||
@@ -41,7 +42,7 @@ namespace PartDesign
|
||||
*/
|
||||
// TODO Add better documentation (2015-09-11, Fat-Zer)
|
||||
|
||||
class PartDesignExport ShapeBinder : public Part::Feature
|
||||
class PartDesignExport ShapeBinder : public PartDesign::FeatureRefine
|
||||
{
|
||||
PROPERTY_HEADER_WITH_OVERRIDE(PartDesign::ShapeBinder);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user