65#include "models/FGFCS.h"
66#include "math/FGCondition.h"
67#include "math/FGRealValue.h"
81 auto PropertyManager = fcs->GetPropertyManager();
83 bind(element, PropertyManager.get());
87 current_test =
new Test;
89 current_test->setTestValue(value, Name, PropertyManager, test_element);
90 current_test->Default =
true;
91 auto output_value = current_test->OutputValue.ptr();
92 if (delay > 0 &&
dynamic_cast<FGRealValue*
>(output_value)) {
93 double v = output_value->GetValue();
94 for (
unsigned int i=0; i<delay-1; i++) {
98 tests.push_back(current_test);
102 while (test_element) {
103 current_test =
new Test;
104 current_test->condition =
new FGCondition(test_element, PropertyManager);
106 current_test->setTestValue(value, Name, PropertyManager, test_element);
107 tests.push_back(current_test);
118 for (
auto test: tests) {
119 delete test->condition;
131 double default_output=0.0;
140 for (
auto test: tests) {
142 default_output = test->OutputValue->GetValue();
144 pass = test->condition->Evaluate();
148 Output = test->OutputValue->GetValue();
153 if (!pass) Output = default_output;
155 if (delay != 0) Delay();
164void FGSwitch::VerifyProperties(
void)
166 for (
auto test: tests) {
167 if (!test->Default) {
168 test->condition->Evaluate();
170 test->OutputValue->GetValue();
193void FGSwitch::Debug(
int from)
195 if (debug_lvl <= 0)
return;
200 for (
auto test: tests) {
202 cout <<
" Switch default value is: " << test->GetOutputName();
204 cout <<
" Switch takes test " << i <<
" value (" << test->GetOutputName() <<
")" << endl;
206 test->condition->PrintCondition(
" ");
211 for (
auto node: OutputNodes)
212 cout <<
" OUTPUT: " << node->getNameString() << 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) {
Element * FindElement(const std::string &el="")
Searches for a specified element.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
Encapsulates a condition, which is used in parts of JSBSim including switches.
Base class for JSBSim Flight Control System Components.
Encapsulates the Flight Control System (FCS) functionality.
FGSwitch(FGFCS *fcs, Element *element)
Constructor.
bool Run(void) override
Executes the switch logic.