Skip to content

Commit

Permalink
Export variables from same result files
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 committed May 14, 2020
1 parent 01ec712 commit 41249a3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 37 deletions.
34 changes: 21 additions & 13 deletions OMEdit/OMEditLIB/Plotting/PlotWindowContainer.cpp
Expand Up @@ -525,38 +525,46 @@ void PlotWindowContainer::exportVariables()
{
PlotWindow *pPlotWindow = getCurrentWindow();
if (!pPlotWindow) {
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information),
QMessageBox::information(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::information),
tr("No plot window is active for exporting variables."), Helper::ok);
return;
}
if (pPlotWindow->getPlot()->getPlotCurvesList().isEmpty()) {
QMessageBox::information(this, QString(Helper::applicationName).append(" - ").append(Helper::information),
QMessageBox::information(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::information),
tr("No variables are selected for exporting."), Helper::ok);
return;
}

PlotCurve *pFirstPlotCurve = pPlotWindow->getPlot()->getPlotCurvesList().first();
int dataPoints = pFirstPlotCurve->mXAxisVector.size();
QString filePath = pFirstPlotCurve->getAbsoluteFilePath();
QStringList headers;
headers << "\"time\"";
foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) {
headers << "\"" + pPlotCurve->getName() + "\"";
if (filePath.compare(pPlotCurve->getAbsoluteFilePath()) != 0) {
QMessageBox::information(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::information),
tr("Not possible to export variables from different result files."), Helper::ok);
return;
}
}

QString name = QString("exportedVariables");
QString fileName = StringHandler::getSaveFileName(this, QString("%1 - %2").arg(Helper::applicationName).arg(Helper::exportVariables), NULL,
"CSV Files (*.csv)", NULL, "csv", &name);
if (fileName.isEmpty()) { // if user press ESC
return;
}
QString contents;
QStringList headers;
int dataPoints = 0;
headers << "\"time\"";
foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) {
headers << "\"" + pPlotCurve->getName() + "\"";
dataPoints = pPlotCurve->mXAxisVector.size();
}

