PartDesignGui: small rework to sketch-based task parameters
This done mostly for thurther unification them with other task parameters/dialogs.
This commit is contained in:
parent
96486cc4ed
commit
d43525370c
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include <Gui/Application.h>
|
||||
#include <Gui/Command.h>
|
||||
#include <Gui/BitmapFactory.h>
|
||||
#include <Mod/PartDesign/App/Feature.h>
|
||||
#include <Mod/PartDesign/App/Body.h>
|
||||
|
||||
|
@ -35,6 +36,31 @@
|
|||
using namespace PartDesignGui;
|
||||
using namespace Gui;
|
||||
|
||||
/*********************************************************************
|
||||
* Task Feature Parameters *
|
||||
*********************************************************************/
|
||||
|
||||
TaskFeatureParameters::TaskFeatureParameters(PartDesignGui::ViewProvider *vp, QWidget *parent,
|
||||
const std::string& pixmapname, const QString& parname)
|
||||
: TaskBox(Gui::BitmapFactory().pixmap(pixmapname.c_str()),parname,true, parent),
|
||||
vp(vp), blockUpdate(false)
|
||||
{ }
|
||||
|
||||
void TaskFeatureParameters::onUpdateView(bool on)
|
||||
{
|
||||
blockUpdate = !on;
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskFeatureParameters::recomputeFeature()
|
||||
{
|
||||
if (!blockUpdate) {
|
||||
App::DocumentObject* obj = vp->getObject ();
|
||||
assert (obj);
|
||||
obj->getDocument()->recomputeFeature ( obj );
|
||||
}
|
||||
}
|
||||
|
||||
/*********************************************************************
|
||||
* Task Dialog *
|
||||
*********************************************************************/
|
||||
|
@ -53,6 +79,12 @@ bool TaskDlgFeatureParameters::accept() {
|
|||
App::DocumentObject* feature = vp->getObject();
|
||||
|
||||
try {
|
||||
// Iterate over parameter dialogs and apply all parameters from them
|
||||
for ( QWidget *wgt : Content ) {
|
||||
TaskFeatureParameters *param = qobject_cast<TaskFeatureParameters *> (wgt);
|
||||
param->saveHistory ();
|
||||
param->apply ();
|
||||
}
|
||||
// Make sure the feature is what we are expecting
|
||||
// Should be fine but you never know...
|
||||
if ( !feature->getTypeId().isDerivedFrom(PartDesign::Feature::getClassTypeId()) ) {
|
||||
|
|
|
@ -24,12 +24,40 @@
|
|||
#define TASKFEATUREPARAMETERS_H_NAHKE2YZ
|
||||
|
||||
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/TaskView/TaskDialog.h>
|
||||
|
||||
#include "ViewProvider.h"
|
||||
|
||||
namespace PartDesignGui {
|
||||
|
||||
/// Convenience class to collect common methods for all SketchBased features
|
||||
class TaskFeatureParameters : public Gui::TaskView::TaskBox
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TaskFeatureParameters(PartDesignGui::ViewProvider* vp, QWidget *parent,
|
||||
const std::string& pixmapname, const QString& parname);
|
||||
virtual ~TaskFeatureParameters() {};
|
||||
|
||||
/// save field history
|
||||
virtual void saveHistory(void) {};
|
||||
/// apply changes made in the parameters input to the model via commands
|
||||
virtual void apply() {};
|
||||
|
||||
void recomputeFeature();
|
||||
|
||||
protected Q_SLOTS:
|
||||
// TODO Add update view to all dialogs (2015-12-05, Fat-Zer)
|
||||
void onUpdateView(bool on);
|
||||
|
||||
protected:
|
||||
PartDesignGui::ViewProvider *vp;
|
||||
/// Lock updateUI(), applying changes to the underlying feature and calling recomputeFeature()
|
||||
bool blockUpdate;
|
||||
};
|
||||
|
||||
/// A common base for sketch based, dressup and other solid parameters dialogs
|
||||
class TaskDlgFeatureParameters : public Gui::TaskView::TaskDialog
|
||||
{
|
||||
|
@ -37,7 +65,7 @@ class TaskDlgFeatureParameters : public Gui::TaskView::TaskDialog
|
|||
|
||||
public:
|
||||
TaskDlgFeatureParameters(PartDesignGui::ViewProvider *vp);
|
||||
~TaskDlgFeatureParameters();
|
||||
virtual ~TaskDlgFeatureParameters();
|
||||
|
||||
public:
|
||||
/// is called by the framework if the dialog is accepted (Ok)
|
||||
|
@ -47,6 +75,7 @@ public:
|
|||
|
||||
/// Returns the view provider dialog is runed for
|
||||
PartDesignGui::ViewProvider *viewProvider() const { return vp; }
|
||||
|
||||
protected:
|
||||
PartDesignGui::ViewProvider *vp;
|
||||
};
|
||||
|
|
|
@ -406,6 +406,7 @@ void TaskPadParameters::apply()
|
|||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.Type = %u", cname, getMode());
|
||||
QString facename = getFaceName();
|
||||
|
||||
// TODO get rid of this if (2015-12-05, Fat-Zer)
|
||||
if (!facename.isEmpty()) {
|
||||
Gui::Command::doCommand(Gui::Command::Doc,"App.ActiveDocument.%s.UpToFace = %s",
|
||||
cname, facename.toLatin1().data());
|
||||
|
@ -426,26 +427,9 @@ TaskDlgPadParameters::TaskDlgPadParameters(ViewProviderPad *PadView,bool newObj)
|
|||
: TaskDlgSketchBasedParameters(PadView)
|
||||
{
|
||||
assert(vp);
|
||||
parameter = new TaskPadParameters(static_cast<ViewProviderPad*>(vp));
|
||||
|
||||
Content.push_back(parameter);
|
||||
}
|
||||
|
||||
TaskDlgPadParameters::~TaskDlgPadParameters()
|
||||
{
|
||||
|
||||
Content.push_back ( new TaskPadParameters(PadView ) );
|
||||
}
|
||||
|
||||
//==== calls from the TaskView ===============================================================
|
||||
|
||||
bool TaskDlgPadParameters::accept()
|
||||
{
|
||||
// save the history
|
||||
parameter->saveHistory();
|
||||
parameter->apply();
|
||||
|
||||
return TaskDlgSketchBasedParameters::accept();
|
||||
}
|
||||
|
||||
|
||||
#include "moc_TaskPadParameters.cpp"
|
||||
|
|
|
@ -52,9 +52,8 @@ public:
|
|||
TaskPadParameters(ViewProviderPad *PadView, QWidget *parent = 0, bool newObj=false);
|
||||
~TaskPadParameters();
|
||||
|
||||
|
||||
void saveHistory(void);
|
||||
void apply();
|
||||
virtual void saveHistory() override;
|
||||
virtual void apply() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onLengthChanged(double);
|
||||
|
@ -92,18 +91,9 @@ class TaskDlgPadParameters : public TaskDlgSketchBasedParameters
|
|||
|
||||
public:
|
||||
TaskDlgPadParameters(ViewProviderPad *PadView, bool newObj=false);
|
||||
~TaskDlgPadParameters();
|
||||
|
||||
ViewProviderPad* getPadView() const
|
||||
{ return static_cast<ViewProviderPad*>(vp); }
|
||||
|
||||
|
||||
public:
|
||||
/// is called by the framework if the dialog is accepted (Ok)
|
||||
virtual bool accept();
|
||||
|
||||
protected:
|
||||
TaskPadParameters *parameter;
|
||||
};
|
||||
|
||||
} //namespace PartDesignGui
|
||||
|
|
|
@ -414,27 +414,7 @@ TaskDlgPocketParameters::TaskDlgPocketParameters(ViewProviderPocket *PocketView)
|
|||
: TaskDlgSketchBasedParameters(PocketView)
|
||||
{
|
||||
assert(vp);
|
||||
parameter = new TaskPocketParameters(static_cast<ViewProviderPocket*>(vp));
|
||||
|
||||
Content.push_back(parameter);
|
||||
Content.push_back ( new TaskPocketParameters(PocketView ) );
|
||||
}
|
||||
|
||||
TaskDlgPocketParameters::~TaskDlgPocketParameters()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//==== calls from the TaskView ===============================================================
|
||||
|
||||
bool TaskDlgPocketParameters::accept()
|
||||
{
|
||||
parameter->apply();
|
||||
|
||||
// save the history
|
||||
parameter->saveHistory();
|
||||
|
||||
return TaskDlgSketchBasedParameters::accept();
|
||||
}
|
||||
|
||||
|
||||
#include "moc_TaskPocketParameters.cpp"
|
||||
|
|
|
@ -52,9 +52,8 @@ public:
|
|||
TaskPocketParameters(ViewProviderPocket *PocketView, QWidget *parent = 0, bool newObj=false);
|
||||
~TaskPocketParameters();
|
||||
|
||||
void apply();
|
||||
|
||||
void saveHistory(void);
|
||||
virtual void saveHistory() override;
|
||||
virtual void apply() override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void onLengthChanged(double);
|
||||
|
@ -92,18 +91,9 @@ class TaskDlgPocketParameters : public TaskDlgSketchBasedParameters
|
|||
|
||||
public:
|
||||
TaskDlgPocketParameters(ViewProviderPocket *PocketView);
|
||||
~TaskDlgPocketParameters();
|
||||
|
||||
ViewProviderPocket* getPocketView() const
|
||||
{ return static_cast<ViewProviderPocket*>(vp); }
|
||||
|
||||
|
||||
public:
|
||||
/// is called by the framework if the dialog is accepted (Ok)
|
||||
virtual bool accept();
|
||||
|
||||
protected:
|
||||
TaskPocketParameters *parameter;
|
||||
};
|
||||
|
||||
} //namespace PartDesignGui
|
||||
|
|
|
@ -409,24 +409,6 @@ TaskDlgRevolutionParameters::TaskDlgRevolutionParameters(PartDesignGui::ViewProv
|
|||
: TaskDlgSketchBasedParameters(RevolutionView)
|
||||
{
|
||||
assert(RevolutionView);
|
||||
parameter = new TaskRevolutionParameters(RevolutionView);
|
||||
|
||||
Content.push_back(parameter);
|
||||
Content.push_back(new TaskRevolutionParameters(RevolutionView));
|
||||
}
|
||||
|
||||
TaskDlgRevolutionParameters::~TaskDlgRevolutionParameters()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//==== calls from the TaskView ===============================================================
|
||||
|
||||
bool TaskDlgRevolutionParameters::accept()
|
||||
{
|
||||
parameter->apply();
|
||||
|
||||
return TaskDlgSketchBasedParameters::accept();
|
||||
}
|
||||
|
||||
|
||||
#include "moc_TaskRevolutionParameters.cpp"
|
||||
|
|
|
@ -53,7 +53,7 @@ public:
|
|||
TaskRevolutionParameters(ViewProvider* RevolutionView,QWidget *parent = 0);
|
||||
~TaskRevolutionParameters();
|
||||
|
||||
void apply();
|
||||
virtual void apply() override;
|
||||
|
||||
/**
|
||||
* @brief fillAxisCombo fills the combo and selects the item according to
|
||||
|
@ -111,17 +111,9 @@ class TaskDlgRevolutionParameters : public TaskDlgSketchBasedParameters
|
|||
|
||||
public:
|
||||
TaskDlgRevolutionParameters(PartDesignGui::ViewProvider *RevolutionView);
|
||||
~TaskDlgRevolutionParameters();
|
||||
|
||||
ViewProvider* getRevolutionView() const
|
||||
{ return vp; }
|
||||
|
||||
public:
|
||||
/// is called by the framework if the dialog is accepted (Ok)
|
||||
virtual bool accept();
|
||||
|
||||
protected:
|
||||
TaskRevolutionParameters *parameter;
|
||||
};
|
||||
|
||||
} //namespace PartDesignGui
|
||||
|
|
|
@ -60,8 +60,7 @@ using namespace Gui;
|
|||
|
||||
TaskSketchBasedParameters::TaskSketchBasedParameters(PartDesignGui::ViewProvider *vp, QWidget *parent,
|
||||
const std::string& pixmapname, const QString& parname)
|
||||
: TaskBox(Gui::BitmapFactory().pixmap(pixmapname.c_str()),parname,true, parent),
|
||||
vp(vp), blockUpdate(false)
|
||||
: TaskFeatureParameters(vp, parent, pixmapname, parname)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -172,7 +171,7 @@ const QByteArray TaskSketchBasedParameters::onFaceName(const QString& text)
|
|||
}
|
||||
}
|
||||
|
||||
QString TaskSketchBasedParameters::getFaceReference(const QString& obj, const QString& sub) const
|
||||
QString TaskSketchBasedParameters::getFaceReference(const QString& obj, const QString& sub)
|
||||
{
|
||||
QString o = obj.left(obj.indexOf(QString::fromAscii(":")));
|
||||
|
||||
|
@ -183,20 +182,6 @@ QString TaskSketchBasedParameters::getFaceReference(const QString& obj, const QS
|
|||
QString::fromAscii(", [\"") + sub + QString::fromAscii("\"])");
|
||||
}
|
||||
|
||||
void TaskSketchBasedParameters::onUpdateView(bool on)
|
||||
{
|
||||
blockUpdate = !on;
|
||||
recomputeFeature();
|
||||
}
|
||||
|
||||
void TaskSketchBasedParameters::recomputeFeature()
|
||||
{
|
||||
if (!blockUpdate) {
|
||||
PartDesign::SketchBased* pcSketchBased = static_cast<PartDesign::SketchBased*>(vp->getObject());
|
||||
pcSketchBased->getDocument()->recomputeFeature(pcSketchBased);
|
||||
}
|
||||
}
|
||||
|
||||
TaskSketchBasedParameters::~TaskSketchBasedParameters()
|
||||
{
|
||||
}
|
||||
|
@ -259,5 +244,4 @@ bool TaskDlgSketchBasedParameters::reject()
|
|||
return rv;
|
||||
}
|
||||
|
||||
|
||||
#include "moc_TaskSketchBasedParameters.cpp"
|
||||
|
|
|
@ -24,7 +24,6 @@
|
|||
#ifndef GUI_TASKVIEW_TaskSketchBasedParameters_H
|
||||
#define GUI_TASKVIEW_TaskSketchBasedParameters_H
|
||||
|
||||
#include <Gui/TaskView/TaskView.h>
|
||||
#include <Gui/Selection.h>
|
||||
#include "ViewProvider.h"
|
||||
|
||||
|
@ -38,7 +37,7 @@ namespace PartDesignGui {
|
|||
|
||||
|
||||
/// Convenience class to collect common methods for all SketchBased features
|
||||
class TaskSketchBasedParameters : public Gui::TaskView::TaskBox, public Gui::SelectionObserver
|
||||
class TaskSketchBasedParameters : public PartDesignGui::TaskFeatureParameters, public Gui::SelectionObserver
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
|
@ -53,16 +52,8 @@ protected:
|
|||
void onSelectReference(const bool pressed, const bool edge, const bool face, const bool planar);
|
||||
void exitSelectionMode();
|
||||
const QByteArray onFaceName(const QString& text);
|
||||
QString getFaceReference(const QString& obj, const QString& sub) const;
|
||||
void recomputeFeature();
|
||||
|
||||
protected Q_SLOTS:
|
||||
void onUpdateView(bool on);
|
||||
|
||||
protected:
|
||||
PartDesignGui::ViewProvider *vp;
|
||||
/// Lock updateUI(), applying changes to the underlying feature and calling recomputeFeature()
|
||||
bool blockUpdate;
|
||||
static QString getFaceReference(const QString& obj, const QString& sub);
|
||||
};
|
||||
|
||||
class TaskDlgSketchBasedParameters : public PartDesignGui::TaskDlgFeatureParameters
|
||||
|
|
Loading…
Reference in New Issue
Block a user