PartDesign: move common code for TaskDlg{SketcherBased,DressUp}Parameters into new base class
Added a new class: TaskDlgFeatureBased which currently contains common code for TaskDlgSketcherBasedParameters::reject() as well as the same methode for TaskDlgDressUpParameters. It's likely that other Feature task dialogs will inherit this class too.
This commit is contained in:
parent
0208a3667d
commit
b14d7c2e14
|
@ -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
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -42,7 +42,6 @@
|
|||
#include <Gui/Command.h>
|
||||
#include <Gui/MainWindow.h>
|
||||
#include <Mod/PartDesign/App/FeatureDressUp.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
#include <Mod/PartDesign/Gui/ReferenceSelection.h>
|
||||
|
||||
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<std::string> refs = parameter->getReferences();
|
||||
|
@ -228,41 +227,4 @@ bool TaskDlgDressUpParameters::accept()
|
|||
return true;
|
||||
}
|
||||
|
||||
bool TaskDlgDressUpParameters::reject()
|
||||
{
|
||||
PartDesign::DressUp* pcDressUp = static_cast<PartDesign::DressUp*>(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"
|
||||
|
|
|
@ -26,8 +26,8 @@
|
|||
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
|
||||
#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<ViewProviderDressUp*>(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;
|
||||
};
|
||||
|
||||
|
|
93
src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp
Normal file
93
src/Mod/PartDesign/Gui/TaskFeatureParameters.cpp
Normal file
|
@ -0,0 +1,93 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2015 Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> *
|
||||
* *
|
||||
* 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 <Gui/Application.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Mod/PartDesign/App/Feature.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
|
||||
#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<PartDesign::Feature*>(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"
|
55
src/Mod/PartDesign/Gui/TaskFeatureParameters.h
Normal file
55
src/Mod/PartDesign/Gui/TaskFeatureParameters.h
Normal file
|
@ -0,0 +1,55 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2015 Alexander Golubev (Fat-Zer) <fatzer2@gmail.com> *
|
||||
* *
|
||||
* 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 <Gui/TaskView/TaskDialog.h>
|
||||
|
||||
#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 */
|
|
@ -484,7 +484,7 @@ TaskDlgPadParameters::~TaskDlgPadParameters()
|
|||
bool TaskDlgPadParameters::accept()
|
||||
{
|
||||
|
||||
// save the history
|
||||
// save the history
|
||||
parameter->saveHistory();
|
||||
|
||||
try {
|
||||
|
|
|
@ -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<PartDesign::SketchBased*>(vp->getObject());
|
||||
// get the Sketch
|
||||
Sketcher::SketchObject *pcSketch;
|
||||
if (pcSketchBased->Sketch.getValue()) {
|
||||
pcSketch = static_cast<Sketcher::SketchObject*>(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<Sketcher::SketchObject*>(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;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -26,9 +26,10 @@
|
|||
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
#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
|
||||
|
|
|
@ -247,7 +247,7 @@ bool TaskDlgThicknessParameters::accept()
|
|||
|
||||
TaskThicknessParameters* draftparameter = static_cast<TaskThicknessParameters*>(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());
|
||||
|
|
Loading…
Reference in New Issue
Block a user