All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -21,9 +21,8 @@
***************************************************************************/
# include <QDockWidget>
# include <QStatusBar>
#include <QDockWidget>
#include <QStatusBar>
#include "Workbench.h"
@@ -55,18 +54,28 @@ using namespace Gui;
\ingroup GUI
FreeCAD provides the possibility to have one or more workbenches for a module.
A workbench changes the appearance of the main window in that way that it defines toolbars, items in the toolbox, menus or the context menu and dockable windows that are shown to the user.
The idea behind this concept is that the user should see only the functions that are required for the task that they are doing at this moment and not to show dozens of unneeded functions which the user never uses.
A workbench changes the appearance of the main window in that way that it defines toolbars,
items in the toolbox, menus or the context menu and dockable windows that are shown to the user.
The idea behind this concept is that the user should see only the functions that are required for
the task that they are doing at this moment and not to show dozens of unneeded functions which the
user never uses.
\section stepbystep Step by step
Here follows a short description of how your own workbench can be added to a module.
\subsection newClass Inherit either from Workbench or StdWorkbench
First you have to subclass either \ref Gui::Workbench "Workbench" or \ref Gui::StdWorkbench "StdWorkbench" and reimplement the methods \ref Gui::Workbench::setupMenuBar() "setupMenuBar()", \ref Gui::Workbench::setupToolBars() "setupToolBars()", \ref Gui::Workbench::setupCommandBars() "setupCommandBars()" and \ref Gui::Workbench::setupDockWindows() "setupDockWindows()".
First you have to subclass either \ref Gui::Workbench "Workbench" or \ref Gui::StdWorkbench
"StdWorkbench" and reimplement the methods \ref Gui::Workbench::setupMenuBar() "setupMenuBar()",
\ref Gui::Workbench::setupToolBars() "setupToolBars()", \ref Gui::Workbench::setupCommandBars()
"setupCommandBars()" and \ref Gui::Workbench::setupDockWindows() "setupDockWindows()".
The difference between both classes is that these methods of %Workbench are pure virtual while StdWorkbench defines already the standard menus and toolbars, such as the 'File', 'Edit', ..., 'Help' menus with their common functions.
The difference between both classes is that these methods of %Workbench are pure virtual while
StdWorkbench defines already the standard menus and toolbars, such as the 'File', 'Edit', ...,
'Help' menus with their common functions.
If your class derives from %Workbench then you have to define your menus, toolbars and toolbox items from scratch while deriving from StdWorkbench you have the possibility to add your preferred functions or even remove some unneeded functions.
If your class derives from %Workbench then you have to define your menus, toolbars and toolbox
items from scratch while deriving from StdWorkbench you have the possibility to add your preferred
functions or even remove some unneeded functions.
* \code
*
* class MyWorkbench : public StdWorkbench
@@ -124,7 +133,8 @@ using namespace Gui;
* \endcode
*
* \subsection customizeWorkbench Customizing the workbench
* If you want to customize your workbench by adding or removing items you can use the ToolBarItem class for customizing toolbars and the MenuItem class
* If you want to customize your workbench by adding or removing items you can use the ToolBarItem
class for customizing toolbars and the MenuItem class
* for menus. Both classes behave basically the same.
* To add a new menu item you can do it as follows
* \code
@@ -140,15 +150,19 @@ using namespace Gui;
* MenuItem* myMenu = new MenuItem( root );
* myMenu->setCommand( "&My Menu" );
* // fill up the menu with some command items
* *myMenu << mySub << "Separator" << "Std_Cut" << "Std_Copy" << "Std_Paste" << "Separator" << "Std_Undo" << "Std_Redo";
* *myMenu << mySub << "Separator" << "Std_Cut" << "Std_Copy" << "Std_Paste" << "Separator" <<
"Std_Undo" << "Std_Redo";
* }
* \endcode
*
* Toolbars can be customized the same way unless that you shouldn't create subitems (there are no subtoolbars).
* Toolbars can be customized the same way unless that you shouldn't create subitems (there are no
subtoolbars).
*
* \subsection regWorkbench Register your workbench
* Once you have implemented your workbench class you have to register it to make it known to the FreeCAD core system. You must make sure that the step
* of registration is performed only once. A good place to do it is e.g. in the global function initMODULEGui in AppMODULEGui.cpp where MODULE stands
* Once you have implemented your workbench class you have to register it to make it known to the
FreeCAD core system. You must make sure that the step
* of registration is performed only once. A good place to do it is e.g. in the global function
initMODULEGui in AppMODULEGui.cpp where MODULE stands
* for the name of your module. Just add the line
* \code
* MODULEGui::MyWorkbench::init();
@@ -156,11 +170,16 @@ using namespace Gui;
* somewhere there.
*
* \subsection itemWorkbench Create an item for your workbench
* Though your workbench has been registered now, at this stage you still cannot invoke it yet. Therefore you must create an item in the list of all visible
* workbenches. To perform this step you must open your InitGui.py (a Python file) and do some adjustments. The file contains already a Python class
* MODULEWorkbench that implements the Activate() method (it imports the needed library). You can also implement the GetIcon() method to set your own icon for
* your workbench, if not, the default FreeCAD icon is taken, and finally the most important method GetClassName(). that represents the link between
* Python and C++. This method must return the name of the associated C++ including namespace. In this case it must the string "ModuleGui::MyWorkbench".
* Though your workbench has been registered now, at this stage you still cannot invoke it yet.
Therefore you must create an item in the list of all visible
* workbenches. To perform this step you must open your InitGui.py (a Python file) and do some
adjustments. The file contains already a Python class
* MODULEWorkbench that implements the Activate() method (it imports the needed library). You can
also implement the GetIcon() method to set your own icon for
* your workbench, if not, the default FreeCAD icon is taken, and finally the most important method
GetClassName(). that represents the link between
* Python and C++. This method must return the name of the associated C++ including namespace. In
this case it must the string "ModuleGui::MyWorkbench".
* At the end you can change the line from
* \code
* Gui.addWorkbench("MODULE design",MODULEWorkbench())
@@ -170,33 +189,49 @@ using namespace Gui;
* Gui.addWorkbench("My workbench",MODULEWorkbench())
* \endcode
* or whatever you want.
* \note You must make sure to choose a unique name for your workbench (in this example "My workbench"). Since FreeCAD doesn't provide a mechanism for
* \note You must make sure to choose a unique name for your workbench (in this example "My
workbench"). Since FreeCAD doesn't provide a mechanism for
* this you have to care on your own.
*
* \section moredetails More details and limitations
* One of the key concepts of the workbench framework is to load a module at runtime when the user needs some function that it
* provides. So, if the user doesn't need a module it never gets loaded into RAM. This speeds up the startup procedure of
* One of the key concepts of the workbench framework is to load a module at runtime when the user
needs some function that it
* provides. So, if the user doesn't need a module it never gets loaded into RAM. This speeds up the
startup procedure of
* FreeCAD and saves memory.
*
* At startup FreeCAD scans all module directories and invokes InitGui.py. So an item for a workbench gets created. If the user
* clicks on such an item the matching module gets loaded, the C++ workbench gets registered and activated.
* At startup FreeCAD scans all module directories and invokes InitGui.py. So an item for a
workbench gets created. If the user
* clicks on such an item the matching module gets loaded, the C++ workbench gets registered and
activated.
*
* The user is able to modify a workbench (Edit|Customize). E.g. they can add new toolbars or items for the toolbox and add their preferred
* functions to them. But the user only has full control over "their" own toolbars, the default workbench items cannot be modified or even removed.
* The user is able to modify a workbench (Edit|Customize). E.g. they can add new toolbars or items
for the toolbox and add their preferred
* functions to them. But the user only has full control over "their" own toolbars, the default
workbench items cannot be modified or even removed.
*
* FreeCAD provides also the possibility to define pure Python workbenches. Such workbenches are temporarily only and are lost after exiting
* the FreeCAD session. But if you want to keep your Python workbench you can write a macro and attach it with a user defined button or just
* FreeCAD provides also the possibility to define pure Python workbenches. Such workbenches are
temporarily only and are lost after exiting
* the FreeCAD session. But if you want to keep your Python workbench you can write a macro and
attach it with a user defined button or just
* perform the macro during the next FreeCAD session.
* Here follows a short example of how to create and embed a workbench in Python
* \code
* w=Workbench() # creates a standard workbench (the same as StdWorkbench in C++)
* w.MenuText = "My Workbench" # the text that will appear in the combo box
* dir(w) # lists all available function of the object
* FreeCADGui.addWorkbench(w) # Creates an item for our workbench now
* # Note: We must first add the workbench to run some initialization code
* # Then we are ready to customize the workbench
* w=Workbench() # creates a standard workbench (the
same as StdWorkbench in C++)
* w.MenuText = "My Workbench" # the text that will appear in the
combo box
* dir(w) # lists all available function of the
object
* FreeCADGui.addWorkbench(w) # Creates an item for our workbench
now
* # Note: We must first add the
workbench to run some initialization code
* # Then we are ready to customize the
workbench
* list = ["Std_Test1", "Std_Test2", "Std_Test3"] # creates a list of new functions
* w.appendMenu("Test functions", list) # creates a new menu with these functions
* w.appendMenu("Test functions", list) # creates a new menu with these
functions
* w.appendToolbar("Test", list) # ... and also a new toolbar
* \endcode
*/
@@ -250,10 +285,10 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) cons
void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference<ParameterGrp> hGrp) const
{
std::vector<Base::Reference<ParameterGrp> > hGrps = hGrp->GetGroups();
std::vector<Base::Reference<ParameterGrp>> hGrps = hGrp->GetGroups();
CommandManager& rMgr = Application::Instance->commandManager();
std::string separator = "Separator";
for (const auto & it : hGrps) {
for (const auto& it : hGrps) {
bool active = it->GetBool("Active", true);
if (!active) {
// ignore this toolbar
@@ -264,8 +299,9 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference<Par
bar->setCommand("Custom");
// get the elements of the subgroups
std::vector<std::pair<std::string,std::string> > items = hGrp->GetGroup(it->GetGroupName())->GetASCIIMap();
for (const auto & item : items) {
std::vector<std::pair<std::string, std::string>> items
= hGrp->GetGroup(it->GetGroupName())->GetASCIIMap();
for (const auto& item : items) {
if (item.first.substr(0, separator.size()) == separator) {
*bar << "Separator";
}
@@ -274,7 +310,7 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference<Par
}
else {
Command* pCmd = rMgr.getCommandByName(item.first.c_str());
if (!pCmd) { // unknown command
if (!pCmd) { // unknown command
// first try the module name as is
std::string pyMod = item.second;
try {
@@ -282,7 +318,7 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference<Par
// Try again
pCmd = rMgr.getCommandByName(item.first.c_str());
}
catch(const Base::Exception&) {
catch (const Base::Exception&) {
}
}
@@ -295,12 +331,12 @@ void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference<Par
// Try again
pCmd = rMgr.getCommandByName(item.first.c_str());
}
catch(const Base::Exception&) {
catch (const Base::Exception&) {
}
}
if (pCmd) {
*bar << item.first; // command name
*bar << item.first; // command name
}
}
}
@@ -318,18 +354,18 @@ void Workbench::createContextMenu(const char* recipient, MenuItem* item) const
WorkbenchManipulator::changeContextMenu(recipient, item);
}
void Workbench::setupContextMenu(const char* recipient,MenuItem* item) const
void Workbench::setupContextMenu(const char* recipient, MenuItem* item) const
{
Q_UNUSED(recipient);
Q_UNUSED(item);
}
void Workbench::createMainWindowPopupMenu(MenuItem*) const
{
}
{}
void Workbench::createLinkMenu(MenuItem *item) {
if(!item || !App::GetApplication().getActiveDocument()) {
void Workbench::createLinkMenu(MenuItem* item)
{
if (!item || !App::GetApplication().getActiveDocument()) {
return;
}
@@ -337,21 +373,30 @@ void Workbench::createLinkMenu(MenuItem *item) {
linkMenu->setCommand("Link Actions");
*linkMenu << "Std_LinkMakeGroup" << "Std_LinkMake";
auto &rMgr = Application::Instance->commandManager();
const char *cmds[] = {"Std_LinkMakeRelative",nullptr,"Std_LinkUnlink","Std_LinkReplace",
"Std_LinkImport","Std_LinkImportAll",nullptr,"Std_LinkSelectLinked",
"Std_LinkSelectLinkedFinal","Std_LinkSelectAllLinks"};
auto& rMgr = Application::Instance->commandManager();
const char* cmds[] = {
"Std_LinkMakeRelative",
nullptr,
"Std_LinkUnlink",
"Std_LinkReplace",
"Std_LinkImport",
"Std_LinkImportAll",
nullptr,
"Std_LinkSelectLinked",
"Std_LinkSelectLinkedFinal",
"Std_LinkSelectAllLinks"
};
bool separator = true;
for(const auto & it : cmds) {
if(!it) {
if(separator) {
for (const auto& it : cmds) {
if (!it) {
if (separator) {
separator = false;
*linkMenu << "Separator";
}
continue;
}
auto cmd = rMgr.getCommandByName(it);
if(cmd->isActive()) {
if (cmd->isActive()) {
separator = true;
*linkMenu << it;
}
@@ -368,16 +413,18 @@ void Workbench::addPermanentMenuItem(const std::string& cmd, const std::string&
void Workbench::removePermanentMenuItem(const std::string& cmd)
{
auto it = std::find_if(staticMenuItems.begin(), staticMenuItems.end(), [cmd](const std::pair<std::string, std::string>& pmi) {
return (pmi.first == cmd);
});
auto it = std::find_if(
staticMenuItems.begin(),
staticMenuItems.end(),
[cmd](const std::pair<std::string, std::string>& pmi) { return (pmi.first == cmd); }
);
if (it != staticMenuItems.end()) {
staticMenuItems.erase(it);
}
}
void Workbench::addPermanentMenuItems(MenuItem* mb) const
void Workbench::addPermanentMenuItems(MenuItem* mb) const
{
for (const auto& it : staticMenuItems) {
MenuItem* par = mb->findParentOf(it.second);
@@ -398,31 +445,30 @@ void Workbench::activated()
}
void Workbench::deactivated()
{
}
{}
bool Workbench::activate()
{
ToolBarItem* tb = setupToolBars();
setupCustomToolbars(tb, "Toolbar");
WorkbenchManipulator::changeToolBars(tb);
ToolBarManager::getInstance()->setup( tb );
ToolBarManager::getInstance()->setup(tb);
delete tb;
//ToolBarItem* cb = setupCommandBars();
//setupCustomToolbars(cb, "Toolboxbar");
//ToolBoxManager::getInstance()->setup( cb );
//delete cb;
// ToolBarItem* cb = setupCommandBars();
// setupCustomToolbars(cb, "Toolboxbar");
// ToolBoxManager::getInstance()->setup( cb );
// delete cb;
DockWindowItems* dw = setupDockWindows();
WorkbenchManipulator::changeDockWindows(dw);
DockWindowManager::instance()->setup( dw );
DockWindowManager::instance()->setup(dw);
delete dw;
MenuItem* mb = setupMenuBar();
addPermanentMenuItems(mb);
WorkbenchManipulator::changeMenuBar(mb);
MenuManager::getInstance()->setup( mb );
MenuManager::getInstance()->setup(mb);
delete mb;
setupCustomShortcuts();
@@ -433,7 +479,7 @@ bool Workbench::activate()
void Workbench::retranslate() const
{
ToolBarManager::getInstance()->retranslate();
//ToolBoxManager::getInstance()->retranslate();
// ToolBoxManager::getInstance()->retranslate();
DockWindowManager::instance()->retranslate();
MenuManager::getInstance()->retranslate();
}
@@ -443,7 +489,7 @@ PyObject* Workbench::getPyObject()
return new WorkbenchPy(this);
}
void Workbench::addTaskWatcher(const std::vector<Gui::TaskView::TaskWatcher*> &Watcher)
void Workbench::addTaskWatcher(const std::vector<Gui::TaskView::TaskWatcher*>& Watcher)
{
Gui::TaskView::TaskView* taskView = Control().taskPanel();
if (taskView) {
@@ -467,7 +513,7 @@ std::list<std::string> Workbench::listToolbars() const
std::list<std::string> bars;
QList<ToolBarItem*> items = tb->getItems();
for (const auto & item : items) {
for (const auto& item : items) {
bars.push_back(item->command());
}
return bars;
@@ -481,10 +527,10 @@ std::list<std::pair<std::string, std::list<std::string>>> Workbench::getToolbarI
std::list<std::pair<std::string, std::list<std::string>>> itemsList;
QList<ToolBarItem*> items = tb->getItems();
for (const auto & item : items) {
for (const auto& item : items) {
QList<ToolBarItem*> sub = item->getItems();
std::list<std::string> cmds;
for (const auto & jt : sub) {
for (const auto& jt : sub) {
cmds.push_back(jt->command());
}
@@ -501,7 +547,7 @@ std::list<std::string> Workbench::listMenus() const
std::list<std::string> menus;
QList<MenuItem*> items = mb->getItems();
for (const auto & item : items) {
for (const auto& item : items) {
menus.push_back(item->command());
}
return menus;
@@ -512,7 +558,7 @@ std::list<std::string> Workbench::listCommandbars() const
std::unique_ptr<ToolBarItem> cb(setupCommandBars());
std::list<std::string> bars;
QList<ToolBarItem*> items = cb->getItems();
for (const auto & item : items) {
for (const auto& item : items) {
bars.push_back(item->command());
}
return bars;
@@ -520,7 +566,7 @@ std::list<std::string> Workbench::listCommandbars() const
// --------------------------------------------------------------------
#if 0 // needed for Qt's lupdate utility
#if 0 // needed for Qt's lupdate utility
qApp->translate("CommandGroup", "File");
qApp->translate("CommandGroup", "Edit");
qApp->translate("CommandGroup", "Help");
@@ -564,7 +610,7 @@ std::list<std::string> Workbench::listCommandbars() const
qApp->translate("Workbench", "Link Actions");
#endif
#if 0 // needed for the application menu on OSX
#if 0 // needed for the application menu on OSX
qApp->translate("MAC_APPLICATION_MENU", "Services");
qApp->translate("MAC_APPLICATION_MENU", "Hide %1");
qApp->translate("MAC_APPLICATION_MENU", "Hide Others");
@@ -577,28 +623,27 @@ std::list<std::string> Workbench::listCommandbars() const
TYPESYSTEM_SOURCE(Gui::StdWorkbench, Gui::Workbench)
StdWorkbench::StdWorkbench()
: Workbench()
{
}
: Workbench()
{}
StdWorkbench::~StdWorkbench() = default;
void StdWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
{
if (strcmp(recipient,"View") == 0)
{
if (strcmp(recipient, "View") == 0) {
createLinkMenu(item);
*item << "Separator";
auto StdViews = new MenuItem;
StdViews->setCommand( "Standard Views" );
StdViews->setCommand("Standard Views");
*StdViews << "Std_ViewIsometric" << "Separator" << "Std_ViewHome" << "Std_ViewFront" << "Std_ViewTop" << "Std_ViewRight"
*StdViews << "Std_ViewIsometric" << "Separator" << "Std_ViewHome" << "Std_ViewFront"
<< "Std_ViewTop" << "Std_ViewRight"
<< "Std_ViewRear" << "Std_ViewBottom" << "Std_ViewLeft"
<< "Separator" << "Std_ViewRotateLeft" << "Std_ViewRotateRight";
*item << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_AlignToSelection" << "Std_DrawStyle"
<< StdViews << "Separator"
*item << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_AlignToSelection"
<< "Std_DrawStyle" << StdViews << "Separator"
<< "Std_ViewDockUndockFullscreen";
if (Gui::Selection().countObjectsOfType<App::DocumentObject>() > 0) {
@@ -608,11 +653,11 @@ void StdWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
<< "Std_SendToPythonConsole" << "Std_TransformManip" << "Std_Placement";
}
}
else if (strcmp(recipient,"Tree") == 0)
{
else if (strcmp(recipient, "Tree") == 0) {
if (Gui::Selection().countObjectsOfType<App::DocumentObject>() > 0) {
*item << "Std_ToggleFreeze" << "Separator"
<< "Std_Placement" << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection"
*item << "Std_ToggleFreeze" << "Separator"
<< "Std_Placement" << "Std_ToggleVisibility" << "Std_ShowSelection"
<< "Std_HideSelection"
<< "Std_ToggleSelectability" << "Std_TreeSelectAllInstances" << "Separator"
<< "Std_RandomColor" << "Std_ToggleTransparency" << "Separator"
<< "Std_Cut" << "Std_Copy" << "Std_Paste" << "Std_Delete"
@@ -633,7 +678,7 @@ MenuItem* StdWorkbench::setupMenuBar() const
auto menuBar = new MenuItem;
// File
auto file = new MenuItem( menuBar );
auto file = new MenuItem(menuBar);
file->setCommand("&File");
*file << "Std_New" << "Std_Open" << "Std_RecentFiles" << "Separator" << "Std_CloseActiveWindow"
<< "Std_CloseAllWindows" << "Separator" << "Std_Save" << "Std_SaveAs"
@@ -643,14 +688,15 @@ MenuItem* StdWorkbench::setupMenuBar() const
<< "Separator" << "Std_Quit";
// Edit
auto edit = new MenuItem( menuBar );
auto edit = new MenuItem(menuBar);
edit->setCommand("&Edit");
*edit << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Cut" << "Std_Copy"
<< "Std_Paste" << "Std_DuplicateSelection" << "Separator"
<< "Std_Refresh" << "Std_BoxSelection" << "Std_BoxElementSelection"
<< "Std_SelectAll" << "Std_Delete" << "Std_SendToPythonConsole"
<< "Separator" << "Std_Placement" << "Std_TransformManip" << "Std_Alignment"
<< "Std_Edit" << "Std_Properties" << "Separator" << "Std_UserEditMode" << "Separator" << "Std_DlgPreferences";
<< "Std_Edit" << "Std_Properties" << "Separator" << "Std_UserEditMode" << "Separator"
<< "Std_DlgPreferences";
auto axoviews = new MenuItem;
axoviews->setCommand("A&xonometric");
@@ -688,18 +734,18 @@ MenuItem* StdWorkbench::setupMenuBar() const
<< "Separator" << "Std_ToggleSelectability";
// View
auto view = new MenuItem( menuBar );
auto view = new MenuItem(menuBar);
view->setCommand("&View");
*view << "Std_ViewCreate" << "Std_OrthographicCamera" << "Std_PerspectiveCamera" << "Std_MainFullscreen" << "Separator"
<< stdviews << "Std_FreezeViews" << "Std_DrawStyle" << "Std_SelBoundingBox"
<< "Separator" << view3d << zoom
<< "Std_ViewDockUndockFullscreen" << "Std_AxisCross" << "Std_ToggleClipPlane"
*view << "Std_ViewCreate" << "Std_OrthographicCamera" << "Std_PerspectiveCamera"
<< "Std_MainFullscreen" << "Separator" << stdviews << "Std_FreezeViews" << "Std_DrawStyle"
<< "Std_SelBoundingBox"
<< "Separator" << view3d << zoom << "Std_ViewDockUndockFullscreen" << "Std_AxisCross"
<< "Std_ToggleClipPlane"
<< "Std_TextureMapping"
#ifdef BUILD_VR
<< "Std_ViewVR"
#endif
<< "Separator" << visu
<< "Std_ToggleNavigation"
<< "Separator" << visu << "Std_ToggleNavigation"
<< "Std_RandomColor"
<< "Std_ToggleTransparency"
<< "Separator"
@@ -715,7 +761,7 @@ MenuItem* StdWorkbench::setupMenuBar() const
<< "Std_ViewStatusBar";
// Tools
auto tool = new MenuItem( menuBar );
auto tool = new MenuItem(menuBar);
tool->setCommand("&Tools");
#ifdef BUILD_ADDONMGR
if (Application::Instance->commandManager().getCommandByName("Std_AddonMgr")) {
@@ -741,7 +787,7 @@ MenuItem* StdWorkbench::setupMenuBar() const
<< "Std_DlgCustomize";
// Macro
auto macro = new MenuItem( menuBar );
auto macro = new MenuItem(menuBar);
macro->setCommand("&Macro");
*macro << "Std_DlgMacroRecord"
<< "Std_DlgMacroExecute"
@@ -756,20 +802,21 @@ MenuItem* StdWorkbench::setupMenuBar() const
<< "Std_ToggleBreakpoint";
// Windows
auto wnd = new MenuItem( menuBar );
auto wnd = new MenuItem(menuBar);
wnd->setCommand("&Windows");
*wnd << "Std_ActivateNextWindow" << "Std_ActivatePrevWindow" << "Separator"
<< "Std_TileWindows" << "Std_CascadeWindows" << "Separator"
<< "Std_WindowsMenu" << "Std_Windows";
// Separator
auto sep = new MenuItem( menuBar );
sep->setCommand( "Separator" );
auto sep = new MenuItem(menuBar);
sep->setCommand("Separator");
// Help
auto help = new MenuItem( menuBar );
auto help = new MenuItem(menuBar);
help->setCommand("&Help");
*help << "Std_WhatsThis" << "Separator"
*help << "Std_WhatsThis"
<< "Separator"
// Start page and additional separator are dynamically inserted here
<< "Std_FreeCADUserHub" << "Std_FreeCADForum" << "Std_ReportBug" << "Separator"
<< "Std_RestartInSafeMode" << "Separator"
@@ -784,18 +831,18 @@ ToolBarItem* StdWorkbench::setupToolBars() const
auto root = new ToolBarItem;
// File
auto file = new ToolBarItem( root );
auto file = new ToolBarItem(root);
file->setCommand("File");
*file << "Std_New" << "Std_Open" << "Std_Save";
// Edit
auto edit = new ToolBarItem( root );
auto edit = new ToolBarItem(root);
edit->setCommand("Edit");
*edit << "Std_Undo" << "Std_Redo"
<< "Separator" << "Std_Refresh";
// Clipboard
auto clipboard = new ToolBarItem( root , ToolBarItem::DefaultVisibility::Hidden );
auto clipboard = new ToolBarItem(root, ToolBarItem::DefaultVisibility::Hidden);
clipboard->setCommand("Clipboard");
*clipboard << "Std_Cut" << "Std_Copy" << "Std_Paste";
@@ -805,13 +852,13 @@ ToolBarItem* StdWorkbench::setupToolBars() const
*wb << "Std_Workbench";
// Macro
auto macro = new ToolBarItem( root, ToolBarItem::DefaultVisibility::Hidden);
auto macro = new ToolBarItem(root, ToolBarItem::DefaultVisibility::Hidden);
macro->setCommand("Macro");
*macro << "Std_DlgMacroRecord" << "Std_DlgMacroExecute"
<< "Std_DlgMacroExecuteDirect";
// View
auto view = new ToolBarItem( root );
auto view = new ToolBarItem(root);
view->setCommand("View");
*view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewGroup" << "Std_AlignToSelection"
<< "Separator" << "Std_DrawStyle" << "Std_TreeViewActions" << "Std_Measure";
@@ -828,12 +875,12 @@ ToolBarItem* StdWorkbench::setupToolBars() const
<< "Std_ViewLeft";
// Structure
auto structure = new ToolBarItem( root );
auto structure = new ToolBarItem(root);
structure->setCommand("Structure");
*structure << "Std_Part" << "Std_Group" << "Std_LinkActions" << "Std_VarSet";
// Help
auto help = new ToolBarItem( root );
auto help = new ToolBarItem(root);
help->setCommand("Help");
*help << "Std_WhatsThis";
@@ -845,14 +892,14 @@ ToolBarItem* StdWorkbench::setupCommandBars() const
auto root = new ToolBarItem;
// View
auto view = new ToolBarItem( root );
auto view = new ToolBarItem(root);
view->setCommand("Standard Views");
*view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewIsometric" << "Separator"
<< "Std_ViewFront" << "Std_ViewRight" << "Std_ViewTop"
<< "Std_ViewRear" << "Std_ViewLeft" << "Std_ViewBottom";
// Special Ops
auto macro = new ToolBarItem( root );
auto macro = new ToolBarItem(root);
macro->setCommand("Special Ops");
*macro << "Std_DlgParameter" << "Std_DlgPreferences" << "Std_DlgMacroRecord"
<< "Std_DlgMacroExecute" << "Std_DlgCustomize";
@@ -871,13 +918,17 @@ DockWindowItems* StdWorkbench::setupDockWindows() const
root->addDockWidget("Std_ReportView", Qt::BottomDockWidgetArea, Gui::DockWindowOption::HiddenTabbed);
root->addDockWidget("Std_PythonView", Qt::BottomDockWidgetArea, Gui::DockWindowOption::HiddenTabbed);
//Dagview through parameter.
ParameterGrp::handle group = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("DockWindows")->GetGroup("DAGView");
// Dagview through parameter.
ParameterGrp::handle group = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("DockWindows")
->GetGroup("DAGView");
bool enabled = group->GetBool("Enabled", false);
if (enabled) {
root->addDockWidget("Std_DAGView", Qt::RightDockWidgetArea, Gui::DockWindowOption::Hidden);
root->addDockWidget("Std_DAGView", Qt::RightDockWidgetArea, Gui::DockWindowOption::Hidden);
}
return root;
@@ -888,16 +939,15 @@ DockWindowItems* StdWorkbench::setupDockWindows() const
TYPESYSTEM_SOURCE(Gui::BlankWorkbench, Gui::Workbench)
BlankWorkbench::BlankWorkbench()
: Workbench()
{
}
: Workbench()
{}
BlankWorkbench::~BlankWorkbench() = default;
void BlankWorkbench::activated()
{
QList<QDockWidget*> dw = getMainWindow()->findChildren<QDockWidget*>();
for (auto & it : dw) {
for (auto& it : dw) {
it->toggleViewAction()->setVisible(false);
}
getMainWindow()->statusBar()->hide();
@@ -908,7 +958,7 @@ void BlankWorkbench::deactivated()
getMainWindow()->statusBar()->show();
}
void BlankWorkbench::setupContextMenu(const char* recipient,MenuItem* item) const
void BlankWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
{
Q_UNUSED(recipient);
Q_UNUSED(item);
@@ -939,13 +989,12 @@ DockWindowItems* BlankWorkbench::setupDockWindows() const
TYPESYSTEM_SOURCE(Gui::NoneWorkbench, Gui::StdWorkbench)
NoneWorkbench::NoneWorkbench()
: StdWorkbench()
{
}
: StdWorkbench()
{}
NoneWorkbench::~NoneWorkbench() = default;
void NoneWorkbench::setupContextMenu(const char* recipient,MenuItem* item) const
void NoneWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const
{
Q_UNUSED(recipient);
Q_UNUSED(item);
@@ -957,26 +1006,26 @@ MenuItem* NoneWorkbench::setupMenuBar() const
auto menuBar = new MenuItem;
// File
auto file = new MenuItem( menuBar );
auto file = new MenuItem(menuBar);
file->setCommand("&File");
*file << "Std_Quit";
// Edit
auto edit = new MenuItem( menuBar );
auto edit = new MenuItem(menuBar);
edit->setCommand("&Edit");
*edit << "Std_DlgPreferences";
// View
auto view = new MenuItem( menuBar );
auto view = new MenuItem(menuBar);
view->setCommand("&View");
*view << "Std_Workbench";
// Separator
auto sep = new MenuItem( menuBar );
auto sep = new MenuItem(menuBar);
sep->setCommand("Separator");
// Help
auto help = new MenuItem( menuBar );
auto help = new MenuItem(menuBar);
help->setCommand("&Help");
*help << "Std_OnlineHelp" << "Std_About";
@@ -1007,9 +1056,8 @@ DockWindowItems* NoneWorkbench::setupDockWindows() const
TYPESYSTEM_SOURCE(Gui::TestWorkbench, Gui::Workbench)
TestWorkbench::TestWorkbench()
: StdWorkbench()
{
}
: StdWorkbench()
{}
TestWorkbench::~TestWorkbench() = default;
@@ -1023,14 +1071,14 @@ MenuItem* TestWorkbench::setupMenuBar() const
// Test commands
auto test = new MenuItem;
menuBar->insertItem( item, test );
test->setCommand( "Test &Commands" );
menuBar->insertItem(item, test);
test->setCommand("Test &Commands");
*test << "Std_Test1" << "Std_Test2" << "Std_Test3" << "Std_Test4" << "Std_Test5"
<< "Std_Test6" << "Std_Test7" << "Std_Test8";
// Inventor View
auto opiv = new MenuItem;
menuBar->insertItem( item, opiv );
menuBar->insertItem(item, opiv);
opiv->setCommand("&Inventor View");
*opiv << "Std_ViewExample1" << "Std_ViewExample2" << "Std_ViewExample3";
@@ -1068,8 +1116,7 @@ PythonBaseWorkbench::~PythonBaseWorkbench()
PyObject* PythonBaseWorkbench::getPyObject()
{
if (!_workbenchPy)
{
if (!_workbenchPy) {
_workbenchPy = new PythonWorkbenchPy(this);
}
@@ -1103,23 +1150,26 @@ void PythonBaseWorkbench::setupContextMenu(const char* recipient, MenuItem* item
{
Q_UNUSED(recipient);
QList<MenuItem*> items = _contextMenu->getItems();
for (const auto & it : items) {
for (const auto& it : items) {
item->appendItem(it->copy());
}
}
void PythonBaseWorkbench::appendMenu(const std::list<std::string>& menu, const std::list<std::string>& items) const
void PythonBaseWorkbench::appendMenu(
const std::list<std::string>& menu,
const std::list<std::string>& items
) const
{
if ( menu.empty() || items.empty() ) {
if (menu.empty() || items.empty()) {
return;
}
auto jt=menu.begin();
MenuItem* item = _menuBar->findItem( *jt );
auto jt = menu.begin();
MenuItem* item = _menuBar->findItem(*jt);
if (!item) {
item = new MenuItem;
item->setCommand( *jt );
Gui::MenuItem* wnd = _menuBar->findItem( "&Windows" );
item->setCommand(*jt);
Gui::MenuItem* wnd = _menuBar->findItem("&Windows");
if (wnd) {
_menuBar->insertItem(wnd, item);
}
@@ -1129,18 +1179,16 @@ void PythonBaseWorkbench::appendMenu(const std::list<std::string>& menu, const s
}
// create sub menus
for ( jt++; jt != menu.end(); jt++ )
{
MenuItem* subitem = item->findItem( *jt );
if ( !subitem )
{
for (jt++; jt != menu.end(); jt++) {
MenuItem* subitem = item->findItem(*jt);
if (!subitem) {
subitem = new MenuItem(item);
subitem->setCommand( *jt );
subitem->setCommand(*jt);
}
item = subitem;
}
for (const auto & it : items) {
for (const auto& it : items) {
*item << it;
}
}
@@ -1148,16 +1196,19 @@ void PythonBaseWorkbench::appendMenu(const std::list<std::string>& menu, const s
void PythonBaseWorkbench::removeMenu(const std::string& menu) const
{
MenuItem* item = _menuBar->findItem(menu);
if ( item ) {
if (item) {
_menuBar->removeItem(item);
delete item;
}
}
void PythonBaseWorkbench::appendContextMenu(const std::list<std::string>& menu, const std::list<std::string>& items) const
void PythonBaseWorkbench::appendContextMenu(
const std::list<std::string>& menu,
const std::list<std::string>& items
) const
{
MenuItem* item = _contextMenu;
for (const auto & jt : menu) {
for (const auto& jt : menu) {
MenuItem* subitem = item->findItem(jt);
if (!subitem) {
subitem = new MenuItem(item);
@@ -1166,7 +1217,7 @@ void PythonBaseWorkbench::appendContextMenu(const std::list<std::string>& menu,
item = subitem;
}
for (const auto & it : items) {
for (const auto& it : items) {
*item << it;
}
}
@@ -1193,7 +1244,7 @@ void PythonBaseWorkbench::appendToolbar(const std::string& bar, const std::list<
item->setCommand(bar);
}
for (const auto & it : items) {
for (const auto& it : items) {
*item << it;
}
}
@@ -1209,13 +1260,13 @@ void PythonBaseWorkbench::removeToolbar(const std::string& bar) const
void PythonBaseWorkbench::appendCommandbar(const std::string& bar, const std::list<std::string>& items) const
{
ToolBarItem* item = _commandBar->findItem( bar );
ToolBarItem* item = _commandBar->findItem(bar);
if (!item) {
item = new ToolBarItem(_commandBar);
item->setCommand(bar);
}
for (const auto & it : items) {
for (const auto& it : items) {
*item << it;
}
}