Changeset 7094b7c in OpenModelica for OMEdit/OMEditLIB/OMS/OMSSimulationDialog.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/OMSSimulationDialog.cpp
rcc6e3e8 r7094b7c 35 35 #include "MainWindow.h" 36 36 #include "Util/Helper.h" 37 #include "SystemSimulationInformationDialog.h" 37 38 #include "Modeling/LibraryTreeWidget.h" 38 39 #include "Modeling/ItemDelegate.h" 39 40 #include "OMSSimulationOutputWidget.h" 40 #include " Options/OptionsDialog.h"41 #include "Modeling/ModelWidgetContainer.h" 41 42 #include "Plotting/VariablesWidget.h" 42 43 … … 56 57 : QDialog(pParent) 57 58 { 58 setWindowTitle(QString("%1 - %2").arg(Helper::applicationName, Helper::archivedSimulations));59 59 // heading 60 mpSimulationHeading = Utilities::getHeadingLabel( Helper::archivedSimulations);60 mpSimulationHeading = Utilities::getHeadingLabel(QString("%1 - %2").arg(Helper::simulationSetup, mModelCref)); 61 61 mpSimulationHeading->setElideMode(Qt::ElideMiddle); 62 62 // Horizontal separator 63 63 mpHorizontalLine = Utilities::getHeadingLine(); 64 // tab widget 65 QTabWidget *pTabWidget = new QTabWidget; 66 // General tab 67 QWidget *pGeneralWidget = new QWidget; 68 // system simulation information groupbox 69 mpSystemSimulationInformationWidget = 0; 70 mpSystemSimulationInformationGroupBox = new QGroupBox(Helper::systemSimulationInformation); 71 // start time 72 mpStartTimeLabel = new Label(QString("%1:").arg(Helper::startTime)); 73 mpStartTimeTextBox = new QLineEdit; 74 // stop time 75 mpStopTimeLabel = new Label(QString("%1:").arg(Helper::stopTime)); 76 mpStopTimeTextBox = new QLineEdit; 77 // result file 78 mpResultFileLabel = new Label(tr("Result File:")); 79 mpResultFileTextBox = new QLineEdit; 80 // result file buffer size 81 mpResultFileBufferSizeLabel = new Label(tr("Result File Buffer Size:")); 82 mpResultFileBufferSizeSpinBox = new QSpinBox; 83 mpResultFileBufferSizeSpinBox->setRange(1, INT_MAX); 84 // logging interval 85 mpLoggingIntervalLabel = new Label(tr("Logging Interval:")); 86 mpLoggingIntervalTextBox = new QLineEdit("0"); 87 // signal filter 88 mpSignalFilterLabel = new Label(tr("Signal Filter:")); 89 mpSignalFilterTextBox = new QLineEdit; 90 mpSignalFilterTextBox->setToolTip(tr("Leave empty to include all signals otherwise use a regex to filter.")); 91 // Add the validators 92 QDoubleValidator *pDoubleValidator = new QDoubleValidator(this); 93 mpStartTimeTextBox->setValidator(pDoubleValidator); 94 mpStopTimeTextBox->setValidator(pDoubleValidator); 95 // General tab widget layout 96 QGridLayout *pGeneralTabWidgetGridLayout = new QGridLayout; 97 pGeneralTabWidgetGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); 98 pGeneralTabWidgetGridLayout->addWidget(mpSystemSimulationInformationGroupBox, 1, 0, 1, 2); 99 pGeneralTabWidgetGridLayout->addWidget(mpStartTimeLabel, 2, 0); 100 pGeneralTabWidgetGridLayout->addWidget(mpStartTimeTextBox, 2, 1); 101 pGeneralTabWidgetGridLayout->addWidget(mpStopTimeLabel, 3, 0); 102 pGeneralTabWidgetGridLayout->addWidget(mpStopTimeTextBox, 3, 1); 103 pGeneralTabWidgetGridLayout->addWidget(mpResultFileLabel, 4, 0); 104 pGeneralTabWidgetGridLayout->addWidget(mpResultFileTextBox, 4, 1); 105 pGeneralTabWidgetGridLayout->addWidget(mpResultFileBufferSizeLabel, 5, 0); 106 pGeneralTabWidgetGridLayout->addWidget(mpResultFileBufferSizeSpinBox, 5, 1); 107 pGeneralTabWidgetGridLayout->addWidget(mpLoggingIntervalLabel, 6, 0); 108 pGeneralTabWidgetGridLayout->addWidget(mpLoggingIntervalTextBox, 6, 1); 109 pGeneralTabWidgetGridLayout->addWidget(mpSignalFilterLabel, 7, 0); 110 pGeneralTabWidgetGridLayout->addWidget(mpSignalFilterTextBox, 7, 1); 111 pGeneralWidget->setLayout(pGeneralTabWidgetGridLayout); 112 pTabWidget->addTab(pGeneralWidget, Helper::general); 113 // Archived simulation tab layout 114 QWidget *pArchivedSimulationsTab = new QWidget; 64 115 // archived simulation tree widget 65 116 mpArchivedSimulationsTreeWidget = new QTreeWidget; … … 72 123 mpArchivedSimulationsTreeWidget->setIndentation(0); 73 124 connect(mpArchivedSimulationsTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), SLOT(showArchivedSimulation(QTreeWidgetItem*))); 125 QGridLayout *pArchivedSimulationsTabGridLayout = new QGridLayout; 126 pArchivedSimulationsTabGridLayout->setAlignment(Qt::AlignTop); 127 pArchivedSimulationsTabGridLayout->addWidget(mpArchivedSimulationsTreeWidget, 0, 0); 128 pArchivedSimulationsTab->setLayout(pArchivedSimulationsTabGridLayout); 129 // add Archived simulations Tab to Simulation TabWidget 130 pTabWidget->addTab(pArchivedSimulationsTab, Helper::archivedSimulations); 74 131 // Create the buttons 75 132 mpOkButton = new QPushButton(Helper::ok); 76 133 mpOkButton->setAutoDefault(true); 77 connect(mpOkButton, SIGNAL(clicked()), this, SLOT( accept()));134 connect(mpOkButton, SIGNAL(clicked()), this, SLOT(saveSimulationSettings())); 78 135 mpCancelButton = new QPushButton(Helper::cancel); 79 136 mpCancelButton->setAutoDefault(false); … … 84 141 mpButtonBox->addButton(mpCancelButton, QDialogButtonBox::ActionRole); 85 142 // Create a layout 86 QGridLayout *pMain Layout = new QGridLayout;87 pMain Layout->setAlignment(Qt::AlignTop | Qt::AlignLeft);88 pMain Layout->addWidget(mpSimulationHeading, 0, 0);89 pMain Layout->addWidget(mpHorizontalLine, 1, 0);90 pMain Layout->addWidget(mpArchivedSimulationsTreeWidget, 2, 0);91 pMain Layout->addWidget(mpButtonBox, 3, 0);92 setLayout(pMain Layout);143 QGridLayout *pMainGridLayout = new QGridLayout; 144 pMainGridLayout->setAlignment(Qt::AlignTop | Qt::AlignLeft); 145 pMainGridLayout->addWidget(mpSimulationHeading, 0, 0); 146 pMainGridLayout->addWidget(mpHorizontalLine, 1, 0); 147 pMainGridLayout->addWidget(pTabWidget, 2, 0); 148 pMainGridLayout->addWidget(mpButtonBox, 3, 0); 149 setLayout(pMainGridLayout); 93 150 } 94 151 … … 103 160 } 104 161 mOMSSimulationOutputWidgetsList.clear(); 162 } 163 164 int OMSSimulationDialog::exec(const QString &modelCref, LibraryTreeItem *pLibraryTreeItem) 165 { 166 mModelCref = modelCref; 167 mpLibraryTreeItem = pLibraryTreeItem; 168 169 setWindowTitle(QString("%1 - %2 - %3").arg(Helper::applicationName, Helper::simulationSetup, mModelCref)); 170 mpSimulationHeading->setText(QString("%1 - %2").arg(Helper::simulationSetup, mModelCref)); 171 // initialize system simulation information 172 if (mpSystemSimulationInformationWidget) { 173 delete mpSystemSimulationInformationGroupBox->layout(); 174 delete mpSystemSimulationInformationWidget; 175 mpSystemSimulationInformationWidget = 0; 176 } 177 LibraryTreeItem *pTopLibraryTreeItem = MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->getTopLevelLibraryTreeItem(mpLibraryTreeItem); 178 LibraryTreeItem *pRootSystemLibraryTreeItem = 0; 179 if (pTopLibraryTreeItem && pTopLibraryTreeItem->childrenSize() > 0) { 180 pRootSystemLibraryTreeItem = pTopLibraryTreeItem->childAt(0); 181 if (pRootSystemLibraryTreeItem) { 182 if (!pRootSystemLibraryTreeItem->getModelWidget()) { 183 MainWindow::instance()->getLibraryWidget()->getLibraryTreeModel()->showModelWidget(pRootSystemLibraryTreeItem, false); 184 } 185 mpSystemSimulationInformationWidget = new SystemSimulationInformationWidget(pRootSystemLibraryTreeItem->getModelWidget()); 186 QHBoxLayout *pSystemSimulationInformationGroupBoxLayout = new QHBoxLayout; 187 pSystemSimulationInformationGroupBoxLayout->addWidget(mpSystemSimulationInformationWidget); 188 mpSystemSimulationInformationGroupBox->setLayout(pSystemSimulationInformationGroupBoxLayout); 189 } 190 } 191 // start time 192 double startTime; 193 OMSProxy::instance()->getStartTime(mModelCref, &startTime); 194 mpStartTimeTextBox->setText(QString::number(startTime)); 195 // stop time 196 double stopTime; 197 OMSProxy::instance()->getStopTime(mModelCref, &stopTime); 198 mpStopTimeTextBox->setText(QString::number(stopTime)); 199 // result file 200 char *fileName = (char*)""; 201 int bufferSize; 202 OMSProxy::instance()->getResultFile(mModelCref, &fileName, &bufferSize); 203 mpResultFileTextBox->setText(QString(fileName)); 204 // result file buffer size 205 mpResultFileBufferSizeSpinBox->setValue(bufferSize); 206 207 mpOkButton->setEnabled(!mpLibraryTreeItem->isSystemLibrary()); 208 209 return QDialog::exec(); 210 } 211 212 /*! 213 * \brief OMSSimulationDialog::simulate 214 * Simulates the OMSimulator model. 215 * \param pLibraryTreeItem 216 */ 217 void OMSSimulationDialog::simulate(LibraryTreeItem *pLibraryTreeItem) 218 { 219 OMSSimulationOutputWidget *pOMSSimulationOutputWidget = new OMSSimulationOutputWidget(pLibraryTreeItem->getNameStructure()); 220 mOMSSimulationOutputWidgetsList.append(pOMSSimulationOutputWidget); 221 int xPos = QApplication::desktop()->availableGeometry().width() - pOMSSimulationOutputWidget->frameSize().width() - 20; 222 int yPos = QApplication::desktop()->availableGeometry().height() - pOMSSimulationOutputWidget->frameSize().height() - 20; 223 pOMSSimulationOutputWidget->setGeometry(xPos, yPos, pOMSSimulationOutputWidget->width(), pOMSSimulationOutputWidget->height()); 224 pOMSSimulationOutputWidget->show(); 105 225 } 106 226 … … 109 229 * Called by OMSSimulationOutputWidget when the simulation is finished.\n 110 230 * Reads the result file and plots the result. 111 * \param omsSimulationOptions231 * \param resultFilePath 112 232 * \param resultFileLastModifiedDateTime 113 233 */ 114 void OMSSimulationDialog::simulationFinished( OMSSimulationOptions omsSimulationOptions, QDateTime resultFileLastModifiedDateTime)234 void OMSSimulationDialog::simulationFinished(const QString &resultFilePath, QDateTime resultFileLastModifiedDateTime) 115 235 { 116 236 // read the result file 117 QFileInfo resultFileInfo(omsSimulationOptions.getWorkingDirectory() + "/" + omsSimulationOptions.getResultFileName()); 118 if (resultFileInfo.exists() && resultFileLastModifiedDateTime <= resultFileInfo.lastModified()) { 119 VariablesWidget *pVariablesWidget = MainWindow::instance()->getVariablesWidget(); 120 OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy(); 121 QStringList list = pOMCProxy->readSimulationResultVars(resultFileInfo.absoluteFilePath()); 122 if (list.size() > 0) { 123 MainWindow::instance()->switchToPlottingPerspectiveSlot(); 124 pVariablesWidget->insertVariablesItemsToTree(resultFileInfo.fileName(), omsSimulationOptions.getWorkingDirectory(), 125 list, SimulationOptions()); 126 MainWindow::instance()->getVariablesDockWidget()->show(); 127 } 128 } 237 QFileInfo resultFileInfo(resultFilePath); 238 if (!resultFileInfo.exists() || resultFileLastModifiedDateTime > resultFileInfo.lastModified()) { 239 MessagesWidget::instance()->addGUIMessage(MessageItem(MessageItem::Modelica, tr("Unable to find the result file <b>%1</b>.").arg(resultFileInfo.absoluteFilePath()), 240 Helper::scriptingKind, Helper::errorLevel)); 241 return; 242 } 243 qDebug() << resultFilePath << resultFileLastModifiedDateTime << resultFileInfo.lastModified(); 244 VariablesWidget *pVariablesWidget = MainWindow::instance()->getVariablesWidget(); 245 OMCProxy *pOMCProxy = MainWindow::instance()->getOMCProxy(); 246 QStringList list = pOMCProxy->readSimulationResultVars(resultFileInfo.absoluteFilePath()); 247 MainWindow::instance()->switchToPlottingPerspectiveSlot(); 248 pVariablesWidget->insertVariablesItemsToTree(resultFileInfo.fileName(), resultFileInfo.absoluteDir().absolutePath(), list, SimulationOptions()); 249 MainWindow::instance()->getVariablesDockWidget()->show(); 129 250 } 130 251 … … 147 268 148 269 /*! 149 * \brief OMSSimulationDialog::simulate 150 * Simulates the OMSimulator model. 151 * \param pLibraryTreeItem 152 */ 153 void OMSSimulationDialog::simulate(LibraryTreeItem *pLibraryTreeItem) 154 { 155 OMSSimulationOutputWidget *pOMSSimulationOutputWidget = new OMSSimulationOutputWidget(pLibraryTreeItem->mOMSSimulationOptions); 156 mOMSSimulationOutputWidgetsList.append(pOMSSimulationOutputWidget); 157 int xPos = QApplication::desktop()->availableGeometry().width() - pOMSSimulationOutputWidget->frameSize().width() - 20; 158 int yPos = QApplication::desktop()->availableGeometry().height() - pOMSSimulationOutputWidget->frameSize().height() - 20; 159 pOMSSimulationOutputWidget->setGeometry(xPos, yPos, pOMSSimulationOutputWidget->width(), pOMSSimulationOutputWidget->height()); 160 pOMSSimulationOutputWidget->show(); 161 } 270 * \brief OMSSimulationDialog::saveSimulationSettings 271 * Saves the simulation settings. 272 */ 273 void OMSSimulationDialog::saveSimulationSettings() 274 { 275 if (mpStartTimeTextBox->text().isEmpty()) { 276 mpStartTimeTextBox->setText("0"); 277 } 278 if (mpStopTimeTextBox->text().isEmpty()) { 279 mpStopTimeTextBox->setText("1"); 280 } 281 if (mpStartTimeTextBox->text().toDouble() > mpStopTimeTextBox->text().toDouble()) { 282 QMessageBox::critical(MainWindow::instance(), QString("%1 - %2").arg(Helper::applicationName, Helper::error), 283 GUIMessages::getMessage(GUIMessages::SIMULATION_STARTTIME_LESSTHAN_STOPTIME), Helper::ok); 284 return; 285 } 286 287 if (mpSystemSimulationInformationWidget) { 288 mpSystemSimulationInformationWidget->setSystemSimulationInformation(false); 289 } 290 291 // set the simulation settings 292 OMSProxy::instance()->setStartTime(mModelCref, mpStartTimeTextBox->text().toDouble()); 293 OMSProxy::instance()->setStopTime(mModelCref, mpStopTimeTextBox->text().toDouble()); 294 OMSProxy::instance()->setResultFile(mModelCref, mpResultFileTextBox->text(), mpResultFileBufferSizeSpinBox->value()); 295 OMSProxy::instance()->setLoggingInterval(mModelCref, mpLoggingIntervalTextBox->text().toDouble()); 296 if (!mpSignalFilterTextBox->text().isEmpty()) { 297 OMSProxy::instance()->setSignalFilter(mModelCref, mpSignalFilterTextBox->text()); 298 } 299 300 ModelWidget *pModelWidget = mpLibraryTreeItem->getModelWidget(); 301 pModelWidget->createOMSimulatorUndoCommand(QString("Simulation setup %1").arg(mModelCref)); 302 pModelWidget->updateModelText(); 303 accept(); 304 }
Note: See TracChangeset
for help on using the changeset viewer.