Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/sbml/EventAssignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,11 @@ ListOfEventAssignments::getElementBySId(const std::string& id)
for (unsigned int i = 0; i < size(); i++)
{
SBase* obj = get(i);
//Event Assignments are not in the SId namespace, so don't check 'getId'. However, their children (through plugins) may have the element we are looking for, so we still need to check all of them.
//The id of an event assignment can only be retrieved with getIdAttribute.
if (obj->isSetIdAttribute() && obj->getIdAttribute() == id)
{
return obj;
}
obj = obj->getElementBySId(id);
if (obj != NULL) return obj;
}
Expand Down
6 changes: 5 additions & 1 deletion src/sbml/InitialAssignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1155,7 +1155,11 @@ ListOfInitialAssignments::getElementBySId(const std::string& id)
for (unsigned int i = 0; i < size(); i++)
{
SBase* obj = get(i);
//Initial assignments are not in the SId namespace, so don't check 'getId'. However, their children (through plugins) may have the element we are looking for, so we still need to check all of them.
//The id of an initial assignment can only be retrieved with getIdAttribute.
if (obj->isSetIdAttribute() && obj->getIdAttribute() == id)
{
return obj;
}
obj = obj->getElementBySId(id);
if (obj != NULL) return obj;
}
Expand Down
6 changes: 5 additions & 1 deletion src/sbml/Rule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1682,7 +1682,11 @@ ListOfRules::getElementBySId(const std::string& id)
for (unsigned int i = 0; i < size(); i++)
{
SBase* obj = get(i);
//No rule is in the SId namespace, so don't check 'getId'. However, their children (through plugins) may have the element we are looking for, so we still need to check all of them.
//The id of a rule can only be retrieved with getIdAttribute.
if (obj->isSetIdAttribute() && obj->getIdAttribute() == id)
{
return obj;
}
obj = obj->getElementBySId(id);
if (obj != NULL) return obj;
}
Expand Down
53 changes: 53 additions & 0 deletions src/sbml/test/TestGetMultipleObjects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,58 @@ START_TEST (test_GetMultipleObjects_noAssignments)
END_TEST


START_TEST (test_GetMultipleObjects_assignmentsWithIds)
{
// From SBML Level 3 Version 2 on, rules, initial assignments and event
// assignments can have an id, which is in the SId namespace. Their
// variable or symbol is not an id, so it still finds the symbol it names.
SBMLDocument d(3, 2);
Model* m = d.createModel();
Parameter* x = m->createParameter();
x->setId("x");
x->setConstant(false);
Parameter* y = m->createParameter();
y->setId("y");
y->setConstant(false);
Parameter* z = m->createParameter();
z->setId("z");
z->setConstant(false);

AlgebraicRule* alg = m->createAlgebraicRule();
alg->setIdAttribute("alg");

AssignmentRule* ar = m->createAssignmentRule();
ar->setVariable("x");
ar->setIdAttribute("ar");

RateRule* rr = m->createRateRule();
rr->setVariable("y");
rr->setIdAttribute("rr");

InitialAssignment* ia = m->createInitialAssignment();
ia->setSymbol("z");
ia->setIdAttribute("ia");

Event* e = m->createEvent();
e->setId("e");
EventAssignment* ea = e->createEventAssignment();
ea->setVariable("z");
ea->setIdAttribute("ea");

fail_unless(d.getElementBySId("alg") == alg);
fail_unless(d.getElementBySId("ar") == ar);
fail_unless(d.getElementBySId("rr") == rr);
fail_unless(d.getElementBySId("ia") == ia);
fail_unless(d.getElementBySId("ea") == ea);
fail_unless(m->getElementBySId("ar") == ar);

fail_unless(d.getElementBySId("x") == x);
fail_unless(d.getElementBySId("y") == y);
fail_unless(d.getElementBySId("z") == z);
}
END_TEST


START_TEST (test_GetMultipleObjects_allElements)
{
SBMLReader reader;
Expand Down Expand Up @@ -511,6 +563,7 @@ create_suite_GetMultipleObjects (void)
tcase_add_test(tcase, test_GetMultipleObjects_noLocalParameters);
tcase_add_test(tcase, test_GetMultipleObjects_noUnits);
tcase_add_test(tcase, test_GetMultipleObjects_noAssignments);
tcase_add_test(tcase, test_GetMultipleObjects_assignmentsWithIds);
tcase_add_test(tcase, test_GetMultipleObjects_allElements);
tcase_add_test(tcase, test_GetMultipleObjects_withFilter);

Expand Down
Loading