[Part Workbench] Fix issue with Sketcher_NewSketch icon moving on changing back to workbench

This commit is contained in:
mwganson
2024-09-30 18:34:08 -05:00
committed by Chris Hennes
parent be5255e9bf
commit a836e0d656
3 changed files with 32 additions and 23 deletions

View File

@@ -24,6 +24,7 @@
#include "PreCompiled.h"
#include "Workbench.h"
#include <Base/Interpreter.h>
#include <Gui/MenuManager.h>
#include <Gui/ToolBarManager.h>
@@ -46,7 +47,25 @@ using namespace PartGui;
/// @namespace PartGui @class Workbench
TYPESYSTEM_SOURCE(PartGui::Workbench, Gui::StdWorkbench)
Workbench::Workbench() = default;
Workbench::Workbench() {
/** If we are to have Sketcher_NewSketch as command in toolbar and menu,
then we must assure SketcherGui has already been loaded.
By putting this in a try/except block we avoid creating a dependency
on sketcher workbench as the import will silently fail if sketcher wb is not built.
Note that BUILD_SKETCHER is a cmake-gui option.
**/
const char* code =
"try:\n"
" import SketcherGui\n"
" success = 'True'\n"
"except ImportError:\n"
" success = 'False'";
const std::string result = Base::Interpreter().runStringWithKey(code, "success", "False");
hasSketcher = (result == "True");
}
Workbench::~Workbench() = default;
@@ -121,9 +140,11 @@ Gui::MenuItem* Workbench::setupMenuBar() const
<< "Materials_InspectMaterial"
<< "Separator"
<< bop << join << split << compound
<< "Separator"
<< "Sketcher_NewSketch"
<< "Part_Extrude"
<< "Separator";
if (hasSketcher) {
*part << "Sketcher_NewSketch";
}
*part << "Part_Extrude"
<< "Part_Revolve"
<< "Part_Mirror"
<< "Part_Scale"
@@ -171,8 +192,10 @@ Gui::ToolBarItem* Workbench::setupToolBars() const
Gui::ToolBarItem* tool = new Gui::ToolBarItem(root);
tool->setCommand("Part tools");
*tool << "Sketcher_NewSketch"
<< "Part_Extrude"
if (hasSketcher) {
*tool << "Sketcher_NewSketch";
}
*tool << "Part_Extrude"
<< "Part_Revolve"
<< "Part_Mirror"
<< "Part_Scale"

View File

@@ -40,6 +40,9 @@ public:
Workbench();
~Workbench() override;
private:
bool hasSketcher = false;
protected:
Gui::MenuItem* setupMenuBar() const override;
Gui::ToolBarItem* setupToolBars() const override;

View File

@@ -38,21 +38,6 @@ class PartWorkbench(Gui.Workbench):
self.__class__.MenuText = "Part"
self.__class__.ToolTip = "Part workbench"
def tryAddManipulator(self):
try:
import SketcherGui
class Manipulator:
def modifyToolBars(self):
return [{"insert" : "Sketcher_NewSketch", "toolItem" : "Part_Extrude"}]
def modifyMenuBar(self):
return [{"insert" : "Sketcher_NewSketch", "menuItem" : "Part_Extrude"}]
manip = Manipulator()
Gui.addWorkbenchManipulator(manip)
except ImportError as err:
pass
def Initialize(self):
# load the module
import PartGui
@@ -79,8 +64,6 @@ class PartWorkbench(Gui.Workbench):
App.Console.PrintError("'BOPTools' package cannot be loaded. "
"{err}\n".format(err=str(err)))
self.tryAddManipulator()
def GetClassName(self):
return "PartGui::Workbench"