]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGCoefficient.cpp
Updated to match changes in radiostack.[ch]xx
[flightgear.git] / src / FDM / JSBSim / FGCoefficient.cpp
index 55639c31f2a4bb3802c3b16517ecd4469e56d0f6..801571f4f3ef1a73c126d8b01463a092ae132a6c 100644 (file)
@@ -47,6 +47,7 @@ INCLUDES
 #include "FGCoefficient.h"
 #include "FGState.h"
 #include "FGFDMExec.h"
+#include "FGPropertyManager.h"
 
 #ifndef FGFS
 #  if defined(sgi) && !defined(__GNUC__)
@@ -67,15 +68,31 @@ CLASS IMPLEMENTATION
 
 FGCoefficient::FGCoefficient( FGFDMExec* fdex )
 {
-
   FDMExec = fdex;
   State   = FDMExec->GetState();
   Table   = 0;
   
-  bias=0;
-  gain=1;
-
-  if (debug_lvl & 2) cout << "Instantiated: FGCoefficient" << endl;
+  PropertyManager = FDMExec->GetPropertyManager();
+  
+  Table = (FGTable*)0L;
+  LookupR = LookupC = 0;
+  numInstances = 0;
+  rows = columns = 0;
+
+  StaticValue  = 0.0;
+  totalValue   = 0.0;
+  bias = 0.0;
+  gain = 1.0;
+
+  filename.erase();
+  description.erase();
+  name.erase();
+  method.erase();
+  multparms.erase();
+  multparmsRow.erase();
+  multparmsCol.erase();
+
+  Debug(0);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -83,7 +100,7 @@ FGCoefficient::FGCoefficient( FGFDMExec* fdex )
 FGCoefficient::~FGCoefficient()
 {
   if (Table) delete Table;
-  if (debug_lvl & 2) cout << "Destroyed:    FGCoefficient" << endl;
+  Debug(1);
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -91,7 +108,7 @@ FGCoefficient::~FGCoefficient()
 bool FGCoefficient::Load(FGConfigFile *AC_cfg)
 {
   int start, end, n;
-  string mult;
+  string mult,prop;
 
   if (AC_cfg) {
     name = AC_cfg->GetValue("NAME");
@@ -115,12 +132,15 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg)
       }
 
       *AC_cfg >> multparmsRow;
-      LookupR = State->GetParameterIndex(multparmsRow);
+      prop = State->GetPropertyName( multparmsRow );
+      LookupR = PropertyManager->GetNode( prop );
     }
 
     if (type == TABLE) {
       *AC_cfg >> multparmsCol;
-      LookupC = State->GetParameterIndex(multparmsCol);
+      prop = State->GetPropertyName( multparmsCol );
+
+      LookupC = PropertyManager->GetNode( prop );
     }
 
     // Here, read in the line of the form (e.g.) FG_MACH|FG_QBAR|FG_ALPHA
@@ -137,11 +157,14 @@ bool FGCoefficient::Load(FGConfigFile *AC_cfg)
       while (n < end && n >= 0) {
         n -= start;
         mult = multparms.substr(start,n);
-        multipliers.push_back( State->GetParameterIndex(mult) );
+        prop= State->GetPropertyName( mult );
+        multipliers.push_back( PropertyManager->GetNode(prop) );
         start += n+1;
         n = multparms.find("|",start);
       }
-      multipliers.push_back(State->GetParameterIndex(multparms.substr(start,n)));
+      prop=State->GetPropertyName( multparms.substr(start,n) );
+      mult = multparms.substr(start,n);
+      multipliers.push_back( PropertyManager->GetNode(prop) );
       // End of non-dimensionalizing parameter read-in
     }
 
@@ -172,10 +195,9 @@ double FGCoefficient::Value(double rVal, double cVal)
   unsigned int midx;
 
   SD = Value = gain*Table->GetValue(rVal, cVal) + bias;
-  
 
   for (midx=0; midx < multipliers.size(); midx++) {
-      Value *= State->GetParameter(multipliers[midx]);
+      Value *= multipliers[midx]->getDoubleValue();
   }
   return Value;
 }
@@ -189,7 +211,7 @@ double FGCoefficient::Value(double Val)
   SD = Value = gain*Table->GetValue(Val) + bias;
   
   for (unsigned int midx=0; midx < multipliers.size(); midx++) 
