From db460cff8a1a3ca98b2d3f541fc3c38b1c0a9667 Mon Sep 17 00:00:00 2001 From: jriegel Date: Fri, 18 May 2012 14:43:35 +0200 Subject: [PATCH] auto WB switching for editing Sketches and new TaskWatcher --- src/Gui/TaskView/TaskWatcher.cpp | 1 + src/Mod/PartDesign/Gui/Workbench.cpp | 28 +++++++++++++-------- src/Mod/PartDesign/Gui/Workbench.h | 2 ++ src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 6 +++++ src/Mod/Sketcher/Gui/ViewProviderSketch.h | 1 + 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/src/Gui/TaskView/TaskWatcher.cpp b/src/Gui/TaskView/TaskWatcher.cpp index 4c6f99d63..4a7d14345 100644 --- a/src/Gui/TaskView/TaskWatcher.cpp +++ b/src/Gui/TaskView/TaskWatcher.cpp @@ -169,4 +169,5 @@ bool TaskWatcherCommandsEmptySelection::shouldShow() return (App::GetApplication().getActiveDocument() && Gui::Selection().size() == 0); } + #include "moc_TaskWatcher.cpp" diff --git a/src/Mod/PartDesign/Gui/Workbench.cpp b/src/Mod/PartDesign/Gui/Workbench.cpp index 0bc109904..ecc5a04d7 100644 --- a/src/Mod/PartDesign/Gui/Workbench.cpp +++ b/src/Mod/PartDesign/Gui/Workbench.cpp @@ -35,6 +35,8 @@ #include #include +#include + using namespace PartDesignGui; #if 0 // needed for Qt's lupdate utility @@ -44,6 +46,9 @@ using namespace PartDesignGui; qApp->translate("Gui::TaskView::TaskWatcherCommands", "Create Geometry"); #endif +extern PartDesign::Body *ActivePartObject; + + /// @namespace PartDesignGui @class Workbench TYPESYSTEM_SOURCE(PartDesignGui::Workbench, Gui::StdWorkbench) @@ -62,16 +67,7 @@ void Workbench::activated() std::vector Watcher; - //Watcher.push_back(new Gui::TaskView::TaskWatcherCommands( - // "FROM Robot SELECT TrajectoryObject COUNT 1" - // "FROM Robot SELECT RobotObject COUNT 1", - // RobotAndTrac, - // "Trajectory tools", - // "Robot_InsertWaypoint" - //)); - - //Watcher.push_back(new TaskWatcherRobot); - + const char* Edge[] = { "PartDesign_Fillet", "PartDesign_Chamfer", @@ -149,15 +145,27 @@ void Workbench::activated() addTaskWatcher(Watcher); Gui::Control().showTaskView(); + + // set the previous used active Body + if(oldActive != "") + Gui::Command::doCommand(Gui::Command::Doc,"PartDesignGui.setActivePart(App.activeDocument().%s)",oldActive.c_str()); + } void Workbench::deactivated() { + // remember the body for later activation + if(ActivePartObject) + oldActive = ActivePartObject->getNameInDocument(); + else + oldActive = ""; + // reset the active Body Gui::Command::doCommand(Gui::Command::Doc,"PartDesignGui.setActivePart(None)"); Gui::Workbench::deactivated(); removeTaskWatcher(); + } Gui::MenuItem* Workbench::setupMenuBar() const diff --git a/src/Mod/PartDesign/Gui/Workbench.h b/src/Mod/PartDesign/Gui/Workbench.h index 1d9272970..02220f870 100644 --- a/src/Mod/PartDesign/Gui/Workbench.h +++ b/src/Mod/PartDesign/Gui/Workbench.h @@ -48,6 +48,8 @@ protected: Gui::MenuItem* setupMenuBar() const; Gui::ToolBarItem* setupToolBars() const; Gui::ToolBarItem* setupCommandBars() const; + + std::string oldActive; }; } // namespace PartDesignGui diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 850397670..e6e6466f2 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -4156,6 +4156,9 @@ void ViewProviderSketch::setupContextMenu(QMenu *menu, QObject *receiver, const bool ViewProviderSketch::setEdit(int ModNum) { + // always change to sketcher WB, remember where we come from + oldWb = Gui::Command::assureWorkbench("SketcherWorkbench"); + // When double-clicking on the item for this sketch the // object unsets and sets its edit mode without closing // the task panel @@ -4580,6 +4583,9 @@ void ViewProviderSketch::unsetEdit(int ModNum) // when pressing ESC make sure to close the dialog Gui::Control().closeDialog(); + + // return to the WB before edeting the sketch + Gui::Command::assureWorkbench(oldWb.c_str()); } void ViewProviderSketch::setEditViewer(Gui::View3DInventorViewer* viewer, int ModNum) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.h b/src/Mod/Sketcher/Gui/ViewProviderSketch.h index 5511f9407..3a718277d 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.h +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.h @@ -382,6 +382,7 @@ protected: bool relative; Gui::Rubberband* rubberband; + std::string oldWb; }; } // namespace PartGui