Skip to content

Commit e338427

Browse files
committed
- when resolving display names, refine model elements to references if not already there.
1 parent e2c0eae commit e338427

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

copasi/CopasiSE/CopasiSE.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,48 @@ int getReportIndex(const std::string& reportName)
139139

140140
void addReportItemsToList(const std::vector<std::string>& items, std::function< std::vector< CRegisteredCommonName >* () > getCnListFunction)
141141
{
142+
if (!pDataModel || !getCnListFunction())
143+
return;
144+
142145
for (const auto& item : items)
143146
{
147+
bool fromDisplayName = true;
144148
const auto* obj = pDataModel->findObjectByDisplayName(item);
145149
if (!obj)
146-
obj = dynamic_cast<const CDataObject*>(pDataModel->getObject(item));
150+
{
151+
obj = dynamic_cast< const CDataObject * >(pDataModel->getObject(item));
152+
fromDisplayName = false;
153+
}
147154
if (!obj)
148155
{
149156
std::cerr << "report item cannot be resolved: " << item << std::endl;
150157
continue;
151158
}
159+
160+
// if the item is not a reference after resolving from
161+
// display name, choose specific reference for model entities
162+
if (fromDisplayName && obj->getObjectType() != "Reference")
163+
{
164+
const CMetab * metab = dynamic_cast< const CMetab * >(obj);
165+
if (metab)
166+
{
167+
obj = metab->getConcentrationReference();
168+
}
169+
170+
const CReaction * reaction = dynamic_cast< const CReaction * >(obj);
171+
if (reaction)
172+
{
173+
obj = reaction->getFluxReference();
174+
}
175+
176+
const CModelEntity * modelEntity = dynamic_cast< const CModelEntity * >(obj);
177+
if (modelEntity)
178+
{
179+
obj = modelEntity->getValueReference();
180+
}
181+
}
182+
183+
152184
getCnListFunction()->push_back(obj->getCN());
153185
}
154186
}

0 commit comments

Comments
 (0)