JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGInputType.cpp
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Module: FGInputType.cpp
4  Author: Paul Chavent
5  Date started: 01/20/15
6  Purpose: Manage input of sim parameters to file or stdout
7 
8  ------------- Copyright (C) 2015 Paul Chavent -------------
9 
10  This program is free software; you can redistribute it and/or modify it under
11  the terms of the GNU Lesser General Public License as published by the Free Software
12  Foundation; either version 2 of the License, or (at your option) any later
13  version.
14 
15  This program is distributed in the hope that it will be useful, but WITHOUT
16  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18  details.
19 
20  You should have received a copy of the GNU Lesser General Public License along with
21  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22  Place - Suite 330, Boston, MA 02111-1307, USA.
23 
24  Further information about the GNU Lesser General Public License can also be found on
25  the world wide web at http://www.gnu.org.
26 
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29 This is the place where you create input routines to dump data for perusal
30 later.
31 
32 HISTORY
33 --------------------------------------------------------------------------------
34 01/20/15 PC Created
35 
36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 
40 #include <ostream>
41 
42 #include "FGFDMExec.h"
43 #include "FGInputType.h"
44 #include "input_output/FGXMLElement.h"
45 #include "input_output/FGPropertyManager.h"
46 
47 namespace JSBSim {
48 
49 IDENT(IdSrc,"$Id: FGInputType.cpp,v 1.4 2015/08/23 09:43:31 bcoconni Exp $");
50 IDENT(IdHdr,ID_INPUTTYPE);
51 
52 using namespace std;
53 
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 CLASS IMPLEMENTATION
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 
59  FGModel(fdmex),
60  enabled(true)
61 {
62  Debug(0);
63 }
64 
65 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66 
68 {
69  Debug(1);
70 }
71 
72 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73 
74 void FGInputType::SetIdx(unsigned int idx)
75 {
76  InputIdx = idx;
77 }
78 
79 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 
81 bool FGInputType::Load(Element* element)
82 {
83  // Perform base class Load.
84  if(!FGModel::Load(element))
85  return false;
86 
87  // no common attributes yet (see FGOutputType for example
88 
89  // FIXME : PostLoad should be called in the most derived class ?
90  PostLoad(element, PropertyManager);
91 
92  return true;
93 }
94 
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 
98 {
99  bool ret = FGModel::InitModel();
100 
101  Debug(2);
102  return ret;
103 }
104 
105 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
106 
107 bool FGInputType::Run(bool Holding)
108 {
109  if (FGModel::Run(Holding)) return true;
110  if (!enabled) return true;
111 
112  RunPreFunctions();
113  Read(Holding);
114  RunPostFunctions();
115 
116  Debug(4);
117 
118  return false;
119 }
120 
121 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122 // The bitmasked value choices are as follows:
123 // unset: In this case (the default) JSBSim would only print
124 // out the normally expected messages, essentially echoing
125 // the config files as they are read. If the environment
126 // variable is not set, debug_lvl is set to 1 internally
127 // 0: This requests JSBSim not to input any messages
128 // whatsoever.
129 // 1: This value explicity requests the normal JSBSim
130 // startup messages
131 // 2: This value asks for a message to be printed out when
132 // a class is instantiated
133 // 4: When this value is set, a message is displayed when a
134 // FGModel object executes its Run() method
135 // 8: When this value is set, various runtime state variables
136 // are printed out periodically
137 // 16: When set various parameters are sanity checked and
138 // a message is printed out when they go out of bounds
139 
140 void FGInputType::Debug(int from)
141 {
142  if (debug_lvl <= 0) return;
143 
144  if (debug_lvl & 1) { // Standard console startup message input
145  if (from == 0) { // Constructor
146 
147  }
148  if (from == 2) {
149  }
150  }
151  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
152  if (from == 0) cout << "Instantiated: FGInputType" << endl;
153  if (from == 1) cout << "Destroyed: FGInputType" << endl;
154  }
155  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
156  }
157  if (debug_lvl & 8 ) { // Runtime state variables
158  }
159  if (debug_lvl & 16) { // Sanity checking
160  }
161  if (debug_lvl & 64) {
162  if (from == 0) { // Constructor
163  cout << IdSrc << endl;
164  cout << IdHdr << endl;
165  }
166  }
167 }
168 }
virtual bool Load(Element *el)
Init the input directives from an XML file (implement the FGModel interface).
Definition: FGInputType.cpp:81
void SetIdx(unsigned int idx)
Set the idx for this input instance.
Definition: FGInputType.cpp:74
STL namespace.
virtual ~FGInputType()
Destructor.
Definition: FGInputType.cpp:67
virtual bool Run(bool Holding)
Runs the model; called by the Executive.
Definition: FGModel.cpp:92
Base class for all scheduled JSBSim models.
Definition: FGModel.h:74
virtual void Read(bool Holding)=0
Generate the input.
bool Run(bool Holding)
Executes the input directives (implement the FGModel interface).
virtual bool InitModel(void)
Init the input model according to its configitation.
Definition: FGInputType.cpp:97
Encapsulates the JSBSim simulation executive.
Definition: FGFDMExec.h:189
FGInputType(FGFDMExec *fdmex)
Constructor (implement the FGModel interface).
Definition: FGInputType.cpp:58
virtual bool Load(Element *el)
Loads this model.
Definition: FGModel.cpp:113