JSBSim Flight Dynamics Model 1.3.0 (09 Apr 2026)
An Open Source Flight Dynamics and Control Software Library in C++
Loading...
Searching...
No Matches
FGDistributor.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGDistributor.cpp
4 Author: Jon S. Berndt
5 Date started: 9/2013
6
7 ------------- Copyright (C) 2013 -------------
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
11 Software Foundation; either version 2 of the License, or (at your option) any
12 later 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
20 with this program; if not, write to the Free Software Foundation, Inc., 59
21 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22
23 Further information about the GNU Lesser General Public License can also be
24 found on the world wide web at http://www.gnu.org.
25
26FUNCTIONAL DESCRIPTION
27--------------------------------------------------------------------------------
28
29HISTORY
30--------------------------------------------------------------------------------
31
32%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33COMMENTS, REFERENCES, and NOTES
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
36Also, see the header file (FGDistributor.h) for further details.
37
38%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39INCLUDES
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41
42#include "FGDistributor.h"
43#include "models/FGFCS.h"
44#include "input_output/FGLog.h"
45
46using namespace std;
47
48namespace JSBSim {
49
50/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51CLASS IMPLEMENTATION
52%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
53
55 : FGFCSComponent(fcs, element)
56{
57 auto PropertyManager = fcs->GetPropertyManager();
58
59 bind(element, PropertyManager.get()); // Bind() this component here in case it is used in its own
60 // definition for a sample-and-hold
61
62 string type_string = element->GetAttributeValue("type");
63 if (type_string == "inclusive") Type = eInclusive;
64 else if (type_string == "exclusive") Type = eExclusive;
65 else {
66 XMLLogException err(element);
67 err << "Distributor type should be \"inclusive\" or \"exclusive\""
68 << " but got \"" << type_string << "\" instead.\n";
69 throw err;
70 }
71
72 Element* case_element = element->FindElement("case");
73 while (case_element) {
74 auto current_case = make_unique<Case>();
75 Element* test_element = case_element->FindElement("test");
76 try {
77 if (test_element) current_case->SetTest(test_element, PropertyManager);
78 } catch (XMLLogException&) {
79 throw;
80 } catch (LogException& e) {
81 throw XMLLogException(e, test_element);
82 } catch (const BaseException& e) {
83 XMLLogException err(test_element);
84 err << LogFormat::RED << e.what() << LogFormat::RESET << "\n\n";
85 throw err;
86 }
87 Element* prop_val_element = case_element->FindElement("property");
88 while (prop_val_element) {
89 string value_string = prop_val_element->GetAttributeValue("value");
90 string property_string = prop_val_element->GetDataLine();
91 current_case->AddPropValPair(property_string, value_string, PropertyManager,
92 prop_val_element);
93 prop_val_element = case_element->FindNextElement("property");
94 }
95 Cases.push_back(std::move(current_case));
96 case_element = element->FindNextElement("case");
97 }
98
99 Debug(0);
100}
101
102//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
105{
106 bool completed = false;
107 for (auto& Case: Cases) { // Loop through all Cases
108 if (Case->HasTest()) {
109 if (Case->GetTestResult() && !((Type == eExclusive) && completed)) {
110 Case->SetPropValPairs();
111 completed = true;
112 }
113 } else { // If no test present, execute always
114 Case->SetPropValPairs();
115 }
116 }
117
118 return true;
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 output any messages
128// whatsoever.
129// 1: This value explicitly 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
140void FGDistributor::Debug(int from)
141{
142 if (debug_lvl <= 0) return;
143
144 if (debug_lvl & 1) { // Standard console startup message output
145 if (from == 0) { // Constructor
146 FGLogging log(LogLevel::DEBUG);
147 unsigned int ctr=0;
148 for (const auto& Case: Cases) {
149 log << " Case: " << fixed << ctr << "\n";
150 if (Case->HasTest()) {
151 Case->GetTest().PrintCondition(" ");
152 } else {
153 log << " Set these properties by default: \n";
154 }
155 log << "\n";
156 for (const auto& propVal: *Case) {
157 log << " Set property " << propVal->GetPropName();
158 if (propVal->GetLateBoundProp()) log << " (late bound)";
159 log << " to " << propVal->GetValString();
160 if (propVal->GetLateBoundValue()) log << " (late bound)";
161 log << "\n";
162 }
163 ctr++;
164 }
165 }
166 }
167 if (debug_lvl & 2 ) { // Instantiation/Destruction notification
168 FGLogging log(LogLevel::DEBUG);
169 if (from == 0) log << "Instantiated: FGDistributor\n";
170 if (from == 1) log << "Destroyed: FGDistributor\n";
171 }
172 if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
173 }
174 if (debug_lvl & 8 ) { // Runtime state variables
175 }
176 if (debug_lvl & 16) { // Sanity checking
177 }
178 if (debug_lvl & 64) {
179 if (from == 0) { // Constructor
180 }
181 }
182}
183
184} //namespace JSBSim
Element * FindElement(const std::string &el="")
Searches for a specified element.
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
Element * FindNextElement(const std::string &el="")
Searches for the next element as specified.
FGDistributor(FGFCS *fcs, Element *element)
Constructor.
bool Run(void) override
Executes the distributor logic.
Base class for JSBSim Flight Control System Components.
Encapsulates the Flight Control System (FCS) functionality.
Definition FGFCS.h:189
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71