// write the csv header
QString contents;
contents.append(headers.join(",")).append("\n");
// write csv data
for (int i = 0 ; i < dataPoints ; ++i) {
QStringList data;
// write time data
data << QString::number(pPlotWindow->getPlot()->getPlotCurvesList().at(0)->mXAxisVector.at(i));
for (int j = 0; j < headers.size() - 1; ++j) {
PlotCurve *pPlotCurve = pPlotWindow->getPlot()->getPlotCurvesList().at(j);
data << QString::number(pFirstPlotCurve->mXAxisVector.at(i));
foreach (PlotCurve *pPlotCurve, pPlotWindow->getPlot()->getPlotCurvesList()) {
OMCInterface::convertUnits_res convertUnit = MainWindow::instance()->getOMCProxy()->convertUnits(pPlotCurve->getDisplayUnit(), pPlotCurve->getUnit());
if (convertUnit.unitsCompatible) {
data << StringHandler::number(Utilities::convertUnit(pPlotCurve->mYAxisVector.at(i), convertUnit.offset, convertUnit.scaleFactor));
Expand Down
2 changes: 1 addition & 1 deletion OMNotebook/OMNotebook/OMNotebookGUI/xmlparser.cpp
Expand Up @@ -629,7 +629,7 @@ namespace IAEX
QDomElement curveElement = n.toElement();
if (curveElement.tagName() == XML_GRAPHCELL_CURVE)
{
PlotCurve *pPlotCurve = new PlotCurve("", curveElement.attribute(XML_GRAPHCELL_TITLE), "", curveElement.attribute(XML_GRAPHCELL_TITLE), "", "", gCell->mpPlotWindow->getPlot());
PlotCurve *pPlotCurve = new PlotCurve("", "", curveElement.attribute(XML_GRAPHCELL_TITLE), "", curveElement.attribute(XML_GRAPHCELL_TITLE), "", "", gCell->mpPlotWindow->getPlot());
// read the curve data
if (curveElement.hasAttribute(XML_GRAPHCELL_XDATA) && curveElement.hasAttribute(XML_GRAPHCELL_YDATA))
{
Expand Down
16 changes: 9 additions & 7 deletions OMPlot/OMPlot/OMPlotGUI/PlotCurve.cpp
Expand Up @@ -41,14 +41,16 @@

using namespace OMPlot;

PlotCurve::PlotCurve(QString fileName, QString name, QString xVariableName, QString yVariableName, QString unit, QString displayUnit, Plot *pParent)
PlotCurve::PlotCurve(const QString &fileName, const QString &absoluteFilePath, const QString &name, const QString &xVariableName, const QString &yVariableName,
const QString &unit, const QString &displayUnit, Plot *pParent)
: mCustomColor(false)
{
mName = name;
mXVariable = xVariableName;
mYVariable = yVariableName;
mNameStructure = fileName + "." + name;
mFileName = fileName;
mAbsoluteFilePath = absoluteFilePath;
mCustomColor = false;
setUnit(unit);
setDisplayUnit(displayUnit);
Expand All @@ -68,11 +70,6 @@ PlotCurve::PlotCurve(QString fileName, QString name, QString xVariableName, QStr
mpPointMarker->setSymbol(new QwtSymbol(QwtSymbol::Rect, QColor(Qt::red), QColor(Qt::red), QSize(6, 6)));
}

PlotCurve::~PlotCurve()
{

}

void PlotCurve::setTitleLocal()
{
if (getDisplayUnit().isEmpty()) {
Expand Down Expand Up @@ -186,11 +183,16 @@ void PlotCurve::setFileName(QString fileName)
mFileName = fileName;
}

QString PlotCurve::getFileName()
QString PlotCurve::getFileName() const
{
return mFileName;
}

QString PlotCurve::getAbsoluteFilePath() const
{
return mAbsoluteFilePath;
}

void PlotCurve::setNameStructure(QString variableName)
{
mNameStructure = getFileName() + "." + variableName;
Expand Down
8 changes: 5 additions & 3 deletions OMPlot/OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -45,6 +45,7 @@ class PlotCurve : public QwtPlotCurve
QString mName;
QString mNameStructure;
QString mFileName;
QString mAbsoluteFilePath;
QString mXVariable;
QString mYVariable;
bool mCustomColor;
Expand All @@ -57,8 +58,8 @@ class PlotCurve : public QwtPlotCurve
QwtPlotDirectPainter *mpPlotDirectPainter;
QwtPlotMarker *mpPointMarker;
public:
PlotCurve(QString fileName, QString name, QString xVariableName, QString yVariableName, QString unit, QString displayUnit, Plot *pParent);
~PlotCurve();
PlotCurve(const QString &fileName, const QString &absoluteFilePath, const QString &name, const QString &xVariableName, const QString &yVariableName,
const QString &unit, const QString &displayUnit, Plot *pParent);

QwtArray<double> mXAxisVector;
QwtArray<double> mYAxisVector;
Expand Down Expand Up @@ -88,7 +89,8 @@ class PlotCurve : public QwtPlotCurve
int getSize();
QString getName() {return mName;}
void setFileName(QString fileName);
QString getFileName();
QString getFileName() const;
QString getAbsoluteFilePath() const;
void setNameStructure(QString variableName);
QString getNameStructure() {return mNameStructure;}
void setXVariable(QString xVariable);
Expand Down
26 changes: 13 additions & 13 deletions OMPlot/OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -406,7 +406,7 @@ void PlotWindow::plot(PlotCurve *pPlotCurve)
{
variablesPlotted.append(currentVariable);
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), currentVariable, "time", currentVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), currentVariable, "time", currentVariable, getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
// clear previous curve data
Expand Down Expand Up @@ -474,7 +474,7 @@ void PlotWindow::plot(PlotCurve *pPlotCurve)
}

if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), csvReader->variables[i], "time", csvReader->variables[i], getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), csvReader->variables[i], "time", csvReader->variables[i], getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
// clear previous curve data
Expand Down Expand Up @@ -526,7 +526,7 @@ void PlotWindow::plot(PlotCurve *pPlotCurve)
variablesPlotted.append(reader.allInfo[i].name);
// create the plot curve for variable
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), reader.allInfo[i].name, "time", reader.allInfo[i].name, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), reader.allInfo[i].name, "time", reader.allInfo[i].name, getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
// read the variable values
Expand Down Expand Up @@ -645,7 +645,7 @@ void PlotWindow::plotParametric(PlotCurve *pPlotCurve)
if (variablesPlotted.size() == 1)
{
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -719,7 +719,7 @@ void PlotWindow::plotParametric(PlotCurve *pPlotCurve)
}

if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -753,7 +753,7 @@ void PlotWindow::plotParametric(PlotCurve *pPlotCurve)
throw PlotException(msg);

if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -962,7 +962,7 @@ void PlotWindow::plotArray(double time, PlotCurve *pPlotCurve)
pPlotCurve->clearXAxisVector();
pPlotCurve->clearYAxisVector();
} else {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), currentVariable, "array index", currentVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), currentVariable, "array index", currentVariable, getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
QList<double> arrLst;
Expand Down Expand Up @@ -1003,7 +1003,7 @@ void PlotWindow::plotArray(double time, PlotCurve *pPlotCurve)
QStringList::Iterator itVarList;
for (itVarList = mVariablesList.begin(); itVarList != mVariablesList.end(); itVarList++){
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), *itVarList, "array index", *itVarList, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), *itVarList, "array index", *itVarList, getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
QList<double> res;
Expand Down Expand Up @@ -1066,7 +1066,7 @@ void PlotWindow::plotArray(double time, PlotCurve *pPlotCurve)
QStringList::Iterator itVarList;
for (itVarList = mVariablesList.begin(); itVarList != mVariablesList.end(); itVarList++){
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), *itVarList, "array index", *itVarList, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), *itVarList, "array index", *itVarList, getUnit(), getDisplayUnit(), mpPlot);
mpPlot->addPlotCurve(pPlotCurve);
}
int i = 1;
Expand Down Expand Up @@ -1176,7 +1176,7 @@ void PlotWindow::plotArrayParametric(double time, PlotCurve *pPlotCurve)
pPlotCurve->clearXAxisVector();
pPlotCurve->clearYAxisVector();
} else {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -1222,7 +1222,7 @@ void PlotWindow::plotArrayParametric(double time, PlotCurve *pPlotCurve)
throw PlotException("Time out of bounds.");
}
if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -1283,7 +1283,7 @@ void PlotWindow::plotArrayParametric(double time, PlotCurve *pPlotCurve)
throw PlotException(msg);

if (!editCase) {
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(QFileInfo(mFile).fileName(), QFileInfo(mFile).absoluteFilePath(), yVariable + " vs " + xVariable, xVariable, yVariable, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve->setXVariable(xVariable);
pPlotCurve->setYVariable(yVariable);
mpPlot->addPlotCurve(pPlotCurve);
Expand Down Expand Up @@ -1354,7 +1354,7 @@ QPair<QVector<double>*, QVector<double>*> PlotWindow::plotInteractive(PlotCurve
throw NoVariableException(QString(tr("Could not determine the variable name!")).toStdString().c_str());
}
QString variableName = mVariablesList.at(0);
pPlotCurve = new PlotCurve(mInteractiveModelName, variableName, "time", variableName, getUnit(), getDisplayUnit(), mpPlot);
pPlotCurve = new PlotCurve(mInteractiveModelName, "", variableName, "time", variableName, getUnit(), getDisplayUnit(), mpPlot);
// clear previous curve data
pPlotCurve->clearXAxisVector();
pPlotCurve->clearYAxisVector();
Expand Down

0 comments on commit 41249a3

Please sign in to comment.