PartDesign/Gui: share code for revolution and groove view providers
This commit is contained in:
parent
5ee0cea467
commit
013381ccb6
|
@ -26,21 +26,15 @@
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
# include <QAction>
|
# include <QAction>
|
||||||
# include <QMenu>
|
# include <QMenu>
|
||||||
# include <QMessageBox>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Mod/PartDesign/App/FeatureGroove.h>
|
#include "TaskRevolutionParameters.h"
|
||||||
#include <Mod/Sketcher/App/SketchObject.h>
|
|
||||||
#include <Gui/Control.h>
|
|
||||||
#include <Gui/Command.h>
|
|
||||||
#include <Gui/Application.h>
|
|
||||||
|
|
||||||
#include "ViewProviderGroove.h"
|
#include "ViewProviderGroove.h"
|
||||||
#include "TaskRevolutionParameters.h"
|
|
||||||
|
|
||||||
using namespace PartDesignGui;
|
using namespace PartDesignGui;
|
||||||
|
|
||||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderGroove,PartDesignGui::ViewProvider)
|
PROPERTY_SOURCE(PartDesignGui::ViewProviderGroove,PartDesignGui::ViewProviderSketchBased)
|
||||||
|
|
||||||
ViewProviderGroove::ViewProviderGroove()
|
ViewProviderGroove::ViewProviderGroove()
|
||||||
{
|
{
|
||||||
|
@ -51,89 +45,15 @@ ViewProviderGroove::~ViewProviderGroove()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<App::DocumentObject*> ViewProviderGroove::claimChildren(void)const
|
|
||||||
{
|
|
||||||
std::vector<App::DocumentObject*> temp;
|
|
||||||
App::DocumentObject* sketch = static_cast<PartDesign::Groove*>(getObject())->Sketch.getValue();
|
|
||||||
if (sketch != NULL)
|
|
||||||
temp.push_back(sketch);
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewProviderGroove::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
void ViewProviderGroove::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||||
{
|
{
|
||||||
QAction* act;
|
QAction* act;
|
||||||
act = menu->addAction(QObject::tr("Edit Groove"), receiver, member);
|
act = menu->addAction(QObject::tr("Edit groove"), receiver, member);
|
||||||
act->setData(QVariant((int)ViewProvider::Default));
|
act->setData(QVariant((int)ViewProvider::Default));
|
||||||
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProviderGroove::setEdit(int ModNum)
|
TaskDlgFeatureParameters *ViewProviderGroove::getEditDialog()
|
||||||
{
|
{
|
||||||
if (ModNum == ViewProvider::Default ) {
|
return new TaskDlgRevolutionParameters( this );
|
||||||
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(getObject());
|
|
||||||
if (pcGroove->getSketchAxisCount() < 0) {
|
|
||||||
QMessageBox msgBox;
|
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
|
||||||
msgBox.setWindowTitle(QObject::tr("Lost link to base sketch"));
|
|
||||||
msgBox.setText(QObject::tr("The object can't be edited because the link to the the base sketch is lost."));
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
||||||
msgBox.exec();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 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();
|
|
||||||
TaskDlgRevolutionParameters *padDlg = qobject_cast<TaskDlgRevolutionParameters *>(dlg);
|
|
||||||
if (padDlg && padDlg->getRevolutionView() != 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 TaskDlgRevolutionParameters(this));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return PartGui::ViewProviderPart::setEdit(ModNum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProviderGroove::onDelete(const std::vector<std::string> &s)
|
|
||||||
{
|
|
||||||
// get the Sketch
|
|
||||||
PartDesign::Groove* pcGroove = static_cast<PartDesign::Groove*>(getObject());
|
|
||||||
Sketcher::SketchObject *pcSketch = 0;
|
|
||||||
if (pcGroove->Sketch.getValue())
|
|
||||||
pcSketch = static_cast<Sketcher::SketchObject*>(pcGroove->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_ViewProviderGroove_H
|
#ifndef PARTGUI_ViewProviderGroove_H
|
||||||
#define PARTGUI_ViewProviderGroove_H
|
#define PARTGUI_ViewProviderGroove_H
|
||||||
|
|
||||||
#include "ViewProvider.h"
|
#include "ViewProviderSketchBased.h"
|
||||||
|
|
||||||
|
|
||||||
namespace PartDesignGui {
|
namespace PartDesignGui {
|
||||||
|
|
||||||
class PartDesignGuiExport ViewProviderGroove : public ViewProvider
|
class PartDesignGuiExport ViewProviderGroove : public ViewProviderSketchBased
|
||||||
{
|
{
|
||||||
PROPERTY_HEADER(PartDesignGui::ViewProviderGroove);
|
PROPERTY_HEADER(PartDesignGui::ViewProviderGroove);
|
||||||
|
|
||||||
|
@ -39,15 +39,14 @@ public:
|
||||||
/// destructor
|
/// destructor
|
||||||
virtual ~ViewProviderGroove();
|
virtual ~ViewProviderGroove();
|
||||||
|
|
||||||
/// 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 TaskDlgRevolutionParameters
|
||||||
|
* NOTE: as for now groove and revolution share the dialog implementation
|
||||||
|
*/
|
||||||
|
virtual TaskDlgFeatureParameters *getEditDialog();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,21 +26,15 @@
|
||||||
#ifndef _PreComp_
|
#ifndef _PreComp_
|
||||||
# include <QAction>
|
# include <QAction>
|
||||||
# include <QMenu>
|
# include <QMenu>
|
||||||
# include <QMessageBox>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <Mod/PartDesign/App/FeatureRevolution.h>
|
#include "TaskRevolutionParameters.h"
|
||||||
#include <Mod/Sketcher/App/SketchObject.h>
|
|
||||||
#include <Gui/Control.h>
|
|
||||||
#include <Gui/Command.h>
|
|
||||||
#include <Gui/Application.h>
|
|
||||||
|
|
||||||
#include "ViewProviderRevolution.h"
|
#include "ViewProviderRevolution.h"
|
||||||
#include "TaskRevolutionParameters.h"
|
|
||||||
|
|
||||||
using namespace PartDesignGui;
|
using namespace PartDesignGui;
|
||||||
|
|
||||||
PROPERTY_SOURCE(PartDesignGui::ViewProviderRevolution,PartDesignGui::ViewProvider)
|
PROPERTY_SOURCE(PartDesignGui::ViewProviderRevolution,PartDesignGui::ViewProviderSketchBased)
|
||||||
|
|
||||||
ViewProviderRevolution::ViewProviderRevolution()
|
ViewProviderRevolution::ViewProviderRevolution()
|
||||||
{
|
{
|
||||||
|
@ -51,16 +45,6 @@ ViewProviderRevolution::~ViewProviderRevolution()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<App::DocumentObject*> ViewProviderRevolution::claimChildren(void)const
|
|
||||||
{
|
|
||||||
std::vector<App::DocumentObject*> temp;
|
|
||||||
App::DocumentObject* sketch = static_cast<PartDesign::Revolution*>(getObject())->Sketch.getValue();
|
|
||||||
if (sketch != NULL)
|
|
||||||
temp.push_back(sketch);
|
|
||||||
|
|
||||||
return temp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ViewProviderRevolution::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
void ViewProviderRevolution::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
|
||||||
{
|
{
|
||||||
QAction* act;
|
QAction* act;
|
||||||
|
@ -69,71 +53,7 @@ void ViewProviderRevolution::setupContextMenu(QMenu* menu, QObject* receiver, co
|
||||||
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProviderRevolution::setEdit(int ModNum)
|
TaskDlgFeatureParameters *ViewProviderRevolution::getEditDialog()
|
||||||
{
|
{
|
||||||
if (ModNum == ViewProvider::Default ) {
|
return new TaskDlgRevolutionParameters( this );
|
||||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(getObject());
|
|
||||||
if (pcRevolution->getSketchAxisCount() < 0) {
|
|
||||||
QMessageBox msgBox;
|
|
||||||
msgBox.setIcon(QMessageBox::Critical);
|
|
||||||
msgBox.setWindowTitle(QObject::tr("Lost link to base sketch"));
|
|
||||||
msgBox.setText(QObject::tr("The object can't be edited because the link to the the base sketch is lost."));
|
|
||||||
msgBox.setStandardButtons(QMessageBox::Ok);
|
|
||||||
msgBox.exec();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
// 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();
|
|
||||||
TaskDlgRevolutionParameters *padDlg = qobject_cast<TaskDlgRevolutionParameters *>(dlg);
|
|
||||||
if (padDlg && padDlg->getRevolutionView() != 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 TaskDlgRevolutionParameters(this));
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return PartGui::ViewProviderPart::setEdit(ModNum);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ViewProviderRevolution::onDelete(const std::vector<std::string> &s)
|
|
||||||
{
|
|
||||||
// get the Sketch
|
|
||||||
PartDesign::Revolution* pcRevolution = static_cast<PartDesign::Revolution*>(getObject());
|
|
||||||
Sketcher::SketchObject *pcSketch = 0;
|
|
||||||
if (pcRevolution->Sketch.getValue())
|
|
||||||
pcSketch = static_cast<Sketcher::SketchObject*>(pcRevolution->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_ViewProviderRevolution_H
|
#ifndef PARTGUI_ViewProviderRevolution_H
|
||||||
#define PARTGUI_ViewProviderRevolution_H
|
#define PARTGUI_ViewProviderRevolution_H
|
||||||
|
|
||||||
#include "ViewProvider.h"
|
#include "ViewProviderSketchBased.h"
|
||||||
|
|
||||||
|
|
||||||
namespace PartDesignGui {
|
namespace PartDesignGui {
|
||||||
|
|
||||||
class PartDesignGuiExport ViewProviderRevolution : public ViewProvider
|
class PartDesignGuiExport ViewProviderRevolution : public ViewProviderSketchBased
|
||||||
{
|
{
|
||||||
PROPERTY_HEADER(PartDesignGui::ViewProviderRevolution);
|
PROPERTY_HEADER(PartDesignGui::ViewProviderRevolution);
|
||||||
|
|
||||||
|
@ -39,15 +39,12 @@ public:
|
||||||
/// destructor
|
/// destructor
|
||||||
virtual ~ViewProviderRevolution();
|
virtual ~ViewProviderRevolution();
|
||||||
|
|
||||||
/// 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 TaskDlgRevolutionParameters
|
||||||
|
virtual TaskDlgFeatureParameters *getEditDialog();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user