From ffc745e489b0615b73a145c774b9a1a0b42b07ab Mon Sep 17 00:00:00 2001 From: Yun Lin Date: Fri, 24 Jun 2022 23:53:30 +0800 Subject: [PATCH] #666 - remove static var to support run in multi-thread env --- src/FGFDMExec.cpp | 110 +++++------ src/FGFDMExec.h | 5 +- src/FGJSBBase.cpp | 130 +++++-------- src/FGJSBBase.h | 122 ++++++++----- src/JSBSim.cpp | 4 +- src/initialization/FGInitialCondition.cpp | 40 ++-- src/initialization/FGTrim.cpp | 22 +-- src/initialization/FGTrimAnalysis.cpp | 1 + src/initialization/FGTrimAnalysisControl.cpp | 3 +- src/initialization/FGTrimAxis.cpp | 4 +- src/input_output/FGInputSocket.cpp | 2 +- src/input_output/FGInputType.cpp | 2 + src/input_output/FGOutputSocket.cpp | 2 +- src/input_output/FGOutputTextFile.cpp | 8 +- src/input_output/FGOutputType.cpp | 9 +- src/input_output/FGPropertyManager.cpp | 1 - src/input_output/FGPropertyManager.h | 5 - src/input_output/FGPropertyReader.cpp | 24 --- src/input_output/FGScript.cpp | 22 ++- src/input_output/FGUDPInputSocket.cpp | 4 +- src/input_output/FGXMLElement.cpp | 17 +- src/input_output/FGfdmSocket.cpp | 21 ++- src/input_output/FGfdmSocket.h | 4 +- src/math/FGCondition.cpp | 13 +- src/math/FGCondition.h | 4 +- src/math/FGFunction.cpp | 114 ++++++------ src/math/FGFunction.h | 8 +- src/math/FGLocation.cpp | 14 +- src/math/FGLocation.h | 14 +- src/math/FGMatrix33.cpp | 4 +- src/math/FGMatrix33.h | 2 +- src/math/FGModelFunctions.cpp | 2 +- src/math/FGModelFunctions.h | 1 + src/math/FGQuaternion.cpp | 11 +- src/math/FGQuaternion.h | 42 +++-- src/math/FGTable.cpp | 43 ++--- src/math/FGTable.h | 8 +- src/math/FGTemplateFunc.cpp | 2 +- src/models/FGAccelerations.cpp | 1 + src/models/FGAerodynamics.cpp | 10 +- src/models/FGAircraft.cpp | 2 + src/models/FGAtmosphere.cpp | 1 + src/models/FGAuxiliary.cpp | 4 +- src/models/FGAuxiliary.h | 1 + src/models/FGBuoyantForces.cpp | 1 + src/models/FGExternalForce.cpp | 1 + src/models/FGExternalReactions.cpp | 2 + src/models/FGFCS.cpp | 17 +- src/models/FGGasCell.cpp | 4 +- src/models/FGGroundReactions.cpp | 4 +- src/models/FGInertial.cpp | 5 +- src/models/FGInertial.h | 3 +- src/models/FGInput.cpp | 3 +- src/models/FGLGear.cpp | 8 +- src/models/FGLGear.h | 1 + src/models/FGMassBalance.cpp | 19 +- src/models/FGModel.cpp | 9 +- src/models/FGOutput.cpp | 5 +- src/models/FGPropagate.cpp | 171 +++++++++--------- src/models/FGPropagate.h | 7 +- src/models/FGPropulsion.cpp | 7 +- src/models/atmosphere/FGMSIS.cpp | 1 + src/models/atmosphere/FGMars.cpp | 2 + .../atmosphere/FGStandardAtmosphere.cpp | 5 +- src/models/atmosphere/FGWinds.cpp | 3 +- src/models/flight_control/FGAccelerometer.cpp | 3 +- src/models/flight_control/FGActuator.cpp | 1 + src/models/flight_control/FGAngles.cpp | 1 + src/models/flight_control/FGDeadBand.cpp | 1 + src/models/flight_control/FGDistributor.cpp | 3 +- src/models/flight_control/FGFCSComponent.cpp | 4 +- src/models/flight_control/FGFCSFunction.cpp | 1 + src/models/flight_control/FGFilter.cpp | 1 + src/models/flight_control/FGGain.cpp | 5 +- src/models/flight_control/FGGyro.cpp | 3 +- src/models/flight_control/FGKinemat.cpp | 1 + .../flight_control/FGLinearActuator.cpp | 1 + src/models/flight_control/FGMagnetometer.cpp | 3 +- src/models/flight_control/FGPID.cpp | 1 + src/models/flight_control/FGSensor.cpp | 1 + .../flight_control/FGSensorOrientation.h | 2 +- src/models/flight_control/FGSummer.cpp | 1 + src/models/flight_control/FGSwitch.cpp | 3 +- src/models/flight_control/FGWaypoint.cpp | 3 +- src/models/propulsion/FGElectric.cpp | 3 +- src/models/propulsion/FGEngine.cpp | 5 +- src/models/propulsion/FGEngine.h | 2 +- src/models/propulsion/FGForce.cpp | 3 +- src/models/propulsion/FGNozzle.cpp | 1 + src/models/propulsion/FGPiston.cpp | 11 +- src/models/propulsion/FGPropeller.cpp | 9 +- src/models/propulsion/FGRocket.cpp | 5 +- src/models/propulsion/FGRotor.cpp | 1 + src/models/propulsion/FGTank.cpp | 3 +- src/models/propulsion/FGThruster.cpp | 3 +- src/models/propulsion/FGTransmission.cpp | 2 + src/models/propulsion/FGTurbine.cpp | 3 +- src/models/propulsion/FGTurboProp.cpp | 13 +- tests/unit_tests/FGJSBBaseTest.h | 3 + 99 files changed, 648 insertions(+), 599 deletions(-) diff --git a/src/FGFDMExec.cpp b/src/FGFDMExec.cpp index 66c96504ec..e207402695 100644 --- a/src/FGFDMExec.cpp +++ b/src/FGFDMExec.cpp @@ -74,7 +74,7 @@ CLASS IMPLEMENTATION // Constructor FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) - : Root(root), RandomEngine(new default_random_engine), FDMctr(fdmctr) + : FGJSBBase(cData), Root(root), RandomEngine(new default_random_engine), FDMctr(fdmctr) { Frame = 0; IC = nullptr; @@ -106,9 +106,9 @@ FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) try { char* num = getenv("JSBSIM_DEBUG"); - if (num) debug_lvl = atoi(num); // set debug level + if (num) gdata().debug_lvl = atoi(num); // set debug level } catch (...) { // if error set to 1 - debug_lvl = 1; + gdata().debug_lvl = 1; } if (Root == 0) { // Then this is the root FDM @@ -571,13 +571,13 @@ bool FGFDMExec::RunIC(void) Propagate->InitializeDerivatives(); ResumeIntegration(); // Restores the integration rate to what it was. - if (debug_lvl > 0) { + if (gdata().debug_lvl > 0) { MassBalance->GetMassPropertiesReport(0); - cout << endl << fgblue << highint + cout << endl << gdata().fgblue << gdata().highint << "End of vehicle configuration loading." << endl << "-------------------------------------------------------------------------------" - << reset << std::setprecision(6) << endl; + << gdata().reset << std::setprecision(6) << endl; } for (unsigned int n=0; n < propulsion->GetNumEngines(); ++n) { @@ -703,16 +703,16 @@ bool FGFDMExec::LoadModel(const string& model, bool addModelToPath) Allocate(); } - int saved_debug_lvl = debug_lvl; + int saved_debug_lvl = gdata().debug_lvl; FGXMLFileRead XMLFileRead; Element *document = XMLFileRead.LoadXMLDocument(aircraftCfgFileName); // "document" is a class member if (document) { - if (IsChild) debug_lvl = 0; + if (IsChild) gdata().debug_lvl = 0; ReadPrologue(document); - if (IsChild) debug_lvl = saved_debug_lvl; + if (IsChild) gdata().debug_lvl = saved_debug_lvl; // Process the fileheader element in the aircraft config file. This element is OPTIONAL. Element* element = document->FindElement("fileheader"); @@ -724,7 +724,7 @@ bool FGFDMExec::LoadModel(const string& model, bool addModelToPath) } } - if (IsChild) debug_lvl = 0; + if (IsChild) gdata().debug_lvl = 0; // Process the planet element. This element is OPTIONAL. element = document->FindElement("planet"); @@ -892,12 +892,12 @@ bool FGFDMExec::LoadModel(const string& model, bool addModelToPath) modelLoaded = true; - if (IsChild) debug_lvl = saved_debug_lvl; + if (IsChild) gdata().debug_lvl = saved_debug_lvl; } else { - cerr << fgred + cerr << gdata().fgred << " JSBSim failed to open the configuration file: " << aircraftCfgFileName - << fgdef << endl; + << gdata().fgdef << endl; } for (unsigned int i=0; i< Models.size(); i++) LoadInputs(i); @@ -964,8 +964,8 @@ string FGFDMExec::QueryPropertyCatalog(const string& in) void FGFDMExec::PrintPropertyCatalog(void) { cout << endl; - cout << " " << fgblue << highint << underon << "Property Catalog for " - << modelName << reset << endl << endl; + cout << " " << gdata().fgblue << gdata().highint << gdata().underon << "Property Catalog for " + << modelName << gdata().reset << endl << endl; for (unsigned i=0; iFindElement("description")) @@ -1017,50 +1017,50 @@ bool FGFDMExec::ReadPrologue(Element* el) // el for ReadPrologue is the document string AircraftName = el->GetAttributeValue("name"); ((FGAircraft*)Models[eAircraft])->SetAircraftName(AircraftName); - if (debug_lvl & 1) cout << underon << "Reading Aircraft Configuration File" - << underoff << ": " << highint << AircraftName << normint << endl; + if (gdata().debug_lvl & 1) cout << gdata().underon << "Reading Aircraft Configuration File" + << gdata().underoff << ": " << gdata().highint << AircraftName << gdata().normint << endl; CFGVersion = el->GetAttributeValue("version"); Release = el->GetAttributeValue("release"); - if (debug_lvl & 1) - cout << " Version: " << highint << CFGVersion - << normint << endl; + if (gdata().debug_lvl & 1) + cout << " Version: " << gdata().highint << CFGVersion + << gdata().normint << endl; if (CFGVersion != needed_cfg_version) { - cerr << endl << fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT." + cerr << endl << gdata().fgred << "YOU HAVE AN INCOMPATIBLE CFG FILE FOR THIS AIRCRAFT." " RESULTS WILL BE UNPREDICTABLE !!" << endl; cerr << "Current version needed is: " << needed_cfg_version << endl; - cerr << " You have version: " << CFGVersion << endl << fgdef << endl; + cerr << " You have version: " << CFGVersion << endl << gdata().fgdef << endl; return false; } - if (Release == "ALPHA" && (debug_lvl & 1)) { + if (Release == "ALPHA" && (gdata().debug_lvl & 1)) { cout << endl << endl - << highint << "This aircraft model is an " << fgred << Release - << reset << highint << " release!!!" << endl << endl << reset + << gdata().highint << "This aircraft model is an " << gdata().fgred << Release + << gdata().reset << gdata().highint << " release!!!" << endl << endl << gdata().reset << "This aircraft model may not even properly load, and probably" << " will not fly as expected." << endl << endl - << fgred << highint << "Use this model for development purposes ONLY!!!" - << normint << reset << endl << endl; - } else if (Release == "BETA" && (debug_lvl & 1)) { + << gdata().fgred << gdata().highint << "Use this model for development purposes ONLY!!!" + << gdata().normint << gdata().reset << endl << endl; + } else if (Release == "BETA" && (gdata().debug_lvl & 1)) { cout << endl << endl - << highint << "This aircraft model is a " << fgred << Release - << reset << highint << " release!!!" << endl << endl << reset + << gdata().highint << "This aircraft model is a " << gdata().fgred << Release + << gdata().reset << gdata().highint << " release!!!" << endl << endl << gdata().reset << "This aircraft model probably will not fly as expected." << endl << endl - << fgblue << highint << "Use this model for development purposes ONLY!!!" - << normint << reset << endl << endl; - } else if (Release == "PRODUCTION" && (debug_lvl & 1)) { + << gdata().fgblue << gdata().highint << "Use this model for development purposes ONLY!!!" + << gdata().normint << gdata().reset << endl << endl; + } else if (Release == "PRODUCTION" && (gdata().debug_lvl & 1)) { cout << endl << endl - << highint << "This aircraft model is a " << fgblue << Release - << reset << highint << " release." << endl << endl << reset; - } else if (debug_lvl & 1) { + << gdata().highint << "This aircraft model is a " << gdata().fgblue << Release + << gdata().reset << gdata().highint << " release." << endl << endl << gdata().reset; + } else if (gdata().debug_lvl & 1) { cout << endl << endl - << highint << "This aircraft model is an " << fgred << Release - << reset << highint << " release!!!" << endl << endl << reset + << gdata().highint << "This aircraft model is an " << gdata().fgred << Release + << gdata().reset << gdata().highint << " release!!!" << endl << endl << gdata().reset << "This aircraft model may not even properly load, and probably" << " will not fly as expected." << endl << endl - << fgred << highint << "Use this model for development purposes ONLY!!!" - << normint << reset << endl << endl; + << gdata().fgred << gdata().highint << "Use this model for development purposes ONLY!!!" + << gdata().normint << gdata().reset << endl << endl; } return result; @@ -1099,16 +1099,16 @@ bool FGFDMExec::ReadChild(Element* el) child->Loc = location->FindElementTripletConvertTo("IN"); } else { const string s(" No location was found for this child object!"); - cerr << el->ReadFrom() << endl << highint << fgred - << s << reset << endl; + cerr << el->ReadFrom() << endl << gdata().highint << gdata().fgred + << s << gdata().reset << endl; throw BaseException(s); } Element* orientation = el->FindElement("orient"); if (orientation) { child->Orient = orientation->FindElementTripletConvertTo("RAD"); - } else if (debug_lvl > 0) { - cerr << endl << highint << " No orientation was found for this child object! Assuming 0,0,0." << reset << endl; + } else if (gdata().debug_lvl > 0) { + cerr << endl << gdata().highint << " No orientation was found for this child object! Assuming 0,0,0." << gdata().reset << endl; } ChildFDMList.push_back(child); @@ -1168,7 +1168,7 @@ void FGFDMExec::DoTrim(int mode) FGTrim trim(this, (JSBSim::TrimMode)mode); bool success = trim.DoTrim(); - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) trim.Report(); if (!success) @@ -1182,7 +1182,7 @@ void FGFDMExec::DoTrim(int mode) void FGFDMExec::SRand(int sr) { RandomSeed = sr; - gaussian_random_number_phase = 0; + gdata().gaussian_random_number_phase = 0; RandomEngine->seed(sr); srand(RandomSeed); } @@ -1208,9 +1208,9 @@ void FGFDMExec::SRand(int sr) void FGFDMExec::Debug(int from) { - if (debug_lvl <= 0) return; + if (gdata().debug_lvl <= 0) return; - if (debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output + if (gdata().debug_lvl & 1 && IdFDM == 0) { // Standard console startup message output if (from == 0) { // Constructor cout << "\n\n " << "JSBSim Flight Dynamics Model v" << JSBSim_version << endl; @@ -1221,21 +1221,21 @@ void FGFDMExec::Debug(int from) cout << "\n\nJSBSim startup complete\n\n"; } } - if (debug_lvl & 2 ) { // Instantiation/Destruction notification + if (gdata().debug_lvl & 2 ) { // Instantiation/Destruction notification if (from == 0) cout << "Instantiated: FGFDMExec" << endl; if (from == 1) cout << "Destroyed: FGFDMExec" << endl; } - if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects + if (gdata().debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects if (from == 2) { cout << "================== Frame: " << Frame << " Time: " << sim_time << " dt: " << dT << endl; } } - if (debug_lvl & 8 ) { // Runtime state variables + if (gdata().debug_lvl & 8 ) { // Runtime state variables } - if (debug_lvl & 16) { // Sanity checking + if (gdata().debug_lvl & 16) { // Sanity checking } - if (debug_lvl & 64) { + if (gdata().debug_lvl & 64) { if (from == 0) { // Constructor } } diff --git a/src/FGFDMExec.h b/src/FGFDMExec.h index a02dcd4d2e..f8cda33be3 100644 --- a/src/FGFDMExec.h +++ b/src/FGFDMExec.h @@ -500,7 +500,7 @@ class JSBSIM_API FGFDMExec : public FGJSBBase @param mode Sets the reset mode.*/ void ResetToInitialConditions(int mode); /// Sets the debug level. - void SetDebugLevel(int level) {debug_lvl = level;} + void SetDebugLevel(int level) {gdata().debug_lvl = level;} struct PropertyCatalogStructure { /// Name of the property. @@ -591,7 +591,7 @@ class JSBSIM_API FGFDMExec : public FGJSBBase unsigned int GetFrame(void) const {return Frame;} /** Retrieves the current debug level setting. */ - int GetDebugLevel(void) const {return debug_lvl;}; + int GetDebugLevel(void) const {return gdata().debug_lvl;}; /** Initializes the simulation with initial conditions @param FGIC The initial conditions that will be passed to the simulation. */ @@ -620,6 +620,7 @@ class JSBSIM_API FGFDMExec : public FGJSBBase { return RandomEngine; } private: + CommonData cData; unsigned int Frame; unsigned int IdFDM; int disperse; diff --git a/src/FGJSBBase.cpp b/src/FGJSBBase.cpp index 09d45689b7..49a98f73c6 100644 --- a/src/FGJSBBase.cpp +++ b/src/FGJSBBase.cpp @@ -47,49 +47,14 @@ namespace JSBSim { /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ - -#ifndef _MSC_VER - char FGJSBBase::highint[5] = {27, '[', '1', 'm', '\0' }; - char FGJSBBase::halfint[5] = {27, '[', '2', 'm', '\0' }; - char FGJSBBase::normint[6] = {27, '[', '2', '2', 'm', '\0' }; - char FGJSBBase::reset[5] = {27, '[', '0', 'm', '\0' }; - char FGJSBBase::underon[5] = {27, '[', '4', 'm', '\0' }; - char FGJSBBase::underoff[6] = {27, '[', '2', '4', 'm', '\0' }; - char FGJSBBase::fgblue[6] = {27, '[', '3', '4', 'm', '\0' }; - char FGJSBBase::fgcyan[6] = {27, '[', '3', '6', 'm', '\0' }; - char FGJSBBase::fgred[6] = {27, '[', '3', '1', 'm', '\0' }; - char FGJSBBase::fggreen[6] = {27, '[', '3', '2', 'm', '\0' }; - char FGJSBBase::fgdef[6] = {27, '[', '3', '9', 'm', '\0' }; -#else - char FGJSBBase::highint[5] = {'\0' }; - char FGJSBBase::halfint[5] = {'\0' }; - char FGJSBBase::normint[6] = {'\0' }; - char FGJSBBase::reset[5] = {'\0' }; - char FGJSBBase::underon[5] = {'\0' }; - char FGJSBBase::underoff[6] = {'\0' }; - char FGJSBBase::fgblue[6] = {'\0' }; - char FGJSBBase::fgcyan[6] = {'\0' }; - char FGJSBBase::fgred[6] = {'\0' }; - char FGJSBBase::fggreen[6] = {'\0' }; - char FGJSBBase::fgdef[6] = {'\0' }; -#endif - const string FGJSBBase::needed_cfg_version = "2.0"; const string FGJSBBase::JSBSim_version = JSBSIM_VERSION " " __DATE__ " " __TIME__ ; -queue FGJSBBase::Messages; -FGJSBBase::Message FGJSBBase::localMsg; -unsigned int FGJSBBase::messageId = 0; - -int FGJSBBase::gaussian_random_number_phase = 0; - -short FGJSBBase::debug_lvl = 1; - //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGJSBBase::PutMessage(const Message& msg) { - Messages.push(msg); + _gdata.Messages.push(msg); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -98,10 +63,10 @@ void FGJSBBase::PutMessage(const string& text) { Message msg; msg.text = text; - msg.messageId = messageId++; + msg.messageId = _gdata.messageId++; msg.subsystem = "FDM"; msg.type = Message::eText; - Messages.push(msg); + _gdata.Messages.push(msg); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -110,11 +75,11 @@ void FGJSBBase::PutMessage(const string& text, bool bVal) { Message msg; msg.text = text; - msg.messageId = messageId++; + msg.messageId = _gdata.messageId++; msg.subsystem = "FDM"; msg.type = Message::eBool; msg.bVal = bVal; - Messages.push(msg); + _gdata.Messages.push(msg); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -123,11 +88,11 @@ void FGJSBBase::PutMessage(const string& text, int iVal) { Message msg; msg.text = text; - msg.messageId = messageId++; + msg.messageId = _gdata.messageId++; msg.subsystem = "FDM"; msg.type = Message::eInteger; msg.iVal = iVal; - Messages.push(msg); + _gdata.Messages.push(msg); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -136,40 +101,40 @@ void FGJSBBase::PutMessage(const string& text, double dVal) { Message msg; msg.text = text; - msg.messageId = messageId++; + msg.messageId = _gdata.messageId++; msg.subsystem = "FDM"; msg.type = Message::eDouble; msg.dVal = dVal; - Messages.push(msg); + _gdata.Messages.push(msg); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGJSBBase::ProcessMessage(void) { - if (Messages.empty()) return; - localMsg = Messages.front(); + if (_gdata.Messages.empty()) return; + _gdata.localMsg = _gdata.Messages.front(); while (SomeMessages()) { - switch (localMsg.type) { - case JSBSim::FGJSBBase::Message::eText: - cout << localMsg.messageId << ": " << localMsg.text << endl; + switch (_gdata.localMsg.type) { + case JSBSim::Message::eText: + cout << _gdata.localMsg.messageId << ": " << _gdata.localMsg.text << endl; break; - case JSBSim::FGJSBBase::Message::eBool: - cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.bVal << endl; + case JSBSim::Message::eBool: + cout << _gdata.localMsg.messageId << ": " << _gdata.localMsg.text << " " << _gdata.localMsg.bVal << endl; break; - case JSBSim::FGJSBBase::Message::eInteger: - cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.iVal << endl; + case JSBSim::Message::eInteger: + cout << _gdata.localMsg.messageId << ": " << _gdata.localMsg.text << " " << _gdata.localMsg.iVal << endl; break; - case JSBSim::FGJSBBase::Message::eDouble: - cout << localMsg.messageId << ": " << localMsg.text << " " << localMsg.dVal << endl; + case JSBSim::Message::eDouble: + cout << _gdata.localMsg.messageId << ": " << _gdata.localMsg.text << " " << _gdata.localMsg.dVal << endl; break; default: cerr << "Unrecognized message type." << endl; break; } - Messages.pop(); - if (SomeMessages()) localMsg = Messages.front(); + _gdata.Messages.pop(); + if (SomeMessages()) _gdata.localMsg = _gdata.Messages.front(); else break; } @@ -177,30 +142,30 @@ void FGJSBBase::ProcessMessage(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGJSBBase::Message* FGJSBBase::ProcessNextMessage(void) +Message* FGJSBBase::ProcessNextMessage(void) { - if (Messages.empty()) return NULL; - localMsg = Messages.front(); + if (_gdata.Messages.empty()) return NULL; + _gdata.localMsg = _gdata.Messages.front(); - Messages.pop(); - return &localMsg; + _gdata.Messages.pop(); + return &_gdata.localMsg; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% void FGJSBBase::disableHighLighting(void) { - highint[0]='\0'; - halfint[0]='\0'; - normint[0]='\0'; - reset[0]='\0'; - underon[0]='\0'; - underoff[0]='\0'; - fgblue[0]='\0'; - fgcyan[0]='\0'; - fgred[0]='\0'; - fggreen[0]='\0'; - fgdef[0]='\0'; + _gdata.highint[0]='\0'; + _gdata.halfint[0]='\0'; + _gdata.normint[0]='\0'; + _gdata.reset[0]='\0'; + _gdata.underon[0]='\0'; + _gdata.underoff[0]='\0'; + _gdata.fgblue[0]='\0'; + _gdata.fgcyan[0]='\0'; + _gdata.fgred[0]='\0'; + _gdata.fggreen[0]='\0'; + _gdata.fgdef[0]='\0'; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -216,26 +181,25 @@ string FGJSBBase::CreateIndexedPropertyName(const string& Property, int index) double FGJSBBase::GaussianRandomNumber(void) { - static double V1, V2, S; double X; - if (gaussian_random_number_phase == 0) { - V1 = V2 = S = X = 0.0; + if (_gdata.gaussian_random_number_phase == 0) { + _gdata.V1 = _gdata.V2 = _gdata.S = X = 0.0; do { double U1 = (double)rand() / RAND_MAX; double U2 = (double)rand() / RAND_MAX; - V1 = 2 * U1 - 1; - V2 = 2 * U2 - 1; - S = V1 * V1 + V2 * V2; - } while(S >= 1 || S == 0); + _gdata.V1 = 2 * U1 - 1; + _gdata.V2 = 2 * U2 - 1; + _gdata.S = _gdata.V1 * _gdata.V1 + _gdata.V2 * _gdata.V2; + } while(_gdata.S >= 1 || _gdata.S == 0); - X = V1 * sqrt(-2 * log(S) / S); + X = _gdata.V1 * sqrt(-2 * log(_gdata.S) / _gdata.S); } else - X = V2 * sqrt(-2 * log(S) / S); + X = _gdata.V2 * sqrt(-2 * log(_gdata.S) / _gdata.S); - gaussian_random_number_phase = 1 - gaussian_random_number_phase; + _gdata.gaussian_random_number_phase = 1 - _gdata.gaussian_random_number_phase; return X; } diff --git a/src/FGJSBBase.h b/src/FGJSBBase.h index 75207ed112..ffb7c780a3 100644 --- a/src/FGJSBBase.h +++ b/src/FGJSBBase.h @@ -76,25 +76,83 @@ CLASS DOCUMENTATION CLASS DECLARATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ +/// JSBSim Message structure +struct Message { + unsigned int fdmId; + unsigned int messageId; + std::string text; + std::string subsystem; + enum mType {eText, eInteger, eDouble, eBool} type; + bool bVal; + int iVal; + double dVal; +}; + +// Common data for FGJSBBase, one instance on global scope, +// A replacement for static variable(not support for multi-thread) in FGJSBBase. +struct CommonData { + Message localMsg; + std::queue Messages; + unsigned int messageId = 0; + + short debug_lvl = 1; + + int gaussian_random_number_phase = 0; + double V1 = 0.0; + double V2 = 0.0; + double S = 0.0; + + ///@name JSBSim console output highlighting terms. + //@{ +#ifndef _MSC_VER + /// highlights text + char highint[5] = {27, '[', '1', 'm', '\0' }; + /// low intensity text + char halfint[5] = {27, '[', '2', 'm', '\0' }; + /// normal intensity text + char normint[6] = {27, '[', '2', '2', 'm', '\0' }; + /// resets text properties + char reset[5] = {27, '[', '0', 'm', '\0' }; + /// underlines text + char underon[5] = {27, '[', '4', 'm', '\0' }; + /// underline off + char underoff[6] = {27, '[', '2', '4', 'm', '\0' }; + /// blue text + char fgblue[6] = {27, '[', '3', '4', 'm', '\0' }; + /// cyan text + char fgcyan[6] = {27, '[', '3', '6', 'm', '\0' }; + /// red text + char fgred[6] = {27, '[', '3', '1', 'm', '\0' }; + /// green text + char fggreen[6] = {27, '[', '3', '2', 'm', '\0' }; + /// default text + char fgdef[6] = {27, '[', '3', '9', 'm', '\0' }; +#else + char highint[5] = {'\0' }; + char halfint[5] = {'\0' }; + char normint[6] = {'\0' }; + char reset[5] = {'\0' }; + char underon[5] = {'\0' }; + char underoff[6] = {'\0' }; + char fgblue[6] = {'\0' }; + char fgcyan[6] = {'\0' }; + char fgred[6] = {'\0' }; + char fggreen[6] = {'\0' }; + char fgdef[6] = {'\0' }; +#endif + //@} +}; + class JSBSIM_API FGJSBBase { public: /// Constructor for FGJSBBase. - FGJSBBase() {}; + FGJSBBase(CommonData& gdata) : _gdata(gdata) {}; /// Destructor for FGJSBBase. virtual ~FGJSBBase() {}; - /// JSBSim Message structure - struct Message { - unsigned int fdmId; - unsigned int messageId; - std::string text; - std::string subsystem; - enum mType {eText, eInteger, eDouble, eBool} type; - bool bVal; - int iVal; - double dVal; - }; + CommonData& gdata() { return _gdata; } + const CommonData& gdata() const { return _gdata; } /// First order, (low pass / lag) filter class Filter { @@ -118,32 +176,6 @@ class JSBSIM_API FGJSBBase { } }; - ///@name JSBSim console output highlighting terms. - //@{ - /// highlights text - static char highint[5]; - /// low intensity text - static char halfint[5]; - /// normal intensity text - static char normint[6]; - /// resets text properties - static char reset[5]; - /// underlines text - static char underon[5]; - /// underline off - static char underoff[6]; - /// blue text - static char fgblue[6]; - /// cyan text - static char fgcyan[6]; - /// red text - static char fgred[6]; - /// green text - static char fggreen[6]; - /// default text - static char fgdef[6]; - //@} - ///@name JSBSim Messaging functions //@{ /** Places a Message structure on the Message queue. @@ -171,7 +203,7 @@ class JSBSIM_API FGJSBBase { void PutMessage(const std::string& text, double dVal); /** Reads the message on the queue (but does not delete it). @return 1 if some messages */ - int SomeMessages(void) const { return !Messages.empty(); } + int SomeMessages(void) const { return !gdata().Messages.empty(); } /** Reads the message on the queue and removes it from the queue. This function also prints out the message.*/ void ProcessMessage(void); @@ -188,8 +220,6 @@ class JSBSIM_API FGJSBBase { /// Disables highlighting in the console output. void disableHighLighting(void); - static short debug_lvl; - /** Converts from degrees Kelvin to degrees Fahrenheit. * @param kelvin The temperature in degrees Kelvin. * @return The temperature in Fahrenheit. */ @@ -337,14 +367,11 @@ class JSBSIM_API FGJSBBase { static constexpr double sign(double num) {return num>=0.0?1.0:-1.0;} - static double GaussianRandomNumber(void); + double GaussianRandomNumber(void); protected: - static Message localMsg; - - static std::queue Messages; - - static unsigned int messageId; + // Reference to the common data + CommonData _gdata; static constexpr double radtodeg = 180. / M_PI; static constexpr double degtorad = M_PI / 180.; @@ -373,7 +400,6 @@ class JSBSIM_API FGJSBBase { static std::string CreateIndexedPropertyName(const std::string& Property, int index); - static int gaussian_random_number_phase; public: /// Moments L, M, N diff --git a/src/JSBSim.cpp b/src/JSBSim.cpp index f1b3977eda..d438becb64 100644 --- a/src/JSBSim.cpp +++ b/src/JSBSim.cpp @@ -481,9 +481,9 @@ int real_main(int argc, char* argv[]) } } - cout << endl << JSBSim::FGFDMExec::fggreen << JSBSim::FGFDMExec::highint + cout << endl << FDMExec->gdata().fggreen << FDMExec->gdata().highint << "---- JSBSim Execution beginning ... --------------------------------------------" - << JSBSim::FGFDMExec::reset << endl << endl; + << FDMExec->gdata().reset << endl << endl; result = FDMExec->Run(); // MAKE AN INITIAL RUN diff --git a/src/initialization/FGInitialCondition.cpp b/src/initialization/FGInitialCondition.cpp index 3f5935935d..d41b7730ae 100644 --- a/src/initialization/FGInitialCondition.cpp +++ b/src/initialization/FGInitialCondition.cpp @@ -57,7 +57,8 @@ namespace JSBSim { //****************************************************************************** -FGInitialCondition::FGInitialCondition(FGFDMExec *FDMExec) : fdmex(FDMExec) +FGInitialCondition::FGInitialCondition(FGFDMExec *FDMExec) + : FGJSBBase(FDMExec->gdata()), position(FDMExec->gdata()), orientation(FDMExec->gdata()), fdmex(FDMExec) { InitializeIC(); @@ -101,7 +102,7 @@ void FGInitialCondition::ResetIC(double u0, double v0, double w0, lastLatitudeSet = setgeoc; lastAltitudeSet = setagl; - orientation = FGQuaternion(phi0, theta0, psi0); + orientation = FGQuaternion(gdata(), phi0, theta0, psi0); const FGMatrix33& Tb2l = orientation.GetTInv(); vUVW_NED = Tb2l * FGColumnVector3(u0, v0, w0); @@ -130,7 +131,7 @@ void FGInitialCondition::InitializeIC(void) position.SetPositionGeodetic(0.0, 0.0, 0.0); - orientation = FGQuaternion(0.0, 0.0, 0.0); + orientation = FGQuaternion(gdata(), 0.0, 0.0, 0.0); vUVW_NED.InitMatrix(); vPQR_body.InitMatrix(); vt=0; @@ -370,7 +371,7 @@ void FGInitialCondition::calcThetaBeta(double alfa, const FGColumnVector3& _vt_N double sinTheta = (v1xz * v0xz)(eY); vOrient(eTht) = asin(sinTheta); - orientation = FGQuaternion(vOrient); + orientation = FGQuaternion(gdata(), vOrient); const FGMatrix33& Tl2b = orientation.GetT(); FGColumnVector3 v2 = Talpha * Tl2b * _vt_NED; @@ -436,7 +437,7 @@ void FGInitialCondition::SetBetaRadIC(double bta) double sinTheta = (v2xz * vfxz)(eY); vOrient(eTht) = -asin(sinTheta); - orientation = FGQuaternion(vOrient); + orientation = FGQuaternion(gdata(), vOrient); } //****************************************************************************** @@ -452,7 +453,7 @@ void FGInitialCondition::SetEulerAngleRadIC(int idx, double angle) FGColumnVector3 vOrient = orientation.GetEuler(); vOrient(idx) = angle; - orientation = FGQuaternion(vOrient); + orientation = FGQuaternion(gdata(), vOrient); if ((lastSpeedSet != setned) && (lastSpeedSet != setvg)) { const FGMatrix33& newTb2l = orientation.GetTInv(); @@ -663,7 +664,7 @@ double FGInitialCondition::GetAltitudeASLFtIC(void) const double FGInitialCondition::GetTerrainElevationFtIC(void) const { FGColumnVector3 normal, v, w; - FGLocation contact; + FGLocation contact(const_cast(gdata())); double a = fdmex->GetInertial()->GetSemimajor(); double b = fdmex->GetInertial()->GetSemiminor(); contact.SetEllipse(a, b); @@ -1144,7 +1145,7 @@ bool FGInitialCondition::Load_v1(Element* document) if (document->FindElement("psi")) vOrient(ePsi) = document->FindElementValueAsNumberConvertTo("psi", "RAD"); - orientation = FGQuaternion(vOrient); + orientation = FGQuaternion(gdata(), vOrient); if (document->FindElement("ubody")) SetUBodyFpsIC(document->FindElementValueAsNumberConvertTo("ubody", "FT/SEC")); @@ -1307,9 +1308,9 @@ bool FGInitialCondition::Load_v2(Element* document) // // Q_b/l = Q_i/l * Q_b/i - FGQuaternion QuatI2Body = FGQuaternion(vOrient); + FGQuaternion QuatI2Body = FGQuaternion(gdata(), vOrient); QuatI2Body.Normalize(); - FGQuaternion QuatLocal2I = Tec2i * position.GetTl2ec(); + FGQuaternion QuatLocal2I(gdata(), Tec2i * position.GetTl2ec()); QuatLocal2I.Normalize(); orientation = QuatLocal2I * QuatI2Body; @@ -1325,20 +1326,20 @@ bool FGInitialCondition::Load_v2(Element* document) // // Q_b/l = Q_e/l * Q_b/e - FGQuaternion QuatEC2Body(vOrient); // Store relationship of Body frame wrt ECEF frame, Q_b/e + FGQuaternion QuatEC2Body(gdata(), vOrient); // Store relationship of Body frame wrt ECEF frame, Q_b/e QuatEC2Body.Normalize(); - FGQuaternion QuatLocal2EC = position.GetTl2ec(); // Get Q_e/l from matrix + FGQuaternion QuatLocal2EC(gdata(), position.GetTl2ec()); // Get Q_e/l from matrix QuatLocal2EC.Normalize(); orientation = QuatLocal2EC * QuatEC2Body; // Q_b/l = Q_e/l * Q_b/e } else if (frame == "local") { - orientation = FGQuaternion(vOrient); + orientation = FGQuaternion(gdata(), vOrient); } else { - cerr << endl << fgred << " Orientation frame type: \"" << frame - << "\" is not supported!" << reset << endl << endl; + cerr << endl << gdata().fgred << " Orientation frame type: \"" << frame + << "\" is not supported!" << gdata().reset << endl << endl; result = false; } @@ -1377,8 +1378,8 @@ bool FGInitialCondition::Load_v2(Element* document) lastSpeedSet = setuvw; } else { - cerr << endl << fgred << " Velocity frame type: \"" << frame - << "\" is not supported!" << reset << endl << endl; + cerr << endl << gdata().fgred << " Velocity frame type: \"" << frame + << "\" is not supported!" << gdata().reset << endl << endl; result = false; } @@ -1425,8 +1426,8 @@ bool FGInitialCondition::Load_v2(Element* document) vPQR_body = vAttRate; } else if (!frame.empty()) { // misspelling of frame - cerr << endl << fgred << " Attitude rate frame type: \"" << frame - << "\" is not supported!" << reset << endl << endl; + cerr << endl << gdata().fgred << " Attitude rate frame type: \"" << frame + << "\" is not supported!" << gdata().reset << endl << endl; result = false; } else if (frame.empty()) { @@ -1608,6 +1609,7 @@ void FGInitialCondition::bind(FGPropertyManager* PropertyManager) void FGInitialCondition::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/initialization/FGTrim.cpp b/src/initialization/FGTrim.cpp index 28cc75964f..d7f3d3ce03 100644 --- a/src/initialization/FGTrim.cpp +++ b/src/initialization/FGTrim.cpp @@ -59,7 +59,7 @@ namespace JSBSim { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGTrim::FGTrim(FGFDMExec *FDMExec,TrimMode tt) - : fgic(FDMExec) + : FGJSBBase(FDMExec->gdata()), fgic(FDMExec) { Nsub=0; @@ -78,13 +78,13 @@ FGTrim::FGTrim(FGFDMExec *FDMExec,TrimMode tt) targetNlf=fgic.GetTargetNlfIC(); debug_axis=tAll; SetMode(tt); - if (debug_lvl & 2) cout << "Instantiated: FGTrim" << endl; + if (gdata().debug_lvl & 2) cout << "Instantiated: FGTrim" << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGTrim::~FGTrim(void) { - if (debug_lvl & 2) cout << "Destroyed: FGTrim" << endl; + if (gdata().debug_lvl & 2) cout << "Destroyed: FGTrim" << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -310,7 +310,7 @@ bool FGTrim::DoTrim(void) { if((!trim_failed) && (axis_count >= TrimAxes.size())) { total_its=N; - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << endl << " Trim successful" << endl; } else { // The trim has failed total_its=N; @@ -331,7 +331,7 @@ bool FGTrim::DoTrim(void) { if (fdmex->GetGroundReactions()->GetWOW()) trimOnGround(); - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << endl << " Trim failed" << endl; } @@ -396,7 +396,7 @@ void FGTrim::trimOnGround(void) FGLocation gearLoc = CGLocation.LocalToLocation(Tb2l * c.location); FGColumnVector3 normal, vDummy; - FGLocation lDummy; + FGLocation lDummy(gdata()); double height = fdmex->GetInertial()->GetContactPoint(gearLoc, lDummy, normal, vDummy, vDummy); @@ -439,7 +439,7 @@ void FGTrim::trimOnGround(void) // Compute the rotation parameters: angle and the first point to come into // contact with the ground when the rotation is applied. RotationParameters rParam = calcRotation(contacts, rotationAxis, contact0); - FGQuaternion q0(rParam.angleMin, rotationAxis); + FGQuaternion q0(gdata(), rParam.angleMin, rotationAxis); // Apply the computed rotation to all the contact points FGMatrix33 rot = q0.GetTInv(); @@ -465,7 +465,7 @@ void FGTrim::trimOnGround(void) // Compute the rotation parameters rParam = calcRotation(contacts, rotationAxis, contact0); - FGQuaternion q1(rParam.angleMin, rotationAxis); + FGQuaternion q1(gdata(), rParam.angleMin, rotationAxis); // Update the aircraft orientation FGColumnVector3 euler = (fgic.GetOrientation() * q0 * q1).GetEuler(); @@ -802,7 +802,7 @@ void FGTrim::SetMode(TrimMode tt) { mode=tt; switch(tt) { case tFull: - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << " Full Trim" << endl; TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tWdot,tAlpha)); TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tUdot,tThrottle )); @@ -813,14 +813,14 @@ void FGTrim::SetMode(TrimMode tt) { TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tRdot,tRudder )); break; case tLongitudinal: - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << " Longitudinal Trim" << endl; TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tWdot,tAlpha )); TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tUdot,tThrottle )); TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tQdot,tPitchTrim )); break; case tGround: - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << " Ground Trim" << endl; TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tWdot,tAltAGL )); TrimAxes.push_back(FGTrimAxis(fdmex,&fgic,tQdot,tTheta )); diff --git a/src/initialization/FGTrimAnalysis.cpp b/src/initialization/FGTrimAnalysis.cpp index c5fc4f3a8c..9d8d22203b 100644 --- a/src/initialization/FGTrimAnalysis.cpp +++ b/src/initialization/FGTrimAnalysis.cpp @@ -318,6 +318,7 @@ void Objective::Set_x_val(double new_x) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGTrimAnalysis::FGTrimAnalysis(FGFDMExec *FDMExec,TrimAnalysisMode tt) + : FGJSBBase(FDMExec->data()) { SetDebug(2); diff --git a/src/initialization/FGTrimAnalysisControl.cpp b/src/initialization/FGTrimAnalysisControl.cpp index 53d37721df..806f476aaa 100644 --- a/src/initialization/FGTrimAnalysisControl.cpp +++ b/src/initialization/FGTrimAnalysisControl.cpp @@ -61,7 +61,8 @@ IDENT(IdHdr,ID_TRIMANALYSISCONTROL); FGTrimAnalysisControl::FGTrimAnalysisControl(FGFDMExec* fdex, FGInitialCondition* ic, //State st, - TaControl ctrl) { + TaControl ctrl) + : FGJSBBase(fdex->gdata()) { fdmex=fdex; fgic=ic; state=taAll; diff --git a/src/initialization/FGTrimAxis.cpp b/src/initialization/FGTrimAxis.cpp index f0e8298e12..2fbcc84bc0 100644 --- a/src/initialization/FGTrimAxis.cpp +++ b/src/initialization/FGTrimAxis.cpp @@ -59,7 +59,7 @@ namespace JSBSim { /*****************************************************************************/ FGTrimAxis::FGTrimAxis(FGFDMExec* fdex, FGInitialCondition* ic, State st, - Control ctrl) { + Control ctrl) : FGJSBBase(fdex->gdata()) { fdmex=fdex; fgic=ic; @@ -339,7 +339,7 @@ double FGTrimAxis::GetAvgStability( void ) { void FGTrimAxis::Debug(int from) { - + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1 ) { // Standard console startup message output if (from == 0) { // Constructor diff --git a/src/input_output/FGInputSocket.cpp b/src/input_output/FGInputSocket.cpp index f5a9510e9b..53786efb83 100644 --- a/src/input_output/FGInputSocket.cpp +++ b/src/input_output/FGInputSocket.cpp @@ -96,7 +96,7 @@ bool FGInputSocket::InitModel(void) { if (FGInputType::InitModel()) { delete socket; - socket = new FGfdmSocket(SockPort, SockProtocol); + socket = new FGfdmSocket(gdata(), SockPort, SockProtocol); if (socket == 0) return false; if (!socket->GetConnectStatus()) return false; diff --git a/src/input_output/FGInputType.cpp b/src/input_output/FGInputType.cpp index 0522f5cc90..03da637935 100644 --- a/src/input_output/FGInputType.cpp +++ b/src/input_output/FGInputType.cpp @@ -38,6 +38,7 @@ INCLUDES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ #include "FGInputType.h" +#include "FGFDMExec.h" using namespace std; @@ -130,6 +131,7 @@ bool FGInputType::Run(bool Holding) void FGInputType::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message input diff --git a/src/input_output/FGOutputSocket.cpp b/src/input_output/FGOutputSocket.cpp index 0ad87af0d0..58cf3e5ea8 100644 --- a/src/input_output/FGOutputSocket.cpp +++ b/src/input_output/FGOutputSocket.cpp @@ -136,7 +136,7 @@ bool FGOutputSocket::InitModel(void) { if (FGOutputType::InitModel()) { delete socket; - socket = new FGfdmSocket(SockName, SockPort, SockProtocol, precision); + socket = new FGfdmSocket(gdata(), SockName, SockPort, SockProtocol, precision); if (socket == 0) return false; if (!socket->GetConnectStatus()) return false; diff --git a/src/input_output/FGOutputTextFile.cpp b/src/input_output/FGOutputTextFile.cpp index 073b9a0c96..e54f8548fb 100644 --- a/src/input_output/FGOutputTextFile.cpp +++ b/src/input_output/FGOutputTextFile.cpp @@ -86,10 +86,10 @@ bool FGOutputTextFile::OpenFile(void) datafile.clear(); datafile.open(Filename); if (!datafile) { - cerr << endl << fgred << highint << "ERROR: unable to open the file " - << reset << Filename.c_str() << endl - << fgred << highint << " => Output to this file is disabled." - << reset << endl << endl; + cerr << endl << gdata().fgred << gdata().highint << "ERROR: unable to open the file " + << gdata().reset << Filename.c_str() << endl + << gdata().fgred << gdata().highint << " => Output to this file is disabled." + << gdata().reset << endl << endl; Disable(); return false; } diff --git a/src/input_output/FGOutputType.cpp b/src/input_output/FGOutputType.cpp index 62465c617e..f885a51d23 100644 --- a/src/input_output/FGOutputType.cpp +++ b/src/input_output/FGOutputType.cpp @@ -135,10 +135,10 @@ bool FGOutputType::Load(Element* element) FGPropertyNode* node = PropertyManager->GetNode(property_str); if (!node) { cerr << property_element->ReadFrom() - << fgred << highint << endl << " No property by the name " + << gdata().fgred << gdata().highint << endl << " No property by the name " << property_str << " has been defined. This property will " << endl << " not be logged. You should check your configuration file." - << reset << endl; + << gdata().reset << endl; } else { if (property_element->HasAttribute("apply")) { string function_str = property_element->GetAttributeValue("apply"); @@ -147,10 +147,10 @@ bool FGOutputType::Load(Element* element) OutputParameters.push_back(new FGFunctionValue(node, f)); else { cerr << property_element->ReadFrom() - << fgred << highint << " No function by the name " + << gdata().fgred << gdata().highint << " No function by the name " << function_str << " has been defined. This property will " << "not be logged. You should check your configuration file." - << reset << endl; + << gdata().reset << endl; } } else @@ -250,6 +250,7 @@ void FGOutputType::SetOutputProperties(vector & outputProper void FGOutputType::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/input_output/FGPropertyManager.cpp b/src/input_output/FGPropertyManager.cpp index 9ec56b539f..761785b34c 100644 --- a/src/input_output/FGPropertyManager.cpp +++ b/src/input_output/FGPropertyManager.cpp @@ -318,7 +318,6 @@ void FGPropertyManager::Untie(SGPropertyNode *property) if (*it == property) { property->untie(); tied_properties.erase(it); - if (FGJSBBase::debug_lvl & 0x20) cout << "Untied " << name << endl; return; } } diff --git a/src/input_output/FGPropertyManager.h b/src/input_output/FGPropertyManager.h index 12c78b4f62..271c66ee47 100644 --- a/src/input_output/FGPropertyManager.h +++ b/src/input_output/FGPropertyManager.h @@ -458,7 +458,6 @@ class JSBSIM_API FGPropertyManager cerr << "Failed to tie property " << name << " to a pointer" << endl; else { tied_properties.push_back(property); - if (FGJSBBase::debug_lvl & 0x20) cout << name << endl; } } @@ -492,7 +491,6 @@ class JSBSIM_API FGPropertyManager if (!setter) property->setAttribute(SGPropertyNode::WRITE, false); if (!getter) property->setAttribute(SGPropertyNode::READ, false); tied_properties.push_back(property); - if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl; } } @@ -529,7 +527,6 @@ class JSBSIM_API FGPropertyManager if (!setter) property->setAttribute(SGPropertyNode::WRITE, false); if (!getter) property->setAttribute(SGPropertyNode::READ, false); tied_properties.push_back(property); - if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl; } } @@ -566,7 +563,6 @@ class JSBSIM_API FGPropertyManager if (!setter) property->setAttribute(SGPropertyNode::WRITE, false); if (!getter) property->setAttribute(SGPropertyNode::READ, false); tied_properties.push_back(property); - if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl; } } @@ -604,7 +600,6 @@ class JSBSIM_API FGPropertyManager if (!setter) property->setAttribute(SGPropertyNode::WRITE, false); if (!getter) property->setAttribute(SGPropertyNode::READ, false); tied_properties.push_back(property); - if (FGJSBBase::debug_lvl & 0x20) std::cout << name << std::endl; } } diff --git a/src/input_output/FGPropertyReader.cpp b/src/input_output/FGPropertyReader.cpp index b4ca79826c..98dbc59075 100644 --- a/src/input_output/FGPropertyReader.cpp +++ b/src/input_output/FGPropertyReader.cpp @@ -67,14 +67,6 @@ bool FGPropertyReader::ResetToIC(void) void FGPropertyReader::Load(Element* el, FGPropertyManager* PM, bool override) { Element *property_element = el->FindElement("property"); - if (property_element && FGJSBBase::debug_lvl > 0) { - cout << endl << " "; - if (override) - cout << "Overriding"; - else - cout << "Declared"; - cout << " properties" << endl << endl; - } while (property_element) { SGPropertyNode* node = nullptr; @@ -87,18 +79,6 @@ void FGPropertyReader::Load(Element* el, FGPropertyManager* PM, bool override) if (override) { node = PM->GetNode(interface_property_string); - if (FGJSBBase::debug_lvl > 0) { - if (interface_prop_initial_value.find(node) == interface_prop_initial_value.end()) { - cout << property_element->ReadFrom() - << " The following property will be overridden but it has not been" << endl - << " defined in the current model '" << el->GetName() << "'" << endl; - } - - cout << " " << "Overriding value for property " << interface_property_string << endl - << " (old value: " << node->getDoubleValue() << " new value: " << value << ")" - << endl << endl; - } - node->setDoubleValue(value); } else { @@ -112,10 +92,6 @@ void FGPropertyReader::Load(Element* el, FGPropertyManager* PM, bool override) node = PM->GetNode(interface_property_string, true); if (node) { node->setDoubleValue(value); - - if (FGJSBBase::debug_lvl > 0) - cout << " " << interface_property_string << " (initial value: " - << value << ")" << endl << endl; } else { cerr << "Could not create property " << interface_property_string diff --git a/src/input_output/FGScript.cpp b/src/input_output/FGScript.cpp index fd5d309a7e..3ba12fe243 100644 --- a/src/input_output/FGScript.cpp +++ b/src/input_output/FGScript.cpp @@ -61,7 +61,7 @@ CLASS IMPLEMENTATION // Constructor -FGScript::FGScript(FGFDMExec* fgex) : FDMExec(fgex) +FGScript::FGScript(FGFDMExec* fgex) : FGJSBBase(fgex->gdata()), FDMExec(fgex) { PropertyManager=FDMExec->GetPropertyManager(); @@ -211,6 +211,7 @@ bool FGScript::LoadScript(const SGPath& script, double default_dT, } // Read local property/value declarations + auto& debug_lvl = gdata().debug_lvl; int saved_debug_lvl = debug_lvl; debug_lvl = 0; // Disable messages LocalProperties.Load(run_element, PropertyManager, true); @@ -242,9 +243,9 @@ bool FGScript::LoadScript(const SGPath& script, double default_dT, Element* condition_element = event_element->FindElement("condition"); if (condition_element != 0) { try { - newCondition = new FGCondition(condition_element, PropertyManager); + newCondition = new FGCondition(gdata(), condition_element, PropertyManager); } catch(string& str) { - cout << endl << fgred << str << reset << endl << endl; + cout << endl << gdata().fgred << str << gdata().reset << endl << endl; delete newEvent; return false; } @@ -287,10 +288,10 @@ bool FGScript::LoadScript(const SGPath& script, double default_dT, newEvent->NotifyProperties.push_back(new FGFunctionValue(notifyPropertyName, PropertyManager, f)); else { cerr << notify_property_element->ReadFrom() - << fgred << highint << " No function by the name " + << gdata().fgred << gdata().highint << " No function by the name " << function_str << " has been defined. This property will " << "not be logged. You should check your configuration file." - << reset << endl; + << gdata().reset << endl; } } else @@ -494,10 +495,10 @@ bool FGScript::RunScript(void) cout << " " << thisEvent.Name << " (Event " << event_ctr << ")" << " executed at time: " << currentTime << "
" << endl; } else { - cout << endl << underon - << highint << thisEvent.Name << normint << underoff + cout << endl <GetDataLine(); FGPropertyNode* node = PropertyManager->GetNode(property_str); if (!node) { - cerr << fgred << highint << endl << " No property by the name " - << property_str << " can be found." << reset << endl; + cerr << gdata().fgred << gdata().highint << endl << " No property by the name " + << property_str << " can be found." << gdata().reset << endl; } else { InputProperties.push_back(node); } diff --git a/src/input_output/FGXMLElement.cpp b/src/input_output/FGXMLElement.cpp index 094735d8ad..02cf1a17bf 100644 --- a/src/input_output/FGXMLElement.cpp +++ b/src/input_output/FGXMLElement.cpp @@ -32,6 +32,7 @@ INCLUDES #include // using domain_error, invalid_argument, and length_error. #include "FGXMLElement.h" #include "FGJSBBase.h" +#include using namespace std; @@ -667,9 +668,12 @@ double Element::DisperseValue(Element *e, double val, const std::string& supplie if (!supplied_units.empty()) disp *= convert[supplied_units][target_units]; string attType = e->GetAttributeValue("type"); if (attType == "gaussian" || attType == "gaussiansigned") { - double grn = FGJSBBase::GaussianRandomNumber(); - if (attType == "gaussian") { - value = val + disp*grn; + std::random_device rd{}; + std::mt19937 gen{rd()}; + std::normal_distribution d{0, 1}; + double grn = d(gen); + if (attType == "gaussian") { + value = val + disp*grn; } else { // Assume gaussiansigned value = (val + disp*grn)*(fabs(grn)/grn); } @@ -755,13 +759,6 @@ void Element::MergeAttributes(Element* el) for (it=el->attributes.begin(); it != el->attributes.end(); ++it) { if (attributes.find(it->first) == attributes.end()) attributes[it->first] = it->second; - else { - if (FGJSBBase::debug_lvl > 0 && (attributes[it->first] != it->second)) - cout << el->ReadFrom() << " Attribute '" << it->first << "' is overridden in file " - << GetFileName() << ": line " << GetLineNumber() << endl - << " The value '" << attributes[it->first] << "' will be used instead of '" - << it->second << "'." << endl; - } } } diff --git a/src/input_output/FGfdmSocket.cpp b/src/input_output/FGfdmSocket.cpp index e6ebc91e14..761ac8e991 100644 --- a/src/input_output/FGfdmSocket.cpp +++ b/src/input_output/FGfdmSocket.cpp @@ -74,14 +74,15 @@ static bool LoadWinSockDLL(int debug_lvl) return false; } - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << "Winsock DLL loaded ..." << endl; return true; } #endif -FGfdmSocket::FGfdmSocket(const string& address, int port, int protocol, int precision) +FGfdmSocket::FGfdmSocket(CommonData& c, const string& address, int port, int protocol, int precision) + : FGJSBBase(c) { sckt = sckt_in = 0; Protocol = (ProtocolType)protocol; @@ -90,7 +91,7 @@ FGfdmSocket::FGfdmSocket(const string& address, int port, int protocol, int prec this->precision = precision; #if defined(_MSC_VER) || defined(__MINGW32__) - if (!LoadWinSockDLL(debug_lvl)) return; + if (!LoadWinSockDLL(gdata().debug_lvl)) return; #endif struct addrinfo hints; @@ -123,7 +124,7 @@ FGfdmSocket::FGfdmSocket(const string& address, int port, int protocol, int prec sckt = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol); - if (debug_lvl > 0) { + if (gdata().debug_lvl > 0) { if (protocol == ptUDP) //use udp protocol cout << "Creating UDP socket on port " << port << endl; else //use tcp protocol @@ -136,7 +137,7 @@ FGfdmSocket::FGfdmSocket(const string& address, int port, int protocol, int prec scktName.sin_port = htons(port); if (connect(sckt, (struct sockaddr*)&scktName, len) == 0) { // successful - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << "Successfully connected to socket for output ..." << endl; connected = true; } else // unsuccessful @@ -151,7 +152,8 @@ FGfdmSocket::FGfdmSocket(const string& address, int port, int protocol, int prec //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // assumes TCP or UDP socket on localhost, for inbound datagrams -FGfdmSocket::FGfdmSocket(int port, int protocol, int precision) +FGfdmSocket::FGfdmSocket(CommonData& c, int port, int protocol, int precision) + : FGJSBBase(c) { sckt = -1; connected = false; @@ -160,7 +162,7 @@ FGfdmSocket::FGfdmSocket(int port, int protocol, int precision) this->precision = precision; #if defined(_MSC_VER) || defined(__MINGW32__) - if (!LoadWinSockDLL(debug_lvl)) return; + if (!LoadWinSockDLL(gdata().debug_lvl)) return; #endif if (Protocol == ptUDP) { //use udp protocol @@ -178,7 +180,7 @@ FGfdmSocket::FGfdmSocket(int port, int protocol, int precision) sckt = socket(AF_INET, SOCK_STREAM, 0); } - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << "Creating input " << ProtocolName << " socket on port " << port << endl; @@ -192,7 +194,7 @@ FGfdmSocket::FGfdmSocket(int port, int protocol, int precision) int len = sizeof(struct sockaddr_in); if (bind(sckt, (struct sockaddr*)&scktName, len) != -1) { - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << "Successfully bound to " << ProtocolName << " input socket on port " << port << endl << endl; @@ -415,6 +417,7 @@ void FGfdmSocket::WaitUntilReadable(void) void FGfdmSocket::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/input_output/FGfdmSocket.h b/src/input_output/FGfdmSocket.h index 7327088df4..a901944c9d 100644 --- a/src/input_output/FGfdmSocket.h +++ b/src/input_output/FGfdmSocket.h @@ -70,8 +70,8 @@ CLASS DECLARATION class FGfdmSocket : public FGJSBBase { public: - FGfdmSocket(const std::string& address, int port, int protocol, int precision = 7); - FGfdmSocket(int port, int protocol, int precision = 7); + FGfdmSocket(CommonData& gdata, const std::string& address, int port, int protocol, int precision = 7); + FGfdmSocket(CommonData& gdata, int port, int protocol, int precision = 7); ~FGfdmSocket(); void Send(void); void Send(const char *data, int length); diff --git a/src/math/FGCondition.cpp b/src/math/FGCondition.cpp index a98f1393ac..b9ef09ac2b 100644 --- a/src/math/FGCondition.cpp +++ b/src/math/FGCondition.cpp @@ -53,8 +53,8 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ // This constructor is called when tests are inside an element -FGCondition::FGCondition(Element* element, FGPropertyManager* PropertyManager) - : Logic(elUndef), TestParam1(nullptr), TestParam2(nullptr), +FGCondition::FGCondition(CommonData& c, Element* element, FGPropertyManager* PropertyManager) + : FGJSBBase(c), Logic(elUndef), TestParam1(nullptr), TestParam2(nullptr), Comparison(ecUndef) { InitializeConditionals(); @@ -74,7 +74,7 @@ FGCondition::FGCondition(Element* element, FGPropertyManager* PropertyManager) for (unsigned int i=0; iGetNumDataLines(); i++) { string data = element->GetDataLine(i); - conditions.push_back(new FGCondition(data, PropertyManager, element)); + conditions.push_back(new FGCondition(c, data, PropertyManager, element)); } Element* condition_element = element->GetElement(); @@ -90,7 +90,7 @@ FGCondition::FGCondition(Element* element, FGPropertyManager* PropertyManager) throw std::invalid_argument("FGCondition: unrecognized tag:'" + tagName + "'"); } - conditions.push_back(new FGCondition(condition_element, PropertyManager)); + conditions.push_back(new FGCondition(c, condition_element, PropertyManager)); condition_element = element->GetNextElement(); } @@ -101,9 +101,9 @@ FGCondition::FGCondition(Element* element, FGPropertyManager* PropertyManager) // This constructor is called when there are no nested test groups inside the // condition -FGCondition::FGCondition(const string& test, FGPropertyManager* PropertyManager, +FGCondition::FGCondition(CommonData& c, const string& test, FGPropertyManager* PropertyManager, Element* el) - : Logic(elUndef), TestParam1(nullptr), TestParam2(nullptr), + : FGJSBBase(c), Logic(elUndef), TestParam1(nullptr), TestParam2(nullptr), Comparison(ecUndef) { InitializeConditionals(); @@ -279,6 +279,7 @@ void FGCondition::PrintCondition(string indent) void FGCondition::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/math/FGCondition.h b/src/math/FGCondition.h index 517a4d8574..b57ed26846 100644 --- a/src/math/FGCondition.h +++ b/src/math/FGCondition.h @@ -66,14 +66,14 @@ CLASS DECLARATION class FGCondition : public FGJSBBase { public: - FGCondition(Element* element, FGPropertyManager* PropertyManager); + FGCondition(CommonData& c, Element* element, FGPropertyManager* PropertyManager); ~FGCondition(void); bool Evaluate(void); void PrintCondition(std::string indent=" "); private: - FGCondition(const std::string& test, FGPropertyManager* PropertyManager, + FGCondition(CommonData& c, const std::string& test, FGPropertyManager* PropertyManager, Element* el); enum eComparison {ecUndef=0, eEQ, eNE, eGT, eGE, eLT, eLE}; diff --git a/src/math/FGFunction.cpp b/src/math/FGFunction.cpp index 0a777425ad..b4678b97ad 100644 --- a/src/math/FGFunction.cpp +++ b/src/math/FGFunction.cpp @@ -79,7 +79,7 @@ class aFunc: public FGFunction aFunc(const func_t& _f, FGFDMExec* fdmex, Element* el, const string& prefix, FGPropertyValue* v, unsigned int Nmax=Nmin, FGFunction::OddEven odd_even=FGFunction::OddEven::Either) - : FGFunction(fdmex->GetPropertyManager()), f(_f) + : FGFunction(fdmex->gdata(), fdmex->GetPropertyManager()), f(_f) { Load(el, v, fdmex, prefix); CheckMinArguments(el, Nmin); @@ -109,14 +109,14 @@ template class aFunc: public FGFunction { public: - aFunc(const func_t& _f, FGPropertyManager* pm, Element* el, + aFunc(CommonData& c, const func_t& _f, FGPropertyManager* pm, Element* el, const string& Prefix) - : FGFunction(pm), f(_f) + : FGFunction(c, pm), f(_f) { if (el->GetNumElements() != 0) { ostringstream buffer; - buffer << el->ReadFrom() << fgred << highint - << "<" << el->GetName() << "> should have no arguments." << reset + buffer << el->ReadFrom() << c.fgred << c.highint + << "<" << el->GetName() << "> should have no arguments." << c.reset << endl; throw WrongNumberOfArguments(buffer.str(), Parameters, el); } @@ -157,9 +157,9 @@ bool GetBinary(double val, const string &ctxMsg) if (val < 1E-9) return false; else if (val-1 < 1E-9) return true; else { - cerr << ctxMsg << FGJSBBase::fgred << FGJSBBase::highint + cerr << ctxMsg << "Malformed conditional check in function definition." - << FGJSBBase::reset << endl; + << endl; throw("Fatal Error."); } } @@ -191,11 +191,11 @@ FGParameter_ptr VarArgsFn(const func_t& _f, FGFDMExec* fdmex, Element* el, } catch(WrongNumberOfArguments& e) { if ((e.GetElement() == el) && (e.NumberOfArguments() == 1)) { - cerr << el->ReadFrom() << FGJSBBase::fgred + cerr << el->ReadFrom() << fdmex->gdata().fgred << "<" << el->GetName() << "> only has one argument which makes it a no-op." << endl << "Its argument will be evaluated but <" << el->GetName() - << "> will not be applied to the result." << FGJSBBase::reset << endl; + << "> will not be applied to the result." << fdmex->gdata().reset << endl; return e.FirstParameter(); } else @@ -207,7 +207,7 @@ FGParameter_ptr VarArgsFn(const func_t& _f, FGFDMExec* fdmex, Element* el, FGFunction::FGFunction(FGFDMExec* fdmex, Element* el, const string& prefix, FGPropertyValue* var) - : FGFunction(fdmex->GetPropertyManager()) + : FGFunction(fdmex->gdata(), fdmex->GetPropertyManager()) { Load(el, var, fdmex, prefix); CheckMinArguments(el, 1); @@ -220,8 +220,8 @@ FGFunction::FGFunction(FGFDMExec* fdmex, Element* el, const string& prefix, if (is_number(prefix)) sCopyTo = replace(sCopyTo,"#",prefix); else { - cerr << el->ReadFrom() << fgred - << "Illegal use of the special character '#'" << reset << endl + cerr << el->ReadFrom() << gdata().fgred + << "Illegal use of the special character '#'" << gdata().reset << endl << "The 'copyto' argument in function " << Name << " is ignored." << endl; return; @@ -230,9 +230,9 @@ FGFunction::FGFunction(FGFDMExec* fdmex, Element* el, const string& prefix, pCopyTo = PropertyManager->GetNode(sCopyTo); if (!pCopyTo) - cerr << el->ReadFrom() << fgred + cerr << el->ReadFrom() << gdata().fgred << "Property \"" << sCopyTo - << "\" must be previously defined in function " << Name << reset + << "\" must be previously defined in function " << Name << gdata().reset << "The 'copyto' argument is ignored." << endl; } } @@ -243,9 +243,9 @@ void FGFunction::CheckMinArguments(Element* el, unsigned int _min) { if (Parameters.size() < _min) { ostringstream buffer; - buffer << el->ReadFrom() << fgred << highint + buffer << el->ReadFrom() << gdata().fgred << gdata().highint << "<" << el->GetName() << "> should have at least " << _min - << " argument(s)." << reset << endl; + << " argument(s)." << gdata().reset << endl; throw WrongNumberOfArguments(buffer.str(), Parameters, el); } } @@ -256,9 +256,9 @@ void FGFunction::CheckMaxArguments(Element* el, unsigned int _max) { if (Parameters.size() > _max) { ostringstream buffer; - buffer << el->ReadFrom() << fgred << highint + buffer << el->ReadFrom() << gdata().fgred << gdata().highint << "<" << el->GetName() << "> should have no more than " << _max - << " argument(s)." << reset << endl; + << " argument(s)." << gdata().reset << endl; throw WrongNumberOfArguments(buffer.str(), Parameters, el); } } @@ -271,17 +271,17 @@ void FGFunction::CheckOddOrEvenArguments(Element* el, OddEven odd_even) switch(odd_even) { case OddEven::Even: if (Parameters.size() % 2 == 1) { - cerr << el->ReadFrom() << fgred << highint + cerr << el->ReadFrom() << gdata().fgred << gdata().highint << "<" << el->GetName() << "> must have an even number of arguments." - << reset << endl; + << gdata().reset << endl; throw("Fatal Error"); } break; case OddEven::Odd: if (Parameters.size() % 2 == 0) { - cerr << el->ReadFrom() << fgred << highint + cerr << el->ReadFrom() << gdata().fgred << gdata().highint << "<" << el->GetName() << "> must have an odd number of arguments." - << reset << endl; + << gdata().reset << endl; throw("Fatal Error"); } break; @@ -338,8 +338,8 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, } else { cerr << element->ReadFrom() - << fgred << "Illegal use of the special character '#'" - << reset << endl; + << gdata().fgred << "Illegal use of the special character '#'" + << gdata().reset << endl; throw("Fatal Error."); } } @@ -352,10 +352,10 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, PropertyManager, f)); else { cerr << element->ReadFrom() - << fgred << highint << " No function by the name " + << gdata().fgred << gdata().highint << " No function by the name " << function_str << " has been defined. This property will " << "not be logged. You should check your configuration file." - << reset << endl; + << gdata().reset << endl; } } else @@ -374,7 +374,7 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, << endl; throw BaseException("An internal table cannot be nested within a function."); } - Parameters.push_back(new FGTable(PropertyManager, element, Prefix)); + Parameters.push_back(new FGTable(gdata(), PropertyManager, element, Prefix)); // operations } else if (operation == "product") { auto f = [](const decltype(Parameters)& Parameters)->double { @@ -611,8 +611,7 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, auto f = [generator, distribution]()->double { return (*distribution.get())(*generator); }; - Parameters.push_back(new aFunc(f, PropertyManager, element, - Prefix)); + Parameters.push_back(new aFunc(gdata(), f, PropertyManager, element, Prefix)); } else if (operation == "urandom") { double lower = -1.0; double upper = 1.0; @@ -627,16 +626,15 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, auto f = [generator, distribution]()->double { return (*distribution.get())(*generator); }; - Parameters.push_back(new aFunc(f, PropertyManager, element, - Prefix)); + Parameters.push_back(new aFunc(gdata(), f, PropertyManager, element, Prefix)); } else if (operation == "switch") { string ctxMsg = element->ReadFrom(); - auto f = [ctxMsg](const decltype(Parameters)& p)->double { + auto f = [this, ctxMsg](const decltype(Parameters)& p)->double { double temp = p[0]->GetValue(); if (temp < 0.0) { - cerr << ctxMsg << fgred << highint + cerr << ctxMsg << gdata().fgred << gdata().highint << "The switch function index (" << temp - << ") is negative." << reset << endl; + << ") is negative." << gdata().reset << endl; throw("Fatal error"); } size_t n = p.size()-1; @@ -645,16 +643,15 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, if (i < n) return p[i+1]->GetValue(); else { - cerr << ctxMsg << fgred << highint + cerr << ctxMsg << gdata().fgred << gdata().highint << "The switch function index (" << temp << ") selected a value above the range of supplied values" << "[0:" << n-1 << "]" - << " - not enough values were supplied." << reset << endl; + << " - not enough values were supplied." << gdata().reset << endl; throw("Fatal error"); } }; - Parameters.push_back(new aFunc(f, fdmex, element, Prefix, - var, MaxArgs)); + Parameters.push_back(new aFunc(f, fdmex, element, Prefix, var, MaxArgs)); } else if (operation == "interpolate1d") { auto f = [](const decltype(Parameters)& p)->double { // This is using the bisection algorithm. Special care has been @@ -696,14 +693,14 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, // Calculates local angle of attack for skydiver body component. // Euler angles from the intermediate body frame to the local body frame // must be from a z-y-x axis rotation order - auto f = [](const decltype(Parameters)& p)->double { + auto f = [this](const decltype(Parameters)& p)->double { double alpha = p[0]->GetValue()*degtorad; //angle of attack of intermediate body frame double beta = p[1]->GetValue()*degtorad; //sideslip angle of intermediate body frame double phi = p[3]->GetValue()*degtorad; //x-axis Euler angle from the intermediate body frame to the local body frame double theta = p[4]->GetValue()*degtorad; //y-axis Euler angle from the intermediate body frame to the local body frame double psi = p[5]->GetValue()*degtorad; //z-axis Euler angle from the intermediate body frame to the local body frame - FGQuaternion qTb2l(phi, theta, psi); + FGQuaternion qTb2l(gdata(), phi, theta, psi); double cos_beta = cos(beta); FGColumnVector3 wind_body(cos(alpha)*cos_beta, sin(beta), sin(alpha)*cos_beta); @@ -719,13 +716,13 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, // Calculates local angle of sideslip for skydiver body component. // Euler angles from the intermediate body frame to the local body frame // must be from a z-y-x axis rotation order - auto f = [](const decltype(Parameters)& p)->double { + auto f = [this](const decltype(Parameters)& p)->double { double alpha = p[0]->GetValue()*degtorad; //angle of attack of intermediate body frame double beta = p[1]->GetValue()*degtorad; //sideslip angle of intermediate body frame double phi = p[3]->GetValue()*degtorad; //x-axis Euler angle from the intermediate body frame to the local body frame double theta = p[4]->GetValue()*degtorad; //y-axis Euler angle from the intermediate body frame to the local body frame double psi = p[5]->GetValue()*degtorad; //z-axis Euler angle from the intermediate body frame to the local body frame - FGQuaternion qTb2l(phi, theta, psi); + FGQuaternion qTb2l(gdata(), phi, theta, psi); double cos_beta = cos(beta); FGColumnVector3 wind_body(cos(alpha)*cos_beta, sin(beta), sin(alpha)*cos_beta); @@ -751,7 +748,7 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, // Calculates local roll angle for skydiver body component. // Euler angles from the intermediate body frame to the local body frame // must be from a z-y-x axis rotation order - auto f = [](const decltype(Parameters)& p)->double { + auto f = [this](const decltype(Parameters)& p)->double { double alpha = p[0]->GetValue()*degtorad; //angle of attack of intermediate body frame double beta = p[1]->GetValue()*degtorad; //sideslip angle of intermediate body frame double gamma = p[2]->GetValue()*degtorad; //roll angle of intermediate body frame @@ -761,7 +758,7 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, double cos_alpha = cos(alpha), sin_alpha = sin(alpha); double cos_beta = cos(beta), sin_beta = sin(beta); double cos_gamma = cos(gamma), sin_gamma = sin(gamma); - FGQuaternion qTb2l(phi, theta, psi); + FGQuaternion qTb2l(gdata(), phi, theta, psi); FGColumnVector3 wind_body_X(cos_alpha*cos_beta, sin_beta, sin_alpha*cos_beta); FGColumnVector3 wind_body_Y(-sin_alpha*sin_gamma-sin_beta*cos_alpha*cos_gamma, @@ -798,7 +795,7 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, // Transforms the input vector from a body frame to a wind frame. The // origin of the vector remains the same. string ctxMsg = element->ReadFrom(); - auto f = [ctxMsg](const decltype(Parameters)& p)->double { + auto f = [this, ctxMsg](const decltype(Parameters)& p)->double { double rx = p[0]->GetValue(); //x component of input vector double ry = p[1]->GetValue(); //y component of input vector double rz = p[2]->GetValue(); //z component of input vector @@ -808,13 +805,13 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, int idx = static_cast(p[6]->GetValue()); if ((idx < 1) || (idx > 3)) { - cerr << ctxMsg << fgred << highint + cerr << ctxMsg << gdata().fgred << gdata().highint << "The index must be one of the integer value 1, 2 or 3." - << reset << endl; + << gdata().reset << endl; throw("Fatal error"); } - FGQuaternion qa(eY, -alpha), qb(eZ, beta), qc(eX, -gamma); + FGQuaternion qa(gdata(), eY, -alpha), qb(gdata(), eZ, beta), qc(gdata(), eX, -gamma); FGMatrix33 mT = (qa*qb*qc).GetT(); FGColumnVector3 r0(rx, ry, rz); FGColumnVector3 r = mT*r0; @@ -826,7 +823,7 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, // Transforms the input vector from q wind frame to a body frame. The // origin of the vector remains the same. string ctxMsg = element->ReadFrom(); - auto f = [ctxMsg](const decltype(Parameters)& p)->double { + auto f = [this, ctxMsg](const decltype(Parameters)& p)->double { double rx = p[0]->GetValue(); //x component of input vector double ry = p[1]->GetValue(); //y component of input vector double rz = p[2]->GetValue(); //z component of input vector @@ -836,13 +833,13 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, int idx = static_cast(p[6]->GetValue()); if ((idx < 1) || (idx > 3)) { - cerr << ctxMsg << fgred << highint + cerr << ctxMsg << gdata().fgred << gdata().highint << "The index must be one of the integer value 1, 2 or 3." - << reset << endl; + << gdata().reset << endl; throw("Fatal error"); } - FGQuaternion qa(eY, -alpha), qb(eZ, beta), qc(eX, -gamma); + FGQuaternion qa(gdata(), eY, -alpha), qb(gdata(), eZ, beta), qc(gdata(), eX, -gamma); FGMatrix33 mT = (qa*qb*qc).GetT(); FGColumnVector3 r0(rx, ry, rz); mT.T(); @@ -852,9 +849,9 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, }; Parameters.push_back(new aFunc(f, fdmex, element, Prefix, var)); } else if (operation != "description") { - cerr << element->ReadFrom() << fgred << highint + cerr << element->ReadFrom() << gdata().fgred << gdata().highint << "Bad operation <" << operation - << "> detected in configuration file" << reset << endl; + << "> detected in configuration file" << gdata().reset << endl; } // Optimize functions applied on constant parameters by replacing them by @@ -869,8 +866,8 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, Parameters.pop_back(); Parameters.push_back(new FGRealValue(constant)); - if (debug_lvl > 0) - cout << element->ReadFrom() << fggreen << highint + if (gdata().debug_lvl > 0) + cout << element->ReadFrom() << gdata().fggreen << gdata().highint << "<" << operation << "> is applied on constant parameters." << endl << "It will be replaced by its result (" << constant << ")"; @@ -878,11 +875,11 @@ void FGFunction::Load(Element* el, FGPropertyValue* var, FGFDMExec* fdmex, if (node) { node->setDoubleValue(constant); node->setAttribute(SGPropertyNode::WRITE, false); - if (debug_lvl > 0) + if (gdata().debug_lvl > 0) cout << " and the property " << pName << " will be unbound and made read only."; } - cout << reset << endl << endl; + cout << gdata().reset << endl << endl; } } element = el->GetNextElement(); @@ -1017,6 +1014,7 @@ void FGFunction::bind(Element* el, const string& Prefix) void FGFunction::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/math/FGFunction.h b/src/math/FGFunction.h index 873af1e3f4..30fc546852 100644 --- a/src/math/FGFunction.h +++ b/src/math/FGFunction.h @@ -753,12 +753,12 @@ class FGFunction : public FGParameter, public FGJSBBase { public: /// Default constructor. - FGFunction() - : cached(false), cachedValue(-HUGE_VAL), PropertyManager(nullptr), + FGFunction(CommonData& c) + : FGJSBBase(c), cached(false), cachedValue(-HUGE_VAL), PropertyManager(nullptr), pNode(nullptr), pCopyTo(nullptr) {} - explicit FGFunction(FGPropertyManager* pm) - : FGFunction() + explicit FGFunction(CommonData& c, FGPropertyManager* pm) + : FGFunction(c) { PropertyManager = pm; } /** Constructor. diff --git a/src/math/FGLocation.cpp b/src/math/FGLocation.cpp index 3db73ec1c3..b13ca1f703 100644 --- a/src/math/FGLocation.cpp +++ b/src/math/FGLocation.cpp @@ -51,8 +51,8 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGLocation::FGLocation(void) - : mECLoc(1.0, 0.0, 0.0), mCacheValid(false) +FGLocation::FGLocation(CommonData& r) + : FGJSBBase(r), mECLoc(1.0, 0.0, 0.0), mCacheValid(false) { e2 = c = 0.0; a = ec = ec2 = 1.0; @@ -66,8 +66,8 @@ FGLocation::FGLocation(void) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGLocation::FGLocation(double lon, double lat, double radius) - : mCacheValid(false) +FGLocation::FGLocation(CommonData& r, double lon, double lat, double radius) + : FGJSBBase(r), mCacheValid(false) { e2 = c = 0.0; a = ec = ec2 = 1.0; @@ -89,8 +89,8 @@ FGLocation::FGLocation(double lon, double lat, double radius) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGLocation::FGLocation(const FGColumnVector3& lv) - : mECLoc(lv), mCacheValid(false) +FGLocation::FGLocation(CommonData& r, const FGColumnVector3& lv) + : FGJSBBase(r), mECLoc(lv), mCacheValid(false) { e2 = c = 0.0; a = ec = ec2 = 1.0; @@ -105,7 +105,7 @@ FGLocation::FGLocation(const FGColumnVector3& lv) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGLocation::FGLocation(const FGLocation& l) - : mECLoc(l.mECLoc), mCacheValid(l.mCacheValid) + : FGJSBBase(const_cast(l.gdata())), mECLoc(l.mECLoc), mCacheValid(l.mCacheValid) { a = l.a; e2 = l.e2; diff --git a/src/math/FGLocation.h b/src/math/FGLocation.h index ca4678016e..8866712c8d 100644 --- a/src/math/FGLocation.h +++ b/src/math/FGLocation.h @@ -152,20 +152,20 @@ class JSBSIM_API FGLocation : public FGJSBBase { public: /** Default constructor. */ - FGLocation(void); + FGLocation(CommonData& c); /** Constructor to set the longitude, latitude and the distance from the center of the earth. @param lon longitude @param lat GEOCENTRIC latitude @param radius distance from center of earth to vehicle in feet*/ - FGLocation(double lon, double lat, double radius); + FGLocation(CommonData& c, double lon, double lat, double radius); /** Constructor to initialize the location with the cartesian coordinates (X,Y,Z) contained in the input FGColumnVector3. Distances are in feet, the position is expressed in the ECEF frame. @param lv vector that contain the cartesian coordinates*/ - FGLocation(const FGColumnVector3& lv); + FGLocation(CommonData& c, const FGColumnVector3& lv); /** Copy constructor. */ FGLocation(const FGLocation& l); @@ -324,7 +324,7 @@ class JSBSIM_API FGLocation : public FGJSBBase @param lvec Vector in the local horizontal coordinate frame @return The location in the earth centered and fixed frame */ FGLocation LocalToLocation(const FGColumnVector3& lvec) const { - ComputeDerived(); return mTl2ec*lvec + mECLoc; + ComputeDerived(); return FGLocation(const_cast(gdata()), mTl2ec*lvec + mECLoc); } /** Conversion from a location in the earth centered and fixed frame @@ -448,7 +448,7 @@ class JSBSIM_API FGLocation : public FGJSBBase A new object is returned that defines a position which is the sum of the cartesian coordinates of the two positions provided. */ FGLocation operator+(const FGLocation& l) const { - FGLocation result(mECLoc + l.mECLoc); + FGLocation result(const_cast(gdata()), mECLoc + l.mECLoc); if (mEllipseSet) result.SetEllipse(a, ec*a); return result; } @@ -457,7 +457,7 @@ class JSBSIM_API FGLocation : public FGJSBBase A new object is returned that defines a position which is the difference of the cartesian coordinates of the two positions provided. */ FGLocation operator-(const FGLocation& l) const { - FGLocation result(mECLoc - l.mECLoc); + FGLocation result(const_cast(gdata()), mECLoc - l.mECLoc); if (mEllipseSet) result.SetEllipse(a, ec*a); return result; } @@ -467,7 +467,7 @@ class JSBSIM_API FGLocation : public FGJSBBase coordinates of the provided ECEF position scaled by the supplied scalar value. */ FGLocation operator*(double scalar) const { - FGLocation result(scalar*mECLoc); + FGLocation result(const_cast(gdata()), scalar*mECLoc); if (mEllipseSet) result.SetEllipse(a, ec*a); return result; } diff --git a/src/math/FGMatrix33.cpp b/src/math/FGMatrix33.cpp index bcf5105f14..7007bc6c44 100644 --- a/src/math/FGMatrix33.cpp +++ b/src/math/FGMatrix33.cpp @@ -103,9 +103,9 @@ string FGMatrix33::Dump(const string& delimiter, const string& prefix) const //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGQuaternion FGMatrix33::GetQuaternion(void) const +FGQuaternion FGMatrix33::GetQuaternion(CommonData& c) const { - FGQuaternion Q; + FGQuaternion Q(c); double tempQ[4]; int idx; diff --git a/src/math/FGMatrix33.h b/src/math/FGMatrix33.h index fce665356d..8c3cf6db37 100644 --- a/src/math/FGMatrix33.h +++ b/src/math/FGMatrix33.h @@ -254,7 +254,7 @@ class JSBSIM_API FGMatrix33 /** Returns the quaternion associated with this direction cosine (rotation) matrix. */ - FGQuaternion GetQuaternion(void) const; + FGQuaternion GetQuaternion(CommonData& c) const; /** Returns the Euler angle column vector associated with this matrix. */ diff --git a/src/math/FGModelFunctions.cpp b/src/math/FGModelFunctions.cpp index 27891e14d2..86d01af3f3 100644 --- a/src/math/FGModelFunctions.cpp +++ b/src/math/FGModelFunctions.cpp @@ -54,7 +54,7 @@ FGModelFunctions::~FGModelFunctions() for (auto prefunc: PreFunctions) delete prefunc; for (auto postfunc: PostFunctions) delete postfunc; - if (debug_lvl & 2) cout << "Destroyed: FGModelFunctions" << endl; + if (gdata().debug_lvl & 2) cout << "Destroyed: FGModelFunctions" << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/math/FGModelFunctions.h b/src/math/FGModelFunctions.h index a19ba248ec..3f764de6ab 100644 --- a/src/math/FGModelFunctions.h +++ b/src/math/FGModelFunctions.h @@ -72,6 +72,7 @@ DECLARATION: FGModelFunctions class FGModelFunctions : public FGJSBBase { public: + FGModelFunctions(CommonData& c) : FGJSBBase(c) {} virtual ~FGModelFunctions(); void RunPreFunctions(void); void RunPostFunctions(void); diff --git a/src/math/FGQuaternion.cpp b/src/math/FGQuaternion.cpp index 1895423c62..dc2d480657 100644 --- a/src/math/FGQuaternion.cpp +++ b/src/math/FGQuaternion.cpp @@ -61,7 +61,8 @@ namespace JSBSim { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Initialize from q -FGQuaternion::FGQuaternion(const FGQuaternion& q) : mCacheValid(q.mCacheValid) +FGQuaternion::FGQuaternion(const FGQuaternion& q) + : FGJSBBase(const_cast(q.gdata())), mCacheValid(q.mCacheValid) { data[0] = q(1); data[1] = q(2); @@ -79,14 +80,14 @@ FGQuaternion::FGQuaternion(const FGQuaternion& q) : mCacheValid(q.mCacheValid) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Initialize with the three euler angles -FGQuaternion::FGQuaternion(double phi, double tht, double psi): mCacheValid(false) +FGQuaternion::FGQuaternion(CommonData& c, double phi, double tht, double psi): FGJSBBase(c), mCacheValid(false) { InitializeFromEulerAngles(phi, tht, psi); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGQuaternion::FGQuaternion(FGColumnVector3 vOrient): mCacheValid(false) +FGQuaternion::FGQuaternion(CommonData& c, FGColumnVector3 vOrient) : FGJSBBase(c), mCacheValid(false) { double phi = vOrient(ePhi); double tht = vOrient(eTht); @@ -136,7 +137,7 @@ void FGQuaternion::InitializeFromEulerAngles(double phi, double tht, double psi) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% // Initialize with a direction cosine (rotation) matrix -FGQuaternion::FGQuaternion(const FGMatrix33& m) : mCacheValid(false) +FGQuaternion::FGQuaternion(CommonData& c, const FGMatrix33& m) : FGJSBBase(c), mCacheValid(false) { data[0] = 0.50*sqrt(1.0 + m(1,1) + m(2,2) + m(3,3)); double t = 0.25/data[0]; @@ -157,7 +158,7 @@ FGQuaternion::FGQuaternion(const FGMatrix33& m) : mCacheValid(false) */ FGQuaternion FGQuaternion::GetQDot(const FGColumnVector3& PQR) const { - return FGQuaternion( + return FGQuaternion(const_cast(gdata()), -0.5*( data[1]*PQR(eP) + data[2]*PQR(eQ) + data[3]*PQR(eR)), 0.5*( data[0]*PQR(eP) - data[3]*PQR(eQ) + data[2]*PQR(eR)), 0.5*( data[3]*PQR(eP) + data[0]*PQR(eQ) - data[1]*PQR(eR)), diff --git a/src/math/FGQuaternion.h b/src/math/FGQuaternion.h index f084a84b90..49ad90eb2c 100644 --- a/src/math/FGQuaternion.h +++ b/src/math/FGQuaternion.h @@ -87,7 +87,7 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { public: /** Default initializer. Default initializer, initializes the class with the identity rotation. */ - FGQuaternion() : mCacheValid(false) { + FGQuaternion(CommonData& c) : FGJSBBase(c), mCacheValid(false) { data[0] = 1.0; data[1] = data[2] = data[3] = 0.0; } @@ -102,20 +102,20 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { @param phi The euler X axis (roll) angle in radians @param tht The euler Y axis (attitude) angle in radians @param psi The euler Z axis (heading) angle in radians */ - FGQuaternion(double phi, double tht, double psi); + FGQuaternion(CommonData& c, double phi, double tht, double psi); /** Initializer by euler angle vector. Initialize the quaternion with the euler angle vector. @param vOrient The euler axis angle vector in radians (phi, tht, psi) */ - FGQuaternion(FGColumnVector3 vOrient); + FGQuaternion(CommonData& c, FGColumnVector3 vOrient); /** Initializer by one euler angle. Initialize the quaternion with the single euler angle where its index is given in the first argument. @param idx Index of the euler angle to initialize @param angle The euler angle in radians */ - FGQuaternion(int idx, double angle) - : mCacheValid(false) { + FGQuaternion(CommonData& c, int idx, double angle) + : FGJSBBase(c), mCacheValid(false) { double angle2 = 0.5*angle; @@ -149,8 +149,8 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { @param angle The angle in radians @param axis The rotation axis */ - FGQuaternion(double angle, const FGColumnVector3& axis) - : mCacheValid(false) { + FGQuaternion(CommonData& c, double angle, const FGColumnVector3& axis) + : FGJSBBase(c), mCacheValid(false) { double angle2 = 0.5 * angle; @@ -168,7 +168,7 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { Initialize the quaternion with the matrix representing a transform from one frame to another using the standard aerospace sequence, Yaw-Pitch-Roll (3-2-1). @param m the rotation matrix */ - FGQuaternion(const FGMatrix33& m); + FGQuaternion(CommonData& c, const FGMatrix33& m); /// Destructor. ~FGQuaternion() {} @@ -387,7 +387,8 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { @param q a quaternion to be summed. @return a quaternion representing Q, where Q = Q + q. */ FGQuaternion operator+(const FGQuaternion& q) const { - return FGQuaternion(data[0]+q.data[0], data[1]+q.data[1], + return FGQuaternion(const_cast(gdata()), + data[0]+q.data[0], data[1]+q.data[1], data[2]+q.data[2], data[3]+q.data[3]); } @@ -395,7 +396,8 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { @param q a quaternion to be subtracted. @return a quaternion representing Q, where Q = Q - q. */ FGQuaternion operator-(const FGQuaternion& q) const { - return FGQuaternion(data[0]-q.data[0], data[1]-q.data[1], + return FGQuaternion(const_cast(gdata()), + data[0]-q.data[0], data[1]-q.data[1], data[2]-q.data[2], data[3]-q.data[3]); } @@ -404,7 +406,8 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { @param q a quaternion to be multiplied. @return a quaternion representing Q, where Q = Q * q. */ FGQuaternion operator*(const FGQuaternion& q) const { - return FGQuaternion(data[0]*q.data[0]-data[1]*q.data[1]-data[2]*q.data[2]-data[3]*q.data[3], + return FGQuaternion(const_cast(gdata()), + data[0]*q.data[0]-data[1]*q.data[1]-data[2]*q.data[2]-data[3]*q.data[3], data[0]*q.data[1]+data[1]*q.data[0]+data[2]*q.data[3]-data[3]*q.data[2], data[0]*q.data[2]-data[1]*q.data[3]+data[2]*q.data[0]+data[3]*q.data[1], data[0]*q.data[3]+data[1]*q.data[2]-data[2]*q.data[1]+data[3]*q.data[0]); @@ -438,7 +441,8 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { if (norm == 0.0) return *this; double rNorm = 1.0/norm; - return FGQuaternion( data[0]*rNorm, -data[1]*rNorm, + return FGQuaternion(const_cast(gdata()), + data[0]*rNorm, -data[1]*rNorm, -data[2]*rNorm, -data[3]*rNorm ); } @@ -448,7 +452,7 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { to the inverse iff the quaternion is normalized. */ FGQuaternion Conjugate(void) const { - return FGQuaternion( data[0], -data[1], -data[2], -data[3] ); + return FGQuaternion(const_cast(gdata()), data[0], -data[1], -data[2], -data[3] ); } friend FGQuaternion operator*(double, const FGQuaternion&); @@ -477,15 +481,15 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { /** Zero quaternion vector. Does not represent any orientation. Useful for initialization of increments */ - static FGQuaternion zero(void) { return FGQuaternion( 0.0, 0.0, 0.0, 0.0 ); } + static FGQuaternion zero(CommonData& c) { return FGQuaternion(c, 0.0, 0.0, 0.0, 0.0 ); } std::string Dump(const std::string& delimiter) const; - friend FGQuaternion QExp(const FGColumnVector3& omega); + friend FGQuaternion QExp(CommonData& c, const FGColumnVector3& omega); private: /** Copying by assigning the vector valued components. */ - FGQuaternion(double q1, double q2, double q3, double q4) : mCacheValid(false) + FGQuaternion(CommonData& c, double q1, double q2, double q3, double q4) : FGJSBBase(c), mCacheValid(false) { data[0] = q1; data[1] = q2; data[2] = q3; data[3] = q4; } /** Computation of derived values. @@ -537,7 +541,7 @@ class JSBSIM_API FGQuaternion : public FGJSBBase { Multiply the Vector with a scalar value. */ inline FGQuaternion operator*(double scalar, const FGQuaternion& q) { - return FGQuaternion(scalar*q.data[0], scalar*q.data[1], scalar*q.data[2], scalar*q.data[3]); + return FGQuaternion(const_cast(q.gdata()), scalar*q.data[0], scalar*q.data[1], scalar*q.data[2], scalar*q.data[3]); } /** Quaternion exponential @@ -545,8 +549,8 @@ inline FGQuaternion operator*(double scalar, const FGQuaternion& q) { Calculate the unit quaternion which is the result of the exponentiation of the vector 'omega'. */ -inline FGQuaternion QExp(const FGColumnVector3& omega) { - FGQuaternion qexp; +inline FGQuaternion QExp(CommonData& c, const FGColumnVector3& omega) { + FGQuaternion qexp(c); double angle = omega.Magnitude(); double sina_a = angle > 0.0 ? sin(angle)/angle : 1.0; diff --git a/src/math/FGTable.cpp b/src/math/FGTable.cpp index 10e7163d4a..ee45ae70df 100644 --- a/src/math/FGTable.cpp +++ b/src/math/FGTable.cpp @@ -50,8 +50,8 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGTable::FGTable(int NRows) - : nRows(NRows), nCols(1), PropertyManager(nullptr) +FGTable::FGTable(CommonData& c, int NRows) + : FGJSBBase(c), nRows(NRows), nCols(1), PropertyManager(nullptr) { Type = tt1D; // Fill unused elements with NaNs to detect illegal access. @@ -62,8 +62,8 @@ FGTable::FGTable(int NRows) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGTable::FGTable(int NRows, int NCols) - : nRows(NRows), nCols(NCols), PropertyManager(nullptr) +FGTable::FGTable(CommonData& c, int NRows, int NCols) + : FGJSBBase(c), nRows(NRows), nCols(NCols), PropertyManager(nullptr) { Type = tt2D; // Fill unused elements with NaNs to detect illegal access. @@ -73,8 +73,8 @@ FGTable::FGTable(int NRows, int NCols) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGTable::FGTable(const FGTable& t) - : PropertyManager(t.PropertyManager) +FGTable::FGTable(CommonData& c, const FGTable& t) + : FGJSBBase(c), PropertyManager(t.PropertyManager) { Type = t.Type; nRows = t.nRows; @@ -88,7 +88,7 @@ FGTable::FGTable(const FGTable& t) // Deep copy of t.Tables Tables.reserve(t.Tables.size()); for(const auto &t: t.Tables) - Tables.push_back(std::unique_ptr(new FGTable(*t))); + Tables.push_back(std::unique_ptr(new FGTable(c, *t))); Data = t.Data; } @@ -109,9 +109,9 @@ unsigned int FindNumColumns(const string& test_line) //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -FGTable::FGTable(FGPropertyManager* propMan, Element* el, +FGTable::FGTable(CommonData& c, FGPropertyManager* propMan, Element* el, const std::string& Prefix) - : PropertyManager(propMan) + : FGJSBBase(c), PropertyManager(propMan) { string brkpt_string; Element *tableData = nullptr; @@ -142,10 +142,10 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el, // at the same time that independentVars are specified. if (internal) { cerr << el->ReadFrom() - << fgred << " This table specifies both 'internal' call type" << endl + << gdata().fgred << " This table specifies both 'internal' call type" << endl << " and specific lookup properties via the 'independentVar' element." << endl << " These are mutually exclusive specifications. The 'internal'" << endl - << " attribute will be ignored." << fgdef << endl << endl; + << " attribute will be ignored." << gdata().fgdef << endl << endl; internal = false; } @@ -326,7 +326,7 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el, tableData = el->FindElement("tableData"); while (tableData) { - Tables.push_back(std::unique_ptr(new FGTable(PropertyManager, tableData))); + Tables.push_back(std::unique_ptr(new FGTable(gdata(), PropertyManager, tableData))); Data.push_back(tableData->GetAttributeValueAsNumber("breakPoint")); Tables.back()->lookupProperty[eRow] = lookupProperty[eRow]; Tables.back()->lookupProperty[eColumn] = lookupProperty[eColumn]; @@ -354,11 +354,11 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el, for (unsigned int b=2; b<=Tables.size(); ++b) { if (Data[b] <= Data[b-1]) { std::cerr << el->ReadFrom() - << fgred << highint + << gdata().fgred << gdata().highint << " FGTable: breakpoint lookup is not monotonically increasing" << endl << " in breakpoint " << b; if (nameel != 0) std::cerr << " of table in " << nameel->GetAttributeValue("name"); - std::cerr << ":" << reset << endl + std::cerr << ":" << gdata().reset << endl << " " << Data[b] << "<=" << Data[b-1] << endl; throw BaseException("Breakpoint lookup is not monotonically increasing"); } @@ -370,11 +370,11 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el, for (unsigned int c=2; c<=nCols; ++c) { if (Data[c] <= Data[c-1]) { std::cerr << el->ReadFrom() - << fgred << highint + << gdata().fgred << gdata().highint << " FGTable: column lookup is not monotonically increasing" << endl << " in column " << c; if (nameel != 0) std::cerr << " of table in " << nameel->GetAttributeValue("name"); - std::cerr << ":" << reset << endl + std::cerr << ":" << gdata().reset << endl << " " << Data[c] << "<=" << Data[c-1] << endl; throw BaseException("FGTable: column lookup is not monotonically increasing"); } @@ -386,11 +386,11 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el, for (size_t r=2; r<=nRows; ++r) { if (Data[r*(nCols+1)]<=Data[(r-1)*(nCols+1)]) { std::cerr << el->ReadFrom() - << fgred << highint + << gdata().fgred << gdata().highint << " FGTable: row lookup is not monotonically increasing" << endl << " in row " << r; if (nameel != 0) std::cerr << " of table in " << nameel->GetAttributeValue("name"); - std::cerr << ":" << reset << endl + std::cerr << ":" << gdata().reset << endl << " " << Data[r*(nCols+1)] << "<=" << Data[(r-1)*(nCols+1)] << endl; throw BaseException("FGTable: row lookup is not monotonically increasing"); } @@ -415,7 +415,7 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el, bind(el, Prefix); - if (debug_lvl & 1) Print(); + if (gdata().debug_lvl & 1) Print(); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -423,10 +423,10 @@ FGTable::FGTable(FGPropertyManager* propMan, Element* el, void FGTable::missingData(Element *el, unsigned int expected_size, size_t actual_size) { std::cerr << el->ReadFrom() - << fgred << highint + << gdata().fgred << gdata().highint << " FGTable: Missing data"; if (!Name.empty()) std::cerr << " in table " << Name; - std::cerr << ":" << reset << endl + std::cerr << ":" << gdata().reset << endl << " Expecting " << expected_size << " elements while " << actual_size << " elements were provided." << endl; throw BaseException("FGTable: missing data"); @@ -718,6 +718,7 @@ void FGTable::bind(Element* el, const string& Prefix) void FGTable::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/math/FGTable.h b/src/math/FGTable.h index 2ac7aeeaa7..2798c5d84d 100644 --- a/src/math/FGTable.h +++ b/src/math/FGTable.h @@ -240,7 +240,7 @@ class JSBSIM_API FGTable : public FGParameter, public FGJSBBase /** This is the very important copy constructor. @param table a const reference to a table.*/ - FGTable(const FGTable& table); + FGTable(CommonData& c, const FGTable& table); /// Copy assignment constructor. /* MSVC issues an error C2280 if not defined : it is needed by std::unique_ptr. @@ -248,9 +248,9 @@ class JSBSIM_API FGTable : public FGParameter, public FGJSBBase FGTable& operator=(const FGTable&); /// The constructor for a table - FGTable (FGPropertyManager* propMan, Element* el, const std::string& prefix=""); - FGTable (int ); - FGTable (int, int); + FGTable (CommonData& c, FGPropertyManager* propMan, Element* el, const std::string& prefix=""); + FGTable (CommonData& c, int ); + FGTable (CommonData& c, int, int); double GetValue(void) const; double GetValue(double key) const; double GetValue(double rowKey, double colKey) const; diff --git a/src/math/FGTemplateFunc.cpp b/src/math/FGTemplateFunc.cpp index 07f95ba24c..1df1885e8a 100644 --- a/src/math/FGTemplateFunc.cpp +++ b/src/math/FGTemplateFunc.cpp @@ -48,7 +48,7 @@ namespace JSBSim { %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGTemplateFunc::FGTemplateFunc(FGFDMExec* fdmex, Element* element) - : FGFunction(fdmex->GetPropertyManager()) + : FGFunction(fdmex->gdata(), fdmex->GetPropertyManager()) { var = new FGPropertyValue(nullptr); Load(element, var, fdmex); diff --git a/src/models/FGAccelerations.cpp b/src/models/FGAccelerations.cpp index b0a50bcb64..c96aa5d436 100644 --- a/src/models/FGAccelerations.cpp +++ b/src/models/FGAccelerations.cpp @@ -403,6 +403,7 @@ void FGAccelerations::bind(void) void FGAccelerations::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGAerodynamics.cpp b/src/models/FGAerodynamics.cpp index c98236a651..af0ecec84a 100644 --- a/src/models/FGAerodynamics.cpp +++ b/src/models/FGAerodynamics.cpp @@ -38,6 +38,7 @@ INCLUDES #include "FGAerodynamics.h" #include "input_output/FGXMLElement.h" +#include "FGFDMExec.h" using namespace std; @@ -382,8 +383,8 @@ bool FGAerodynamics::Load(Element *document) ca.push_back( new FGFunction(FDMExec, function_element) ); } catch (const string& str) { cerr << endl << axis_element->ReadFrom() - << endl << fgred << "Error loading aerodynamic function in " - << current_func_name << ":" << str << " Aborting." << reset << endl; + << endl << gdata().fgred << "Error loading aerodynamic function in " + << current_func_name << ":" << str << " Aborting." << gdata().reset << endl; return false; } } else { @@ -391,8 +392,8 @@ bool FGAerodynamics::Load(Element *document) ca_atCG.push_back( new FGFunction(FDMExec, function_element) ); } catch (const string& str) { cerr << endl << axis_element->ReadFrom() - << endl << fgred << "Error loading aerodynamic function in " - << current_func_name << ":" << str << " Aborting." << reset << endl; + << endl << gdata().fgred << "Error loading aerodynamic function in " + << current_func_name << ":" << str << " Aborting." << gdata().reset << endl; return false; } } @@ -692,6 +693,7 @@ void FGAerodynamics::BuildStabilityTransformMatrices(void) void FGAerodynamics::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGAircraft.cpp b/src/models/FGAircraft.cpp index cdd0703d4d..04b15cd313 100644 --- a/src/models/FGAircraft.cpp +++ b/src/models/FGAircraft.cpp @@ -40,6 +40,7 @@ INCLUDES #include "FGAircraft.h" #include "input_output/FGXMLElement.h" +#include "FGFDMExec.h" using namespace std; @@ -218,6 +219,7 @@ void FGAircraft::bind(void) void FGAircraft::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGAtmosphere.cpp b/src/models/FGAtmosphere.cpp index 219f9b68b5..8b93234fed 100644 --- a/src/models/FGAtmosphere.cpp +++ b/src/models/FGAtmosphere.cpp @@ -306,6 +306,7 @@ void FGAtmosphere::bind(void) void FGAtmosphere::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGAuxiliary.cpp b/src/models/FGAuxiliary.cpp index 67c5b905fd..5ee320db64 100644 --- a/src/models/FGAuxiliary.cpp +++ b/src/models/FGAuxiliary.cpp @@ -57,7 +57,8 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex) +FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) + : FGModel(fdmex), in(fdmex->gdata()), vLocationVRP(fdmex->gdata()) { Name = "FGAuxiliary"; pt = 2116.23; // ISA SL pressure @@ -395,6 +396,7 @@ double FGAuxiliary::BadUnits(void) const void FGAuxiliary::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGAuxiliary.h b/src/models/FGAuxiliary.h index f1e3fa1b34..4536003b9b 100644 --- a/src/models/FGAuxiliary.h +++ b/src/models/FGAuxiliary.h @@ -252,6 +252,7 @@ class JSBSIM_API FGAuxiliary : public FGModel { void SetAeroPQR(const FGColumnVector3& tt) { vAeroPQR = tt; } struct Inputs { + Inputs(CommonData& c) : vLocation(c) {} double Pressure; double Density; double DensitySL; diff --git a/src/models/FGBuoyantForces.cpp b/src/models/FGBuoyantForces.cpp index ec1dfe729f..c80b7e8a31 100644 --- a/src/models/FGBuoyantForces.cpp +++ b/src/models/FGBuoyantForces.cpp @@ -277,6 +277,7 @@ void FGBuoyantForces::bind(void) void FGBuoyantForces::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGExternalForce.cpp b/src/models/FGExternalForce.cpp index 81221b54d4..0173f3e499 100644 --- a/src/models/FGExternalForce.cpp +++ b/src/models/FGExternalForce.cpp @@ -223,6 +223,7 @@ const FGColumnVector3& FGExternalForce::GetBodyForces(void) void FGExternalForce::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGExternalReactions.cpp b/src/models/FGExternalReactions.cpp index 4e28c31c58..5ee8af919b 100644 --- a/src/models/FGExternalReactions.cpp +++ b/src/models/FGExternalReactions.cpp @@ -39,6 +39,7 @@ INCLUDES #include "FGExternalForce.h" #include "FGExternalReactions.h" #include "input_output/FGXMLElement.h" +#include "FGFDMExec.h" using namespace std; @@ -167,6 +168,7 @@ void FGExternalReactions::bind(void) void FGExternalReactions::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGFCS.cpp b/src/models/FGFCS.cpp index 9409af82c2..4be9ab8069 100644 --- a/src/models/FGFCS.cpp +++ b/src/models/FGFCS.cpp @@ -166,7 +166,7 @@ bool FGFCS::Run(bool Holding) // Execute system channels in order for (i=0; iGetName() << endl; + if (gdata().debug_lvl & 4) cout << " Executing System Channel: " << SystemChannels[i]->GetName() << endl; ChannelRate = SystemChannels[i]->GetRate(); SystemChannels[i]->Execute(); } @@ -506,10 +506,10 @@ bool FGFCS::Load(Element* document) if (sOnOffProperty.length() > 0) { FGPropertyNode* OnOffPropertyNode = PropertyManager->GetNode(sOnOffProperty); if (OnOffPropertyNode == 0) { - cerr << channel_element->ReadFrom() << highint << fgred + cerr << channel_element->ReadFrom() << gdata().highint << gdata().fgred << "The On/Off property, " << sOnOffProperty << " specified for channel " << channel_element->GetAttributeValue("name") << " is undefined or not " - << "understood. The simulation will abort" << reset << endl; + << "understood. The simulation will abort" << gdata().reset << endl; throw("Bad system definition"); } else newChannel = new FGFCSChannel(this, sChannelName, ChannelRate, @@ -519,9 +519,9 @@ bool FGFCS::Load(Element* document) SystemChannels.push_back(newChannel); - if (debug_lvl > 0) - cout << endl << highint << fgblue << " Channel " - << normint << channel_element->GetAttributeValue("name") << reset << endl; + if (gdata().debug_lvl > 0) + cout << endl << gdata().highint << gdata().fgblue << " Channel " + << gdata().normint << channel_element->GetAttributeValue("name") << gdata().reset << endl; Element* component_element = channel_element->GetElement(); while (component_element) { @@ -585,8 +585,8 @@ bool FGFCS::Load(Element* document) cerr << "Unknown FCS component: " << component_element->GetName() << endl; } } catch(string& s) { - cerr << highint << fgred << endl << " " << s << endl; - cerr << reset << endl; + cerr << gdata().highint << gdata().fgred << endl << " " << s << endl; + cerr << gdata().reset << endl; return false; } component_element = channel_element->GetNextElement(); @@ -804,6 +804,7 @@ void FGFCS::bindThrottle(unsigned int num) void FGFCS::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGGasCell.cpp b/src/models/FGGasCell.cpp index ad16e1d038..2a1fea0b29 100644 --- a/src/models/FGGasCell.cpp +++ b/src/models/FGGasCell.cpp @@ -444,6 +444,7 @@ void FGGasCell::Calculate(double dt) void FGGasCell::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output @@ -498,7 +499,7 @@ const double FGBallonet::Cv_air = 5.0/2.0; // [??] FGBallonet::FGBallonet(FGFDMExec* exec, Element* el, unsigned int num, FGGasCell* parent, const struct FGGasCell::Inputs& input) - : in(input) + : FGJSBBase(exec->gdata()), in(input) { string token; Element* element; @@ -794,6 +795,7 @@ void FGBallonet::Calculate(double dt) void FGBallonet::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGGroundReactions.cpp b/src/models/FGGroundReactions.cpp index 7b6503411d..23c53e2f9b 100644 --- a/src/models/FGGroundReactions.cpp +++ b/src/models/FGGroundReactions.cpp @@ -52,7 +52,8 @@ CLASS IMPLEMENTATION FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : FGModel(fgex), FGSurface(fgex), - DsCmd(0.0) + DsCmd(0.0), + in(fgex->gdata()) { Name = "FGGroundReactions"; @@ -288,6 +289,7 @@ void FGGroundReactions::bind(void) void FGGroundReactions::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGInertial.cpp b/src/models/FGInertial.cpp index c1c6249866..60cb0ce3b1 100644 --- a/src/models/FGInertial.cpp +++ b/src/models/FGInertial.cpp @@ -37,6 +37,7 @@ INCLUDES #include "FGInertial.h" #include "input_output/FGXMLElement.h" +#include "FGFDMExec.h" using namespace std; @@ -49,6 +50,7 @@ CLASS IMPLEMENTATION FGInertial::FGInertial(FGFDMExec* fgex) : FGModel(fgex) + , in(fgex->gdata()) { Name = "Earth"; @@ -216,7 +218,7 @@ FGColumnVector3 FGInertial::GetGravityJ2(const FGLocation& position) const void FGInertial::SetAltitudeAGL(FGLocation& location, double altitudeAGL) { FGColumnVector3 vDummy; - FGLocation contact; + FGLocation contact(location.gdata()); contact.SetEllipse(a, b); GroundCallback->GetAGLevel(location, contact, vDummy, vDummy, vDummy); double groundHeight = contact.GetGeodAltitude(); @@ -276,6 +278,7 @@ void FGInertial::bind(void) void FGInertial::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGInertial.h b/src/models/FGInertial.h index c8ab6ff4cc..c6592b7707 100644 --- a/src/models/FGInertial.h +++ b/src/models/FGInertial.h @@ -112,7 +112,7 @@ class JSBSIM_API FGInertial : public FGModel { @param location Location at which the AGL is evaluated. @see SetGroundCallback */ double GetAltitudeAGL(const FGLocation& location) const { - FGLocation lDummy; + FGLocation lDummy(const_cast(location.gdata())); FGColumnVector3 vDummy; return GroundCallback->GetAGLevel(location, lDummy, vDummy, vDummy, vDummy); @@ -195,6 +195,7 @@ class JSBSIM_API FGInertial : public FGModel { { return GetTl2ec(location).Transposed(); } struct Inputs { + Inputs(CommonData& c) : Position(c) {} FGLocation Position; } in; diff --git a/src/models/FGInput.cpp b/src/models/FGInput.cpp index 1fe66c76e0..c030fee740 100644 --- a/src/models/FGInput.cpp +++ b/src/models/FGInput.cpp @@ -91,7 +91,7 @@ bool FGInput::Load(Element* el) string type = element->GetAttributeValue("type"); FGInputType* Input = 0; - if (debug_lvl > 0) cout << endl << " Input data set: " << idx << " " << endl; + if (gdata().debug_lvl > 0) cout << endl << " Input data set: " << idx << " " << endl; type = to_upper(type); @@ -220,6 +220,7 @@ void FGInput::Debug(int from) { string scratch=""; + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGLGear.cpp b/src/models/FGLGear.cpp index 049b246a67..0bbb2a6e61 100644 --- a/src/models/FGLGear.cpp +++ b/src/models/FGLGear.cpp @@ -170,7 +170,7 @@ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number, const struct Inputs& while (force_table) { string force_type = force_table->GetAttributeValue("name"); if (force_type == "CORNERING_COEFF") { - ForceY_Table = new FGTable(PropertyManager, force_table); + ForceY_Table = new FGTable(gdata(), PropertyManager, force_table); break; } else { cerr << "Undefined force table for " << name << " contact point" << endl; @@ -190,7 +190,7 @@ FGLGear::FGLGear(Element* el, FGFDMExec* fdmex, int number, const struct Inputs& element = el->FindElement("orientation"); if (element && (eContactType == ctBOGEY)) { - FGQuaternion quatFromEuler(element->FindElementTripletConvertTo("RAD")); + FGQuaternion quatFromEuler(gdata(), element->FindElementTripletConvertTo("RAD")); mTGear = quatFromEuler.GetT(); } @@ -286,7 +286,7 @@ const FGColumnVector3& FGLGear::GetBodyForces(FGSurface *surface) if (gearPos > 0.99) { // Gear DOWN FGColumnVector3 normal, terrainVel, dummy; - FGLocation gearLoc, contact; + FGLocation gearLoc(gdata()), contact(gdata()); FGColumnVector3 vWhlBodyVec = Ts2b * (vXYZn - in.vXYZcg); vLocalGear = in.Tb2l * vWhlBodyVec; // Get local frame wheel location @@ -524,6 +524,7 @@ void FGLGear::ReportTakeoffOrLanding(void) if (WOW) TakeoffDistanceTraveled += in.Vground * in.TotalDeltaT; } + auto debug_lvl = gdata().debug_lvl; if ( ReportEnable && in.Vground <= 0.05 && !LandingReported @@ -906,6 +907,7 @@ void FGLGear::Debug(int from) static const char* sBrakeGroup[] = {"NONE", "LEFT", "RIGHT", "CENTER", "NOSE", "TAIL"}; static const char* sContactType[] = {"BOGEY", "STRUCTURE" }; + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGLGear.h b/src/models/FGLGear.h index daf939cee2..eeb41be046 100644 --- a/src/models/FGLGear.h +++ b/src/models/FGLGear.h @@ -191,6 +191,7 @@ class JSBSIM_API FGLGear : protected FGSurface, public FGForce { public: struct Inputs { + Inputs(CommonData& c) : Location(c) {} double Vground; double VcalibratedKts; double Temperature; diff --git a/src/models/FGMassBalance.cpp b/src/models/FGMassBalance.cpp index b65a8e85b7..ad6166e763 100644 --- a/src/models/FGMassBalance.cpp +++ b/src/models/FGMassBalance.cpp @@ -451,14 +451,14 @@ void FGMassBalance::PointMass::bind(FGPropertyManager* PropertyManager, void FGMassBalance::GetMassPropertiesReport(int i) { - cout << endl << fgblue << highint + cout << endl << gdata().fgblue << gdata().highint << " Mass Properties Report (English units: lbf, in, slug-ft^2)" - << reset << endl; - cout << " " << underon << " Weight CG-X CG-Y" + << gdata().reset << endl; + cout << " " << gdata().underon << " Weight CG-X CG-Y" << " CG-Z Ixx Iyy Izz" - << " Ixy Ixz Iyz" << underoff << endl; + << " Ixy Ixz Iyz" << gdata().underoff << endl; cout.precision(1); - cout << highint << setw(34) << left << " Base Vehicle " << normint + cout << gdata().highint << setw(34) << left << " Base Vehicle " << gdata().normint << right << setw(10) << EmptyWeight << setw(8) << vbaseXYZcg(eX) << setw(8) << vbaseXYZcg(eY) << setw(8) << vbaseXYZcg(eZ) << setw(12) << baseJ(1,1) << setw(12) << baseJ(2,2) << setw(12) << baseJ(3,3) @@ -467,7 +467,7 @@ void FGMassBalance::GetMassPropertiesReport(int i) for (unsigned int i=0;iGetPointMassWeight(); - cout << highint << left << setw(4) << i << setw(30) << pm->GetName() << normint + cout << gdata().highint << left << setw(4) << i << setw(30) << pm->GetName() << gdata().normint << right << setw(10) << pmweight << setw(8) << pm->GetLocation()(eX) << setw(8) << pm->GetLocation()(eY) << setw(8) << pm->GetLocation()(eZ) << setw(12) << pm->GetPointMassMoI(1,1) << setw(12) << pm->GetPointMassMoI(2,2) << setw(12) << pm->GetPointMassMoI(3,3) @@ -476,8 +476,8 @@ void FGMassBalance::GetMassPropertiesReport(int i) cout << FDMExec->GetPropulsionTankReport(); - cout << " " << underon << setw(136) << " " << underoff << endl; - cout << highint << left << setw(30) << " Total: " << right << setw(14) << Weight + cout << " " << gdata().underon << setw(136) << " " << gdata().underoff << endl; + cout << gdata().highint << left << setw(30) << " Total: " << right << setw(14) << Weight << setw(8) << vXYZcg(eX) << setw(8) << vXYZcg(eY) << setw(8) << vXYZcg(eZ) @@ -487,7 +487,7 @@ void FGMassBalance::GetMassPropertiesReport(int i) << setw(12) << mJ(1,2) << setw(12) << mJ(1,3) << setw(12) << mJ(2,3) - << normint << endl; + << gdata().normint << endl; cout.setf(ios_base::fixed); } @@ -513,6 +513,7 @@ void FGMassBalance::GetMassPropertiesReport(int i) void FGMassBalance::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGModel.cpp b/src/models/FGModel.cpp index 5759d72513..c32a57ebe3 100644 --- a/src/models/FGModel.cpp +++ b/src/models/FGModel.cpp @@ -54,7 +54,7 @@ GLOBAL DECLARATIONS CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGModel::FGModel(FGFDMExec* fdmex) +FGModel::FGModel(FGFDMExec* fdmex) : FGModelFunctions(fdmex->gdata()) { FDMExec = fdmex; @@ -66,14 +66,14 @@ FGModel::FGModel(FGFDMExec* fdmex) exe_ctr = 1; rate = 1; - if (debug_lvl & 2) cout << " FGModel Base Class" << endl; + if (gdata().debug_lvl & 2) cout << " FGModel Base Class" << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGModel::~FGModel() { - if (debug_lvl & 2) cout << "Destroyed: FGModel" << endl; + if (gdata().debug_lvl & 2) cout << "Destroyed: FGModel" << endl; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -88,7 +88,7 @@ bool FGModel::InitModel(void) bool FGModel::Run(bool Holding) { - if (debug_lvl & 4) cout << "Entering Run() for model " << Name << endl; + if (gdata().debug_lvl & 4) cout << "Entering Run() for model " << Name << endl; if (rate == 1) return false; // Fast exit if nothing to do @@ -169,6 +169,7 @@ bool FGModel::Upload(Element* el, bool preLoad) void FGModel::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGOutput.cpp b/src/models/FGOutput.cpp index f98abb5a68..71296b7bb3 100644 --- a/src/models/FGOutput.cpp +++ b/src/models/FGOutput.cpp @@ -195,7 +195,7 @@ bool FGOutput::Load(int subSystems, std::string protocol, std::string type, size_t idx = OutputTypes.size(); FGOutputType* Output = 0; - if (debug_lvl > 0) cout << endl << " Output data set: " << idx << endl; + if (gdata().debug_lvl > 0) cout << endl << " Output data set: " << idx << endl; type = to_upper(type); @@ -248,7 +248,7 @@ bool FGOutput::Load(Element* document, const SGPath& dir) string type = document->GetAttributeValue("type"); FGOutputType* Output = 0; - if (debug_lvl > 0) cout << endl << " Output data set: " << idx << " " << endl; + if (gdata().debug_lvl > 0) cout << endl << " Output data set: " << idx << " " << endl; type = to_upper(type); @@ -313,6 +313,7 @@ SGPath FGOutput::FindFullPathName(const SGPath& path) const void FGOutput::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/FGPropagate.cpp b/src/models/FGPropagate.cpp index 5dc0f127b9..b4032b0fc2 100644 --- a/src/models/FGPropagate.cpp +++ b/src/models/FGPropagate.cpp @@ -81,6 +81,8 @@ CLASS IMPLEMENTATION FGPropagate::FGPropagate(FGFDMExec* fdmex) : FGModel(fdmex) + , VState(fdmex->gdata()) + , Qec2b(fdmex->gdata()) { Debug(0); Name = "FGPropagate"; @@ -98,7 +100,7 @@ FGPropagate::FGPropagate(FGFDMExec* fdmex) VState.dqPQRidot.resize(5, FGColumnVector3(0.0,0.0,0.0)); VState.dqUVWidot.resize(5, FGColumnVector3(0.0,0.0,0.0)); VState.dqInertialVelocity.resize(5, FGColumnVector3(0.0,0.0,0.0)); - VState.dqQtrndot.resize(5, FGQuaternion(0.0,0.0,0.0)); + VState.dqQtrndot.resize(5, FGQuaternion(gdata(), 0.0, 0.0, 0.0)); epa = 0.0; @@ -126,7 +128,7 @@ bool FGPropagate::InitModel(void) VState.dqPQRidot.resize(5, FGColumnVector3(0.0,0.0,0.0)); VState.dqUVWidot.resize(5, FGColumnVector3(0.0,0.0,0.0)); VState.dqInertialVelocity.resize(5, FGColumnVector3(0.0,0.0,0.0)); - VState.dqQtrndot.resize(5, FGColumnVector3(0.0,0.0,0.0)); + VState.dqQtrndot.resize(5, FGQuaternion(gdata(), FGColumnVector3(0.0, 0.0, 0.0))); integrator_rotational_rate = eRectEuler; integrator_translational_rate = eAdamsBashforth2; @@ -162,7 +164,7 @@ void FGPropagate::SetInitialState(const FGInitialCondition *FGIC) // frame relative to the local frame. VState.qAttitudeLocal = FGIC->GetOrientation(); - VState.qAttitudeECI = Ti2l.GetQuaternion()*VState.qAttitudeLocal; + VState.qAttitudeECI = Ti2l.GetQuaternion(gdata()) * VState.qAttitudeLocal; UpdateBodyMatrices(); // Set the velocities in the instantaneus body frame @@ -269,7 +271,7 @@ bool FGPropagate::Run(bool Holding) // Angular orientation derivative CalculateQuatdot(); - VState.qAttitudeLocal = Tl2b.GetQuaternion(); + VState.qAttitudeLocal = Tl2b.GetQuaternion(gdata()); // Compute vehicle velocity wrt ECEF frame, expressed in Local horizontal // frame. @@ -393,7 +395,7 @@ void FGPropagate::Integrate( FGQuaternion& Integrand, // The formula from Buss' paper is transposed below to quaternions and is // actually the exact solution of the quaternion differential equation // qdot = 1/2*w*q when w is constant. - Integrand = Integrand * QExp(0.5 * dt * VState.vPQRi); + Integrand = Integrand * QExp(gdata(), 0.5 * dt * VState.vPQRi); } return; // No need to normalize since the quaternion exponential is always normal case eBuss2: @@ -404,7 +406,7 @@ void FGPropagate::Integrate( FGQuaternion& Integrand, FGColumnVector3 wi = VState.vPQRi; FGColumnVector3 wdoti = in.vPQRidot; FGColumnVector3 omega = wi + 0.5*dt*wdoti + dt*dt/12.*wdoti*wi; - Integrand = Integrand * QExp(0.5 * dt * omega); + Integrand = Integrand * QExp(gdata(), 0.5 * dt * omega); } return; // No need to normalize since the quaternion exponential is always normal case eLocalLinearization: @@ -423,7 +425,7 @@ void FGPropagate::Integrate( FGQuaternion& Integrand, double C3 = 4.0 * (1.0 - C1) / (omegak*omegak); double C4 = 4.0 * (dt - C2) / (omegak*omegak); FGColumnVector3 Omega = C2*wi + C3*wdoti + C4*wi*wdoti; - FGQuaternion q; + FGQuaternion q(gdata()); q(1) = C1 - C4*DotProduct(wi, wdoti); q(2) = Omega(eP); @@ -488,7 +490,7 @@ void FGPropagate::UpdateBodyMatrices(void) Tec2b = Ti2b * Tec2i; // ECEF to body frame transform Tb2ec = Tec2b.Transposed(); // body to ECEF frame tranform - Qec2b = Tec2b.GetQuaternion(); + Qec2b = Tec2b.GetQuaternion(gdata()); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -498,7 +500,7 @@ void FGPropagate::SetInertialOrientation(const FGQuaternion& Qi) VState.qAttitudeECI = Qi; VState.qAttitudeECI.Normalize(); UpdateBodyMatrices(); - VState.qAttitudeLocal = Tl2b.GetQuaternion(); + VState.qAttitudeLocal = Tl2b.GetQuaternion(gdata()); CalculateQuatdot(); } @@ -538,7 +540,7 @@ void FGPropagate::SetAltitudeASL(double altASL) void FGPropagate::RecomputeLocalTerrainVelocity() { - FGLocation contact; + FGLocation contact(gdata()); FGColumnVector3 normal; Inertial->GetContactPoint(VState.vLocation, contact, normal, LocalTerrainVelocity, LocalTerrainAngularVelocity); @@ -549,7 +551,7 @@ void FGPropagate::RecomputeLocalTerrainVelocity() double FGPropagate::GetTerrainElevation(void) const { FGColumnVector3 vDummy; - FGLocation contact; + FGLocation contact(const_cast(gdata())); contact.SetEllipse(in.SemiMajor, in.SemiMinor); Inertial->GetContactPoint(VState.vLocation, contact, vDummy, vDummy, vDummy); return contact.GetGeodAltitude(); @@ -566,7 +568,7 @@ void FGPropagate::SetTerrainElevation(double terrainElev) double FGPropagate::GetLocalTerrainRadius(void) const { - FGLocation contact; + FGLocation contact(const_cast(gdata())); FGColumnVector3 vDummy; Inertial->GetContactPoint(VState.vLocation, contact, vDummy, vDummy, vDummy); return contact.GetRadius(); @@ -627,7 +629,7 @@ void FGPropagate::UpdateVehicleState(void) UpdateLocationMatrices(); UpdateBodyMatrices(); vVel = Tb2l * VState.vUVW; - VState.qAttitudeLocal = Tl2b.GetQuaternion(); + VState.qAttitudeLocal = Tl2b.GetQuaternion(gdata()); } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -650,32 +652,32 @@ FGColumnVector3 FGPropagate::GetEulerDeg(void) const void FGPropagate::DumpState(void) { cout << endl; - cout << fgblue - << "------------------------------------------------------------------" << reset << endl; - cout << highint - << "State Report at sim time: " << FDMExec->GetSimTime() << " seconds" << reset << endl; - cout << " " << underon - << "Position" << underoff << endl; + cout << gdata().fgblue + << "------------------------------------------------------------------" << gdata().reset << endl; + cout << gdata().highint + << "State Report at sim time: " << FDMExec->GetSimTime() << " seconds" << gdata().reset << endl; + cout << " " << gdata().underon + << "Position" << gdata().underoff << endl; cout << " ECI: " << VState.vInertialPosition.Dump(", ") << " (x,y,z, in ft)" << endl; cout << " ECEF: " << VState.vLocation << " (x,y,z, in ft)" << endl; cout << " Local: " << VState.vLocation.GetGeodLatitudeDeg() << ", " << VState.vLocation.GetLongitudeDeg() << ", " << GetAltitudeASL() << " (geodetic lat, lon, alt ASL in deg and ft)" << endl; - cout << endl << " " << underon - << "Orientation" << underoff << endl; + cout << endl << " " << gdata().underon + << "Orientation" << gdata().underoff << endl; cout << " ECI: " << VState.qAttitudeECI.GetEulerDeg().Dump(", ") << " (phi, theta, psi in deg)" << endl; cout << " Local: " << VState.qAttitudeLocal.GetEulerDeg().Dump(", ") << " (phi, theta, psi in deg)" << endl; - cout << endl << " " << underon - << "Velocity" << underoff << endl; + cout << endl << " " << gdata().underon + << "Velocity" << gdata().underoff << endl; cout << " ECI: " << VState.vInertialVelocity.Dump(", ") << " (x,y,z in ft/s)" << endl; cout << " ECEF: " << (Tb2ec * VState.vUVW).Dump(", ") << " (x,y,z in ft/s)" << endl; cout << " Local: " << GetVel() << " (n,e,d in ft/sec)" << endl; cout << " Body: " << GetUVW() << " (u,v,w in ft/sec)" << endl; - cout << endl << " " << underon - << "Body Rates (relative to given frame, expressed in body frame)" << underoff << endl; + cout << endl << " " << gdata().underon + << "Body Rates (relative to given frame, expressed in body frame)" << gdata().underoff << endl; cout << " ECI: " << (VState.vPQRi*radtodeg).Dump(", ") << " (p,q,r in deg/s)" << endl; cout << " ECEF: " << (VState.vPQR*radtodeg).Dump(", ") << " (p,q,r in deg/s)" << endl; } @@ -861,6 +863,7 @@ void FGPropagate::bind(void) void FGPropagate::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output @@ -875,92 +878,92 @@ void FGPropagate::Debug(int from) if (debug_lvl & 4 ) { // Run() method entry print for FGModel-derived objects } if (debug_lvl & 8 && from == 2) { // Runtime state variables - cout << endl << fgblue << highint << left + cout << endl << gdata().fgblue << gdata().highint << left << " Propagation Report (English units: ft, degrees) at simulation time " << FDMExec->GetSimTime() << " seconds" - << reset << endl; + << gdata().reset << endl; cout << endl; - cout << highint << " Earth Position Angle (deg): " << setw(8) << setprecision(3) << reset + cout << gdata().highint << " Earth Position Angle (deg): " << setw(8) << setprecision(3) << gdata().reset << GetEarthPositionAngleDeg() << endl; cout << endl; - cout << highint << " Body velocity (ft/sec): " << setw(8) << setprecision(3) << reset << VState.vUVW << endl; - cout << highint << " Local velocity (ft/sec): " << setw(8) << setprecision(3) << reset << vVel << endl; - cout << highint << " Inertial velocity (ft/sec): " << setw(8) << setprecision(3) << reset << VState.vInertialVelocity << endl; - cout << highint << " Inertial Position (ft): " << setw(10) << setprecision(3) << reset << VState.vInertialPosition << endl; - cout << highint << " Latitude (deg): " << setw(8) << setprecision(3) << reset << VState.vLocation.GetLatitudeDeg() << endl; - cout << highint << " Longitude (deg): " << setw(8) << setprecision(3) << reset << VState.vLocation.GetLongitudeDeg() << endl; - cout << highint << " Altitude ASL (ft): " << setw(8) << setprecision(3) << reset << GetAltitudeASL() << endl; -// cout << highint << " Acceleration (NED, ft/sec^2): " << setw(8) << setprecision(3) << reset << Tb2l*GetUVWdot() << endl; + cout << gdata().highint << " Body velocity (ft/sec): " << setw(8) << setprecision(3) << gdata().reset << VState.vUVW << endl; + cout << gdata().highint << " Local velocity (ft/sec): " << setw(8) << setprecision(3) << gdata().reset << vVel << endl; + cout << gdata().highint << " Inertial velocity (ft/sec): " << setw(8) << setprecision(3) << gdata().reset << VState.vInertialVelocity << endl; + cout << gdata().highint << " Inertial Position (ft): " << setw(10) << setprecision(3) << gdata().reset << VState.vInertialPosition << endl; + cout << gdata().highint << " Latitude (deg): " << setw(8) << setprecision(3) << gdata().reset << VState.vLocation.GetLatitudeDeg() << endl; + cout << gdata().highint << " Longitude (deg): " << setw(8) << setprecision(3) << gdata().reset << VState.vLocation.GetLongitudeDeg() << endl; + cout << gdata().highint << " Altitude ASL (ft): " << setw(8) << setprecision(3) << gdata().reset << GetAltitudeASL() << endl; +// cout << gdata().highint << " Acceleration (NED, ft/sec^2): " << setw(8) << setprecision(3) << gdata().reset << Tb2l*GetUVWdot() << endl; cout << endl; - cout << highint << " Matrix ECEF to Body (Orientation of Body with respect to ECEF): " - << reset << endl << Tec2b.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tec2b.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix ECEF to Body (Orientation of Body with respect to ECEF): " + << gdata().reset << endl << Tec2b.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tec2b.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Body to ECEF (Orientation of ECEF with respect to Body):" - << reset << endl << Tb2ec.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tb2ec.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Body to ECEF (Orientation of ECEF with respect to Body):" + << gdata().reset << endl << Tb2ec.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tb2ec.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Local to Body (Orientation of Body with respect to Local):" - << reset << endl << Tl2b.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tl2b.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Local to Body (Orientation of Body with respect to Local):" + << gdata().reset << endl << Tl2b.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tl2b.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Body to Local (Orientation of Local with respect to Body):" - << reset << endl << Tb2l.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tb2l.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Body to Local (Orientation of Local with respect to Body):" + << gdata().reset << endl << Tb2l.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tb2l.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Local to ECEF (Orientation of ECEF with respect to Local):" - << reset << endl << Tl2ec.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tl2ec.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Local to ECEF (Orientation of ECEF with respect to Local):" + << gdata().reset << endl << Tl2ec.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tl2ec.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix ECEF to Local (Orientation of Local with respect to ECEF):" - << reset << endl << Tec2l.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tec2l.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix ECEF to Local (Orientation of Local with respect to ECEF):" + << gdata().reset << endl << Tec2l.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tec2l.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix ECEF to Inertial (Orientation of Inertial with respect to ECEF):" - << reset << endl << Tec2i.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tec2i.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix ECEF to Inertial (Orientation of Inertial with respect to ECEF):" + << gdata().reset << endl << Tec2i.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tec2i.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Inertial to ECEF (Orientation of ECEF with respect to Inertial):" - << reset << endl << Ti2ec.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Ti2ec.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Inertial to ECEF (Orientation of ECEF with respect to Inertial):" + << gdata().reset << endl << Ti2ec.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Ti2ec.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Inertial to Body (Orientation of Body with respect to Inertial):" - << reset << endl << Ti2b.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Ti2b.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Inertial to Body (Orientation of Body with respect to Inertial):" + << gdata().reset << endl << Ti2b.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Ti2b.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Body to Inertial (Orientation of Inertial with respect to Body):" - << reset << endl << Tb2i.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tb2i.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Body to Inertial (Orientation of Inertial with respect to Body):" + << gdata().reset << endl << Tb2i.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tb2i.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Inertial to Local (Orientation of Local with respect to Inertial):" - << reset << endl << Ti2l.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Ti2l.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Inertial to Local (Orientation of Local with respect to Inertial):" + << gdata().reset << endl << Ti2l.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Ti2l.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; - cout << highint << " Matrix Local to Inertial (Orientation of Inertial with respect to Local):" - << reset << endl << Tl2i.Dump("\t", " ") << endl; - cout << highint << " Associated Euler angles (deg): " << setw(8) - << setprecision(3) << reset << (Tl2i.GetQuaternion().GetEuler()*radtodeg) + cout << gdata().highint << " Matrix Local to Inertial (Orientation of Inertial with respect to Local):" + << gdata().reset << endl << Tl2i.Dump("\t", " ") << endl; + cout << gdata().highint << " Associated Euler angles (deg): " << setw(8) + << setprecision(3) << gdata().reset << (Tl2i.GetQuaternion(gdata()).GetEuler()*radtodeg) << endl << endl; cout << setprecision(6); // reset the output stream diff --git a/src/models/FGPropagate.h b/src/models/FGPropagate.h index 293b24b656..7ce1106fa9 100644 --- a/src/models/FGPropagate.h +++ b/src/models/FGPropagate.h @@ -96,6 +96,7 @@ class JSBSIM_API FGPropagate : public FGModel { /** The current vehicle state vector structure contains the translational and angular position, and the translational and angular velocity. */ struct VehicleState { + VehicleState(CommonData& c) : vLocation(c), qAttitudeLocal(c), qAttitudeECI(c), vQtrndot(c) {} /** Represents the current location of the vehicle in Earth centered Earth fixed (ECEF) frame. units ft */ @@ -583,18 +584,18 @@ class JSBSIM_API FGPropagate : public FGModel { void SetLocation(const FGLocation& l); void SetLocation(const FGColumnVector3& lv) { - FGLocation l = FGLocation(lv); + FGLocation l = FGLocation(gdata(), lv); SetLocation(l); } void SetPosition(const double Lon, const double Lat, const double Radius) { - FGLocation l = FGLocation(Lon, Lat, Radius); + FGLocation l = FGLocation(gdata(), Lon, Lat, Radius); SetLocation(l); } void NudgeBodyLocation(const FGColumnVector3& deltaLoc) { VState.vInertialPosition -= Tb2i*deltaLoc; - VState.vLocation -= Tb2ec*deltaLoc; + VState.vLocation -= FGLocation(VState.vLocation.gdata(), Tb2ec*deltaLoc); } /** Sets the property forces/hold-down. This allows to do hard 'hold-down' diff --git a/src/models/FGPropulsion.cpp b/src/models/FGPropulsion.cpp index 685498b0a1..f54598d27d 100644 --- a/src/models/FGPropulsion.cpp +++ b/src/models/FGPropulsion.cpp @@ -61,8 +61,6 @@ using namespace std; namespace JSBSim { -extern short debug_lvl; - /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ @@ -426,7 +424,7 @@ bool FGPropulsion::Load(Element* el) return false; } } catch (std::string& str) { - cerr << endl << fgred << str << reset << endl; + cerr << endl << gdata().fgred << str << gdata().reset << endl; return false; } @@ -542,7 +540,7 @@ string FGPropulsion::GetPropulsionTankReport() } else { tankname = "(Unknown tank type)"; } - outstream << highint << left << setw(4) << i << setw(30) << tankname << normint + outstream << gdata().highint << left << setw(4) << i << setw(30) << tankname << gdata().normint << right << setw(10) << tank->GetContents() << setw(8) << tank->GetXYZ(eX) << setw(8) << tank->GetXYZ(eY) << setw(8) << tank->GetXYZ(eZ) << setw(12) << tank->GetIxx() << setw(12) << tank->GetIyy() @@ -852,6 +850,7 @@ void FGPropulsion::bind(void) void FGPropulsion::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/atmosphere/FGMSIS.cpp b/src/models/atmosphere/FGMSIS.cpp index 41be26913d..08810c7227 100644 --- a/src/models/atmosphere/FGMSIS.cpp +++ b/src/models/atmosphere/FGMSIS.cpp @@ -1604,6 +1604,7 @@ void MSIS::gts7(struct nrlmsise_input *input, struct nrlmsise_flags *flags, void MSIS::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/atmosphere/FGMars.cpp b/src/models/atmosphere/FGMars.cpp index 6362f70ce0..aca5a5ea93 100644 --- a/src/models/atmosphere/FGMars.cpp +++ b/src/models/atmosphere/FGMars.cpp @@ -43,6 +43,7 @@ INCLUDES #include "FGMars.h" #include +#include "FGFDMExec.h" using namespace std; @@ -102,6 +103,7 @@ void FGMars::Calculate(double altitude) void FGMars::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/atmosphere/FGStandardAtmosphere.cpp b/src/models/atmosphere/FGStandardAtmosphere.cpp index 1077c52c65..66e8f7ab20 100644 --- a/src/models/atmosphere/FGStandardAtmosphere.cpp +++ b/src/models/atmosphere/FGStandardAtmosphere.cpp @@ -59,8 +59,8 @@ CLASS IMPLEMENTATION FGStandardAtmosphere::FGStandardAtmosphere(FGFDMExec* fdmex) : FGAtmosphere(fdmex), StdSLpressure(StdDaySLpressure), TemperatureBias(0.0), TemperatureDeltaGradient(0.0), VaporMassFraction(0.0), - SaturatedVaporPressure(0.0), StdAtmosTemperatureTable(9), - MaxVaporMassFraction(10) + SaturatedVaporPressure(0.0), StdAtmosTemperatureTable(fdmex->gdata(), 9), + MaxVaporMassFraction(fdmex->gdata(), 10) { Name = "FGStandardAtmosphere"; @@ -718,6 +718,7 @@ void FGStandardAtmosphere::bind(void) void FGStandardAtmosphere::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/atmosphere/FGWinds.cpp b/src/models/atmosphere/FGWinds.cpp index 550281977e..736dddb84f 100644 --- a/src/models/atmosphere/FGWinds.cpp +++ b/src/models/atmosphere/FGWinds.cpp @@ -91,7 +91,7 @@ FGWinds::FGWinds(FGFDMExec* fdmex) : FGModel(fdmex) // Milspec turbulence model windspeed_at_20ft = 0.; probability_of_exceedence_index = 0; - POE_Table = new FGTable(7,12); + POE_Table = new FGTable(gdata(), 7, 12); // this is Figure 7 from p. 49 of MIL-F-8785C // rows: probability of exceedance curve index, cols: altitude in ft *POE_Table @@ -586,6 +586,7 @@ void FGWinds::bind(void) void FGWinds::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGAccelerometer.cpp b/src/models/flight_control/FGAccelerometer.cpp index 6d7962815e..a142b7b335 100644 --- a/src/models/flight_control/FGAccelerometer.cpp +++ b/src/models/flight_control/FGAccelerometer.cpp @@ -52,7 +52,7 @@ CLASS IMPLEMENTATION FGAccelerometer::FGAccelerometer(FGFCS* fcs, Element* element) : FGSensor(fcs, element), - FGSensorOrientation(element) + FGSensorOrientation(fcs->gdata(), element) { Propagate = fcs->GetExec()->GetPropagate(); Accelerations = fcs->GetExec()->GetAccelerations(); @@ -127,6 +127,7 @@ void FGAccelerometer::Debug(int from) { string ax[4] = {"none", "X", "Y", "Z"}; + auto debug_lvl = FGSensorOrientation::gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGActuator.cpp b/src/models/flight_control/FGActuator.cpp index b0cc9d4cfc..ab0b900cf3 100644 --- a/src/models/flight_control/FGActuator.cpp +++ b/src/models/flight_control/FGActuator.cpp @@ -331,6 +331,7 @@ void FGActuator::InitializeLagCoefficients() void FGActuator::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGAngles.cpp b/src/models/flight_control/FGAngles.cpp index 7d9dbc35d1..256b5ef375 100644 --- a/src/models/flight_control/FGAngles.cpp +++ b/src/models/flight_control/FGAngles.cpp @@ -177,6 +177,7 @@ bool FGAngles::Run(void ) void FGAngles::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGDeadBand.cpp b/src/models/flight_control/FGDeadBand.cpp index a09e0b1902..bf94e4668f 100644 --- a/src/models/flight_control/FGDeadBand.cpp +++ b/src/models/flight_control/FGDeadBand.cpp @@ -121,6 +121,7 @@ bool FGDeadBand::Run(void) void FGDeadBand::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGDistributor.cpp b/src/models/flight_control/FGDistributor.cpp index efcfb45e9d..afa4c2dc5f 100644 --- a/src/models/flight_control/FGDistributor.cpp +++ b/src/models/flight_control/FGDistributor.cpp @@ -66,7 +66,7 @@ FGDistributor::FGDistributor(FGFCS* fcs, Element* element) while (case_element) { Case* current_case = new Case; Element* test_element = case_element->FindElement("test"); - if (test_element) current_case->SetTest(new FGCondition(test_element, PropertyManager)); + if (test_element) current_case->SetTest(new FGCondition(gdata(), test_element, PropertyManager)); Element* prop_val_element = case_element->FindElement("property"); while (prop_val_element) { string value_string = prop_val_element->GetAttributeValue("value"); @@ -129,6 +129,7 @@ bool FGDistributor::Run(void ) void FGDistributor::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGFCSComponent.cpp b/src/models/flight_control/FGFCSComponent.cpp index dbfe6cc46e..c07e2088cc 100644 --- a/src/models/flight_control/FGFCSComponent.cpp +++ b/src/models/flight_control/FGFCSComponent.cpp @@ -49,7 +49,8 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) : fcs(_fcs) +FGFCSComponent::FGFCSComponent(FGFCS* _fcs, Element* element) + : FGJSBBase(_fcs->gdata()), fcs(_fcs) { Input = Output = delay_time = 0.0; delay = index = 0; @@ -343,6 +344,7 @@ void FGFCSComponent::bind(Element* el) void FGFCSComponent::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGFCSFunction.cpp b/src/models/flight_control/FGFCSFunction.cpp index 23b881701c..6e72c25ae6 100644 --- a/src/models/flight_control/FGFCSFunction.cpp +++ b/src/models/flight_control/FGFCSFunction.cpp @@ -114,6 +114,7 @@ bool FGFCSFunction::Run(void ) void FGFCSFunction::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGFilter.cpp b/src/models/flight_control/FGFilter.cpp index 08681261e8..b08c57fd71 100644 --- a/src/models/flight_control/FGFilter.cpp +++ b/src/models/flight_control/FGFilter.cpp @@ -209,6 +209,7 @@ bool FGFilter::Run(void) void FGFilter::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGGain.cpp b/src/models/flight_control/FGGain.cpp index ac2d36c20d..b65b706723 100644 --- a/src/models/flight_control/FGGain.cpp +++ b/src/models/flight_control/FGGain.cpp @@ -62,7 +62,7 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) if (Type == "PURE_GAIN") { if ( !element->FindElement("gain") ) { cerr << element->ReadFrom() - << highint << " No GAIN specified (default: 1.0)" << normint + << gdata().highint << " No GAIN specified (default: 1.0)" << gdata().normint << endl; } } @@ -108,7 +108,7 @@ FGGain::FGGain(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) if (Type == "SCHEDULED_GAIN") { if (element->FindElement("table")) { - Table = new FGTable(PropertyManager, element->FindElement("table")); + Table = new FGTable(gdata(), PropertyManager, element->FindElement("table")); } else { cerr << element->ReadFrom() << "A table must be provided for the scheduled gain component" @@ -190,6 +190,7 @@ bool FGGain::Run(void ) void FGGain::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGGyro.cpp b/src/models/flight_control/FGGyro.cpp index f144422b52..b8c382bb90 100644 --- a/src/models/flight_control/FGGyro.cpp +++ b/src/models/flight_control/FGGyro.cpp @@ -49,7 +49,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGGyro::FGGyro(FGFCS* fcs, Element* element) : FGSensor(fcs, element), - FGSensorOrientation(element) + FGSensorOrientation(fcs->gdata(), element) { Propagate = fcs->GetExec()->GetPropagate(); @@ -107,6 +107,7 @@ void FGGyro::Debug(int from) { string ax[4] = {"none", "X", "Y", "Z"}; + auto debug_lvl = FGSensor::gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGKinemat.cpp b/src/models/flight_control/FGKinemat.cpp index 039860f656..90d66ecd5c 100644 --- a/src/models/flight_control/FGKinemat.cpp +++ b/src/models/flight_control/FGKinemat.cpp @@ -175,6 +175,7 @@ bool FGKinemat::Run(void ) void FGKinemat::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGLinearActuator.cpp b/src/models/flight_control/FGLinearActuator.cpp index b18ca841a1..2580e7330c 100644 --- a/src/models/flight_control/FGLinearActuator.cpp +++ b/src/models/flight_control/FGLinearActuator.cpp @@ -235,6 +235,7 @@ bool FGLinearActuator::Run(void ) // a message is printed out when they go out of bounds void FGLinearActuator::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGMagnetometer.cpp b/src/models/flight_control/FGMagnetometer.cpp index 14218bde07..25cbbfb701 100644 --- a/src/models/flight_control/FGMagnetometer.cpp +++ b/src/models/flight_control/FGMagnetometer.cpp @@ -52,7 +52,7 @@ CLASS IMPLEMENTATION FGMagnetometer::FGMagnetometer(FGFCS* fcs, Element* element) - : FGSensor(fcs, element), FGSensorOrientation(element), counter(0), + : FGSensor(fcs, element), FGSensorOrientation(fcs->gdata(), element), counter(0), INERTIAL_UPDATE_RATE(1000) { Propagate = fcs->GetExec()->GetPropagate(); @@ -170,6 +170,7 @@ void FGMagnetometer::Debug(int from) { string ax[4] = {"none", "X", "Y", "Z"}; + auto debug_lvl = FGSensor::gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGPID.cpp b/src/models/flight_control/FGPID.cpp index 24de8a4868..fda93a10b7 100644 --- a/src/models/flight_control/FGPID.cpp +++ b/src/models/flight_control/FGPID.cpp @@ -230,6 +230,7 @@ bool FGPID::Run(void ) void FGPID::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGSensor.cpp b/src/models/flight_control/FGSensor.cpp index 5c0d085707..54d00139c2 100644 --- a/src/models/flight_control/FGSensor.cpp +++ b/src/models/flight_control/FGSensor.cpp @@ -298,6 +298,7 @@ void FGSensor::bind(Element* el) void FGSensor::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGSensorOrientation.h b/src/models/flight_control/FGSensorOrientation.h index 0c62034d05..62066623ae 100644 --- a/src/models/flight_control/FGSensorOrientation.h +++ b/src/models/flight_control/FGSensorOrientation.h @@ -69,7 +69,7 @@ CLASS DECLARATION class FGSensorOrientation : public FGJSBBase { public: - FGSensorOrientation(Element* element) + FGSensorOrientation(CommonData& c, Element* element) : FGJSBBase(c) { Element* orient_element = element->FindElement("orientation"); if (orient_element) vOrient = orient_element->FindElementTripletConvertTo("RAD"); diff --git a/src/models/flight_control/FGSummer.cpp b/src/models/flight_control/FGSummer.cpp index 978168da57..0e4c43f86a 100644 --- a/src/models/flight_control/FGSummer.cpp +++ b/src/models/flight_control/FGSummer.cpp @@ -104,6 +104,7 @@ bool FGSummer::Run(void) void FGSummer::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGSwitch.cpp b/src/models/flight_control/FGSwitch.cpp index 926308c796..76d0c5de2b 100644 --- a/src/models/flight_control/FGSwitch.cpp +++ b/src/models/flight_control/FGSwitch.cpp @@ -96,7 +96,7 @@ FGSwitch::FGSwitch(FGFCS* fcs, Element* element) : FGFCSComponent(fcs, element) test_element = element->FindElement("test"); while (test_element) { current_test = new Test; - current_test->condition = new FGCondition(test_element, PropertyManager); + current_test->condition = new FGCondition(gdata(), test_element, PropertyManager); value = test_element->GetAttributeValue("value"); current_test->setTestValue(value, Name, PropertyManager); tests.push_back(current_test); @@ -187,6 +187,7 @@ void FGSwitch::VerifyProperties(void) void FGSwitch::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/flight_control/FGWaypoint.cpp b/src/models/flight_control/FGWaypoint.cpp index c813c0a4ed..9043918a6a 100644 --- a/src/models/flight_control/FGWaypoint.cpp +++ b/src/models/flight_control/FGWaypoint.cpp @@ -55,7 +55,7 @@ CLASS IMPLEMENTATION //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGWaypoint::FGWaypoint(FGFCS* fcs, Element* element) - : FGFCSComponent(fcs, element) + : FGFCSComponent(fcs, element), source(fcs->gdata()) { if (Type == "WAYPOINT_HEADING") WaypointType = eHeading; else if (Type == "WAYPOINT_DISTANCE") WaypointType = eDistance; @@ -242,6 +242,7 @@ bool FGWaypoint::Run(void ) void FGWaypoint::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGElectric.cpp b/src/models/propulsion/FGElectric.cpp index 06d01a9898..c8c5b619c1 100644 --- a/src/models/propulsion/FGElectric.cpp +++ b/src/models/propulsion/FGElectric.cpp @@ -56,7 +56,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGElectric::FGElectric(FGFDMExec* exec, Element *el, int engine_number, struct FGEngine::Inputs& input) - : FGEngine(engine_number, input) + : FGEngine(exec->gdata(), engine_number, input) { Load(exec,el); @@ -158,6 +158,7 @@ string FGElectric::GetEngineValues(const string& delimiter) void FGElectric::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGEngine.cpp b/src/models/propulsion/FGEngine.cpp index 0241c28377..747052d407 100644 --- a/src/models/propulsion/FGEngine.cpp +++ b/src/models/propulsion/FGEngine.cpp @@ -52,8 +52,8 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGEngine::FGEngine(int engine_number, struct Inputs& input) - : in(input), EngineNumber(engine_number) +FGEngine::FGEngine(CommonData& c, int engine_number, struct Inputs& input) + : FGModelFunctions(c), in(input), EngineNumber(engine_number) { Type = etUnknown; SLFuelFlowMax = 0.0; @@ -262,6 +262,7 @@ bool FGEngine::Load(FGFDMExec *exec, Element *engine_element) void FGEngine::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGEngine.h b/src/models/propulsion/FGEngine.h index 5edc751ce2..12dd59ef5f 100644 --- a/src/models/propulsion/FGEngine.h +++ b/src/models/propulsion/FGEngine.h @@ -130,7 +130,7 @@ class FGEngine : public FGModelFunctions double TotalDeltaT; }; - FGEngine(int engine_number, struct Inputs& input); + FGEngine(CommonData& c, int engine_number, struct Inputs& input); ~FGEngine() override; enum EngineType {etUnknown, etRocket, etPiston, etTurbine, etTurboprop, etElectric}; diff --git a/src/models/propulsion/FGForce.cpp b/src/models/propulsion/FGForce.cpp index 30350350bd..d26c757150 100644 --- a/src/models/propulsion/FGForce.cpp +++ b/src/models/propulsion/FGForce.cpp @@ -51,7 +51,7 @@ namespace JSBSim { //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FGForce::FGForce(FGFDMExec *FDMExec) - : fdmex(FDMExec), MassBalance(fdmex->GetMassBalance()), ttype(tNone) + : FGJSBBase(FDMExec->gdata()), fdmex(FDMExec), MassBalance(fdmex->GetMassBalance()), ttype(tNone) { vFn.InitMatrix(); vMn.InitMatrix(); @@ -176,6 +176,7 @@ void FGForce::SetAnglesToBody(double broll, double bpitch, double byaw) void FGForce::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGNozzle.cpp b/src/models/propulsion/FGNozzle.cpp index 9765339605..d1a8af6b69 100644 --- a/src/models/propulsion/FGNozzle.cpp +++ b/src/models/propulsion/FGNozzle.cpp @@ -129,6 +129,7 @@ string FGNozzle::GetThrusterValues(int id, const string& delimeter) void FGNozzle::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGPiston.cpp b/src/models/propulsion/FGPiston.cpp index 38813b5564..1f8fe0980a 100644 --- a/src/models/propulsion/FGPiston.cpp +++ b/src/models/propulsion/FGPiston.cpp @@ -57,7 +57,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Inputs& input) - : FGEngine(engine_number, input), + : FGEngine(exec->gdata(), engine_number, input), R_air(287.3), // Gas constant for air J/Kg/K calorific_value_fuel(47.3e6), // J/Kg Cp_air(1005), // Specific heat (constant pressure) J/Kg/K @@ -249,9 +249,9 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Input string name = table_element->GetAttributeValue("name"); try { if (name == "COMBUSTION") { - Lookup_Combustion_Efficiency = new FGTable(PropertyManager, table_element); + Lookup_Combustion_Efficiency = new FGTable(gdata(), PropertyManager, table_element); } else if (name == "MIXTURE") { - Mixture_Efficiency_Correlation = new FGTable(PropertyManager, table_element); + Mixture_Efficiency_Correlation = new FGTable(gdata(), PropertyManager, table_element); } else { cerr << "Unknown table type: " << name << " in piston engine definition." << endl; } @@ -315,7 +315,7 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Input // Default tables if not provided in the configuration file if(Lookup_Combustion_Efficiency == 0) { // First column is thi, second is neta (combustion efficiency) - Lookup_Combustion_Efficiency = new FGTable(12); + Lookup_Combustion_Efficiency = new FGTable(gdata(), 12); *Lookup_Combustion_Efficiency << 0.00 << 0.980; *Lookup_Combustion_Efficiency << 0.90 << 0.980; *Lookup_Combustion_Efficiency << 1.00 << 0.970; @@ -332,7 +332,7 @@ FGPiston::FGPiston(FGFDMExec* exec, Element* el, int engine_number, struct Input // First column is Fuel/Air Ratio, second is neta (mixture efficiency) if( Mixture_Efficiency_Correlation == 0) { - Mixture_Efficiency_Correlation = new FGTable(15); + Mixture_Efficiency_Correlation = new FGTable(gdata(), 15); *Mixture_Efficiency_Correlation << 0.05000 << 0.00000; *Mixture_Efficiency_Correlation << 0.05137 << 0.00862; *Mixture_Efficiency_Correlation << 0.05179 << 0.21552; @@ -1017,6 +1017,7 @@ string FGPiston::GetEngineValues(const string& delimiter) void FGPiston::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGPropeller.cpp b/src/models/propulsion/FGPropeller.cpp index 58b1f55ead..9280203d8f 100644 --- a/src/models/propulsion/FGPropeller.cpp +++ b/src/models/propulsion/FGPropeller.cpp @@ -102,13 +102,13 @@ FGPropeller::FGPropeller(FGFDMExec* exec, Element* prop_element, int num) name = table_element->GetAttributeValue("name"); try { if (name == "C_THRUST") { - cThrust = new FGTable(PropertyManager, table_element); + cThrust = new FGTable(gdata(), PropertyManager, table_element); } else if (name == "C_POWER") { - cPower = new FGTable(PropertyManager, table_element); + cPower = new FGTable(gdata(), PropertyManager, table_element); } else if (name == "CT_MACH") { - CtMach = new FGTable(PropertyManager, table_element); + CtMach = new FGTable(gdata(), PropertyManager, table_element); } else if (name == "CP_MACH") { - CpMach = new FGTable(PropertyManager, table_element); + CpMach = new FGTable(gdata(), PropertyManager, table_element); } else { cerr << "Unknown table type: " << name << " in propeller definition." << endl; } @@ -436,6 +436,7 @@ string FGPropeller::GetThrusterValues(int id, const string& delimeter) void FGPropeller::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGRocket.cpp b/src/models/propulsion/FGRocket.cpp index 098b0259ba..d0b69d1076 100644 --- a/src/models/propulsion/FGRocket.cpp +++ b/src/models/propulsion/FGRocket.cpp @@ -52,7 +52,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGRocket::FGRocket(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input) - : FGEngine(engine_number, input), isp_function(nullptr), FDMExec(exec) + : FGEngine(exec->gdata(), engine_number, input), isp_function(nullptr), FDMExec(exec) { Load(exec, el); @@ -127,7 +127,7 @@ FGRocket::FGRocket(FGFDMExec* exec, Element *el, int engine_number, struct Input // If there is a thrust table element, this is a solid propellant engine. thrust_table_element = el->FindElement("thrust_table"); if (thrust_table_element) { - ThrustTable = new FGTable(PropertyManager, thrust_table_element); + ThrustTable = new FGTable(gdata(), PropertyManager, thrust_table_element); Element* variation_element = el->FindElement("variation"); if (variation_element) { if (variation_element->FindElement("thrust")) { @@ -333,6 +333,7 @@ void FGRocket::bindmodel(FGPropertyManager* PropertyManager) void FGRocket::Debug(int from) { + const auto& debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGRotor.cpp b/src/models/propulsion/FGRotor.cpp index ab064e59fc..73774e809c 100644 --- a/src/models/propulsion/FGRotor.cpp +++ b/src/models/propulsion/FGRotor.cpp @@ -832,6 +832,7 @@ void FGRotor::Debug(int from) { string ControlMapName; + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGTank.cpp b/src/models/propulsion/FGTank.cpp index 30d09eaed4..539cdafa7e 100644 --- a/src/models/propulsion/FGTank.cpp +++ b/src/models/propulsion/FGTank.cpp @@ -49,7 +49,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGTank::FGTank(FGFDMExec* exec, Element* el, int tank_number) - : TankNumber(tank_number) + : FGJSBBase(exec->gdata()), TankNumber(tank_number) { string token, strFuelName; Element* element; @@ -510,6 +510,7 @@ void FGTank::bind(FGPropertyManager* PropertyManager) void FGTank::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGThruster.cpp b/src/models/propulsion/FGThruster.cpp index 9b70a5d2cb..3b05a26028 100644 --- a/src/models/propulsion/FGThruster.cpp +++ b/src/models/propulsion/FGThruster.cpp @@ -72,7 +72,7 @@ FGThruster::FGThruster(FGFDMExec *FDMExec, Element *el, int num ): FGForce(FDMEx element = thruster_element->FindElement("location"); if (element) location = element->FindElementTripletConvertTo("IN"); - else cerr << fgred << " No thruster location found." << reset << endl; + else cerr << gdata().fgred << " No thruster location found." << gdata().reset << endl; SetLocation(location); @@ -175,6 +175,7 @@ string FGThruster::GetThrusterValues(int id, const string& delimeter) void FGThruster::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGTransmission.cpp b/src/models/propulsion/FGTransmission.cpp index 4c756a7a68..4a94bc7b30 100644 --- a/src/models/propulsion/FGTransmission.cpp +++ b/src/models/propulsion/FGTransmission.cpp @@ -53,6 +53,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGTransmission::FGTransmission(FGFDMExec *exec, int num, double dt) : + FGJSBBase(exec->gdata()), FreeWheelTransmission(1.0), ThrusterMoment(1.0), EngineMoment(1.0), EngineFriction(0.0), ClutchCtrlNorm(1.0), BrakeCtrlNorm(0.0), MaxBrakePower(0.0), @@ -176,6 +177,7 @@ bool FGTransmission::BindModel(int num) void FGTransmission::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGTurbine.cpp b/src/models/propulsion/FGTurbine.cpp index 75b01106e0..29c952a091 100644 --- a/src/models/propulsion/FGTurbine.cpp +++ b/src/models/propulsion/FGTurbine.cpp @@ -57,7 +57,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGTurbine::FGTurbine(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input) - : FGEngine(engine_number, input), FDMExec(exec) + : FGEngine(exec->gdata(), engine_number, input), FDMExec(exec) { Type = etTurbine; @@ -632,6 +632,7 @@ int FGTurbine::InitRunning(void) void FGTurbine::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/src/models/propulsion/FGTurboProp.cpp b/src/models/propulsion/FGTurboProp.cpp index 4cad50b408..6e1d9aedd3 100644 --- a/src/models/propulsion/FGTurboProp.cpp +++ b/src/models/propulsion/FGTurboProp.cpp @@ -60,7 +60,7 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGTurboProp::FGTurboProp(FGFDMExec* exec, Element *el, int engine_number, struct Inputs& input) - : FGEngine(engine_number, input), + : FGEngine(exec->gdata(), engine_number, input), ITT_N1(NULL), EnginePowerRPM_N1(NULL), EnginePowerVC(NULL), CombustionEfficiency_N1(NULL) { @@ -148,18 +148,18 @@ bool FGTurboProp::Load(FGFDMExec* exec, Element *el) // ugly hack but the functionality is obsolete and will be removed some // time in the future. table_element->SetAttributeValue("name", string("propulsion/engine[#]/") + name); - EnginePowerVC = new FGTable(PropertyManager, table_element, + EnginePowerVC = new FGTable(gdata(), PropertyManager, table_element, to_string((int)EngineNumber)); table_element->SetAttributeValue("name", name); cerr << table_element->ReadFrom() <<"Note: Using the EnginePowerVC without enclosed tag is deprecated" << endl; } else if (name == "EnginePowerRPM_N1") { - EnginePowerRPM_N1 = new FGTable(PropertyManager, table_element); + EnginePowerRPM_N1 = new FGTable(gdata(), PropertyManager, table_element); } else if (name == "ITT_N1") { - ITT_N1 = new FGTable(PropertyManager, table_element); + ITT_N1 = new FGTable(gdata(), PropertyManager, table_element); } else if (name == "CombustionEfficiency_N1") { - CombustionEfficiency_N1 = new FGTable(PropertyManager, table_element); + CombustionEfficiency_N1 = new FGTable(gdata(), PropertyManager, table_element); } else { cerr << el->ReadFrom() << "Unknown table type: " << name << " in turboprop definition." << endl; @@ -176,7 +176,7 @@ bool FGTurboProp::Load(FGFDMExec* exec, Element *el) // default table based on '9.333 - (N1)/12.0' approximation // gives 430%Fuel at 60%N1 if (! CombustionEfficiency_N1) { - CombustionEfficiency_N1 = new FGTable(6); + CombustionEfficiency_N1 = new FGTable(gdata(), 6); *CombustionEfficiency_N1 << 60.0 << 12.0/52.0; *CombustionEfficiency_N1 << 82.0 << 12.0/30.0; *CombustionEfficiency_N1 << 96.0 << 12.0/16.0; @@ -584,6 +584,7 @@ void FGTurboProp::bindmodel(FGPropertyManager* PropertyManager) void FGTurboProp::Debug(int from) { + auto debug_lvl = gdata().debug_lvl; if (debug_lvl <= 0) return; if (debug_lvl & 1) { // Standard console startup message output diff --git a/tests/unit_tests/FGJSBBaseTest.h b/tests/unit_tests/FGJSBBaseTest.h index a493f89f65..d176c49331 100644 --- a/tests/unit_tests/FGJSBBaseTest.h +++ b/tests/unit_tests/FGJSBBaseTest.h @@ -6,6 +6,9 @@ class FGJSBBaseTest : public CxxTest::TestSuite, public JSBSim::FGJSBBase { public: + CommonData c; + FGJSBBaseTest() : JSBSim::FGJSBBase(c) {} + void testMessages() { const std::string myMessage = "My message"; std::set mesId;