]> git.mxchange.org Git - flightgear.git/blob - src/Model/modelmgr.hxx
Improve transponder instrumentation: new version
[flightgear.git] / src / Model / modelmgr.hxx
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 #ifndef __cplusplus
10 # error This library requires C++
11 #endif
12
13 #include <vector>
14
15 #include <simgear/compiler.h>   // for SG_USING_STD
16 #include <simgear/structure/subsystem_mgr.hxx>
17
18 using std::vector;
19
20 // Don't pull in headers, since we don't need them here.
21 class SGPropertyNode;
22 class SGModelPlacement;
23
24
25 /**
26  * Manage a list of user-specified models.
27  */
28 class FGModelMgr : public SGSubsystem
29 {
30 public:
31
32   /**
33    * A dynamically-placed model using properties.
34    *
35    * The model manager uses the property nodes to update the model's
36    * position and orientation; any of the property node pointers may
37    * be set to zero to avoid update.  Normally, a caller should
38    * load the model by instantiating SGModelPlacement with the path
39    * to the model or its XML wrapper, then assign any relevant
40    * property node pointers.
41    *
42    * @see SGModelPlacement
43    * @see FGModelMgr#add_instance
44    */
45   struct Instance
46   {
47     Instance ();
48     virtual ~Instance ();
49     SGModelPlacement * model;
50     SGPropertyNode_ptr node;
51     SGPropertyNode_ptr lon_deg_node;
52     SGPropertyNode_ptr lat_deg_node;
53     SGPropertyNode_ptr elev_ft_node;
54     SGPropertyNode_ptr roll_deg_node;
55     SGPropertyNode_ptr pitch_deg_node;
56     SGPropertyNode_ptr heading_deg_node;
57     bool shadow;
58   };
59
60   FGModelMgr ();
61   virtual ~FGModelMgr ();
62
63   virtual void init ();
64   virtual void bind ();
65   virtual void unbind ();
66   virtual void update (double dt);
67
68   virtual void add_model (SGPropertyNode * node);
69
70   /**
71    * Add an instance of a dynamic model to the manager.
72    *
73    * NOTE: pointer ownership is transferred to the model manager!
74    *
75    * The caller is responsible for setting up the Instance structure
76    * as required.  The model manager will continuously update the
77    * location and orientation of the model based on the current
78    * values of the properties.
79    */
80   virtual void add_instance (Instance * instance);
81
82
83   /**
84    * Remove an instance of a dynamic model from the manager.
85    *
86    * NOTE: the manager will delete the instance as well.
87    */
88   virtual void remove_instance (Instance * instance);
89
90
91 private:
92   /**
93    * Listener class that adds models at runtime.
94    */
95   class Listener : public SGPropertyChangeListener
96   {
97   public:
98     Listener(FGModelMgr *mgr) : _mgr(mgr) {}
99     virtual void childAdded (SGPropertyNode * parent, SGPropertyNode * child);
100     virtual void childRemoved (SGPropertyNode * parent, SGPropertyNode * child);
101
102   private:
103     FGModelMgr * _mgr;
104   };
105
106   SGPropertyNode_ptr _models;
107   Listener * _listener;
108
109   vector<Instance *> _instances;
110
111 };
112
113 #endif // __MODELMGR_HXX