From 07f8e0ff7e413825dd27ec87a4d15bcaa907d727 Mon Sep 17 00:00:00 2001 From: Alan Garny Date: Fri, 10 Nov 2017 17:49:19 +0100 Subject: [PATCH] SimulationExperiment view: now have SED-ML support for the background colour (#1426). --- ...ewinformationgraphpanelandgraphswidget.cpp | 9 +++ ...viewinformationgraphpanelandgraphswidget.h | 1 + ...mulationexperimentviewsimulationwidget.cpp | 69 ++++++++++++++----- .../support/SEDMLSupport/src/sedmlfile.cpp | 24 +++++++ .../support/SEDMLSupport/src/sedmlfile.h | 2 + 5 files changed, 89 insertions(+), 16 deletions(-) diff --git a/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewinformationgraphpanelandgraphswidget.cpp b/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewinformationgraphpanelandgraphswidget.cpp index c4b03b8fba..1410595fe3 100644 --- a/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewinformationgraphpanelandgraphswidget.cpp +++ b/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewinformationgraphpanelandgraphswidget.cpp @@ -628,6 +628,15 @@ void SimulationExperimentViewInformationGraphPanelAndGraphsWidget::finishEditing //============================================================================== +Core::Properties SimulationExperimentViewInformationGraphPanelAndGraphsWidget::graphPanelProperties(GraphPanelWidget::GraphPanelWidget *pGraphPanel) const +{ + // Retrieve and return all the graph panel properties + + return mGraphPanelPropertyEditors.value(pGraphPanel)->properties(); +} + +//============================================================================== + static const auto PropertySeparator = QStringLiteral(" | "); //============================================================================== diff --git a/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewinformationgraphpanelandgraphswidget.h b/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewinformationgraphpanelandgraphswidget.h index a4ad486cb3..c52cae6920 100644 --- a/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewinformationgraphpanelandgraphswidget.h +++ b/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewinformationgraphpanelandgraphswidget.h @@ -94,6 +94,7 @@ class SimulationExperimentViewInformationGraphPanelAndGraphsWidget : public QSta void finishEditing(); + Core::Properties graphPanelProperties(GraphPanelWidget::GraphPanelWidget *pGraphPanel) const; Core::Properties graphProperties(GraphPanelWidget::GraphPanelWidget *pGraphPanel, const QString &pFileName = QString()) const; diff --git a/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewsimulationwidget.cpp b/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewsimulationwidget.cpp index 62079601fe..5db8f19faf 100644 --- a/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewsimulationwidget.cpp +++ b/src/plugins/simulation/SimulationExperimentView/src/simulationexperimentviewsimulationwidget.cpp @@ -1674,6 +1674,8 @@ bool SimulationExperimentViewSimulationWidget::createSedmlFile(const QString &pF // Create a 2D plot output for each graph panel that we have, and retrieve // all the graphs, if any, that are to be plotted on them + static const QString SedmlProperty = QString("<%1>%2"); + typedef struct { libsedml::SedPlot2D *sedmlPlot2d; int graphPlotCounter; @@ -1689,10 +1691,18 @@ bool SimulationExperimentViewSimulationWidget::createSedmlFile(const QString &pF mContentsWidget->graphPanelsWidget()->graphPanels()) { // Create and customise the look and feel of our 2D plot + Core::Properties graphPanelProperties = graphPanelAndGraphsWidget->graphPanelProperties(graphPanel); libsedml::SedPlot2D *sedmlPlot2d = sedmlDocument->createPlot2D(); sedmlPlot2d->setId(QString("plot%1").arg(++graphPlotCounter).toStdString()); + sedmlPlot2d->appendAnnotation(QString("<%1 xmlns=\"%2\">" + " %3" + "").arg( SEDMLSupport::Plot2dProperties, + SEDMLSupport::OpencorNamespace, + SedmlProperty.arg(SEDMLSupport::BackgroundColor, + stringValue(graphPanelProperties[0]))).toStdString()); + // Keep track of the graph panel's graphs, if any Core::Properties graphProperties = graphPanelAndGraphsWidget->graphProperties(graphPanel, mFileName); @@ -1767,8 +1777,6 @@ bool SimulationExperimentViewSimulationWidget::createSedmlFile(const QString &pF // Customise our curve using an annotation - static const QString CurveProperty = QString("<%1>%2"); - Core::Properties lineProperties = property->properties()[3]->properties(); Core::Properties symbolProperties = property->properties()[4]->properties(); @@ -1778,22 +1786,22 @@ bool SimulationExperimentViewSimulationWidget::createSedmlFile(const QString &pF "").arg( SEDMLSupport::CurveProperties, SEDMLSupport::OpencorNamespace, SEDMLSupport::LineProperties, - CurveProperty.arg(SEDMLSupport::LineStyle, + SedmlProperty.arg(SEDMLSupport::LineStyle, SEDMLSupport::lineStyleValue(lineProperties[0]->listValueIndex())) - +CurveProperty.arg(SEDMLSupport::LineWidth, + +SedmlProperty.arg(SEDMLSupport::LineWidth, stringValue(lineProperties[1])) - +CurveProperty.arg(SEDMLSupport::LineColor, + +SedmlProperty.arg(SEDMLSupport::LineColor, stringValue(lineProperties[2])), SEDMLSupport::SymbolProperties, - CurveProperty.arg(SEDMLSupport::SymbolStyle, + SedmlProperty.arg(SEDMLSupport::SymbolStyle, SEDMLSupport::symbolStyleValue(symbolProperties[0]->listValueIndex())) - +CurveProperty.arg(SEDMLSupport::SymbolSize, + +SedmlProperty.arg(SEDMLSupport::SymbolSize, stringValue(symbolProperties[1])) - +CurveProperty.arg(SEDMLSupport::SymbolColor, + +SedmlProperty.arg(SEDMLSupport::SymbolColor, stringValue(symbolProperties[2])) - +CurveProperty.arg(SEDMLSupport::SymbolFilled, + +SedmlProperty.arg(SEDMLSupport::SymbolFilled, stringValue(symbolProperties[3])) - +CurveProperty.arg(SEDMLSupport::SymbolFillColor, + +SedmlProperty.arg(SEDMLSupport::SymbolFillColor, stringValue(symbolProperties[4]))).toStdString()); } } @@ -2432,22 +2440,51 @@ bool SimulationExperimentViewSimulationWidget::doFurtherInitialize() graphPanelsWidget->setActiveGraphPanel(graphPanelsWidget->graphPanels().first()); - // Customise our graph panel and graphs widget + // Customise our graph panel and graphs for (int i = 0; i < newNbOfGraphPanels; ++i) { + // Customise our graph panel + libsedml::SedPlot2D *sedmlPlot2d = static_cast(sedmlDocument->getOutput(i)); GraphPanelWidget::GraphPanelWidget *graphPanel = graphPanelsWidget->graphPanels()[i]; + GraphPanelWidget::GraphPanelPlotWidget *graphPanelPlot = graphPanel->plot(); + + annotation = sedmlPlot2d->getAnnotation(); + + if (annotation) { + SimulationExperimentViewInformationGraphPanelAndGraphsWidget *graphPanelAndGraphsWidget = mContentsWidget->informationWidget()->graphPanelAndGraphsWidget(); + Core::Properties graphPanelProperties = graphPanelAndGraphsWidget->graphPanelProperties(graphPanel); + + for (uint i = 0, iMax = annotation->getNumChildren(); i < iMax; ++i) { + const libsbml::XMLNode &sedmlPlot2dPropertiesNode = annotation->getChild(i); + + if ( QString::fromStdString(sedmlPlot2dPropertiesNode.getURI()).compare(SEDMLSupport::OpencorNamespace) + || QString::fromStdString(sedmlPlot2dPropertiesNode.getName()).compare(SEDMLSupport::Plot2dProperties)) { + continue; + } + + graphPanelPlot->setUpdatesEnabled(false); + + for (uint j = 0, jMax = sedmlPlot2dPropertiesNode.getNumChildren(); j < jMax; ++j) { + const libsbml::XMLNode &sedmlPlot2dPropertyNode = sedmlPlot2dPropertiesNode.getChild(j); + QString sedmlPlot2dPropertyNodeName = QString::fromStdString(sedmlPlot2dPropertyNode.getName()); + QString sedmlPlot2dPropertyNodeValue = QString::fromStdString(sedmlPlot2dPropertyNode.getChild(0).getCharacters()); + + if (!sedmlPlot2dPropertyNodeName.compare(SEDMLSupport::BackgroundColor)) + graphPanelProperties[0]->setValue(sedmlPlot2dPropertyNodeValue); + } + + graphPanelPlot->setUpdatesEnabled(true); + } + } + + // Customise our graphs graphPanel->removeAllGraphs(); for (uint j = 0, jMax = sedmlPlot2d->getNumCurves(); j < jMax; ++j) { libsedml::SedCurve *sedmlCurve = sedmlPlot2d->getCurve(j); - if (!j) { - graphPanel->plot()->setLogAxisX(sedmlCurve->getLogX()); - graphPanel->plot()->setLogAxisY(sedmlCurve->getLogY()); - } - CellMLSupport::CellmlFileRuntimeParameter *xParameter = runtimeParameter(sedmlDocument->getDataGenerator(sedmlCurve->getXDataReference())->getVariable(0)); CellMLSupport::CellmlFileRuntimeParameter *yParameter = runtimeParameter(sedmlDocument->getDataGenerator(sedmlCurve->getYDataReference())->getVariable(0)); diff --git a/src/plugins/support/SEDMLSupport/src/sedmlfile.cpp b/src/plugins/support/SEDMLSupport/src/sedmlfile.cpp index ae70f6a2b6..82e7b66266 100644 --- a/src/plugins/support/SEDMLSupport/src/sedmlfile.cpp +++ b/src/plugins/support/SEDMLSupport/src/sedmlfile.cpp @@ -820,6 +820,30 @@ bool SedmlFile::isSupported() return false; } + annotation = output->getAnnotation(); + + if (annotation) { + for (uint i = 0, iMax = annotation->getNumChildren(); i < iMax; ++i) { + const libsbml::XMLNode &plot2dPropertiesNode = annotation->getChild(i); + + if ( QString::fromStdString(plot2dPropertiesNode.getURI()).compare(OpencorNamespace) + || QString::fromStdString(plot2dPropertiesNode.getName()).compare(Plot2dProperties)) { + continue; + } + + for (uint j = 0, jMax = plot2dPropertiesNode.getNumChildren(); j < jMax; ++j) { + const libsbml::XMLNode &plot2dPropertyNode = plot2dPropertiesNode.getChild(j); + QString plot2dPropertyNodeName = QString::fromStdString(plot2dPropertyNode.getName()); + QString plot2dPropertyNodeValue = QString::fromStdString(plot2dPropertyNode.getChild(0).getCharacters()); + + if ( !plot2dPropertyNodeName.compare(BackgroundColor) + && !validColorPropertyValue(plot2dPropertyNode, plot2dPropertyNodeValue, BackgroundColor)) { + return false; + } + } + } + } + // Make sure that the curves reference listed data generators and don't // use logarithmic axes diff --git a/src/plugins/support/SEDMLSupport/src/sedmlfile.h b/src/plugins/support/SEDMLSupport/src/sedmlfile.h index 7e39984e89..ebb25449fa 100644 --- a/src/plugins/support/SEDMLSupport/src/sedmlfile.h +++ b/src/plugins/support/SEDMLSupport/src/sedmlfile.h @@ -70,6 +70,8 @@ static const auto SolverPropertyId = QStringLiteral("id"); static const auto SolverPropertyValue = QStringLiteral("value"); static const auto NlaSolver = QStringLiteral("nlaSolver"); static const auto NlaSolverName = QStringLiteral("name"); +static const auto Plot2dProperties = QStringLiteral("plot2dProperties"); +static const auto BackgroundColor = QStringLiteral("backgroundColor"); static const auto CurveProperties = QStringLiteral("curveProperties"); static const auto LineProperties = QStringLiteral("lineProperties"); static const auto LineStyle = QStringLiteral("lineStyle");