diff --git a/src/input_output/FGInputType.cpp b/src/input_output/FGInputType.cpp index e41413bec..20ab4ec11 100644 --- a/src/input_output/FGInputType.cpp +++ b/src/input_output/FGInputType.cpp @@ -50,8 +50,9 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGInputType::FGInputType(FGFDMExec* fdmex, bool isEnabled) : - FGModel(fdmex), enabled(isEnabled) + FGModel(fdmex, "") { + enabled = isEnabled; Debug(0); } @@ -100,7 +101,6 @@ bool FGInputType::InitModel(void) bool FGInputType::Run(bool Holding) { if (FGModel::Run(Holding)) return true; - if (!enabled) return true; RunPreFunctions(); Read(Holding); diff --git a/src/input_output/FGInputType.h b/src/input_output/FGInputType.h index 596120ae6..93389cf99 100644 --- a/src/input_output/FGInputType.h +++ b/src/input_output/FGInputType.h @@ -130,7 +130,6 @@ class FGInputType : public FGModel protected: unsigned int InputIdx; - bool enabled; void Debug(int from) override; }; diff --git a/src/input_output/FGOutputType.cpp b/src/input_output/FGOutputType.cpp index 3bb7b50a4..257d418c7 100644 --- a/src/input_output/FGOutputType.cpp +++ b/src/input_output/FGOutputType.cpp @@ -54,9 +54,8 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGOutputType::FGOutputType(FGFDMExec* fdmex) : - FGModel(fdmex), - SubSystems(0), - enabled(true) + FGModel(fdmex, ""), + SubSystems(0) { Aerodynamics = FDMExec->GetAerodynamics(); Auxiliary = FDMExec->GetAuxiliary(); @@ -186,7 +185,6 @@ bool FGOutputType::InitModel(void) bool FGOutputType::Run(bool Holding) { if (FGModel::Run(Holding)) return true; - if (!enabled) return true; RunPreFunctions(); Print(); diff --git a/src/input_output/FGOutputType.h b/src/input_output/FGOutputType.h index 495d824a2..122d30090 100644 --- a/src/input_output/FGOutputType.h +++ b/src/input_output/FGOutputType.h @@ -196,7 +196,6 @@ class FGOutputType : public FGModel int SubSystems; std::vector OutputParameters; std::vector OutputCaptions; - bool enabled; std::shared_ptr Aerodynamics; std::shared_ptr Auxiliary; diff --git a/src/models/FGAccelerations.cpp b/src/models/FGAccelerations.cpp index 5bc6e9105..36f1524b8 100644 --- a/src/models/FGAccelerations.cpp +++ b/src/models/FGAccelerations.cpp @@ -66,10 +66,9 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGAccelerations::FGAccelerations(FGFDMExec* fdmex) - : FGModel(fdmex) + : FGModel(fdmex, "FGAccelerations") { Debug(0); - Name = "FGAccelerations"; gravTorque = false; vPQRidot.InitMatrix(); diff --git a/src/models/FGAerodynamics.cpp b/src/models/FGAerodynamics.cpp index c0cb78418..dfb7af1df 100644 --- a/src/models/FGAerodynamics.cpp +++ b/src/models/FGAerodynamics.cpp @@ -50,10 +50,8 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec) +FGAerodynamics::FGAerodynamics(FGFDMExec* FDMExec) : FGModel(FDMExec, "FGAerodynamics") { - Name = "FGAerodynamics"; - AxisIdx["DRAG"] = 0; AxisIdx["SIDE"] = 1; AxisIdx["LIFT"] = 2; diff --git a/src/models/FGAircraft.cpp b/src/models/FGAircraft.cpp index a7c7e6337..9fbd77e79 100644 --- a/src/models/FGAircraft.cpp +++ b/src/models/FGAircraft.cpp @@ -51,9 +51,8 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex) +FGAircraft::FGAircraft(FGFDMExec* fdmex) : FGModel(fdmex, "FGAircraft") { - Name = "FGAircraft"; WingSpan = 0.0; WingArea = 0.0; cbar = 0.0; diff --git a/src/models/FGAtmosphere.cpp b/src/models/FGAtmosphere.cpp index 063f7d126..637986215 100644 --- a/src/models/FGAtmosphere.cpp +++ b/src/models/FGAtmosphere.cpp @@ -55,11 +55,9 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGAtmosphere::FGAtmosphere(FGFDMExec* fdmex) - : FGModel(fdmex), + : FGModel(fdmex, "FGAtmosphere"), StdDaySLsoundspeed(sqrt(SHRatio*Reng0*StdDaySLtemperature)) { - Name = "FGAtmosphere"; - bind(); SGPropertyNode* root = PropertyManager->GetNode(); atmosphere_node = root->getNode("atmosphere"); diff --git a/src/models/FGAuxiliary.cpp b/src/models/FGAuxiliary.cpp index 1f2e4de75..66dc6f0e9 100644 --- a/src/models/FGAuxiliary.cpp +++ b/src/models/FGAuxiliary.cpp @@ -59,9 +59,8 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex) +FGAuxiliary::FGAuxiliary(FGFDMExec* fdmex) : FGModel(fdmex, "FGAuxiliary") { - Name = "FGAuxiliary"; pt = FGAtmosphere::StdDaySLpressure; // ISA SL pressure tat = FGAtmosphere::StdDaySLtemperature; // ISA SL temperature tatc = RankineToCelsius(tat); diff --git a/src/models/FGBuoyantForces.cpp b/src/models/FGBuoyantForces.cpp index de0e2baac..267eb6cc4 100644 --- a/src/models/FGBuoyantForces.cpp +++ b/src/models/FGBuoyantForces.cpp @@ -49,10 +49,8 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGBuoyantForces::FGBuoyantForces(FGFDMExec* FDMExec) : FGModel(FDMExec) +FGBuoyantForces::FGBuoyantForces(FGFDMExec* FDMExec) : FGModel(FDMExec, "FGBuoyantForces") { - Name = "FGBuoyantForces"; - NoneDefined = true; vTotalForces.InitMatrix(); diff --git a/src/models/FGExternalReactions.cpp b/src/models/FGExternalReactions.cpp index b58e9f9ff..caedbb1ac 100644 --- a/src/models/FGExternalReactions.cpp +++ b/src/models/FGExternalReactions.cpp @@ -50,7 +50,7 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex) +FGExternalReactions::FGExternalReactions(FGFDMExec* fdmex) : FGModel(fdmex, "FGExternalReactions") { Debug(0); } diff --git a/src/models/FGFCS.cpp b/src/models/FGFCS.cpp index 539674630..2fc7bf95d 100644 --- a/src/models/FGFCS.cpp +++ b/src/models/FGFCS.cpp @@ -71,10 +71,9 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGFCS::FGFCS(FGFDMExec* fdm) : FGModel(fdm), ChannelRate(1) +FGFCS::FGFCS(FGFDMExec* fdm) : FGModel(fdm, "FGFCS"), ChannelRate(1) { int i; - Name = "FGFCS"; systype = stFCS; DaCmd = DeCmd = DrCmd = DfCmd = DsbCmd = DspCmd = 0; diff --git a/src/models/FGGroundReactions.cpp b/src/models/FGGroundReactions.cpp index 73377d16a..685f0d9c3 100644 --- a/src/models/FGGroundReactions.cpp +++ b/src/models/FGGroundReactions.cpp @@ -52,12 +52,10 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGGroundReactions::FGGroundReactions(FGFDMExec* fgex) : - FGModel(fgex), + FGModel(fgex, "FGGroundReactions"), FGSurface(fgex), DsCmd(0.0) { - Name = "FGGroundReactions"; - bind(); Debug(0); diff --git a/src/models/FGInertial.cpp b/src/models/FGInertial.cpp index 4ddb35dcd..2c2c6bcb5 100644 --- a/src/models/FGInertial.cpp +++ b/src/models/FGInertial.cpp @@ -51,7 +51,7 @@ CLASS IMPLEMENTATION FGInertial::FGInertial(FGFDMExec* fgex) - : FGModel(fgex) + : FGModel(fgex, "FGInertial") { Name = "Earth"; diff --git a/src/models/FGInput.cpp b/src/models/FGInput.cpp index 06b014b3d..7f9056153 100644 --- a/src/models/FGInput.cpp +++ b/src/models/FGInput.cpp @@ -54,9 +54,8 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGInput::FGInput(FGFDMExec* fdmex) : FGModel(fdmex) +FGInput::FGInput(FGFDMExec* fdmex) : FGModel(fdmex, "FGInput") { - Name = "FGInput"; enabled = true; Debug(0); @@ -142,7 +141,6 @@ bool FGInput::Run(bool Holding) { if (FDMExec->GetTrimStatus()) return true; if (FGModel::Run(Holding)) return true; - if (!enabled) return true; vector::iterator it; for (it = InputTypes.begin(); it != InputTypes.end(); ++it) diff --git a/src/models/FGInput.h b/src/models/FGInput.h index af27287d9..9d6a94f53 100644 --- a/src/models/FGInput.h +++ b/src/models/FGInput.h @@ -145,7 +145,6 @@ class FGInput : public FGModel private: std::vector InputTypes; - bool enabled; void Debug(int from) override; }; diff --git a/src/models/FGMassBalance.cpp b/src/models/FGMassBalance.cpp index e431fdf49..766c5d204 100644 --- a/src/models/FGMassBalance.cpp +++ b/src/models/FGMassBalance.cpp @@ -55,9 +55,8 @@ CLASS IMPLEMENTATION FGMassBalance::FGMassBalance(FGFDMExec* fdmex) - : FGModel(fdmex) + : FGModel(fdmex, "FGMassBalance") { - Name = "FGMassBalance"; Weight = EmptyWeight = Mass = 0.0; vbaseXYZcg.InitMatrix(); diff --git a/src/models/FGModel.cpp b/src/models/FGModel.cpp index 7b76d9a2f..82d19c567 100644 --- a/src/models/FGModel.cpp +++ b/src/models/FGModel.cpp @@ -42,6 +42,7 @@ INCLUDES #include "FGFDMExec.h" #include "input_output/FGModelLoader.h" #include "input_output/FGLog.h" +#include "input_output/FGPropertyManager.h" using namespace std; @@ -55,7 +56,8 @@ GLOBAL DECLARATIONS CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGModel::FGModel(FGFDMExec* fdmex) +FGModel::FGModel(FGFDMExec* fdmex, const std::string& name) + : Name(name) { FDMExec = fdmex; @@ -67,6 +69,15 @@ FGModel::FGModel(FGFDMExec* fdmex) exe_ctr = 1; rate = 1; + // A model that is scheduled by FGFDMExec is named and gets an enable property. + // The input and output types are not scheduled: they are instantiated one per + // and element, so a shared property path would be tied more + // than once. They pass an empty name and are enabled through the per-instance + // property that FGOutputType::SetIdx already binds, or through Enable() and + // Disable(). + if (!Name.empty()) + PropertyManager->Tie("simulation/models/" + Name + "/enabled", &enabled); + Debug(0); } @@ -91,12 +102,13 @@ bool FGModel::Run(bool Holding) { FGModel::Debug(2); - if (rate == 1) return false; // Fast exit if nothing to do + if (rate == 1) return !enabled; // Fast exit if nothing to do if (exe_ctr >= rate) exe_ctr = 0; - if (exe_ctr++ == 1) return false; - else return true; + if (exe_ctr++ == 1) return !enabled; + + return true; } //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/src/models/FGModel.h b/src/models/FGModel.h index 752ef4f35..bec31739b 100644 --- a/src/models/FGModel.h +++ b/src/models/FGModel.h @@ -59,6 +59,15 @@ CLASS DOCUMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ /** Base class for all scheduled JSBSim models + + Each model binds simulation/models//enabled (default true), where Name + is the name passed to the constructor. Setting that property false skips the + model's Run(): its last state and its property bindings are preserved, which + is the property-tree mechanism by which an external system can replace a + model, for example a host physics engine owning FGGroundReactions. The + binding is made at construction, so a model that renames itself while + loading does not move its enable property. + @author Jon S. Berndt */ @@ -70,14 +79,16 @@ class JSBSIM_API FGModel : public FGModelFunctions { public: - /// Constructor - explicit FGModel(FGFDMExec*); + /** Constructor. + @param name the name of this model. It populates the member Name and binds + simulation/models//enabled. */ + FGModel(FGFDMExec*, const std::string& name); /// Destructor ~FGModel() override; /** Runs the model; called by the Executive. Can pass in a value indicating if the executive is directing the simulation to Hold. - @param Holding if true, the executive has been directed to hold the sim from + @param Holding if true, the executive has been directed to hold the sim from advancing time. Some models may ignore this flag, such as the Input model, which may need to be active to listen on a socket for the "Resume" command to be given. The Holding flag is not used in the base @@ -101,6 +112,7 @@ class JSBSIM_API FGModel : public FGModelFunctions protected: unsigned int exe_ctr; unsigned int rate; + bool enabled = true; std::string Name; /** Uploads this model in memory. diff --git a/src/models/FGOutput.cpp b/src/models/FGOutput.cpp index 9a8d47d63..fd8ed8c29 100644 --- a/src/models/FGOutput.cpp +++ b/src/models/FGOutput.cpp @@ -55,9 +55,8 @@ namespace JSBSim { CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex) +FGOutput::FGOutput(FGFDMExec* fdmex) : FGModel(fdmex, "FGOutput") { - Name = "FGOutput"; enabled = true; PropertyManager->Tie("simulation/force-output", this, nullptr, @@ -97,7 +96,6 @@ bool FGOutput::Run(bool Holding) if (FDMExec->GetTrimStatus()) return true; if (FGModel::Run(Holding)) return true; if (Holding) return false; - if (!enabled) return true; for (auto output: OutputTypes) output->Run(Holding); diff --git a/src/models/FGOutput.h b/src/models/FGOutput.h index 17367c2e8..40e13c727 100644 --- a/src/models/FGOutput.h +++ b/src/models/FGOutput.h @@ -222,7 +222,6 @@ class JSBSIM_API FGOutput : public FGModel private: std::vector OutputTypes; - bool enabled; SGPath includePath; void Debug(int from) override; diff --git a/src/models/FGPropagate.cpp b/src/models/FGPropagate.cpp index ada4e0af9..24dcec0ea 100644 --- a/src/models/FGPropagate.cpp +++ b/src/models/FGPropagate.cpp @@ -81,10 +81,8 @@ CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ FGPropagate::FGPropagate(FGFDMExec* fdmex) - : FGModel(fdmex) + : FGModel(fdmex, "FGPropagate") { - Name = "FGPropagate"; - Inertial = FDMExec->GetInertial(); /// These define the indices use to select the various integrators. diff --git a/src/models/FGPropulsion.cpp b/src/models/FGPropulsion.cpp index 3bcbc5079..765b584b5 100644 --- a/src/models/FGPropulsion.cpp +++ b/src/models/FGPropulsion.cpp @@ -72,10 +72,8 @@ extern short debug_lvl; CLASS IMPLEMENTATION %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/ -FGPropulsion::FGPropulsion(FGFDMExec* exec) : FGModel(exec) +FGPropulsion::FGPropulsion(FGFDMExec* exec) : FGModel(exec, "FGPropulsion") { - Name = "FGPropulsion"; - ActiveEngine = -1; // -1: ALL, 0: Engine 1, 1: Engine 2 ... tankJ.InitMatrix(); DumpRate = 0.0; diff --git a/src/models/atmosphere/FGWinds.cpp b/src/models/atmosphere/FGWinds.cpp index b6ade15ea..8b156b6ae 100644 --- a/src/models/atmosphere/FGWinds.cpp +++ b/src/models/atmosphere/FGWinds.cpp @@ -73,10 +73,8 @@ static inline double square_signed (double value) constexpr double sqr(double x) { return x*x; } FGWinds::FGWinds(FGFDMExec* fdmex) - : FGModel(fdmex), generator(fdmex->GetRandomGenerator()) + : FGModel(fdmex, "FGWinds"), generator(fdmex->GetRandomGenerator()) { - Name = "FGWinds"; - MagnitudedAccelDt = MagnitudeAccel = Magnitude = TurbDirection = 0.0; SetTurbType( ttMilspec ); TurbGain = 1.0;