-/*******************************************************************************
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Module: FGFDMExec.cpp
Author: Jon S. Berndt
--------------------------------------------------------------------------------
11/17/98 JSB Created
-********************************************************************************
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
INCLUDES
-*******************************************************************************/
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
#ifdef FGFS
-# include <Include/compiler.h>
-# ifdef FG_HAVE_STD_INCLUDES
+# include <simgear/compiler.h>
+# ifdef SG_HAVE_STD_INCLUDES
# include <iostream>
# include <ctime>
# else
#include "FGAuxiliary.h"
#include "FGOutput.h"
-/*******************************************************************************
-************************************ CODE **************************************
-*******************************************************************************/
+static const char *IdSrc = "$Header$";
+static const char *IdHdr = "ID_FDMEXEC";
+
+/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+CLASS IMPLEMENTATION
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
// Constructor
Auxiliary = 0;
Output = 0;
- // Instantiate this FDM Executive's Models
+ terminate = false;
+ frozen = false;
+ modelLoaded = false;
+
+ Allocate();
+
+}
+
+FGFDMExec::~FGFDMExec(void){
+
+ DeAllocate();
+}
+
+bool FGFDMExec::Allocate(void) {
+
+ bool result=true;
+
Atmosphere = new FGAtmosphere(this);
FCS = new FGFCS(this);
Aircraft = new FGAircraft(this);
Rotation = new FGRotation(this);
Position = new FGPosition(this);
Auxiliary = new FGAuxiliary(this);
-// Output = new FGOutput(this);
+ Output = new FGOutput(this);
State = new FGState(this);
if (!Rotation->InitModel()) {cerr << "Rotation model init failed"; Error+=16;}
if (!Position->InitModel()) {cerr << "Position model init failed"; Error+=32;}
if (!Auxiliary->InitModel()) {cerr << "Auxiliary model init failed"; Error+=64;}
-// if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;}
-
- Schedule(Atmosphere, 5);
+ if (!Output->InitModel()) {cerr << "Output model init failed"; Error+=128;}
+
+ if(Error > 0) result=false;
+
+ // Schedule a model. The second arg (the integer) is the pass number. For
+ // instance, the atmosphere model gets executed every fifth pass it is called
+ // by the executive. Everything else here gets executed each pass.
+
+ Schedule(Atmosphere, 1);
Schedule(FCS, 1);
Schedule(Aircraft, 1);
Schedule(Rotation, 1);
Schedule(Translation, 1);
Schedule(Position, 1);
Schedule(Auxiliary, 1);
-// Schedule(Output, 1);
+ Schedule(Output, 1);
+
+ modelLoaded = false;
+ return result;
- terminate = false;
- frozen = false;
}
+bool FGFDMExec::DeAllocate(void) {
+
+ if ( Atmosphere != 0 ) delete Atmosphere;
+ if ( FCS != 0 ) delete FCS;
+ if ( Aircraft != 0 ) delete Aircraft;
+ if ( Translation != 0 ) delete Translation;
+ if ( Rotation != 0 ) delete Rotation;
+ if ( Position != 0 ) delete Position;
+ if ( Auxiliary != 0 ) delete Auxiliary;
+ if ( Output != 0 ) delete Output;
+ if ( State != 0 ) delete State;
+
+ FirstModel = 0L;
+ Error = 0;
-FGFDMExec::~FGFDMExec(void)
-{
+ State = 0;
+ Atmosphere = 0;
+ FCS = 0;
+ Aircraft = 0;
+ Translation = 0;
+ Rotation = 0;
+ Position = 0;
+ Auxiliary = 0;
+ Output = 0;
+
+ modelLoaded = false;
+
}
return true;
}
+
+bool FGFDMExec::RunIC(FGInitialCondition *fgic)
+{
+ State->Suspend();
+ State->Initialize(fgic);
+ Run();
+ State->Resume();
+ return true;
+}
+
+
+bool FGFDMExec::LoadModel(string APath, string EPath, string model)
+{
+ bool result=false;
+ if(modelLoaded) {
+ DeAllocate();
+ Allocate();
+ }
+ AircraftPath = APath;
+ EnginePath = EPath;
+ result = Aircraft->LoadAircraft(AircraftPath, EnginePath, model);
+
+ if (result) {
+ modelLoaded = true;
+ } else {
+ cerr << "FGFDMExec: Failed to load aircraft and/or engine model" << endl;
+ }
+
+ return result;
+}
+
+
+bool FGFDMExec::RunScript(string script)
+{
+}