File size: 3,925 Bytes
985c397
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/**************************************************************************
 *   Copyright (c) 2014 Jürgen Riegel <juergen.riegel@web.de>              *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU Library General Public License (LGPL)   *
 *   as published by the Free Software Foundation; either version 2 of     *
 *   the License, or (at your option) any later version.                   *
 *   for detail see the LICENCE text file.                                 *
 *                                                                         *
 *   FreeCAD is distributed in the hope that it will be useful,            *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with FreeCAD; if not, write to the Free Software        *
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
 *   USA                                                                   *
 *                                                                         *
 ***************************************************************************/


#ifndef GUI_ActiveObjectList_H
#define GUI_ActiveObjectList_H

#include <map>
#include <string>
#include <Base/Type.h>
#include <Gui/TreeItemMode.h>
#include <FCGlobal.h>


namespace App
{
class DocumentObject;
}

namespace Gui
{
class Document;
class ViewProviderDocumentObject;

/** List of active or special objects
 * This class holds a list of objects with a special name.
 * Its mainly used to points to something like the active Body or Part in a edit session.
 * The class is used the viewer (editor) of a document.
 * @see Gui::MDIViewer
 * @author Jürgen Riegel
 */
class GuiExport ActiveObjectList
{
public:
    explicit ActiveObjectList(Document* doc)
        : _Doc(doc)
    {}

    template<typename _T>
    inline _T getObject(
        const char* name,
        App::DocumentObject** parent = nullptr,
        std::string* subname = nullptr
    ) const
    {
        auto it = _ObjectMap.find(name);
        if (it == _ObjectMap.end()) {
            return 0;
        }
        return dynamic_cast<_T>(getObject(it->second, true, parent, subname));
    }
    void setObject(
        App::DocumentObject*,
        const char*,
        const char* subname = nullptr,
        const Gui::HighlightMode& m = HighlightMode::UserDefined
    );
    bool hasObject(const char*) const;
    void objectDeleted(const ViewProviderDocumentObject& viewProviderIn);
    bool hasObject(App::DocumentObject* obj, const char*, const char* subname = nullptr) const;

    App::DocumentObject* getObjectWithExtension(Base::Type extensionTypeId) const;

private:
    struct ObjectInfo;
    void setHighlight(const ObjectInfo& info, Gui::HighlightMode mode, bool enable);
    App::DocumentObject* getObject(
        const ObjectInfo& info,
        bool resolve,
        App::DocumentObject** parent = nullptr,
        std::string* subname = nullptr
    ) const;
    ObjectInfo getObjectInfo(App::DocumentObject* obj, const char* subname) const;

private:
    struct ObjectInfo
    {
        App::DocumentObject* obj;
        std::string subname;
    };
    std::map<std::string, ObjectInfo> _ObjectMap;
    Document* _Doc;
};

}  // namespace Gui

static const char PDBODYKEY[] = "pdbody";
static const char PARTKEY[] = "part";

#endif