Debian Codegraph @

src/Gui/ActiveObjectList.h

raw
1 /**************************************************************************
2 * Copyright (c) 2014 Jürgen Riegel <[email protected]> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU Library General Public License (LGPL) *
8 * as published by the Free Software Foundation; either version 2 of *
9 * the License, or (at your option) any later version. *
10 * for detail see the LICENCE text file. *
11 * *
12 * FreeCAD is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Library General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Library General Public *
18 * License along with FreeCAD; if not, write to the Free Software *
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
20 * USA *
21 * *
22 ***************************************************************************/
23
24
25 #ifndef GUI_ActiveObjectList_H
26 #define GUI_ActiveObjectList_H
27
28 #include <map>
29 #include <string>
30 #include <Base/Type.h>
31 #include <Gui/TreeItemMode.h>
32 #include <FCGlobal.h>
33
34
35 namespace App
36 {
37 class DocumentObject;
38 }
39
40 namespace Gui
41 {
42 class Document;
43 class ViewProviderDocumentObject;
44
45 /** List of active or special objects
46 * This class holds a list of objects with a special name.
47 * Its mainly used to points to something like the active Body or Part in a edit session.
48 * The class is used the viewer (editor) of a document.
49 * @see Gui::MDIViewer
50 * @author Jürgen Riegel
51 */
52 class GuiExport ActiveObjectList
53 {
54 public:
55 explicit ActiveObjectList(Document* doc)
56 : _Doc(doc)
57 {}
58
59 template<typename _T>
60 inline _T getObject(
61 const char* name,
62 App::DocumentObject** parent = nullptr,
63 std::string* subname = nullptr
64 ) const
65 {
66 auto it = _ObjectMap.find(name);
67 if (it == _ObjectMap.end()) {
68 return 0;
69 }
70 return dynamic_cast<_T>(getObject(it->second, true, parent, subname));
71 }
72 void setObject(
73 App::DocumentObject*,
74 const char*,
75 const char* subname = nullptr,
76 const Gui::HighlightMode& m = HighlightMode::UserDefined
77 );
78 bool hasObject(const char*) const;
79 void objectDeleted(const ViewProviderDocumentObject& viewProviderIn);
80 bool hasObject(App::DocumentObject* obj, const char*, const char* subname = nullptr) const;
81
82 App::DocumentObject* getObjectWithExtension(Base::Type extensionTypeId) const;
83
84 private:
85 struct ObjectInfo;
86 void setHighlight(const ObjectInfo& info, Gui::HighlightMode mode, bool enable);
87 App::DocumentObject* getObject(
88 const ObjectInfo& info,
89 bool resolve,
90 App::DocumentObject** parent = nullptr,
91 std::string* subname = nullptr
92 ) const;
93 ObjectInfo getObjectInfo(App::DocumentObject* obj, const char* subname) const;
94
95 private:
96 struct ObjectInfo
97 {
98 App::DocumentObject* obj;
99 std::string subname;
100 };
101 std::map<std::string, ObjectInfo> _ObjectMap;
102 Document* _Doc;
103 };
104
105 } // namespace Gui
106
107 static const char PDBODYKEY[] = "pdbody";
108 static const char PARTKEY[] = "part";
109 static const char ASSEMBLYKEY[] = "assembly";
110
111 #endif