JSBSim Flight Dynamics Model  1.0 (02 March 2017)
An Open Source Flight Dynamics and Control Software Library in C++
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 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 FUNCTIONAL DESCRIPTION
27 --------------------------------------------------------------------------------
28 
29 HISTORY
30 --------------------------------------------------------------------------------
31 
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 COMMENTS, REFERENCES, and NOTES
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 
36 Also, see the header file (FGDistributor.h) for further details.
37 
38 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 INCLUDES
40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
41 
42 #include <iostream>
43 
44 #include "FGDistributor.h"
45 #include "input_output/FGXMLElement.h"
46 
47 using namespace std;
48 
49 namespace JSBSim {
50 
51 IDENT(IdSrc,"$Id: FGDistributor.cpp,v 1.7 2015/02/27 20:46:01 bcoconni Exp $");
52 IDENT(IdHdr,ID_DISTRIBUTOR);
53 
54 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55 CLASS IMPLEMENTATION
56 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
57 
58 FGDistributor::FGDistributor(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element)
59 {
60  Element *case_element=0;
61  Element* test_element=0;
62  Element* prop_val_element=0;
63  string type_string;
64  Case* current_case=0;
65 
66  FGFCSComponent::bind(); // Bind() this component here in case it is used
67  // in its own definition for a sample-and-hold
68 
69  type_string = element->GetAttributeValue("type");
70  if (type_string == "inclusive") Type = eInclusive;
71  else if (type_string == "exclusive") Type = eExclusive;
72  else {
73  throw("Not a known Distributor type, "+type_string);
74  }
75 
76  case_element = element->FindElement("case");
77  while (case_element) {
78  current_case = new Case;
79  test_element = case_element->FindElement("test");
80  if (test_element) current_case->SetTest(new FGCondition(test_element, PropertyManager));
81  prop_val_element = case_element->FindElement("property");
82  while (prop_val_element) {
83  string value_string = prop_val_element->GetAttributeValue("value");
84  string property_string = prop_val_element->GetDataLine();
85  current_case->AddPropValPair(new PropValPair(property_string, value_string, PropertyManager));
86  prop_val_element = case_element->FindNextElement("property");
87  }
88  Cases.push_back(current_case);
89  case_element = element->FindNextElement("case");
90  }
91 
92  Debug(0);
93 }
94 
95 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 
98 {
99 
100  Debug(1);
101 }
102 
103 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 
106 {
107  bool completed = false;
108  for (unsigned int ctr=0; ctr<Cases.size(); ctr++) { // Loop through all Cases
109  if (Cases[ctr]->HasTest()) {
110  if (Cases[ctr]->GetTestResult() && !((Type == eExclusive) && completed)) {
111  Cases[ctr]->SetPropValPairs();
112  completed = true;
113  }
114  } else { // If no test present, execute always
115  Cases[ctr]->SetPropValPairs();
116  }
117  }
118 
119 // if (delay != 0) Delay();
120 // Clip();
121 // if (IsOutput) SetOutput();
122 
123  return true;
124 }
125 
126 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
127 // The bitmasked value choices are as follows:
128 // unset: In this case (the default) JSBSim would only print
129 // out the normally expected messages, essentially echoing
130 // the config files as they are read. If the environment
131 // variable is not set, debug_lvl is set to 1 internally
132 // 0: This requests JSBSim not to output any messages
133 // whatsoever.
134 // 1: This value explicity requests the normal JSBSim
135 // startup messages
136 // 2: This value asks for a message to be printed out when
137 // a class is instantiated
138 // 4: When this value is set, a message is displayed when a
139 // FGModel object executes its Run() method
140 // 8: When this value is set, various runtime state variables
141 // are printed out periodically
142 // 16: When set various parameters are sanity checked and
143 // a message is printed out when they go out of bounds
144 
145 void FGDistributor::Debug(int from)
146 {
147  string comp, scratch;
148  string indent = " ";
149  //bool first = false;
150 
151  if (debug_lvl <= 0) return;
152 
153  if (debug_lvl & 1) { // Standard console startup message output
154  if (from == 0) { // Constructor
155  for (unsigned int ctr=0; ctr < Cases.size(); ctr++) {
156  std::cout << " Case: " << ctr << endl;
157  if (Cases[ctr]->GetTest() != 0) {
158  Cases[ctr]->GetTest()->PrintCondition(" ");
159  } else {
160  std::cout << " Set these properties by default: " << std::endl;
161  }
162  std::cout << std::endl;
163  for (unsigned int propCtr=0; propCtr < Cases[ctr]->GetNumPropValPairs(); propCtr++) {
164  std::cout << " Set property " << Cases[ctr]->GetPropValPair(propCtr)->GetPropName();
165  if (Cases[ctr]->GetPropValPair(propCtr)->GetPropNode() == 0) std::cout << " (late bound)";
166  std::cout << " to " << Cases[ctr]->GetPropValPair(propCtr)->GetValString();
167  if (Cases[ctr]->GetPropValPair(propCtr)->GetLateBoundValue()) std::cout << " (late bound)";
168  std::cout << std::endl;
169  }
170  }
171  }
172  }
173  if (debug_lvl & 2 ) { // Instantiation/Destruction notification
174  if (from == 0) cout << "Instantiated: FGDistributor" << endl;
175  if (from == 1) cout << "Destroyed: FGDistributor" << endl;
176  }
177  if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects
178  }
179  if (debug_lvl & 8 ) { // Runtime state variables
180  }
181  if (debug_lvl & 16) { // Sanity checking
182  }
183  if (debug_lvl & 64) {
184  if (from == 0) { // Constructor
185  cout << IdSrc << endl;
186  cout << IdHdr << endl;
187  }
188  }
189 }
190 
191 } //namespace JSBSim
192 
std::string GetAttributeValue(const std::string &key)
Retrieves an attribute.
~FGDistributor()
Destructor.
STL namespace.
Element * FindElement(const std::string &el="")
Searches for a specified element.
std::string GetDataLine(unsigned int i=0)
Gets a line of data belonging to an element.
Encapsulates the Flight Control System (FCS) functionality.
Definition: FGFCS.h:193
bool Run(void)
Executes the distributor logic.
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.
Definition: FGCondition.h:70