diff --git a/src/Mod/Fem/Gui/CMakeLists.txt b/src/Mod/Fem/Gui/CMakeLists.txt index cb1d00273c..097e6a446f 100755 --- a/src/Mod/Fem/Gui/CMakeLists.txt +++ b/src/Mod/Fem/Gui/CMakeLists.txt @@ -140,6 +140,8 @@ SET(FemGui_DLG_SRCS TaskFemConstraint.ui TaskFemConstraint.cpp TaskFemConstraint.h + TaskFemConstraintOnBoundary.cpp + TaskFemConstraintOnBoundary.h TaskFemConstraintBearing.ui TaskFemConstraintBearing.cpp TaskFemConstraintBearing.h diff --git a/src/Mod/Fem/Gui/TaskFemConstraint.cpp b/src/Mod/Fem/Gui/TaskFemConstraint.cpp index b87ea73820..62f51d1550 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraint.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraint.cpp @@ -201,6 +201,11 @@ void TaskFemConstraint::onButtonWizCancel() onButtonWizOk(); } +const QString TaskFemConstraint::makeRefText(const std::string& objName, const std::string& subName) const +{ + return QString::fromUtf8((objName + ":" + subName).c_str()); +} + const QString TaskFemConstraint::makeRefText(const App::DocumentObject* obj, const std::string& subName) const { return QString::fromUtf8((std::string(obj->getNameInDocument()) + ":" + subName).c_str()); diff --git a/src/Mod/Fem/Gui/TaskFemConstraint.h b/src/Mod/Fem/Gui/TaskFemConstraint.h index c3b29ded24..2dab3c55d0 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraint.h +++ b/src/Mod/Fem/Gui/TaskFemConstraint.h @@ -59,12 +59,11 @@ protected Q_SLOTS: protected: virtual void changeEvent(QEvent *e) { TaskBox::changeEvent(e); } + const QString makeRefText(const std::string& objName, const std::string& subName) const; const QString makeRefText(const App::DocumentObject* obj, const std::string& subName) const; virtual void keyPressEvent(QKeyEvent * ke); void createDeleteAction(QListWidget* parentList); bool KeyEvent(QEvent *e); - -private: virtual void onSelectionChanged(const Gui::SelectionChanges&) {} protected: diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp index 2d215d5168..94e5c3d234 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp @@ -54,6 +54,7 @@ #include #include #include +#include using namespace FemGui; @@ -62,7 +63,7 @@ using namespace Gui; /* TRANSLATOR FemGui::TaskFemConstraintDisplacement */ TaskFemConstraintDisplacement::TaskFemConstraintDisplacement(ViewProviderFemConstraintDisplacement *ConstraintView,QWidget *parent) - : TaskFemConstraint(ConstraintView, parent, "FEM_ConstraintDisplacement") + : TaskFemConstraintOnBoundary(ConstraintView, parent, "FEM_ConstraintDisplacement") { proxy = new QWidget(this); ui = new Ui_TaskFemConstraintDisplacement(); @@ -197,8 +198,10 @@ TaskFemConstraintDisplacement::TaskFemConstraintDisplacement(ViewProviderFemCons ui->rotzfree->blockSignals(false); //Selection buttons - connect(ui->btnAdd, SIGNAL(clicked()), this, SLOT(addToSelection())); - connect(ui->btnRemove, SIGNAL(clicked()), this, SLOT(removeFromSelection())); + connect(ui->btnAdd, SIGNAL(toggled(bool)), + this, SLOT(_addToSelection(bool))); + connect(ui->btnRemove, SIGNAL(toggled(bool)), + this, SLOT(_removeFromSelection(bool))); updateUI(); } @@ -563,6 +566,12 @@ void TaskFemConstraintDisplacement::changeEvent(QEvent *) // } } +void TaskFemConstraintDisplacement::clearButtons(const SelectionChangeModes notThis) +{ + if (notThis != refAdd) ui->btnAdd->setChecked(false); + if (notThis != refRemove) ui->btnRemove->setChecked(false); +} + //************************************************************************** // TaskDialog //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.h b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.h index 6ced3f52c8..d2f7b21fae 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.h @@ -33,6 +33,7 @@ #include #include "TaskFemConstraint.h" +#include "TaskFemConstraintOnBoundary.h" #include "ViewProviderFemConstraintDisplacement.h" #include @@ -43,7 +44,7 @@ class Ui_TaskFemConstraintDisplacement; namespace FemGui { -class TaskFemConstraintDisplacement : public TaskFemConstraint +class TaskFemConstraintDisplacement : public TaskFemConstraintOnBoundary { Q_OBJECT @@ -95,8 +96,9 @@ private Q_SLOTS: void removeFromSelection(); protected: - bool event(QEvent *e); + bool event(QEvent *e); void changeEvent(QEvent *e); + void clearButtons(const SelectionChangeModes notThis) override; private: void updateUI(); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.ui b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.ui index ee83fbaf0b..5c5fb789dd 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.ui +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.ui @@ -54,17 +54,23 @@ - + Add + + true + - + Remove + + true + diff --git a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp new file mode 100644 index 0000000000..e738e9ab89 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp @@ -0,0 +1,128 @@ +/*************************************************************************** + * Copyright (c) 2021 FreeCAD Developers * + * Author: Ajinkya Dahale * + * 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 + +# include +# include +# include +# include +# include + +# include +# include +# include +# include +# include +#endif + +#include "TaskFemConstraintOnBoundary.h" +#include +#include +#include +#include +#include + + +using namespace FemGui; +using namespace Gui; + +/* TRANSLATOR FemGui::TaskFemConstraintOnBoundary */ + +TaskFemConstraintOnBoundary::TaskFemConstraintOnBoundary(ViewProviderFemConstraint *ConstraintView, QWidget *parent, const char* pixmapname) + : TaskFemConstraint(ConstraintView, parent, pixmapname) +{ +} + +TaskFemConstraintOnBoundary::~TaskFemConstraintOnBoundary() +{ +} + +void TaskFemConstraintOnBoundary::_addToSelection(bool checked) +{ + if (checked) + { + const auto& selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + if (selection.empty()) { + this->clearButtons(refAdd); + selChangeMode = refAdd; + } else { + this->addToSelection(); + clearButtons(none); + } + } else { + exitSelectionChangeMode(); + } +} + +void TaskFemConstraintOnBoundary::_removeFromSelection(bool checked) +{ + if (checked) + { + const auto& selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document + if (selection.empty()) { + this->clearButtons(refRemove); + selChangeMode = refRemove; + } else { + this->removeFromSelection(); + clearButtons(none); + } + } else { + exitSelectionChangeMode(); + } +} + +void TaskFemConstraintOnBoundary::onSelectionChanged(const Gui::SelectionChanges&msg) +{ + if (msg.Type == Gui::SelectionChanges::AddSelection) { + switch (selChangeMode) { + case refAdd: + // TODO: Optimize to just perform actions on the newly selected item. Suggestion from PartDesign: + // ui->lw_references->addItem(makeRefText(msg.pObjectName, msg.pSubName)); + this->addToSelection(); + break; + case refRemove: + this->removeFromSelection(); + break; + case none: + return; + default: + return; + } + } +} + +void TaskFemConstraintOnBoundary::exitSelectionChangeMode() +{ + selChangeMode = none; + Gui::Selection().clearSelection(); +} + +#include "moc_TaskFemConstraintOnBoundary.cpp" diff --git a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h new file mode 100644 index 0000000000..908174a245 --- /dev/null +++ b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (c) 2021 FreeCAD Developers * + * Author: Ajinkya Dahale * + * * + * 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_TASKVIEW_TaskFemConstraintOnBoundary_H +#define GUI_TASKVIEW_TaskFemConstraintOnBoundary_H + +#include +#include +#include +#include + +#include "TaskFemConstraint.h" + +#include +#include +#include +#include + +namespace FemGui { + +/** @brief Taskbox for FEM constraints that apply on subsets of the domain boundary + * + * @detail Convenience superclass for taskboxes setting certain constraints + * that apply on subsets of the boundary (faces/edges/vertices), where one or + * more boundary entities need to be selected. + */ +class TaskFemConstraintOnBoundary : public TaskFemConstraint +{ + Q_OBJECT + +public: + TaskFemConstraintOnBoundary(ViewProviderFemConstraint *ConstraintView, QWidget *parent = 0, const char* pixmapname = ""); + ~TaskFemConstraintOnBoundary(); + +protected Q_SLOTS: + void _addToSelection(bool checked); + virtual void addToSelection() = 0; + void _removeFromSelection(bool checked); + virtual void removeFromSelection() = 0; + +protected: + enum SelectionChangeModes {none, refAdd, refRemove}; + virtual void onSelectionChanged(const Gui::SelectionChanges&) override; + virtual void clearButtons(const SelectionChangeModes notThis) = 0; + void exitSelectionChangeMode(); + +protected: + enum SelectionChangeModes selChangeMode; +}; + +} // namespace FemGui + +#endif // GUI_TASKVIEW_TaskFemConstraintOnBoundary_H