/
SceneGraph.h
125 lines (97 loc) · 3.61 KB
/
SceneGraph.h
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#pragma once
#include <map>
#include <list>
#include <sigc++/signal.h>
#include <sigc++/connection.h>
#include "iscenegraph.h"
#include "imodule.h"
#include "ispacepartition.h"
#include "imap.h"
#include "iundo.h"
namespace scene
{
/**
* Implementing class for the scenegraph.
*
* \ingroup scenegraph
* \see scene::Graph
*/
class SceneGraph :
public Graph,
public std::enable_shared_from_this<SceneGraph>
{
private:
typedef std::list<Graph::Observer*> ObserverList;
ObserverList _sceneObservers;
sigc::signal<void> _sigBoundsChanged;
// The root-element, the scenegraph starts here
IMapRootNodePtr _root;
// The space partitioning system
ISpacePartitionSystemPtr _spacePartition;
std::size_t _visitedSPNodes;
std::size_t _skippedSPNodes;
// During partition traversal all link/unlink calls are buffered and
// performed later on.
enum ActionType
{
Insert,
Erase,
BoundsChange,
};
typedef std::pair<ActionType, scene::INodePtr> NodeAction;
typedef std::list<NodeAction> BufferedActions;
BufferedActions _actionBuffer;
bool _traversalOngoing;
sigc::connection _undoEventHandler;
public:
SceneGraph();
~SceneGraph();
/** greebo: Adds/removes an observer from the scenegraph,
* to get notified upon insertions/deletions
*/
void addSceneObserver(Graph::Observer* observer) override;
void removeSceneObserver(Graph::Observer* observer) override;
// Triggers a call to all the connected Scene::Graph::Observers
void sceneChanged() override;
// Root node accessor methods
const IMapRootNodePtr& root() const override;
void setRoot(const IMapRootNodePtr& newRoot) override;
// greebo: Emits the "bounds changed" signal to all connected observers
// Note: these are the WorkZone and the SelectionSystem, AFAIK
void boundsChanged() override;
/// Return the boundsChanged signal
sigc::signal<void> signal_boundsChanged() const override;
void insert(const INodePtr& node) override;
void erase(const INodePtr& node) override;
void nodeBoundsChanged(const scene::INodePtr& node) override;
// Walker variants
void foreachNodeInVolume(const VolumeTest& volume, Walker& walker) override;
void foreachVisibleNodeInVolume(const VolumeTest& volume, Walker& walker) override;
// Lambda variants
void foreachNode(const INode::VisitorFunc& functor) override;
void foreachVisibleNode(const INode::VisitorFunc& functor) override;
void foreachNodeInVolume(const VolumeTest& volume, const INode::VisitorFunc& functor) override;
void foreachVisibleNodeInVolume(const VolumeTest& volume, const INode::VisitorFunc& functor) override;
ISpacePartitionSystemPtr getSpacePartition() override;
private:
void foreachNodeInVolume(const VolumeTest& volume, const INode::VisitorFunc& functor, bool visitHidden);
// Recursive method used to descend the SpacePartition tree, returns FALSE if the walker signaled stop
bool foreachNodeInVolume_r(const ISPNode& node, const VolumeTest& volume,
const INode::VisitorFunc& functor, bool visitHidden);
void flushActionBuffer();
void onUndoEvent(IUndoSystem::EventType type, const std::string& operationName);
};
typedef std::shared_ptr<SceneGraph> SceneGraphPtr;
// Type used to register the GlobalSceneGraph in the module registry
class SceneGraphModule :
public SceneGraph,
public RegisterableModule
{
public:
// RegisterableModule implementation
const std::string& getName() const;
const StringSet& getDependencies() const;
void initialiseModule(const IApplicationContext& ctx);
};
typedef std::shared_ptr<SceneGraphModule> SceneGraphModulePtr;
} // namespace scene