-      Value *= State->GetParameter(multipliers[midx]);
+      Value *= multipliers[midx]->getDoubleValue();
   
   return Value;
 }
@@ -203,35 +225,39 @@ double FGCoefficient::Value(void)
   SD = Value = gain*StaticValue + bias;
 
   for (unsigned int midx=0; midx < multipliers.size(); midx++)
-    Value *= State->GetParameter(multipliers[midx]);
+    Value *= multipliers[midx]->getDoubleValue();
 
   return Value;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-double FGCoefficient::TotalValue()
+double FGCoefficient::TotalValue(void)
 {
   switch(type) {
-  case 0:
-    return -1;
-  case 1:
-    return (Value());
-  case 2:
-    return (Value(State->GetParameter(LookupR)));
-  case 3:
-    return (Value(State->GetParameter(LookupR),State->GetParameter(LookupC)));
-  case 4:
-    return 0.0;
-  }
-  return 0;
-}
 
-//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+  case UNKNOWN:
+    totalValue = -1;
+    break;
 
-void FGCoefficient::DumpSD(void)
-{
-  cout << "   " << name << ": " << SD << endl;
+  case VALUE:
+    totalValue = Value();
+    break;
+
+  case VECTOR:
+    totalValue = Value( LookupR->getDoubleValue() );
+    break;
+
+  case TABLE:
+    totalValue = Value( LookupR->getDoubleValue(),
+                      LookupC->getDoubleValue() );
+    break;
+
+  case EQUATION:
+    totalValue = 0.0;
+    break;
+  }
+  return totalValue;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -246,14 +272,14 @@ void FGCoefficient::DisplayCoeffFactors(void)
     cout << "none" << endl;
   } else {
     for (i=0; i<multipliers.size(); i++) 
-      cout << State->GetParameterName(multipliers[i]);
+      cout << multipliers[i]->getName() << "  ";
   }
   cout << endl;
 }
 
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 
-string FGCoefficient::GetCoefficientValues(void)
+string FGCoefficient::GetSDstring(void)
 {
   char buffer[10];
   string value;
@@ -263,6 +289,50 @@ string FGCoefficient::GetCoefficientValues(void)
   return value;
 }
 
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGCoefficient::bind(FGPropertyManager *parent)
+{
+  string mult;
+  unsigned i;
+  
+  node=parent->GetNode(name,true);
+  
+  node->SetString("description",description);
+  if (LookupR) node->SetString("row-parm",LookupR->getName() );
+  if (LookupC) node->SetString("column-parm",LookupC->getName() );
+  
+  mult="";
+  if (multipliers.size() == 0) 
+    mult="none";
+    
+  for (i=0; i<multipliers.size(); i++) {
+      mult += multipliers[i]->getName();
+      if ( i < multipliers.size()-1 ) mult += " "; 
+  }
+  node->SetString("multipliers",mult);
+  
+  node->Tie("SD-norm",this,&FGCoefficient::GetSD );
+  node->Tie("value-lbs",this,&FGCoefficient::GetValue );
+  
+  node->Tie("bias", this, &FGCoefficient::getBias,
+                          &FGCoefficient::setBias );
+                          
+  node->Tie("gain", this, &FGCoefficient::getGain,
+                          &FGCoefficient::setGain );
+
+}
+
+//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+void FGCoefficient::unbind(void)
+{
+  node->Untie("SD-norm");
+  node->Untie("value-lbs"); 
+  node->Untie("bias");  
+  node->Untie("gain");
+}
+  
 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 //    The bitmasked value choices are as follows:
 //    unset: In this case (the default) JSBSim would only print
@@ -298,11 +368,11 @@ void FGCoefficient::Debug(int from)
         if (type == TABLE) {
           cout << "Cols: " << columns;
         }
-        cout << endl << "   Row indexing parameter: " << multparmsRow << endl;
+        cout << endl << "   Row indexing parameter: " << LookupR->getName() << endl;
       }
 
       if (type == TABLE) {
-        cout << "   Column indexing parameter: " << multparmsCol << endl;
+        cout << "   Column indexing parameter: " << LookupC->getName() << endl;
       }
 
       if (type == VALUE) {