- if (!ReadPrologue(&AC_cfg)) return false;
-
- while ((AC_cfg.GetNextConfigLine() != string("EOF")) &&
- (token = AC_cfg.GetValue()) != string("/FDM_CONFIG")) {
- if (token == "METRICS") {
- if (debug_lvl > 0) cout << fgcyan << "\n Reading Metrics" << fgdef << endl;
- if (!ReadMetrics(&AC_cfg)) result = false;
- } else if (token == "SLAVE") {
- if (debug_lvl > 0) cout << fgcyan << "\n Reading Slave flight vehicle: " << fgdef
- << AC_cfg.GetValue("NAME") << endl;
- if (!ReadSlave(&AC_cfg)) result = false;
- } else if (token == "AERODYNAMICS") {
- if (debug_lvl > 0) cout << fgcyan << "\n Reading Aerodynamics" << fgdef << endl;
- if (!ReadAerodynamics(&AC_cfg)) result = false;
- } else if (token == "UNDERCARRIAGE") {
- if (debug_lvl > 0) cout << fgcyan << "\n Reading Landing Gear" << fgdef << endl;
- if (!ReadUndercarriage(&AC_cfg)) result = false;
- } else if (token == "PROPULSION") {
- if (debug_lvl > 0) cout << fgcyan << "\n Reading Propulsion" << fgdef << endl;
- if (!ReadPropulsion(&AC_cfg)) result = false;
- } else if (token == "FLIGHT_CONTROL") {
- if (debug_lvl > 0) cout << fgcyan << "\n Reading Flight Control" << fgdef << endl;
- if (!ReadFlightControls(&AC_cfg)) result = false;
- } else if (token == "AUTOPILOT") {
- if (debug_lvl > 0) cout << fgcyan << "\n Reading Autopilot" << fgdef << endl;
- if (!ReadFlightControls(&AC_cfg)) result = false;
- } else if (token == "OUTPUT") {
- if (debug_lvl > 0) cout << fgcyan << "\n Reading Output directives" << fgdef << endl;
- if (!ReadOutput(&AC_cfg)) result = false;
+ int saved_debug_lvl = debug_lvl;
+
+ document = LoadXMLDocument(aircraftCfgFileName); // "document" is a class member
+ if (document) {
+ if (IsChild) debug_lvl = 0;
+
+ ReadPrologue(document);
+
+ if (IsChild) debug_lvl = saved_debug_lvl;
+
+ // Process the fileheader element in the aircraft config file. This element is OPTIONAL.
+ element = document->FindElement("fileheader");
+ if (element) {
+ result = ReadFileHeader(element);
+ if (!result) {
+ cerr << endl << "Aircraft fileheader element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ }
+
+ if (IsChild) debug_lvl = 0;
+
+ // Process the metrics element. This element is REQUIRED.
+ element = document->FindElement("metrics");
+ if (element) {
+ result = Aircraft->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft metrics element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ } else {
+ cerr << endl << "No metrics element was found in the aircraft config file." << endl;
+ return false;
+ }
+
+ // Process the mass_balance element. This element is REQUIRED.
+ element = document->FindElement("mass_balance");
+ if (element) {
+ result = MassBalance->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft mass_balance element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ } else {
+ cerr << endl << "No mass_balance element was found in the aircraft config file." << endl;
+ return false;
+ }
+
+ // Process the ground_reactions element. This element is REQUIRED.
+ element = document->FindElement("ground_reactions");
+ if (element) {
+ result = GroundReactions->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft ground_reactions element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ } else {
+ cerr << endl << "No ground_reactions element was found in the aircraft config file." << endl;
+ return false;
+ }
+
+ // Process the external_reactions element. This element is OPTIONAL.
+ element = document->FindElement("external_reactions");
+ if (element) {
+ result = ExternalReactions->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft external_reactions element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ }
+
+ // Process the buoyant_forces element. This element is OPTIONAL.
+ element = document->FindElement("buoyant_forces");
+ if (element) {
+ result = BuoyantForces->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft buoyant_forces element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ }
+
+ // Process the propulsion element. This element is OPTIONAL.
+ element = document->FindElement("propulsion");
+ if (element) {
+ result = Propulsion->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft propulsion element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ }
+
+ // Process the system element[s]. This element is OPTIONAL, and there may be more than one.
+ element = document->FindElement("system");
+ while (element) {
+ result = FCS->Load(element, FGFCS::stSystem);
+ if (!result) {
+ cerr << endl << "Aircraft system element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ element = document->FindNextElement("system");
+ }
+
+ // Process the autopilot element. This element is OPTIONAL.
+ element = document->FindElement("autopilot");
+ if (element) {
+ result = FCS->Load(element, FGFCS::stAutoPilot);
+ if (!result) {
+ cerr << endl << "Aircraft autopilot element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ }
+
+ // Process the flight_control element. This element is OPTIONAL.
+ element = document->FindElement("flight_control");
+ if (element) {
+ result = FCS->Load(element, FGFCS::stFCS);
+ if (!result) {
+ cerr << endl << "Aircraft flight_control element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ }
+
+ // Process the aerodynamics element. This element is OPTIONAL, but almost always expected.
+ element = document->FindElement("aerodynamics");
+ if (element) {
+ result = Aerodynamics->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft aerodynamics element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ } else {
+ cerr << endl << "No expected aerodynamics element was found in the aircraft config file." << endl;
+ }
+
+ // Process the input element. This element is OPTIONAL.
+ element = document->FindElement("input");
+ if (element) {
+ result = Input->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft input element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }
+ }
+
+ // Process the output element[s]. This element is OPTIONAL, and there may be more than one.
+ unsigned int idx=0;
+ typedef double (FGOutput::*iOPMF)(void) const;
+ typedef int (FGFDMExec::*iOPV)(void) const;
+ typedef void (FGFDMExec::*vOPI)(int) const;
+ element = document->FindElement("output");
+ while (element) {
+ if (debug_lvl > 0) cout << endl << " Output data set: " << idx << " ";
+ FGOutput* Output = new FGOutput(this);
+ Output->InitModel();
+ Schedule(Output, 1);
+ result = Output->Load(element);
+ if (!result) {
+ cerr << endl << "Aircraft output element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ } else {
+ Outputs.push_back(Output);
+ string outputProp = CreateIndexedPropertyName("simulation/output",idx);
+ instance->Tie(outputProp+"/log_rate_hz", Output, (iOPMF)0, &FGOutput::SetRate, false);
+ instance->Tie("simulation/force-output", this, (iOPV)0, &FGFDMExec::ForceOutput, false);
+ idx++;
+ }
+ element = document->FindNextElement("output");
+ }
+
+ // Lastly, process the child element. This element is OPTIONAL - and NOT YET SUPPORTED.
+ element = document->FindElement("child");
+ if (element) {
+ result = ReadChild(element);
+ if (!result) {
+ cerr << endl << "Aircraft child element has problems in file " << aircraftCfgFileName << endl;
+ return result;
+ }