diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp index 8f4f49dddb..5cf222c7f6 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp @@ -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(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp index ee5eabc3c0..10097ffeea 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp @@ -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(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp index 7bfbccb0cc..303777de22 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp @@ -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(ConstraintView->getObject()); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp index 39a34abff9..8ecac686b3 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp @@ -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(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp index be43f8dbf2..c5b99de74b 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp @@ -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); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp index a57fca6e4b..c8c880e8ca 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp @@ -35,6 +35,12 @@ TaskFemConstraintOnBoundary::TaskFemConstraintOnBoundary(ViewProviderFemConstrai , selChangeMode(SelectionChangeModes::none) { ConstraintView->highlightReferences(true); + + buttonGroup = new ButtonGroup(this); + buttonGroup->setExclusive(true); + + connect(buttonGroup, qOverload(&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(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" diff --git a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h index a5d4b7cd6f..17833b2e9a 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h @@ -28,6 +28,7 @@ #include #include #include +#include #include #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 diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp index df346f826d..791428f521 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -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(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp index 4900e905a3..373915a17f 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp @@ -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(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp index 6afbf579a7..49bceba6d3 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -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(); } diff --git a/src/Mod/Fem/Gui/ViewProviderFemConstraintOnBoundary.cpp b/src/Mod/Fem/Gui/ViewProviderFemConstraintOnBoundary.cpp index 5c5267e328..79612b3c7f 100644 --- a/src/Mod/Fem/Gui/ViewProviderFemConstraintOnBoundary.cpp +++ b/src/Mod/Fem/Gui/ViewProviderFemConstraintOnBoundary.cpp @@ -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(subSet.first); + Part::Feature* base = dynamic_cast(subSet.first); + if (!base) continue; PartGui::ViewProviderPart* vp = dynamic_cast( 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( + 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( + 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( + Gui::Application::Instance->getViewProvider(ogPair.first)); + if (!vp) continue; + + vp->DiffuseColor.setValues(ogPair.second); + ogPair.second.clear(); + } + } }