]> git.mxchange.org Git - flightgear.git/blob - src/FDM/JSBSim/input_output/FGOutputType.h
Fix for bug 1304 - crash loading XML route
[flightgear.git] / src / FDM / JSBSim / input_output / FGOutputType.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3  Header:       FGOutputType.h
4  Author:       Bertrand Coconnier
5  Date started: 09/10/11
6
7  ------------- Copyright (C) 2011 Bertrand Coconnier -------------
8
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
17  details.
18
19  You should have received a copy of the GNU Lesser General Public License along with
20  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21  Place - Suite 330, Boston, MA  02111-1307, USA.
22
23  Further information about the GNU Lesser General Public License can also be found on
24  the world wide web at http://www.gnu.org.
25
26 HISTORY
27 --------------------------------------------------------------------------------
28 09/10/11   BC    Created
29
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31 SENTRY
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
33
34 #ifndef FGOUTPUTTYPE_H
35 #define FGOUTPUTTYPE_H
36
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38 INCLUDES
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
40
41 #include "models/FGModel.h"
42
43 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
44 DEFINITIONS
45 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
46
47 #define ID_OUTPUTTYPE "$Id: FGOutputType.h,v 1.5 2013/01/26 17:06:49 bcoconni Exp $"
48
49 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
50 FORWARD DECLARATIONS
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
52
53 namespace JSBSim {
54
55 class FGFDMExec;
56 class Element;
57 class FGAerodynamics;
58 class FGAuxiliary;
59 class FGAircraft;
60 class FGAtmosphere;
61 class FGWinds;
62 class FGPropulsion;
63 class FGMassBalance;
64 class FGPropagate;
65 class FGAccelerations;
66 class FGFCS;
67 class FGGroundReactions;
68 class FGExternalReactions;
69 class FGBuoyantForces;
70
71 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72 CLASS DOCUMENTATION
73 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
74
75 /** Abstract class to provide functions generic to all the output directives.
76     This class is used by the output manager FGOutput to manage a list of
77     different output classes without needing to know the details of each one of
78     them. It also provides the functions that are common to all the output
79     classes.
80
81     The class inherits from FGModelFunctions so it is possible to define
82     functions that execute before or after the output is generated. Such
83     functions need to be tagged with a "pre" or "post" type attribute to denote
84     the sequence in which they should be executed.
85
86     The class mimics some functionalities of FGModel (methods InitModel(),
87     Run() and SetRate()). However it does not inherit from FGModel since it is
88     conceptually different from the model paradigm.
89  */
90
91 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 CLASS DECLARATION
93 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94
95 class FGOutputType : public FGModel
96 {
97 public:
98   /** Constructor (implement the FGModel interface).
99       @param fdmex a pointer to the parent executive object
100    */
101   FGOutputType(FGFDMExec* fdmex);
102
103   /// Destructor
104   virtual ~FGOutputType();
105
106   /** Set the idx for this output instance
107       @param idx ID of the output instance that is constructed
108    */
109   void SetIdx(int idx);
110
111   /** Set the output rate for this output instances.
112       @param rtHz new output rate in Hz */
113   void SetRate(double rtHz);
114
115   /** Set the activated subsystems for this output instance.
116       @param subSystems bitfield that describes the activated subsystems
117       @param outputProperties list of properties that should be output
118   */
119   void SetSubSystems(int subSystems) { SubSystems = subSystems; }
120
121   /** Set the list of properties that should be output for this output instance.
122       @param outputProperties list of properties that should be output
123   */
124   void SetOutputProperties(std::vector<FGPropertyNode_ptr> & outputProperties)
125   {
126     OutputProperties = outputProperties;
127   }
128
129   /** Overwrites the name identifier under which the output will be logged.
130       This method is taken into account if it is called before
131       FGFDMExec::RunIC() otherwise it is ignored until the next call to
132       SetStartNewOutput().
133       @param name new name */
134   virtual void SetOutputName(const std::string& name) { Name = name; }
135
136   /** Get the name identifier to which the output will be directed.
137       @result the name identifier.*/
138   virtual const std::string& GetOutputName(void) const { return Name; }
139
140   /** Init the output directives from an XML file (implement the FGModel interface).
141       @param element XML Element that is pointing to the output directives
142   */
143   virtual bool Load(Element* el);
144
145   /// Init the output model according to its configitation.
146   virtual bool InitModel(void);
147
148   /** Executes the output directives (implement the FGModel interface).
149       This method checks that the current time step matches the output
150       rate and calls the registered "pre" functions, the output
151       generation and finally the "post" functions.
152       @result false if no error.
153    */
154   bool Run(bool Holding);
155
156   /** Generate the output. This is a pure method so it must be implemented by
157       the classes that inherits from FGOutputType. The Print name may not be
158       relevant to all outputs but it has been kept for backward compatibility.
159    */
160   virtual void Print(void) = 0;
161
162   /** Reset the output prior to a restart of the simulation. This method should
163       be called when the simulation is restarted with, for example, new initial
164       conditions. When this method is executed the output instance can take
165       special actions such as closing the current output file and open a new
166       one with a different name. */
167
168   virtual void SetStartNewOutput(void) {}
169
170   /// Enables the output generation.
171   void Enable(void) { enabled = true; }
172   /// Disables the output generation.
173   void Disable(void) { enabled = false; }
174   /** Toggles the output generation.
175       @result the output generation status i.e. true if the output has been
176               enabled, false if the output has been disabled. */
177   bool Toggle(void) {enabled = !enabled; return enabled;}
178
179   /// Subsystem types for specifying which will be output in the FDM data logging
180   enum  eSubSystems {
181     /** Subsystem: Simulation (= 1)          */ ssSimulation      = 1,
182     /** Subsystem: Aerosurfaces (= 2)        */ ssAerosurfaces    = 2,
183     /** Subsystem: Body rates (= 4)          */ ssRates           = 4,
184     /** Subsystem: Velocities (= 8)          */ ssVelocities      = 8,
185     /** Subsystem: Forces (= 16)             */ ssForces          = 16,
186     /** Subsystem: Moments (= 32)            */ ssMoments         = 32,
187     /** Subsystem: Atmosphere (= 64)         */ ssAtmosphere      = 64,
188     /** Subsystem: Mass Properties (= 128)   */ ssMassProps       = 128,
189     /** Subsystem: Coefficients (= 256)      */ ssAeroFunctions   = 256,
190     /** Subsystem: Propagate (= 512)         */ ssPropagate       = 512,
191     /** Subsystem: Ground Reactions (= 1024) */ ssGroundReactions = 1024,
192     /** Subsystem: FCS (= 2048)              */ ssFCS             = 2048,
193     /** Subsystem: Propulsion (= 4096)       */ ssPropulsion      = 4096
194   } subsystems;
195
196 protected:
197   int OutputIdx;
198   int SubSystems;
199   std::vector <FGPropertyNode_ptr> OutputProperties;
200   std::vector <std::string> OutputCaptions;
201   bool enabled;
202
203   FGAerodynamics* Aerodynamics;
204   FGAuxiliary* Auxiliary;
205   FGAircraft* Aircraft;
206   FGAtmosphere* Atmosphere;
207   FGWinds* Winds;
208   FGPropulsion* Propulsion;
209   FGMassBalance* MassBalance;
210   FGPropagate* Propagate;
211   FGAccelerations* Accelerations;
212   FGFCS* FCS;
213   FGGroundReactions* GroundReactions;
214   FGExternalReactions* ExternalReactions;
215   FGBuoyantForces* BuoyantForces;
216
217   void Debug(int from);
218 };
219 }
220 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221 #endif