369
378
// Iterate over all events.
370
379
for (unsigned int ev_ctr=0; ev_ctr < Events.size(); ev_ctr++) {
381
struct event &thisEvent = Events[ev_ctr];
371
383
// Determine whether the set of conditional tests for this condition equate
372
384
// to true and should cause the event to execute. If the conditions evaluate
373
385
// to true, then the event is triggered. If the event is not persistent,
374
386
// then this trigger will remain set true. If the event is persistent,
375
387
// the trigger will reset to false when the condition evaluates to false.
376
if (Events[ev_ctr].Condition->Evaluate()) {
377
if (!Events[ev_ctr].Triggered) {
388
if (thisEvent.Condition->Evaluate()) {
389
if (!thisEvent.Triggered) {
379
391
// The conditions are true, do the setting of the desired Event parameters
380
for (i=0; i<Events[ev_ctr].SetValue.size(); i++) {
381
Events[ev_ctr].OriginalValue[i] = Events[ev_ctr].SetParam[i]->getDoubleValue();
382
if (Events[ev_ctr].Functions[i] != 0) { // Parameter should be set to a function value
392
for (i=0; i<thisEvent.SetValue.size(); i++) {
393
if (thisEvent.SetParam[i] == 0L) { // Late bind property if necessary
394
if (PropertyManager->HasNode(thisEvent.SetParamName[i])) {
395
thisEvent.SetParam[i] = PropertyManager->GetNode(thisEvent.SetParamName[i]);
397
throw("No property, \""+thisEvent.SetParamName[i]+"\" is defined.");
400
thisEvent.OriginalValue[i] = thisEvent.SetParam[i]->getDoubleValue();
401
if (thisEvent.Functions[i] != 0) { // Parameter should be set to a function value
384
Events[ev_ctr].SetValue[i] = Events[ev_ctr].Functions[i]->GetValue();
403
thisEvent.SetValue[i] = thisEvent.Functions[i]->GetValue();
385
404
} catch (string msg) {
386
405
std::cerr << std::endl << "A problem occurred in the execution of the script. " << msg << endl;
390
switch (Events[ev_ctr].Type[i]) {
409
switch (thisEvent.Type[i]) {
393
Events[ev_ctr].newValue[i] = Events[ev_ctr].SetValue[i];
412
thisEvent.newValue[i] = thisEvent.SetValue[i];
396
Events[ev_ctr].newValue[i] = Events[ev_ctr].OriginalValue[i] + Events[ev_ctr].SetValue[i];
415
thisEvent.newValue[i] = thisEvent.OriginalValue[i] + thisEvent.SetValue[i];
399
418
cerr << "Invalid Type specified" << endl;
402
Events[ev_ctr].StartTime = currentTime + Events[ev_ctr].Delay;
403
Events[ev_ctr].ValueSpan[i] = Events[ev_ctr].newValue[i] - Events[ev_ctr].OriginalValue[i];
404
Events[ev_ctr].Transiting[i] = true;
421
thisEvent.StartTime = currentTime + thisEvent.Delay;
422
thisEvent.ValueSpan[i] = thisEvent.newValue[i] - thisEvent.OriginalValue[i];
423
thisEvent.Transiting[i] = true;
407
Events[ev_ctr].Triggered = true;
426
thisEvent.Triggered = true;
409
} else if (Events[ev_ctr].Persistent) { // If the event is persistent, reset the trigger.
410
Events[ev_ctr].Triggered = false; // Reset the trigger for persistent events
411
Events[ev_ctr].Notified = false; // Also reset the notification flag
412
} else if (Events[ev_ctr].Continuous) { // If the event is continuous, reset the trigger.
413
Events[ev_ctr].Triggered = false; // Reset the trigger for persistent events
414
Events[ev_ctr].Notified = false; // Also reset the notification flag
428
} else if (thisEvent.Persistent) { // If the event is persistent, reset the trigger.
429
thisEvent.Triggered = false; // Reset the trigger for persistent events
430
thisEvent.Notified = false; // Also reset the notification flag
431
} else if (thisEvent.Continuous) { // If the event is continuous, reset the trigger.
432
thisEvent.Triggered = false; // Reset the trigger for persistent events
433
thisEvent.Notified = false; // Also reset the notification flag
417
if ((currentTime >= Events[ev_ctr].StartTime) && Events[ev_ctr].Triggered) {
436
if ((currentTime >= thisEvent.StartTime) && thisEvent.Triggered) {
419
for (i=0; i<Events[ev_ctr].SetValue.size(); i++) {
420
if (Events[ev_ctr].Transiting[i]) {
421
Events[ev_ctr].TimeSpan = currentTime - Events[ev_ctr].StartTime;
422
switch (Events[ev_ctr].Action[i]) {
438
for (i=0; i<thisEvent.SetValue.size(); i++) {
439
if (thisEvent.Transiting[i]) {
440
thisEvent.TimeSpan = currentTime - thisEvent.StartTime;
441
switch (thisEvent.Action[i]) {
424
if (Events[ev_ctr].TimeSpan <= Events[ev_ctr].TC[i]) {
425
newSetValue = Events[ev_ctr].TimeSpan/Events[ev_ctr].TC[i] * Events[ev_ctr].ValueSpan[i] + Events[ev_ctr].OriginalValue[i];
443
if (thisEvent.TimeSpan <= thisEvent.TC[i]) {
444
newSetValue = thisEvent.TimeSpan/thisEvent.TC[i] * thisEvent.ValueSpan[i] + thisEvent.OriginalValue[i];
427
newSetValue = Events[ev_ctr].newValue[i];
428
if (Events[ev_ctr].Continuous != true) Events[ev_ctr].Transiting[i] = false;
446
newSetValue = thisEvent.newValue[i];
447
if (thisEvent.Continuous != true) thisEvent.Transiting[i] = false;
432
newSetValue = Events[ev_ctr].newValue[i];
451
newSetValue = thisEvent.newValue[i];
434
453
// If this is not a continuous event, reset the transiting flag.
435
454
// Otherwise, it is known that the event is a continuous event.
436
455
// Furthermore, if the event is to be determined by a function,
437
456
// then the function will be continuously calculated.
438
if (Events[ev_ctr].Continuous != true)
439
Events[ev_ctr].Transiting[i] = false;
440
else if (Events[ev_ctr].Functions[i] != 0)
441
newSetValue = Events[ev_ctr].Functions[i]->GetValue();
457
if (thisEvent.Continuous != true)
458
thisEvent.Transiting[i] = false;
459
else if (thisEvent.Functions[i] != 0)
460
newSetValue = thisEvent.Functions[i]->GetValue();
445
newSetValue = (1 - exp( -Events[ev_ctr].TimeSpan/Events[ev_ctr].TC[i] )) * Events[ev_ctr].ValueSpan[i] + Events[ev_ctr].OriginalValue[i];
464
newSetValue = (1 - exp( -thisEvent.TimeSpan/thisEvent.TC[i] )) * thisEvent.ValueSpan[i] + thisEvent.OriginalValue[i];
448
467
cerr << "Invalid Action specified" << endl;
451
Events[ev_ctr].SetParam[i]->setDoubleValue(newSetValue);
470
thisEvent.SetParam[i]->setDoubleValue(newSetValue);
455
474
// Print notification values after setting them
456
if (Events[ev_ctr].Notify && !Events[ev_ctr].Notified) {
457
cout << endl << " Event " << event_ctr << " (" << Events[ev_ctr].Name << ")"
458
<< " executed at time: " << currentTime << endl;
459
if (!Events[ev_ctr].Description.empty()) {
460
cout << " " << Events[ev_ctr].Description << endl;
462
for (j=0; j<Events[ev_ctr].NotifyProperties.size();j++) {
463
// cout << " " << Events[ev_ctr].NotifyProperties[j]->GetRelativeName()
464
cout << " " << Events[ev_ctr].DisplayString[j]
465
<< " = " << Events[ev_ctr].NotifyProperties[j]->getDoubleValue() << endl;
475
if (thisEvent.Notify && !thisEvent.Notified) {
476
if (thisEvent.NotifyKML) {
477
cout << endl << "<Placemark>" << endl;
478
cout << " <name> " << currentTime << " seconds" << " </name>" << endl;
479
cout << " <description>" << endl;
480
cout << " <![CDATA[" << endl;
481
cout << " <b>" << thisEvent.Name << " (Event " << event_ctr << ")" << " executed at time: " << currentTime << "</b><br/>" << endl;
483
cout << endl << underon
484
<< highint << thisEvent.Name << normint << underoff
485
<< " (Event " << event_ctr << ")"
486
<< " executed at time: " << highint << currentTime << normint << endl;
488
if (!thisEvent.Description.empty()) {
489
cout << " " << thisEvent.Description << endl;
491
for (j=0; j<thisEvent.NotifyProperties.size();j++) {
492
if (thisEvent.NotifyProperties[j] == 0) {
493
if (PropertyManager->HasNode(thisEvent.NotifyPropertyNames[j])) {
494
thisEvent.NotifyProperties[j] = PropertyManager->GetNode(thisEvent.NotifyPropertyNames[j]);
496
throw("Could not find property named "+thisEvent.NotifyPropertyNames[j]+" in script.");
499
cout << " " << thisEvent.DisplayString[j] << " = " << thisEvent.NotifyProperties[j]->getDoubleValue();
500
if (thisEvent.NotifyKML) cout << " <br/>";
503
if (thisEvent.NotifyKML) {
504
cout << " ]]>" << endl;
505
cout << " </description>" << endl;
506
cout << " <Point>" << endl;
507
cout << " <altitudeMode> absolute </altitudeMode>" << endl;
508
cout << " <extrude> 1 </extrude>" << endl;
509
cout << " <coordinates>" << FDMExec->GetPropagate()->GetLongitudeDeg()
510
<< "," << FDMExec->GetPropagate()->GetGeodLatitudeDeg()
511
<< "," << FDMExec->GetPropagate()->GetAltitudeASLmeters() << "</coordinates>" << endl;
512
cout << " </Point>" << endl;
513
cout << "</Placemark>" << endl;
468
Events[ev_ctr].Notified = true;
516
thisEvent.Notified = true;