void UnitReplacementCheck::checkReferencedElement(ReplacedElement& repE, const Model& m) { // if the deletion attribute is set then it is not a true replacement if (repE.isSetDeletion() == true) { return; } unsigned int numErrsB4 = repE.getSBMLDocument()->getNumErrors(); SBase* refElem = repE.getReferencedElement(); // if there is an issue with references the getReferencedElement // will log errors and possibly fail // we dont want to try any further unsigned int numErrsAfter = repE.getSBMLDocument()->getNumErrors(); if (numErrsB4 != numErrsAfter || refElem == NULL) { return; } SBase * parent = repE.getParentSBMLObject()->getParentSBMLObject(); UnitDefinition *parentUnits = parent->getDerivedUnitDefinition(); UnitDefinition *refElemUnits = refElem->getDerivedUnitDefinition(); bool delrefelem = false; bool cfPresent = false; /* adjust the refElement units for conversion factor */ if (repE.isSetConversionFactor() == true && refElemUnits && refElemUnits->getNumUnits() > 0) { Parameter * p = const_cast<Model *>(&m) ->getParameter(repE.getConversionFactor()); UnitDefinition *ud = p->getDerivedUnitDefinition(); UnitDefinition *newRefElemUnits = UnitDefinition::combine(refElemUnits, ud); refElemUnits = newRefElemUnits; delrefelem = true; cfPresent = true; } if (parentUnits == NULL) { if (delrefelem) { delete refElemUnits; } return; } if (refElemUnits == NULL) { return; } if (parent->containsUndeclaredUnits() == true || refElem->containsUndeclaredUnits() == true) { if (delrefelem) { delete refElemUnits; } return; } if (UnitDefinition::areIdentical(parentUnits, refElemUnits) == false) { logMismatchUnits(repE, refElem, parent, cfPresent); } else { // if we have Compartments that have spatialDimensions but no units // we can check this if (parent->getTypeCode() == SBML_COMPARTMENT && parentUnits->getNumUnits() == 0 && refElem->getTypeCode() == SBML_COMPARTMENT && refElemUnits->getNumUnits() == 0) { if (static_cast<Compartment *>(parent)->isSetSpatialDimensions() == true && static_cast<Compartment *>(refElem)->isSetSpatialDimensions() == true) { if (util_isEqual( static_cast<Compartment *>(parent)->getSpatialDimensionsAsDouble(), static_cast<Compartment *>(refElem)->getSpatialDimensionsAsDouble()) == 0) { logMismatchSpatialDimensions(repE, refElem, parent); } } } } if (delrefelem) { delete refElemUnits; } }
void UnitReplacementCheck::checkReferencedElement(ReplacedBy& repBy) { unsigned int numErrsB4 = repBy.getSBMLDocument()->getNumErrors(); SBase* refElem = repBy.getReferencedElement(); // if there is an issue with references the getReferencedElement // will log errors and possibly fail // we dont want to try any further unsigned int numErrsAfter = repBy.getSBMLDocument()->getNumErrors(); if (numErrsB4 != numErrsAfter || refElem == NULL) { return; } SBase * parent = repBy.getParentSBMLObject(); UnitDefinition *parentUnits = parent->getDerivedUnitDefinition(); //bool delparunit = parent->getTypeCode()==SBML_PARAMETER; UnitDefinition *refElemUnits = refElem->getDerivedUnitDefinition(); //bool delrefunit = refElem->getTypeCode()==SBML_PARAMETER; if (parentUnits == NULL || refElemUnits == NULL) { //if (delparunit) //{ // delete parentUnits; //} //if (delrefunit) //{ // delete refElemUnits; //} return; } if (parent->containsUndeclaredUnits() == true || refElem->containsUndeclaredUnits() == true) { //if (delparunit) //{ // delete parentUnits; //} //if (delrefunit) //{ // delete refElemUnits; //} return; } if (UnitDefinition::areIdentical(parentUnits, refElemUnits) == false) { logMismatchUnits(repBy, refElem, parent); } else { // if we have Compartments that have spatialDimensions but no units // we can check this if (parent->getTypeCode() == SBML_COMPARTMENT && parentUnits->getNumUnits() == 0 && refElem->getTypeCode() == SBML_COMPARTMENT && refElemUnits->getNumUnits() == 0) { if (static_cast<Compartment *>(parent)->isSetSpatialDimensions() == true && static_cast<Compartment *>(refElem)->isSetSpatialDimensions() == true) { if (util_isEqual( static_cast<Compartment *>(parent)->getSpatialDimensionsAsDouble(), static_cast<Compartment *>(refElem)->getSpatialDimensionsAsDouble()) == 0) { logMismatchSpatialDimensions(repBy, refElem, parent); } } } } //if (delparunit) //{ // delete parentUnits; //} //if (delrefunit) //{ // delete refElemUnits; //} }