+ rework edit modes

git-svn-id: https://free-cad.svn.sourceforge.net/svnroot/free-cad/trunk@5102 e8eeb9e2-ec13-0410-a4a9-efa5cf37419d
This commit is contained in:
wmayer 2011-11-08 21:15:49 +00:00
parent c152e988be
commit c7985e5c06
15 changed files with 155 additions and 131 deletions

View File

@ -181,10 +181,18 @@ public:
* you can handle most of the events in the viewer by yourself
*/
//@{
protected:
enum EditMode {Default = 0,
Transform = 1
Transform,
Cutting,
Color,
Mirror,
Fillet,
Sketch,
Pad,
Pocket,
Revolve
};
protected:
/// is called by the document when the provider goes in edit mode
virtual bool setEdit(int ModNum);
/// is called when you loose the edit mode

View File

@ -369,8 +369,7 @@ bool ViewProviderAnnotationLabel::doubleClicked(void)
void ViewProviderAnnotationLabel::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
QAction* act = menu->addAction(QObject::tr("Move annotation"), receiver, member);
act->setData(QVariant((int)ViewProvider::Transform));
menu->addAction(QObject::tr("Move annotation"), receiver, member);
}
void ViewProviderAnnotationLabel::dragStartCallback(void *data, SoDragger *)

View File

@ -197,7 +197,7 @@ void ViewProviderGeometryObject::updateData(const App::Property* prop)
bool ViewProviderGeometryObject::doubleClicked(void)
{
Gui::Application::Instance->activeDocument()->setEdit(this, (int)ViewProvider::Transform);
Gui::Application::Instance->activeDocument()->setEdit(this, (int)ViewProvider::Default);
return true;
}

View File

