Skip to content

Commit

Permalink
SimulationExperiment view: now have SED-ML support for the background…
Browse files Browse the repository at this point in the history
… colour (opencor#1426).
  • Loading branch information
agarny committed Nov 10, 2017
1 parent 2c52505 commit 07f8e0f
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 16 deletions.
Expand Up @@ -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(" | ");

//==============================================================================
Expand Down
Expand Up @@ -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;

Expand Down
Expand Up @@ -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</%1>");

typedef struct {
libsedml::SedPlot2D *sedmlPlot2d;
int graphPlotCounter;
Expand All @@ -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"
"</%1>").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);
Expand Down Expand Up @@ -1767,8 +1777,6 @@ bool SimulationExperimentViewSimulationWidget::createSedmlFile(const QString &pF

// Customise our curve using an annotation

static const QString CurveProperty = QString("<%1>%2</%1>");

Core::Properties lineProperties = property->properties()[3]->properties();
Core::Properties symbolProperties = property->properties()[4]->properties();

Expand All @@ -1778,22 +1786,22 @@ bool SimulationExperimentViewSimulationWidget::createSedmlFile(const QString &pF
"</%1>").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());
}
}
Expand Down Expand Up @@ -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<libsedml::SedPlot2D *>(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));

Expand Down
24 changes: 24 additions & 0 deletions src/plugins/support/SEDMLSupport/src/sedmlfile.cpp
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions src/plugins/support/SEDMLSupport/src/sedmlfile.h
Expand Up @@ -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");
Expand Down

0 comments on commit 07f8e0f

Please sign in to comment.