From b3eb9c3a9c36cd833c2d1ca7ebc9523403c54ed2 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Fri, 15 Sep 2023 12:13:18 +0200 Subject: [PATCH 1/8] Update Fbc V3 package --- NEWS.txt | 10 + .../extension/test/TestWriteFbcExtension.cpp | 8 +- .../test/test-data/fbc_example2_v3.xml | 4 +- .../test/test-data/fbc_examplev3.xml | 2 +- src/sbml/packages/fbc/sbml/FluxObjective.cpp | 128 ++++++++- src/sbml/packages/fbc/sbml/FluxObjective.h | 113 ++++++++ .../sbml/UserDefinedConstraintComponent.cpp | 264 +++++++++++++++--- .../fbc/sbml/UserDefinedConstraintComponent.h | 142 +++++++++- 8 files changed, 614 insertions(+), 57 deletions(-) diff --git a/NEWS.txt b/NEWS.txt index e48c1f75cc..fd54af1c12 100644 --- a/NEWS.txt +++ b/NEWS.txt @@ -14,6 +14,11 @@ and converting models. - Attributes of the ModelHistory can now be accessed from const objects. + - The FBC V3 package has been updated to reflect the latest + specification. There are now optional attributes `fbc:reaction2` + on the FluxObjective and `fbc:variable2` on the + UserDefinedConstraintComponent. + * Bug fixes - A bug converting / validating models with the 'comp' package @@ -23,6 +28,11 @@ and converting models. - A fix to the CMake Build system ensures that check for dependencies is more robust. Thanks to first time contributor @adelhpour + + - The type of the FBC V3 `coefficient` attribute on the + UserDefinedConstraintComponent has been corrected, it was mistakenly + a double before, now it has been corrected to be a SIdRef as + described in the specification. ==================================================================== diff --git a/src/sbml/packages/fbc/extension/test/TestWriteFbcExtension.cpp b/src/sbml/packages/fbc/extension/test/TestWriteFbcExtension.cpp index 24767a865e..a314411a1d 100644 --- a/src/sbml/packages/fbc/extension/test/TestWriteFbcExtension.cpp +++ b/src/sbml/packages/fbc/extension/test/TestWriteFbcExtension.cpp @@ -415,7 +415,8 @@ START_TEST(test_FbcExtension_create_and_write_L3V1V3) FluxObjective* fluxObjective = objective->createFluxObjective(); fluxObjective->setReaction("J0"); fluxObjective->setCoefficient(1); - fluxObjective->setVariableType("linear"); + fluxObjective->setReaction2("J0"); + fluxObjective->setVariableType("quadratic"); UserDefinedConstraint* userconstraint = mplugin->createUserDefinedConstraint(); userconstraint->setId("uc2"); @@ -423,9 +424,10 @@ START_TEST(test_FbcExtension_create_and_write_L3V1V3) userconstraint->setUpperBound("uc2ub"); UserDefinedConstraintComponent * udcc = userconstraint->createUserDefinedConstraintComponent(); - udcc->setCoefficient(2); + udcc->setCoefficient("ucc1"); udcc->setVariable("Avar"); - udcc->setVariableType("linear"); + udcc->setVariableType("quadratic"); + udcc->setVariable2("Avar2"); // check annotations on several types FbcSBasePlugin* sbaseplugin = dynamic_cast(compartment->getPlugin("fbc")); diff --git a/src/sbml/packages/fbc/extension/test/test-data/fbc_example2_v3.xml b/src/sbml/packages/fbc/extension/test/test-data/fbc_example2_v3.xml index 583b6a52e7..6e696a7167 100644 --- a/src/sbml/packages/fbc/extension/test/test-data/fbc_example2_v3.xml +++ b/src/sbml/packages/fbc/extension/test/test-data/fbc_example2_v3.xml @@ -32,14 +32,14 @@ - + - + diff --git a/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml b/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml index b7090bb8d0..85ce707a8b 100644 --- a/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml +++ b/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml @@ -28,7 +28,7 @@ - + diff --git a/src/sbml/packages/fbc/sbml/FluxObjective.cpp b/src/sbml/packages/fbc/sbml/FluxObjective.cpp index a51a16b533..419f8f8449 100644 --- a/src/sbml/packages/fbc/sbml/FluxObjective.cpp +++ b/src/sbml/packages/fbc/sbml/FluxObjective.cpp @@ -69,6 +69,7 @@ FluxObjective::FluxObjective (unsigned int level, unsigned int version, unsigned , mCoefficient (numeric_limits::quiet_NaN()) , mIsSetCoefficient (false) , mVariableType (FBC_VARIABLE_TYPE_INVALID) + , mReaction2 ("") { // set an SBMLNamespaces derived object of this package setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion)); @@ -86,6 +87,7 @@ FluxObjective::FluxObjective (FbcPkgNamespaces* fbcns) , mCoefficient (numeric_limits::quiet_NaN()) , mIsSetCoefficient (false) , mVariableType (FBC_VARIABLE_TYPE_INVALID) + , mReaction2 ("") { // set the element namespace of this object setElementNamespace(fbcns->getURI()); @@ -104,6 +106,7 @@ FluxObjective::FluxObjective(const FluxObjective& orig) , mCoefficient ( orig.mCoefficient ) , mIsSetCoefficient ( orig.mIsSetCoefficient ) , mVariableType ( orig.mVariableType ) + , mReaction2 (orig.mReaction2) { } @@ -123,6 +126,7 @@ FluxObjective::operator=(const FluxObjective& rhs) mCoefficient = rhs.mCoefficient; mIsSetCoefficient = rhs.mIsSetCoefficient; mVariableType = rhs.mVariableType; + mReaction2 = rhs.mReaction2; } return *this; } @@ -176,6 +180,16 @@ FluxObjective::getReaction() const } +/* + * Returns the value of the "reaction2" attribute of this FluxObjective. + */ +const std::string& +FluxObjective::getReaction2() const +{ + return mReaction2; +} + + /* * Returns the value of the "coefficient" attribute of this FluxObjective. */ @@ -238,6 +252,16 @@ FluxObjective::isSetReaction() const } +/* + * Predicate returning @c true if this FluxObjective's "reaction2" attribute is + * set. + */ +bool +FluxObjective::isSetReaction2() const +{ + return (mReaction2.empty() == false); +} + /* * Predicate returning @c true if this FluxObjective's "coefficient" attribute * is set. @@ -287,7 +311,17 @@ FluxObjective::setName(const std::string& name) int FluxObjective::setReaction(const std::string& reaction) { - return SyntaxChecker::checkAndSetSId(reaction ,mReaction); + return SyntaxChecker::checkAndSetSId(reaction, mReaction); +} + + +/* + * Sets reaction2 and returns value indicating success. + */ +int +FluxObjective::setReaction2(const std::string& reaction) +{ + return SyntaxChecker::checkAndSetSId(reaction, mReaction2); } @@ -418,6 +452,25 @@ FluxObjective::unsetReaction() } +/* + * Unsets reaction and returns value indicating success. + */ +int +FluxObjective::unsetReaction2() +{ + mReaction2.erase(); + + if (mReaction2.empty() == true) + { + return LIBSBML_OPERATION_SUCCESS; + } + else + { + return LIBSBML_OPERATION_FAILED; + } +} + + /* * Unsets coefficient and returns value indicating success. */ @@ -460,6 +513,10 @@ FluxObjective::renameSIdRefs(const std::string& oldid, const std::string& newid) { setReaction(newid); } + if (isSetReaction2() == true && mReaction2 == oldid) + { + setReaction2(newid); + } } @@ -697,7 +754,12 @@ FluxObjective::getAttribute(const std::string& attributeName, value = getVariableTypeAsString(); return_value = LIBSBML_OPERATION_SUCCESS; } - + else if (attributeName == "reaction2") + { + value = getReaction2(); + return_value = LIBSBML_OPERATION_SUCCESS; + } + return return_value; } @@ -736,6 +798,10 @@ FluxObjective::isSetAttribute(const std::string& attributeName) const { value = isSetVariableType(); } + else if (attributeName == "reaction2") + { + value = isSetReaction2(); + } return value; } @@ -845,6 +911,10 @@ FluxObjective::setAttribute(const std::string& attributeName, { return_value = setVariableType(value); } + else if (attributeName == "reaction2") + { + return_value = setReaction2(value); + } return return_value; } @@ -883,6 +953,10 @@ FluxObjective::unsetAttribute(const std::string& attributeName) { value = unsetVariableType(); } + else if (attributeName == "reaction2") + { + value = unsetReaction2(); + } return value; } @@ -912,6 +986,7 @@ FluxObjective::addExpectedAttributes(ExpectedAttributes& attributes) if (level == 3 && coreVersion == 1 && pkgVersion == 3) { attributes.add("variableType"); + attributes.add("reaction2"); } } @@ -1052,6 +1127,17 @@ FluxObjective::readAttributes (const XMLAttributes& attributes, } + assigned = attributes.readInto("reaction2", mReaction2); + if (assigned && !SyntaxChecker::isValidSBMLSId(mReaction2)) + { + // + // Logs an error if the "id" attribute doesn't + // conform to the SBML type SId. + // + log->logPackageError("fbc", FbcFluxObjectReactionMustBeSIdRef, + getPackageVersion(), sbmlLevel, sbmlVersion, "", getLine(), getColumn()); + } + unsigned int numErrs = log->getNumErrors(); mIsSetCoefficient = attributes.readInto("coefficient", mCoefficient, log); @@ -1153,6 +1239,9 @@ FluxObjective::writeAttributes (XMLOutputStream& stream) const FbcVariableType_toString(mVariableType)); } + if (isSetReaction2() == true) + stream.writeAttribute("reaction2", getPrefix(), mReaction2); + // // (EXTENSION) // @@ -1542,6 +1631,13 @@ FluxObjective_getVariableTypeAsString(const FluxObjective_t * fo) return (char*)(FbcVariableType_toString(fo->getVariableType())); } +LIBSBML_EXTERN +const char * +FluxObjective_getReaction2(const FluxObjective_t * fo) +{ + return (fo != NULL && fo->isSetReaction2()) ? fo->getReaction2().c_str() : NULL; +} + LIBSBML_EXTERN int @@ -1583,6 +1679,14 @@ FluxObjective_isSetVariableType(const FluxObjective_t * fo) } +LIBSBML_EXTERN +int +FluxObjective_isSetReaction2(const FluxObjective_t * fo) +{ + return (fo != NULL) ? static_cast(fo->isSetReaction2()) : 0; +} + + /* * Sets the value of the "id" attribute of this FluxObjective_t. */ @@ -1652,6 +1756,18 @@ FluxObjective_setVariableTypeAsString(FluxObjective_t * fo, LIBSBML_INVALID_OBJECT; } + +LIBSBML_EXTERN +int +FluxObjective_setReaction2(FluxObjective_t * fo, const char * reaction) +{ + if (fo != NULL) + return (reaction == NULL) ? fo->setReaction2("") : fo->setReaction2(reaction); + else + return LIBSBML_INVALID_OBJECT; +} + + LIBSBML_EXTERN int FluxObjective_unsetId(FluxObjective_t * fo) @@ -1695,6 +1811,14 @@ FluxObjective_unsetVariableType(FluxObjective_t * fo) } +LIBSBML_EXTERN +int +FluxObjective_unsetReaction2(FluxObjective_t * fo) +{ + return (fo != NULL) ? fo->unsetReaction2() : LIBSBML_INVALID_OBJECT; +} + + LIBSBML_EXTERN int FluxObjective_hasRequiredAttributes(const FluxObjective_t * fo) diff --git a/src/sbml/packages/fbc/sbml/FluxObjective.h b/src/sbml/packages/fbc/sbml/FluxObjective.h index 47796ac403..ca3f98b953 100644 --- a/src/sbml/packages/fbc/sbml/FluxObjective.h +++ b/src/sbml/packages/fbc/sbml/FluxObjective.h @@ -113,6 +113,7 @@ class LIBSBML_EXTERN FluxObjective : public SBase double mCoefficient; bool mIsSetCoefficient; FbcVariableType_t mVariableType; + std::string mReaction2; /** @endcond */ public: @@ -215,6 +216,14 @@ class LIBSBML_EXTERN FluxObjective : public SBase */ virtual const std::string& getReaction() const; + /** + * Returns the value of the "reaction2" attribute of this FluxObjective. + * + * @return the value of the "reaction2" attribute of this FluxObjective as a + * string. + */ + virtual const std::string& getReaction2() const; + /** * Returns the value of the "coefficient" attribute of this FluxObjective. @@ -284,6 +293,15 @@ class LIBSBML_EXTERN FluxObjective : public SBase */ virtual bool isSetReaction() const; + /** + * Predicate returning @c true if this FluxObjective's "reaction2" attribute + * is set. + * + * @return @c true if this FluxObjective's "reaction2" attribute has been set, + * otherwise @c false is returned. + */ + virtual bool isSetReaction2() const; + /** * Predicate returning @c true if this FluxObjective's "coefficient" @@ -334,6 +352,16 @@ class LIBSBML_EXTERN FluxObjective : public SBase */ virtual int setReaction(const std::string& reaction); + /** + * Sets the value of the "reaction2" attribute of this FluxObjective. + * + * @param reaction the value of the "reaction2" attribute to be set. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} + */ + virtual int setReaction2(const std::string& reaction); /** * Sets the value of the "coefficient" attribute of this FluxObjective. @@ -405,6 +433,16 @@ class LIBSBML_EXTERN FluxObjective : public SBase virtual int unsetReaction(); + /** + * Unsets the value of the "reaction2" attribute of this FluxObjective. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} + */ + virtual int unsetReaction2(); + + /** * Unsets the value of the "coefficient" attribute of this FluxObjective. * @@ -1201,6 +1239,21 @@ char * FluxObjective_getVariableTypeAsString(const FluxObjective_t * fo); +/** + * Returns the value of the "reaction2" attribute of the given FluxObjective_t + * structure. + * + * @param fo the FluxObjective_t structure. + * + * @return the reaction of this structure. + * + * @memberof FluxObjective_t + */ +LIBSBML_EXTERN +const char * +FluxObjective_getReaction2(const FluxObjective_t * fo); + + /** * Predicate returning @c 1 (true) if this FluxObjective_t's "id" attribute is * set. @@ -1283,6 +1336,22 @@ int FluxObjective_isSetVariableType(const FluxObjective_t * fo); +/** + * Predicate returning @c 1 (true) if the given FluxObjective_t structure's "reaction2" + * is set. + * + * @param fo the FluxObjective_t structure. + * + * @return @c 1 (true) if the "reaction2" of this FluxObjective_t structure is + * set, @c 0 (false) otherwise. + * + * @memberof FluxObjective_t + */ +LIBSBML_EXTERN +int +FluxObjective_isSetReaction2(const FluxObjective_t * fo); + + /** * Sets the value of the "id" attribute of this FluxObjective_t. * @@ -1423,6 +1492,32 @@ FluxObjective_setVariableTypeAsString(FluxObjective_t * fo, const char * variableType); +/** + * Sets the "reaction2" attribute of the given FluxObjective_t structure. + * + * This function copies the string given in @p reaction. If the string is + * a null pointer, this function is equivalent to calling FluxObjective_unsetReaction(). + * + * @param fo the FluxObjective_t structure. + * + * @param reaction the string to which the structures "reaction2" attribute should be + * set. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} + * + * @note Using this function with a null pointer for @p reaction is equivalent to + * unsetting the value of the "reaction2" attribute. + * + * @memberof FluxObjective_t + */ +LIBSBML_EXTERN +int +FluxObjective_setReaction2(FluxObjective_t * fo, const char * reaction); + + /** * Unsets the value of the "id" attribute of this FluxObjective_t. * @@ -1512,6 +1607,24 @@ int FluxObjective_unsetVariableType(FluxObjective_t * fo); +/** + * Unsets the value of the "reaction2" attribute of the given + * FluxObjective_t structure. + * + * @param fo the FluxObjective_t structure. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} + * + * @memberof FluxObjective_t + */ +LIBSBML_EXTERN +int +FluxObjective_unsetReaction2(FluxObjective_t * fo); + + /** * Predicate returning @c 1 (true) or @c 0 (false) depending on whether all the required * attributes of the given FluxObjective_t structure have been set. diff --git a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp index ffb3880e80..b43fe422eb 100644 --- a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp +++ b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp @@ -63,10 +63,10 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent( unsigned int pkgVersion) : SBase(level, version) - , mCoefficient (util_NaN()) - , mIsSetCoefficient (false) + , mCoefficient ("") , mVariable ("") , mVariableType (FBC_VARIABLE_TYPE_INVALID) + , mVariable2 ("") { setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion)); } @@ -79,10 +79,10 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent( UserDefinedConstraintComponent::UserDefinedConstraintComponent(FbcPkgNamespaces *fbcns) : SBase(fbcns) - , mCoefficient (util_NaN()) - , mIsSetCoefficient (false) + , mCoefficient ("") , mVariable ("") , mVariableType (FBC_VARIABLE_TYPE_INVALID) + , mVariable2 ("") { setElementNamespace(fbcns->getURI()); loadPlugins(fbcns); @@ -96,9 +96,9 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent(const UserDefinedConstraintComponent& orig) : SBase( orig ) , mCoefficient ( orig.mCoefficient ) - , mIsSetCoefficient ( orig.mIsSetCoefficient ) , mVariable ( orig.mVariable ) , mVariableType ( orig.mVariableType ) + , mVariable2 ( orig.mVariable2 ) { } @@ -114,9 +114,9 @@ UserDefinedConstraintComponent::operator=(const UserDefinedConstraintComponent& { SBase::operator=(rhs); mCoefficient = rhs.mCoefficient; - mIsSetCoefficient = rhs.mIsSetCoefficient; mVariable = rhs.mVariable; mVariableType = rhs.mVariableType; + mVariable2 = rhs.mVariable2; } return *this; @@ -168,7 +168,7 @@ UserDefinedConstraintComponent::getName() const * Returns the value of the "coefficient" attribute of this * UserDefinedConstraintComponent. */ -double +const std::string& UserDefinedConstraintComponent::getCoefficient() const { return mCoefficient; @@ -185,6 +185,16 @@ UserDefinedConstraintComponent::getVariable() const return mVariable; } +/* + * Returns the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + */ +const std::string& +UserDefinedConstraintComponent::getVariable2() const +{ + return mVariable2; +} + /* * Returns the value of the "variableType" attribute of this @@ -238,7 +248,7 @@ UserDefinedConstraintComponent::isSetName() const bool UserDefinedConstraintComponent::isSetCoefficient() const { - return mIsSetCoefficient; + return (mCoefficient.empty() == false); } @@ -253,6 +263,16 @@ UserDefinedConstraintComponent::isSetVariable() const } +/* + * Predicate returning @c true if this UserDefinedConstraintComponent's + * "variable2" attribute is set. + */ +bool +UserDefinedConstraintComponent::isSetVariable2() const +{ + return (mVariable2.empty() == false); +} + /* * Predicate returning @c true if this UserDefinedConstraintComponent's * "variableType" attribute is set. @@ -313,7 +333,7 @@ UserDefinedConstraintComponent::setName(const std::string& name) * UserDefinedConstraintComponent. */ int -UserDefinedConstraintComponent::setCoefficient(double coefficient) +UserDefinedConstraintComponent::setCoefficient(const std::string& coefficient) { unsigned int coreLevel = getLevel(); unsigned int coreVersion = getVersion(); @@ -322,13 +342,10 @@ UserDefinedConstraintComponent::setCoefficient(double coefficient) if (coreLevel == 3 && coreVersion == 1 && pkgVersion == 3) { mCoefficient = coefficient; - mIsSetCoefficient = true; return LIBSBML_OPERATION_SUCCESS; } else { - mCoefficient = coefficient; - mIsSetCoefficient = false; return LIBSBML_UNEXPECTED_ATTRIBUTE; } } @@ -364,6 +381,35 @@ UserDefinedConstraintComponent::setVariable(const std::string& variable) } +/* + * Sets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + */ +int +UserDefinedConstraintComponent::setVariable2(const std::string& variable) +{ + unsigned int coreLevel = getLevel(); + unsigned int coreVersion = getVersion(); + unsigned int pkgVersion = getPackageVersion(); + + if (coreLevel == 3 && coreVersion == 1 && pkgVersion == 3) + { + if (!(SyntaxChecker::isValidInternalSId(variable))) + { + return LIBSBML_INVALID_ATTRIBUTE_VALUE; + } + else + { + mVariable2 = variable; + return LIBSBML_OPERATION_SUCCESS; + } + } + else + { + return LIBSBML_UNEXPECTED_ATTRIBUTE; + } +} + /* * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -473,8 +519,7 @@ UserDefinedConstraintComponent::unsetName() int UserDefinedConstraintComponent::unsetCoefficient() { - mCoefficient = util_NaN(); - mIsSetCoefficient = false; + mCoefficient.erase(); if (isSetCoefficient() == false) { @@ -507,6 +552,25 @@ UserDefinedConstraintComponent::unsetVariable() } +/* + * Unsets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + */ +int +UserDefinedConstraintComponent::unsetVariable2() +{ + mVariable2.erase(); + + if (mVariable2.empty() == true) + { + return LIBSBML_OPERATION_SUCCESS; + } + else + { + return LIBSBML_OPERATION_FAILED; + } +} + /* * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -526,10 +590,18 @@ void UserDefinedConstraintComponent::renameSIdRefs(const std::string& oldid, const std::string& newid) { + if (isSetCoefficient() && mCoefficient == oldid) + { + setCoefficient(newid); + } if (isSetVariable() && mVariable == oldid) { setVariable(newid); } + if (isSetVariable2() && mVariable2 == oldid) + { + setVariable2(newid); + } } @@ -719,12 +791,6 @@ UserDefinedConstraintComponent::getAttribute(const std::string& attributeName, return return_value; } - if (attributeName == "coefficient") - { - value = getCoefficient(); - return_value = LIBSBML_OPERATION_SUCCESS; - } - return return_value; } @@ -788,6 +854,16 @@ UserDefinedConstraintComponent::getAttribute(const std::string& attributeName, value = getVariableTypeAsString(); return_value = LIBSBML_OPERATION_SUCCESS; } + else if (attributeName == "coefficient") + { + value = getCoefficient(); + return_value = LIBSBML_OPERATION_SUCCESS; + } + else if (attributeName == "variable2") + { + value = getVariable2(); + return_value = LIBSBML_OPERATION_SUCCESS; + } return return_value; } @@ -828,6 +904,10 @@ UserDefinedConstraintComponent::isSetAttribute(const std::string& { value = isSetVariableType(); } + else if (attributeName == "variable2") + { + value = isSetVariable2(); + } return value; } @@ -886,11 +966,6 @@ UserDefinedConstraintComponent::setAttribute(const std::string& attributeName, { int return_value = SBase::setAttribute(attributeName, value); - if (attributeName == "coefficient") - { - return_value = setCoefficient(value); - } - return return_value; } @@ -945,6 +1020,14 @@ UserDefinedConstraintComponent::setAttribute(const std::string& attributeName, { return_value = setVariableType(value); } + else if (attributeName == "coefficient") + { + return_value = setCoefficient(value); + } + else if (attributeName == "variable2") + { + return_value = setVariable2(value); + } return return_value; } @@ -985,6 +1068,10 @@ UserDefinedConstraintComponent::unsetAttribute(const std::string& { value = unsetVariableType(); } + else if (attributeName == "variable2") + { + value = unsetVariable2(); + } return value; } @@ -1015,6 +1102,7 @@ UserDefinedConstraintComponent::addExpectedAttributes(ExpectedAttributes& attributes.add("coefficient"); attributes.add("variable"); attributes.add("variableType"); + attributes.add("variable2"); } } @@ -1166,21 +1254,24 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes& // numErrs = log ? log->getNumErrors() : 0; - mIsSetCoefficient = attributes.readInto("coefficient", mCoefficient); + assigned = attributes.readInto("coefficient", mCoefficient); - if ( mIsSetCoefficient == false && log) + if (assigned == true) { - if (log && log->getNumErrors() == numErrs + 1 && - log->contains(XMLAttributeTypeMismatch)) + if (mId.empty() == true) { - log->remove(XMLAttributeTypeMismatch); - std::string message = "Fbc attribute 'coefficient' from the " - " element must be a double."; - log->logPackageError("fbc", - FbcUserDefinedConstraintComponentCoefficientMustBeDouble, pkgVersion, - level, version, message, getLine(), getColumn()); + logEmptyString(mCoefficient, level, version, ""); } - else + else if (SyntaxChecker::isValidSBMLSId(mCoefficient) == false) + { + log->logPackageError("fbc", FbcSBMLSIdSyntax, pkgVersion, level, version, + "The coefficient on the <" + getElementName() + "> is '" + mCoefficient + "', which does " + "not conform to the syntax.", getLine(), getColumn()); + } + } + else + { + if (log) { std::string message = "Fbc attribute 'coefficient' is missing from the " " element."; @@ -1274,6 +1365,35 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes& version, message, getLine(), getColumn()); } } + + // + // variable2 SIdRef (use = "optional" ) + // + + assigned = attributes.readInto("variable2", mVariable2); + + if (assigned == true) + { + if (mVariable2.empty() == true) + { + logEmptyString(mVariable2, level, version, + ""); + } + else if (SyntaxChecker::isValidSBMLSId(mVariable2) == false) + { + std::string msg = "The variable2 attribute on the <" + getElementName() + + ">"; + if (isSetId()) + { + msg += " with id '" + getId() + "'"; + } + + msg += " is '" + mVariable2 + "', which does not conform to the syntax."; + log->logPackageError("fbc", FbcSBMLSIdSyntax, pkgVersion, level, version, msg, + getLine(), getColumn()); + } + } + } /** @endcond */ @@ -1340,6 +1460,12 @@ UserDefinedConstraintComponent::writeL3V1V3Attributes(XMLOutputStream& stream) stream.writeAttribute("variableType", getPrefix(), FbcVariableType_toString(mVariableType)); } + + if (isSetVariable2() == true) + { + stream.writeAttribute("variable2", getPrefix(), mVariable2); + } + } /** @endcond */ @@ -1439,11 +1565,16 @@ UserDefinedConstraintComponent_getName(const UserDefinedConstraintComponent_t * * UserDefinedConstraintComponent_t. */ LIBSBML_EXTERN -double +char* UserDefinedConstraintComponent_getCoefficient(const UserDefinedConstraintComponent_t * udcc) { - return (udcc != NULL) ? udcc->getCoefficient() : util_NaN(); + if (udcc == NULL) + { + return NULL; + } + + return udcc->getName().empty() ? NULL : safe_strdup(udcc->getCoefficient().c_str()); } @@ -1465,6 +1596,24 @@ UserDefinedConstraintComponent_getVariable(const safe_strdup(udcc->getVariable().c_str()); } +/* + * Returns the value of the "variable" attribute of this + * UserDefinedConstraintComponent_t. + */ +LIBSBML_EXTERN +char * +UserDefinedConstraintComponent_getVariable2(const + UserDefinedConstraintComponent_t * udcc) +{ + if (udcc == NULL) + { + return NULL; + } + + return udcc->getVariable2().empty() ? NULL : + safe_strdup(udcc->getVariable2().c_str()); +} + /* * Returns the value of the "variableType" attribute of this @@ -1548,6 +1697,17 @@ UserDefinedConstraintComponent_isSetVariable(const return (udcc != NULL) ? static_cast(udcc->isSetVariable()) : 0; } +/* + * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's + * "variable2" attribute is set. + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_isSetVariable2(const + UserDefinedConstraintComponent_t * udcc) +{ + return (udcc != NULL) ? static_cast(udcc->isSetVariable2()) : 0; +} /* * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's @@ -1597,7 +1757,7 @@ int UserDefinedConstraintComponent_setCoefficient( UserDefinedConstraintComponent_t * udcc, - double coefficient) + const char* coefficient) { return (udcc != NULL) ? udcc->setCoefficient(coefficient) : LIBSBML_INVALID_OBJECT; @@ -1619,6 +1779,21 @@ UserDefinedConstraintComponent_setVariable( } +/* + * Sets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_setVariable2( + UserDefinedConstraintComponent_t * + udcc, + const char * variable) +{ + return (udcc != NULL) ? udcc->setVariable2(variable) : LIBSBML_INVALID_OBJECT; +} + + /* * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. @@ -1702,6 +1877,17 @@ UserDefinedConstraintComponent_unsetVariable(UserDefinedConstraintComponent_t * return (udcc != NULL) ? udcc->unsetVariable() : LIBSBML_INVALID_OBJECT; } +/* + * Unsets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t * + udcc) +{ + return (udcc != NULL) ? udcc->unsetVariable2() : LIBSBML_INVALID_OBJECT; +} /* * Unsets the value of the "variableType" attribute of this diff --git a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h index ca7a41d5ce..87edf2a314 100644 --- a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h +++ b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h @@ -93,10 +93,10 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase /** @cond doxygenLibsbmlInternal */ - double mCoefficient; - bool mIsSetCoefficient; + std::string mCoefficient; std::string mVariable; FbcVariableType_t mVariableType; + std::string mVariable2; /** @endcond */ @@ -196,9 +196,9 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase * UserDefinedConstraintComponent. * * @return the value of the "coefficient" attribute of this - * UserDefinedConstraintComponent as a double. + * UserDefinedConstraintComponent as a string. */ - double getCoefficient() const; + const std::string& getCoefficient() const; /** @@ -211,6 +211,15 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase const std::string& getVariable() const; + /** + * Returns the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + * + * @return the value of the "variable2" attribute of this + * UserDefinedConstraintComponent as a string. + */ + const std::string& getVariable2() const; + /** * Returns the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -285,6 +294,15 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase bool isSetVariable() const; + /** + * Predicate returning @c true if this UserDefinedConstraintComponent's + * "variable2" attribute is set. + * + * @return @c true if this UserDefinedConstraintComponent's "variable2" + * attribute has been set, otherwise @c false is returned. + */ + bool isSetVariable2() const; + /** * Predicate returning @c true if this UserDefinedConstraintComponent's * "variableType" attribute is set. @@ -333,14 +351,14 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase * Sets the value of the "coefficient" attribute of this * UserDefinedConstraintComponent. * - * @param coefficient double value of the "coefficient" attribute to be set. + * @param coefficient string value of the "coefficient" attribute to be set. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, * OperationReturnValues_t} */ - int setCoefficient(double coefficient); + int setCoefficient(const std::string& coefficient); /** @@ -357,6 +375,19 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase int setVariable(const std::string& variable); + /** + * Sets the value of the "variable" attribute of this + * UserDefinedConstraintComponent. + * + * @param variable std::string& value of the "variable2" attribute to be set. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, + * OperationReturnValues_t} + */ + int setVariable2(const std::string& variable); + /** * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -435,6 +466,16 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase int unsetVariable(); + /** + * Unsets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} + */ + int unsetVariable2(); + /** * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -988,12 +1029,14 @@ UserDefinedConstraintComponent_getName(const UserDefinedConstraintComponent_t * * is sought. * * @return the value of the "coefficient" attribute of this - * UserDefinedConstraintComponent_t as a double. + * UserDefinedConstraintComponent_t as a pointer to a string. + * + * @copydetails doc_returned_owned_char * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN -double +char* UserDefinedConstraintComponent_getCoefficient(const UserDefinedConstraintComponent_t * udcc); @@ -1070,6 +1113,26 @@ UserDefinedConstraintComponent_getVariableTypeAsString(const UserDefinedConstraintComponent_t * udcc); +/** + * Returns the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + * + * @param udcc the UserDefinedConstraintComponent_t structure whose variable is + * sought. + * + * @return the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t as a pointer to a string. + * + * @copydetails doc_returned_owned_char + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +char * +UserDefinedConstraintComponent_getVariable2(const + UserDefinedConstraintComponent_t * udcc); + + /** * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's * "id" attribute is set. @@ -1157,6 +1220,23 @@ UserDefinedConstraintComponent_isSetVariableType(const UserDefinedConstraintComponent_t * udcc); +/** + * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's + * "variable2" attribute is set. + * + * @param udcc the UserDefinedConstraintComponent_t structure. + * + * @return @c 1 (true) if this UserDefinedConstraintComponent_t's "variable2" + * attribute has been set, otherwise @c 0 (false) is returned. + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_isSetVariable2(const + UserDefinedConstraintComponent_t * udcc); + + /** * Sets the value of the "id" attribute of this * UserDefinedConstraintComponent_t. @@ -1210,7 +1290,7 @@ UserDefinedConstraintComponent_setName(UserDefinedConstraintComponent_t * udcc, * * @param udcc the UserDefinedConstraintComponent_t structure. * - * @param coefficient double value of the "coefficient" attribute to be set. + * @param coefficient const char* value of the "coefficient" attribute to be set. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} @@ -1224,7 +1304,7 @@ int UserDefinedConstraintComponent_setCoefficient( UserDefinedConstraintComponent_t * udcc, - double coefficient); + const char* coefficient); /** @@ -1302,6 +1382,29 @@ UserDefinedConstraintComponent_setVariableTypeAsString( variableType); +/** + * Sets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + * + * @param udcc the UserDefinedConstraintComponent_t structure. + * + * @param variable const char * value of the "variable2" attribute to be set. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_setVariable2( + UserDefinedConstraintComponent_t * + udcc, + const char * variable); + + /** * Unsets the value of the "id" attribute of this * UserDefinedConstraintComponent_t. @@ -1398,6 +1501,25 @@ UserDefinedConstraintComponent_unsetVariableType(UserDefinedConstraintComponent_ * udcc); +/** + * Unsets the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + * + * @param udcc the UserDefinedConstraintComponent_t structure. + * + * @copydetails doc_returns_success_code + * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t * + udcc); + + /** * Predicate returning @c 1 (true) if all the required attributes for this * UserDefinedConstraintComponent_t object have been set. From 9816eb75bda095021ea181326e65e0c2706e174d Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Fri, 15 Sep 2023 12:23:56 +0200 Subject: [PATCH 2/8] - update matlab test file --- src/bindings/matlab/test/test-data/fbcV3.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/matlab/test/test-data/fbcV3.xml b/src/bindings/matlab/test/test-data/fbcV3.xml index 2f34912ec4..eb2bb29874 100644 --- a/src/bindings/matlab/test/test-data/fbcV3.xml +++ b/src/bindings/matlab/test/test-data/fbcV3.xml @@ -75,7 +75,7 @@ - + From 5a54f1573762aff6ec1a132d46e2a17ce62c35c3 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Fri, 15 Sep 2023 12:40:09 +0200 Subject: [PATCH 3/8] - updated matlab test file --- src/bindings/matlab/test/testReadFromFileFbc3.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/matlab/test/testReadFromFileFbc3.m b/src/bindings/matlab/test/testReadFromFileFbc3.m index c6cf6ea452..d554c941c9 100644 --- a/src/bindings/matlab/test/testReadFromFileFbc3.m +++ b/src/bindings/matlab/test/testReadFromFileFbc3.m @@ -77,8 +77,8 @@ Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).typecode, 'SBML_FBC_USERDEFINEDCONSTRAINTCOMPONENT')); Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_id, 'dd')); - Totalfail = Totalfail + fail_unless( m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_coefficient == 2); Totalfail = Totalfail + fail_unless( m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).isSetfbc_coefficient == 1); + Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_coefficient, 'uc2ub')); Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_variable, 'R2')); Totalfail = Totalfail + fail_unless( strcmp(m.fbc_userDefinedConstraint(1).fbc_userDefinedConstraintComponent(1).fbc_variableType, 'linear')); From 876212b76fa5d66e6bbffffade2e95771a6681ee Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Fri, 15 Sep 2023 14:05:59 +0200 Subject: [PATCH 4/8] - fix validation of coefficient --- .../packages/fbc/sbml/UserDefinedConstraintComponent.cpp | 7 ++++--- .../{2021304-fail-01-01.xml => 2010302-fail-01-01.xml} | 2 +- .../test-data/general-constraints/2020206-fail-01-05.xml | 2 +- .../test-data/general-constraints/2020213-pass-00-01.xml | 2 +- .../test-data/general-constraints/2020214-fail-01-01.xml | 2 +- .../test-data/general-constraints/2020214-pass-00-01.xml | 2 +- .../test-data/general-constraints/2021301-pass-00-01.xml | 2 +- .../test-data/general-constraints/2021302-pass-00-01.xml | 2 +- .../test-data/general-constraints/2021303-fail-01-01.xml | 2 +- .../test-data/general-constraints/2021303-pass-00-01.xml | 2 +- .../test-data/general-constraints/2021305-fail-01-01.xml | 2 +- .../test-data/general-constraints/2021305-pass-00-01.xml | 2 +- .../test-data/general-constraints/2021305-pass-00-02.xml | 2 +- .../test-data/general-constraints/2021306-fail-01-01.xml | 2 +- .../test-data/general-constraints/2021306-pass-00-01.xml | 2 +- .../test-data/general-constraints/2021401-pass-00-01.xml | 2 +- .../test-data/general-constraints/2021403-fail-01-01.xml | 2 +- .../test-data/general-constraints/2021403-fail-01-02.xml | 2 +- .../test-data/general-constraints/2021405-fail-01-01.xml | 2 +- .../test-data/general-constraints/2021406-fail-01-01.xml | 2 +- .../test-data/general-constraints/2021408-pass-00-01.xml | 2 +- .../test-data/general-constraints/2021409-fail-01-01.xml | 2 +- 22 files changed, 25 insertions(+), 24 deletions(-) rename src/sbml/packages/fbc/validator/test/test-data/general-constraints/{2021304-fail-01-01.xml => 2010302-fail-01-01.xml} (98%) diff --git a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp index b43fe422eb..54ff6115e7 100644 --- a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp +++ b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp @@ -1254,13 +1254,14 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes& // numErrs = log ? log->getNumErrors() : 0; - assigned = attributes.readInto("coefficient", mCoefficient); + XMLTriple tripleCOEFF("coefficient", mURI, getPrefix()); + assigned = attributes.readInto(tripleCOEFF, mCoefficient); if (assigned == true) { - if (mId.empty() == true) + if (mCoefficient.empty() == true) { - logEmptyString(mCoefficient, level, version, ""); + logEmptyString("coefficient", level, version, ""); } else if (SyntaxChecker::isValidSBMLSId(mCoefficient) == false) { diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021304-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2010302-fail-01-01.xml similarity index 98% rename from src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021304-fail-01-01.xml rename to src/sbml/packages/fbc/validator/test/test-data/general-constraints/2010302-fail-01-01.xml index 0edb76efb9..e39084567d 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021304-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2010302-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020206-fail-01-05.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020206-fail-01-05.xml index 7b1a464f3d..c07d0c43e1 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020206-fail-01-05.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020206-fail-01-05.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020213-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020213-pass-00-01.xml index 97d1e172af..41dabf5830 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020213-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020213-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-fail-01-01.xml index fdfd0f5d54..be9eb3217f 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-pass-00-01.xml index 52e2749368..00db78cbf0 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2020214-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021301-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021301-pass-00-01.xml index ae0e9198c2..d79c6e883a 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021301-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021301-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021302-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021302-pass-00-01.xml index 00ba00c5aa..1ed5e144fd 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021302-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021302-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml index bfb1c4ddfb..ddd1ab1d94 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-pass-00-01.xml index ccf42db1ac..12b604f1f9 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-fail-01-01.xml index 91d01b97bb..c013a92f89 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-01.xml index 838d64f7fc..acf02cd1ca 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-02.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-02.xml index e1b61fc2f0..b2e83d10f1 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-02.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021305-pass-00-02.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-fail-01-01.xml index fd1767b838..0827303736 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-fail-01-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-pass-00-01.xml index 97f00c5129..5b919a0b60 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021306-pass-00-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021401-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021401-pass-00-01.xml index 5ca442321a..122c0545ab 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021401-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021401-pass-00-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-01.xml index 3f4823dec4..d802d00b5f 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-02.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-02.xml index a8beb24d0f..0c7c176d50 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-02.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021403-fail-01-02.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021405-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021405-fail-01-01.xml index 130d6860e3..aa3ab7c9d1 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021405-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021405-fail-01-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021406-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021406-fail-01-01.xml index 0467bf3491..5df88201a7 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021406-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021406-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021408-pass-00-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021408-pass-00-01.xml index 378615e533..148584f896 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021408-pass-00-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021408-pass-00-01.xml @@ -81,7 +81,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021409-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021409-fail-01-01.xml index 78385bf1ee..8eb5fe3936 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021409-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021409-fail-01-01.xml @@ -80,7 +80,7 @@ - + From c2e165605d0ebf91bfd18e0f53e9f7e059e3554d Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Fri, 15 Sep 2023 14:09:07 +0200 Subject: [PATCH 5/8] - fix another test file --- .../packages/fbc/extension/test/test-data/fbc_examplev3.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml b/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml index 85ce707a8b..b73b4e1db1 100644 --- a/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml +++ b/src/sbml/packages/fbc/extension/test/test-data/fbc_examplev3.xml @@ -21,7 +21,7 @@ - + From 45ab62e8a9abc2ca123165d5755d44a9b3cc9988 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Fri, 15 Sep 2023 15:02:27 +0200 Subject: [PATCH 6/8] - the default should not be nan for a string --- src/bindings/matlab/getDefaultValues.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/matlab/getDefaultValues.m b/src/bindings/matlab/getDefaultValues.m index 19d12aeb21..4913b9fd82 100644 --- a/src/bindings/matlab/getDefaultValues.m +++ b/src/bindings/matlab/getDefaultValues.m @@ -3565,7 +3565,7 @@ int32(-1), ... '', ... '', ... - 0/0, ... + '', ... int32(0), ... '', ... '', ... From 7013ab7f88baa2c7641a57b4b0aed94080a10ec9 Mon Sep 17 00:00:00 2001 From: "Frank T. Bergmann" Date: Fri, 15 Sep 2023 15:40:59 +0200 Subject: [PATCH 7/8] - change value type --- src/bindings/matlab/getValueType.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bindings/matlab/getValueType.m b/src/bindings/matlab/getValueType.m index 68b4f3be77..4a45982f63 100644 --- a/src/bindings/matlab/getValueType.m +++ b/src/bindings/matlab/getValueType.m @@ -3568,7 +3568,7 @@ 'int', ... 'char', ... 'char', ... - 'double', ... + 'char', ... 'bool', ... 'char', ... 'char', ... From aee04c30dee025210da7928835bd4793a6e67a50 Mon Sep 17 00:00:00 2001 From: skeating Date: Tue, 19 Sep 2023 11:32:52 +0100 Subject: [PATCH 8/8] adding validation --- dev/packages/deviser-fbc_v3.xml | 4 +- .../sbml/UserDefinedConstraintComponent.cpp | 135 +++++++++++------- .../fbc/sbml/UserDefinedConstraintComponent.h | 124 +++++++++++----- .../packages/fbc/validator/FbcSBMLError.h | 6 +- .../fbc/validator/FbcSBMLErrorTable.h | 64 ++++++++- .../constraints/FbcConsistencyConstraints.cpp | 88 +++++++++++- .../FbcConsistencyConstraintsDeclared.cxx | 6 + .../2010302-fail-01-01.xml | 88 ------------ .../2021303-fail-01-01.xml | 2 +- .../2010302-fail-01-01.xml | 2 +- 10 files changed, 328 insertions(+), 191 deletions(-) delete mode 100644 src/sbml/packages/fbc/validator/test/test-data/general-constraints/2010302-fail-01-01.xml diff --git a/dev/packages/deviser-fbc_v3.xml b/dev/packages/deviser-fbc_v3.xml index 3b389757a7..c820afefae 100644 --- a/dev/packages/deviser-fbc_v3.xml +++ b/dev/packages/deviser-fbc_v3.xml @@ -168,6 +168,7 @@ + @@ -226,8 +227,9 @@ - + + diff --git a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp index 54ff6115e7..d62ed00d53 100644 --- a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp +++ b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.cpp @@ -65,8 +65,8 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent( : SBase(level, version) , mCoefficient ("") , mVariable ("") - , mVariableType (FBC_VARIABLE_TYPE_INVALID) , mVariable2 ("") + , mVariableType (FBC_VARIABLE_TYPE_INVALID) { setSBMLNamespacesAndOwn(new FbcPkgNamespaces(level, version, pkgVersion)); } @@ -81,8 +81,8 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent(FbcPkgNamespaces : SBase(fbcns) , mCoefficient ("") , mVariable ("") - , mVariableType (FBC_VARIABLE_TYPE_INVALID) , mVariable2 ("") + , mVariableType (FBC_VARIABLE_TYPE_INVALID) { setElementNamespace(fbcns->getURI()); loadPlugins(fbcns); @@ -97,8 +97,8 @@ UserDefinedConstraintComponent::UserDefinedConstraintComponent(const : SBase( orig ) , mCoefficient ( orig.mCoefficient ) , mVariable ( orig.mVariable ) - , mVariableType ( orig.mVariableType ) , mVariable2 ( orig.mVariable2 ) + , mVariableType ( orig.mVariableType ) { } @@ -115,8 +115,8 @@ UserDefinedConstraintComponent::operator=(const UserDefinedConstraintComponent& SBase::operator=(rhs); mCoefficient = rhs.mCoefficient; mVariable = rhs.mVariable; - mVariableType = rhs.mVariableType; mVariable2 = rhs.mVariable2; + mVariableType = rhs.mVariableType; } return *this; @@ -185,6 +185,7 @@ UserDefinedConstraintComponent::getVariable() const return mVariable; } + /* * Returns the value of the "variable2" attribute of this * UserDefinedConstraintComponent. @@ -273,6 +274,7 @@ UserDefinedConstraintComponent::isSetVariable2() const return (mVariable2.empty() == false); } + /* * Predicate returning @c true if this UserDefinedConstraintComponent's * "variableType" attribute is set. @@ -341,8 +343,15 @@ UserDefinedConstraintComponent::setCoefficient(const std::string& coefficient) if (coreLevel == 3 && coreVersion == 1 && pkgVersion == 3) { - mCoefficient = coefficient; - return LIBSBML_OPERATION_SUCCESS; + if (!(SyntaxChecker::isValidInternalSId(coefficient))) + { + return LIBSBML_INVALID_ATTRIBUTE_VALUE; + } + else + { + mCoefficient = coefficient; + return LIBSBML_OPERATION_SUCCESS; + } } else { @@ -410,6 +419,7 @@ UserDefinedConstraintComponent::setVariable2(const std::string& variable) } } + /* * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -521,7 +531,7 @@ UserDefinedConstraintComponent::unsetCoefficient() { mCoefficient.erase(); - if (isSetCoefficient() == false) + if (mCoefficient.empty() == true) { return LIBSBML_OPERATION_SUCCESS; } @@ -571,6 +581,7 @@ UserDefinedConstraintComponent::unsetVariable2() } } + /* * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -594,10 +605,12 @@ UserDefinedConstraintComponent::renameSIdRefs(const std::string& oldid, { setCoefficient(newid); } + if (isSetVariable() && mVariable == oldid) { setVariable(newid); } + if (isSetVariable2() && mVariable2 == oldid) { setVariable2(newid); @@ -786,11 +799,6 @@ UserDefinedConstraintComponent::getAttribute(const std::string& attributeName, { int return_value = SBase::getAttribute(attributeName, value); - if (return_value == LIBSBML_OPERATION_SUCCESS) - { - return return_value; - } - return return_value; } @@ -844,24 +852,24 @@ UserDefinedConstraintComponent::getAttribute(const std::string& attributeName, value = getName(); return_value = LIBSBML_OPERATION_SUCCESS; } - else if (attributeName == "variable") + else if (attributeName == "coefficient") { - value = getVariable(); + value = getCoefficient(); return_value = LIBSBML_OPERATION_SUCCESS; } - else if (attributeName == "variableType") + else if (attributeName == "variable") { - value = getVariableTypeAsString(); + value = getVariable(); return_value = LIBSBML_OPERATION_SUCCESS; } - else if (attributeName == "coefficient") + else if (attributeName == "variable2") { - value = getCoefficient(); + value = getVariable2(); return_value = LIBSBML_OPERATION_SUCCESS; } - else if (attributeName == "variable2") + else if (attributeName == "variableType") { - value = getVariable2(); + value = getVariableTypeAsString(); return_value = LIBSBML_OPERATION_SUCCESS; } @@ -900,14 +908,14 @@ UserDefinedConstraintComponent::isSetAttribute(const std::string& { value = isSetVariable(); } - else if (attributeName == "variableType") - { - value = isSetVariableType(); - } else if (attributeName == "variable2") { value = isSetVariable2(); } + else if (attributeName == "variableType") + { + value = isSetVariableType(); + } return value; } @@ -1012,22 +1020,22 @@ UserDefinedConstraintComponent::setAttribute(const std::string& attributeName, { return_value = setName(value); } - else if (attributeName == "variable") - { - return_value = setVariable(value); - } - else if (attributeName == "variableType") - { - return_value = setVariableType(value); - } else if (attributeName == "coefficient") { return_value = setCoefficient(value); } + else if (attributeName == "variable") + { + return_value = setVariable(value); + } else if (attributeName == "variable2") { return_value = setVariable2(value); } + else if (attributeName == "variableType") + { + return_value = setVariableType(value); + } return return_value; } @@ -1064,14 +1072,14 @@ UserDefinedConstraintComponent::unsetAttribute(const std::string& { value = unsetVariable(); } - else if (attributeName == "variableType") - { - value = unsetVariableType(); - } else if (attributeName == "variable2") { value = unsetVariable2(); } + else if (attributeName == "variableType") + { + value = unsetVariableType(); + } return value; } @@ -1101,8 +1109,8 @@ UserDefinedConstraintComponent::addExpectedAttributes(ExpectedAttributes& attributes.add("name"); attributes.add("coefficient"); attributes.add("variable"); - attributes.add("variableType"); attributes.add("variable2"); + attributes.add("variableType"); } } @@ -1250,12 +1258,12 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes& } // - // coefficient double (use = "required" ) + // coefficient SIdRef (use = "required" ) // numErrs = log ? log->getNumErrors() : 0; XMLTriple tripleCOEFF("coefficient", mURI, getPrefix()); - assigned = attributes.readInto(tripleCOEFF, mCoefficient); + assigned = attributes.readInto("coefficient", mCoefficient); if (assigned == true) { @@ -1321,6 +1329,34 @@ UserDefinedConstraintComponent::readL3V1V3Attributes(const XMLAttributes& } } + // + // variable2 SIdRef (use = "optional" ) + // + + assigned = attributes.readInto("variable2", mVariable2); + + if (assigned == true) + { + if (mVariable2.empty() == true) + { + logEmptyString(mVariable2, level, version, + ""); + } + else if (SyntaxChecker::isValidSBMLSId(mVariable2) == false) + { + std::string msg = "The variable2 attribute on the <" + getElementName() + + ">"; + if (isSetId()) + { + msg += " with id '" + getId() + "'"; + } + + msg += " is '" + mVariable2 + "', which does not conform to the syntax."; + log->logPackageError("fbc", FbcSBMLSIdSyntax, pkgVersion, level, version, msg, + getLine(), getColumn()); + } + } + // // variableType enum (use = "required" ) // @@ -1456,17 +1492,16 @@ UserDefinedConstraintComponent::writeL3V1V3Attributes(XMLOutputStream& stream) stream.writeAttribute("variable", getPrefix(), mVariable); } - if (isSetVariableType() == true) - { - stream.writeAttribute("variableType", getPrefix(), - FbcVariableType_toString(mVariableType)); - } - if (isSetVariable2() == true) { stream.writeAttribute("variable2", getPrefix(), mVariable2); } + if (isSetVariableType() == true) + { + stream.writeAttribute("variableType", getPrefix(), + FbcVariableType_toString(mVariableType)); + } } /** @endcond */ @@ -1698,6 +1733,7 @@ UserDefinedConstraintComponent_isSetVariable(const return (udcc != NULL) ? static_cast(udcc->isSetVariable()) : 0; } + /* * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's * "variable2" attribute is set. @@ -1710,6 +1746,7 @@ UserDefinedConstraintComponent_isSetVariable2(const return (udcc != NULL) ? static_cast(udcc->isSetVariable2()) : 0; } + /* * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's * "variableType" attribute is set. @@ -1758,7 +1795,7 @@ int UserDefinedConstraintComponent_setCoefficient( UserDefinedConstraintComponent_t * udcc, - const char* coefficient) + const char * coefficient) { return (udcc != NULL) ? udcc->setCoefficient(coefficient) : LIBSBML_INVALID_OBJECT; @@ -1878,18 +1915,20 @@ UserDefinedConstraintComponent_unsetVariable(UserDefinedConstraintComponent_t * return (udcc != NULL) ? udcc->unsetVariable() : LIBSBML_INVALID_OBJECT; } + /* * Unsets the value of the "variable2" attribute of this * UserDefinedConstraintComponent_t. */ LIBSBML_EXTERN int -UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t * - udcc) +UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t + * udcc) { return (udcc != NULL) ? udcc->unsetVariable2() : LIBSBML_INVALID_OBJECT; } + /* * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. diff --git a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h index 87edf2a314..59def6fb59 100644 --- a/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h +++ b/src/sbml/packages/fbc/sbml/UserDefinedConstraintComponent.h @@ -95,8 +95,8 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase std::string mCoefficient; std::string mVariable; - FbcVariableType_t mVariableType; std::string mVariable2; + FbcVariableType_t mVariableType; /** @endcond */ @@ -220,6 +220,7 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase */ const std::string& getVariable2() const; + /** * Returns the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -303,6 +304,7 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase */ bool isSetVariable2() const; + /** * Predicate returning @c true if this UserDefinedConstraintComponent's * "variableType" attribute is set. @@ -351,12 +353,14 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase * Sets the value of the "coefficient" attribute of this * UserDefinedConstraintComponent. * - * @param coefficient string value of the "coefficient" attribute to be set. + * @param coefficient std::string& value of the "coefficient" attribute to be + * set. * - * @copydetails doc_returns_success_code + * @copydetails doc_returns_one_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} - * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, - * OperationReturnValues_t} + * + * Calling this function with @p coefficient = @c NULL or an empty string is + * equivalent to calling unsetCoefficient(). */ int setCoefficient(const std::string& coefficient); @@ -376,7 +380,7 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase /** - * Sets the value of the "variable" attribute of this + * Sets the value of the "variable2" attribute of this * UserDefinedConstraintComponent. * * @param variable std::string& value of the "variable2" attribute to be set. @@ -388,6 +392,7 @@ class LIBSBML_EXTERN UserDefinedConstraintComponent : public SBase */ int setVariable2(const std::string& variable); + /** * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent. @@ -1031,12 +1036,12 @@ UserDefinedConstraintComponent_getName(const UserDefinedConstraintComponent_t * * @return the value of the "coefficient" attribute of this * UserDefinedConstraintComponent_t as a pointer to a string. * - * @copydetails doc_returned_owned_char + * @copydetails doc_returned_owned_char * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN -char* +char * UserDefinedConstraintComponent_getCoefficient(const UserDefinedConstraintComponent_t * udcc); @@ -1061,6 +1066,26 @@ UserDefinedConstraintComponent_getVariable(const UserDefinedConstraintComponent_t * udcc); +/** + * Returns the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t. + * + * @param udcc the UserDefinedConstraintComponent_t structure whose variable2 + * is sought. + * + * @return the value of the "variable2" attribute of this + * UserDefinedConstraintComponent_t as a pointer to a string. + * + * @copydetails doc_returned_owned_char + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +char * +UserDefinedConstraintComponent_getVariable2(const + UserDefinedConstraintComponent_t * udcc); + + /** * Returns the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. @@ -1201,6 +1226,23 @@ UserDefinedConstraintComponent_isSetVariable(const UserDefinedConstraintComponent_t * udcc); +/** + * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's + * "variable2" attribute is set. + * + * @param udcc the UserDefinedConstraintComponent_t structure. + * + * @return @c 1 (true) if this UserDefinedConstraintComponent_t's "variable2" + * attribute has been set, otherwise @c 0 (false) is returned. + * + * @memberof UserDefinedConstraintComponent_t + */ +LIBSBML_EXTERN +int +UserDefinedConstraintComponent_isSetVariable2(const + UserDefinedConstraintComponent_t * udcc); + + /** * Predicate returning @c 1 (true) if this UserDefinedConstraintComponent_t's * "variableType" attribute is set. @@ -1290,13 +1332,17 @@ UserDefinedConstraintComponent_setName(UserDefinedConstraintComponent_t * udcc, * * @param udcc the UserDefinedConstraintComponent_t structure. * - * @param coefficient const char* value of the "coefficient" attribute to be set. + * @param coefficient const char * value of the "coefficient" attribute to be + * set. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} * + * Calling this function with @p coefficient = @c NULL or an empty string is + * equivalent to calling UserDefinedConstraintComponent_unsetCoefficient(). + * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN @@ -1304,7 +1350,7 @@ int UserDefinedConstraintComponent_setCoefficient( UserDefinedConstraintComponent_t * udcc, - const char* coefficient); + const char * coefficient); /** @@ -1331,29 +1377,26 @@ UserDefinedConstraintComponent_setVariable( /** - * Sets the value of the "variableType" attribute of this + * Sets the value of the "variable2" attribute of this * UserDefinedConstraintComponent_t. * * @param udcc the UserDefinedConstraintComponent_t structure. * - * @param variableType FbcVariableType_t value of the "variableType" attribute - * to be set. + * @param variable2 const char * value of the "variable2" attribute to be set. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} * - * @copydetails doc_userdefinedconstraintcomponent_variableType - * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN int -UserDefinedConstraintComponent_setVariableType( - UserDefinedConstraintComponent_t - * udcc, - FbcVariableType_t variableType); +UserDefinedConstraintComponent_setVariable2( + UserDefinedConstraintComponent_t * + udcc, + const char * variable2); /** @@ -1362,7 +1405,8 @@ UserDefinedConstraintComponent_setVariableType( * * @param udcc the UserDefinedConstraintComponent_t structure. * - * @param variableType const char * of the "variableType" attribute to be set. + * @param variableType FbcVariableType_t value of the "variableType" attribute + * to be set. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} @@ -1375,34 +1419,36 @@ UserDefinedConstraintComponent_setVariableType( */ LIBSBML_EXTERN int -UserDefinedConstraintComponent_setVariableTypeAsString( - UserDefinedConstraintComponent_t - * udcc, - const char * - variableType); +UserDefinedConstraintComponent_setVariableType( + UserDefinedConstraintComponent_t + * udcc, + FbcVariableType_t variableType); /** - * Sets the value of the "variable2" attribute of this + * Sets the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. * * @param udcc the UserDefinedConstraintComponent_t structure. * - * @param variable const char * value of the "variable2" attribute to be set. + * @param variableType const char * of the "variableType" attribute to be set. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_ATTRIBUTE_VALUE, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} * + * @copydetails doc_userdefinedconstraintcomponent_variableType + * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN int -UserDefinedConstraintComponent_setVariable2( - UserDefinedConstraintComponent_t * - udcc, - const char * variable); +UserDefinedConstraintComponent_setVariableTypeAsString( + UserDefinedConstraintComponent_t + * udcc, + const char * + variableType); /** @@ -1482,42 +1528,42 @@ UserDefinedConstraintComponent_unsetVariable(UserDefinedConstraintComponent_t * /** - * Unsets the value of the "variableType" attribute of this + * Unsets the value of the "variable2" attribute of this * UserDefinedConstraintComponent_t. * * @param udcc the UserDefinedConstraintComponent_t structure. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} + * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} * - * @copydetails doc_userdefinedconstraintcomponent_variableType - * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN int -UserDefinedConstraintComponent_unsetVariableType(UserDefinedConstraintComponent_t +UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t * udcc); /** - * Unsets the value of the "variable2" attribute of this + * Unsets the value of the "variableType" attribute of this * UserDefinedConstraintComponent_t. * * @param udcc the UserDefinedConstraintComponent_t structure. * * @copydetails doc_returns_success_code * @li @sbmlconstant{LIBSBML_OPERATION_SUCCESS, OperationReturnValues_t} - * @li @sbmlconstant{LIBSBML_OPERATION_FAILED, OperationReturnValues_t} * @li @sbmlconstant{LIBSBML_INVALID_OBJECT, OperationReturnValues_t} * + * @copydetails doc_userdefinedconstraintcomponent_variableType + * * @memberof UserDefinedConstraintComponent_t */ LIBSBML_EXTERN int -UserDefinedConstraintComponent_unsetVariable2(UserDefinedConstraintComponent_t * - udcc); +UserDefinedConstraintComponent_unsetVariableType(UserDefinedConstraintComponent_t + * udcc); /** diff --git a/src/sbml/packages/fbc/validator/FbcSBMLError.h b/src/sbml/packages/fbc/validator/FbcSBMLError.h index 66ed79d638..1a24baa36e 100644 --- a/src/sbml/packages/fbc/validator/FbcSBMLError.h +++ b/src/sbml/packages/fbc/validator/FbcSBMLError.h @@ -115,6 +115,8 @@ typedef enum , FbcFluxObjectCoefficientMustBeDouble = 2020607 /*!< The attribute 'fbc:coefficient' must be of the data type double */ , FbcFluxObjectCoefficientWhenStrict = 2020608 /*!< The 'fbc:coefficient' must be declared when strict */ , FbcFluxObjectiveVariableTypeMustBeFbcVariableTypeEnum = 2020609 +, FbcFluxObjectReaction2MustBeSIdRef = 2020610 /*!< Datatype for 'fbc:reaction' must be SIdRef */ +, FbcFluxObjectReaction2MustExist = 2020611 /*!< 'fbc:reaction' must refer to valid reaction */ , FbcReactionOnlyOneGeneProdAss = 2020701 /*!< One GeneProductAssociation in a Reaction */ , FbcReactionAllowedAttributes = 2020702 /*!< Fbc attributes on a Reaction */ @@ -165,11 +167,11 @@ typedef enum , FbcUserDefinedConstraintComponentAllowedCoreAttributes = 2021301 , FbcUserDefinedConstraintComponentAllowedCoreElements = 2021302 , FbcUserDefinedConstraintComponentAllowedAttributes = 2021303 -, FbcUserDefinedConstraintComponentCoefficientMustBeDouble = 2021304 +, FbcUserDefinedConstraintComponentCoefficientMustBeParameter = 2021304 , FbcUserDefinedConstraintComponentVariableMustBeReactionOrParameter= 2021305 , FbcUserDefinedConstraintComponentVariableTypeMustBeFbcVariableTypeEnum= 2021306 , FbcUserDefinedConstraintComponentNameMustBeString = 2021307 - +, FbcUserDefinedConstraintComponentVariable2MustBeReactionOrParameter= 2021308 , FbcUserDefinedConstraintAllowedCoreAttributes = 2021401 , FbcUserDefinedConstraintAllowedCoreElements = 2021402 , FbcUserDefinedConstraintAllowedAttributes = 2021403 diff --git a/src/sbml/packages/fbc/validator/FbcSBMLErrorTable.h b/src/sbml/packages/fbc/validator/FbcSBMLErrorTable.h index cc90278465..e88404f4e1 100644 --- a/src/sbml/packages/fbc/validator/FbcSBMLErrorTable.h +++ b/src/sbml/packages/fbc/validator/FbcSBMLErrorTable.h @@ -903,6 +903,37 @@ static const packageErrorTableEntryV3 fbcErrorTableV3[] = } }, + // 2020610 + { FbcFluxObjectReaction2MustBeSIdRef, + "Datatype for 'fbc:reaction2' must be SIdRef", + LIBSBML_CAT_GENERAL_CONSISTENCY, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_ERROR, + "The value of the attribute 'fbc:reaction2' of a object " + "must conform to the syntax of the SBML data type 'SIdRef'.", + { "", + "", + "L3V1 Fbc V3, Section 3.7" + } + }, + + // 2020611 + { FbcFluxObjectReaction2MustExist, + "'fbc:reaction2' must refer to valid reaction", + LIBSBML_CAT_GENERAL_CONSISTENCY, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_ERROR, + "The value of the attribute 'fbc:reaction2' of a " + " object must be the identifier of an existing " + "object defined in the enclosing object.", + { "", + "", + "L3V1 Fbc V3, Section 3.7" + } + }, + // 2020701 @@ -1616,9 +1647,10 @@ static const packageErrorTableEntryV3 fbcErrorTableV3[] = LIBSBML_SEV_ERROR, "An object must have the required " "attributes 'fbc:coefficient', 'fbc:variable' and 'fbc:variableType', and " - "may have the optional attributes 'fbc:id' and 'fbc:name'. No other " - "attributes from the SBML Level 3 Flux Balance Constraints namespaces are " - "permitted on an object. ", + "may have the optional attributes 'fbc:id', 'fbc:name' and " + "'fbc:variable2'. No other attributes from the SBML Level 3 Flux Balance " + "Constraints namespaces are permitted on an " + " object. ", { "", "", "" @@ -1626,14 +1658,15 @@ static const packageErrorTableEntryV3 fbcErrorTableV3[] = }, // 2021304 - { FbcUserDefinedConstraintComponentCoefficientMustBeDouble, - "The 'coefficient' attribute must be Double.", + { FbcUserDefinedConstraintComponentCoefficientMustBeParameter, + "The attribute 'coefficient' must point to Parameter object.", LIBSBML_CAT_GENERAL_CONSISTENCY, LIBSBML_SEV_NOT_APPLICABLE, LIBSBML_SEV_NOT_APPLICABLE, LIBSBML_SEV_ERROR, - "The attribute 'fbc:coefficient' on an " - "must have a value of data type 'double'.", + "The value of the attribute 'fbc:coefficient' of an " + " object must be the identifier of an " + "existing object defined in the enclosing object.", { "", "", "" @@ -1690,6 +1723,23 @@ static const packageErrorTableEntryV3 fbcErrorTableV3[] = } }, + // 2021308 + { FbcUserDefinedConstraintComponentVariable2MustBeReactionOrParameter, + "The attribute 'variable2' must point to ReactionOrParameter object.", + LIBSBML_CAT_GENERAL_CONSISTENCY, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_NOT_APPLICABLE, + LIBSBML_SEV_ERROR, + "The value of the attribute 'fbc:variable2' of an " + " object must be the identifier of an " + "existing or object defined in the enclosing " + "object.", + { "", + "", + "" + } + }, + // 2021401 { FbcUserDefinedConstraintAllowedCoreAttributes, "Core attributes allowed on .", diff --git a/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraints.cpp b/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraints.cpp index 0fdb30d569..fb7946adf9 100644 --- a/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraints.cpp +++ b/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraints.cpp @@ -162,8 +162,8 @@ END_CONSTRAINT // 20601 - caught at read // 20602 - caught at read // 20603 - caught at read -// 20606 - caught at read -// 20606 - caught at read +// 20604 - caught at read +// 20605 - caught at read // 20606 START_CONSTRAINT (FbcFluxObjectReactionMustExist, FluxObjective, fo) @@ -217,6 +217,36 @@ START_CONSTRAINT(FbcFluxObjectCoefficientWhenStrict, FluxObjective, fo) } END_CONSTRAINT +// 20809 - caught at read +// 20810 - caught at read + +// 20811 +START_CONSTRAINT(FbcFluxObjectReaction2MustExist, FluxObjective, fo) +{ + pre(fo.isSetReaction2()); + + bool fail = false; + + msg = "The "; + if (fo.isSetId()) { + msg += "with the id '" + fo.getId() + "' "; + } + msg += "refers to a reaction with id '"; + msg += fo.getReaction2(); + msg += "' that does not exist within the ."; + + std::string reaction = fo.getReaction2(); + + if (m.getReaction(reaction) == NULL) + { + fail = true; + } + + inv(fail == false); +} +END_CONSTRAINT + + // 20701 - caught at read // 20702 - caught at read // 20703 - caught at read @@ -826,7 +856,31 @@ END_CONSTRAINT // 21301 - caught at read // 21302 - caught at read // 21303 - caught at read -// 21304 - caught at read + +// 21304 +START_CONSTRAINT(FbcUserDefinedConstraintComponentCoefficientMustBeParameter, UserDefinedConstraintComponent, udcc) +{ + pre(udcc.isSetCoefficient()); + + std::string as = udcc.getCoefficient(); + + bool fail = false; + + msg = "The with id '"; + msg += udcc.getId(); + msg += "' refers to a parameter '"; + msg += as; + msg += "' that does not exist within the ."; + + if (m.getParameter(as) == NULL) + { + fail = true; + } + + inv(fail == false); +} +END_CONSTRAINT + // 21305 START_CONSTRAINT(FbcUserDefinedConstraintComponentVariableMustBeReactionOrParameter, UserDefinedConstraintComponent, udcc) @@ -853,7 +907,33 @@ START_CONSTRAINT(FbcUserDefinedConstraintComponentVariableMustBeReactionOrParame END_CONSTRAINT // 21306 - caught at read -// 21307 - sring +// 21307 - string + +// 21308 +START_CONSTRAINT(FbcUserDefinedConstraintComponentVariable2MustBeReactionOrParameter, UserDefinedConstraintComponent, udcc) +{ + pre(udcc.isSetVariable2()); + + std::string as = udcc.getVariable2(); + + bool fail = false; + + msg = "The with id '"; + msg += udcc.getId(); + msg += "' refers to a variable2 '"; + msg += as; + msg += "' that does not exist within the ."; + + if (m.getReaction(as) == NULL && m.getParameter(as) == NULL) + { + fail = true; + } + + inv(fail == false); +} +END_CONSTRAINT + + // 21401 - caught at read // 21402 - caught at read diff --git a/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraintsDeclared.cxx b/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraintsDeclared.cxx index 0c075682e3..ff39717578 100644 --- a/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraintsDeclared.cxx +++ b/src/sbml/packages/fbc/validator/constraints/FbcConsistencyConstraintsDeclared.cxx @@ -48,6 +48,8 @@ addConstraint(new VConstraintFluxObjectiveFbcFluxObjectReactionMustExist(*this)) addConstraint(new VConstraintFluxObjectiveFbcFluxObjectCoefficientWhenStrict(*this)); +addConstraint(new VConstraintFluxObjectiveFbcFluxObjectReaction2MustExist(*this)); + addConstraint(new VConstraintReactionFbcReactionLwrBoundRefExists(*this)); addConstraint(new VConstraintReactionFbcReactionUpBoundRefExists(*this)); @@ -84,8 +86,12 @@ addConstraint(new UniqueGeneProductLabels(FbcGeneProductLabelMustBeUnique, *this addConstraint(new VConstraintGeneProductFbcGeneProductAssocSpeciesMustExist(*this)); +addConstraint(new VConstraintUserDefinedConstraintComponentFbcUserDefinedConstraintComponentCoefficientMustBeParameter(*this)); + addConstraint(new VConstraintUserDefinedConstraintComponentFbcUserDefinedConstraintComponentVariableMustBeReactionOrParameter(*this)); +addConstraint(new VConstraintUserDefinedConstraintComponentFbcUserDefinedConstraintComponentVariable2MustBeReactionOrParameter(*this)); + addConstraint(new VConstraintUserDefinedConstraintFbcUserDefinedConstraintLowerBoundMustBeParameter(*this)); addConstraint(new VConstraintUserDefinedConstraintFbcUserDefinedConstraintUpperBoundMustBeParameter(*this)); diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2010302-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2010302-fail-01-01.xml deleted file mode 100644 index e39084567d..0000000000 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2010302-fail-01-01.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - k - S1 - - - - - - - - - - - - - - - - - - - k - S2 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml index ddd1ab1d94..695370d385 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/general-constraints/2021303-fail-01-01.xml @@ -80,7 +80,7 @@ - + diff --git a/src/sbml/packages/fbc/validator/test/test-data/identifier-constraints/2010302-fail-01-01.xml b/src/sbml/packages/fbc/validator/test/test-data/identifier-constraints/2010302-fail-01-01.xml index 7ab407d093..aa858dd0dd 100644 --- a/src/sbml/packages/fbc/validator/test/test-data/identifier-constraints/2010302-fail-01-01.xml +++ b/src/sbml/packages/fbc/validator/test/test-data/identifier-constraints/2010302-fail-01-01.xml @@ -107,7 +107,7 @@ - + day2.c9