~ubuntu-branches/debian/sid/flightgear/sid

« back to all changes in this revision

Viewing changes to src/FDM/JSBSim/math/FGFunction.cpp

  • Committer: Package Import Robot
  • Author(s): Markus Wanner, Markus Wanner, Rebecca Palmer
  • Date: 2014-01-21 22:31:02 UTC
  • mfrom: (1.3.1) (15.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20140121223102-cjw7g9le25acd119
Tags: 3.0.0~git20140204+c99ea4-1
[ Markus Wanner ]
* Upload to unstable.
* Adjust B-D to allow building on kfreebsd-*. Closes: #724686.
* Add a lintian-overrides on autotools; we use cmake.
* Upstream corrected the fgfs manpage. Closes: #556362.
* Drop unnecessary man page for gl-info. Closes: #698308.
* Drop README.Linux: it's outdated to the point of uselessness.
  Closes: #574173.
* Add an upper limit of libsimgear-dev versions that flightgear can be
  built with. Closes: #738436.
* Drop the libsvn-dev dependency, neither flightgear nor simgear depend
  on libsvn, anymore. Closes: #682947.
* List icons in debian/install rather than copying around from rules.
* Update menu entry for flightgear, add one for fgcom; add .xpm icons.
  Closes: #713924.
* flightgear.desktop: add German translation
* Bump Standards-Version to 3.9.5; no changes needed.

[ Rebecca Palmer ]
* New upstream release.
* Install the icons (based on code by Saikrishna Arcot).  (Not a
  complete fix for LP908153 as it only sets the menu/Dash icon, not the
  running window's icon, but better than nothing).
* Disable screensaver while running. Closes: LP#793599. Add required
  libdbus-1-dev dependency.
* Remove outdated README.Debian.
* Terrasync now works after just ticking the box. Closes: #252899.
* Always set Terrasync directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
43
43
 
44
44
namespace JSBSim {
45
45
 
46
 
static const char *IdSrc = "$Id: FGFunction.cpp,v 1.43 2012/02/05 11:15:54 bcoconni Exp $";
 
46
static const char *IdSrc = "$Id: FGFunction.cpp,v 1.53 2013/09/27 19:42:08 jberndt Exp $";
47
47
static const char *IdHdr = ID_FUNCTION;
48
48
 
49
49
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
64
const std::string FGFunction::product_string = "product";
65
65
const std::string FGFunction::quotient_string = "quotient";
66
66
const std::string FGFunction::pow_string = "pow";
 
67
const std::string FGFunction::sqrt_string = "sqrt";
 
68
const std::string FGFunction::toradians_string = "toradians";
 
69
const std::string FGFunction::todegrees_string = "todegrees";
67
70
const std::string FGFunction::exp_string = "exp";
68
71
const std::string FGFunction::log2_string = "log2";
69
72
const std::string FGFunction::ln_string = "ln";
83
86
const std::string FGFunction::fraction_string = "fraction";
84
87
const std::string FGFunction::mod_string = "mod";
85
88
const std::string FGFunction::random_string = "random";
 
89
const std::string FGFunction::urandom_string = "urandom";
 
90
const std::string FGFunction::pi_string = "pi";
86
91
const std::string FGFunction::integer_string = "integer";
87
92
const std::string FGFunction::rotation_alpha_local_string = "rotation_alpha_local";
88
93
const std::string FGFunction::rotation_beta_local_string = "rotation_beta_local";
101
106
const std::string FGFunction::not_string = "not";
102
107
const std::string FGFunction::ifthen_string = "ifthen";
103
108
const std::string FGFunction::switch_string = "switch";
 
109
const std::string FGFunction::interpolate1d_string = "interpolate1d";
104
110
 
105
111
FGFunction::FGFunction(FGPropertyManager* propMan, Element* el, const string& prefix)
106
112
                                      : PropertyManager(propMan), Prefix(prefix)
110
116
  cached = false;
111
117
  cachedValue = -HUGE_VAL;
112
118
  invlog2val = 1.0/log10(2.0);
 
119
  pCopyTo = 0L;
113
120
 
114
121
  Name = el->GetAttributeValue("name");
115
122
  operation = el->GetName();
116
123
 
117
124
  if (operation == function_string) {
 
125
    sCopyTo = el->GetAttributeValue("copyto");
 
126
    if (!sCopyTo.empty()) {
 
127
 
 
128
      if (sCopyTo.find("#") != string::npos) {
 
129
        if (is_number(Prefix)) sCopyTo = replace(sCopyTo,"#",Prefix);
 
130
      }
 
131
 
 
132
      pCopyTo = PropertyManager->GetNode(sCopyTo);
 
133
      if (pCopyTo == 0L) cerr << "Property \"" << sCopyTo << "\" must be previously defined in function "
 
134
                              << Name << endl;
 
135
    }
118
136
    Type = eTopLevel;
119
137
  } else if (operation == product_string) {
120
138
    Type = eProduct;
126
144
    Type = eQuotient;
127
145
  } else if (operation == pow_string) {
128
146
    Type = ePow;
 
147
  } else if (operation == sqrt_string) {
 
148
    Type = eSqrt;
 
149
  } else if (operation == toradians_string) {
 
150
    Type = eToRadians;
 
151
  } else if (operation == todegrees_string) {
 
152
    Type = eToDegrees;
129
153
  } else if (operation == log2_string) {
130
154
    Type = eLog2;
131
155
  } else if (operation == ln_string) {
166
190
    Type = eMod;
167
191
  } else if (operation == random_string) {
168
192
    Type = eRandom;
 
193
  } else if (operation == urandom_string) {
 
194
    Type = eUrandom;
 
195
  } else if (operation == pi_string) {
 
196
    Type = ePi;
169
197
  } else if (operation == rotation_alpha_local_string) {
170
198
    Type = eRotation_alpha_local;
171
199
  } else if (operation == rotation_beta_local_string) {
198
226
    Type = eIfThen;
199
227
  } else if (operation == switch_string) {
200
228
    Type = eSwitch;
 
229
  } else if (operation == interpolate1d_string) {
 
230
    Type = eInterpolate1D;
201
231
  } else if (operation != description_string) {
202
232
    cerr << "Bad operation " << operation << " detected in configuration file" << endl;
203
233
  }
204
234
 
205
235
  element = el->GetElement();
206
 
  if (!element) {
 
236
  if (!element && Type != eRandom && Type != eUrandom && Type != ePi) {
207
237
    cerr << fgred << highint << endl;
208
238
    cerr << "  No element was specified as an argument to the \"" << operation << "\" operation" << endl;
209
239
    cerr << "  This can happen when, for instance, a cos operation is specified and a " << endl;
224
254
          property_name = replace(property_name,"#",Prefix);
225
255
        }
226
256
      }
227
 
      FGPropertyManager* newNode = 0L;
 
257
      FGPropertyNode* newNode = 0L;
228
258
      if (PropertyManager->HasNode(property_name)) {
229
259
        newNode = PropertyManager->GetNode(property_name);
230
260
        Parameters.push_back(new FGPropertyValue( newNode ));
231
261
      } else {
232
 
        cerr << fgcyan << "Warning: The property " + property_name + " is initially undefined."
233
 
             << reset << endl;
 
262
        // cerr << fgcyan << "Warning: The property " + property_name + " is initially undefined."
 
263
        //      << reset << endl;
234
264
        Parameters.push_back(new FGPropertyValue( property_name,
235
265
                                                  PropertyManager ));
236
266
      }
244
274
               operation == sum_string ||
245
275
               operation == quotient_string ||
246
276
               operation == pow_string ||
 
277
               operation == sqrt_string ||
 
278
               operation == toradians_string ||
 
279
               operation == todegrees_string ||
247
280
               operation == exp_string ||
248
281
               operation == log2_string ||
249
282
               operation == ln_string ||
263
296
               operation == integer_string ||
264
297
               operation == mod_string ||
265
298
               operation == random_string ||
 
299
               operation == urandom_string ||
 
300
               operation == pi_string ||
266
301
               operation == avg_string ||
267
302
               operation == rotation_alpha_local_string||
268
303
               operation == rotation_beta_local_string||
279
314
               operation == or_string ||
280
315
               operation == not_string ||
281
316
               operation == ifthen_string ||
282
 
               operation == switch_string)
 
317
               operation == switch_string ||
 
318
               operation == interpolate1d_string)
283
319
    {
284
320
      Parameters.push_back(new FGFunction(PropertyManager, element, Prefix));
285
321
    } else if (operation != description_string) {
334
370
 
335
371
  if (cached) return cachedValue;
336
372
 
337
 
  temp = Parameters[0]->GetValue();
 
373
  if (   Type != eRandom
 
374
      && Type != eUrandom
 
375
      && Type != ePi      ) temp = Parameters[0]->GetValue();
338
376
  
339
377
  switch (Type) {
340
378
  case eTopLevel:
 
379
    if (pCopyTo) pCopyTo->setDoubleValue(temp);
341
380
    break;
342
381
  case eProduct:
343
382
    for (i=1;i<Parameters.size();i++) {
363
402
  case ePow:
364
403
    temp = pow(temp,Parameters[1]->GetValue());
365
404
    break;
 
405
  case eSqrt:
 
406
    temp = sqrt(temp);
 
407
    break;
 
408
  case eToRadians:
 
409
    temp *= M_PI/180.0;
 
410
    break;
 
411
  case eToDegrees:
 
412
    temp *= 180.0/M_PI;
 
413
    break;
366
414
  case eExp:
367
415
    temp = exp(temp);
368
416
    break;
434
482
  case eRandom:
435
483
    temp = GaussianRandomNumber();
436
484
    break;
 
485
  case eUrandom:
 
486
    temp = -1.0 + (((double)rand()/double(RAND_MAX))*2.0);
 
487
    break;
 
488
  case ePi:
 
489
    temp = M_PI;
 
490
    break;
437
491
  case eLT:
438
492
    temp = (temp < Parameters[1]->GetValue())?1:0;
439
493
    break;
499
553
      }
500
554
    }
501
555
    break;
 
556
  case eInterpolate1D:
 
557
    {
 
558
      unsigned int sz = Parameters.size();
 
559
      if (temp <= Parameters[1]->GetValue()) {
 
560
        temp = Parameters[2]->GetValue();
 
561
      } else if (temp >= Parameters[sz-2]->GetValue()) {
 
562
        temp = Parameters[sz-1]->GetValue();
 
563
      } else {
 
564
        for (unsigned int i=1; i<=sz-4; i+=2) {
 
565
          if (temp < Parameters[i+2]->GetValue()) {
 
566
            double factor = (temp - Parameters[i]->GetValue()) /
 
567
                            (Parameters[i+2]->GetValue() - Parameters[i]->GetValue());
 
568
            double span = Parameters[i+3]->GetValue() - Parameters[i+1]->GetValue();
 
569
            double val = factor*span;
 
570
            temp = Parameters[i+1]->GetValue() + val;
 
571
            break;
 
572
          }
 
573
        }
 
574
      }
 
575
    }
 
576
    break;
502
577
  case eRotation_alpha_local:
503
578
    if (Parameters.size()==6) // calculates local angle of attack for skydiver body component
504
579
        //Euler angles from the intermediate body frame to the local body frame must be from a z-y-x axis rotation order
731
806
      }
732
807
    }
733
808
 
 
809
    if (PropertyManager->HasNode(tmp)) {
 
810
      FGPropertyNode* _property = PropertyManager->GetNode(tmp);
 
811
      if (_property->isTied()) {
 
812
      cout << "Property " << tmp << " has already been successfully bound (late)." << endl;
 
813
        throw("Failed to bind the property to an existing already tied node.");
 
814
      }
 
815
    }
734
816
    PropertyManager->Tie( tmp, this, &FGFunction::GetValue);
735
817
  }
736
818
}