MCPcopy Create free account
hub / github.com/JSBSim-Team/jsbsim / RunScript

Method RunScript

src/input_output/FGScript.cpp:393–556  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

391//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
392
393bool FGScript::RunScript(void)
394{
395 unsigned i, j;
396 unsigned event_ctr = 0;
397
398 double currentTime = FDMExec->GetSimTime();
399 double newSetValue = 0;
400
401 if (currentTime > EndTime) return false;
402
403 // Iterate over all events.
404 for (unsigned int ev_ctr=0; ev_ctr < Events.size(); ev_ctr++) {
405
406 struct event &thisEvent = Events[ev_ctr];
407
408 // Determine whether the set of conditional tests for this condition equate
409 // to true and should cause the event to execute. If the conditions evaluate
410 // to true, then the event is triggered. If the event is not persistent,
411 // then this trigger will remain set true. If the event is persistent, the
412 // trigger will reset to false when the condition evaluates to false.
413 if (thisEvent.Condition->Evaluate()) {
414 if (!thisEvent.Triggered) {
415
416 // The conditions are true, do the setting of the desired Event
417 // parameters
418 for (i=0; i<thisEvent.SetValue.size(); i++) {
419 if (thisEvent.SetParam[i] == 0L) { // Late bind property if necessary
420 if (PropertyManager->HasNode(thisEvent.SetParamName[i])) {
421 thisEvent.SetParam[i] = PropertyManager->GetNode(thisEvent.SetParamName[i]);
422 } else {
423 LogException err;
424 err << "No property, \"" << thisEvent.SetParamName[i] << "\" is defined.\n";
425 throw err;
426 }
427 }
428 thisEvent.OriginalValue[i] = thisEvent.SetParam[i]->getDoubleValue();
429 if (thisEvent.Functions[i] != 0) { // Parameter should be set to a function value
430 try {
431 thisEvent.SetValue[i] = thisEvent.Functions[i]->GetValue();
432 } catch (BaseException& e) {
433 LogException err;
434 err << "\nA problem occurred in the execution of the script. "
435 << e.what() << "\n";
436 throw err;
437 }
438 }
439 switch (thisEvent.Type[i]) {
440 case FG_VALUE:
441 case FG_BOOL:
442 thisEvent.newValue[i] = thisEvent.SetValue[i];
443 break;
444 case FG_DELTA:
445 thisEvent.newValue[i] = thisEvent.OriginalValue[i] + thisEvent.SetValue[i];
446 break;
447 default:
448 FGLogging log(LogLevel::WARN);
449 log << "Invalid Type specified\n";
450 break;

Callers 1

RunMethod · 0.80

Calls 9

sizeMethod · 0.80
EvaluateMethod · 0.80
GetNodeMethod · 0.80
getDoubleValueMethod · 0.80
setDoubleValueMethod · 0.80
emptyMethod · 0.80
GetPropagateMethod · 0.80
GetValueMethod · 0.45
whatMethod · 0.45

Tested by

no test coverage detected