From fa50729aeb34e1f5a44ce74b2bf70552de95ef99 Mon Sep 17 00:00:00 2001 From: wmayer Date: Mon, 24 Apr 2017 19:18:58 +0200 Subject: [PATCH] reset highlighting of references if object is being deleted, fix crash with invalid sub-element names --- src/Mod/Surface/Gui/TaskFilling.cpp | 39 +++++++++++++++++---- src/Mod/Surface/Gui/TaskFilling.h | 2 ++ src/Mod/Surface/Gui/TaskFillingVertex.cpp | 10 ++++++ src/Mod/Surface/Gui/TaskFillingVertex.h | 2 ++ src/Mod/Surface/Gui/TaskGeomFillSurface.cpp | 12 ++++++- src/Mod/Surface/Gui/TaskGeomFillSurface.h | 2 ++ 6 files changed, 60 insertions(+), 7 deletions(-) diff --git a/src/Mod/Surface/Gui/TaskFilling.cpp b/src/Mod/Surface/Gui/TaskFilling.cpp index 48c2f4be9318..7f7b82b26c61 100644 --- a/src/Mod/Surface/Gui/TaskFilling.cpp +++ b/src/Mod/Surface/Gui/TaskFilling.cpp @@ -121,9 +121,11 @@ void ViewProviderFilling::highlightReferences(ShapeType type, const References& colors.resize(vMap.Extent(), svp->PointColor.getValue()); for (auto jt : it.second) { + // check again that the index is in range because it's possible that the + // sub-names are invalid std::size_t idx = static_cast(std::stoi(jt.substr(6)) - 1); - assert (idx < colors.size()); - colors[idx] = App::Color(1.0,0.0,1.0); // magenta + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta } svp->setHighlightedPoints(colors); @@ -141,8 +143,10 @@ void ViewProviderFilling::highlightReferences(ShapeType type, const References& for (auto jt : it.second) { std::size_t idx = static_cast(std::stoi(jt.substr(4)) - 1); - assert (idx < colors.size()); - colors[idx] = App::Color(1.0,0.0,1.0); // magenta + // check again that the index is in range because it's possible that the + // sub-names are invalid + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta } svp->setHighlightedEdges(colors); @@ -160,8 +164,10 @@ void ViewProviderFilling::highlightReferences(ShapeType type, const References& for (auto jt : it.second) { std::size_t idx = static_cast(std::stoi(jt.substr(4)) - 1); - assert (idx < colors.size()); - colors[idx] = App::Color(1.0,0.0,1.0); // magenta + // check again that the index is in range because it's possible that the + // sub-names are invalid + if (idx < colors.size()) + colors[idx] = App::Color(1.0,0.0,1.0); // magenta } svp->setHighlightedFaces(colors); @@ -399,6 +405,22 @@ void FillingPanel::slotRedoDocument(const Gui::Document&) checkCommand = true; } +void FillingPanel::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) +{ + // If this view provider is being deleted then reset the colors of + // referenced part objects. The dialog will be deleted later. + if (this->vp == &Obj) { + this->vp->highlightReferences(ViewProviderFilling::Edge, + editedObject->BoundaryEdges.getSubListValues(), false); + + // unhighlight the referenced face + std::vector links; + links.push_back(std::make_pair(editedObject->InitialFace.getValue(), + editedObject->InitialFace.getSubValues())); + this->vp->highlightReferences(ViewProviderFilling::Face, links, false); + } +} + bool FillingPanel::accept() { selectionMode = None; @@ -716,6 +738,8 @@ void FillingPanel::onDeleteEdge() } this->vp->highlightReferences(ViewProviderFilling::Edge, editedObject->BoundaryEdges.getSubListValues(), true); + + editedObject->recomputeFeature(); } } @@ -760,6 +784,8 @@ void FillingPanel::on_buttonAccept_clicked() ui->comboBoxFaces->clear(); ui->comboBoxCont->clear(); ui->statusLabel->clear(); + + editedObject->recomputeFeature(); } void FillingPanel::on_buttonIgnore_clicked() @@ -818,6 +844,7 @@ void TaskFilling::setEditedObject(Surface::Filling* obj) void TaskFilling::open() { widget1->open(); + widget2->open(); } bool TaskFilling::accept() diff --git a/src/Mod/Surface/Gui/TaskFilling.h b/src/Mod/Surface/Gui/TaskFilling.h index a1e448334c48..157c2172c59e 100644 --- a/src/Mod/Surface/Gui/TaskFilling.h +++ b/src/Mod/Surface/Gui/TaskFilling.h @@ -87,6 +87,8 @@ class FillingPanel : public QWidget, virtual void slotUndoDocument(const Gui::Document& Doc); /** Notifies on redo */ virtual void slotRedoDocument(const Gui::Document& Doc); + /** Notifies when the object is about to be removed. */ + virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj); void modifyBoundary(bool); private Q_SLOTS: diff --git a/src/Mod/Surface/Gui/TaskFillingVertex.cpp b/src/Mod/Surface/Gui/TaskFillingVertex.cpp index b9246d673c93..b39d0fd3345d 100644 --- a/src/Mod/Surface/Gui/TaskFillingVertex.cpp +++ b/src/Mod/Surface/Gui/TaskFillingVertex.cpp @@ -220,6 +220,16 @@ void FillingVertexPanel::slotRedoDocument(const Gui::Document&) checkCommand = true; } +void FillingVertexPanel::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) +{ + // If this view provider is being deleted then reset the colors of + // referenced part objects. The dialog will be deleted later. + if (this->vp == &Obj) { + this->vp->highlightReferences(ViewProviderFilling::Vertex, + editedObject->Points.getSubListValues(), false); + } +} + void FillingVertexPanel::on_buttonVertexAdd_clicked() { // 'selectionMode' is passed by reference and changed when the filter is deleted diff --git a/src/Mod/Surface/Gui/TaskFillingVertex.h b/src/Mod/Surface/Gui/TaskFillingVertex.h index a1a704fb07a3..7b6749342518 100644 --- a/src/Mod/Surface/Gui/TaskFillingVertex.h +++ b/src/Mod/Surface/Gui/TaskFillingVertex.h @@ -72,6 +72,8 @@ class FillingVertexPanel : public QWidget, virtual void slotUndoDocument(const Gui::Document& Doc); /** Notifies on redo */ virtual void slotRedoDocument(const Gui::Document& Doc); + /** Notifies when the object is about to be removed. */ + virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj); private Q_SLOTS: void on_buttonVertexAdd_clicked(); diff --git a/src/Mod/Surface/Gui/TaskGeomFillSurface.cpp b/src/Mod/Surface/Gui/TaskGeomFillSurface.cpp index 19ddc7037ce5..ae9ec5eb3638 100644 --- a/src/Mod/Surface/Gui/TaskGeomFillSurface.cpp +++ b/src/Mod/Surface/Gui/TaskGeomFillSurface.cpp @@ -297,9 +297,17 @@ void GeomFillSurface::slotRedoDocument(const Gui::Document&) checkCommand = true; } +void GeomFillSurface::slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj) +{ + // If this view provider is being deleted then reset the colors of + // referenced part objects. The dialog will be deleted later. + if (this->vp == &Obj) { + this->vp->highlightReferences(false); + } +} + bool GeomFillSurface::accept() { - this->vp->highlightReferences(false); selectionMode = None; Gui::Selection().rmvSelectionGate(); @@ -325,6 +333,8 @@ bool GeomFillSurface::accept() return false; } + this->vp->highlightReferences(false); + Gui::Command::commitCommand(); Gui::Command::doCommand(Gui::Command::Gui,"Gui.ActiveDocument.resetEdit()"); Gui::Command::updateActive(); diff --git a/src/Mod/Surface/Gui/TaskGeomFillSurface.h b/src/Mod/Surface/Gui/TaskGeomFillSurface.h index 8ba76034ec12..1ed15fa28733 100644 --- a/src/Mod/Surface/Gui/TaskGeomFillSurface.h +++ b/src/Mod/Surface/Gui/TaskGeomFillSurface.h @@ -82,6 +82,8 @@ class GeomFillSurface : public QWidget, virtual void slotUndoDocument(const Gui::Document& Doc); /** Notifies on redo */ virtual void slotRedoDocument(const Gui::Document& Doc); + /** Notifies when the object is about to be removed. */ + virtual void slotDeletedObject(const Gui::ViewProviderDocumentObject& Obj); void changeFillType(GeomFill_FillingStyle); private Q_SLOTS: