Skip to content

Commit

Permalink
Avoid making too many changeDirectory calls.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed Mar 15, 2016
1 parent 6ca8c1c commit 6cc344e
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 17 deletions.
21 changes: 11 additions & 10 deletions OMEdit/OMEditGUI/MainWindow.cpp
Expand Up @@ -92,7 +92,7 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, bool debug, QWidget *parent
mpMessagesDockWidget->hide();
connect(mpMessagesWidget, SIGNAL(MessageAdded()), mpMessagesDockWidget, SLOT(show()));
// Reopen the standard output stream.
QString outputFileName = mpOMCProxy->changeDirectory()+ "/omeditoutput.txt";
QString outputFileName = OpenModelica::tempDirectory() + "/omeditoutput.txt";
freopen(outputFileName.toStdString().c_str(), "w", stdout);
setbuf(stdout, NULL); // used non-buffered stdout
mpOutputFileDataNotifier = 0;
Expand All @@ -107,7 +107,7 @@ MainWindow::MainWindow(QSplashScreen *pSplashScreen, bool debug, QWidget *parent

}
// Reopen the standard error stream.
QString errorFileName = mpOMCProxy->changeDirectory()+ "/omediterror.txt";
QString errorFileName = OpenModelica::tempDirectory() + "/omediterror.txt";
freopen(errorFileName.toStdString().c_str(), "w", stderr);
setbuf(stderr, NULL); // used non-buffered stderr
mpErrorFileDataNotifier = 0;
Expand Down Expand Up @@ -472,14 +472,16 @@ void MainWindow::openDroppedFile(QDropEvent *event)
hideProgressBar();
}

