FlightGear next
modelmgr.hxx
Go to the documentation of this file.
1// model-mgr.hxx - manage user-specified 3D models.
2// Written by David Megginson, started 2002.
3//
4// This file is in the Public Domain, and comes with no warranty.
5
6#ifndef __MODELMGR_HXX
7#define __MODELMGR_HXX 1
8
9#include <vector>
10#include <memory>
11
12#include <simgear/compiler.h> // for SG_USING_STD
13#include <simgear/structure/subsystem_mgr.hxx>
14
16
17// Don't pull in headers, since we don't need them here.
18class SGPropertyNode;
19class SGModelPlacement;
20
21
25class FGModelMgr : public SGSubsystem
26{
27public:
28
42 struct Instance
43 {
44 virtual ~Instance ();
45 SGModelPlacement * model = nullptr;
46 SGPropertyNode_ptr node;
47 SGPropertyNode_ptr lon_deg_node;
48 SGPropertyNode_ptr lat_deg_node;
49 SGPropertyNode_ptr elev_ft_node;
50 SGPropertyNode_ptr roll_deg_node;
51 SGPropertyNode_ptr pitch_deg_node;
52 SGPropertyNode_ptr heading_deg_node;
53 SGPropertyNode_ptr loaded_node;
54 bool shadow = false;
55
56 bool checkLoaded() const;
57 };
58
59 FGModelMgr ();
60 virtual ~FGModelMgr ();
61
62 // Subsystem API.
63 void bind() override;
64 void init() override;
65 void shutdown() override;
66 void unbind() override;
67 void update(double dt) override;
68
69 // Subsystem identification.
70 static const char* staticSubsystemClassId() { return "model-manager"; }
71
72 virtual void add_model (SGPropertyNode * node);
73
84 virtual void add_instance (Instance * instance);
85
86
92 virtual void remove_instance (Instance * instance);
93
94
101 Instance* findInstanceByNodePath(const std::string& nodePath) const;
102
103private:
107 class Listener : public SGPropertyChangeListener
108 {
109 public:
110 Listener(FGModelMgr *mgr) : _mgr(mgr) {}
111 virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child);
112 virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child);
113
114 private:
115 FGModelMgr * _mgr;
116 };
117
118 SGPropertyNode_ptr _models;
119 std::unique_ptr<Listener> _listener;
120
121 std::vector<Instance *> _instances;
122};
123
124#endif // __MODELMGR_HXX
Manage a list of user-specified models.
Definition modelmgr.hxx:26
virtual ~FGModelMgr()
Definition modelmgr.cxx:90
static const char * staticSubsystemClassId()
Definition modelmgr.hxx:70
void init() override
Definition modelmgr.cxx:95
virtual void add_instance(Instance *instance)
Add an instance of a dynamic model to the manager.
Definition modelmgr.cxx:310
virtual void remove_instance(Instance *instance)
Remove an instance of a dynamic model from the manager.
Definition modelmgr.cxx:316
void unbind() override
Definition modelmgr.cxx:241
Instance * findInstanceByNodePath(const std::string &nodePath) const
Finds an instance in the model manager from a given node path in the property tree.
Definition modelmgr.cxx:329
virtual void add_model(SGPropertyNode *node)
Definition modelmgr.cxx:121
void update(double dt) override
Definition modelmgr.cxx:264
void shutdown() override
Definition modelmgr.cxx:103
void bind() override
Definition modelmgr.cxx:232
A dynamically-placed model using properties.
Definition modelmgr.hxx:43
SGPropertyNode_ptr pitch_deg_node
Definition modelmgr.hxx:51
bool checkLoaded() const
Definition modelmgr.cxx:358
SGModelPlacement * model
Definition modelmgr.hxx:45
SGPropertyNode_ptr roll_deg_node
Definition modelmgr.hxx:50
SGPropertyNode_ptr lon_deg_node
Definition modelmgr.hxx:47
SGPropertyNode_ptr node
Definition modelmgr.hxx:46
SGPropertyNode_ptr heading_deg_node
Definition modelmgr.hxx:52
SGPropertyNode_ptr loaded_node
Definition modelmgr.hxx:53
SGPropertyNode_ptr lat_deg_node
Definition modelmgr.hxx:48
SGPropertyNode_ptr elev_ft_node
Definition modelmgr.hxx:49