Ignore:
Timestamp:
2020-06-12T14:35:32+02:00 (4 years ago)
Author:
Adeel Asghar <adeel.asghar@…>
Parents:
327c277
git-author:
Adeel Asghar <adeel.asghar@…> (05/29/20 14:56:19)
git-committer:
Adeel Asghar <adeel.asghar@…> (06/12/20 14:35:32)
Message:

Snapshot based redo undo functionality for OMSimulator models

Create new OMSimulator models by right clicking in the Libraries Browser
Improved the addsubmodel dialog. Let user first select the file and then propose name from filename.
Fixes ticket:5789
Fixes ticket:5984
Disable the text view if its not allowed to edit.
Tabs should be preserved when accepting text changes.
The open nodes of the tree view in the libraries browser should be preserved when accepting text changes.

Handle deletion of multiple components.
Convert dots to underscores in submodel name.
Set background-color to show the read-only ssp editor as disbaled.
Renamed OMSimulator menu item to SSP.
Use the same GUI buttons for simulation.
Separated instantiation from simulation setup.
Disable the changes once the model is in instantiated state.
Get rid of OMSSimulationOptions.h InstantiateDialog.h/.cpp
Accept text changes when user clicks in the libraries browser.
Open directly the file browser when adding a submodel.
Use just one setting for working directory.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • OMEdit/OMEditLIB/OMS/OMSSimulationOutputWidget.cpp

    rcc6e3e8 r7094b7c  
    3838#include "OMSProxy.h"
    3939#include "Modeling/LibraryTreeWidget.h"
     40#include "Options/OptionsDialog.h"
    4041
    4142#include <QGridLayout>
    4243#include <QtCore/qmath.h>
    4344
    44 OMSSimulationOutputWidget::OMSSimulationOutputWidget(OMSSimulationOptions omsSimulationOptions, QWidget *pParent)
    45   : mOMSSimulationOptions(omsSimulationOptions)
     45OMSSimulationOutputWidget::OMSSimulationOutputWidget(const QString &cref, QWidget *pParent)
     46  : QWidget(pParent), mCref(cref)
    4647{
    47   Q_UNUSED(pParent);
    48   setWindowTitle(QString("%1 - %2 - %3").arg(Helper::applicationName)
    49                  .arg(mOMSSimulationOptions.getModelName()).arg(Helper::simulationOutput));
     48  setWindowTitle(QString("%1 - %2 - %3").arg(Helper::applicationName, mCref, Helper::simulationOutput));
    5049  resize(640, 120);
    5150  // simulation widget heading
    52   mpSimulationHeading = Utilities::getHeadingLabel(QString("%1 - %2")
    53                                                    .arg(tr("OMSimulator Simulation"), mOMSSimulationOptions.getModelName()));
     51  mpSimulationHeading = Utilities::getHeadingLabel(QString("%1 - %2").arg(tr("OMSimulator Simulation"), mCref));
    5452  mpSimulationHeading->setElideMode(Qt::ElideMiddle);
    5553  // Horizontal separator
    5654  mpHorizontalLine = Utilities::getHeadingLine();
    5755  // progress label
    58   mpProgressLabel = new Label(tr("Running simulation of <b>%1</b>. Please wait for a while.").arg(mOMSSimulationOptions.getModelName()));
     56  mpProgressLabel = new Label(tr("Running simulation of <b>%1</b>. Please wait for a while.").arg(mCref));
    5957  mpProgressLabel->setTextFormat(Qt::RichText);
    6058  mpCancelSimulationButton = new QPushButton(Helper::cancelSimulation);
     
    7573  pMainLayout->addWidget(mpCancelSimulationButton, 3, 1);
    7674  setLayout(pMainLayout);
     75  // save the model start time
     76  OMSProxy::instance()->getStartTime(mCref, &mStartTime);
     77  // save the model stop time
     78  OMSProxy::instance()->getStopTime(mCref, &mStopTime);
    7779  // create the ArchivedSimulationItem
    78   mpArchivedOMSSimulationItem = new ArchivedOMSSimulationItem(mOMSSimulationOptions, this);
     80  mpArchivedOMSSimulationItem = new ArchivedOMSSimulationItem(mCref, mStartTime, mStopTime, this);
    7981  MainWindow::instance()->getOMSSimulationDialog()->getArchivedSimulationsTreeWidget()->addTopLevelItem(mpArchivedOMSSimulationItem);
    8082  // save the last modified datetime of result file.
    81   QFileInfo resultFileInfo(mOMSSimulationOptions.getWorkingDirectory() + "/" + mOMSSimulationOptions.getResultFileName());
     83  char *fileName = (char*)"";
     84  int bufferSize;
     85  OMSProxy::instance()->getResultFile(mCref, &fileName, &bufferSize);
     86  mResultFilePath = QString("%1/%2").arg(OptionsDialog::instance()->getGeneralSettingsPage()->getWorkingDirectory(), QString(fileName));
     87  QFileInfo resultFileInfo(mResultFilePath);
    8288  if (resultFileInfo.exists()) {
    8389    mResultFileLastModifiedDateTime = resultFileInfo.lastModified();
     
    8793  mIsSimulationRunning = false;
    8894  // initialize the model
    89   if (OMSProxy::instance()->initialize(mOMSSimulationOptions.getModelName())) {
     95  if (OMSProxy::instance()->initialize(mCref)) {
    9096    // start the asynchronous simulation
    9197    qRegisterMetaType<oms_status_enu_t>("oms_status_enu_t");
    9298    connect(this, SIGNAL(sendSimulationProgress(QString,double,oms_status_enu_t)), SLOT(simulationProgress(QString,double,oms_status_enu_t)));
    93     if (OMSProxy::instance()->simulate_asynchronous(mOMSSimulationOptions.getModelName())) {
     99    if (OMSProxy::instance()->simulate_asynchronous(mCref)) {
    94100      mIsSimulationRunning = true;
    95101      mpCancelSimulationButton->setEnabled(true);
    96102    } else {
    97       mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is failed. %2")
    98                                .arg(mOMSSimulationOptions.getModelName())
    99                                .arg(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER)));
     103      mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is failed. %2").arg(mCref).arg(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER)));
    100104      mpProgressBar->setValue(mpProgressBar->maximum());
    101105      mpArchivedOMSSimulationItem->setStatus(tr("Simulation failed!"));
     
    103107  } else {
    104108    LibraryTreeItem *pLibraryTreeItem;
    105     pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(mOMSSimulationOptions.getModelName());
     109    pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItemOneLevel(mCref);
    106110    if (pLibraryTreeItem) {
    107111      MainWindow::instance()->instantiateOMSModel(pLibraryTreeItem, false);
    108112    }
    109     mpProgressLabel->setText(tr("Initialization using the <b>%1</b> model is failed. %2")
    110                              .arg(mOMSSimulationOptions.getModelName())
    111                              .arg(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER)));
     113    mpProgressLabel->setText(tr("Initialization using the <b>%1</b> model is failed. %2").arg(mCref).arg(GUIMessages::getMessage(GUIMessages::CHECK_MESSAGES_BROWSER)));
    112114    mpProgressBar->setValue(mpProgressBar->maximum());
    113115    mpArchivedOMSSimulationItem->setStatus(tr("Initialization failed!"));
     
    136138{
    137139  // cancel the simulation
    138   if (OMSProxy::instance()->cancelSimulation_asynchronous(mOMSSimulationOptions.getModelName())) {
     140  if (OMSProxy::instance()->cancelSimulation_asynchronous(mCref)) {
    139141    LibraryTreeItem *pLibraryTreeItem;
    140     pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem(mOMSSimulationOptions.getModelName());
     142    pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItemOneLevel(mCref);
    141143    if (pLibraryTreeItem) {
    142144      MainWindow::instance()->instantiateOMSModel(pLibraryTreeItem, false);
    143145    }
    144     mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is cancelled.").arg(mOMSSimulationOptions.getModelName()));
     146    mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is cancelled.").arg(mCref));
    145147    mpProgressBar->setValue(mpProgressBar->maximum());
    146148    mIsSimulationRunning = false;
     
    160162{
    161163  if (status < oms_status_warning) {
    162     int progress = (time * 100) / mOMSSimulationOptions.getStopTime();
     164    int progress = (time * 100) / mStopTime;
    163165    mpProgressBar->setValue(progress);
    164     if (time >= mOMSSimulationOptions.getStopTime()) {
    165       mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is finished.").arg(mOMSSimulationOptions.getModelName()));
     166    if (time >= mStopTime) {
     167      mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is finished.").arg(mCref));
    166168      mpProgressBar->setValue(mpProgressBar->maximum());
    167169      mIsSimulationRunning = false;
     
    175177      }
    176178      // simulation finished show the results
    177       MainWindow::instance()->getOMSSimulationDialog()->simulationFinished(mOMSSimulationOptions, mResultFileLastModifiedDateTime);
     179      MainWindow::instance()->getOMSSimulationDialog()->simulationFinished(mResultFilePath, mResultFileLastModifiedDateTime);
    178180    }
    179181  }
Note: See TracChangeset for help on using the changeset viewer.