diff --git a/src/Mod/PartDesign/Gui/CMakeLists.txt b/src/Mod/PartDesign/Gui/CMakeLists.txt index 84d97295d..38c637309 100644 --- a/src/Mod/PartDesign/Gui/CMakeLists.txt +++ b/src/Mod/PartDesign/Gui/CMakeLists.txt @@ -29,6 +29,7 @@ set(PartDesignGui_LIBS set(PartDesignGui_MOC_HDRS TaskFeaturePick.h + TaskFeatureParameters.h TaskSketchBasedParameters.h TaskPadParameters.h TaskPocketParameters.h @@ -149,6 +150,8 @@ SET(PartDesignGuiTaskDlgs_SRCS TaskFeaturePick.h ReferenceSelection.cpp ReferenceSelection.h + TaskFeatureParameters.cpp + TaskFeatureParameters.h TaskSketchBasedParameters.cpp TaskSketchBasedParameters.h TaskPadParameters.ui diff --git a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp index 7b9b7c4f5..0eb2c5981 100644 --- a/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDraftParameters.cpp @@ -291,7 +291,7 @@ bool TaskDlgDraftParameters::accept() return false; } - std::string name = DressUpView->getObject()->getNameInDocument(); + std::string name = vp->getObject()->getNameInDocument(); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Angle = %f",name.c_str(),draftparameter->getAngle()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed()); diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp index 41564dc0d..0e1a7bede 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.cpp @@ -42,7 +42,6 @@ #include #include #include -#include #include using namespace PartDesignGui; @@ -190,7 +189,7 @@ void TaskDressUpParameters::exitSelectionMode() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TaskDlgDressUpParameters::TaskDlgDressUpParameters(ViewProviderDressUp *DressUpView) - : TaskDialog(),DressUpView(DressUpView) + : TaskDlgFeatureParameters(DressUpView) { assert(DressUpView); } @@ -204,8 +203,8 @@ TaskDlgDressUpParameters::~TaskDlgDressUpParameters() bool TaskDlgDressUpParameters::accept() { - std::string name = DressUpView->getObject()->getNameInDocument(); - DressUpView->highlightReferences(false); + std::string name = vp->getObject()->getNameInDocument(); + getDressUpView()->highlightReferences(false); try { std::vector refs = parameter->getReferences(); @@ -228,41 +227,4 @@ bool TaskDlgDressUpParameters::accept() return true; } -bool TaskDlgDressUpParameters::reject() -{ - PartDesign::DressUp* pcDressUp = static_cast(DressUpView->getObject()); - App::DocumentObject* pcSupport = pcDressUp->Base.getValue(); - PartDesign::Body* body = PartDesign::Body::findBodyOf (pcDressUp); - - DressUpView->highlightReferences(false); - - // roll back the done things - Gui::Command::abortCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); - Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.recompute()"); - - // if abort command deleted the object the support is visible again - if (!Gui::Application::Instance->getViewProvider(pcDressUp)) { - // Body housekeeping - if (body != NULL) { - // Make the new Tip and the previous solid feature visible again - // TODO: share the code with TaskDlgSketchBasedDlg::reject() - 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(); - } - } else { - if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport)) - Gui::Application::Instance->getViewProvider(pcSupport)->show(); - } - } - - return true; -} - - - #include "moc_TaskDressUpParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskDressUpParameters.h b/src/Mod/PartDesign/Gui/TaskDressUpParameters.h index b46b2a631..d689f4601 100644 --- a/src/Mod/PartDesign/Gui/TaskDressUpParameters.h +++ b/src/Mod/PartDesign/Gui/TaskDressUpParameters.h @@ -26,8 +26,8 @@ #include #include -#include +#include "TaskFeatureParameters.h" #include "ViewProviderDressUp.h" class QListWidget; @@ -78,7 +78,7 @@ protected: }; /// simulation dialog for the TaskView -class TaskDlgDressUpParameters : public Gui::TaskView::TaskDialog +class TaskDlgDressUpParameters : public TaskDlgFeatureParameters { Q_OBJECT @@ -87,29 +87,13 @@ public: virtual ~TaskDlgDressUpParameters(); ViewProviderDressUp* getDressUpView() const - { return DressUpView; } - + { return static_cast(vp); } public: - /// is called the TaskView when the dialog is opened - virtual void open() {} - /// is called by the framework if an button is clicked which has no accept or reject role - virtual void clicked(int) {} /// is called by the framework if the dialog is accepted (Ok) virtual bool accept(); - /// is called by the framework if the dialog is rejected (Cancel) - virtual bool reject(); - /// is called by the framework if the user presses the help button - virtual bool isAllowedAlterDocument(void) const - { return false; } - - /// returns for Close and Help button - virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const - { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } protected: - ViewProviderDressUp *DressUpView; - TaskDressUpParameters *parameter; }; diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp new file mode 100644 index 000000000..4cc6f2ce5 --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp @@ -0,0 +1,93 @@ +/*************************************************************************** + * 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 + +#include "TaskFeatureParameters.h" + +using namespace PartDesignGui; +using namespace Gui; + +/********************************************************************* + * Task Dialog * + *********************************************************************/ +TaskDlgFeatureParameters::TaskDlgFeatureParameters(PartDesignGui::ViewProvider *vp) + : TaskDialog(),vp(vp) +{ + assert(vp); +} + +TaskDlgFeatureParameters::~TaskDlgFeatureParameters() +{ + +} + +bool TaskDlgFeatureParameters::reject() +{ + PartDesign::Feature* feature = static_cast(vp->getObject()); + + PartDesign::Body* body = PartDesign::Body::findBodyOf(feature); + + // 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(); + } + + // 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 + 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)) { + Gui::Application::Instance->getViewProvider(tip)->show(); + } + } else { + if (previous && Gui::Application::Instance->getViewProvider(previous)) + Gui::Application::Instance->getViewProvider(previous)->show(); + } + } + + return true; +} + +#include "moc_TaskFeatureParameters.cpp" diff --git a/src/Mod/PartDesign/Gui/TaskFeatureParameters.h b/src/Mod/PartDesign/Gui/TaskFeatureParameters.h new file mode 100644 index 000000000..ce207478d --- /dev/null +++ b/src/Mod/PartDesign/Gui/TaskFeatureParameters.h @@ -0,0 +1,55 @@ +/*************************************************************************** + * 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 TASKFEATUREPARAMETERS_H_NAHKE2YZ +#define TASKFEATUREPARAMETERS_H_NAHKE2YZ + + +#include + +#include "ViewProvider.h" + +namespace PartDesignGui { + +/// A common base for sketch based, dressup and other solid parameters dialogs +class TaskDlgFeatureParameters : public Gui::TaskView::TaskDialog +{ + Q_OBJECT + +public: + TaskDlgFeatureParameters(PartDesignGui::ViewProvider *vp); + ~TaskDlgFeatureParameters(); + +public: + /// is called by the framework if the dialog is accepted (Ok) + virtual bool accept()=0; + /// is called by the framework if the dialog is rejected (Cancel) + virtual bool reject(); + +protected: + PartDesignGui::ViewProvider *vp; +}; + +} //namespace PartDesignGui + + +#endif /* end of include guard: TASKFEATUREPARAMETERS_H_NAHKE2YZ */ diff --git a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp index 977884711..6a64b407f 100644 --- a/src/Mod/PartDesign/Gui/TaskPadParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskPadParameters.cpp @@ -484,7 +484,7 @@ TaskDlgPadParameters::~TaskDlgPadParameters() bool TaskDlgPadParameters::accept() { - // save the history + // save the history parameter->saveHistory(); try { diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp index c88318b0e..cdf1ad32c 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.cpp @@ -272,7 +272,7 @@ TaskSketchBasedParameters::~TaskSketchBasedParameters() //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ TaskDlgSketchBasedParameters::TaskDlgSketchBasedParameters(PartDesignGui::ViewProvider *vp) - : TaskDialog(),vp(vp) + : TaskDlgFeatureParameters(vp) { } @@ -283,57 +283,25 @@ TaskDlgSketchBasedParameters::~TaskDlgSketchBasedParameters() //==== calls from the TaskView =============================================================== - -void TaskDlgSketchBasedParameters::open() -{ - -} - -void TaskDlgSketchBasedParameters::clicked(int) -{ - -} - bool TaskDlgSketchBasedParameters::reject() { PartDesign::SketchBased* pcSketchBased = static_cast(vp->getObject()); // get the Sketch - Sketcher::SketchObject *pcSketch; - if (pcSketchBased->Sketch.getValue()) { - pcSketch = static_cast(pcSketchBased->Sketch.getValue()); - } - - PartDesign::Body* body = PartDesign::Body::findBodyOf(pcSketchBased); - - // roll back the done things - Gui::Command::abortCommand(); - Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()"); + Sketcher::SketchObject *pcSketch = static_cast(pcSketchBased->Sketch.getValue()); + bool rv; + // rv should be true anyway but to be on the safe side dur to thurver changes better respect it. + rv = TaskDlgFeatureParameters::reject(); - // if abort command deleted the object the sketch is visible again as well as the previous feature + // if abort command deleted the object the sketch is visible again. + // The the previous one feature already should be made visiable if (!Gui::Application::Instance->getViewProvider(pcSketchBased)) { + // Make the sketch visiable if (pcSketch && Gui::Application::Instance->getViewProvider(pcSketch)) Gui::Application::Instance->getViewProvider(pcSketch)->show(); - - // Body housekeeping - if (body != NULL) { - // Make the new Tip and the previous solid feature visible again - // TODO: do we really should make them both visiable? - App::DocumentObject* tip = body->Tip.getValue(); - App::DocumentObject* prev = body->getPrevSolidFeature(pcSketchBased); - if (tip != NULL) { - Gui::Application::Instance->getViewProvider(tip)->show(); - if ((tip != prev) && (prev != NULL)) - Gui::Application::Instance->getViewProvider(prev)->show(); - } - } else { - App::DocumentObject *pcSupport = pcSketch->Support.getValue(); - if (pcSupport && Gui::Application::Instance->getViewProvider(pcSupport)) - Gui::Application::Instance->getViewProvider(pcSupport)->show(); - } } - return true; + return rv; } diff --git a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h index cd0d2a9b0..af3e62507 100644 --- a/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h +++ b/src/Mod/PartDesign/Gui/TaskSketchBasedParameters.h @@ -26,9 +26,10 @@ #include #include -#include #include "ViewProvider.h" +#include "TaskFeatureParameters.h" + namespace App { class Property; } @@ -67,7 +68,7 @@ protected: bool blockUpdate; }; -class TaskDlgSketchBasedParameters : public Gui::TaskView::TaskDialog +class TaskDlgSketchBasedParameters : public PartDesignGui::TaskDlgFeatureParameters { Q_OBJECT @@ -76,24 +77,8 @@ public: ~TaskDlgSketchBasedParameters(); public: - /// is called the TaskView when the dialog is opened - virtual void open(); - /// is called by the framework if an button is clicked which has no accept or reject role - virtual void clicked(int); - /// is called by the framework if the dialog is accepted (Ok) - virtual bool accept()=0; /// is called by the framework if the dialog is rejected (Cancel) virtual bool reject(); - /// is called by the framework if the user presses the help button - virtual bool isAllowedAlterDocument(void) const - { return false; } - - /// returns for Close and Help button - virtual QDialogButtonBox::StandardButtons getStandardButtons(void) const - { return QDialogButtonBox::Ok|QDialogButtonBox::Cancel; } - -protected: - PartDesignGui::ViewProvider *vp; }; } //namespace PartDesignGui diff --git a/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp b/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp index df69dac1c..4b3a66bfd 100644 --- a/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskThicknessParameters.cpp @@ -247,7 +247,7 @@ bool TaskDlgThicknessParameters::accept() TaskThicknessParameters* draftparameter = static_cast(parameter); - std::string name = DressUpView->getObject()->getNameInDocument(); + std::string name = vp->getObject()->getNameInDocument(); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Value = %f",name.c_str(),draftparameter->getValue()); Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Reversed = %u",name.c_str(),draftparameter->getReversed());