@ -109,7 +109,6 @@ void ViewProviderDrawingPage::setupContextMenu(QMenu* menu, QObject* receiver, c
{
QAction* act;
act = menu->addAction(QObject::tr("Show drawing"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
}
bool ViewProviderDrawingPage::setEdit(int ModNum)

View File

@ -484,11 +484,15 @@ std::vector<std::string> ViewProviderMesh::getDisplayModes(void) const
bool ViewProviderMesh::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Transform)
return ViewProviderGeometryObject::setEdit(ModNum);
return true;
}
void ViewProviderMesh::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Transform)
ViewProviderGeometryObject::unsetEdit(ModNum);
}
bool ViewProviderMesh::createToolMesh(const std::vector<SbVec2f>& rclPoly, const SbViewVolume& vol,

View File

@ -125,8 +125,7 @@ public:
/** @name Editing */
//@{
bool doubleClicked(void){return false;}
void setupContextMenu(QMenu*, QObject*, const char*) {}
bool doubleClicked(void){ return false; }
void selectComponent(unsigned long facet);
void deselectComponent(unsigned long facet);
void selectFacet(unsigned long facet);

View File

@ -675,11 +675,15 @@ void TaskFilletEdges::clicked(int)
bool TaskFilletEdges::accept()
{
return widget->accept();
bool ok = widget->accept();
if (ok)
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
return ok;
}
bool TaskFilletEdges::reject()
{
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().resetEdit()");
return true;
}

View File

@ -508,12 +508,12 @@ void ViewProviderPartExt::setupContextMenu(QMenu* menu, QObject* receiver, const
{
Gui::ViewProviderGeometryObject::setupContextMenu(menu, receiver, member);
QAction* act = menu->addAction(QObject::tr("Set colors..."), receiver, member);
act->setData(QVariant(getClassTypeId().getKey()));
act->setData(QVariant((int)ViewProvider::Color));
}
bool ViewProviderPartExt::setEdit(int ModNum)
{
if (ModNum == (int)getClassTypeId().getKey()) {
if (ModNum == ViewProvider::Color) {
// When double-clicking on the item for this pad the
// object unsets and sets its edit mode without closing
// the task panel
@ -534,7 +534,7 @@ bool ViewProviderPartExt::setEdit(int ModNum)
void ViewProviderPartExt::unsetEdit(int ModNum)
{
if (ModNum == (int)getClassTypeId().getKey()) {
if (ModNum == ViewProvider::Color) {
}
else {
Gui::ViewProviderGeometryObject::unsetEdit(ModNum);

View File

@ -65,14 +65,13 @@ void ViewProviderMirror::setupContextMenu(QMenu* menu, QObject* receiver, const
{
QAction* act;
act = menu->addAction(QObject::tr("Edit mirror plane"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
act = menu->addAction(QObject::tr("Transform"), receiver, member);
act->setData(QVariant((int)ViewProvider::Transform));
act->setData(QVariant((int)ViewProvider::Mirror));
ViewProviderPart::setupContextMenu(menu, receiver, member);
}
bool ViewProviderMirror::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Mirror) {
// get the properties from the mirror feature
Part::Mirroring* mf = static_cast<Part::Mirroring*>(getObject());
Base::BoundBox3d bbox = mf->Shape.getBoundingBox();
@ -135,7 +134,7 @@ bool ViewProviderMirror::setEdit(int ModNum)
void ViewProviderMirror::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Mirror) {
SoCenterballManip* manip = static_cast<SoCenterballManip *>(pcEditNode->getChild(0));
SbVec3f move = manip->translation.getValue();
@ -206,19 +205,18 @@ void ViewProviderFillet::setupContextMenu(QMenu* menu, QObject* receiver, const
{
QAction* act;
act = menu->addAction(QObject::tr("Edit fillet edges"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
act = menu->addAction(QObject::tr("Transform"), receiver, member);
act->setData(QVariant((int)ViewProvider::Transform));
act->setData(QVariant((int)ViewProvider::Fillet));
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
}
bool ViewProviderFillet::setEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Fillet) {
if (Gui::Control().activeDialog())
return false;
Part::Fillet* fillet = static_cast<Part::Fillet*>(getObject());
Gui::Control().showDialog(new PartGui::TaskFilletEdges(fillet));
return false;
return true;
}
else {
ViewProviderPart::setEdit(ModNum);
@ -228,7 +226,8 @@ bool ViewProviderFillet::setEdit(int ModNum)
void ViewProviderFillet::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Fillet) {
Gui::Control().closeDialog();
}
else {
ViewProviderPart::unsetEdit(ModNum);

View File

@ -146,7 +146,7 @@ void CmdPartDesignPad::activated(int iMsg)
if (support)
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
}
doCommand(Gui,"Gui.activeDocument().setEdit('%s',2)",FeatName.c_str());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
//commitCommand();
adjustCameraPosition();
@ -227,7 +227,7 @@ void CmdPartDesignPocket::activated(int iMsg)
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",sketch->getNameInDocument());
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
}
doCommand(Gui,"Gui.activeDocument().setEdit('%s',2)",FeatName.c_str());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument());
copyVisual(FeatName.c_str(), "LineColor", support->getNameInDocument());
@ -301,7 +301,7 @@ void CmdPartDesignRevolution::activated(int iMsg)
if (support)
doCommand(Gui,"Gui.activeDocument().hide(\"%s\")",support->getNameInDocument());
}
doCommand(Gui,"Gui.activeDocument().setEdit('%s',2)",FeatName.c_str());
doCommand(Gui,"Gui.activeDocument().setEdit('%s')",FeatName.c_str());
if (support) {
copyVisual(FeatName.c_str(), "ShapeColor", support->getNameInDocument());

View File

@ -44,7 +44,7 @@ ViewProvider::~ViewProvider()
bool ViewProvider::doubleClicked(void)
{
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s',2)",this->pcObject->getNameInDocument());
Gui::Command::doCommand(Gui::Command::Gui,"Gui.activeDocument().setEdit('%s',0)",this->pcObject->getNameInDocument());
return true;
}

View File

@ -58,50 +58,54 @@ void ViewProviderPad::setupContextMenu(QMenu* menu, QObject* receiver, const cha
{
QAction* act;
act = menu->addAction(QObject::tr("Edit pad"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
act = menu->addAction(QObject::tr("Transform"), receiver, member);
act->setData(QVariant((int)ViewProvider::Transform));
act->setData(QVariant((int)ViewProvider::Pad));
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
}
bool ViewProviderPad::setEdit(int ModNum)
{
// 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();
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().closeDialog();
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Pad) {
// 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();
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().closeDialog();
else
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
if (ModNum == 1)
Gui::Command::openCommand("Change pad parameters");
// start the edit dialog
if (padDlg)
Gui::Control().showDialog(padDlg);
else
return false;
Gui::Control().showDialog(new TaskDlgPadParameters(this));
return true;
}
else {
return ViewProviderPart::setEdit(ModNum);
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
if(ModNum == 1)
Gui::Command::openCommand("Change pad parameters");
// start the edit dialog
if (padDlg)
Gui::Control().showDialog(padDlg);
else
Gui::Control().showDialog(new TaskDlgPadParameters(this));
return true;
}
void ViewProviderPad::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Pad) {
// and update the pad
//getSketchObject()->getDocument()->recompute();

View File

@ -54,54 +54,59 @@ std::vector<App::DocumentObject*> ViewProviderPocket::claimChildren(void)const
return temp;
}
void ViewProviderPocket::setupContextMenu(QMenu* menu, QObject* receiver, const char* member)
{
QAction* act;
act = menu->addAction(QObject::tr("Edit pocket"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
act = menu->addAction(QObject::tr("Transform"), receiver, member);
act->setData(QVariant((int)ViewProvider::Transform));
act->setData(QVariant((int)ViewProvider::Pocket));
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
}
bool ViewProviderPocket::setEdit(int ModNum)
{
// 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().closeDialog();
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Pocket) {
// 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().closeDialog();
else
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
if(ModNum == 1)
Gui::Command::openCommand("Change pocket parameters");
// start the edit dialog
if (padDlg)
Gui::Control().showDialog(padDlg);
else
return false;
Gui::Control().showDialog(new TaskDlgPocketParameters(this));
return true;
}
else {
return PartGui::ViewProviderPart::setEdit(ModNum);
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
if(ModNum == 1)
Gui::Command::openCommand("Change pocket parameters");
// start the edit dialog
if (padDlg)
Gui::Control().showDialog(padDlg);
else
Gui::Control().showDialog(new TaskDlgPocketParameters(this));
return true;
}
void ViewProviderPocket::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Pocket) {
// and update the pad
//getSketchObject()->getDocument()->recompute();

View File

@ -59,50 +59,54 @@ void ViewProviderRevolution::setupContextMenu(QMenu* menu, QObject* receiver, co
{
QAction* act;
act = menu->addAction(QObject::tr("Edit revolution"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
act = menu->addAction(QObject::tr("Transform"), receiver, member);
act->setData(QVariant((int)ViewProvider::Transform));
act->setData(QVariant((int)ViewProvider::Revolve));
PartGui::ViewProviderPart::setupContextMenu(menu, receiver, member);
}
bool ViewProviderRevolution::setEdit(int ModNum)
{
// 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().closeDialog();
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Revolve) {
// 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().closeDialog();
else
return false;
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
if (ModNum == 1)
Gui::Command::openCommand("Change revolution parameters");
// start the edit dialog
if (padDlg)
Gui::Control().showDialog(padDlg);
else
return false;
Gui::Control().showDialog(new TaskDlgRevolutionParameters(this));
return true;
}
else {
return PartGui::ViewProviderPart::setEdit(ModNum);
}
// clear the selection (convenience)
Gui::Selection().clearSelection();
if(ModNum == 1)
Gui::Command::openCommand("Change revolution parameters");
// start the edit dialog
if (padDlg)
Gui::Control().showDialog(padDlg);
else
Gui::Control().showDialog(new TaskDlgRevolutionParameters(this));
return true;
}
void ViewProviderRevolution::unsetEdit(int ModNum)
{
if (ModNum == ViewProvider::Default) {
if (ModNum == ViewProvider::Default || ModNum == ViewProvider::Revolve) {
// and update the pad
//getSketchObject()->getDocument()->recompute();

View File

@ -2573,8 +2573,7 @@ void ViewProviderSketch::attach(App::DocumentObject *pcFeat)
void ViewProviderSketch::setupContextMenu(QMenu *menu, QObject *receiver, const char *member)
{
QAction *act = menu->addAction(QObject::tr("Edit sketch"), receiver, member);
act->setData(QVariant((int)ViewProvider::Default));
menu->addAction(QObject::tr("Edit sketch"), receiver, member);
}
bool ViewProviderSketch::setEdit(int ModNum)