From 1bd1d42fa87ff630f54caa0346991718bc50de34 Mon Sep 17 00:00:00 2001 From: Abdullah Tahiri Date: Sun, 3 Oct 2021 16:41:47 +0200 Subject: [PATCH] Sketcher: New constraint special filter, filter selection ========================================================= It filters the constraint list to the selected constraints. It observes selection changes and reacts to new selections. Forum: https://forum.freecadweb.org/viewtopic.php?p=537028#p537028 --- src/Mod/Sketcher/Gui/ConstraintFilters.h | 1 + .../Sketcher/Gui/TaskSketcherConstrains.cpp | 61 +++++++++++++++---- src/Mod/Sketcher/Gui/TaskSketcherConstrains.h | 6 +- .../Sketcher/Gui/TaskSketcherConstrains.ui | 5 ++ 4 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ConstraintFilters.h b/src/Mod/Sketcher/Gui/ConstraintFilters.h index 6f86e2e3f0..4c8a292948 100644 --- a/src/Mod/Sketcher/Gui/ConstraintFilters.h +++ b/src/Mod/Sketcher/Gui/ConstraintFilters.h @@ -60,6 +60,7 @@ namespace ConstraintFilter { enum SpecialFilterValue { Multiple = 24, + Selection = 25, NumSpecialFilterValue }; diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp index 26c199e421..4add6a36ec 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.cpp @@ -453,13 +453,18 @@ void ConstraintView::contextMenuEvent (QContextMenuEvent* event) // Sync the FreeCAD selection with the selection in the ConstraintView widget if (didRelease) { Gui::Selection().clearSelection(); + std::string doc_name = static_cast(item)->sketchView->getSketchObject()->getDocument()->getName(); + std::string obj_name = static_cast(item)->sketchView->getSketchObject()->getNameInDocument(); + + std::vector constraintSubNames; for (auto&& it : items) { auto ci = static_cast(it); std::string constraint_name = Sketcher::PropertyConstraintList::getConstraintName(ci->ConstraintNbr); - std::string doc_name = ci->sketchView->getSketchObject()->getDocument()->getName(); - std::string obj_name = ci->sketchView->getSketchObject()->getNameInDocument(); - Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), constraint_name.c_str()); + constraintSubNames.push_back(constraint_name.c_str()); } + + if(!constraintSubNames.empty()) + Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), constraintSubNames); } bool isQuantity = false; @@ -719,13 +724,15 @@ TaskSketcherConstrains::~TaskSketcherConstrains() connectionConstraintsChanged.disconnect(); } -void TaskSketcherConstrains::updateMultiFilter() +void TaskSketcherConstrains::updateSelectionFilter() { - int filterindex = ui->comboBoxFilter->currentIndex(); + // Snapshot current selection + auto items = ui->listWidgetConstraints->selectedItems(); - multiFilterStatus.reset(); + selectionFilter.clear(); - multiFilterStatus.set(filterindex); + for(const auto & item : items) + selectionFilter.push_back(static_cast(item)->ConstraintNbr); } void TaskSketcherConstrains::updateList() @@ -857,8 +864,16 @@ void TaskSketcherConstrains::onSelectionChanged(const Gui::SelectionChanges& msg std::string temp; if (msg.Type == Gui::SelectionChanges::ClrSelection) { ui->listWidgetConstraints->blockSignals(true); - ui->listWidgetConstraints->clearSelection (); + ui->listWidgetConstraints->clearSelection(); ui->listWidgetConstraints->blockSignals(false); + + if(isFilter(ConstraintFilter::SpecialFilterValue::Selection)) { + updateSelectionFilter(); + + bool block = this->blockConnection(true); // avoid to be notified by itself + updateList(); + this->blockConnection(block); + } } else if (msg.Type == Gui::SelectionChanges::AddSelection || msg.Type == Gui::SelectionChanges::RmvSelection) { @@ -885,6 +900,10 @@ void TaskSketcherConstrains::onSelectionChanged(const Gui::SelectionChanges& msg break; } } + updateSelectionFilter(); + bool block = this->blockConnection(true); // avoid to be notified by itself + updateList(); + this->blockConnection(block); } } } @@ -896,8 +915,14 @@ void TaskSketcherConstrains::onSelectionChanged(const Gui::SelectionChanges& msg } -void TaskSketcherConstrains::on_comboBoxFilter_currentIndexChanged(int) +void TaskSketcherConstrains::on_comboBoxFilter_currentIndexChanged(int filterindex) { + selectionFilter.clear(); // reset the stored selection filter + + if(filterindex == ConstraintFilter::SpecialFilterValue::Selection) { + updateSelectionFilter(); + } + updateList(); } @@ -932,12 +957,17 @@ void TaskSketcherConstrains::on_listWidgetConstraints_itemSelectionChanged(void) bool block = this->blockConnection(true); // avoid to be notified by itself Gui::Selection().clearSelection(); + + std::vector constraintSubNames; QList items = ui->listWidgetConstraints->selectedItems(); for (QList::iterator it = items.begin(); it != items.end(); ++it) { std::string constraint_name(Sketcher::PropertyConstraintList::getConstraintName(static_cast(*it)->ConstraintNbr)); - - Gui::Selection().addSelection(doc_name.c_str(), obj_name.c_str(), constraint_name.c_str()); + constraintSubNames.push_back(constraint_name); } + + if(!constraintSubNames.empty()) + Gui::Selection().addSelections(doc_name.c_str(), obj_name.c_str(), constraintSubNames); + this->blockConnection(block); } @@ -1210,6 +1240,10 @@ bool TaskSketcherConstrains::isConstraintFiltered(QListWidgetItem * item) break; } + // Constraint Type independent, selection filter + visible = visible || (Filter == SpecialFilterValue::Selection && + std::find(selectionFilter.begin(), selectionFilter.end(), it->ConstraintNbr) != selectionFilter.end()); + return !visible; } @@ -1274,6 +1308,11 @@ void TaskSketcherConstrains::changeEvent(QEvent *e) } } +template +bool TaskSketcherConstrains::isFilter(T filterValue) { + return (ui->comboBoxFilter->currentIndex() == filterValue); +} + #include "moc_TaskSketcherConstrains.cpp" diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.h b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.h index e4bbebf5bf..f273b767ab 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.h +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.h @@ -92,9 +92,12 @@ private: bool isConstraintFiltered(QListWidgetItem * item); void change3DViewVisibilityToTrackFilter(); void changeFilteredVisibility(bool show, ActionTarget target = ActionTarget::All); - void updateMultiFilter(); + void updateSelectionFilter(); void updateList(); + template + bool isFilter(T filterValue); + public Q_SLOTS: void on_comboBoxFilter_currentIndexChanged(int); void on_listWidgetConstraints_itemSelectionChanged(void); @@ -123,6 +126,7 @@ private: bool inEditMode; std::unique_ptr ui; std::bitset multiFilterStatus; + std::vector selectionFilter; }; } //namespace SketcherGui diff --git a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.ui b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.ui index 5ede5770f6..e2e4d454b6 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherConstrains.ui +++ b/src/Mod/Sketcher/Gui/TaskSketcherConstrains.ui @@ -165,6 +165,11 @@ Multiple Filters + + + Selection Filter + +