From 89da8ed7dd825c651e8b4f23a363b257131a5f88 Mon Sep 17 00:00:00 2001 From: Lucian Smith Date: Fri, 13 Sep 2024 19:30:05 -0700 Subject: [PATCH] At attempt to fix #398 First pass at a fix for #398, which resulted from inappropriately casting an element. Not sure I got all the use cases, but I might have? --- .../packages/render/sbml/Transformation2D.cpp | 117 ++++++++++-------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/src/sbml/packages/render/sbml/Transformation2D.cpp b/src/sbml/packages/render/sbml/Transformation2D.cpp index fc03e34cab..a58776d794 100644 --- a/src/sbml/packages/render/sbml/Transformation2D.cpp +++ b/src/sbml/packages/render/sbml/Transformation2D.cpp @@ -714,65 +714,72 @@ Transformation2D::addExpectedAttributes(ExpectedAttributes& attributes) */ void Transformation2D::readAttributes(const XMLAttributes& attributes, - const ExpectedAttributes& expectedAttributes) -{ - unsigned int level = getLevel(); - unsigned int version = getVersion(); - unsigned int pkgVersion = getPackageVersion(); - unsigned int numErrs; - SBMLErrorLog* log = getErrorLog(); - - if (log && getParentSBMLObject() && - static_cast(getParentSBMLObject())->size() < 2) - { - numErrs = log->getNumErrors(); - for (int n = numErrs-1; n >= 0; n--) - { - if (log->getError(n)->getErrorId() == UnknownPackageAttribute) - { - const std::string details = log->getError(n)->getMessage(); - log->remove(UnknownPackageAttribute); - log->logPackageError("render", RenderUnknown, pkgVersion, level, - version, details, getLine(), getColumn()); - } - else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) - { - const std::string details = log->getError(n)->getMessage(); - log->remove(UnknownCoreAttribute); - log->logPackageError("render", RenderUnknown, pkgVersion, level, - version, details, getLine(), getColumn()); - } + const ExpectedAttributes& expectedAttributes) +{ + unsigned int level = getLevel(); + unsigned int version = getVersion(); + unsigned int pkgVersion = getPackageVersion(); + unsigned int numErrs; + SBMLErrorLog* log = getErrorLog(); + + if (log && getParentSBMLObject()) { + bool isSizeOne = false; + int type = getParentSBMLObject()->getTypeCode(); + switch (type) { + case SBML_LIST_OF: + if (static_cast(getParentSBMLObject())->size() < 2) + { + isSizeOne = true; + } + break; + case SBML_RENDER_LINEENDING: + case SBML_RENDER_STYLE_BASE: + case SBML_RENDER_LOCALSTYLE: + case SBML_RENDER_GLOBALSTYLE: + // These objects all have a single RenderGroup child, so the size can never be greater than 2. + isSizeOne = true; + break; + case SBML_RENDER_GROUP: + { + //A RenderGroup can have multiple Transformation2D children. + RenderGroup* rg = static_cast(getParentSBMLObject()); + if (rg->getNumElements() < 2) + { + isSizeOne = false; + } + break; + } + default: + assert(false); //Some situation we didn't think through; could be anything. + isSizeOne = true; + } + if (isSizeOne) { + numErrs = log->getNumErrors(); + for (int n = numErrs - 1; n >= 0; n--) + { + if (log->getError(n)->getErrorId() == UnknownPackageAttribute) + { + const std::string details = log->getError(n)->getMessage(); + log->remove(UnknownPackageAttribute); + log->logPackageError("render", RenderUnknown, pkgVersion, level, + version, details, getLine(), getColumn()); + } + else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) + { + const std::string details = log->getError(n)->getMessage(); + log->remove(UnknownCoreAttribute); + log->logPackageError("render", RenderUnknown, pkgVersion, level, + version, details, getLine(), getColumn()); + } + } + } } - } - Transformation::readAttributes(attributes, expectedAttributes); - - //if (log) - //{ - // numErrs = log->getNumErrors(); - - // for (int n = numErrs-1; n >= 0; n--) - // { - // if (log->getError(n)->getErrorId() == UnknownPackageAttribute) - // { - // const std::string details = log->getError(n)->getMessage(); - // log->remove(UnknownPackageAttribute); - // log->logPackageError("render", RenderUnknown, pkgVersion, level, - // version, details); - // } - // else if (log->getError(n)->getErrorId() == UnknownCoreAttribute) - // { - // const std::string details = log->getError(n)->getMessage(); - // log->remove(UnknownCoreAttribute); - // log->logPackageError("render", - // RenderTransformation2DAllowedCoreAttributes, pkgVersion, level, - // version, details); - // } - // } - //} + Transformation::readAttributes(attributes, expectedAttributes); + std::string s; attributes.readInto("transform", s); - if(!s.empty()) + if (!s.empty()) { this->parseTransformation(s); }