[FEM] Refactor TaskFemConstraintOnBoundary (#6615)
* Now the behavior is consistent with behavior of PD fillets, for example. See https://forum.freecadweb.org/viewtopic.php?f=18&t=67135#p580192. In the future it may be possible to reuse some code from there. * When the last selected item is removed we need to reset the existing highlighting separately. * Use `Gui::ButtonGroup` in `TaskFemConstraintOnBoundary`
This commit is contained in:
@@ -154,10 +154,8 @@ TaskFemConstraintDisplacement::TaskFemConstraintDisplacement(ViewProviderFemCons
|
||||
connect(ui->rotzfree, SIGNAL(stateChanged(int)), this, SLOT(rotfreez(int)));
|
||||
|
||||
//Selection buttons
|
||||
connect(ui->btnAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_addToSelection(bool)));
|
||||
connect(ui->btnRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_removeFromSelection(bool)));
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@@ -80,10 +80,8 @@ TaskFemConstraintFixed::TaskFemConstraintFixed(ViewProviderFemConstraintFixed* C
|
||||
}
|
||||
|
||||
//Selection buttons
|
||||
connect(ui->btnAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_addToSelection(bool)));
|
||||
connect(ui->btnRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_removeFromSelection(bool)));
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@@ -165,10 +165,8 @@ TaskFemConstraintFluidBoundary::TaskFemConstraintFluidBoundary(ViewProviderFemCo
|
||||
ui->checkReverse->blockSignals(true);
|
||||
|
||||
//Selection buttons
|
||||
connect(ui->btnAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_addToSelection(bool)));
|
||||
connect(ui->btnRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_removeFromSelection(bool)));
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
// Get the feature data
|
||||
Fem::ConstraintFluidBoundary* pcConstraint = static_cast<Fem::ConstraintFluidBoundary*>(ConstraintView->getObject());
|
||||
|
||||
@@ -106,10 +106,8 @@ TaskFemConstraintForce::TaskFemConstraintForce(ViewProviderFemConstraintForce* C
|
||||
ui->checkReverse->blockSignals(false);
|
||||
|
||||
//Selection buttons
|
||||
connect(ui->btnAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_addToSelection(bool)));
|
||||
connect(ui->btnRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_removeFromSelection(bool)));
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@@ -117,10 +117,8 @@ TaskFemConstraintHeatflux::TaskFemConstraintHeatflux(ViewProviderFemConstraintHe
|
||||
}
|
||||
|
||||
//Selection buttons
|
||||
connect(ui->btnAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_addToSelection(bool)));
|
||||
connect(ui->btnRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_removeFromSelection(bool)));
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
ui->if_ambienttemp->blockSignals(false);
|
||||
//ui->if_facetemp->blockSignals(false);
|
||||
|
||||
@@ -35,6 +35,12 @@ TaskFemConstraintOnBoundary::TaskFemConstraintOnBoundary(ViewProviderFemConstrai
|
||||
, selChangeMode(SelectionChangeModes::none)
|
||||
{
|
||||
ConstraintView->highlightReferences(true);
|
||||
|
||||
buttonGroup = new ButtonGroup(this);
|
||||
buttonGroup->setExclusive(true);
|
||||
|
||||
connect(buttonGroup, qOverload<QAbstractButton *, bool>(&QButtonGroup::buttonToggled),
|
||||
this, &TaskFemConstraintOnBoundary::onButtonToggled);
|
||||
}
|
||||
|
||||
TaskFemConstraintOnBoundary::~TaskFemConstraintOnBoundary()
|
||||
@@ -42,44 +48,20 @@ TaskFemConstraintOnBoundary::~TaskFemConstraintOnBoundary()
|
||||
if (!ConstraintView.expired())
|
||||
ConstraintView->highlightReferences(false);
|
||||
}
|
||||
|
||||
void TaskFemConstraintOnBoundary::_addToSelection(bool checked)
|
||||
void TaskFemConstraintOnBoundary::onButtonToggled(QAbstractButton *button, bool checked)
|
||||
{
|
||||
auto mode = static_cast<SelectionChangeModes>(buttonGroup->id(button));
|
||||
|
||||
Gui::Selection().clearSelection();
|
||||
|
||||
if (checked)
|
||||
{
|
||||
const auto& selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document
|
||||
if (selection.empty()) {
|
||||
this->clearButtons(SelectionChangeModes::refAdd);
|
||||
selChangeMode = SelectionChangeModes::refAdd;
|
||||
ConstraintView->highlightReferences(true);
|
||||
}
|
||||
else {
|
||||
this->addToSelection();
|
||||
clearButtons(SelectionChangeModes::none);
|
||||
}
|
||||
selChangeMode = mode;
|
||||
ConstraintView->highlightReferences(true);
|
||||
}
|
||||
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(SelectionChangeModes::refRemove);
|
||||
selChangeMode = SelectionChangeModes::refRemove;
|
||||
ConstraintView->highlightReferences(true);
|
||||
}
|
||||
else {
|
||||
this->removeFromSelection();
|
||||
clearButtons(SelectionChangeModes::none);
|
||||
}
|
||||
}
|
||||
else {
|
||||
exitSelectionChangeMode();
|
||||
if (selChangeMode == mode)
|
||||
selChangeMode = SelectionChangeModes::none;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,10 +86,4 @@ void TaskFemConstraintOnBoundary::onSelectionChanged(const Gui::SelectionChanges
|
||||
}
|
||||
}
|
||||
|
||||
void TaskFemConstraintOnBoundary::exitSelectionChangeMode()
|
||||
{
|
||||
selChangeMode = SelectionChangeModes::none;
|
||||
Gui::Selection().clearSelection();
|
||||
}
|
||||
|
||||
#include "moc_TaskFemConstraintOnBoundary.cpp"
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#include <Gui/Widgets.h>
|
||||
#include <Base/Quantity.h>
|
||||
|
||||
#include "TaskFemConstraint.h"
|
||||
@@ -54,19 +55,18 @@ public:
|
||||
~TaskFemConstraintOnBoundary();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void _addToSelection(bool checked);
|
||||
void onButtonToggled(QAbstractButton *button, bool checked);
|
||||
virtual void addToSelection() = 0;
|
||||
void _removeFromSelection(bool checked);
|
||||
virtual void removeFromSelection() = 0;
|
||||
|
||||
protected:
|
||||
enum class SelectionChangeModes {none, refAdd, refRemove};
|
||||
virtual void onSelectionChanged(const Gui::SelectionChanges&) override;
|
||||
virtual void clearButtons(const SelectionChangeModes notThis) = 0;
|
||||
void exitSelectionChangeMode();
|
||||
|
||||
protected:
|
||||
enum SelectionChangeModes selChangeMode;
|
||||
Gui::ButtonGroup *buttonGroup;
|
||||
};
|
||||
|
||||
} // namespace FemGui
|
||||
|
||||
@@ -89,10 +89,8 @@ TaskFemConstraintPressure::TaskFemConstraintPressure(ViewProviderFemConstraintPr
|
||||
}
|
||||
|
||||
//Selection buttons
|
||||
connect(ui->btnAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_addToSelection(bool)));
|
||||
connect(ui->btnRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_removeFromSelection(bool)));
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@@ -92,10 +92,8 @@ TaskFemConstraintSpring::TaskFemConstraintSpring(ViewProviderFemConstraintSpring
|
||||
}
|
||||
|
||||
//Selection buttons
|
||||
connect(ui->btnAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_addToSelection(bool)));
|
||||
connect(ui->btnRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_removeFromSelection(bool)));
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@@ -106,10 +106,8 @@ TaskFemConstraintTemperature::TaskFemConstraintTemperature(ViewProviderFemConstr
|
||||
}
|
||||
|
||||
//Selection buttons
|
||||
connect(ui->btnAdd, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_addToSelection(bool)));
|
||||
connect(ui->btnRemove, SIGNAL(toggled(bool)),
|
||||
this, SLOT(_removeFromSelection(bool)));
|
||||
buttonGroup->addButton(ui->btnAdd, (int)SelectionChangeModes::refAdd);
|
||||
buttonGroup->addButton(ui->btnRemove, (int)SelectionChangeModes::refRemove);
|
||||
|
||||
updateUI();
|
||||
}
|
||||
|
||||
@@ -56,16 +56,14 @@ void ViewProviderFemConstraintOnBoundary::highlightReferences(const bool on)
|
||||
const auto& subSets = pcConstraint->References.getSubListValues();
|
||||
|
||||
for (auto& subSet : subSets) {
|
||||
// if somehow the subnames are empty, we have nothing to do
|
||||
if (subSet.second.empty())
|
||||
continue;
|
||||
|
||||
Part::Feature* base = static_cast<Part::Feature*>(subSet.first);
|
||||
Part::Feature* base = dynamic_cast<Part::Feature*>(subSet.first);
|
||||
if (!base) continue;
|
||||
PartGui::ViewProviderPart* vp = dynamic_cast<PartGui::ViewProviderPart*>(
|
||||
Gui::Application::Instance->getViewProvider(base));
|
||||
if (vp == nullptr) continue;
|
||||
if (!vp) continue;
|
||||
|
||||
if (on) {
|
||||
// if somehow the subnames are empty, clear any existing colors
|
||||
if (on && !subSet.second.empty()) {
|
||||
// identify the type of subelements
|
||||
// TODO: Assumed here the subelements are of the same type.
|
||||
// It is a requirement but we should keep safeguards.
|
||||
@@ -107,22 +105,53 @@ void ViewProviderFemConstraintOnBoundary::highlightReferences(const bool on)
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (subSet.second[0].find("Vertex") != std::string::npos &&
|
||||
!originalPointColors[base].empty()) {
|
||||
if (!originalPointColors[base].empty()) {
|
||||
vp->PointColorArray.setValues(originalPointColors[base]);
|
||||
originalPointColors[base].clear();
|
||||
}
|
||||
else if (subSet.second[0].find("Edge") != std::string::npos &&
|
||||
!originalLineColors[base].empty()) {
|
||||
else if (!originalLineColors[base].empty()) {
|
||||
vp->LineColorArray.setValues(originalLineColors[base]);
|
||||
originalLineColors[base].clear();
|
||||
}
|
||||
else if (subSet.second[0].find("Face") != std::string::npos &&
|
||||
!originalFaceColors[base].empty()) {
|
||||
else if (!originalFaceColors[base].empty()) {
|
||||
vp->DiffuseColor.setValues(originalFaceColors[base]);
|
||||
originalFaceColors[base].clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (subSets.empty()) {
|
||||
// there is nothing selected but previous selection may have highlighting
|
||||
// reset that highlighting here
|
||||
for (auto& ogPair : originalPointColors) {
|
||||
if (ogPair.second.empty()) continue;
|
||||
PartGui::ViewProviderPart* vp = dynamic_cast<PartGui::ViewProviderPart*>(
|
||||
Gui::Application::Instance->getViewProvider(ogPair.first));
|
||||
if (!vp) continue;
|
||||
|
||||
vp->PointColorArray.setValues(ogPair.second);
|
||||
ogPair.second.clear();
|
||||
}
|
||||
|
||||
for (auto& ogPair : originalLineColors) {
|
||||
if (ogPair.second.empty()) continue;
|
||||
PartGui::ViewProviderPart* vp = dynamic_cast<PartGui::ViewProviderPart*>(
|
||||
Gui::Application::Instance->getViewProvider(ogPair.first));
|
||||
if (!vp) continue;
|
||||
|
||||
vp->LineColorArray.setValues(ogPair.second);
|
||||
ogPair.second.clear();
|
||||
}
|
||||
|
||||
for (auto& ogPair : originalFaceColors) {
|
||||
if (ogPair.second.empty()) continue;
|
||||
PartGui::ViewProviderPart* vp = dynamic_cast<PartGui::ViewProviderPart*>(
|
||||
Gui::Application::Instance->getViewProvider(ogPair.first));
|
||||
if (!vp) continue;
|
||||
|
||||
vp->DiffuseColor.setValues(ogPair.second);
|
||||
ogPair.second.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user