From b2e6f91c1d672a9c9bb3b88d15cbee196ee5a0c0 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Mon, 22 Nov 2021 17:30:06 -0500 Subject: [PATCH] [PD] Use `buttonToggled` signal in PD pipe Combines other button toggle methods/signals/slots involved. --- src/Mod/PartDesign/Gui/TaskPipeParameters.cpp | 340 +++++++----------- src/Mod/PartDesign/Gui/TaskPipeParameters.h | 61 ++-- 2 files changed, 169 insertions(+), 232 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp index 673614ee6b..8fc507b326 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.cpp @@ -83,16 +83,11 @@ TaskPipeParameters::TaskPipeParameters(ViewProviderPipe *PipeView, bool /*newObj ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); + // some buttons are handled in a buttongroup connect(ui->buttonProfileBase, SIGNAL(toggled(bool)), this, SLOT(onProfileButton(bool))); connect(ui->comboBoxTransition, SIGNAL(currentIndexChanged(int)), this, SLOT(onTransitionChanged(int))); - connect(ui->buttonRefAdd, SIGNAL(toggled(bool)), - this, SLOT(onButtonRefAdd(bool))); - connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), - this, SLOT(onButtonRefRemove(bool))); - connect(ui->buttonSpineBase, SIGNAL(toggled(bool)), - this, SLOT(onBaseButton(bool))); // Create context menu QAction* remove = new QAction(tr("Remove"), this); @@ -182,12 +177,12 @@ void TaskPipeParameters::updateUI() void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) { - if (selectionMode == none) + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) return; if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { - if (selectionMode == refProfile) { + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refProfile) { App::Document* document = App::GetApplication().getDocument(msg.pDocName); App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; if (object) { @@ -195,7 +190,7 @@ void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) ui->profileBaseEdit->setText(label); } } - else if (selectionMode == refAdd) { + else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd) { QString sub = QString::fromStdString(msg.pSubName); if (!sub.isEmpty()) { QListWidgetItem* item = new QListWidgetItem(); @@ -211,7 +206,7 @@ void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) ui->spineBaseEdit->setText(label); } } - else if (selectionMode == refRemove) { + else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove) { QString sub = QString::fromLatin1(msg.pSubName); if (!sub.isEmpty()) { removeFromListWidget(ui->listWidgetReferences, sub); @@ -220,7 +215,7 @@ void TaskPipeParameters::onSelectionChanged(const Gui::SelectionChanges& msg) ui->spineBaseEdit->clear(); } } - else if (selectionMode == refObjAdd) { + else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::refSpine) { ui->listWidgetReferences->clear(); App::Document* document = App::GetApplication().getDocument(msg.pDocName); @@ -246,54 +241,6 @@ void TaskPipeParameters::onTransitionChanged(int idx) recomputeFeature(); } -void TaskPipeParameters::onButtonRefAdd(bool checked) -{ - if (checked) { - //hideObject(); - Gui::Selection().clearSelection(); - selectionMode = refAdd; - static_cast(vp)->highlightReferences(ViewProviderPipe::Spine, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refAdd) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::Spine, false); - } -} - -void TaskPipeParameters::onButtonRefRemove(bool checked) -{ - if (checked) { - //hideObject(); - Gui::Selection().clearSelection(); - selectionMode = refRemove; - static_cast(vp)->highlightReferences(ViewProviderPipe::Spine, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refRemove) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::Spine, false); - } -} - -void TaskPipeParameters::onBaseButton(bool checked) -{ - if (checked) { - //hideObject(); - Gui::Selection().clearSelection(); - selectionMode = refObjAdd; - static_cast(vp)->highlightReferences(ViewProviderPipe::Spine, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refObjAdd) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::Spine, false); - } -} - void TaskPipeParameters::onProfileButton(bool checked) { if (checked) { @@ -304,17 +251,6 @@ void TaskPipeParameters::onProfileButton(bool checked) auto* pvp = doc->getViewProvider(pipe->Profile.getValue()); pvp->setVisible(true); } - - //hideObject(); - Gui::Selection().clearSelection(); - selectionMode = refProfile; - static_cast(vp)->highlightReferences(ViewProviderPipe::Profile, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refProfile) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::Profile, false); } } @@ -362,7 +298,10 @@ void TaskPipeParameters::onDeleteEdge() bool TaskPipeParameters::referenceSelected(const SelectionChanges& msg) const { - if (msg.Type == Gui::SelectionChanges::AddSelection && selectionMode != none) { + auto selectionMode = stateHandler->getSelectionMode(); + + if (msg.Type == Gui::SelectionChanges::AddSelection && + selectionMode != StateHandlerTaskPipe::SelectionModes::none) { if (strcmp(msg.pDocName, vp->getObject()->getDocument()->getName()) != 0) return false; @@ -371,7 +310,9 @@ bool TaskPipeParameters::referenceSelected(const SelectionChanges& msg) const if (strcmp(msg.pObjectName, fname) == 0) return false; - if (selectionMode == refProfile) { + switch (selectionMode) { + case StateHandlerTaskPipe::SelectionModes::refProfile: + { PartDesign::Pipe* pipe = static_cast(vp->getObject()); Gui::Document* doc = vp->getDocument(); @@ -397,23 +338,26 @@ bool TaskPipeParameters::referenceSelected(const SelectionChanges& msg) const } return success; } - else if (selectionMode == refObjAdd || selectionMode == refAdd || selectionMode == refRemove) { + case StateHandlerTaskPipe::SelectionModes::refSpine: + case StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd: + case StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove: + { //change the references std::string subName(msg.pSubName); std::vector refs = static_cast(vp->getObject())->Spine.getSubValues(); std::vector::iterator f = std::find(refs.begin(), refs.end(), subName); - if (selectionMode == refObjAdd) { + if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpine) { static_cast(vp)->highlightReferences(ViewProviderPipe::Spine, false); refs.clear(); } - else if (selectionMode == refAdd) { + else if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd) { if (f == refs.end()) refs.push_back(subName); else return false; // duplicate selection } - else if (selectionMode == refRemove) { + else if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove) { if (f != refs.end()) refs.erase(f); else @@ -424,27 +368,26 @@ bool TaskPipeParameters::referenceSelected(const SelectionChanges& msg) const vp->getObject()->getDocument()->getObject(msg.pObjectName), refs); return true; } + default: + return false; + } } return false; } -void TaskPipeParameters::clearButtons(const selectionModes notThis) +void TaskPipeParameters::clearButtons() { - // TODO: Clear buttons in the other pipe taskboxes as well - if (notThis != refProfile) - ui->buttonProfileBase->setChecked(false); - if (notThis != refAdd) - ui->buttonRefAdd->setChecked(false); - if (notThis != refRemove) - ui->buttonRefRemove->setChecked(false); - if (notThis != refObjAdd) - ui->buttonSpineBase->setChecked(false); + ui->buttonProfileBase->setChecked(false); + ui->buttonRefAdd->setChecked(false); + ui->buttonRefRemove->setChecked(false); + ui->buttonSpineBase->setChecked(false); } void TaskPipeParameters::exitSelectionMode() { - selectionMode = none; + // commenting because this should be handled by buttonToggled signal + // selectionMode = none; Gui::Selection().clearSelection(); } @@ -609,14 +552,9 @@ TaskPipeOrientation::TaskPipeOrientation(ViewProviderPipe* PipeView, bool /*newO ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); + // some buttons are handled in a buttongroup connect(ui->comboBoxMode, SIGNAL(currentIndexChanged(int)), this, SLOT(onOrientationChanged(int))); - connect(ui->buttonRefAdd, SIGNAL(toggled(bool)), - this, SLOT(onButtonRefAdd(bool))); - connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), - this, SLOT(onButtonRefRemove(bool))); - connect(ui->buttonProfileBase, SIGNAL(toggled(bool)), - this, SLOT(onBaseButton(bool))); connect(ui->buttonProfileClear, SIGNAL(clicked()), this, SLOT(onClearButton())); connect(ui->stackedWidget, SIGNAL(currentChanged(int)), @@ -681,68 +619,20 @@ void TaskPipeOrientation::onOrientationChanged(int idx) recomputeFeature(); } -void TaskPipeOrientation::clearButtons(const selectionModes notThis) +void TaskPipeOrientation::clearButtons() { - // TODO: Clear buttons in the other pipe taskboxes as well - if (notThis != refAdd) - ui->buttonRefAdd->setChecked(false); - if (notThis != refRemove) - ui->buttonRefRemove->setChecked(false); - if (notThis != refObjAdd) - ui->buttonProfileBase->setChecked(false); + ui->buttonRefAdd->setChecked(false); + ui->buttonRefRemove->setChecked(false); + ui->buttonProfileBase->setChecked(false); } void TaskPipeOrientation::exitSelectionMode() { - selectionMode = none; + // commenting because this should be handled by buttonToggled signal + // selectionMode = none; Gui::Selection().clearSelection(); } -void TaskPipeOrientation::onButtonRefAdd(bool checked) -{ - if (checked) { - Gui::Selection().clearSelection(); - selectionMode = refAdd; - static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refAdd) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, false); - } -} - -void TaskPipeOrientation::onButtonRefRemove(bool checked) -{ - if (checked) { - Gui::Selection().clearSelection(); - selectionMode = refRemove; - static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refRemove) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, false); - } -} - -void TaskPipeOrientation::onBaseButton(bool checked) -{ - if (checked) { - Gui::Selection().clearSelection(); - selectionMode = refObjAdd; - static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refObjAdd) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, false); - } -} - void TaskPipeOrientation::onClearButton() { static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, false); @@ -770,12 +660,12 @@ void TaskPipeOrientation::onBinormalChanged(double) void TaskPipeOrientation::onSelectionChanged(const SelectionChanges& msg) { - if (selectionMode == none) + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) return; if (msg.Type == Gui::SelectionChanges::AddSelection) { if (referenceSelected(msg)) { - if (selectionMode == refAdd) { + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd) { QString sub = QString::fromStdString(msg.pSubName); if (!sub.isEmpty()) { QListWidgetItem* item = new QListWidgetItem(); @@ -791,7 +681,7 @@ void TaskPipeOrientation::onSelectionChanged(const SelectionChanges& msg) ui->profileBaseEdit->setText(label); } } - else if (selectionMode == refRemove) { + else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove) { QString sub = QString::fromLatin1(msg.pSubName); if (!sub.isEmpty()) removeFromListWidget(ui->listWidgetReferences, sub); @@ -799,7 +689,7 @@ void TaskPipeOrientation::onSelectionChanged(const SelectionChanges& msg) ui->profileBaseEdit->clear(); } } - else if (selectionMode == refObjAdd) { + else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refAuxSpine) { ui->listWidgetReferences->clear(); App::Document* document = App::GetApplication().getDocument(msg.pDocName); @@ -822,7 +712,12 @@ void TaskPipeOrientation::onSelectionChanged(const SelectionChanges& msg) bool TaskPipeOrientation::referenceSelected(const SelectionChanges& msg) const { - if (msg.Type == Gui::SelectionChanges::AddSelection && selectionMode != none) { + auto selectionMode = stateHandler->getSelectionMode(); + + if (msg.Type == Gui::SelectionChanges::AddSelection && + (selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpine || + selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd || + selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove)) { if (strcmp(msg.pDocName, vp->getObject()->getDocument()->getName()) != 0) return false; @@ -836,16 +731,16 @@ bool TaskPipeOrientation::referenceSelected(const SelectionChanges& msg) const std::vector refs = static_cast(vp->getObject())->AuxillerySpine.getSubValues(); std::vector::iterator f = std::find(refs.begin(), refs.end(), subName); - if (selectionMode == refObjAdd) { + if (selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpine) { refs.clear(); } - else if (selectionMode == refAdd) { + else if (selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd) { if (f == refs.end()) refs.push_back(subName); else return false; // duplicate selection } - else if (selectionMode == refRemove) { + else if (selectionMode == StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove) { if (f != refs.end()) refs.erase(f); else @@ -920,12 +815,9 @@ TaskPipeScaling::TaskPipeScaling(ViewProviderPipe* PipeView, bool /*newObj*/, QW ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); + // some buttons are handled in a buttongroup connect(ui->comboBoxScaling, SIGNAL(currentIndexChanged(int)), this, SLOT(onScalingChanged(int))); - connect(ui->buttonRefAdd, SIGNAL(toggled(bool)), - this, SLOT(onButtonRefAdd(bool))); - connect(ui->buttonRefRemove, SIGNAL(toggled(bool)), - this, SLOT(onButtonRefRemove(bool))); connect(ui->stackedWidget, SIGNAL(currentChanged(int)), this, SLOT(updateUI(int))); @@ -992,51 +884,19 @@ void TaskPipeScaling::indexesMoved() updateUI(ui->stackedWidget->currentIndex()); } -void TaskPipeScaling::clearButtons(const selectionModes notThis) +void TaskPipeScaling::clearButtons() { - // TODO: Clear buttons in the other pipe taskboxes as well - if (notThis != refRemove) - ui->buttonRefRemove->setChecked(false); - if (notThis != refAdd) - ui->buttonRefAdd->setChecked(false); + ui->buttonRefRemove->setChecked(false); + ui->buttonRefAdd->setChecked(false); } void TaskPipeScaling::exitSelectionMode() { - selectionMode = none; + // commenting because this should be handled by buttonToggled signal + // selectionMode = none; Gui::Selection().clearSelection(); } -void TaskPipeScaling::onButtonRefAdd(bool checked) -{ - if (checked) { - Gui::Selection().clearSelection(); - selectionMode = refAdd; - static_cast(vp)->highlightReferences(ViewProviderPipe::Section, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refAdd) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::Section, false); - } -} - -void TaskPipeScaling::onButtonRefRemove(bool checked) -{ - if (checked) { - Gui::Selection().clearSelection(); - selectionMode = refRemove; - static_cast(vp)->highlightReferences(ViewProviderPipe::Section, true); - } - else { - Gui::Selection().clearSelection(); - if (selectionMode == refRemove) - selectionMode = none; - static_cast(vp)->highlightReferences(ViewProviderPipe::Section, false); - } -} - void TaskPipeScaling::onScalingChanged(int idx) { updateUI(idx); @@ -1045,7 +905,7 @@ void TaskPipeScaling::onScalingChanged(int idx) void TaskPipeScaling::onSelectionChanged(const SelectionChanges& msg) { - if (selectionMode == none) + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::none) return; if (msg.Type == Gui::SelectionChanges::AddSelection) { @@ -1054,14 +914,14 @@ void TaskPipeScaling::onSelectionChanged(const SelectionChanges& msg) App::DocumentObject* object = document ? document->getObject(msg.pObjectName) : nullptr; if (object) { QString label = make2DLabel(object, {msg.pSubName}); - if (selectionMode == refAdd) { + if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSectionAdd) { QListWidgetItem* item = new QListWidgetItem(); item->setText(label); item->setData(Qt::UserRole, QVariant::fromValue(std::make_pair(object, std::vector(1, msg.pSubName)))); ui->listWidgetReferences->addItem(item); } - else if (selectionMode == refRemove) { + else if (stateHandler->getSelectionMode() == StateHandlerTaskPipe::SelectionModes::refSectionRemove) { removeFromListWidget(ui->listWidgetReferences, label); } } @@ -1076,8 +936,11 @@ void TaskPipeScaling::onSelectionChanged(const SelectionChanges& msg) bool TaskPipeScaling::referenceSelected(const SelectionChanges& msg) const { - if ((msg.Type == Gui::SelectionChanges::AddSelection) && ( - (selectionMode == refAdd) || (selectionMode == refRemove))) { + auto selectionMode = stateHandler->getSelectionMode(); + + if ((msg.Type == Gui::SelectionChanges::AddSelection) && + ((selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionAdd) || + (selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionRemove))) { if (strcmp(msg.pDocName, vp->getObject()->getDocument()->getName()) != 0) return false; @@ -1095,7 +958,7 @@ bool TaskPipeScaling::referenceSelected(const SelectionChanges& msg) const App::DocumentObject* obj = vp->getObject()->getDocument()->getObject(msg.pObjectName); std::vector::iterator f = std::find(refs.begin(), refs.end(), obj); - if (selectionMode == refAdd) { + if (selectionMode == StateHandlerTaskPipe::SelectionModes::refSectionAdd) { if (f == refs.end()) pipe->Sections.addValue(obj, {msg.pSubName}); else @@ -1178,30 +1041,85 @@ TaskDlgPipeParameters::TaskDlgPipeParameters(ViewProviderPipe *PipeView,bool new orientation = new TaskPipeOrientation(PipeView,newObj); scaling = new TaskPipeScaling(PipeView,newObj); + stateHandler = new StateHandlerTaskPipe(); + Content.push_back(parameter); Content.push_back(orientation); Content.push_back(scaling); + parameter->stateHandler = stateHandler; + orientation->stateHandler = stateHandler; + scaling->stateHandler = stateHandler; buttonGroup = new ButtonGroup(this); buttonGroup->setExclusive(true); - buttonGroup->addButton(parameter->ui->buttonProfileBase); - buttonGroup->addButton(parameter->ui->buttonRefAdd); - buttonGroup->addButton(parameter->ui->buttonRefRemove); - buttonGroup->addButton(parameter->ui->buttonSpineBase); + buttonGroup->addButton(parameter->ui->buttonProfileBase, + StateHandlerTaskPipe::refProfile); + buttonGroup->addButton(parameter->ui->buttonSpineBase, + StateHandlerTaskPipe::refSpine); + buttonGroup->addButton(parameter->ui->buttonRefAdd, + StateHandlerTaskPipe::refSpineEdgeAdd); + buttonGroup->addButton(parameter->ui->buttonRefRemove, + StateHandlerTaskPipe::refSpineEdgeRemove); - buttonGroup->addButton(orientation->ui->buttonRefAdd); - buttonGroup->addButton(orientation->ui->buttonRefRemove); - buttonGroup->addButton(orientation->ui->buttonProfileBase); + buttonGroup->addButton(orientation->ui->buttonProfileBase, + StateHandlerTaskPipe::refAuxSpine); + buttonGroup->addButton(orientation->ui->buttonRefAdd, + StateHandlerTaskPipe::refAuxSpineEdgeAdd); + buttonGroup->addButton(orientation->ui->buttonRefRemove, + StateHandlerTaskPipe::refAuxSpineEdgeRemove); - buttonGroup->addButton(scaling->ui->buttonRefAdd); - buttonGroup->addButton(scaling->ui->buttonRefRemove); + buttonGroup->addButton(scaling->ui->buttonRefAdd, + StateHandlerTaskPipe::refSectionAdd); + buttonGroup->addButton(scaling->ui->buttonRefRemove, + StateHandlerTaskPipe::refSectionRemove); + + connect(buttonGroup, QOverload::of(&QButtonGroup::buttonToggled), + this, &TaskDlgPipeParameters::onButtonToggled); } TaskDlgPipeParameters::~TaskDlgPipeParameters() { + delete stateHandler; +} +void TaskDlgPipeParameters::onButtonToggled(QAbstractButton *button, bool checked) +{ + int id = buttonGroup->id(button); + + if (checked) { + //hideObject(); + Gui::Selection().clearSelection(); + stateHandler->selectionMode = static_cast(id); + } + else { + Gui::Selection().clearSelection(); + if (stateHandler->selectionMode == static_cast(id)) + stateHandler->selectionMode = StateHandlerTaskPipe::SelectionModes::none; + } + + switch (id) { + case StateHandlerTaskPipe::SelectionModes::refProfile: + static_cast(vp)->highlightReferences(ViewProviderPipe::Profile, checked); + break; + case StateHandlerTaskPipe::SelectionModes::refSpine: + case StateHandlerTaskPipe::SelectionModes::refSpineEdgeAdd: + case StateHandlerTaskPipe::SelectionModes::refSpineEdgeRemove: + static_cast(vp)->highlightReferences(ViewProviderPipe::Spine, checked); + break; + case StateHandlerTaskPipe::SelectionModes::refAuxSpine: + case StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeAdd: + case StateHandlerTaskPipe::SelectionModes::refAuxSpineEdgeRemove: + static_cast(vp)->highlightReferences(ViewProviderPipe::AuxiliarySpine, checked); + break; + case StateHandlerTaskPipe::SelectionModes::refSectionAdd: + case StateHandlerTaskPipe::SelectionModes::refSectionRemove: + static_cast(vp)->highlightReferences(ViewProviderPipe::Section, checked); + break; + default: + break; + } } //==== calls from the TaskView =============================================================== diff --git a/src/Mod/PartDesign/Gui/TaskPipeParameters.h b/src/Mod/PartDesign/Gui/TaskPipeParameters.h index e365a5b001..9cea27d3f7 100644 --- a/src/Mod/PartDesign/Gui/TaskPipeParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPipeParameters.h @@ -48,6 +48,36 @@ class Ui_TaskPipeParameters; class Ui_TaskPipeOrientation; class Ui_TaskPipeScaling; +/// Convenience class to maintain states between the various task boxes for pipe +class StateHandlerTaskPipe +{ +public: + enum SelectionModes { + none = 0, + refProfile, + refSpine, + refSpineEdgeAdd, + refSpineEdgeRemove, + refAuxSpine, + refAuxSpineEdgeAdd, + refAuxSpineEdgeRemove, + refSectionAdd, + refSectionRemove + }; + +public: + StateHandlerTaskPipe() {selectionMode = SelectionModes::none;} + ~StateHandlerTaskPipe() {} + + // only keeping getter because task boxes shouldn't need to change this + // and task dialog is already friend + enum SelectionModes getSelectionMode() {return selectionMode;} + +private: + enum SelectionModes selectionMode; + friend class TaskDlgPipeParameters; +}; + class TaskPipeParameters : public TaskSketchBasedParameters { @@ -62,23 +92,17 @@ public: private Q_SLOTS: void onTangentChanged(bool checked); void onTransitionChanged(int); - void onButtonRefAdd(bool checked); - void onButtonRefRemove(bool checked); - void onBaseButton(bool checked); void onProfileButton(bool checked); void onDeleteEdge(); protected: - enum selectionModes { none, refAdd, refRemove, refObjAdd, refProfile }; - selectionModes selectionMode = none; - void removeFromListWidget(QListWidget*w, QString name); bool referenceSelected(const Gui::SelectionChanges& msg) const; private: void onSelectionChanged(const Gui::SelectionChanges& msg); void updateUI(); - void clearButtons(const selectionModes notThis=none); + void clearButtons(); void exitSelectionMode(); void setVisibilityOfSpineAndProfile(); @@ -92,6 +116,7 @@ private: private: QWidget* proxy; std::unique_ptr ui; + StateHandlerTaskPipe *stateHandler; friend class TaskDlgPipeParameters; }; @@ -106,30 +131,25 @@ public: private Q_SLOTS: void onOrientationChanged(int); - void onButtonRefAdd(bool checked); - void onButtonRefRemove(bool checked); void updateUI(int idx); - void onBaseButton(bool checked); void onClearButton(); void onCurvelinearChanged(bool checked); void onBinormalChanged(double); void onDeleteItem(); protected: - enum selectionModes { none, refAdd, refRemove, refObjAdd }; - selectionModes selectionMode = none; - void removeFromListWidget(QListWidget*w, QString name); bool referenceSelected(const Gui::SelectionChanges& msg) const; private: void onSelectionChanged(const Gui::SelectionChanges& msg); - void clearButtons(const selectionModes notThis=none); + void clearButtons(); void exitSelectionMode(); private: QWidget* proxy; std::unique_ptr ui; + StateHandlerTaskPipe *stateHandler; friend class TaskDlgPipeParameters; }; @@ -144,31 +164,26 @@ public: private Q_SLOTS: void onScalingChanged(int); - void onButtonRefAdd(bool checked); - void onButtonRefRemove(bool checked); void updateUI(int idx); void onDeleteSection(); void indexesMoved(); protected: - enum selectionModes { none, refAdd, refRemove }; - selectionModes selectionMode = none; - void removeFromListWidget(QListWidget*w, QString name); bool referenceSelected(const Gui::SelectionChanges& msg) const; private: void onSelectionChanged(const Gui::SelectionChanges& msg); - void clearButtons(const selectionModes notThis=none); + void clearButtons(); void exitSelectionMode(); private: QWidget* proxy; std::unique_ptr ui; + StateHandlerTaskPipe *stateHandler; friend class TaskDlgPipeParameters; }; - /// simulation dialog for the TaskView class TaskDlgPipeParameters : public TaskDlgSketchBasedParameters { @@ -183,12 +198,16 @@ public: virtual bool accept(); /// is called by the framework if the dialog is rejected (Cancel) +protected Q_SLOTS: + void onButtonToggled(QAbstractButton *button, bool checked); + protected: TaskPipeParameters *parameter; TaskPipeOrientation *orientation; TaskPipeScaling *scaling; Gui::ButtonGroup *buttonGroup; + StateHandlerTaskPipe *stateHandler; }; } //namespace PartDesignGui