JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
FGSwitch.h
1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 
3  Header: FGSwitch.h
4  Author: Jon S. Berndt
5  Date started: 12/23/2002
6 
7  ------------- Copyright (C) 2002 jon@jsbsim.org -------------
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 
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30 SENTRY
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
32 
33 #ifndef FGSWITCH_H
34 #define FGSWITCH_H
35 
36 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 INCLUDES
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 
40 #include <iostream>
41 #include <cstdlib>
42 
43 #include "FGFCSComponent.h"
44 #include "math/FGCondition.h"
45 #include "math/FGPropertyValue.h"
46 
47 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48 DEFINITIONS
49 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
50 
51 #define ID_SWITCH "$Id: FGSwitch.h,v 1.18 2013/11/24 11:40:57 bcoconni Exp $"
52 
53 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54 FORWARD DECLARATIONS
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
56 
57 namespace JSBSim {
58 
59 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 CLASS DOCUMENTATION
61 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
62 
133 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 CLASS DECLARATION
135 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
136 
137 class FGSwitch : public FGFCSComponent
138 {
139 public:
144  FGSwitch(FGFCS* fcs, Element* element);
145 
147  ~FGSwitch();
148 
151  bool Run(void);
152 
153 private:
154 
155  struct test {
156  FGCondition* condition;
157  bool Default;
158  double OutputVal;
159  FGPropertyValue *OutputProp;
160  float sign;
161 
162  double GetValue(void) {
163  if (OutputProp == 0L) return OutputVal;
164  else return OutputProp->GetValue()*sign;
165  }
166 
167  test(void) { // constructor for the test structure
168  Default = false;
169  OutputVal = 0.0;
170  OutputProp = 0L;
171  sign = 1.0;
172  }
173 
174  void setTestValue(std::string value, std::string Name,
175  FGPropertyManager* propMan)
176  {
177  if (value.empty()) {
178  std::cerr << "No VALUE supplied for switch component: " << Name << std::endl;
179  } else {
180  if (is_number(value)) {
181  OutputVal = atof(value.c_str());
182  } else {
183  // "value" must be a property if execution passes to here.
184  if (value[0] == '-') {
185  sign = -1.0;
186  value.erase(0,1);
187  } else {
188  sign = 1.0;
189  }
190  FGPropertyNode *node = propMan->GetNode(value, false);
191  if (node) {
192  OutputProp = new FGPropertyValue(node);
193  } else {
194  OutputProp = new FGPropertyValue(value, propMan);
195  }
196  }
197  }
198  }
199 
200  };
201 
202  std::vector <test*> tests;
203 
204  void Debug(int from);
205 };
206 }
207 #endif
~FGSwitch()
Destructor.
Definition: FGSwitch.cpp:123
Represents a property value which can use late binding.
FGSwitch(FGFCS *fcs, Element *element)
Constructor.
Definition: FGSwitch.cpp:80
Class wrapper for property handling.
bool Run(void)
Executes the switch logic.
Definition: FGSwitch.cpp:136
Encapsulates the Flight Control System (FCS) functionality.
Definition: FGFCS.h:193
Base class for JSBSim Flight Control System Components.
Encapsulates a condition, which is used in parts of JSBSim including switches.
Definition: FGCondition.h:70
Encapsulates a switch for the flight control system.
Definition: FGSwitch.h:137