Skip to content

Commit

Permalink
- Don't close the simulation result set since we have a caching to ma…
Browse files Browse the repository at this point in the history
…t format.

- closeSimulationResultFile() :: Closes the current simulation result set. OMEdit uses it for windows to close the result file.
- some minor fixes in OMPlot.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@11053 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Feb 9, 2012
1 parent 6bc6784 commit 4fb1730
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
50 changes: 32 additions & 18 deletions OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -80,7 +80,7 @@ void PlotWindow::setUpWidget()
void PlotWindow::initializePlot(QStringList arguments)
{
// open the file
openFile(QString(arguments[1]));
initializeFile(QString(arguments[1]));
//Set up arguments
setTitle(QString(arguments[2]));
if(QString(arguments[3]) == "true")
Expand Down Expand Up @@ -134,7 +134,6 @@ void PlotWindow::initializePlot(QStringList arguments)
setPlotType(PlotWindow::PLOTPARAMETRIC);
plotParametric();
}
closeFile();
}

void PlotWindow::setVariablesList(QStringList variables)
Expand All @@ -152,23 +151,13 @@ PlotWindow::PlotType PlotWindow::getPlotType()
return mPlotType;
}

void PlotWindow::openFile(QString file)
{
//Open file to a textstream
// close the file if it is already opened
if (mFile.isOpen())
mFile.close();

void PlotWindow::initializeFile(QString file)
{
mFile.setFileName(file);
if(!mFile.exists())
throw NoFileException(QString("File not found : ").append(file).toStdString().c_str());
mFile.open(QIODevice::ReadOnly);
mpTextStream = new QTextStream(&mFile);
}

void PlotWindow::closeFile()
{
mFile.close();
// mFile.open(QIODevice::ReadOnly);
// mpTextStream = new QTextStream(&mFile);
}

void PlotWindow::setupToolbar()
Expand Down Expand Up @@ -242,6 +231,9 @@ void PlotWindow::plot()
//PLOT PLT
if (mFile.fileName().endsWith("plt"))
{
// open the file
mFile.open(QIODevice::ReadOnly);
mpTextStream = new QTextStream(&mFile);
// read the interval size from the file
int intervalSize;
while (!mpTextStream->atEnd())
Expand Down Expand Up @@ -293,10 +285,15 @@ void PlotWindow::plot()
// if plottype is PLOT then check which requested variables are not found in the file
if (getPlotType() == PlotWindow::PLOT)
checkForErrors(mVariablesList, variablesPlotted);
// close the file
mFile.close();
}
//PLOT CSV
else if (mFile.fileName().endsWith("csv"))
{
// open the file
mFile.open(QIODevice::ReadOnly);
mpTextStream = new QTextStream(&mFile);
currentLine = mpTextStream->readLine();
currentLine.remove(QChar('"'));
QStringList allVariablesInFile = currentLine.split(",");
Expand Down Expand Up @@ -351,6 +348,8 @@ void PlotWindow::plot()
// if plottype is PLOT then check which requested variables are not found in the file
if (getPlotType() == PlotWindow::PLOT)
checkForErrors(mVariablesList, variablesPlotted);
// close the file
mFile.close();
}
//PLOT MAT
else if(mFile.fileName().endsWith("mat"))
Expand All @@ -369,7 +368,8 @@ void PlotWindow::plot()
double stopTime = omc_matlab4_stopTime(&reader);
if (reader.nvar < 1)
throw NoVariableException("Variable doesnt exist: time");
double *timeVals = omc_matlab4_read_vals(&reader,1);
double *timeVals = (double*) malloc(reader.nrows*sizeof(double));
memcpy(timeVals, omc_matlab4_read_vals(&reader,1), reader.nrows*sizeof(double));

// read in all values
int counter = 0;
Expand All @@ -389,7 +389,8 @@ void PlotWindow::plot()
// if variable is not a parameter then
if (!var->isParam)
{
double *vals = omc_matlab4_read_vals(&reader, var->index);
double *vals = (double*) malloc(reader.nrows*sizeof(double));
memcpy(vals, omc_matlab4_read_vals(&reader,var->index), reader.nrows*sizeof(double));
// set plot curve data and attach it to plot
pPlotCurve->setData(timeVals, vals, reader.nrows);
pPlotCurve->attach(mpPlot);
Expand All @@ -416,6 +417,8 @@ void PlotWindow::plot()
// if plottype is PLOT then check which requested variables are not found in the file
if (getPlotType() == PlotWindow::PLOT)
checkForErrors(mVariablesList, variablesPlotted);
// close the file
omc_free_matlab4_reader(&reader);
}
}

Expand All @@ -435,6 +438,9 @@ void PlotWindow::plotParametric()
//PLOT PLT
if (mFile.fileName().endsWith("plt"))
{
// open the file
mFile.open(QIODevice::ReadOnly);
mpTextStream = new QTextStream(&mFile);
// read the interval size from the file
int intervalSize;
while (!mpTextStream->atEnd())
Expand Down Expand Up @@ -498,10 +504,15 @@ void PlotWindow::plotParametric()
}
// check which requested variables are not found in the file
checkForErrors(mVariablesList, variablesPlotted);
// close the file
mFile.close();
}
//PLOT CSV
else if (mFile.fileName().endsWith("csv"))
{
// open the file
mFile.open(QIODevice::ReadOnly);
mpTextStream = new QTextStream(&mFile);
currentLine = mpTextStream->readLine();
currentLine.remove(QChar('"'));

Expand Down Expand Up @@ -550,6 +561,8 @@ void PlotWindow::plotParametric()
mpPlot->replot();
// check which requested variables are not found in the file
checkForErrors(mVariablesList, variablesPlotted);
// close the file
mFile.close();
}
//PLOT MAT
else if(mFile.fileName().endsWith("mat"))
Expand Down Expand Up @@ -582,6 +595,7 @@ void PlotWindow::plotParametric()
pPlotCurve->setTitle(yVariable + "(" + xVariable + ")");
pPlotCurve->attach(mpPlot);
mpPlot->replot();
omc_free_matlab4_reader(&reader);
}
}

Expand Down
3 changes: 1 addition & 2 deletions OMPlot/OMPlotGUI/PlotWindow.h
Expand Up @@ -73,8 +73,7 @@ class PlotWindow : public QMainWindow
void setVariablesList(QStringList variables);
void setPlotType(PlotType type);
PlotType getPlotType();
void openFile(QString file);
void closeFile();
void initializeFile(QString file);
void setupToolbar();
void plot();
void plotParametric();
Expand Down

0 comments on commit 4fb1730

Please sign in to comment.