From 1bb9e53326f429ed6213e49c1ba81d62750b4a94 Mon Sep 17 00:00:00 2001 From: jriegel Date: Sat, 16 Mar 2013 16:23:12 +0100 Subject: [PATCH] Picking elements and faces in TaskCreateNodeSet --- src/Mod/Fem/Gui/CMakeLists.txt | 2 + src/Mod/Fem/Gui/FemSelectionGate.cpp | 52 ++++++++++++++++++++++++++ src/Mod/Fem/Gui/FemSelectionGate.h | 53 +++++++++++++++++++++++++++ src/Mod/Fem/Gui/TaskCreateNodeSet.cpp | 41 ++++++++++++++++++++- src/Mod/Fem/Gui/TaskCreateNodeSet.h | 6 ++- src/Mod/Fem/Gui/TaskCreateNodeSet.ui | 2 +- 6 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 src/Mod/Fem/Gui/FemSelectionGate.cpp create mode 100644 src/Mod/Fem/Gui/FemSelectionGate.h diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index 1a1b7a501..6a36cfbec 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -60,6 +60,8 @@ SET(FemGui_SRCS_ViewProvider ViewProviderSetFaces.h ViewProviderSetGeometry.cpp ViewProviderSetGeometry.h + FemSelectionGate.cpp + FemSelectionGate.h ) SOURCE_GROUP("ViewProvider" FILES ${FemGui_SRCS_ViewProvider}) diff --git a/src/Mod/Fem/Gui/FemSelectionGate.cpp b/src/Mod/Fem/Gui/FemSelectionGate.cpp new file mode 100644 index 000000000..430c71911 --- /dev/null +++ b/src/Mod/Fem/Gui/FemSelectionGate.cpp @@ -0,0 +1,52 @@ +/****************************************************************************** + * Copyright (c) 2013 Jürgen Riegel (FreeCAD@juergen-riegel.net) * + * * + * 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_ +#endif + +#include "FemSelectionGate.h" + +using namespace FemGui; +using namespace Gui; + +bool FemSelectionGate::allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName) +{ + if (!sSubName || sSubName[0] == '\0') + return false; + + if( sSubName[0] == 'E' && + sSubName[1] == 'l' && + sSubName[2] == 'e' && + sSubName[3] == 'm' && + (Type == Element || Type == NodeElement) ) + return true; + if( sSubName[0] == 'N' && + sSubName[1] == 'o' && + sSubName[2] == 'd' && + sSubName[3] == 'e' && + (Type == Node || Type == NodeElement) ) + return true; + + return false; +} diff --git a/src/Mod/Fem/Gui/FemSelectionGate.h b/src/Mod/Fem/Gui/FemSelectionGate.h new file mode 100644 index 000000000..6c3552b6d --- /dev/null +++ b/src/Mod/Fem/Gui/FemSelectionGate.h @@ -0,0 +1,53 @@ +/****************************************************************************** + * Copyright (c) 2013 Jürgen Riegel (FreeCAD@juergen-riegel.net) * + * 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_FemSelectionGate_H +#define GUI_FemSelectionGate_H + +#include + +namespace FemGui { + +class FemSelectionGate : public Gui::SelectionFilterGate +{ + public: + enum ElemType { + Nothing , + Node , + Element , + NodeElement + }; + + FemSelectionGate(ElemType type) + : Gui::SelectionFilterGate((Gui::SelectionFilter*)0),Type(type) + { + }; + + ElemType Type; + + /// get called by the frame-work + bool allow(App::Document* pDoc, App::DocumentObject* pObj, const char* sSubName); +}; + +} //namespace FemGui + +#endif // GUI_FemSelectionGate_H diff --git a/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp b/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp index 170f061af..efc203a04 100644 --- a/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp +++ b/src/Mod/Fem/Gui/TaskCreateNodeSet.cpp @@ -51,11 +51,13 @@ #include #include #include "ViewProviderFemMesh.h" +#include "FemSelectionGate.h" using namespace FemGui; using namespace Gui; + TaskCreateNodeSet::TaskCreateNodeSet(Fem::FemSetNodesObject *pcObject,QWidget *parent) : TaskBox(Gui::BitmapFactory().pixmap("Fem_FemMesh_createnodebypoly"), tr("Nodes set"), @@ -72,6 +74,7 @@ TaskCreateNodeSet::TaskCreateNodeSet(Fem::FemSetNodesObject *pcObject,QWidget *p this->groupLayout()->addWidget(proxy); QObject::connect(ui->toolButton_Poly,SIGNAL(clicked()),this,SLOT(Poly())); + QObject::connect(ui->toolButton_Pick,SIGNAL(clicked()),this,SLOT(Pick())); QObject::connect(ui->comboBox,SIGNAL(activated (int)),this,SLOT(SwitchMethod(int))); MeshViewProvider = dynamic_cast(Gui::Application::Instance->getViewProvider( pcObject->FemMesh.getValue())); @@ -97,12 +100,26 @@ void TaskCreateNodeSet::Poly(void) } } +void TaskCreateNodeSet::Pick(void) +{ + if (selectionMode == none){ + selectionMode = PickElement; + Gui::Selection().clearSelection(); + Gui::Selection().addSelectionGate(new FemSelectionGate(FemSelectionGate::Element)); + } +} + void TaskCreateNodeSet::SwitchMethod(int Value) { - if(Value == 1) + if(Value == 1){ ui->groupBox_AngleSearch->setEnabled(true); - else + ui->toolButton_Pick->setEnabled(true); + ui->toolButton_Poly->setEnabled(false); + }else{ ui->groupBox_AngleSearch->setEnabled(false); + ui->toolButton_Pick->setEnabled(false); + ui->toolButton_Poly->setEnabled(true); + } } @@ -161,6 +178,26 @@ void TaskCreateNodeSet::DefineNodes(const Base::Polygon2D &polygon,const Gui::Vi } +void TaskCreateNodeSet::onSelectionChanged(const Gui::SelectionChanges& msg) +{ + if (selectionMode == none) + return; + + if (msg.Type == Gui::SelectionChanges::AddSelection) { + std::string subName(msg.pSubName); + unsigned int i=0; + for(;i 0 0 - 177 + 179 180