Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8431 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Haris Kapidzic committed Mar 31, 2011
1 parent 57cc4ea commit 66f5d22
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
6 changes: 5 additions & 1 deletion OMPlot/OMPlotGUI/Legend.cpp
Expand Up @@ -89,7 +89,11 @@ void Legend::selectColor()
for(int i = 0; i < list.length(); i++)
{
if(list[i]->title() == legendItem)
list[i]->setPen(QPen(c));
{
QPen pen = list[i]->pen();
pen.setColor(c);
list[i]->setPen(pen);
}
}
mpPlot->replot();
}
Expand Down
4 changes: 3 additions & 1 deletion OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -43,6 +43,7 @@ class PlotCurve : public QwtPlotCurve
private:
QVector<double> mXAxisVector;
QVector<double> mYAxisVector;

Plot *mpParentPlot;
public:
PlotCurve(Plot *pParent);
Expand All @@ -53,7 +54,8 @@ class PlotCurve : public QwtPlotCurve
QVector<double> getXAxisVector();
void setYAxisVector(QVector<double> vector);
void addYAxisValue(double value);
QVector<double> getYAxisVector();
QVector<double> getYAxisVector();

QColor getUniqueColor(QColor color = QColor(255, 0, 0));

virtual void updateLegend(QwtLegend *legend) const;
Expand Down
67 changes: 36 additions & 31 deletions OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -226,9 +226,7 @@ void PlotWindow::plot(QStringList variables)
throw NoVariableException(QString("No variables specified!").toStdString().c_str());

if(mpFile->fileName().endsWith("plt"))
{
std::cout << "Time before PLT collect : " << QTime::currentTime().toString().toStdString() << ":" << QTime::currentTime().msec();

{
//PLOT PLT
//Set intervalSize
int intervalSize;
Expand Down Expand Up @@ -269,15 +267,16 @@ void PlotWindow::plot(QStringList variables)
variableExists.replace(i , 1);
PlotCurve *pPlotCurve = new PlotCurve(mpPlot);
currentLine = mpTextStream->readLine();
intervalSize = intervalString.toInt();
while(intervalSize != 0)

for(int j = 0; j < intervalSize; j++)
{
QStringList doubleList = currentLine.split(",");
pPlotCurve->addXAxisValue(QString(doubleList[0]).toDouble());
pPlotCurve->addYAxisValue(QString(doubleList[1]).toDouble());
currentLine = mpTextStream->readLine();
intervalSize--;

currentLine = mpTextStream->readLine();
}

pPlotCurve->setTitle(currentVariable);
mpPlot->addPlotCurve(pPlotCurve);
}
Expand All @@ -287,14 +286,10 @@ void PlotWindow::plot(QStringList variables)
}
//Error handling
if(!(variables[0] == ""))
checkForErrors(variables, variableExists);

std::cout << "Time after PLT collect : " << QTime::currentTime().toString().toStdString() << ":" << QTime::currentTime().msec();
checkForErrors(variables, variableExists);
}
else if(mpFile->fileName().endsWith("csv"))
{
std::cout << "Time before CSV collect : " << QTime::currentTime().toString().toStdString() << ":" << QTime::currentTime().msec();

{
//PLOT CSV
currentLine = mpTextStream->readLine();
currentLine.remove(QChar('"'));
Expand Down Expand Up @@ -364,8 +359,6 @@ void PlotWindow::plot(QStringList variables)
}
else if(mpFile->fileName().endsWith("mat"))
{
std::cout << "Time before MAT collect : " << QTime::currentTime().toString().toStdString() << ":" << QTime::currentTime().msec();

//PLOT MAT
ModelicaMatReader reader;
ModelicaMatVariable_t *var;
Expand All @@ -380,7 +373,7 @@ void PlotWindow::plot(QStringList variables)
double stopTime = omc_matlab4_stopTime(&reader);
if (reader.nvar < 1)
throw NoVariableException("Variable doesnt exist: time");
double *timeVals = omc_matlab4_read_vals(&reader,0);
double *timeVals = omc_matlab4_read_vals(&reader,0);

if(variables[0] == "")
{
Expand All @@ -400,9 +393,20 @@ void PlotWindow::plot(QStringList variables)
var = omc_matlab4_find_var(&reader, currentPlotVariable.toStdString().c_str());
if(!var)
throw NoVariableException(QString("Variable doesnt exist : ").append(currentPlotVariable).toStdString().c_str());
if (!var->isParam) {
double *vals = omc_matlab4_read_vals(&reader, var->index);
pPlotCurve->setRawData(timeVals,vals,reader.nrows);
if (!var->isParam) {
double *vals = omc_matlab4_read_vals(&reader, var->index);

for (int j = 0; j<reader.nrows; j++)
{
pPlotCurve->addXAxisValue(timeVals[j]);
pPlotCurve->addYAxisValue(vals[j]);
}

pPlotCurve->setTitle(variables[i]);
// pPlotCurve->setXAxisPointer(timeVals);
// pPlotCurve->setYAxisPointer(vals);
// pPlotCurve->setNumberOfValues(reader.nrows);

} else {
double val;
double startStop[2] = {startTime,stopTime};
Expand All @@ -415,10 +419,9 @@ void PlotWindow::plot(QStringList variables)
}

//Set curvename and push back to list
pPlotCurve->setTitle(variables[i]);

mpPlot->addPlotCurve(pPlotCurve);
}
std::cout << "Time after MAT collect : " << QTime::currentTime().toString().toStdString() << ":" << QTime::currentTime().msec();
}
}
plotGraph(mpPlot->getPlotCurvesList());
}
Expand Down Expand Up @@ -500,7 +503,7 @@ void PlotWindow::plotParametric(QString xVariable, QString yVariable)
//Error handling
checkForErrors(variablesList, variableExists);

