PartDesign: put selection filter in separate file in order to be reused by multiple features

This commit is contained in:
logari81
2012-11-03 22:48:04 +01:00
parent 30fce802a6
commit 83cca85c1c
5 changed files with 136 additions and 34 deletions

View File

@@ -45,6 +45,7 @@
#include <Mod/PartDesign/App/FeatureTransformed.h>
#include <Mod/PartDesign/App/FeatureAdditive.h>
#include <Mod/PartDesign/App/FeatureSubtractive.h>
#include "ReferenceSelection.h"
using namespace PartDesignGui;
using namespace Gui;
@@ -192,42 +193,9 @@ void TaskTransformedParameters::exitSelectionMode()
hideOriginals();
}
class ReferenceSelection : public Gui::SelectionFilterGate
{
const App::DocumentObject* support;
bool edge, plane;
public:
ReferenceSelection(const App::DocumentObject* support_, bool edge_, bool plane_)
: Gui::SelectionFilterGate((Gui::SelectionFilter*)0),
support(support_), edge(edge_), plane(plane_)
{
}
bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName)
{
if (!sSubName || sSubName[0] == '\0')
return false;
if (pObj != support)
return false;
std::string subName(sSubName);
if (edge && subName.size() > 4 && subName.substr(0,4) == "Edge")
return true;
if (plane && subName.size() > 4 && subName.substr(0,4) == "Face") {
const Part::TopoShape &shape = static_cast<const Part::Feature*>(support)->Shape.getValue();
TopoDS_Shape sh = shape.getSubShape(subName.c_str());
const TopoDS_Face& face = TopoDS::Face(sh);
if (!face.IsNull()) {
BRepAdaptor_Surface adapt(face);
if (adapt.GetType() == GeomAbs_Plane)
return true;
}
}
return false;
}
};
void TaskTransformedParameters::addReferenceSelectionGate(bool edge, bool face)
{
Gui::Selection().addSelectionGate(new ReferenceSelection(getSupportObject(), edge, face));
Gui::Selection().addSelectionGate(new ReferenceSelection(getSupportObject(), edge, face, true));
}