From 5ee0cea467a8b773550245e7ddead5a455d3a2d4 Mon Sep 17 00:00:00 2001 From: Alexander Golubev Date: Sun, 26 Jul 2015 06:29:02 +0300 Subject: [PATCH] PartDesign/Gui: start to unify view providers code - Moved all common code for part design features view providers to a base class. - Move shared code for Sketch based features to newly created ViewProviderSketchBased class - Add ViewProviderSketchBased to initialization - Make Pad and Pocket ViewProviders to use the shared code - Minor fixes to TaskFeatureParameters and some derived classes --- src/Mod/PartDesign/Gui/AppPartDesignGui.cpp | 4 +- src/Mod/PartDesign/Gui/CMakeLists.txt | 2 + .../PartDesign/Gui/TaskFeatureParameters.cpp | 26 ++-- .../PartDesign/Gui/TaskFeatureParameters.h | 6 +- src/Mod/PartDesign/Gui/TaskPadParameters.cpp | 1 + src/Mod/PartDesign/Gui/TaskPadParameters.h | 2 +- .../PartDesign/Gui/TaskPocketParameters.cpp | 1 + src/Mod/PartDesign/Gui/ViewProvider.cpp | 118 ++++++++++++++---- src/Mod/PartDesign/Gui/ViewProvider.h | 10 ++ src/Mod/PartDesign/Gui/ViewProviderPad.cpp | 86 ++----------- src/Mod/PartDesign/Gui/ViewProviderPad.h | 11 +- src/Mod/PartDesign/Gui/ViewProviderPocket.cpp | 81 ++---------- src/Mod/PartDesign/Gui/ViewProviderPocket.h | 11 +- .../Gui/ViewProviderSketchBased.cpp | 74 +++++++++++ .../PartDesign/Gui/ViewProviderSketchBased.h | 51 ++++++++ 15 files changed, 274 insertions(+), 210 deletions(-) create mode 100644 src/Mod/PartDesign/Gui/ViewProviderSketchBased.cpp create mode 100644 src/Mod/PartDesign/Gui/ViewProviderSketchBased.h diff --git a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp index 5c59e50e4..8b0aa1461 100644 --- a/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp +++ b/src/Mod/PartDesign/Gui/AppPartDesignGui.cpp @@ -37,6 +37,7 @@ #include "Workbench.h" #include "ViewProviderPocket.h" #include "ViewProviderBody.h" +#include "ViewProviderSketchBased.h" #include "ViewProviderPad.h" #include "ViewProviderChamfer.h" #include "ViewProviderFillet.h" @@ -119,7 +120,8 @@ PyMODINIT_FUNC initPartDesignGui() PartDesignGui::Workbench ::init(); PartDesignGui::ViewProvider ::init(); - PartDesignGui::ViewProviderBody ::init(); + PartDesignGui::ViewProviderBody ::init(); + PartDesignGui::ViewProviderSketchBased ::init(); PartDesignGui::ViewProviderPocket ::init(); PartDesignGui::ViewProviderPad ::init(); PartDesignGui::ViewProviderRevolution ::init(); diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index 38c637309..b87e5ac5d 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -89,6 +89,8 @@ SET(PartDesignGuiViewProvider_SRCS CommandPrimitive.cpp ViewProvider.h ViewProviderBody.cpp ViewProviderBody.h + ViewProviderSketchBased.cpp + ViewProviderSketchBased.h ViewProviderPad.cpp ViewProviderPad.h #ViewProviderHole.cpp diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp index 9b575811d..f25f3e02a 100644 --- a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp @@ -92,33 +92,27 @@ bool TaskDlgFeatureParameters::reject() // Find out previous feature we won't be able to do it after abort // (at least in the body case) App::DocumentObject* previous; - if (body) { - // NOTE: feature->getBaseObject() should return the same for body - previous = body->getPrevSolidFeature(feature, /*inclusive =*/ false); - } else { - previous = feature->getBaseObject(); + try { + previous = feature->getBaseObject(); // throws on errors + } catch (const Base::Exception &ex) { + previous = 0; } // roll back the done things Gui::Command::abortCommand(); Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); - // if abort command deleted the object make the previous feature visible again if (!Gui::Application::Instance->getViewProvider(feature)) { - // Body housekeeping - if (body != NULL) { - // Make the tip or the prebious feature visiable again with preference to the previous one + // Make the tip or the previous feature visiable again with preference to the previous one + // TODO: ViewProvider::onDelete has the same code. May be this one is excess? + if (previous && Gui::Application::Instance->getViewProvider(previous)) { + Gui::Application::Instance->getViewProvider(previous)->show(); + } else if (body != NULL) { App::DocumentObject* tip = body->Tip.getValue(); - - if (previous && Gui::Application::Instance->getViewProvider(previous)) { - Gui::Application::Instance->getViewProvider(previous)->show(); - } else if (tip && Gui::Application::Instance->getViewProvider(tip)) { + if (tip && Gui::Application::Instance->getViewProvider(tip)) { Gui::Application::Instance->getViewProvider(tip)->show(); } - } else { - if (previous && Gui::Application::Instance->getViewProvider(previous)) - Gui::Application::Instance->getViewProvider(previous)->show(); } } diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.h b/src/Mod/PartDesign/Gui/TaskFeatureParameters.h index 41305cc39..4c3a5aecd 100644 --- a/src/Mod/PartDesign/Gui/TaskFeatureParameters.h +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.h @@ -28,7 +28,7 @@ #include "ViewProvider.h" -namespace PartDesignGui { +namespace PartDesignGui { /// A common base for sketch based, dressup and other solid parameters dialogs class TaskDlgFeatureParameters : public Gui::TaskView::TaskDialog @@ -45,8 +45,10 @@ public: /// is called by the framework if the dialog is rejected (Cancel) virtual bool reject(); + /// Returns the view provider dialog is runed for + PartDesignGui::ViewProvider *viewProvider() const { return vp; } protected: - PartDesignGui::ViewProvider *vp; + PartDesignGui::ViewProvider *vp; }; } //namespace PartDesignGui diff --git a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp index f10773e51..97c858f2f 100644 --- a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp @@ -139,6 +139,7 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent, updateUI(index); // if it is a newly created object use the last value of the history + // TODO: newObj doesn't supplied normally by any caller (2015-07-24, Fat-Zer) if(newObj){ ui->lengthEdit->setToLastUsedValue(); ui->lengthEdit->selectNumber(); diff --git a/src/Mod/PartDesign/Gui/TaskPadParameters.h b/src/Mod/PartDesign/Gui/TaskPadParameters.h index 9e2c9d17d..6914dad73 100644 --- a/src/Mod/PartDesign/Gui/TaskPadParameters.h +++ b/src/Mod/PartDesign/Gui/TaskPadParameters.h @@ -91,7 +91,7 @@ class TaskDlgPadParameters : public TaskDlgSketchBasedParameters Q_OBJECT public: - TaskDlgPadParameters(ViewProviderPad *PadView,bool newObj=false); + TaskDlgPadParameters(ViewProviderPad *PadView, bool newObj=false); ~TaskDlgPadParameters(); ViewProviderPad* getPadView() const diff --git a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp index 1cb0118c0..575b274bf 100644 --- a/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPocketParameters.cpp @@ -130,6 +130,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge updateUI(index); // if it is a newly created object use the last value of the history + // TODO: newObj doesn't supplied normally by any caller (2015-07-24, Fat-Zer) if(newObj){ ui->lengthEdit->setToLastUsedValue(); ui->lengthEdit->selectNumber(); diff --git a/src/Mod/PartDesign/Gui/ViewProvider.cpp b/src/Mod/PartDesign/Gui/ViewProvider.cpp index 0db0c7da4..9377c36af 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.cpp +++ b/src/Mod/PartDesign/Gui/ViewProvider.cpp @@ -24,26 +24,28 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include #endif -#include "ViewProvider.h" -#include "Workbench.h" -#include -#include #include #include #include #include #include +#include +#include + +#include "TaskFeatureParameters.h" + +#include "ViewProvider.h" using namespace PartDesignGui; -PROPERTY_SOURCE(PartDesignGui::ViewProvider,PartGui::ViewProviderPart) +PROPERTY_SOURCE(PartDesignGui::ViewProvider, PartGui::ViewProviderPart) ViewProvider::ViewProvider() + :oldWb(""), oldTip(NULL) { - oldWb = ""; - oldTip = NULL; } ViewProvider::~ViewProvider() @@ -51,12 +53,13 @@ ViewProvider::~ViewProvider() } bool ViewProvider::doubleClicked(void) -{ - PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject(PDBODYKEY); - if (activeBody != NULL) { +{ + PartDesign::Body* body = PartDesign::Body::findBodyOf(getObject()); + + if (body != NULL) { // Drop into insert mode so that the user doesn't see all the geometry that comes later in the tree // Also, this way the user won't be tempted to use future geometry as external references for the sketch - oldTip = activeBody->Tip.getValue(); + oldTip = body->Tip.getValue(); if (oldTip != this->pcObject) Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')"); else @@ -69,7 +72,8 @@ bool ViewProvider::doubleClicked(void) std::string Msg("Edit "); Msg += this->pcObject->Label.getValue(); Gui::Command::openCommand(Msg.c_str()); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s',0)",this->pcObject->getNameInDocument()); + Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s',0)", + this->pcObject->getNameInDocument()); } catch (const Base::Exception&) { Gui::Command::abortCommand(); @@ -77,6 +81,56 @@ bool ViewProvider::doubleClicked(void) return true; } +bool ViewProvider::setEdit(int ModNum) +{ + if (ModNum == ViewProvider::Default ) { + // When double-clicking on the item for this feature the + // object unsets and sets its edit mode without closing + // the task panel + Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog(); + TaskDlgFeatureParameters *featureDlg = qobject_cast(dlg); + // NOTE: if the dialog is not partDesigan dialog the featureDlg will be NULL + if (featureDlg && featureDlg->viewProvider() != this) { + featureDlg = 0; // another feature left open its task panel + } + if (dlg && !featureDlg) { + 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 (featureDlg) { + Gui::Control().showDialog(featureDlg); + } else { + Gui::Control().showDialog(this->getEditDialog()); + } + + return true; + } else { + return PartGui::ViewProviderPart::setEdit(ModNum); + } +} + +TaskDlgFeatureParameters *ViewProvider::getEditDialog() +{ + throw Base::Exception("getEditDialog() not implemented"); +} + void ViewProvider::unsetEdit(int ModNum) { // return to the WB we were in before editing the PartDesign feature @@ -102,7 +156,8 @@ void ViewProvider::unsetEdit(int ModNum) void ViewProvider::updateData(const App::Property* prop) { - if (prop->getTypeId() == Part::PropertyPartShape::getClassTypeId() && + // TODO What's that? (2015-07-24, Fat-Zer) + if (prop->getTypeId() == Part::PropertyPartShape::getClassTypeId() && strcmp(prop->getName(),"AddSubShape") == 0) { return; } @@ -112,19 +167,32 @@ void ViewProvider::updateData(const App::Property* prop) bool ViewProvider::onDelete(const std::vector &) { - // Body feature housekeeping - Part::BodyBase* body = Part::BodyBase::findBodyOf(getObject()); - if (body != NULL) { - body->removeFeature(getObject()); - // Make the new Tip and the previous solid feature visible again - App::DocumentObject* tip = body->Tip.getValue(); - App::DocumentObject* prev = body->getPrevSolidFeature(); - if (tip != NULL) { - Gui::Application::Instance->getViewProvider(tip)->show(); - if ((tip != prev) && (prev != NULL)) - Gui::Application::Instance->getViewProvider(prev)->show(); - } + App::DocumentObject* previous; + PartDesign::Feature* feature = static_cast(getObject()); + + try { + previous = feature->getBaseObject(); + } catch (const Base::Exception &ex) { + previous = 0; } + // Make the tip or the previous feature visiable again with preference to the previous one + // if the feature was visiable itself + if (isShow()) { + // TODO TaskDlgFeatureParameters::reject has the same code. May be this one is excess? + // (2015-07-24, Fat-Zer) + if (previous && Gui::Application::Instance->getViewProvider(previous)) { + Gui::Application::Instance->getViewProvider(previous)->show(); + } else { + // Body feature housekeeping + Part::BodyBase* body = PartDesign::Body::findBodyOf(getObject()); + if (body != NULL) { + App::DocumentObject* tip = body->Tip.getValue(); + if (tip && Gui::Application::Instance->getViewProvider(tip)) { + Gui::Application::Instance->getViewProvider(tip)->show(); + } + } + } + } return true; } diff --git a/src/Mod/PartDesign/Gui/ViewProvider.h b/src/Mod/PartDesign/Gui/ViewProvider.h index 6e859a22e..cd9a42cc1 100644 --- a/src/Mod/PartDesign/Gui/ViewProvider.h +++ b/src/Mod/PartDesign/Gui/ViewProvider.h @@ -29,6 +29,11 @@ namespace PartDesignGui { +class TaskDlgFeatureParameters; + +/** + * A common base class for all part design features view providers + */ class PartDesignGuiExport ViewProvider : public PartGui::ViewProviderPart { typedef PartGui::ViewProviderPart inherited; PROPERTY_HEADER(PartDesignGui::ViewProvider); @@ -43,10 +48,15 @@ public: void updateData(const App::Property*); protected: + virtual bool setEdit(int ModNum); virtual void unsetEdit(int ModNum); virtual bool onDelete(const std::vector &); + /// Returns a newly create dialog for the part to be placed in the task view + // TODO make it pure virtual when finish implementation for all view providers (2015-07-24, Fat-Zer) + virtual TaskDlgFeatureParameters *getEditDialog()/* =0 */; + std::string oldWb; App::DocumentObject* oldTip; }; diff --git a/src/Mod/PartDesign/Gui/ViewProviderPad.cpp b/src/Mod/PartDesign/Gui/ViewProviderPad.cpp index 974fe69c0..67ffd38d6 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPad.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPad.cpp @@ -26,42 +26,26 @@ #ifndef _PreComp_ # include # include -# include #endif -#include "ViewProviderPad.h" #include "TaskPadParameters.h" -#include "Workbench.h" -#include -#include -#include -#include -#include -#include + +#include "ViewProviderPad.h" using namespace PartDesignGui; -PROPERTY_SOURCE(PartDesignGui::ViewProviderPad,PartDesignGui::ViewProvider) +PROPERTY_SOURCE(PartDesignGui::ViewProviderPad,PartDesignGui::ViewProviderSketchBased) ViewProviderPad::ViewProviderPad() { - sPixmap = "Tree_PartDesign_Pad.svg"; + sPixmap = "Tree_PartDesign_Pad.svg"; } ViewProviderPad::~ViewProviderPad() { } -std::vector ViewProviderPad::claimChildren(void)const -{ - std::vector temp; - App::DocumentObject* sketch = static_cast(getObject())->Sketch.getValue(); - if (sketch != NULL) - temp.push_back(sketch); - - return temp; -} - +// TODO This methode could also be unified with other features (2015-07-26, Fat-Zer) void ViewProviderPad::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) { QAction* act; @@ -70,61 +54,9 @@ void ViewProviderPad::setupContextMenu(QMenu* menu, QObject* receiver, const cha PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member); } -bool ViewProviderPad::setEdit(int ModNum) +TaskDlgFeatureParameters *ViewProviderPad::getEditDialog() { - if (ModNum == ViewProvider::Default || ModNum == 1 ) { - // 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(); - TaskDlgPadParameters *padDlg = qobject_cast(dlg); - if (padDlg && padDlg->getPadView() != 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 TaskDlgPadParameters(this,ModNum == 1)); - - return true; - } - else { - return ViewProviderPart::setEdit(ModNum); - } + // TODO fix setting values from the history: now it doesn't work neither in + // the master and in the migrated branch (2015-07-26, Fat-Zer) + return new TaskDlgPadParameters( this ); } - -bool ViewProviderPad::onDelete(const std::vector &s) -{ - PartDesign::Pad* pcPad = static_cast(getObject()); - - // get the Sketch - Sketcher::SketchObject *pcSketch = 0; - if (pcPad->Sketch.getValue()) - pcSketch = static_cast(pcPad->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/ViewProviderPad.h b/src/Mod/PartDesign/Gui/ViewProviderPad.h index 3116a8c80..f4465015d 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPad.h +++ b/src/Mod/PartDesign/Gui/ViewProviderPad.h @@ -24,11 +24,11 @@ #ifndef PARTGUI_ViewProviderPad_H #define PARTGUI_ViewProviderPad_H -#include "ViewProvider.h" +#include "ViewProviderSketchBased.h" namespace PartDesignGui { -class PartDesignGuiExport ViewProviderPad : public ViewProvider +class PartDesignGuiExport ViewProviderPad : public ViewProviderSketchBased { PROPERTY_HEADER(PartDesignGui::ViewProviderPad); @@ -38,14 +38,11 @@ public: /// destructor virtual ~ViewProviderPad(); - /// 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 TaskDlgPadParameters + virtual TaskDlgFeatureParameters *getEditDialog(); }; diff --git a/src/Mod/PartDesign/Gui/ViewProviderPocket.cpp b/src/Mod/PartDesign/Gui/ViewProviderPocket.cpp index 8a0639d7a..58ea2c08e 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPocket.cpp +++ b/src/Mod/PartDesign/Gui/ViewProviderPocket.cpp @@ -26,40 +26,26 @@ #ifndef _PreComp_ # include # include -# include #endif -#include "ViewProviderPocket.h" #include "TaskPocketParameters.h" -#include -#include -#include -#include -#include + +#include "ViewProviderPocket.h" using namespace PartDesignGui; -PROPERTY_SOURCE(PartDesignGui::ViewProviderPocket,PartDesignGui::ViewProvider) +PROPERTY_SOURCE(PartDesignGui::ViewProviderPocket,PartDesignGui::ViewProviderSketchBased) ViewProviderPocket::ViewProviderPocket() { - sPixmap = "PartDesign_Pocket.svg"; + sPixmap = "PartDesign_Pocket.svg"; } ViewProviderPocket::~ViewProviderPocket() { } -std::vector ViewProviderPocket::claimChildren(void)const -{ - std::vector temp; - App::DocumentObject* sketch = static_cast(getObject())->Sketch.getValue(); - if (sketch != NULL) - temp.push_back(sketch); - - return temp; -} void ViewProviderPocket::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) { @@ -69,61 +55,8 @@ void ViewProviderPocket::setupContextMenu(QMenu* menu, QObject* receiver, const PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member); } -bool ViewProviderPocket::setEdit(int ModNum) + +TaskDlgFeatureParameters *ViewProviderPocket::getEditDialog() { - if (ModNum == ViewProvider::Default ) { - // 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(); - TaskDlgPocketParameters *padDlg = qobject_cast(dlg); - if (padDlg && padDlg->getPocketView() != 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 TaskDlgPocketParameters(this)); - - return true; - } - else { - return PartGui::ViewProviderPart::setEdit(ModNum); - } + return new TaskDlgPocketParameters( this ); } - -bool ViewProviderPocket::onDelete(const std::vector &s) -{ - // get the Sketch - PartDesign::Pocket* pcPocket = static_cast(getObject()); - Sketcher::SketchObject *pcSketch = 0; - if (pcPocket->Sketch.getValue()) - pcSketch = static_cast(pcPocket->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/ViewProviderPocket.h b/src/Mod/PartDesign/Gui/ViewProviderPocket.h index 56e10d63f..9b22c2cc0 100644 --- a/src/Mod/PartDesign/Gui/ViewProviderPocket.h +++ b/src/Mod/PartDesign/Gui/ViewProviderPocket.h @@ -24,12 +24,12 @@ #ifndef PARTGUI_ViewProviderPocket_H #define PARTGUI_ViewProviderPocket_H -#include "ViewProvider.h" +#include "ViewProviderSketchBased.h" namespace PartDesignGui { -class PartDesignGuiExport ViewProviderPocket : public ViewProvider +class PartDesignGuiExport ViewProviderPocket : public ViewProviderSketchBased { PROPERTY_HEADER(PartDesignGui::ViewProviderPocket); @@ -39,14 +39,11 @@ public: /// destructor virtual ~ViewProviderPocket(); - /// 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 TaskDlgPocketParameters + virtual TaskDlgFeatureParameters *getEditDialog(); }; diff --git a/src/Mod/PartDesign/Gui/ViewProviderSketchBased.cpp b/src/Mod/PartDesign/Gui/ViewProviderSketchBased.cpp new file mode 100644 index 000000000..46db9872b --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderSketchBased.cpp @@ -0,0 +1,74 @@ +/*************************************************************************** + * Copyright (C) 2015 Alexander Golubev (Fat-Zer) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + + +#include "PreCompiled.h" + +#ifndef _PreComp_ +#endif + +#include +#include +#include + +#include "ViewProviderSketchBased.h" + + +using namespace PartDesignGui; + +PROPERTY_SOURCE(PartDesignGui::ViewProviderSketchBased, PartDesignGui::ViewProvider) + + +ViewProviderSketchBased::ViewProviderSketchBased() +{ +} + + +ViewProviderSketchBased::~ViewProviderSketchBased() +{ +} + + +std::vector ViewProviderSketchBased::claimChildren(void) const { + std::vector temp; + App::DocumentObject* sketch = static_cast(getObject())->Sketch.getValue(); + if (sketch != NULL) + temp.push_back(sketch); + + return temp; +} + + +bool ViewProviderSketchBased::onDelete(const std::vector &s) { + PartDesign::SketchBased* feature = static_cast(getObject()); + + // get the Sketch + Sketcher::SketchObject *pcSketch = 0; + if (feature->Sketch.getValue()) + pcSketch = static_cast(feature->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/ViewProviderSketchBased.h b/src/Mod/PartDesign/Gui/ViewProviderSketchBased.h new file mode 100644 index 000000000..3831c3c92 --- /dev/null +++ b/src/Mod/PartDesign/Gui/ViewProviderSketchBased.h @@ -0,0 +1,51 @@ +/*************************************************************************** + * Copyright (C) 2015 Alexander Golubev (Fat-Zer) * + * * + * This file is part of the FreeCAD CAx development system. * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Library General Public * + * License as published by the Free Software Foundation; either * + * version 2 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU Library General Public License for more details. * + * * + * You should have received a copy of the GNU Library General Public * + * License along with this library; see the file COPYING.LIB. If not, * + * write to the Free Software Foundation, Inc., 59 Temple Place, * + * Suite 330, Boston, MA 02111-1307, USA * + * * + ***************************************************************************/ + +#ifndef VIEWPROVIDERSKETCHBASED_H_QKP3UG9A +#define VIEWPROVIDERSKETCHBASED_H_QKP3UG9A + +#include "ViewProvider.h" + +namespace PartDesignGui { + +/** + * A common base class for Sketch based view providers + */ +class PartDesignGuiExport ViewProviderSketchBased : public ViewProvider +{ + PROPERTY_HEADER(PartDesignGui::ViewProviderSketchBased); + +public: + /// constructor + ViewProviderSketchBased(); + /// destructor + virtual ~ViewProviderSketchBased(); + + /// grouping handling + std::vector claimChildren(void)const; + + virtual bool onDelete(const std::vector &); +}; + +} /* PartDesignGui */ + +#endif /* end of include guard: VIEWPROVIDERSKETCHBASED_H_QKP3UG9A */