1
/***************************************************************************
2
* Copyright (c) 2005 Werner Mayer <wmayer[at]users.sourceforge.net> *
4
* This file is part of the FreeCAD CAx development system. *
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. *
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. *
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 *
21
***************************************************************************/
24
#include "PreCompiled.h"
26
#include <Base/Console.h>
28
#include "WorkbenchManager.h"
30
#include "DockWindowManager.h"
31
#include "MenuManager.h"
32
#include "ToolBarManager.h"
36
WorkbenchManager* WorkbenchManager::_instance = nullptr;
38
WorkbenchManager* WorkbenchManager::instance()
41
_instance = new WorkbenchManager;
45
void WorkbenchManager::destruct()
51
WorkbenchManager::WorkbenchManager() = default;
53
WorkbenchManager::~WorkbenchManager()
55
for (auto & it : _workbenches) {
56
Workbench* wb = it.second;
60
MenuManager::destruct();
61
ToolBarManager::destruct();
62
//ToolBoxManager::destruct();
63
DockWindowManager::destruct();
66
Workbench* WorkbenchManager::createWorkbench (const std::string& name, const std::string& className)
68
Workbench* wb = getWorkbench(name);
71
// try to create an instance now
72
Base::Type type = Base::Type::getTypeIfDerivedFrom(className.c_str(), Workbench::getClassTypeId(), false);
73
wb = static_cast<Workbench*>(type.createInstance());
74
// createInstance could return a null pointer
76
std::stringstream str;
77
str << "'" << className << "' not a workbench type" << std::ends;
78
throw Base::TypeError(str.str());
82
_workbenches[name] = wb;
88
void WorkbenchManager::removeWorkbench(const std::string& name)
90
std::map<std::string, Workbench*>::iterator it = _workbenches.find(name);
91
if (it != _workbenches.end()) {
92
Workbench* wb = it->second;
93
_workbenches.erase(it);
94
if (_activeWorkbench == wb)
95
_activeWorkbench = nullptr;
100
Workbench* WorkbenchManager::getWorkbench (const std::string& name) const
102
Workbench* wb=nullptr;
104
std::map<std::string, Workbench*>::const_iterator it = _workbenches.find(name);
105
if (it != _workbenches.end()) {
106
// returns the already created object
113
bool WorkbenchManager::activate(const std::string& name, const std::string& className)
115
Workbench* wb = createWorkbench(name, className);
117
_activeWorkbench = wb;
125
Workbench* WorkbenchManager::active() const
127
return _activeWorkbench;
130
std::list<std::string> WorkbenchManager::workbenches() const
132
std::list<std::string> wb;
133
for (const auto & it : _workbenches)
134
wb.push_back(it.first);