From 013381ccb6a2a19eae9fcbd18633ec9d2ec0a2a7 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Sun, 26 Jul 2015 07:02:27 +0300 Subject: [PATCH] PartDesign/Gui: share code for revolution and groove view providers --- src/Mod/PartDesign/Gui/ViewProviderGroove.cpp | 90 ++----------------- src/Mod/PartDesign/Gui/ViewProviderGroove.h | 15 ++-- .../PartDesign/Gui/ViewProviderRevolution.cpp | 90 ++----------------- .../PartDesign/Gui/ViewProviderRevolution.h | 13 ++- 4 files changed, 22 insertions(+), 186 deletions(-) diff --git a/src/Mod/PartDesign/Gui/ViewProviderGroove.cpp b/src/Mod/PartDesign/Gui/ViewProviderGroove.cpp index bb443fb88..1a287c47e 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderGroove.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderGroove.cpp @@ -26,21 +26,15 @@ #ifndef _PreComp_ # include # include -# include #endif -#include -#include -#include -#include -#include +#include "TaskRevolutionParameters.h" #include "ViewProviderGroove.h" -#include "TaskRevolutionParameters.h" using namespace PartDesignGui; -PROPERTY_SOURCE(PartDesignGui::ViewProviderGroove,PartDesignGui::ViewProvider) +PROPERTY_SOURCE(PartDesignGui::ViewProviderGroove,PartDesignGui::ViewProviderSketchBased) ViewProviderGroove::ViewProviderGroove() { @@ -51,89 +45,15 @@ ViewProviderGroove::~ViewProviderGroove() { } -std::vector ViewProviderGroove::claimChildren(void)const -{ - std::vector temp; - App::DocumentObject* sketch = static_cast(getObject())->Sketch.getValue(); - if (sketch != NULL) - temp.push_back(sketch); - - return temp; -} - void ViewProviderGroove::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) { QAction* act; - act = menu->addAction(QObject::tr("Edit Groove"), receiver, member); + act = menu->addAction(QObject::tr("Edit groove"), receiver, member); act->setData(QVariant((int)ViewProvider::Default)); PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member); } -bool ViewProviderGroove::setEdit(int ModNum) +TaskDlgFeatureParameters *ViewProviderGroove::getEditDialog() { - if (ModNum == ViewProvider::Default ) { - PartDesign::Groove* pcGroove = static_cast(getObject()); - if (pcGroove->getSketchAxisCount() < 0) { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setWindowTitle(QObject::tr("Lost link to base sketch")); - msgBox.setText(QObject::tr("The object can't be edited because the link to the the base sketch is lost.")); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.exec(); - return false; - } - // 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(); - TaskDlgRevolutionParameters *padDlg = qobject_cast(dlg); - if (padDlg && padDlg->getRevolutionView() != this) - padDlg = 0; // another pad left open its task panel - if (dlg && !padDlg) { - QMessageBox msgBox; - msgBox.setText(QObject::tr("A dialog is already open in the task panel")); - msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?")); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::Yes); - int ret = msgBox.exec(); - if (ret == QMessageBox::Yes) - Gui::Control().reject(); - else - return false; - } - - // clear the selection (convenience) - Gui::Selection().clearSelection(); - - // always change to PartDesign WB, remember where we come from - oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench"); - - // start the edit dialog - if (padDlg) - Gui::Control().showDialog(padDlg); - else - Gui::Control().showDialog(new TaskDlgRevolutionParameters(this)); - - return true; - } - else { - return PartGui::ViewProviderPart::setEdit(ModNum); - } + return new TaskDlgRevolutionParameters( this ); } - -bool ViewProviderGroove::onDelete(const std::vector &s) -{ - // get the Sketch - PartDesign::Groove* pcGroove = static_cast(getObject()); - Sketcher::SketchObject *pcSketch = 0; - if (pcGroove->Sketch.getValue()) - pcSketch = static_cast(pcGroove->Sketch.getValue()); - - // if abort command deleted the object the Sketch is visible again - if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch)) - Gui::Application::Instance->getViewProvider(pcSketch)->show(); - - return ViewProvider::onDelete(s); -} - - diff --git a/src/Mod/PartDesign/Gui/ViewProviderGroove.h b/src/Mod/PartDesign/Gui/ViewProviderGroove.h index 92f3e4b4a..2cfc1c183 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderGroove.h +++ b/src/Mod/PartDesign/Gui/ViewProviderGroove.h @@ -24,12 +24,12 @@ #ifndef PARTGUI_ViewProviderGroove_H #define PARTGUI_ViewProviderGroove_H -#include "ViewProvider.h" +#include "ViewProviderSketchBased.h" namespace PartDesignGui { -class PartDesignGuiExport ViewProviderGroove : public ViewProvider +class PartDesignGuiExport ViewProviderGroove : public ViewProviderSketchBased { PROPERTY_HEADER(PartDesignGui::ViewProviderGroove); @@ -39,15 +39,14 @@ public: /// destructor virtual ~ViewProviderGroove(); - /// grouping handling - std::vector claimChildren(void)const; - void setupContextMenu(QMenu*, QObject*, const char*); - virtual bool onDelete(const std::vector &); - protected: - virtual bool setEdit(int ModNum); + /** + * Returns a newly created TaskDlgRevolutionParameters + * NOTE: as for now groove and revolution share the dialog implementation + */ + virtual TaskDlgFeatureParameters *getEditDialog(); }; diff --git a/src/Mod/PartDesign/Gui/ViewProviderRevolution.cpp b/src/Mod/PartDesign/Gui/ViewProviderRevolution.cpp index 86bcd221c..b1eb50631 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderRevolution.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderRevolution.cpp @@ -26,41 +26,25 @@ #ifndef _PreComp_ # include # include -# include #endif -#include -#include -#include -#include -#include +#include "TaskRevolutionParameters.h" #include "ViewProviderRevolution.h" -#include "TaskRevolutionParameters.h" using namespace PartDesignGui; -PROPERTY_SOURCE(PartDesignGui::ViewProviderRevolution,PartDesignGui::ViewProvider) +PROPERTY_SOURCE(PartDesignGui::ViewProviderRevolution,PartDesignGui::ViewProviderSketchBased) ViewProviderRevolution::ViewProviderRevolution() { - sPixmap = "Tree_PartDesign_Revolution.svg"; + sPixmap = "Tree_PartDesign_Revolution.svg"; } ViewProviderRevolution::~ViewProviderRevolution() { } -std::vector ViewProviderRevolution::claimChildren(void)const -{ - std::vector temp; - App::DocumentObject* sketch = static_cast(getObject())->Sketch.getValue(); - if (sketch != NULL) - temp.push_back(sketch); - - return temp; -} - void ViewProviderRevolution::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) { QAction* act; @@ -69,71 +53,7 @@ void ViewProviderRevolution::setupContextMenu(QMenu* menu, QObject* receiver, co PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member); } -bool ViewProviderRevolution::setEdit(int ModNum) +TaskDlgFeatureParameters *ViewProviderRevolution::getEditDialog() { - if (ModNum == ViewProvider::Default ) { - PartDesign::Revolution* pcRevolution = static_cast(getObject()); - if (pcRevolution->getSketchAxisCount() < 0) { - QMessageBox msgBox; - msgBox.setIcon(QMessageBox::Critical); - msgBox.setWindowTitle(QObject::tr("Lost link to base sketch")); - msgBox.setText(QObject::tr("The object can't be edited because the link to the the base sketch is lost.")); - msgBox.setStandardButtons(QMessageBox::Ok); - msgBox.exec(); - return false; - } - // 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(); - TaskDlgRevolutionParameters *padDlg = qobject_cast(dlg); - if (padDlg && padDlg->getRevolutionView() != this) - padDlg = 0; // another pad left open its task panel - if (dlg && !padDlg) { - QMessageBox msgBox; - msgBox.setText(QObject::tr("A dialog is already open in the task panel")); - msgBox.setInformativeText(QObject::tr("Do you want to close this dialog?")); - msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); - msgBox.setDefaultButton(QMessageBox::Yes); - int ret = msgBox.exec(); - if (ret == QMessageBox::Yes) - Gui::Control().reject(); - else - return false; - } - - // clear the selection (convenience) - Gui::Selection().clearSelection(); - - // always change to PartDesign WB, remember where we come from - oldWb = Gui::Command::assureWorkbench("PartDesignWorkbench"); - - // start the edit dialog - if (padDlg) - Gui::Control().showDialog(padDlg); - else - Gui::Control().showDialog(new TaskDlgRevolutionParameters(this)); - - return true; - } - else { - return PartGui::ViewProviderPart::setEdit(ModNum); - } + return new TaskDlgRevolutionParameters( this ); } - -bool ViewProviderRevolution::onDelete(const std::vector &s) -{ - // get the Sketch - PartDesign::Revolution* pcRevolution = static_cast(getObject()); - Sketcher::SketchObject *pcSketch = 0; - if (pcRevolution->Sketch.getValue()) - pcSketch = static_cast(pcRevolution->Sketch.getValue()); - - // if abort command deleted the object the Sketch is visible again - if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch)) - Gui::Application::Instance->getViewProvider(pcSketch)->show(); - - return ViewProvider::onDelete(s); -} - - diff --git a/src/Mod/PartDesign/Gui/ViewProviderRevolution.h b/src/Mod/PartDesign/Gui/ViewProviderRevolution.h index 42d17ecd3..dcafe4115 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderRevolution.h +++ b/src/Mod/PartDesign/Gui/ViewProviderRevolution.h @@ -24,12 +24,12 @@ #ifndef PARTGUI_ViewProviderRevolution_H #define PARTGUI_ViewProviderRevolution_H -#include "ViewProvider.h" +#include "ViewProviderSketchBased.h" namespace PartDesignGui { -class PartDesignGuiExport ViewProviderRevolution : public ViewProvider +class PartDesignGuiExport ViewProviderRevolution : public ViewProviderSketchBased { PROPERTY_HEADER(PartDesignGui::ViewProviderRevolution); @@ -39,15 +39,12 @@ public: /// destructor virtual ~ViewProviderRevolution(); - /// grouping handling - std::vector claimChildren(void)const; - void setupContextMenu(QMenu*, QObject*, const char*); - virtual bool onDelete(const std::vector &); - protected: - virtual bool setEdit(int ModNum); + /// Returns a newly created TaskDlgRevolutionParameters + virtual TaskDlgFeatureParameters *getEditDialog(); + };