From db72aa2a98fdec091f685529a296a7dd55e8a007 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 24 Apr 2014 22:29:07 +0200 Subject: [PATCH] + Improve performance when selecting all edges of an edited fillet feature --- src/Gui/Selection.cpp | 60 +++++++++++++++++++++++++++-- src/Gui/Selection.h | 2 + src/Mod/Part/Gui/DlgFilletEdges.cpp | 36 ++++++++++++++++- 3 files changed, 94 insertions(+), 4 deletions(-) diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index 05a62ed45..109d02a52 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -627,7 +627,7 @@ bool SelectionSingleton::addSelection(const char* pDocName, const char* pObjectN if (isSelected(pDocName, pObjectName, pSubName)) return true; - _SelObj temp; + _SelObj temp; temp.pDoc = getDocument(pDocName); @@ -681,8 +681,62 @@ bool SelectionSingleton::addSelection(const char* pDocName, const char* pObjectN // allow selection return true; } - else { // neither an existing nor active document available - //assert(0); + else { + // neither an existing nor active document available + // this can often happen when importing .iv files + Base::Console().Error("Cannot add to selection: no document '%s' found.\n", pDocName); + return false; + } +} + +bool SelectionSingleton::addSelection(const char* pDocName, const char* pObjectName, const std::vector& pSubNames) +{ + // already in ? + //if (isSelected(pDocName, pObjectName, pSubName)) + // return true; + + _SelObj temp; + + temp.pDoc = getDocument(pDocName); + + if (temp.pDoc) { + if(pObjectName) + temp.pObject = temp.pDoc->getObject(pObjectName); + else + temp.pObject = 0; + + if (temp.pObject) + temp.TypeName = temp.pObject->getTypeId().getName(); + + temp.DocName = pDocName; + temp.FeatName = pObjectName ? pObjectName : ""; + for (std::vector::const_iterator it = pSubNames.begin(); it != pSubNames.end(); ++it) { + temp.SubName = it->c_str(); + temp.x = 0; + temp.y = 0; + temp.z = 0; + + _SelList.push_back(temp); + } + + SelectionChanges Chng; + + Chng.pDocName = pDocName; + Chng.pObjectName = pObjectName ? pObjectName : ""; + Chng.pSubName = ""; + Chng.x = 0; + Chng.y = 0; + Chng.z = 0; + Chng.Type = SelectionChanges::AddSelection; + + Notify(Chng); + signalSelectionChanged(Chng); + + // allow selection + return true; + } + else { + // neither an existing nor active document available // this can often happen when importing .iv files Base::Console().Error("Cannot add to selection: no document '%s' found.\n", pDocName); return false; diff --git a/src/Gui/Selection.h b/src/Gui/Selection.h index 7aa665615..fa810f56b 100644 --- a/src/Gui/Selection.h +++ b/src/Gui/Selection.h @@ -200,6 +200,8 @@ class GuiExport SelectionSingleton : public Base::Subject& pSubNames); /// Remove from selection (for internal use) void rmvSelection(const char* pDocName, const char* pObjectName=0, const char* pSubName=0); /// Set the selection for a document diff --git a/src/Mod/Part/Gui/DlgFilletEdges.cpp b/src/Mod/Part/Gui/DlgFilletEdges.cpp index 4ce7843a1..25904c459 100644 --- a/src/Mod/Part/Gui/DlgFilletEdges.cpp +++ b/src/Mod/Part/Gui/DlgFilletEdges.cpp @@ -540,7 +540,10 @@ void DlgFilletEdges::setupFillet(const std::vector& objs) ui->shapeObject->setCurrentIndex(current_index); on_shapeObject_activated(current_index); ui->shapeObject->setEnabled(false); + + std::vector subElements; QStandardItemModel *model = qobject_cast(ui->treeView->model()); + bool block = model->blockSignals(true); // do not call toggleCheckState for (std::vector::const_iterator et = e.begin(); et != e.end(); ++et) { std::vector::iterator it = std::find(d->edge_ids.begin(), d->edge_ids.end(), et->edgeid); if (it != d->edge_ids.end()) { @@ -548,8 +551,19 @@ void DlgFilletEdges::setupFillet(const std::vector& objs) model->setData(model->index(index, 0), Qt::Checked, Qt::CheckStateRole); model->setData(model->index(index, 1), QVariant(QLocale::system().toString(et->radius1,'f',Base::UnitsApi::getDecimals()))); model->setData(model->index(index, 2), QVariant(QLocale::system().toString(et->radius2,'f',Base::UnitsApi::getDecimals()))); + + int id = model->index(index, 0).data(Qt::UserRole).toInt(); + std::stringstream str; + str << "Edge" << id; + subElements.push_back(str.str()); } } + model->blockSignals(block); + + App::Document* doc = d->object->getDocument(); + Gui::Selection().addSelection(doc->getName(), + d->object->getNameInDocument(), + subElements); } } @@ -667,12 +681,32 @@ void DlgFilletEdges::on_selectFaces_toggled(bool on) void DlgFilletEdges::on_selectAllButton_clicked() { + std::vector subElements; QAbstractItemModel* model = ui->treeView->model(); + bool block = model->blockSignals(true); // do not call toggleCheckState for (int i=0; irowCount(); ++i) { + QModelIndex index = model->index(i,0); + + // is not yet checked? + QVariant check = index.data(Qt::CheckStateRole); + Qt::CheckState state = static_cast(check.toInt()); + if (state == Qt::Unchecked) { + int id = index.data(Qt::UserRole).toInt(); + std::stringstream str; + str << "Edge" << id; + subElements.push_back(str.str()); + } + Qt::CheckState checkState = Qt::Checked; QVariant value(static_cast(checkState)); - model->setData(model->index(i,0), value, Qt::CheckStateRole); + model->setData(index, value, Qt::CheckStateRole); } + model->blockSignals(block); + + App::Document* doc = d->object->getDocument(); + Gui::Selection().addSelection(doc->getName(), + d->object->getNameInDocument(), + subElements); } void DlgFilletEdges::on_selectNoneButton_clicked()