1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 Module: FGPropertyReader.cpp
4 Author: Bertrand Coconnier
6 Purpose: Read and manage properties from XML data
8 ------------- Copyright (C) 2013 Bertrand Coconnier -------------
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
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
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.
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.
27 FUNCTIONAL DESCRIPTION
28 --------------------------------------------------------------------------------
29 This class reads and manages properties defined in XML data
32 --------------------------------------------------------------------------------
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
39 #include "FGPropertyReader.h"
40 #include "FGPropertyManager.h"
41 #include "FGXMLElement.h"
42 #include "FGJSBBase.h"
48 IDENT(IdSrc,"$Id: FGPropertyReader.cpp,v 1.3 2014/01/13 10:46:00 ehofman Exp $");
49 IDENT(IdHdr,ID_PROPERTYREADER);
51 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
55 bool FGPropertyReader::ResetToIC(void)
57 map<FGPropertyNode_ptr, double>::iterator it = interface_prop_initial_value.begin();
58 for (;it != interface_prop_initial_value.end(); ++it) {
59 FGPropertyNode* node = it->first;
60 if (!node->getAttribute(SGPropertyNode::PRESERVE))
61 node->setDoubleValue(it->second);
67 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
69 void FGPropertyReader::LoadProperties(Element* el, FGPropertyManager* PM,
72 // Interface properties are all stored in the interface properties array.
73 string interface_property_string = "";
75 Element *property_element = el->FindElement("property");
76 if (property_element && FGJSBBase::debug_lvl > 0) {
82 cout << " properties" << endl << endl;
85 while (property_element) {
86 FGPropertyNode* node = 0;
88 if ( ! property_element->GetAttributeValue("value").empty())
89 value = property_element->GetAttributeValueAsNumber("value");
91 interface_property_string = property_element->GetDataLine();
92 if (PM->HasNode(interface_property_string)) {
94 node = PM->GetNode(interface_property_string);
96 if (FGJSBBase::debug_lvl > 0) {
97 if (interface_prop_initial_value.find(node) == interface_prop_initial_value.end()) {
98 cout << property_element->ReadFrom()
99 << " The following property will be overridden but it has not been" << endl
100 << " defined in the current model '" << el->GetName() << "'" << endl;
103 cout << " " << "Overriding value for property " << interface_property_string << endl
104 << " (old value: " << node->getDoubleValue() << " new value: " << value << ")"
108 node->setDoubleValue(value);
111 cerr << property_element->ReadFrom()
112 << " Property " << interface_property_string
113 << " is already defined." << endl;
114 property_element = el->FindNextElement("property");
118 interface_properties.push_back(value);
119 PM->Tie(interface_property_string, &interface_properties.back());
120 if (FGJSBBase::debug_lvl > 0)
121 cout << " " << interface_property_string << " (initial value: "
122 << value << ")" << endl << endl;
123 node = PM->GetNode(interface_property_string);
125 interface_prop_initial_value[node] = value;
126 if (property_element->GetAttributeValue("persistent") == string("true"))
127 node->setAttribute(SGPropertyNode::PRESERVE, true);
129 property_element = el->FindNextElement("property");
132 // End of interface property loading logic