]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGFDMExec.cpp
Bertrand Coconnier: updated fix for #204 and #222: JSBSim reset
[flightgear.git] / src / FDM / JSBSim / FGFDMExec.cpp
index 616dd6ea6e2c893c859edb2ef25142996e99819a..ade4209cdf5a26fa07a7673964c13b66bcb8006f 100644 (file)
@@ -71,47 +71,19 @@ using namespace std;
 
 namespace JSBSim {
 
-static const char *IdSrc = "$Id: FGFDMExec.cpp,v 1.82 2010/10/07 03:17:29 jberndt Exp $";
+static const char *IdSrc = "$Id: FGFDMExec.cpp,v 1.84 2011/01/16 16:26:14 bcoconni Exp $";
 static const char *IdHdr = ID_FDMEXEC;
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 CLASS IMPLEMENTATION
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-void checkTied ( FGPropertyManager *node )
-{
-  int N = node->nChildren();
-  string name;
-
-  for (int i=0; i<N; i++) {
-    if (node->getChild(i)->nChildren() ) {
-      checkTied( (FGPropertyManager*)node->getChild(i) );
-    }
-    if ( node->getChild(i)->isTied() ) {
-      name = ((FGPropertyManager*)node->getChild(i))->GetFullyQualifiedName();
-      node->Untie(name);
-    }
-  }
-}
-
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-// Constructors
-FGFDMExec::FGFDMExec(FGPropertyManager* root) : Root(root), delete_root(false)
-{
-  FDMctr = new unsigned int;
-  *FDMctr = 0;
-  Initialize();
-  root_overload = (root != NULL);
-}
+// Constructor
 
-FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) : Root(root), delete_root(false), FDMctr(fdmctr)
+FGFDMExec::FGFDMExec(FGPropertyManager* root, unsigned int* fdmctr) : Root(root), FDMctr(fdmctr)
 {
-  Initialize();
-  root_overload = (root != NULL);
-}
 
-void FGFDMExec::Initialize()
-{
   Frame           = 0;
   Error           = 0;
   GroundCallback  = 0;
@@ -138,6 +110,7 @@ void FGFDMExec::Initialize()
   IsChild = false;
   holding = false;
   Terminate = false;
+  StandAlone = false;
 
   sim_time = 0.0;
   dT = 1.0/120.0; // a default timestep size. This is needed for when JSBSim is
@@ -152,8 +125,10 @@ void FGFDMExec::Initialize()
 
   if (Root == 0) {                 // Then this is the root FDM
     Root = new FGPropertyManager;  // Create the property manager
-    delete_root = true;
-    
+    StandAlone = true;
+  }
+
+  if (FDMctr == 0) {
     FDMctr = new unsigned int;     // Create and initialize the child FDM counter
     (*FDMctr) = 0;
   }
@@ -194,16 +169,16 @@ void FGFDMExec::Initialize()
 FGFDMExec::~FGFDMExec()
 {
   try {
-    checkTied( instance );
+    Unbind();
     DeAllocate();
     
-   if(FDMctr != 0 && !root_overload) {
+    if (IdFDM == 0) { // Meaning this is no child FDM
       if(Root != 0) {
-         if (delete_root)
+         if(StandAlone)
             delete Root;
          Root = 0;
       }
-      if (IdFDM == 0) { // Meaning this is no child FDM
+      if(FDMctr != 0) {
          delete FDMctr;
          FDMctr = 0;
       }
@@ -709,7 +684,7 @@ bool FGFDMExec::LoadModel(const string& model, bool addModelToPath)
     FCS->LateBind();
   } catch (string prop) {
     cerr << endl << fgred << "  Could not late bind property " << prop 
-         << ". Aborting." << endl;
+         << ". Aborting." << reset << endl;
     result = false;
   }