67 #include "input_output/FGXMLElement.h" 73 IDENT(IdSrc,
"$Id: FGSwitch.cpp,v 1.29 2014/01/13 10:46:10 ehofman Exp $");
74 IDENT(IdHdr,ID_SWITCH);
83 struct test *current_test;
86 FGFCSComponent::bind();
95 current_test =
new struct test;
96 current_test->condition = 0;
98 current_test->setTestValue(value, Name, PropertyManager);
99 current_test->Default =
true;
100 if (delay > 0 && is_number(value)) {
101 for (
unsigned int i=0; i<delay-1; i++) {
102 output_array[i] = atof(value.c_str());
105 tests.push_back(current_test);
109 while (test_element) {
110 current_test =
new struct test;
111 current_test->condition =
new FGCondition(test_element, PropertyManager);
113 current_test->setTestValue(value, Name, PropertyManager);
114 tests.push_back(current_test);
125 for (
unsigned int i=0; i<tests.size(); i++) {
126 delete tests[i]->condition;
127 delete tests[i]->OutputProp;
139 double default_output=0.0;
141 for (
unsigned int i=0; i<tests.size(); i++) {
142 if (tests[i]->Default) {
143 default_output = tests[i]->GetValue();
145 pass = tests[i]->condition->Evaluate();
149 Output = tests[i]->GetValue();
154 if (!pass) Output = default_output;
156 if (delay != 0) Delay();
158 if (IsOutput) SetOutput();
182 void FGSwitch::Debug(
int from)
184 string comp, scratch;
188 if (debug_lvl <= 0)
return;
192 for (
unsigned int i=0; i<tests.size(); i++) {
193 if (tests[i]->Default) {
194 if (tests[i]->OutputProp == 0) {
195 cout <<
" Switch default value is: " << tests[i]->OutputVal;
197 cout <<
" Switch default value is: " << tests[i]->OutputProp->GetName();
200 if (tests[i]->OutputProp == 0) {
201 cout <<
" Switch takes test " << i <<
" value (" << tests[i]->OutputVal <<
")" << endl;
203 cout <<
" Switch takes test " << i <<
" value (" << tests[i]->OutputProp->GetName() <<
")" << endl;
205 tests[i]->condition->PrintCondition(
" ");
210 for (
unsigned int i=0; i<OutputNodes.size(); i++)
211 cout <<
" OUTPUT: " << OutputNodes[i]->getName() << endl;
215 if (debug_lvl & 2 ) {
216 if (from == 0) cout <<
"Instantiated: FGSwitch" << endl;
217 if (from == 1) cout <<
"Destroyed: FGSwitch" << endl;
219 if (debug_lvl & 4 ) {
221 if (debug_lvl & 8 ) {
223 if (debug_lvl & 16) {
225 if (debug_lvl & 64) {
227 cout << IdSrc << endl;
228 cout << IdHdr << endl;
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * FindElement(const std::string &el="")
Searches for a specified element.
bool Run(void)
Executes the switch logic.
unsigned int GetNumElements(void)
Returns the number of child elements for this element.
Encapsulates the Flight Control System (FCS) functionality.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
Base class for JSBSim Flight Control System Components.
Encapsulates a condition, which is used in parts of JSBSim including switches.