From 83cca85c1c6028a915af22749be455a9ac8a03ea Mon Sep 17 00:00:00 2001 From: logari81 Date: Sat, 3 Nov 2012 22:48:04 +0100 Subject: [PATCH] PartDesign: put selection filter in separate file in order to be reused by multiple features --- src/Mod/PartDesign/Gui/CMakeLists.txt | 3 + src/Mod/PartDesign/Gui/Makefile.am | 2 + src/Mod/PartDesign/Gui/ReferenceSelection.cpp | 78 +++++++++++++++++++ src/Mod/PartDesign/Gui/ReferenceSelection.h | 51 ++++++++++++ .../Gui/TaskTransformedParameters.cpp | 36 +-------- 5 files changed, 136 insertions(+), 34 deletions(-) create mode 100644 src/Mod/PartDesign/Gui/ReferenceSelection.cpp create mode 100644 src/Mod/PartDesign/Gui/ReferenceSelection.h diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index fb518372f..0d603218e 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -26,6 +26,7 @@ set(PartDesignGui_LIBS set(PartDesignGui_MOC_HDRS FeaturePickDialog.h + ReferenceSelection.h TaskPadParameters.h TaskPocketParameters.h TaskChamferParameters.h @@ -100,6 +101,8 @@ SET(PartDesignGuiTaskDlgs_SRCS FeaturePickDialog.ui FeaturePickDialog.cpp FeaturePickDialog.h + ReferenceSelection.cpp + ReferenceSelection.h TaskPadParameters.ui TaskPadParameters.cpp TaskPadParameters.h diff --git a/src/Mod/PartDesign/Gui/Makefile.am b/src/Mod/PartDesign/Gui/Makefile.am index 4d0ca5034..d9a3557ec 100644 --- a/src/Mod/PartDesign/Gui/Makefile.am +++ b/src/Mod/PartDesign/Gui/Makefile.am @@ -56,6 +56,8 @@ libPartDesignGui_la_SOURCES=\ PreCompiled.h \ FeaturePickDialog.cpp \ FeaturePickDialog.h \ + ReferenceSelection.cpp \ + ReferenceSelection.h \ TaskGrooveParameters.cpp \ TaskGrooveParameters.h \ TaskPadParameters.cpp \ diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.cpp b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp new file mode 100644 index 000000000..f2bfcd42e --- /dev/null +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.cpp @@ -0,0 +1,78 @@ +/****************************************************************************** + * Copyright (c)2012 Konstantinos Poulios * + * * + * 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 +# include +# include +# include +# include +#endif + +#include +#include +#include "ReferenceSelection.h" + +using namespace PartDesignGui; +using namespace Gui; + +/* TRANSLATOR PartDesignGui::ReferenceSelection.cpp */ + +bool ReferenceSelection::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") { + const Part::TopoShape &shape = static_cast(support)->Shape.getValue(); + TopoDS_Shape sh = shape.getSubShape(subName.c_str()); + const TopoDS_Edge& edge = TopoDS::Edge(sh); + if (!edge.IsNull()) { + if (planar) { + BRepAdaptor_Curve adapt(edge); + if (adapt.GetType() == GeomAbs_Line) + return true; + } else { + return true; + } + } + } + if (plane && subName.size() > 4 && subName.substr(0,4) == "Face") { + const Part::TopoShape &shape = static_cast(support)->Shape.getValue(); + TopoDS_Shape sh = shape.getSubShape(subName.c_str()); + const TopoDS_Face& face = TopoDS::Face(sh); + if (!face.IsNull()) { + if (planar) { + BRepAdaptor_Surface adapt(face); + if (adapt.GetType() == GeomAbs_Plane) + return true; + } else { + return true; + } + } + } + return false; +} diff --git a/src/Mod/PartDesign/Gui/ReferenceSelection.h b/src/Mod/PartDesign/Gui/ReferenceSelection.h new file mode 100644 index 000000000..03b634012 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ReferenceSelection.h @@ -0,0 +1,51 @@ +/****************************************************************************** + * Copyright (c)2012 Konstantinos Poulios * + * 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 GUI_ReferenceSelection_H +#define GUI_ReferenceSelection_H + +#include + +namespace PartDesignGui { + +class ReferenceSelection : public Gui::SelectionFilterGate +{ + const App::DocumentObject* support; + bool edge, plane; + bool planar; +public: + ReferenceSelection(const App::DocumentObject* support_, + const bool edge_, const bool plane_, const bool planar_) + : Gui::SelectionFilterGate((Gui::SelectionFilter*)0), + support(support_), edge(edge_), plane(plane_), planar(planar_) + { + } + /** + * Allow the user to pick only edges or faces (or both) from the defined support + * Optionally restrict the selection to planar edges/faces + */ + bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName); +}; + +} //namespace PartDesignGui + +#endif // GUI_ReferenceSelection_H diff --git a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp index 83952dcfc..b7fdb6fe6 100644 --- a/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskTransformedParameters.cpp @@ -45,6 +45,7 @@ #include #include #include +#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(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)); }