/*!
* \brief MainWindow::openResultFiles
* Opens the result file(s).
* \param fileNames
*/
void MainWindow::openResultFiles(QStringList fileNames)
{
QString currentDirectory = mpOMCProxy->changeDirectory();
foreach (QString fileName, fileNames)
{
foreach (QString fileName, fileNames) {
QFileInfo fileInfo(fileName);
mpOMCProxy->changeDirectory(fileInfo.absoluteDir().absolutePath());
QStringList list = mpOMCProxy->readSimulationResultVars(fileInfo.fileName());
QStringList list = mpOMCProxy->readSimulationResultVars(fileInfo.absoluteFilePath());
// close the simulation result file.
mpOMCProxy->closeSimulationResultFile();
if (list.size() > 0) {
Expand All @@ -488,7 +490,6 @@ void MainWindow::openResultFiles(QStringList fileNames)
mpVariablesDockWidget->show();
}
}
mpOMCProxy->changeDirectory(currentDirectory);
}

void MainWindow::simulate(LibraryTreeItem *pLibraryTreeItem)
Expand Down Expand Up @@ -642,7 +643,7 @@ void MainWindow::exportModelFMU(LibraryTreeItem *pLibraryTreeItem)
if (mpOMCProxy->translateModelFMU(pLibraryTreeItem->getNameStructure(), version, type, FMUName)) {
mpMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, GUIMessages::getMessage(GUIMessages::FMU_GENERATED)
.arg(FMUName.isEmpty() ? pLibraryTreeItem->getNameStructure() : FMUName)
.arg(mpOMCProxy->changeDirectory()), Helper::scriptingKind,
.arg(mpOptionsDialog->getGeneralSettingsPage()->getWorkingDirectory()), Helper::scriptingKind,
Helper::notificationLevel));
}
// hide progress bar
Expand All @@ -666,7 +667,7 @@ void MainWindow::exportModelXML(LibraryTreeItem *pLibraryTreeItem)
showProgressBar();
if (mpOMCProxy->translateModelXML(pLibraryTreeItem->getNameStructure())) {
mpMessagesWidget->addGUIMessage(MessageItem(MessageItem::Modelica, "", false, 0, 0, 0, 0, GUIMessages::getMessage(GUIMessages::XML_GENERATED)
.arg(mpOMCProxy->changeDirectory()).arg(pLibraryTreeItem->getNameStructure()),
.arg(mpOptionsDialog->getGeneralSettingsPage()->getWorkingDirectory()).arg(pLibraryTreeItem->getNameStructure()),
Helper::scriptingKind, Helper::notificationLevel));
}
// hide progress bar
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Modeling/DocumentationWidget.cpp
Expand Up @@ -51,7 +51,7 @@ DocumentationWidget::DocumentationWidget(MainWindow *pParent)
setObjectName("DocumentationWidget");
setMinimumWidth(175);
mpMainWindow = pParent;
mDocumentationFile.setFileName(mpMainWindow->getOMCProxy()->changeDirectory() + "/DocumentationWidget.html");
mDocumentationFile.setFileName(OpenModelica::tempDirectory() + "/DocumentationWidget.html");
// create previous and next buttons for documentation navigation
// create the previous button
mpPreviousToolButton = new QToolButton;
Expand Down
3 changes: 2 additions & 1 deletion OMEdit/OMEditGUI/Options/OptionsDialog.cpp
Expand Up @@ -603,7 +603,8 @@ void OptionsDialog::saveGeneralSettings()
mpSettings->setValue("language", language);
// save working directory
mpMainWindow->getOMCProxy()->changeDirectory(mpGeneralSettingsPage->getWorkingDirectory());
mpSettings->setValue("workingDirectory", mpMainWindow->getOMCProxy()->changeDirectory());
mpGeneralSettingsPage->setWorkingDirectory(mpMainWindow->getOMCProxy()->changeDirectory());
mpSettings->setValue("workingDirectory", mpGeneralSettingsPage->getWorkingDirectory());
// save toolbar icon size
mpSettings->setValue("toolbarIconSize", mpGeneralSettingsPage->getToolbarIconSizeSpinBox()->value());
// save user customizations
Expand Down
2 changes: 1 addition & 1 deletion OMEdit/OMEditGUI/Simulation/SimulationDialog.cpp
Expand Up @@ -879,7 +879,7 @@ SimulationOptions SimulationDialog::createSimulationOptions()
simulationOptions.setSimulationFlags(simulationFlags);
simulationOptions.setIsValid(true);
simulationOptions.setReSimulate(mIsReSimulate);
simulationOptions.setWorkingDirectory(mpMainWindow->getOMCProxy()->changeDirectory());
simulationOptions.setWorkingDirectory(mpMainWindow->getOptionsDialog()->getGeneralSettingsPage()->getWorkingDirectory());
simulationOptions.setFileName(mFileName);
return simulationOptions;
}
Expand Down
5 changes: 1 addition & 4 deletions OMEdit/OMEditGUI/TLM/TLMCoSimulationDialog.cpp
Expand Up @@ -207,12 +207,9 @@ void TLMCoSimulationDialog::simulationProcessFinished(TLMCoSimulationOptions tlm
if (resultFileInfo.exists() && resultFileLastModifiedDateTime <= resultFileInfo.lastModified()) {
VariablesWidget *pVariablesWidget = mpMainWindow->getVariablesWidget();
OMCProxy *pOMCProxy = mpMainWindow->getOMCProxy();
QString currentDirectory = pOMCProxy->changeDirectory();
pOMCProxy->changeDirectory(fileInfo.absoluteDir().absolutePath());
QStringList list = pOMCProxy->readSimulationResultVars(resultFileInfo.fileName());
QStringList list = pOMCProxy->readSimulationResultVars(resultFileInfo.absoluteFilePath());
// close the simulation result file.
pOMCProxy->closeSimulationResultFile();
pOMCProxy->changeDirectory(currentDirectory);
if (list.size() > 0) {
mpMainWindow->getPerspectiveTabBar()->setCurrentIndex(2);
pVariablesWidget->insertVariablesItemsToTree(resultFileInfo.fileName(), fileInfo.absoluteDir().absolutePath(), list, SimulationOptions());
Expand Down

0 comments on commit 6cc344e

Please sign in to comment.