Changeset 7094b7c in OpenModelica for OMEdit/OMEditLIB/OMS/OMSSimulationOutputWidget.cpp
- Timestamp:
- 2020-06-12T14:35:32+02:00 (4 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
OMEdit/OMEditLIB/OMS/OMSSimulationOutputWidget.cpp
rcc6e3e8 r7094b7c 38 38 #include "OMSProxy.h" 39 39 #include "Modeling/LibraryTreeWidget.h" 40 #include "Options/OptionsDialog.h" 40 41 41 42 #include <QGridLayout> 42 43 #include <QtCore/qmath.h> 43 44 44 OMSSimulationOutputWidget::OMSSimulationOutputWidget( OMSSimulationOptions omsSimulationOptions, QWidget *pParent)45 : mOMSSimulationOptions(omsSimulationOptions)45 OMSSimulationOutputWidget::OMSSimulationOutputWidget(const QString &cref, QWidget *pParent) 46 : QWidget(pParent), mCref(cref) 46 47 { 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)); 50 49 resize(640, 120); 51 50 // 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)); 54 52 mpSimulationHeading->setElideMode(Qt::ElideMiddle); 55 53 // Horizontal separator 56 54 mpHorizontalLine = Utilities::getHeadingLine(); 57 55 // progress label 58 mpProgressLabel = new Label(tr("Running simulation of <b>%1</b>. Please wait for a while.").arg(m OMSSimulationOptions.getModelName()));56 mpProgressLabel = new Label(tr("Running simulation of <b>%1</b>. Please wait for a while.").arg(mCref)); 59 57 mpProgressLabel->setTextFormat(Qt::RichText); 60 58 mpCancelSimulationButton = new QPushButton(Helper::cancelSimulation); … … 75 73 pMainLayout->addWidget(mpCancelSimulationButton, 3, 1); 76 74 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); 77 79 // create the ArchivedSimulationItem 78 mpArchivedOMSSimulationItem = new ArchivedOMSSimulationItem(m OMSSimulationOptions, this);80 mpArchivedOMSSimulationItem = new ArchivedOMSSimulationItem(mCref, mStartTime, mStopTime, this); 79 81 MainWindow::instance()->getOMSSimulationDialog()->getArchivedSimulationsTreeWidget()->addTopLevelItem(mpArchivedOMSSimulationItem); 80 82 // 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); 82 88 if (resultFileInfo.exists()) { 83 89 mResultFileLastModifiedDateTime = resultFileInfo.lastModified(); … … 87 93 mIsSimulationRunning = false; 88 94 // initialize the model 89 if (OMSProxy::instance()->initialize(m OMSSimulationOptions.getModelName())) {95 if (OMSProxy::instance()->initialize(mCref)) { 90 96 // start the asynchronous simulation 91 97 qRegisterMetaType<oms_status_enu_t>("oms_status_enu_t"); 92 98 connect(this, SIGNAL(sendSimulationProgress(QString,double,oms_status_enu_t)), SLOT(simulationProgress(QString,double,oms_status_enu_t))); 93 if (OMSProxy::instance()->simulate_asynchronous(m OMSSimulationOptions.getModelName())) {99 if (OMSProxy::instance()->simulate_asynchronous(mCref)) { 94 100 mIsSimulationRunning = true; 95 101 mpCancelSimulationButton->setEnabled(true); 96 102 } 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))); 100 104 mpProgressBar->setValue(mpProgressBar->maximum()); 101 105 mpArchivedOMSSimulationItem->setStatus(tr("Simulation failed!")); … … 103 107 } else { 104 108 LibraryTreeItem *pLibraryTreeItem; 105 pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem (mOMSSimulationOptions.getModelName());109 pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItemOneLevel(mCref); 106 110 if (pLibraryTreeItem) { 107 111 MainWindow::instance()->instantiateOMSModel(pLibraryTreeItem, false); 108 112 } 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))); 112 114 mpProgressBar->setValue(mpProgressBar->maximum()); 113 115 mpArchivedOMSSimulationItem->setStatus(tr("Initialization failed!")); … … 136 138 { 137 139 // cancel the simulation 138 if (OMSProxy::instance()->cancelSimulation_asynchronous(m OMSSimulationOptions.getModelName())) {140 if (OMSProxy::instance()->cancelSimulation_asynchronous(mCref)) { 139 141 LibraryTreeItem *pLibraryTreeItem; 140 pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItem (mOMSSimulationOptions.getModelName());142 pLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->findLibraryTreeItemOneLevel(mCref); 141 143 if (pLibraryTreeItem) { 142 144 MainWindow::instance()->instantiateOMSModel(pLibraryTreeItem, false); 143 145 } 144 mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is cancelled.").arg(m OMSSimulationOptions.getModelName()));146 mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is cancelled.").arg(mCref)); 145 147 mpProgressBar->setValue(mpProgressBar->maximum()); 146 148 mIsSimulationRunning = false; … … 160 162 { 161 163 if (status < oms_status_warning) { 162 int progress = (time * 100) / m OMSSimulationOptions.getStopTime();164 int progress = (time * 100) / mStopTime; 163 165 mpProgressBar->setValue(progress); 164 if (time >= m OMSSimulationOptions.getStopTime()) {165 mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is finished.").arg(m OMSSimulationOptions.getModelName()));166 if (time >= mStopTime) { 167 mpProgressLabel->setText(tr("Simulation using the <b>%1</b> model is finished.").arg(mCref)); 166 168 mpProgressBar->setValue(mpProgressBar->maximum()); 167 169 mIsSimulationRunning = false; … … 175 177 } 176 178 // simulation finished show the results 177 MainWindow::instance()->getOMSSimulationDialog()->simulationFinished(m OMSSimulationOptions, mResultFileLastModifiedDateTime);179 MainWindow::instance()->getOMSSimulationDialog()->simulationFinished(mResultFilePath, mResultFileLastModifiedDateTime); 178 180 } 179 181 }
Note: See TracChangeset
for help on using the changeset viewer.