| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
|
| 24 |
#include <QDockWidget> |
| 25 |
#include <QStatusBar> |
| 26 |
|
| 27 |
|
| 28 |
#include "Workbench.h" |
| 29 |
#include "WorkbenchManipulator.h" |
| 30 |
#include "WorkbenchPy.h" |
| 31 |
#include "Action.h" |
| 32 |
#include "Application.h" |
| 33 |
#include "Command.h" |
| 34 |
#include "Control.h" |
| 35 |
#include "DockWindowManager.h" |
| 36 |
#include "MainWindow.h" |
| 37 |
#include "MenuManager.h" |
| 38 |
#include "PythonWorkbenchPy.h" |
| 39 |
#include "Selection.h" |
| 40 |
#include "ToolBarManager.h" |
| 41 |
#include "ToolBoxManager.h" |
| 42 |
#include "Window.h" |
| 43 |
|
| 44 |
#include <App/Application.h> |
| 45 |
#include <App/DocumentObject.h> |
| 46 |
#include <Base/Interpreter.h> |
| 47 |
#include <Gui/ComboView.h> |
| 48 |
#include <Gui/TaskView/TaskView.h> |
| 49 |
#include <Gui/TaskView/TaskWatcher.h> |
| 50 |
|
| 51 |
using namespace Gui; |
| 52 |
|
| 53 |
/** \defgroup workbench Workbench Framework |
| 54 |
\ingroup GUI |
| 55 |
|
| 56 |
FreeCAD provides the possibility to have one or more workbenches for a module. |
| 57 |
A workbench changes the appearance of the main window in that way that it defines toolbars, |
| 58 |
items in the toolbox, menus or the context menu and dockable windows that are shown to the user. |
| 59 |
The idea behind this concept is that the user should see only the functions that are required for |
| 60 |
the task that they are doing at this moment and not to show dozens of unneeded functions which the |
| 61 |
user never uses. |
| 62 |
|
| 63 |
\section stepbystep Step by step |
| 64 |
Here follows a short description of how your own workbench can be added to a module. |
| 65 |
|
| 66 |
\subsection newClass Inherit either from Workbench or StdWorkbench |
| 67 |
First you have to subclass either \ref Gui::Workbench "Workbench" or \ref Gui::StdWorkbench |
| 68 |
"StdWorkbench" and reimplement the methods \ref Gui::Workbench::setupMenuBar() "setupMenuBar()", |
| 69 |
\ref Gui::Workbench::setupToolBars() "setupToolBars()", \ref Gui::Workbench::setupCommandBars() |
| 70 |
"setupCommandBars()" and \ref Gui::Workbench::setupDockWindows() "setupDockWindows()". |
| 71 |
|
| 72 |
The difference between both classes is that these methods of %Workbench are pure virtual while |
| 73 |
StdWorkbench defines already the standard menus and toolbars, such as the 'File', 'Edit', ..., |
| 74 |
'Help' menus with their common functions. |
| 75 |
|
| 76 |
If your class derives from %Workbench then you have to define your menus, toolbars and toolbox |
| 77 |
items from scratch while deriving from StdWorkbench you have the possibility to add your preferred |
| 78 |
functions or even remove some unneeded functions. |
| 79 |
* \code |
| 80 |
* |
| 81 |
* class MyWorkbench : public StdWorkbench |
| 82 |
* { |
| 83 |
* ... |
| 84 |
* protected: |
| 85 |
* MenuItem* setupMenuBar() const |
| 86 |
* { |
| 87 |
* MenuItem* root = StdWorkbench::setupMenuBar(); |
| 88 |
* // your changes |
| 89 |
* return root; |
| 90 |
* } |
| 91 |
* ToolBarItem* setupToolBars() const |
| 92 |
* { |
| 93 |
* ToolBarItem* root = StdWorkbench::setupToolBars(); |
| 94 |
* // your changes |
| 95 |
* return root; |
| 96 |
* } |
| 97 |
* ToolBarItem* setupCommandBars() const |
| 98 |
* { |
| 99 |
* ToolBarItem* root = StdWorkbench::setupCommandBars(); |
| 100 |
* // your changes |
| 101 |
* return root; |
| 102 |
* } |
| 103 |
* }; |
| 104 |
* |
| 105 |
* \endcode |
| 106 |
* or |
| 107 |
* \code |
| 108 |
* |
| 109 |
* class MyWorkbench : public Workbench |
| 110 |
* { |
| 111 |
* ... |
| 112 |
* protected: |
| 113 |
* MenuItem* setupMenuBar() const |
| 114 |
* { |
| 115 |
* MenuItem* root = new MenuItem; |
| 116 |
* // setup from scratch |
| 117 |
* return root; |
| 118 |
* } |
| 119 |
* ToolBarItem* setupToolBars() const |
| 120 |
* { |
| 121 |
* ToolBarItem* root = new ToolBarItem; |
| 122 |
* // setup from scratch |
| 123 |
* return root; |
| 124 |
* } |
| 125 |
* ToolBarItem* setupCommandBars() const |
| 126 |
* { |
| 127 |
* ToolBarItem* root = new ToolBarItem; |
| 128 |
* // setup from scratch |
| 129 |
* return root; |
| 130 |
* } |
| 131 |
* }; |
| 132 |
* |
| 133 |
* \endcode |
| 134 |
* |
| 135 |
* \subsection customizeWorkbench Customizing the workbench |
| 136 |
* If you want to customize your workbench by adding or removing items you can use the ToolBarItem |
| 137 |
class for customizing toolbars and the MenuItem class |
| 138 |
* for menus. Both classes behave basically the same. |
| 139 |
* To add a new menu item you can do it as follows |
| 140 |
* \code |
| 141 |
* MenuItem* setupMenuBar() const |
| 142 |
* { |
| 143 |
* MenuItem* root = StdWorkbench::setupMenuBar(); |
| 144 |
* // create a sub menu |
| 145 |
* MenuItem* mySub = new MenuItem; // note: no parent is given |
| 146 |
* mySub->setCommand( "My &Submenu" ); |
| 147 |
* *mySub << "Std_Undo" << "Std_Redo"; |
| 148 |
* |
| 149 |
* // My menu |
| 150 |
* MenuItem* myMenu = new MenuItem( root ); |
| 151 |
* myMenu->setCommand( "&My Menu" ); |
| 152 |
* // fill up the menu with some command items |
| 153 |
* *myMenu << mySub << "Separator" << "Std_Cut" << "Std_Copy" << "Std_Paste" << "Separator" << |
| 154 |
"Std_Undo" << "Std_Redo"; |
| 155 |
* } |
| 156 |
* \endcode |
| 157 |
* |
| 158 |
* Toolbars can be customized the same way unless that you shouldn't create subitems (there are no |
| 159 |
subtoolbars). |
| 160 |
* |
| 161 |
* \subsection regWorkbench Register your workbench |
| 162 |
* Once you have implemented your workbench class you have to register it to make it known to the |
| 163 |
FreeCAD core system. You must make sure that the step |
| 164 |
* of registration is performed only once. A good place to do it is e.g. in the global function |
| 165 |
initMODULEGui in AppMODULEGui.cpp where MODULE stands |
| 166 |
* for the name of your module. Just add the line |
| 167 |
* \code |
| 168 |
* MODULEGui::MyWorkbench::init(); |
| 169 |
* \endcode |
| 170 |
* somewhere there. |
| 171 |
* |
| 172 |
* \subsection itemWorkbench Create an item for your workbench |
| 173 |
* Though your workbench has been registered now, at this stage you still cannot invoke it yet. |
| 174 |
Therefore you must create an item in the list of all visible |
| 175 |
* workbenches. To perform this step you must open your InitGui.py (a Python file) and do some |
| 176 |
adjustments. The file contains already a Python class |
| 177 |
* MODULEWorkbench that implements the Activate() method (it imports the needed library). You can |
| 178 |
also implement the GetIcon() method to set your own icon for |
| 179 |
* your workbench, if not, the default FreeCAD icon is taken, and finally the most important method |
| 180 |
GetClassName(). that represents the link between |
| 181 |
* Python and C++. This method must return the name of the associated C++ including namespace. In |
| 182 |
this case it must the string "ModuleGui::MyWorkbench". |
| 183 |
* At the end you can change the line from |
| 184 |
* \code |
| 185 |
* Gui.addWorkbench("MODULE design",MODULEWorkbench()) |
| 186 |
* \endcode |
| 187 |
* to |
| 188 |
* \code |
| 189 |
* Gui.addWorkbench("My workbench",MODULEWorkbench()) |
| 190 |
* \endcode |
| 191 |
* or whatever you want. |
| 192 |
* \note You must make sure to choose a unique name for your workbench (in this example "My |
| 193 |
workbench"). Since FreeCAD doesn't provide a mechanism for |
| 194 |
* this you have to care on your own. |
| 195 |
* |
| 196 |
* \section moredetails More details and limitations |
| 197 |
* One of the key concepts of the workbench framework is to load a module at runtime when the user |
| 198 |
needs some function that it |
| 199 |
* provides. So, if the user doesn't need a module it never gets loaded into RAM. This speeds up the |
| 200 |
startup procedure of |
| 201 |
* FreeCAD and saves memory. |
| 202 |
* |
| 203 |
* At startup FreeCAD scans all module directories and invokes InitGui.py. So an item for a |
| 204 |
workbench gets created. If the user |
| 205 |
* clicks on such an item the matching module gets loaded, the C++ workbench gets registered and |
| 206 |
activated. |
| 207 |
* |
| 208 |
* The user is able to modify a workbench (Edit|Customize). E.g. they can add new toolbars or items |
| 209 |
for the toolbox and add their preferred |
| 210 |
* functions to them. But the user only has full control over "their" own toolbars, the default |
| 211 |
workbench items cannot be modified or even removed. |
| 212 |
* |
| 213 |
* FreeCAD provides also the possibility to define pure Python workbenches. Such workbenches are |
| 214 |
temporarily only and are lost after exiting |
| 215 |
* the FreeCAD session. But if you want to keep your Python workbench you can write a macro and |
| 216 |
attach it with a user defined button or just |
| 217 |
* perform the macro during the next FreeCAD session. |
| 218 |
* Here follows a short example of how to create and embed a workbench in Python |
| 219 |
* \code |
| 220 |
* w=Workbench() # creates a standard workbench (the |
| 221 |
same as StdWorkbench in C++) |
| 222 |
* w.MenuText = "My Workbench" # the text that will appear in the |
| 223 |
combo box |
| 224 |
* dir(w) # lists all available function of the |
| 225 |
object |
| 226 |
* FreeCADGui.addWorkbench(w) # Creates an item for our workbench |
| 227 |
now |
| 228 |
* # Note: We must first add the |
| 229 |
workbench to run some initialization code |
| 230 |
* # Then we are ready to customize the |
| 231 |
workbench |
| 232 |
* list = ["Std_Test1", "Std_Test2", "Std_Test3"] # creates a list of new functions |
| 233 |
* w.appendMenu("Test functions", list) # creates a new menu with these |
| 234 |
functions |
| 235 |
* w.appendToolbar("Test", list) # ... and also a new toolbar |
| 236 |
* \endcode |
| 237 |
*/ |
| 238 |
|
| 239 |
/// @namespace Gui @class Workbench |
| 240 |
TYPESYSTEM_SOURCE_ABSTRACT(Gui::Workbench, Base::BaseClass) |
| 241 |
|
| 242 |
Workbench::Workbench() = default; |
| 243 |
|
| 244 |
Workbench::~Workbench() = default; |
| 245 |
|
| 246 |
std::string Workbench::name() const |
| 247 |
{ |
| 248 |
return _name; |
| 249 |
} |
| 250 |
|
| 251 |
void Workbench::setName(const std::string& name) |
| 252 |
{ |
| 253 |
_name = name; |
| 254 |
} |
| 255 |
|
| 256 |
void Workbench::setupCustomToolbars(ToolBarItem* root, const char* toolbar) const |
| 257 |
{ |
| 258 |
std::string name = this->name(); |
| 259 |
const auto workbenchGroup { |
| 260 |
App::GetApplication().GetUserParameter().GetGroup("BaseApp")->GetGroup("Workbench") |
| 261 |
}; |
| 262 |
// workbench specific custom toolbars |
| 263 |
if (workbenchGroup->HasGroup(name.c_str())) { |
| 264 |
const auto customGroup = workbenchGroup->GetGroup(name.c_str()); |
| 265 |
if (customGroup->HasGroup(toolbar)) { |
| 266 |
const auto customToolbarGroup = customGroup->GetGroup(toolbar); |
| 267 |
setupCustomToolbars(root, customToolbarGroup); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
// for this workbench global toolbars are not allowed |
| 272 |
if (is<NoneWorkbench>()) { |
| 273 |
return; |
| 274 |
} |
| 275 |
|
| 276 |
// application-wide custom toolbars |
| 277 |
if (workbenchGroup->HasGroup("Global")) { |
| 278 |
const auto globalGroup = workbenchGroup->GetGroup("Global"); |
| 279 |
if (globalGroup->HasGroup(toolbar)) { |
| 280 |
const auto customToolbarGroup = globalGroup->GetGroup(toolbar); |
| 281 |
setupCustomToolbars(root, customToolbarGroup); |
| 282 |
} |
| 283 |
} |
| 284 |
} |
| 285 |
|
| 286 |
void Workbench::setupCustomToolbars(ToolBarItem* root, const Base::Reference<ParameterGrp> hGrp) const |
| 287 |
{ |
| 288 |
std::vector<Base::Reference<ParameterGrp>> hGrps = hGrp->GetGroups(); |
| 289 |
CommandManager& rMgr = Application::Instance->commandManager(); |
| 290 |
std::string separator = "Separator"; |
| 291 |
for (const auto& it : hGrps) { |
| 292 |
bool active = it->GetBool("Active", true); |
| 293 |
if (!active) { |
| 294 |
// ignore this toolbar |
| 295 |
continue; |
| 296 |
} |
| 297 |
|
| 298 |
auto bar = new ToolBarItem(root); |
| 299 |
bar->setCommand("Custom"); |
| 300 |
|
| 301 |
// get the elements of the subgroups |
| 302 |
std::vector<std::pair<std::string, std::string>> items |
| 303 |
= hGrp->GetGroup(it->GetGroupName())->GetASCIIMap(); |
| 304 |
for (const auto& item : items) { |
| 305 |
if (item.first.substr(0, separator.size()) == separator) { |
| 306 |
*bar << "Separator"; |
| 307 |
} |
| 308 |
else if (item.first == "Name") { |
| 309 |
bar->setCommand(item.second); |
| 310 |
} |
| 311 |
else { |
| 312 |
Command* pCmd = rMgr.getCommandByName(item.first.c_str()); |
| 313 |
if (!pCmd) { // unknown command |
| 314 |
// first try the module name as is |
| 315 |
std::string pyMod = item.second; |
| 316 |
try { |
| 317 |
Base::Interpreter().loadModule(pyMod.c_str()); |
| 318 |
// Try again |
| 319 |
pCmd = rMgr.getCommandByName(item.first.c_str()); |
| 320 |
} |
| 321 |
catch (const Base::Exception&) { |
| 322 |
} |
| 323 |
} |
| 324 |
|
| 325 |
// still not there? |
| 326 |
if (!pCmd) { |
| 327 |
// add the 'Gui' suffix |
| 328 |
std::string pyMod = item.second + "Gui"; |
| 329 |
try { |
| 330 |
Base::Interpreter().loadModule(pyMod.c_str()); |
| 331 |
// Try again |
| 332 |
pCmd = rMgr.getCommandByName(item.first.c_str()); |
| 333 |
} |
| 334 |
catch (const Base::Exception&) { |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
if (pCmd) { |
| 339 |
*bar << item.first; // command name |
| 340 |
} |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
} |
| 345 |
|
| 346 |
void Workbench::setupCustomShortcuts() const |
| 347 |
{ |
| 348 |
// Now managed by ShortcutManager |
| 349 |
} |
| 350 |
|
| 351 |
void Workbench::createContextMenu(const char* recipient, MenuItem* item) const |
| 352 |
{ |
| 353 |
setupContextMenu(recipient, item); |
| 354 |
WorkbenchManipulator::changeContextMenu(recipient, item); |
| 355 |
} |
| 356 |
|
| 357 |
void Workbench::setupContextMenu(const char* recipient, MenuItem* item) const |
| 358 |
{ |
| 359 |
Q_UNUSED(recipient); |
| 360 |
Q_UNUSED(item); |
| 361 |
} |
| 362 |
|
| 363 |
void Workbench::createMainWindowPopupMenu(MenuItem*) const |
| 364 |
{} |
| 365 |
|
| 366 |
void Workbench::createLinkMenu(MenuItem* item) |
| 367 |
{ |
| 368 |
if (!item || !App::GetApplication().getActiveDocument()) { |
| 369 |
return; |
| 370 |
} |
| 371 |
|
| 372 |
auto linkMenu = new MenuItem; |
| 373 |
linkMenu->setCommand("Link Actions"); |
| 374 |
*linkMenu << "Std_LinkMakeGroup" << "Std_LinkMake"; |
| 375 |
|
| 376 |
auto& rMgr = Application::Instance->commandManager(); |
| 377 |
const char* cmds[] = { |
| 378 |
"Std_LinkMakeRelative", |
| 379 |
nullptr, |
| 380 |
"Std_LinkUnlink", |
| 381 |
"Std_LinkReplace", |
| 382 |
"Std_LinkImport", |
| 383 |
"Std_LinkImportAll", |
| 384 |
nullptr, |
| 385 |
"Std_LinkSelectLinked", |
| 386 |
"Std_LinkSelectLinkedFinal", |
| 387 |
"Std_LinkSelectAllLinks" |
| 388 |
}; |
| 389 |
bool separator = true; |
| 390 |
for (const auto& it : cmds) { |
| 391 |
if (!it) { |
| 392 |
if (separator) { |
| 393 |
separator = false; |
| 394 |
*linkMenu << "Separator"; |
| 395 |
} |
| 396 |
continue; |
| 397 |
} |
| 398 |
auto cmd = rMgr.getCommandByName(it); |
| 399 |
if (cmd->isActive()) { |
| 400 |
separator = true; |
| 401 |
*linkMenu << it; |
| 402 |
} |
| 403 |
} |
| 404 |
*item << linkMenu; |
| 405 |
} |
| 406 |
|
| 407 |
std::vector<std::pair<std::string, std::string>> Workbench::staticMenuItems; |
| 408 |
|
| 409 |
void Workbench::addPermanentMenuItem(const std::string& cmd, const std::string& after) |
| 410 |
{ |
| 411 |
staticMenuItems.emplace_back(cmd, after); |
| 412 |
} |
| 413 |
|
| 414 |
void Workbench::removePermanentMenuItem(const std::string& cmd) |
| 415 |
{ |
| 416 |
auto it = std::find_if( |
| 417 |
staticMenuItems.begin(), |
| 418 |
staticMenuItems.end(), |
| 419 |
[cmd](const std::pair<std::string, std::string>& pmi) { return (pmi.first == cmd); } |
| 420 |
); |
| 421 |
|
| 422 |
if (it != staticMenuItems.end()) { |
| 423 |
staticMenuItems.erase(it); |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
void Workbench::addPermanentMenuItems(MenuItem* mb) const |
| 428 |
{ |
| 429 |
for (const auto& it : staticMenuItems) { |
| 430 |
MenuItem* par = mb->findParentOf(it.second); |
| 431 |
if (par) { |
| 432 |
Gui::MenuItem* item = par->findItem(it.second); |
| 433 |
item = par->afterItem(item); |
| 434 |
|
| 435 |
auto add = new Gui::MenuItem(); |
| 436 |
add->setCommand(it.first); |
| 437 |
par->insertItem(item, add); |
| 438 |
} |
| 439 |
} |
| 440 |
} |
| 441 |
|
| 442 |
void Workbench::activated() |
| 443 |
{ |
| 444 |
Application::Instance->commandManager().signalPyCmdInitialized(); |
| 445 |
} |
| 446 |
|
| 447 |
void Workbench::deactivated() |
| 448 |
{} |
| 449 |
|
| 450 |
bool Workbench::activate() |
| 451 |
{ |
| 452 |
ToolBarItem* tb = setupToolBars(); |
| 453 |
setupCustomToolbars(tb, "Toolbar"); |
| 454 |
WorkbenchManipulator::changeToolBars(tb); |
| 455 |
ToolBarManager::getInstance()->setup(tb); |
| 456 |
delete tb; |
| 457 |
|
| 458 |
// ToolBarItem* cb = setupCommandBars(); |
| 459 |
// setupCustomToolbars(cb, "Toolboxbar"); |
| 460 |
// ToolBoxManager::getInstance()->setup( cb ); |
| 461 |
// delete cb; |
| 462 |
|
| 463 |
DockWindowItems* dw = setupDockWindows(); |
| 464 |
WorkbenchManipulator::changeDockWindows(dw); |
| 465 |
DockWindowManager::instance()->setup(dw); |
| 466 |
delete dw; |
| 467 |
|
| 468 |
MenuItem* mb = setupMenuBar(); |
| 469 |
addPermanentMenuItems(mb); |
| 470 |
WorkbenchManipulator::changeMenuBar(mb); |
| 471 |
MenuManager::getInstance()->setup(mb); |
| 472 |
delete mb; |
| 473 |
|
| 474 |
setupCustomShortcuts(); |
| 475 |
|
| 476 |
return true; |
| 477 |
} |
| 478 |
|
| 479 |
void Workbench::retranslate() const |
| 480 |
{ |
| 481 |
ToolBarManager::getInstance()->retranslate(); |
| 482 |
// ToolBoxManager::getInstance()->retranslate(); |
| 483 |
DockWindowManager::instance()->retranslate(); |
| 484 |
MenuManager::getInstance()->retranslate(); |
| 485 |
} |
| 486 |
|
| 487 |
PyObject* Workbench::getPyObject() |
| 488 |
{ |
| 489 |
return new WorkbenchPy(this); |
| 490 |
} |
| 491 |
|
| 492 |
void Workbench::addTaskWatcher(const std::vector<Gui::TaskView::TaskWatcher*>& Watcher) |
| 493 |
{ |
| 494 |
Gui::TaskView::TaskView* taskView = Control().taskPanel(); |
| 495 |
if (taskView) { |
| 496 |
taskView->addTaskWatcher(Watcher); |
| 497 |
} |
| 498 |
} |
| 499 |
|
| 500 |
void Workbench::removeTaskWatcher() |
| 501 |
{ |
| 502 |
Gui::TaskView::TaskView* taskView = Control().taskPanel(); |
| 503 |
if (taskView) { |
| 504 |
taskView->clearTaskWatcher(); |
| 505 |
} |
| 506 |
} |
| 507 |
|
| 508 |
std::list<std::string> Workbench::listToolbars() const |
| 509 |
{ |
| 510 |
std::unique_ptr<ToolBarItem> tb(setupToolBars()); |
| 511 |
setupCustomToolbars(tb.get(), "Toolbar"); |
| 512 |
WorkbenchManipulator::changeToolBars(tb.get()); |
| 513 |
|
| 514 |
std::list<std::string> bars; |
| 515 |
QList<ToolBarItem*> items = tb->getItems(); |
| 516 |
for (const auto& item : items) { |
| 517 |
bars.push_back(item->command()); |
| 518 |
} |
| 519 |
return bars; |
| 520 |
} |
| 521 |
|
| 522 |
std::list<std::pair<std::string, std::list<std::string>>> Workbench::getToolbarItems() const |
| 523 |
{ |
| 524 |
std::unique_ptr<ToolBarItem> tb(setupToolBars()); |
| 525 |
setupCustomToolbars(tb.get(), "Toolbar"); |
| 526 |
WorkbenchManipulator::changeToolBars(tb.get()); |
| 527 |
|
| 528 |
std::list<std::pair<std::string, std::list<std::string>>> itemsList; |
| 529 |
QList<ToolBarItem*> items = tb->getItems(); |
| 530 |
for (const auto& item : items) { |
| 531 |
QList<ToolBarItem*> sub = item->getItems(); |
| 532 |
std::list<std::string> cmds; |
| 533 |
for (const auto& jt : sub) { |
| 534 |
cmds.push_back(jt->command()); |
| 535 |
} |
| 536 |
|
| 537 |
itemsList.emplace_back(item->command(), cmds); |
| 538 |
} |
| 539 |
return itemsList; |
| 540 |
} |
| 541 |
|
| 542 |
std::list<std::string> Workbench::listMenus() const |
| 543 |
{ |
| 544 |
std::unique_ptr<MenuItem> mb(setupMenuBar()); |
| 545 |
addPermanentMenuItems(mb.get()); |
| 546 |
WorkbenchManipulator::changeMenuBar(mb.get()); |
| 547 |
|
| 548 |
std::list<std::string> menus; |
| 549 |
QList<MenuItem*> items = mb->getItems(); |
| 550 |
for (const auto& item : items) { |
| 551 |
menus.push_back(item->command()); |
| 552 |
} |
| 553 |
return menus; |
| 554 |
} |
| 555 |
|
| 556 |
std::list<std::string> Workbench::listCommandbars() const |
| 557 |
{ |
| 558 |
std::unique_ptr<ToolBarItem> cb(setupCommandBars()); |
| 559 |
std::list<std::string> bars; |
| 560 |
QList<ToolBarItem*> items = cb->getItems(); |
| 561 |
for (const auto& item : items) { |
| 562 |
bars.push_back(item->command()); |
| 563 |
} |
| 564 |
return bars; |
| 565 |
} |
| 566 |
|
| 567 |
// -------------------------------------------------------------------- |
| 568 |
|
| 569 |
#if 0 // needed for Qt's lupdate utility |
| 570 |
qApp->translate("CommandGroup", "File"); |
| 571 |
qApp->translate("CommandGroup", "Edit"); |
| 572 |
qApp->translate("CommandGroup", "Help"); |
| 573 |
qApp->translate("CommandGroup", "Link"); |
| 574 |
qApp->translate("CommandGroup", "Tools"); |
| 575 |
qApp->translate("CommandGroup", "View"); |
| 576 |
qApp->translate("CommandGroup", "Window"); |
| 577 |
qApp->translate("CommandGroup", "Standard"); |
| 578 |
qApp->translate("CommandGroup", "Macros"); |
| 579 |
qApp->translate("CommandGroup", "Macro"); |
| 580 |
qApp->translate("CommandGroup", "Structure"); |
| 581 |
qApp->translate("CommandGroup", "Standard-Test"); |
| 582 |
qApp->translate("CommandGroup", "Standard-View"); |
| 583 |
qApp->translate("CommandGroup", "Tree View"); |
| 584 |
qApp->translate("CommandGroup", "Measure"); |
| 585 |
|
| 586 |
qApp->translate("Workbench", "&File"); |
| 587 |
qApp->translate("Workbench", "&Edit"); |
| 588 |
qApp->translate("Workbench", "Edit"); |
| 589 |
qApp->translate("Workbench", "Clipboard"); |
| 590 |
qApp->translate("Workbench", "Workbench"); |
| 591 |
qApp->translate("Workbench", "Structure"); |
| 592 |
qApp->translate("Workbench", "Standard &Views"); |
| 593 |
qApp->translate("Workbench", "Individual Views"); |
| 594 |
qApp->translate("Workbench", "A&xonometric"); |
| 595 |
qApp->translate("Workbench", "&Stereo"); |
| 596 |
qApp->translate("Workbench", "&Zoom"); |
| 597 |
qApp->translate("Workbench", "V&isibility"); |
| 598 |
qApp->translate("Workbench", "&View"); |
| 599 |
qApp->translate("Workbench", "&Tools"); |
| 600 |
qApp->translate("Workbench", "&Macro"); |
| 601 |
qApp->translate("Workbench", "&Windows"); |
| 602 |
qApp->translate("Workbench", "&Online Help"); |
| 603 |
qApp->translate("Workbench", "&Help"); |
| 604 |
qApp->translate("Workbench", "Help"); |
| 605 |
qApp->translate("Workbench", "File"); |
| 606 |
qApp->translate("Workbench", "Macro"); |
| 607 |
qApp->translate("Workbench", "View"); |
| 608 |
qApp->translate("Workbench", "Special Ops"); |
| 609 |
// needed for Structure toolbar |
| 610 |
qApp->translate("Workbench", "Link Actions"); |
| 611 |
#endif |
| 612 |
|
| 613 |
#if 0 // needed for the application menu on OSX |
| 614 |
qApp->translate("MAC_APPLICATION_MENU", "Services"); |
| 615 |
qApp->translate("MAC_APPLICATION_MENU", "Hide %1"); |
| 616 |
qApp->translate("MAC_APPLICATION_MENU", "Hide Others"); |
| 617 |
qApp->translate("MAC_APPLICATION_MENU", "Show All"); |
| 618 |
qApp->translate("MAC_APPLICATION_MENU", "Preferences"); |
| 619 |
qApp->translate("MAC_APPLICATION_MENU", "Quit %1"); |
| 620 |
qApp->translate("MAC_APPLICATION_MENU", "About %1"); |
| 621 |
#endif |
| 622 |
|
| 623 |
TYPESYSTEM_SOURCE(Gui::StdWorkbench, Gui::Workbench) |
| 624 |
|
| 625 |
StdWorkbench::StdWorkbench() |
| 626 |
: Workbench() |
| 627 |
{} |
| 628 |
|
| 629 |
StdWorkbench::~StdWorkbench() = default; |
| 630 |
|
| 631 |
void StdWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const |
| 632 |
{ |
| 633 |
if (strcmp(recipient, "View") == 0) { |
| 634 |
createLinkMenu(item); |
| 635 |
*item << "Separator"; |
| 636 |
|
| 637 |
auto StdViews = new MenuItem; |
| 638 |
StdViews->setCommand("Standard Views"); |
| 639 |
|
| 640 |
*StdViews << "Std_ViewIsometric" << "Separator" << "Std_ViewHome" << "Std_ViewFront" |
| 641 |
<< "Std_ViewTop" << "Std_ViewRight" |
| 642 |
<< "Std_ViewRear" << "Std_ViewBottom" << "Std_ViewLeft" |
| 643 |
<< "Separator" << "Std_ViewRotateLeft" << "Std_ViewRotateRight"; |
| 644 |
|
| 645 |
*item << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_AlignToSelection" |
| 646 |
<< "Std_DrawStyle" << StdViews << "Separator" |
| 647 |
<< "Std_ViewDockUndockFullscreen"; |
| 648 |
|
| 649 |
if (Gui::Selection().countObjectsOfType<App::DocumentObject>() > 0) { |
| 650 |
*item << "Separator" << "Std_ToggleVisibility" |
| 651 |
<< "Std_ToggleSelectability" << "Std_TreeSelection" |
| 652 |
<< "Std_RandomColor" << "Std_ToggleTransparency" << "Separator" << "Std_Delete" |
| 653 |
<< "Std_SendToPythonConsole" << "Std_TransformManip" << "Std_Placement"; |
| 654 |
} |
| 655 |
} |
| 656 |
else if (strcmp(recipient, "Tree") == 0) { |
| 657 |
if (Gui::Selection().countObjectsOfType<App::DocumentObject>() > 0) { |
| 658 |
*item << "Std_ToggleFreeze" << "Separator" |
| 659 |
<< "Std_Placement" << "Std_ToggleVisibility" << "Std_ShowSelection" |
| 660 |
<< "Std_HideSelection" |
| 661 |
<< "Std_ToggleSelectability" << "Std_TreeSelectAllInstances" << "Separator" |
| 662 |
<< "Std_RandomColor" << "Std_ToggleTransparency" << "Separator" |
| 663 |
<< "Std_Cut" << "Std_Copy" << "Std_Paste" << "Std_Delete" |
| 664 |
<< "Std_SendToPythonConsole" << "Separator"; |
| 665 |
} |
| 666 |
} |
| 667 |
} |
| 668 |
|
| 669 |
void StdWorkbench::createMainWindowPopupMenu(MenuItem* item) const |
| 670 |
{ |
| 671 |
*item << "Std_ToggleToolBarLock"; |
| 672 |
*item << "Std_DlgCustomize"; |
| 673 |
} |
| 674 |
|
| 675 |
MenuItem* StdWorkbench::setupMenuBar() const |
| 676 |
{ |
| 677 |
// Setup the default menu bar |
| 678 |
auto menuBar = new MenuItem; |
| 679 |
|
| 680 |
// File |
| 681 |
auto file = new MenuItem(menuBar); |
| 682 |
file->setCommand("&File"); |
| 683 |
*file << "Std_New" << "Std_Open" << "Std_RecentFiles" << "Separator" << "Std_CloseActiveWindow" |
| 684 |
<< "Std_CloseAllWindows" << "Separator" << "Std_Save" << "Std_SaveAs" |
| 685 |
<< "Std_SaveCopy" << "Std_SaveAll" << "Std_Revert" << "Separator" << "Std_Import" |
| 686 |
<< "Std_Export" << "Std_MergeProjects" << "Std_ProjectInfo" |
| 687 |
<< "Separator" << "Std_Print" << "Std_PrintPreview" << "Std_PrintPdf" |
| 688 |
<< "Separator" << "Std_Quit"; |
| 689 |
|
| 690 |
// Edit |
| 691 |
auto edit = new MenuItem(menuBar); |
| 692 |
edit->setCommand("&Edit"); |
| 693 |
*edit << "Std_Undo" << "Std_Redo" << "Separator" << "Std_Cut" << "Std_Copy" |
| 694 |
<< "Std_Paste" << "Std_DuplicateSelection" << "Separator" |
| 695 |
<< "Std_Refresh" << "Std_BoxSelection" << "Std_BoxElementSelection" |
| 696 |
<< "Std_SelectAll" << "Std_Delete" << "Std_SendToPythonConsole" |
| 697 |
<< "Separator" << "Std_Placement" << "Std_TransformManip" << "Std_Alignment" |
| 698 |
<< "Std_Edit" << "Std_Properties" << "Separator" << "Std_UserEditMode" << "Separator" |
| 699 |
<< "Std_DlgPreferences"; |
| 700 |
|
| 701 |
auto axoviews = new MenuItem; |
| 702 |
axoviews->setCommand("A&xonometric"); |
| 703 |
*axoviews << "Std_ViewIsometric" |
| 704 |
<< "Std_ViewDimetric" |
| 705 |
<< "Std_ViewTrimetric"; |
| 706 |
|
| 707 |
// Standard views |
| 708 |
auto stdviews = new MenuItem; |
| 709 |
stdviews->setCommand("Standard &Views"); |
| 710 |
*stdviews << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_AlignToSelection" << axoviews |
| 711 |
<< "Separator" << "Std_ViewHome" << "Std_ViewFront" << "Std_ViewTop" |
| 712 |
<< "Std_ViewRight" << "Std_ViewRear" << "Std_ViewBottom" << "Std_ViewLeft" |
| 713 |
<< "Separator" << "Std_ViewRotateLeft" << "Std_ViewRotateRight" << "Separator" |
| 714 |
<< "Std_StoreWorkingView" << "Std_RecallWorkingView"; |
| 715 |
|
| 716 |
// stereo |
| 717 |
auto view3d = new MenuItem; |
| 718 |
view3d->setCommand("&Stereo"); |
| 719 |
*view3d << "Std_ViewIvStereoRedGreen" << "Std_ViewIvStereoQuadBuff" |
| 720 |
<< "Std_ViewIvStereoInterleavedRows" << "Std_ViewIvStereoInterleavedColumns" |
| 721 |
<< "Std_ViewIvStereoOff" << "Separator" << "Std_ViewIvIssueCamPos"; |
| 722 |
|
| 723 |
// zoom |
| 724 |
auto zoom = new MenuItem; |
| 725 |
zoom->setCommand("&Zoom"); |
| 726 |
*zoom << "Std_ViewZoomIn" << "Std_ViewZoomOut" << "Separator" << "Std_ViewBoxZoom"; |
| 727 |
|
| 728 |
// Visibility |
| 729 |
auto visu = new MenuItem; |
| 730 |
visu->setCommand("V&isibility"); |
| 731 |
*visu << "Std_ToggleVisibility" << "Std_ShowSelection" << "Std_HideSelection" |
| 732 |
<< "Std_SelectVisibleObjects" |
| 733 |
<< "Separator" << "Std_ToggleObjects" << "Std_ShowObjects" << "Std_HideObjects" |
| 734 |
<< "Separator" << "Std_ToggleSelectability"; |
| 735 |
|
| 736 |
// View |
| 737 |
auto view = new MenuItem(menuBar); |
| 738 |
view->setCommand("&View"); |
| 739 |
*view << "Std_ViewCreate" << "Std_OrthographicCamera" << "Std_PerspectiveCamera" |
| 740 |
<< "Std_MainFullscreen" << "Separator" << stdviews << "Std_FreezeViews" << "Std_DrawStyle" |
| 741 |
<< "Std_SelBoundingBox" |
| 742 |
<< "Separator" << view3d << zoom << "Std_ViewDockUndockFullscreen" << "Std_AxisCross" |
| 743 |
<< "Std_ToggleClipPlane" |
| 744 |
<< "Std_TextureMapping" |
| 745 |
#ifdef BUILD_VR |
| 746 |
<< "Std_ViewVR" |
| 747 |
#endif |
| 748 |
<< "Separator" << visu << "Std_ToggleNavigation" |
| 749 |
<< "Std_RandomColor" |
| 750 |
<< "Std_ToggleTransparency" |
| 751 |
<< "Separator" |
| 752 |
<< "Std_Workbench" |
| 753 |
<< "Std_ToolBarMenu" |
| 754 |
<< "Std_DockViewMenu"; |
| 755 |
if (DockWindowManager::instance()->isOverlayActivated()) { |
| 756 |
*view << "Std_DockOverlay"; |
| 757 |
} |
| 758 |
*view << "Separator" |
| 759 |
<< "Std_LinkSelectActions" |
| 760 |
<< "Std_TreeViewActions" |
| 761 |
<< "Std_ViewStatusBar"; |
| 762 |
|
| 763 |
// Tools |
| 764 |
auto tool = new MenuItem(menuBar); |
| 765 |
tool->setCommand("&Tools"); |
| 766 |
#ifdef BUILD_ADDONMGR |
| 767 |
if (Application::Instance->commandManager().getCommandByName("Std_AddonMgr")) { |
| 768 |
*tool << "Std_AddonMgr" |
| 769 |
<< "Separator"; |
| 770 |
} |
| 771 |
#endif |
| 772 |
*tool << "Std_Measure" |
| 773 |
<< "Std_ClarifySelection" |
| 774 |
<< "Std_UnitsCalculator" |
| 775 |
<< "Separator" |
| 776 |
<< "Std_ViewLoadImage" |
| 777 |
<< "Std_ViewScreenShot" |
| 778 |
<< "Std_TextDocument" |
| 779 |
<< "Std_DemoMode" |
| 780 |
<< "Separator" |
| 781 |
<< "Std_SceneInspector" |
| 782 |
<< "Std_DependencyGraph" |
| 783 |
<< "Std_ExportDependencyGraph" |
| 784 |
<< "Separator" |
| 785 |
<< "Std_ProjectUtil" |
| 786 |
<< "Std_DlgParameter" |
| 787 |
<< "Std_DlgCustomize"; |
| 788 |
|
| 789 |
// Macro |
| 790 |
auto macro = new MenuItem(menuBar); |
| 791 |
macro->setCommand("&Macro"); |
| 792 |
*macro << "Std_DlgMacroRecord" |
| 793 |
<< "Std_DlgMacroExecute" |
| 794 |
<< "Std_RecentMacros" |
| 795 |
<< "Separator" |
| 796 |
<< "Std_DlgMacroExecuteDirect" |
| 797 |
<< "Std_MacroAttachDebugger" |
| 798 |
<< "Std_MacroStartDebug" |
| 799 |
<< "Std_MacroStopDebug" |
| 800 |
<< "Std_MacroStepOver" |
| 801 |
<< "Std_MacroStepInto" |
| 802 |
<< "Std_ToggleBreakpoint"; |
| 803 |
|
| 804 |
// Windows |
| 805 |
auto wnd = new MenuItem(menuBar); |
| 806 |
wnd->setCommand("&Windows"); |
| 807 |
*wnd << "Std_ActivateNextWindow" << "Std_ActivatePrevWindow" << "Separator" |
| 808 |
<< "Std_TileWindows" << "Std_CascadeWindows" << "Separator" |
| 809 |
<< "Std_WindowsMenu" << "Std_Windows"; |
| 810 |
|
| 811 |
// Separator |
| 812 |
auto sep = new MenuItem(menuBar); |
| 813 |
sep->setCommand("Separator"); |
| 814 |
|
| 815 |
// Help |
| 816 |
auto help = new MenuItem(menuBar); |
| 817 |
help->setCommand("&Help"); |
| 818 |
*help << "Std_WhatsThis" |
| 819 |
<< "Separator" |
| 820 |
// Start page and additional separator are dynamically inserted here |
| 821 |
<< "Std_FreeCADUserHub" << "Std_FreeCADForum" << "Std_ReportBug" << "Separator" |
| 822 |
<< "Std_RestartInSafeMode" << "Separator" |
| 823 |
<< "Std_DevHandbook" << "Std_PythonHelp" << "Separator" |
| 824 |
<< "Std_FreeCADWebsite" << "Std_FreeCADDonation" << "Std_About"; |
| 825 |
|
| 826 |
return menuBar; |
| 827 |
} |
| 828 |
|
| 829 |
ToolBarItem* StdWorkbench::setupToolBars() const |
| 830 |
{ |
| 831 |
auto root = new ToolBarItem; |
| 832 |
|
| 833 |
// File |
| 834 |
auto file = new ToolBarItem(root); |
| 835 |
file->setCommand("File"); |
| 836 |
*file << "Std_New" << "Std_Open" << "Std_Save"; |
| 837 |
|
| 838 |
// Edit |
| 839 |
auto edit = new ToolBarItem(root); |
| 840 |
edit->setCommand("Edit"); |
| 841 |
*edit << "Std_Undo" << "Std_Redo" |
| 842 |
<< "Separator" << "Std_Refresh"; |
| 843 |
|
| 844 |
// Clipboard |
| 845 |
auto clipboard = new ToolBarItem(root, ToolBarItem::DefaultVisibility::Hidden); |
| 846 |
clipboard->setCommand("Clipboard"); |
| 847 |
*clipboard << "Std_Cut" << "Std_Copy" << "Std_Paste"; |
| 848 |
|
| 849 |
// Workbench switcher |
| 850 |
auto wb = new ToolBarItem(root); |
| 851 |
wb->setCommand("Workbench"); |
| 852 |
*wb << "Std_Workbench"; |
| 853 |
|
| 854 |
// Macro |
| 855 |
auto macro = new ToolBarItem(root, ToolBarItem::DefaultVisibility::Hidden); |
| 856 |
macro->setCommand("Macro"); |
| 857 |
*macro << "Std_DlgMacroRecord" << "Std_DlgMacroExecute" |
| 858 |
<< "Std_DlgMacroExecuteDirect"; |
| 859 |
|
| 860 |
// View |
| 861 |
auto view = new ToolBarItem(root); |
| 862 |
view->setCommand("View"); |
| 863 |
*view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewGroup" << "Std_AlignToSelection" |
| 864 |
<< "Separator" << "Std_DrawStyle" << "Std_TreeViewActions" << "Std_Measure"; |
| 865 |
|
| 866 |
// Individual views |
| 867 |
auto individualViews = new ToolBarItem(root, ToolBarItem::DefaultVisibility::Hidden); |
| 868 |
individualViews->setCommand("Individual Views"); |
| 869 |
*individualViews << "Std_ViewIsometric" |
| 870 |
<< "Std_ViewFront" |
| 871 |
<< "Std_ViewTop" |
| 872 |
<< "Std_ViewRight" |
| 873 |
<< "Std_ViewRear" |
| 874 |
<< "Std_ViewBottom" |
| 875 |
<< "Std_ViewLeft"; |
| 876 |
|
| 877 |
// Structure |
| 878 |
auto structure = new ToolBarItem(root); |
| 879 |
structure->setCommand("Structure"); |
| 880 |
*structure << "Std_Part" << "Std_Group" << "Std_LinkActions" << "Std_VarSet"; |
| 881 |
|
| 882 |
// Help |
| 883 |
auto help = new ToolBarItem(root); |
| 884 |
help->setCommand("Help"); |
| 885 |
*help << "Std_WhatsThis"; |
| 886 |
|
| 887 |
return root; |
| 888 |
} |
| 889 |
|
| 890 |
ToolBarItem* StdWorkbench::setupCommandBars() const |
| 891 |
{ |
| 892 |
auto root = new ToolBarItem; |
| 893 |
|
| 894 |
// View |
| 895 |
auto view = new ToolBarItem(root); |
| 896 |
view->setCommand("Standard Views"); |
| 897 |
*view << "Std_ViewFitAll" << "Std_ViewFitSelection" << "Std_ViewIsometric" << "Separator" |
| 898 |
<< "Std_ViewFront" << "Std_ViewRight" << "Std_ViewTop" |
| 899 |
<< "Std_ViewRear" << "Std_ViewLeft" << "Std_ViewBottom"; |
| 900 |
|
| 901 |
// Special Ops |
| 902 |
auto macro = new ToolBarItem(root); |
| 903 |
macro->setCommand("Special Ops"); |
| 904 |
*macro << "Std_DlgParameter" << "Std_DlgPreferences" << "Std_DlgMacroRecord" |
| 905 |
<< "Std_DlgMacroExecute" << "Std_DlgCustomize"; |
| 906 |
|
| 907 |
return root; |
| 908 |
} |
| 909 |
|
| 910 |
DockWindowItems* StdWorkbench::setupDockWindows() const |
| 911 |
{ |
| 912 |
auto root = new DockWindowItems(); |
| 913 |
root->addDockWidget("Std_TreeView", Qt::LeftDockWidgetArea, Gui::DockWindowOption::Visible); |
| 914 |
root->addDockWidget("Std_PropertyView", Qt::LeftDockWidgetArea, Gui::DockWindowOption::Visible); |
| 915 |
root->addDockWidget("Std_SelectionView", Qt::LeftDockWidgetArea, Gui::DockWindowOption::Hidden); |
| 916 |
root->addDockWidget("Std_ComboView", Qt::LeftDockWidgetArea, Gui::DockWindowOption::VisibleTabbed); |
| 917 |
root->addDockWidget("Std_TaskView", Qt::RightDockWidgetArea, Gui::DockWindowOption::VisibleTabbed); |
| 918 |
root->addDockWidget("Std_ReportView", Qt::BottomDockWidgetArea, Gui::DockWindowOption::HiddenTabbed); |
| 919 |
root->addDockWidget("Std_PythonView", Qt::BottomDockWidgetArea, Gui::DockWindowOption::HiddenTabbed); |
| 920 |
|
| 921 |
// Dagview through parameter. |
| 922 |
ParameterGrp::handle group = App::GetApplication() |
| 923 |
.GetUserParameter() |
| 924 |
.GetGroup("BaseApp") |
| 925 |
->GetGroup("Preferences") |
| 926 |
->GetGroup("DockWindows") |
| 927 |
->GetGroup("DAGView"); |
| 928 |
|
| 929 |
bool enabled = group->GetBool("Enabled", false); |
| 930 |
if (enabled) { |
| 931 |
root->addDockWidget("Std_DAGView", Qt::RightDockWidgetArea, Gui::DockWindowOption::Hidden); |
| 932 |
} |
| 933 |
|
| 934 |
return root; |
| 935 |
} |
| 936 |
|
| 937 |
// -------------------------------------------------------------------- |
| 938 |
|
| 939 |
TYPESYSTEM_SOURCE(Gui::BlankWorkbench, Gui::Workbench) |
| 940 |
|
| 941 |
BlankWorkbench::BlankWorkbench() |
| 942 |
: Workbench() |
| 943 |
{} |
| 944 |
|
| 945 |
BlankWorkbench::~BlankWorkbench() = default; |
| 946 |
|
| 947 |
void BlankWorkbench::activated() |
| 948 |
{ |
| 949 |
QList<QDockWidget*> dw = getMainWindow()->findChildren<QDockWidget*>(); |
| 950 |
for (auto& it : dw) { |
| 951 |
it->toggleViewAction()->setVisible(false); |
| 952 |
} |
| 953 |
getMainWindow()->statusBar()->hide(); |
| 954 |
} |
| 955 |
|
| 956 |
void BlankWorkbench::deactivated() |
| 957 |
{ |
| 958 |
getMainWindow()->statusBar()->show(); |
| 959 |
} |
| 960 |
|
| 961 |
void BlankWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const |
| 962 |
{ |
| 963 |
Q_UNUSED(recipient); |
| 964 |
Q_UNUSED(item); |
| 965 |
} |
| 966 |
|
| 967 |
MenuItem* BlankWorkbench::setupMenuBar() const |
| 968 |
{ |
| 969 |
return new MenuItem(); |
| 970 |
} |
| 971 |
|
| 972 |
ToolBarItem* BlankWorkbench::setupToolBars() const |
| 973 |
{ |
| 974 |
return new ToolBarItem(); |
| 975 |
} |
| 976 |
|
| 977 |
ToolBarItem* BlankWorkbench::setupCommandBars() const |
| 978 |
{ |
| 979 |
return new ToolBarItem(); |
| 980 |
} |
| 981 |
|
| 982 |
DockWindowItems* BlankWorkbench::setupDockWindows() const |
| 983 |
{ |
| 984 |
return new DockWindowItems(); |
| 985 |
} |
| 986 |
|
| 987 |
// -------------------------------------------------------------------- |
| 988 |
|
| 989 |
TYPESYSTEM_SOURCE(Gui::NoneWorkbench, Gui::StdWorkbench) |
| 990 |
|
| 991 |
NoneWorkbench::NoneWorkbench() |
| 992 |
: StdWorkbench() |
| 993 |
{} |
| 994 |
|
| 995 |
NoneWorkbench::~NoneWorkbench() = default; |
| 996 |
|
| 997 |
void NoneWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const |
| 998 |
{ |
| 999 |
Q_UNUSED(recipient); |
| 1000 |
Q_UNUSED(item); |
| 1001 |
} |
| 1002 |
|
| 1003 |
MenuItem* NoneWorkbench::setupMenuBar() const |
| 1004 |
{ |
| 1005 |
// Setup the default menu bar |
| 1006 |
auto menuBar = new MenuItem; |
| 1007 |
|
| 1008 |
// File |
| 1009 |
auto file = new MenuItem(menuBar); |
| 1010 |
file->setCommand("&File"); |
| 1011 |
*file << "Std_Quit"; |
| 1012 |
|
| 1013 |
// Edit |
| 1014 |
auto edit = new MenuItem(menuBar); |
| 1015 |
edit->setCommand("&Edit"); |
| 1016 |
*edit << "Std_DlgPreferences"; |
| 1017 |
|
| 1018 |
// View |
| 1019 |
auto view = new MenuItem(menuBar); |
| 1020 |
view->setCommand("&View"); |
| 1021 |
*view << "Std_Workbench"; |
| 1022 |
|
| 1023 |
// Separator |
| 1024 |
auto sep = new MenuItem(menuBar); |
| 1025 |
sep->setCommand("Separator"); |
| 1026 |
|
| 1027 |
// Help |
| 1028 |
auto help = new MenuItem(menuBar); |
| 1029 |
help->setCommand("&Help"); |
| 1030 |
*help << "Std_OnlineHelp" << "Std_About"; |
| 1031 |
|
| 1032 |
return menuBar; |
| 1033 |
} |
| 1034 |
|
| 1035 |
ToolBarItem* NoneWorkbench::setupToolBars() const |
| 1036 |
{ |
| 1037 |
auto root = new ToolBarItem; |
| 1038 |
return root; |
| 1039 |
} |
| 1040 |
|
| 1041 |
ToolBarItem* NoneWorkbench::setupCommandBars() const |
| 1042 |
{ |
| 1043 |
auto root = new ToolBarItem; |
| 1044 |
return root; |
| 1045 |
} |
| 1046 |
|
| 1047 |
DockWindowItems* NoneWorkbench::setupDockWindows() const |
| 1048 |
{ |
| 1049 |
auto root = new DockWindowItems(); |
| 1050 |
root->addDockWidget("Std_ReportView", Qt::BottomDockWidgetArea, Gui::DockWindowOption::Visible); |
| 1051 |
return root; |
| 1052 |
} |
| 1053 |
|
| 1054 |
// -------------------------------------------------------------------- |
| 1055 |
|
| 1056 |
TYPESYSTEM_SOURCE(Gui::TestWorkbench, Gui::Workbench) |
| 1057 |
|
| 1058 |
TestWorkbench::TestWorkbench() |
| 1059 |
: StdWorkbench() |
| 1060 |
{} |
| 1061 |
|
| 1062 |
TestWorkbench::~TestWorkbench() = default; |
| 1063 |
|
| 1064 |
MenuItem* TestWorkbench::setupMenuBar() const |
| 1065 |
{ |
| 1066 |
// Setup the default menu bar |
| 1067 |
MenuItem* menuBar = StdWorkbench::setupMenuBar(); |
| 1068 |
|
| 1069 |
MenuItem* item = menuBar->findItem("&Help"); |
| 1070 |
item->removeItem(item->findItem("Std_WhatsThis")); |
| 1071 |
|
| 1072 |
// Test commands |
| 1073 |
auto test = new MenuItem; |
| 1074 |
menuBar->insertItem(item, test); |
| 1075 |
test->setCommand("Test &Commands"); |
| 1076 |
*test << "Std_Test1" << "Std_Test2" << "Std_Test3" << "Std_Test4" << "Std_Test5" |
| 1077 |
<< "Std_Test6" << "Std_Test7" << "Std_Test8"; |
| 1078 |
|
| 1079 |
// Inventor View |
| 1080 |
auto opiv = new MenuItem; |
| 1081 |
menuBar->insertItem(item, opiv); |
| 1082 |
opiv->setCommand("&Inventor View"); |
| 1083 |
*opiv << "Std_ViewExample1" << "Std_ViewExample2" << "Std_ViewExample3"; |
| 1084 |
|
| 1085 |
return menuBar; |
| 1086 |
} |
| 1087 |
|
| 1088 |
ToolBarItem* TestWorkbench::setupToolBars() const |
| 1089 |
{ |
| 1090 |
return nullptr; |
| 1091 |
} |
| 1092 |
|
| 1093 |
ToolBarItem* TestWorkbench::setupCommandBars() const |
| 1094 |
{ |
| 1095 |
return nullptr; |
| 1096 |
} |
| 1097 |
|
| 1098 |
// ----------------------------------------------------------------------- |
| 1099 |
|
| 1100 |
TYPESYSTEM_SOURCE_ABSTRACT(Gui::PythonBaseWorkbench, Gui::Workbench) |
| 1101 |
|
| 1102 |
PythonBaseWorkbench::PythonBaseWorkbench() = default; |
| 1103 |
|
| 1104 |
PythonBaseWorkbench::~PythonBaseWorkbench() |
| 1105 |
{ |
| 1106 |
delete _menuBar; |
| 1107 |
delete _contextMenu; |
| 1108 |
delete _toolBar; |
| 1109 |
delete _commandBar; |
| 1110 |
if (_workbenchPy) { |
| 1111 |
Base::PyGILStateLocker lock; |
| 1112 |
_workbenchPy->setInvalid(); |
| 1113 |
_workbenchPy->DecRef(); |
| 1114 |
} |
| 1115 |
} |
| 1116 |
|
| 1117 |
PyObject* PythonBaseWorkbench::getPyObject() |
| 1118 |
{ |
| 1119 |
if (!_workbenchPy) { |
| 1120 |
_workbenchPy = new PythonWorkbenchPy(this); |
| 1121 |
} |
| 1122 |
|
| 1123 |
// Increment every time when this object is returned |
| 1124 |
_workbenchPy->IncRef(); |
| 1125 |
|
| 1126 |
return _workbenchPy; |
| 1127 |
} |
| 1128 |
|
| 1129 |
MenuItem* PythonBaseWorkbench::setupMenuBar() const |
| 1130 |
{ |
| 1131 |
return _menuBar->copy(); |
| 1132 |
} |
| 1133 |
|
| 1134 |
ToolBarItem* PythonBaseWorkbench::setupToolBars() const |
| 1135 |
{ |
| 1136 |
return _toolBar->copy(); |
| 1137 |
} |
| 1138 |
|
| 1139 |
ToolBarItem* PythonBaseWorkbench::setupCommandBars() const |
| 1140 |
{ |
| 1141 |
return _commandBar->copy(); |
| 1142 |
} |
| 1143 |
|
| 1144 |
DockWindowItems* PythonBaseWorkbench::setupDockWindows() const |
| 1145 |
{ |
| 1146 |
return new DockWindowItems(); |
| 1147 |
} |
| 1148 |
|
| 1149 |
void PythonBaseWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const |
| 1150 |
{ |
| 1151 |
Q_UNUSED(recipient); |
| 1152 |
QList<MenuItem*> items = _contextMenu->getItems(); |
| 1153 |
for (const auto& it : items) { |
| 1154 |
item->appendItem(it->copy()); |
| 1155 |
} |
| 1156 |
} |
| 1157 |
|
| 1158 |
void PythonBaseWorkbench::appendMenu( |
| 1159 |
const std::list<std::string>& menu, |
| 1160 |
const std::list<std::string>& items |
| 1161 |
) const |
| 1162 |
{ |
| 1163 |
if (menu.empty() || items.empty()) { |
| 1164 |
return; |
| 1165 |
} |
| 1166 |
|
| 1167 |
auto jt = menu.begin(); |
| 1168 |
MenuItem* item = _menuBar->findItem(*jt); |
| 1169 |
if (!item) { |
| 1170 |
item = new MenuItem; |
| 1171 |
item->setCommand(*jt); |
| 1172 |
Gui::MenuItem* wnd = _menuBar->findItem("&Windows"); |
| 1173 |
if (wnd) { |
| 1174 |
_menuBar->insertItem(wnd, item); |
| 1175 |
} |
| 1176 |
else { |
| 1177 |
_menuBar->appendItem(item); |
| 1178 |
} |
| 1179 |
} |
| 1180 |
|
| 1181 |
// create sub menus |
| 1182 |
for (jt++; jt != menu.end(); jt++) { |
| 1183 |
MenuItem* subitem = item->findItem(*jt); |
| 1184 |
if (!subitem) { |
| 1185 |
subitem = new MenuItem(item); |
| 1186 |
subitem->setCommand(*jt); |
| 1187 |
} |
| 1188 |
item = subitem; |
| 1189 |
} |
| 1190 |
|
| 1191 |
for (const auto& it : items) { |
| 1192 |
*item << it; |
| 1193 |
} |
| 1194 |
} |
| 1195 |
|
| 1196 |
void PythonBaseWorkbench::removeMenu(const std::string& menu) const |
| 1197 |
{ |
| 1198 |
MenuItem* item = _menuBar->findItem(menu); |
| 1199 |
if (item) { |
| 1200 |
_menuBar->removeItem(item); |
| 1201 |
delete item; |
| 1202 |
} |
| 1203 |
} |
| 1204 |
|
| 1205 |
void PythonBaseWorkbench::appendContextMenu( |
| 1206 |
const std::list<std::string>& menu, |
| 1207 |
const std::list<std::string>& items |
| 1208 |
) const |
| 1209 |
{ |
| 1210 |
MenuItem* item = _contextMenu; |
| 1211 |
for (const auto& jt : menu) { |
| 1212 |
MenuItem* subitem = item->findItem(jt); |
| 1213 |
if (!subitem) { |
| 1214 |
subitem = new MenuItem(item); |
| 1215 |
subitem->setCommand(jt); |
| 1216 |
} |
| 1217 |
item = subitem; |
| 1218 |
} |
| 1219 |
|
| 1220 |
for (const auto& it : items) { |
| 1221 |
*item << it; |
| 1222 |
} |
| 1223 |
} |
| 1224 |
|
| 1225 |
void PythonBaseWorkbench::removeContextMenu(const std::string& menu) const |
| 1226 |
{ |
| 1227 |
MenuItem* item = _contextMenu->findItem(menu); |
| 1228 |
if (item) { |
| 1229 |
_contextMenu->removeItem(item); |
| 1230 |
delete item; |
| 1231 |
} |
| 1232 |
} |
| 1233 |
|
| 1234 |
void PythonBaseWorkbench::clearContextMenu() |
| 1235 |
{ |
| 1236 |
_contextMenu->clear(); |
| 1237 |
} |
| 1238 |
|
| 1239 |
void PythonBaseWorkbench::appendToolbar(const std::string& bar, const std::list<std::string>& items) const |
| 1240 |
{ |
| 1241 |
ToolBarItem* item = _toolBar->findItem(bar); |
| 1242 |
if (!item) { |
| 1243 |
item = new ToolBarItem(_toolBar); |
| 1244 |
item->setCommand(bar); |
| 1245 |
} |
| 1246 |
|
| 1247 |
for (const auto& it : items) { |
| 1248 |
*item << it; |
| 1249 |
} |
| 1250 |
} |
| 1251 |
|
| 1252 |
void PythonBaseWorkbench::removeToolbar(const std::string& bar) const |
| 1253 |
{ |
| 1254 |
ToolBarItem* item = _toolBar->findItem(bar); |
| 1255 |
if (item) { |
| 1256 |
_toolBar->removeItem(item); |
| 1257 |
delete item; |
| 1258 |
} |
| 1259 |
} |
| 1260 |
|
| 1261 |
void PythonBaseWorkbench::appendCommandbar(const std::string& bar, const std::list<std::string>& items) const |
| 1262 |
{ |
| 1263 |
ToolBarItem* item = _commandBar->findItem(bar); |
| 1264 |
if (!item) { |
| 1265 |
item = new ToolBarItem(_commandBar); |
| 1266 |
item->setCommand(bar); |
| 1267 |
} |
| 1268 |
|
| 1269 |
for (const auto& it : items) { |
| 1270 |
*item << it; |
| 1271 |
} |
| 1272 |
} |
| 1273 |
|
| 1274 |
void PythonBaseWorkbench::removeCommandbar(const std::string& bar) const |
| 1275 |
{ |
| 1276 |
ToolBarItem* item = _commandBar->findItem(bar); |
| 1277 |
if (item) { |
| 1278 |
_commandBar->removeItem(item); |
| 1279 |
delete item; |
| 1280 |
} |
| 1281 |
} |
| 1282 |
|
| 1283 |
// ----------------------------------------------------------------------- |
| 1284 |
|
| 1285 |
TYPESYSTEM_SOURCE(Gui::PythonBlankWorkbench, Gui::PythonBaseWorkbench) |
| 1286 |
|
| 1287 |
PythonBlankWorkbench::PythonBlankWorkbench() |
| 1288 |
{ |
| 1289 |
_menuBar = new MenuItem; |
| 1290 |
_contextMenu = new MenuItem; |
| 1291 |
_toolBar = new ToolBarItem; |
| 1292 |
_commandBar = new ToolBarItem; |
| 1293 |
} |
| 1294 |
|
| 1295 |
PythonBlankWorkbench::~PythonBlankWorkbench() = default; |
| 1296 |
|
| 1297 |
// ----------------------------------------------------------------------- |
| 1298 |
|
| 1299 |
TYPESYSTEM_SOURCE(Gui::PythonWorkbench, Gui::PythonBaseWorkbench) |
| 1300 |
|
| 1301 |
PythonWorkbench::PythonWorkbench() |
| 1302 |
{ |
| 1303 |
StdWorkbench wb; |
| 1304 |
_menuBar = wb.setupMenuBar(); |
| 1305 |
_contextMenu = new MenuItem; |
| 1306 |
_toolBar = wb.setupToolBars(); |
| 1307 |
_commandBar = new ToolBarItem; |
| 1308 |
} |
| 1309 |
|
| 1310 |
PythonWorkbench::~PythonWorkbench() = default; |
| 1311 |
|
| 1312 |
MenuItem* PythonWorkbench::setupMenuBar() const |
| 1313 |
{ |
| 1314 |
return _menuBar->copy(); |
| 1315 |
} |
| 1316 |
|
| 1317 |
ToolBarItem* PythonWorkbench::setupToolBars() const |
| 1318 |
{ |
| 1319 |
return _toolBar->copy(); |
| 1320 |
} |
| 1321 |
|
| 1322 |
ToolBarItem* PythonWorkbench::setupCommandBars() const |
| 1323 |
{ |
| 1324 |
return _commandBar->copy(); |
| 1325 |
} |
| 1326 |
|
| 1327 |
DockWindowItems* PythonWorkbench::setupDockWindows() const |
| 1328 |
{ |
| 1329 |
StdWorkbench wb; |
| 1330 |
return wb.setupDockWindows(); |
| 1331 |
} |
| 1332 |
|
| 1333 |
void PythonWorkbench::setupContextMenu(const char* recipient, MenuItem* item) const |
| 1334 |
{ |
| 1335 |
StdWorkbench wb; |
| 1336 |
wb.setupContextMenu(recipient, item); |
| 1337 |
PythonBaseWorkbench::setupContextMenu(recipient, item); |
| 1338 |
} |
| 1339 |
|
| 1340 |
void PythonWorkbench::createMainWindowPopupMenu(MenuItem* item) const |
| 1341 |
{ |
| 1342 |
StdWorkbench wb; |
| 1343 |
wb.createMainWindowPopupMenu(item); |
| 1344 |
} |