pPlotCurve->setTitle(variablesList[1]);
pPlotCurve->setTitle(yVariable + "(" + xVariable + ")");
mpPlot->addPlotCurve(pPlotCurve);
}
else if(mpFile->fileName().endsWith("csv"))
Expand Down Expand Up @@ -547,7 +550,7 @@ void PlotWindow::plotParametric(QString xVariable, QString yVariable)
list.append(yVariable);
checkForErrors(list, variableExists);

pPlotCurve->setTitle(yVariable);
pPlotCurve->setTitle(yVariable + "(" + xVariable + ")");
mpPlot->addPlotCurve(pPlotCurve);
}
else if(mpFile->fileName().endsWith("mat"))
Expand Down Expand Up @@ -580,21 +583,22 @@ void PlotWindow::plotParametric(QString xVariable, QString yVariable)
for (int j = 0; j<reader.nrows; j++)
pPlotCurve->addYAxisValue(vals[j]);

pPlotCurve->setTitle(yVariable);
pPlotCurve->setTitle(yVariable + "(" + xVariable + ")");
mpPlot->addPlotCurve(pPlotCurve);
}
plotGraph(mpPlot->getPlotCurvesList());
}

void PlotWindow::plotGraph(QList<PlotCurve*> plotCurvesList)
{
{
for(int i = 0; i < plotCurvesList.length(); i++)
{
{
plotCurvesList[i]->setData(plotCurvesList[i]->getXAxisVector(), plotCurvesList[i]->getYAxisVector());
//plotCurvesList[i]->setRawData(plotCurvesList[i]->getXAxisPointer(), plotCurvesList[i]->getYAxisPointer(), plotCurvesList[i]->getNumberOfValues());
QPen pen(plotCurvesList[i]->getUniqueColor());
pen.setWidth(2);
plotCurvesList[i]->setPen(pen);
plotCurvesList[i]->attach(mpPlot);
plotCurvesList[i]->setPen(pen);
plotCurvesList[i]->attach(mpPlot);
//mpPlot->addPlotCurve(plotCurvesList[i]);
}
mpPlot->getPlotZoomer()->setZoomBase();
Expand Down Expand Up @@ -705,8 +709,9 @@ void PlotWindow::setGrid(bool on)

void PlotWindow::setOriginal()
{
mpPlot->setAxisAutoScale(QwtPlot::yLeft);
mpPlot->setAxisAutoScale(QwtPlot::xBottom);
// mpPlot->setAxisAutoScale(QwtPlot::yLeft);
// mpPlot->setAxisAutoScale(QwtPlot::xBottom);
mpPlot->getPlotZoomer()->zoom(0);
mpPlot->replot();
}

Expand Down
2 changes: 1 addition & 1 deletion OMPlot/OMPlotGUI/main.cpp
Expand Up @@ -39,7 +39,7 @@ using namespace OMPlot;
int main(int argc, char *argv[])
{
if (argc < 14) {
printf("Usage: %s filename title legend grid plottype logx logy xlabel ylabel xrange1 xrange2 yrange1 yrange2 variables\n", *argv);
printf("Usage: %s arg1 ... arg13 variables\n", *argv);
return 1;
}
QApplication a(argc, argv);
Expand Down

0 comments on commit 66f5d22

Please sign in to comment.