[FEM] Add modal add/remove for dispacement constraint
With this, add/remove buttons for displacement constraint will put the user in a selection mode if pressed when nothing is selected. Superclass `TaskFemConstraintOnBoundary` Allows code reuse for other constraints. We do not need this in `TaskFemConstraints` because it is only used in a subset of constraints, particularly that applies on only some of the boundary entities. TODO: Confirm Undo/Redo works appropriately. TODO: Optimize `onSelectionChanged()`.
This commit is contained in:
@@ -140,6 +140,8 @@ SET(FemGui_DLG_SRCS
|
||||
TaskFemConstraint.ui
|
||||
TaskFemConstraint.cpp
|
||||
TaskFemConstraint.h
|
||||
TaskFemConstraintOnBoundary.cpp
|
||||
TaskFemConstraintOnBoundary.h
|
||||
TaskFemConstraintBearing.ui
|
||||
TaskFemConstraintBearing.cpp
|
||||
TaskFemConstraintBearing.h
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -54,6 +54,7 @@
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/SelectionFilter.h>
|
||||
#include <Mod/Part/App/PartFeature.h>
|
||||
#include <Mod/PartDesign/Gui/ReferenceSelection.h>
|
||||
|
||||
|
||||
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
|
||||
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include <Base/Quantity.h>
|
||||
|
||||
#include "TaskFemConstraint.h"
|
||||
#include "TaskFemConstraintOnBoundary.h"
|
||||
#include "ViewProviderFemConstraintDisplacement.h"
|
||||
|
||||
#include <QObject>
|
||||
@@ -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();
|
||||
|
||||
@@ -54,17 +54,23 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="hLayout1">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnAdd">
|
||||
<widget class="QToolButton" name="btnAdd">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRemove">
|
||||
<widget class="QToolButton" name="btnRemove">
|
||||
<property name="text">
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
128
src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp
Normal file
128
src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp
Normal file
@@ -0,0 +1,128 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2021 FreeCAD Developers *
|
||||
* Author: Ajinkya Dahale <dahale.a.p@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 <BRepAdaptor_Curve.hxx>
|
||||
# include <BRepAdaptor_Surface.hxx>
|
||||
# include <Geom_Line.hxx>
|
||||
# include <Geom_Plane.hxx>
|
||||
# include <Precision.hxx>
|
||||
|
||||
# include <QAction>
|
||||
# include <QKeyEvent>
|
||||
# include <QMessageBox>
|
||||
# include <QRegExp>
|
||||
# include <QTextStream>
|
||||
|
||||
# include <TopoDS.hxx>
|
||||
# include <gp_Ax1.hxx>
|
||||
# include <gp_Lin.hxx>
|
||||
# include <gp_Pln.hxx>
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
#include "TaskFemConstraintOnBoundary.h"
|
||||
#include <App/Application.h>
|
||||
#include <Base/Tools.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/SelectionFilter.h>
|
||||
|
||||
|
||||
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"
|
||||
74
src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h
Normal file
74
src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2021 FreeCAD Developers *
|
||||
* Author: Ajinkya Dahale <dahale.a.p@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 GUI_TASKVIEW_TaskFemConstraintOnBoundary_H
|
||||
#define GUI_TASKVIEW_TaskFemConstraintOnBoundary_H
|
||||
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#include <Base/Quantity.h>
|
||||
|
||||
#include "TaskFemConstraint.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <Base/Console.h>
|
||||
#include <App/DocumentObject.h>
|
||||
#include <QKeyEvent>
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user