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
FGPropertyReader.cpp
1/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2
3 Module: FGPropertyReader.cpp
4 Author: Bertrand Coconnier
5 Date started: 12/30/13
6 Purpose: Read and manage properties from XML data
7
8 ------------- Copyright (C) 2013 Bertrand Coconnier -------------
9
10 This program is free software; you can redistribute it and/or modify it under
11 the terms of the GNU Lesser General Public License as published by the Free Software
12 Foundation; either version 2 of the License, or (at your option) any later
13 version.
14
15 This program is distributed in the hope that it will be useful, but WITHOUT
16 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
18 details.
19
20 You should have received a copy of the GNU Lesser General Public License along with
21 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
22 Place - Suite 330, Boston, MA 02111-1307, USA.
23
24 Further information about the GNU Lesser General Public License can also be found on
25 the world wide web at http://www.gnu.org.
26
27FUNCTIONAL DESCRIPTION
28--------------------------------------------------------------------------------
29This class reads and manages properties defined in XML data
30
31HISTORY
32--------------------------------------------------------------------------------
3312/30/13 BC Created
34
35%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36INCLUDES
37%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
38
39#include "FGPropertyReader.h"
40#include "FGPropertyManager.h"
41#include "FGXMLElement.h"
42#include "FGJSBBase.h"
43
44using namespace std;
45
46namespace JSBSim {
47
48/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
49CLASS IMPLEMENTATION
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
51
52//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53
54bool FGPropertyReader::ResetToIC(void)
55{
56 for (auto v: interface_prop_initial_value) {
57 SGPropertyNode* node = v.first;
58 if (!node->getAttribute(SGPropertyNode::PRESERVE))
59 node->setDoubleValue(v.second);
60 }
61
62 return true;
63}
64
65//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66
67void FGPropertyReader::Load(Element* el, FGPropertyManager* PM, bool override_props)
68{
69 Element *property_element = el->FindElement("property");
70 if (property_element && FGJSBBase::debug_lvl > 0) {
71 FGLogging log(LogLevel::DEBUG);
72 log << "\n ";
73 if (override_props)
74 log << "Overriding";
75 else
76 log << "Declared";
77 log << " properties\n\n";
78 }
79
80 while (property_element) {
81 SGPropertyNode* node = nullptr;
82 double value=0.0;
83 bool has_value_attribute = !property_element->GetAttributeValue("value").empty();
84
85 if (has_value_attribute)
86 value = property_element->GetAttributeValueAsNumber("value");
87
88 string interface_property_string = property_element->GetDataLine();
89 if (PM->HasNode(interface_property_string)) {
90 node = PM->GetNode(interface_property_string);
91 if (override_props) {
92
93 if (FGJSBBase::debug_lvl > 0) {
94 FGXMLLogging log(property_element, LogLevel::DEBUG);
95 if (interface_prop_initial_value.find(node) == interface_prop_initial_value.end()) {
96 log << " The following property will be overridden but it has not been\n"
97 << " defined in the current model '" << el->GetName() << "'\n";
98 }
99
100 log << " " << "Overriding value for property " << interface_property_string
101 << "\n (old value: " << node->getDoubleValue()
102 << " new value: " << value << ")\n\n";
103 }
104
105 node->setDoubleValue(value);
106 }
107 else {
108 if (has_value_attribute) {
109 FGXMLLogging log(property_element, LogLevel::WARN);
110 log << " Property " << interface_property_string
111 << " is already defined.\n"
112 << " Its value (" << node->getDoubleValue() << ") will not"
113 << " be overridden.\n";
114 }
115 property_element = el->FindNextElement("property");
116 continue;
117 }
118 } else {
119 node = PM->GetNode(interface_property_string, true);
120 if (node) {
121 node->setDoubleValue(value);
122
123 if (FGJSBBase::debug_lvl > 0) {
124 FGLogging log(LogLevel::DEBUG);
125 log << " " << interface_property_string << " (initial value: "
126 << value << ")\n\n";
127 }
128 }
129 else {
130 FGXMLLogging log(property_element, LogLevel::ERROR);
131 log << "Could not create property " << interface_property_string << "\n";
132 property_element = el->FindNextElement("property");
133 continue;
134 }
135 }
136 interface_prop_initial_value[node] = value;
137 if (property_element->GetAttributeValue("persistent") == string("true"))
138 node->setAttribute(SGPropertyNode::PRESERVE, true);
139
140 property_element = el->FindNextElement("property");
141 }
142
143 // End of interface property loading logic
144}
145}
A node in a property tree.
Definition props.hxx:747
bool getAttribute(Attribute attr) const
Check a single mode attribute for the property node.
Definition props.hxx:1125
void setAttribute(Attribute attr, bool state)
Set a single mode attribute for the property node.
Definition props.hxx:1131
double getDoubleValue() const
Get a double value for this node.
bool setDoubleValue(double value)
Set a double value for this node.
Main namespace for the JSBSim Flight Dynamics Model.
Definition FGFDMExec.cpp:71