Debian Codegraph @

src/Gui/WorkbenchFactory.cpp

raw
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 "WorkbenchFactory.h"
25 #include "Workbench.h"
26
27 using namespace Gui;
28
29 Gui::WorkbenchFactoryInst* Gui::WorkbenchFactoryInst::_pcSingleton = nullptr;
30
31 WorkbenchFactoryInst& WorkbenchFactoryInst::instance()
32 {
33 if (!_pcSingleton) {
34 _pcSingleton = new WorkbenchFactoryInst;
35 }
36 return *_pcSingleton;
37 }
38
39 void WorkbenchFactoryInst::destruct()
40 {
41 delete _pcSingleton;
42 _pcSingleton = nullptr;
43 }
44
45 Workbench* WorkbenchFactoryInst::createWorkbench(const char* sName) const
46 {
47 auto obj = (Workbench*)Produce(sName);
48 auto wb = freecad_cast<Workbench*>(obj);
49 if (!wb) {
50 delete obj; // delete the unknown object as no workbench object
51 return nullptr;
52 }
53
54 wb->setName(sName);
55 return wb;
56 }
57
58 std::list<std::string> WorkbenchFactoryInst::workbenches() const
59 {
60 std::list<std::string> wb;
61 for (const auto& it : _mpcProducers) {
62 wb.push_back(it.first);
63 }
64 return wb;
65 }