Beispiel #1
0
int controls_evaluate(DateTime currentTime, DateTime elapsedTime, double tStep)
//
//  Input:   currentTime = current simulation date/time
//           elapsedTime = decimal days since start of simulation
//           tStep = simulation time step (days)                               //(5.0.013 - LR)
//  Output:  returns number of new actions taken
//  Purpose: evaluates all control rules at current time of the simulation.
//
{
    int    r;                          // control rule index
    int    result;                     // TRUE if rule premises satisfied
    struct TPremise* p;                // pointer to rule premise clause
    struct TAction*  a;                // pointer to rule action clause
    DateTime theDate = floor(currentTime);
    DateTime theTime = currentTime - floor(currentTime);

    // --- evaluate each rule
    if ( RuleCount == 0 ) return 0;
    clearActionList();
    for (r=0; r<RuleCount; r++)
    {
        // --- evaluate rule's premises
        result = TRUE;
        p = Rules[r].firstPremise;
        while (p)
        {
            if ( p->type == r_OR )
            {
                if ( result == FALSE )
                    result = evaluatePremise(p, theDate, theTime,
                                 elapsedTime, tStep);
            }
            else
            {
                if ( result == FALSE ) break;
                result = evaluatePremise(p, theDate, theTime, 
                             elapsedTime, tStep);
            }
            p = p->next;
        }    

        // --- if premises true, add THEN clauses to action list
        //     else add ELSE clauses to action list
        if ( result == TRUE ) a = Rules[r].thenActions;
        else                  a = Rules[r].elseActions;
        while (a)
        {
            updateActionValue(a, currentTime, tStep);                          //(5.0.012 - LR)
            updateActionList(a);
            a = a->next;
        }
    }

    // --- execute actions on action list
    if ( ActionList ) return executeActionList(currentTime);
    else return 0;
}
Beispiel #2
0
/**
 * @brief Constructor
 *
 * This is the constructor of the main-UI class - the Simon View class.
 * It displays a little splash screen and initializes the member-variables
 *
 * @author Peter Grasch
 * @param Qwidget *parent
 * The parent which is passed on to the QMainWindow initialization - Default: 0
 * @param Qt::WFlags flags
 * The flags which are also passed on to the QMainWindow constructor - as before: Default: 0
 *
 */
SimonView::SimonView(QWidget* parent, Qt::WFlags flags)
: KXmlGuiWindow(parent, flags), ScenarioDisplay(),
  backButtonAnimation(new QTimeLine(700, this))
{
  Logger::log ( i18n ( "Starting Simon..." ) );

  //showing splash
  bool showSplash = KCmdLineArgs::parsedArgs()->isSet("splash");
  SimonInfo *info = 0;

  if (showSplash) {
    info = new SimonInfo();
    Logger::log ( i18n ( "Displaying Splashscreen..." ) );
    info->showSplash();
    info->writeToSplash ( i18n ( "Loading core..." ) );
  }

  KGlobal::locale()->insertCatalog("simonlib");

  control = (new SimonControl(this));

  if (!control->firstRunWizardCompleted()) {
    QPointer<FirstRunWizard> firstRun = new FirstRunWizard(this);
    bool firstRunWizardCompleted = firstRun->exec();
    delete firstRun;

    if (firstRunWizardCompleted || KMessageBox::questionYesNo(this, i18n("You did not complete the initial configuration. Simon will continue with default values.\n\nDo you want Simon to display the wizard again on the next start?"))==KMessageBox::No)
      control->setFirstRunWizardCompleted(true);
  }

  trayManager = new TrayIconManager(this);

  this->trayManager->createIcon ( KIcon ( KIconLoader().loadIcon("simon", KIconLoader::Panel, KIconLoader::SizeMedium, KIconLoader::DisabledState) ), i18n ( "Simon - Deactivated" ) );

  QMainWindow ( parent,flags );
  qApp->setQuitOnLastWindowClosed(false);
  ui.setupUi ( this );
  
  statusBar()->insertItem(i18n("Not connected"),0);
  statusBar()->insertItem("",1,10);
  statusBar()->insertPermanentWidget(2,StatusManager::global(this)->createWidget(this));

  ScenarioManager::getInstance()->registerScenarioDisplay(this);
  ScenarioManager::getInstance()->installScenarioOfferUi(this);
  
  //Preloads all Dialogs
  if (showSplash)
    info->writeToSplash ( i18n ( "Loading training..." ) );
  trainDialog = new TrainingView(this);
  ScenarioManager::getInstance()->registerScenarioDisplay(trainDialog);

  if (showSplash)
    info->writeToSplash ( i18n ( "Loading vocabulary..." ) );
  vocabularyView = new VocabularyView(this);
  ScenarioManager::getInstance()->registerScenarioDisplay(vocabularyView);

  if (showSplash)
    info->writeToSplash ( i18n ( "Loading grammar..." ) );
  grammarView = new GrammarView(this);
  ScenarioManager::getInstance()->registerScenarioDisplay(grammarView);

  if (showSplash)
    info->writeToSplash ( i18n ( "Loading context..." ) );
  contextDialog = new ContextView(this);
  ScenarioManager::getInstance()->registerScenarioDisplay(contextDialog);

  if (showSplash)
    info->writeToSplash ( i18n ( "Loading run..." ) );
  runDialog = new RunCommandView(this);
  connect(runDialog, SIGNAL(actionsChanged()), this, SLOT(updateActionList()));
  ScenarioManager::getInstance()->registerScenarioDisplay(runDialog);

  if (showSplash)
    info->writeToSplash ( i18n ( "Loading interface..." ) );

  setupActions();

  setupGUI();
  displayScenarioPrivate(ScenarioManager::getInstance()->getCurrentScenario());
  
  welcomePage = new WelcomePage(actionCollection()->action("activate"));
  ScenarioManager::getInstance()->registerScenarioDisplay(welcomePage);
  connect(welcomePage, SIGNAL(editScenario()), this, SLOT(editScenario()));
  
  ui.swMain->insertWidget(0, welcomePage);
  ui.swMain->setCurrentIndex(0);
  
  ui.inlineView->registerPage(vocabularyView);
  ui.inlineView->registerPage(trainDialog);
  ui.inlineView->registerPage(grammarView);
  ui.inlineView->registerPage(contextDialog);
  ui.inlineView->registerPage(runDialog);
  
  ui.frmBackToOverview->setMaximumHeight(0);
  connect(backButtonAnimation, SIGNAL(frameChanged(int)), this, SLOT(backButtonAnimationStep(int)));
  {
    QPalette p = ui.frmBackToOverview->palette();
    p.setBrush(QPalette::Window, p.alternateBase());
    ui.frmBackToOverview->setPalette(p);
  }
  
  connect(ui.pbBackToOverview, SIGNAL(clicked()), this, SLOT(backToOverview()));
  
  setupSignalSlots();
  control->startup();

  //hiding splash again after loading
  if (showSplash) {
    info->hideSplash();
    delete info;
  }

  if (!control->startMinimized()) {
    show();
#ifdef Q_OS_MAC
    raise();
#endif
  }
}
Beispiel #3
0
void SimonView::displayScenarioPrivate(Scenario *scenario)
{
  Q_UNUSED(scenario);
  updateActionList();
}