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
This commit is contained in:
parent
6266d514d3
commit
5ee0cea467
|
@ -37,6 +37,7 @@
|
||||||
#include "Workbench.h"
|
#include "Workbench.h"
|
||||||
#include "ViewProviderPocket.h"
|
#include "ViewProviderPocket.h"
|
||||||
#include "ViewProviderBody.h"
|
#include "ViewProviderBody.h"
|
||||||
|
#include "ViewProviderSketchBased.h"
|
||||||
#include "ViewProviderPad.h"
|
#include "ViewProviderPad.h"
|
||||||
#include "ViewProviderChamfer.h"
|
#include "ViewProviderChamfer.h"
|
||||||
#include "ViewProviderFillet.h"
|
#include "ViewProviderFillet.h"
|
||||||
|
@ -119,7 +120,8 @@ PyMODINIT_FUNC initPartDesignGui()
|
||||||
|
|
||||||
PartDesignGui::Workbench ::init();
|
PartDesignGui::Workbench ::init();
|
||||||
PartDesignGui::ViewProvider ::init();
|
PartDesignGui::ViewProvider ::init();
|
||||||
PartDesignGui::ViewProviderBody ::init();
|
PartDesignGui::ViewProviderBody ::init();
|
||||||
|
PartDesignGui::ViewProviderSketchBased ::init();
|
||||||
PartDesignGui::ViewProviderPocket ::init();
|
PartDesignGui::ViewProviderPocket ::init();
|
||||||
PartDesignGui::ViewProviderPad ::init();
|
PartDesignGui::ViewProviderPad ::init();
|
||||||
PartDesignGui::ViewProviderRevolution ::init();
|
PartDesignGui::ViewProviderRevolution ::init();
|
||||||
|
|
|
@ -89,6 +89,8 @@ SET(PartDesignGuiViewProvider_SRCS CommandPrimitive.cpp
|
||||||
ViewProvider.h
|
ViewProvider.h
|
||||||
ViewProviderBody.cpp
|
ViewProviderBody.cpp
|
||||||
ViewProviderBody.h
|
ViewProviderBody.h
|
||||||
|
ViewProviderSketchBased.cpp
|
||||||
|
ViewProviderSketchBased.h
|
||||||
ViewProviderPad.cpp
|
ViewProviderPad.cpp
|
||||||
ViewProviderPad.h
|
ViewProviderPad.h
|
||||||
#ViewProviderHole.cpp
|
#ViewProviderHole.cpp
|
||||||
|
|
|
@ -92,33 +92,27 @@ bool TaskDlgFeatureParameters::reject()
|
||||||
// Find out previous feature we won't be able to do it after abort
|
// Find out previous feature we won't be able to do it after abort
|
||||||
// (at least in the body case)
|
// (at least in the body case)
|
||||||
App::DocumentObject* previous;
|
App::DocumentObject* previous;
|
||||||
if (body) {
|
try {
|
||||||
// NOTE: feature->getBaseObject() should return the same for body
|
previous = feature->getBaseObject(); // throws on errors
|
||||||
previous = body->getPrevSolidFeature(feature, /*inclusive =*/ false);
|
} catch (const Base::Exception &ex) {
|
||||||
} else {
|
previous = 0;
|
||||||
previous = feature->getBaseObject();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// roll back the done things
|
// roll back the done things
|
||||||
Gui::Command::abortCommand();
|
Gui::Command::abortCommand();
|
||||||
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
|
||||||
|
|
||||||
|
|
||||||
// if abort command deleted the object make the previous feature visible again
|
// if abort command deleted the object make the previous feature visible again
|
||||||
if (!Gui::Application::Instance->getViewProvider(feature)) {
|
if (!Gui::Application::Instance->getViewProvider(feature)) {
|
||||||
// Body housekeeping
|
// Make the tip or the previous feature visiable again with preference to the previous one
|
||||||
if (body != NULL) {
|
// TODO: ViewProvider::onDelete has the same code. May be this one is excess?
|
||||||
// Make the tip or the prebious feature visiable again with preference to the previous one
|
if (previous && Gui::Application::Instance->getViewProvider(previous)) {
|
||||||
|
Gui::Application::Instance->getViewProvider(previous)->show();
|
||||||
|
} else if (body != NULL) {
|
||||||
App::DocumentObject* tip = body->Tip.getValue();
|
App::DocumentObject* tip = body->Tip.getValue();
|
||||||
|
if (tip && Gui::Application::Instance->getViewProvider(tip)) {
|
||||||
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();
|
Gui::Application::Instance->getViewProvider(tip)->show();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
if (previous && Gui::Application::Instance->getViewProvider(previous))
|
|
||||||
Gui::Application::Instance->getViewProvider(previous)->show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
|
|
||||||
#include "ViewProvider.h"
|
#include "ViewProvider.h"
|
||||||
|
|
||||||
namespace PartDesignGui {
|
namespace PartDesignGui {
|
||||||
|
|
||||||
/// A common base for sketch based, dressup and other solid parameters dialogs
|
/// A common base for sketch based, dressup and other solid parameters dialogs
|
||||||
class TaskDlgFeatureParameters : public Gui::TaskView::TaskDialog
|
class TaskDlgFeatureParameters : public Gui::TaskView::TaskDialog
|
||||||
|
@ -45,8 +45,10 @@ public:
|
||||||
/// is called by the framework if the dialog is rejected (Cancel)
|
/// is called by the framework if the dialog is rejected (Cancel)
|
||||||
virtual bool reject();
|
virtual bool reject();
|
||||||
|
|
||||||
|
/// Returns the view provider dialog is runed for
|
||||||
|
PartDesignGui::ViewProvider *viewProvider() const { return vp; }
|
||||||
protected:
|
protected:
|
||||||
PartDesignGui::ViewProvider *vp;
|
PartDesignGui::ViewProvider *vp;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace PartDesignGui
|
} //namespace PartDesignGui
|
||||||
|
|
|
@ -139,6 +139,7 @@ TaskPadParameters::TaskPadParameters(ViewProviderPad *PadView, QWidget *parent,
|
||||||
updateUI(index);
|
updateUI(index);
|
||||||
|
|
||||||
// if it is a newly created object use the last value of the history
|
// 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){
|
if(newObj){
|
||||||
ui->lengthEdit->setToLastUsedValue();
|
ui->lengthEdit->setToLastUsedValue();
|
||||||
ui->lengthEdit->selectNumber();
|
ui->lengthEdit->selectNumber();
|
||||||
|
|
|
@ -91,7 +91,7 @@ class TaskDlgPadParameters : public TaskDlgSketchBasedParameters
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
TaskDlgPadParameters(ViewProviderPad *PadView,bool newObj=false);
|
TaskDlgPadParameters(ViewProviderPad *PadView, bool newObj=false);
|
||||||
~TaskDlgPadParameters();
|
~TaskDlgPadParameters();
|
||||||
|
|
||||||
ViewProviderPad* getPadView() const
|
ViewProviderPad* getPadView() const
|
||||||
|
|
|
@ -130,6 +130,7 @@ TaskPocketParameters::TaskPocketParameters(ViewProviderPocket *PocketView,QWidge
|
||||||
updateUI(index);
|
updateUI(index);
|
||||||
|
|
||||||
// if it is a newly created object use the last value of the history
|
// 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){
|
if(newObj){
|
||||||
ui->lengthEdit->setToLastUsedValue();
|
ui->lengthEdit->setToLastUsedValue();
|
||||||
ui->lengthEdit->selectNumber();
|
ui->lengthEdit->selectNumber();
|
||||||
|
|
|
@ -24,26 +24,28 @@
|
||||||
#include "PreCompiled.h"
|
#include "PreCompiled.h"
|
||||||
|
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
|
# include <QMessageBox>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ViewProvider.h"
|
|
||||||
#include "Workbench.h"
|
|
||||||
#include <Mod/PartDesign/App/Body.h>
|
|
||||||
#include <Mod/Part/App/PropertyTopoShape.h>
|
|
||||||
#include <Gui/Command.h>
|
#include <Gui/Command.h>
|
||||||
#include <Gui/MDIView.h>
|
#include <Gui/MDIView.h>
|
||||||
#include <Gui/Control.h>
|
#include <Gui/Control.h>
|
||||||
#include <Gui/Application.h>
|
#include <Gui/Application.h>
|
||||||
#include <Base/Exception.h>
|
#include <Base/Exception.h>
|
||||||
|
#include <Mod/PartDesign/App/Body.h>
|
||||||
|
#include <Mod/PartDesign/App/Feature.h>
|
||||||
|
|
||||||
|
#include "TaskFeatureParameters.h"
|
||||||
|
|
||||||
|
#include "ViewProvider.h"
|
||||||
|
|
||||||
using namespace PartDesignGui;
|
using namespace PartDesignGui;
|
||||||
|
|
||||||
PROPERTY_SOURCE(PartDesignGui::ViewProvider,PartGui::ViewProviderPart)
|
PROPERTY_SOURCE(PartDesignGui::ViewProvider, PartGui::ViewProviderPart)
|
||||||
|
|
||||||
ViewProvider::ViewProvider()
|
ViewProvider::ViewProvider()
|
||||||
|
:oldWb(""), oldTip(NULL)
|
||||||
{
|
{
|
||||||
oldWb = "";
|
|
||||||
oldTip = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewProvider::~ViewProvider()
|
ViewProvider::~ViewProvider()
|
||||||
|
@ -51,12 +53,13 @@ ViewProvider::~ViewProvider()
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProvider::doubleClicked(void)
|
bool ViewProvider::doubleClicked(void)
|
||||||
{
|
{
|
||||||
PartDesign::Body* activeBody = Gui::Application::Instance->activeView()->getActiveObject<PartDesign::Body*>(PDBODYKEY);
|
PartDesign::Body* body = PartDesign::Body::findBodyOf(getObject());
|
||||||
if (activeBody != NULL) {
|
|
||||||
|
if (body != NULL) {
|
||||||
// Drop into insert mode so that the user doesn't see all the geometry that comes later in the tree
|
// 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
|
// 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)
|
if (oldTip != this->pcObject)
|
||||||
Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')");
|
Gui::Command::doCommand(Gui::Command::Gui,"FreeCADGui.runCommand('PartDesign_MoveTip')");
|
||||||
else
|
else
|
||||||
|
@ -69,7 +72,8 @@ bool ViewProvider::doubleClicked(void)
|
||||||
std::string Msg("Edit ");
|
std::string Msg("Edit ");
|
||||||
Msg += this->pcObject->Label.getValue();
|
Msg += this->pcObject->Label.getValue();
|
||||||
Gui::Command::openCommand(Msg.c_str());
|
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&) {
|
catch (const Base::Exception&) {
|
||||||
Gui::Command::abortCommand();
|
Gui::Command::abortCommand();
|
||||||
|
@ -77,6 +81,56 @@ bool ViewProvider::doubleClicked(void)
|
||||||
return true;
|
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<TaskDlgFeatureParameters *>(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)
|
void ViewProvider::unsetEdit(int ModNum)
|
||||||
{
|
{
|
||||||
// return to the WB we were in before editing the PartDesign feature
|
// 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)
|
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) {
|
strcmp(prop->getName(),"AddSubShape") == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -112,19 +167,32 @@ void ViewProvider::updateData(const App::Property* prop)
|
||||||
|
|
||||||
bool ViewProvider::onDelete(const std::vector<std::string> &)
|
bool ViewProvider::onDelete(const std::vector<std::string> &)
|
||||||
{
|
{
|
||||||
// Body feature housekeeping
|
App::DocumentObject* previous;
|
||||||
Part::BodyBase* body = Part::BodyBase::findBodyOf(getObject());
|
PartDesign::Feature* feature = static_cast<PartDesign::Feature*>(getObject());
|
||||||
if (body != NULL) {
|
|
||||||
body->removeFeature(getObject());
|
try {
|
||||||
// Make the new Tip and the previous solid feature visible again
|
previous = feature->getBaseObject();
|
||||||
App::DocumentObject* tip = body->Tip.getValue();
|
} catch (const Base::Exception &ex) {
|
||||||
App::DocumentObject* prev = body->getPrevSolidFeature();
|
previous = 0;
|
||||||
if (tip != NULL) {
|
|
||||||
Gui::Application::Instance->getViewProvider(tip)->show();
|
|
||||||
if ((tip != prev) && (prev != NULL))
|
|
||||||
Gui::Application::Instance->getViewProvider(prev)->show();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,11 @@
|
||||||
|
|
||||||
namespace PartDesignGui {
|
namespace PartDesignGui {
|
||||||
|
|
||||||
|
class TaskDlgFeatureParameters;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A common base class for all part design features view providers
|
||||||
|
*/
|
||||||
class PartDesignGuiExport ViewProvider : public PartGui::ViewProviderPart {
|
class PartDesignGuiExport ViewProvider : public PartGui::ViewProviderPart {
|
||||||
typedef PartGui::ViewProviderPart inherited;
|
typedef PartGui::ViewProviderPart inherited;
|
||||||
PROPERTY_HEADER(PartDesignGui::ViewProvider);
|
PROPERTY_HEADER(PartDesignGui::ViewProvider);
|
||||||
|
@ -43,10 +48,15 @@ public:
|
||||||
void updateData(const App::Property*);
|
void updateData(const App::Property*);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
virtual bool setEdit(int ModNum);
|
||||||
virtual void unsetEdit(int ModNum);
|
virtual void unsetEdit(int ModNum);
|
||||||
|
|
||||||
virtual bool onDelete(const std::vector<std::string> &);
|
virtual bool onDelete(const std::vector<std::string> &);
|
||||||
|
|
||||||
|
/// 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;
|
std::string oldWb;
|
||||||
App::DocumentObject* oldTip;
|
App::DocumentObject* oldTip;
|
||||||
};
|
};
|
||||||
|
|
|
@ -26,42 +26,26 @@
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
# include <QAction>
|
# include <QAction>
|
||||||
# include <QMenu>
|
# include <QMenu>
|
||||||
# include <QMessageBox>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ViewProviderPad.h"
|
|
||||||
#include "TaskPadParameters.h"
|
#include "TaskPadParameters.h"
|
||||||
#include "Workbench.h"
|
|
||||||
#include <Mod/PartDesign/App/Body.h>
|
#include "ViewProviderPad.h"
|
||||||
#include <Mod/PartDesign/App/FeaturePad.h>
|
|
||||||
#include <Mod/Sketcher/App/SketchObject.h>
|
|
||||||
#include <Gui/Control.h>
|
|
||||||
#include <Gui/Command.h>
|
|
||||||
#include <Gui/Application.h>
|
|
||||||
|
|
||||||
using namespace PartDesignGui;
|
using namespace PartDesignGui;
|
||||||
|
|
||||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderPad,PartDesignGui::ViewProvider)
|
PROPERTY_SOURCE(PartDesignGui::ViewProviderPad,PartDesignGui::ViewProviderSketchBased)
|
||||||
|
|
||||||
ViewProviderPad::ViewProviderPad()
|
ViewProviderPad::ViewProviderPad()
|
||||||
{
|
{
|
||||||
sPixmap = "Tree_PartDesign_Pad.svg";
|
sPixmap = "Tree_PartDesign_Pad.svg";
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewProviderPad::~ViewProviderPad()
|
ViewProviderPad::~ViewProviderPad()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<App::DocumentObject*> ViewProviderPad::claimChildren(void)const
|
// TODO This methode could also be unified with other features (2015-07-26, Fat-Zer)
|
||||||
{
|
|
||||||
std::vector<App::DocumentObject*> temp;
|
|
||||||
App::DocumentObject* sketch = static_cast<PartDesign::Pad*>(getObject())->Sketch.getValue();
|
|
||||||
if (sketch != NULL)
|
|
||||||
temp.push_back(sketch);
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewProviderPad::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
void ViewProviderPad::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||||
{
|
{
|
||||||
QAction* act;
|
QAction* act;
|
||||||
|
@ -70,61 +54,9 @@ void ViewProviderPad::setupContextMenu(QMenu* menu, QObject* receiver, const cha
|
||||||
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProviderPad::setEdit(int ModNum)
|
TaskDlgFeatureParameters *ViewProviderPad::getEditDialog()
|
||||||
{
|
{
|
||||||
if (ModNum == ViewProvider::Default || ModNum == 1 ) {
|
// TODO fix setting values from the history: now it doesn't work neither in
|
||||||
// When double-clicking on the item for this pad the
|
// the master and in the migrated branch (2015-07-26, Fat-Zer)
|
||||||
// object unsets and sets its edit mode without closing
|
return new TaskDlgPadParameters( this );
|
||||||
// the task panel
|
|
||||||
Gui::TaskView::TaskDialog *dlg = Gui::Control().activeDialog();
|
|
||||||
TaskDlgPadParameters *padDlg = qobject_cast<TaskDlgPadParameters *>(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProviderPad::onDelete(const std::vector<std::string> &s)
|
|
||||||
{
|
|
||||||
PartDesign::Pad* pcPad = static_cast<PartDesign::Pad*>(getObject());
|
|
||||||
|
|
||||||
// get the Sketch
|
|
||||||
Sketcher::SketchObject *pcSketch = 0;
|
|
||||||
if (pcPad->Sketch.getValue())
|
|
||||||
pcSketch = static_cast<Sketcher::SketchObject*>(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -24,11 +24,11 @@
|
||||||
#ifndef PARTGUI_ViewProviderPad_H
|
#ifndef PARTGUI_ViewProviderPad_H
|
||||||
#define PARTGUI_ViewProviderPad_H
|
#define PARTGUI_ViewProviderPad_H
|
||||||
|
|
||||||
#include "ViewProvider.h"
|
#include "ViewProviderSketchBased.h"
|
||||||
|
|
||||||
namespace PartDesignGui {
|
namespace PartDesignGui {
|
||||||
|
|
||||||
class PartDesignGuiExport ViewProviderPad : public ViewProvider
|
class PartDesignGuiExport ViewProviderPad : public ViewProviderSketchBased
|
||||||
{
|
{
|
||||||
PROPERTY_HEADER(PartDesignGui::ViewProviderPad);
|
PROPERTY_HEADER(PartDesignGui::ViewProviderPad);
|
||||||
|
|
||||||
|
@ -38,14 +38,11 @@ public:
|
||||||
/// destructor
|
/// destructor
|
||||||
virtual ~ViewProviderPad();
|
virtual ~ViewProviderPad();
|
||||||
|
|
||||||
/// grouping handling
|
|
||||||
std::vector<App::DocumentObject*> claimChildren(void)const;
|
|
||||||
void setupContextMenu(QMenu*, QObject*, const char*);
|
void setupContextMenu(QMenu*, QObject*, const char*);
|
||||||
|
|
||||||
virtual bool onDelete(const std::vector<std::string> &);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool setEdit(int ModNum);
|
/// Returns a newly created TaskDlgPadParameters
|
||||||
|
virtual TaskDlgFeatureParameters *getEditDialog();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,40 +26,26 @@
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
# include <QAction>
|
# include <QAction>
|
||||||
# include <QMenu>
|
# include <QMenu>
|
||||||
# include <QMessageBox>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ViewProviderPocket.h"
|
|
||||||
#include "TaskPocketParameters.h"
|
#include "TaskPocketParameters.h"
|
||||||
#include <Mod/PartDesign/App/FeaturePocket.h>
|
|
||||||
#include <Mod/Sketcher/App/SketchObject.h>
|
#include "ViewProviderPocket.h"
|
||||||
#include <Gui/Control.h>
|
|
||||||
#include <Gui/Command.h>
|
|
||||||
#include <Gui/Application.h>
|
|
||||||
|
|
||||||
|
|
||||||
using namespace PartDesignGui;
|
using namespace PartDesignGui;
|
||||||
|
|
||||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderPocket,PartDesignGui::ViewProvider)
|
PROPERTY_SOURCE(PartDesignGui::ViewProviderPocket,PartDesignGui::ViewProviderSketchBased)
|
||||||
|
|
||||||
ViewProviderPocket::ViewProviderPocket()
|
ViewProviderPocket::ViewProviderPocket()
|
||||||
{
|
{
|
||||||
sPixmap = "PartDesign_Pocket.svg";
|
sPixmap = "PartDesign_Pocket.svg";
|
||||||
}
|
}
|
||||||
|
|
||||||
ViewProviderPocket::~ViewProviderPocket()
|
ViewProviderPocket::~ViewProviderPocket()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<App::DocumentObject*> ViewProviderPocket::claimChildren(void)const
|
|
||||||
{
|
|
||||||
std::vector<App::DocumentObject*> temp;
|
|
||||||
App::DocumentObject* sketch = static_cast<PartDesign::Pocket*>(getObject())->Sketch.getValue();
|
|
||||||
if (sketch != NULL)
|
|
||||||
temp.push_back(sketch);
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewProviderPocket::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
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);
|
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProviderPocket::setEdit(int ModNum)
|
|
||||||
|
TaskDlgFeatureParameters *ViewProviderPocket::getEditDialog()
|
||||||
{
|
{
|
||||||
if (ModNum == ViewProvider::Default ) {
|
return new TaskDlgPocketParameters( this );
|
||||||
// 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<TaskDlgPocketParameters *>(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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProviderPocket::onDelete(const std::vector<std::string> &s)
|
|
||||||
{
|
|
||||||
// get the Sketch
|
|
||||||
PartDesign::Pocket* pcPocket = static_cast<PartDesign::Pocket*>(getObject());
|
|
||||||
Sketcher::SketchObject *pcSketch = 0;
|
|
||||||
if (pcPocket->Sketch.getValue())
|
|
||||||
pcSketch = static_cast<Sketcher::SketchObject*>(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);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,12 +24,12 @@
|
||||||
#ifndef PARTGUI_ViewProviderPocket_H
|
#ifndef PARTGUI_ViewProviderPocket_H
|
||||||
#define PARTGUI_ViewProviderPocket_H
|
#define PARTGUI_ViewProviderPocket_H
|
||||||
|
|
||||||
#include "ViewProvider.h"
|
#include "ViewProviderSketchBased.h"
|
||||||
|
|
||||||
|
|
||||||
namespace PartDesignGui {
|
namespace PartDesignGui {
|
||||||
|
|
||||||
class PartDesignGuiExport ViewProviderPocket : public ViewProvider
|
class PartDesignGuiExport ViewProviderPocket : public ViewProviderSketchBased
|
||||||
{
|
{
|
||||||
PROPERTY_HEADER(PartDesignGui::ViewProviderPocket);
|
PROPERTY_HEADER(PartDesignGui::ViewProviderPocket);
|
||||||
|
|
||||||
|
@ -39,14 +39,11 @@ public:
|
||||||
/// destructor
|
/// destructor
|
||||||
virtual ~ViewProviderPocket();
|
virtual ~ViewProviderPocket();
|
||||||
|
|
||||||
/// grouping handling
|
|
||||||
std::vector<App::DocumentObject*> claimChildren(void)const;
|
|
||||||
void setupContextMenu(QMenu*, QObject*, const char*);
|
void setupContextMenu(QMenu*, QObject*, const char*);
|
||||||
|
|
||||||
virtual bool onDelete(const std::vector<std::string> &);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual bool setEdit(int ModNum);
|
/// Returns a newly created TaskDlgPocketParameters
|
||||||
|
virtual TaskDlgFeatureParameters *getEditDialog();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
74
src/Mod/PartDesign/Gui/ViewProviderSketchBased.cpp
Normal file
74
src/Mod/PartDesign/Gui/ViewProviderSketchBased.cpp
Normal file
|
@ -0,0 +1,74 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* 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 <Mod/Sketcher/App/SketchObject.h>
|
||||||
|
#include <Mod/PartDesign/App/FeatureSketchBased.h>
|
||||||
|
|
||||||
|
#include "ViewProviderSketchBased.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace PartDesignGui;
|
||||||
|
|
||||||
|
PROPERTY_SOURCE(PartDesignGui::ViewProviderSketchBased, PartDesignGui::ViewProvider)
|
||||||
|
|
||||||
|
|
||||||
|
ViewProviderSketchBased::ViewProviderSketchBased()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ViewProviderSketchBased::~ViewProviderSketchBased()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<App::DocumentObject*> ViewProviderSketchBased::claimChildren(void) const {
|
||||||
|
std::vector<App::DocumentObject*> temp;
|
||||||
|
App::DocumentObject* sketch = static_cast<PartDesign::SketchBased*>(getObject())->Sketch.getValue();
|
||||||
|
if (sketch != NULL)
|
||||||
|
temp.push_back(sketch);
|
||||||
|
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool ViewProviderSketchBased::onDelete(const std::vector<std::string> &s) {
|
||||||
|
PartDesign::SketchBased* feature = static_cast<PartDesign::SketchBased*>(getObject());
|
||||||
|
|
||||||
|
// get the Sketch
|
||||||
|
Sketcher::SketchObject *pcSketch = 0;
|
||||||
|
if (feature->Sketch.getValue())
|
||||||
|
pcSketch = static_cast<Sketcher::SketchObject*>(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);
|
||||||
|
}
|
51
src/Mod/PartDesign/Gui/ViewProviderSketchBased.h
Normal file
51
src/Mod/PartDesign/Gui/ViewProviderSketchBased.h
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* 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 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<App::DocumentObject*> claimChildren(void)const;
|
||||||
|
|
||||||
|
virtual bool onDelete(const std::vector<std::string> &);
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* PartDesignGui */
|
||||||
|
|
||||||
|
#endif /* end of include guard: VIEWPROVIDERSKETCHBASED_H_QKP3UG9A */
|
Loading…
Reference in New Issue
Block a user