From 165feeba534806b87f9ef7cbdfa00ad4b5c7848c Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 13 Oct 2020 14:16:01 +0200 Subject: [PATCH] Part: make changing face colors independent of edit-mode implementation of a view provider --- src/Mod/Part/Gui/Command.cpp | 17 ++++------------- src/Mod/Part/Gui/ViewProviderExt.cpp | 23 ++++++++++++++--------- src/Mod/Part/Gui/ViewProviderExt.h | 4 +++- src/Mod/Part/Gui/Workbench.cpp | 12 ------------ 4 files changed, 21 insertions(+), 35 deletions(-) diff --git a/src/Mod/Part/Gui/Command.cpp b/src/Mod/Part/Gui/Command.cpp index 7d7864703d..7ce1d1c472 100644 --- a/src/Mod/Part/Gui/Command.cpp +++ b/src/Mod/Part/Gui/Command.cpp @@ -2159,14 +2159,7 @@ CmdColorPerFace::CmdColorPerFace() sGroup = QT_TR_NOOP("Part"); sMenuText = QT_TR_NOOP("Color per face"); sToolTipText = QT_TR_NOOP("Set the color of each individual face " - "of the selected object.\n" - "\n" - "At the moment, this command only works " - "with objects which have not reimplemented\n" - "their 'edit modes'; this means, it works " - "with Part and PartDesign created objects,\n" - "but not with most Draft or Arch objects. " - "See issues #0477 and #1954 in the tracker."); + "of the selected object."); sStatusTip = sToolTipText; sWhatsThis = "Part_ColorPerFace"; sPixmap = "Part_ColorFace"; @@ -2178,13 +2171,11 @@ void CmdColorPerFace::activated(int iMsg) if (getActiveGuiDocument()->getInEdit()) getActiveGuiDocument()->resetEdit(); std::vector sel = Gui::Selection().getObjectsOfType(Part::Feature::getClassTypeId()); - if(sel.empty()) + if (sel.empty()) return; - Gui::ViewProvider* vp = Gui::Application::Instance->getViewProvider(sel.front()); - // FIXME: Need a way to force 'Color' edit mode - // #0000477: Proper interface for edit modes of view provider + PartGui::ViewProviderPartExt* vp = dynamic_cast(Gui::Application::Instance->getViewProvider(sel.front())); if (vp) - getActiveGuiDocument()->setEdit(vp, Gui::ViewProvider::Color); + vp->changeFaceColors(); } bool CmdColorPerFace::isActive(void) diff --git a/src/Mod/Part/Gui/ViewProviderExt.cpp b/src/Mod/Part/Gui/ViewProviderExt.cpp index f3df91ade2..6f4cc5277e 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.cpp +++ b/src/Mod/Part/Gui/ViewProviderExt.cpp @@ -962,21 +962,26 @@ void ViewProviderPartExt::setupContextMenu(QMenu* menu, QObject* receiver, const act->setData(QVariant((int)ViewProvider::Color)); } +bool ViewProviderPartExt::changeFaceColors() +{ + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + if (dlg) { + Gui::Control().showDialog(dlg); + return false; + } + + Gui::Selection().clearSelection(); + Gui::Control().showDialog(new TaskFaceColors(this)); + return true; +} + bool ViewProviderPartExt::setEdit(int ModNum) { if (ModNum == ViewProvider::Color) { // When double-clicking on the item for this pad the // object unsets and sets its edit mode without closing // the task panel - Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); - if (dlg) { - Gui::Control().showDialog(dlg); - return false; - } - - Gui::Selection().clearSelection(); - Gui::Control().showDialog(new TaskFaceColors(this)); - return true; + return changeFaceColors(); } else { return Gui::ViewProviderGeometryObject::setEdit(ModNum); diff --git a/src/Mod/Part/Gui/ViewProviderExt.h b/src/Mod/Part/Gui/ViewProviderExt.h index 37c14135e5..d890e9a716 100644 --- a/src/Mod/Part/Gui/ViewProviderExt.h +++ b/src/Mod/Part/Gui/ViewProviderExt.h @@ -89,7 +89,7 @@ public: App::PropertyMaterial LineMaterial; App::PropertyColorList LineColorArray; // Faces (Gui::ViewProviderGeometryObject::ShapeColor and Gui::ViewProviderGeometryObject::ShapeMaterial apply) - App::PropertyColorList DiffuseColor; + App::PropertyColorList DiffuseColor; virtual void attach(App::DocumentObject *) override; virtual void setDisplayMode(const char* ModeName) override; @@ -97,6 +97,8 @@ public: virtual std::vector getDisplayModes(void) const override; /// Update the view representation void reload(); + /// If no other task is pending it opens a dialog to allow to change face colors + bool changeFaceColors(); virtual void updateData(const App::Property*) override; diff --git a/src/Mod/Part/Gui/Workbench.cpp b/src/Mod/Part/Gui/Workbench.cpp index 0bf741e1e4..2d30a2a3bf 100644 --- a/src/Mod/Part/Gui/Workbench.cpp +++ b/src/Mod/Part/Gui/Workbench.cpp @@ -157,17 +157,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const << "Part_Measure_Toggle_3D" << "Part_Measure_Toggle_Delta"; - // leave this for 0.14 until #0000477 is fixed - - // According to #0477 and #1954 - // `Part_ColorPerFace` does not work with objects that reimplement - // their edit modes, meaning it may work with Part and PartDesign - // created objects but not with Draft and Arch objects. - // However, it does not make much sense to keep it hidden; - // having it available in the interface will allow more people - // to use it, and maybe somebody will be able to investigate - // and fix the issue. -#if 1 Gui::MenuItem* view = root->findItem("&View"); if (view) { Gui::MenuItem* appr = view->findItem("Std_RandomColor"); @@ -176,7 +165,6 @@ Gui::MenuItem* Workbench::setupMenuBar() const face->setCommand("Part_ColorPerFace"); view->insertItem(appr, face); } -#endif return root; }