Skip to content

Commit 48dad15

Browse files
committed
Bug 3130: Applied patch.
1 parent 9e6380b commit 48dad15

File tree

5 files changed

+108
-38
lines changed

5 files changed

+108
-38
lines changed

copasi/sedml/SEDMLImporter.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ SEDMLImporter::parseSEDML(const std::string & sedmlDocumentText,
10051005

10061006
case LIBSEDML_SEV_FATAL:
10071007

1008-
// treat unknown as fatal
1008+
// treat unknown as fatal
10091009
default:
10101010

10111011
if (pSEDMLError->getErrorId() == 10804)
@@ -1064,15 +1064,22 @@ SEDMLImporter::parseSEDML(const std::string & sedmlDocumentText,
10641064
// initialize data:
10651065
initializeContent();
10661066

1067+
setSEDMLDocument(pSEDMLDocument);
1068+
10671069
// merge subtasks if needed
10681070
mergeNestedSubtasks();
10691071

1070-
setSEDMLDocument(pSEDMLDocument);
1071-
1072-
if (pOptions != NULL && !pOptions->getModelId().empty())
1073-
importModel(pOptions->getModelId());
1072+
if (pOptions == NULL || pOptions->skipModelImport() == false)
1073+
{
1074+
if (pOptions != NULL && !pOptions->getModelId().empty())
1075+
importModel(pOptions->getModelId());
1076+
else
1077+
importFirstSBMLModel();
1078+
}
10741079
else
1075-
importFirstSBMLModel();
1080+
{
1081+
mpCopasiModel = pDataModel->getModel();
1082+
}
10761083

10771084
if (pOptions != NULL && !pOptions->getTaskId().empty())
10781085
importTask(mpSEDMLDocument->getTask(pOptions->getTaskId()), false);
@@ -1083,7 +1090,6 @@ SEDMLImporter::parseSEDML(const std::string & sedmlDocumentText,
10831090

10841091
assignReportDefinitions();
10851092

1086-
10871093
if (mpProcessReport != NULL)
10881094
mpProcessReport->finishItem(mhImportStep);
10891095

@@ -1145,10 +1151,8 @@ void SEDMLImporter::importTasks(CDataVectorN< CCopasiTask > * pTaskList)
11451151

11461152
importTask(task, pTaskList);
11471153
}
1148-
11491154
}
11501155

1151-
11521156
void SEDMLImporter::assignReportDefinitions(CDataVectorN< CCopasiTask > * pTaskList)
11531157
{
11541158

@@ -1292,7 +1296,7 @@ void SEDMLImporter::importTask(
12921296
std::stringstream str;
12931297
std::vector< double > vals = vrange->getValues();
12941298

1295-
for (double val : vals)
1299+
for (double val : vals)
12961300
str << val << " ";
12971301

12981302
group->setValue< std::string >("Values", str.str());
@@ -1428,7 +1432,7 @@ SEDMLImporter::convertSimpleFunctionalRange(SedFunctionalRange * frange, SedRepe
14281432
knownValues[p->getId()] = p->getValue();
14291433
}
14301434

1431-
for (auto value : oldValues)
1435+
for (auto value : oldValues)
14321436
{
14331437
knownValues[insideVRange->getId()] = value;
14341438
newValues.push_back(SBMLTransforms::evaluateASTNode(frange->getMath(), knownValues));

copasi/sedml/SEDMLUtils.cpp

Lines changed: 67 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,9 @@ void SEDMLUtils::setLibCombineTempDir()
681681
const CDataObject *
682682
SEDMLUtils::getObjectForSbmlId(const CModel * pModel, const std::string & id, const std::string & SBMLType, bool initial /* = false*/)
683683
{
684+
if (!pModel)
685+
return NULL;
686+
684687
if (SBMLType == "Time")
685688
return static_cast< const CDataObject * >(pModel->getObject(CCommonName("Reference=Time")));
686689

@@ -959,25 +962,7 @@ SedmlInfo::SedmlInfo(SedDocument * pDocument, bool ownDocument)
959962
if (!pDocument)
960963
return;
961964

962-
std::map< int, int > taskCount;
963-
964-
for (unsigned int i = 0; i < pDocument->getNumTasks(); ++i)
965-
{
966-
auto * current = pDocument->getTask(i);
967-
mTaskMap[current->getId()] = getModelForTask(current);
968-
taskCount[current->getTypeCode()] = taskCount[current->getTypeCode()] + 1;
969-
mReports[current->getId()] = std::vector< std::pair< std::string, std::string > >();
970-
mPlots[current->getId()] = std::vector< std::pair< std::string, std::string > >();
971-
std::stringstream str;
972-
973-
if (current->isSetName())
974-
str << current->getName() << " - ";
975-
976-
str << current->getId();
977-
978-
mTaskNames.push_back(std::make_pair(current->getId(), str.str()));
979-
mComplex |= taskCount[current->getTypeCode()] > 1 || mTaskMap[current->getId()].size() > 1;
980-
}
965+
std::map< std::pair< int, int>, int > taskCount;
981966

982967
for (unsigned int i = 0; i < pDocument->getNumOutputs(); ++i)
983968
{
@@ -1000,6 +985,57 @@ SedmlInfo::SedmlInfo(SedDocument * pDocument, bool ownDocument)
1000985
mPlots[taskId].push_back(std::make_pair(current->getId(), str.str()));
1001986
}
1002987
}
988+
989+
for (unsigned int i = 0; i < pDocument->getNumTasks(); ++i)
990+
{
991+
auto * current = pDocument->getTask(i);
992+
993+
if (isRecursiveWithoutOutputs(current))
994+
continue;
995+
996+
mTaskMap[current->getId()] = getModelForTask(current);
997+
998+
int simType = SEDML_SIMULATION;
999+
1000+
if (current->getTypeCode() == SEDML_TASK)
1001+
{
1002+
auto * simulation = pDocument->getSimulation(dynamic_cast< SedTask * >(current)->getSimulationReference());
1003+
1004+
if (simulation != NULL)
1005+
simType = simulation->getTypeCode();
1006+
}
1007+
1008+
auto currentKey = std::make_pair(current->getTypeCode(), simType);
1009+
1010+
taskCount[currentKey] = taskCount[currentKey] + 1;
1011+
std::stringstream str;
1012+
1013+
if (current->isSetName())
1014+
str << current->getName() << " - ";
1015+
1016+
str << current->getId();
1017+
1018+
mTaskNames.push_back(std::make_pair(current->getId(), str.str()));
1019+
mComplex |= taskCount[currentKey] > 1 || mTaskMap[current->getId()].size() > 1;
1020+
}
1021+
}
1022+
1023+
bool SedmlInfo::hasOutputs(const std::string & taskId)
1024+
{
1025+
return !(mReports[taskId].empty() && mPlots[taskId].empty());
1026+
}
1027+
1028+
bool SedmlInfo::isRecursiveWithoutOutputs(SedAbstractTask * task)
1029+
{
1030+
auto * repeat = dynamic_cast< SedRepeatedTask * >(task);
1031+
1032+
if (repeat == NULL)
1033+
return false;
1034+
1035+
if (hasOutputs(task->getId()))
1036+
return false;
1037+
1038+
return true;
10031039
}
10041040

10051041
SedmlInfo::~SedmlInfo()
@@ -1283,6 +1319,7 @@ SedmlImportOptions::SedmlImportOptions(
12831319
, mPlots(plots)
12841320
, mReportId(reportId)
12851321
, mReportFile(reportFilename)
1322+
, mSkipModelImport(false)
12861323
{
12871324
}
12881325

@@ -1295,11 +1332,22 @@ SedmlImportOptions & SedmlImportOptions::operator=(const SedmlImportOptions & rh
12951332
mPlots = rhs.mPlots;
12961333
mReportId = rhs.mReportId;
12971334
mReportFile = rhs.mReportFile;
1335+
mSkipModelImport = rhs.mSkipModelImport;
12981336
}
12991337

13001338
return *this;
13011339
}
13021340

1341+
void SedmlImportOptions::setSkipModelImport(bool skipModelLoading)
1342+
{
1343+
mSkipModelImport = skipModelLoading;
1344+
}
1345+
1346+
bool SedmlImportOptions::skipModelImport() const
1347+
{
1348+
return mSkipModelImport;
1349+
}
1350+
13031351
const std::string & SedmlImportOptions::getTaskId() const
13041352
{
13051353
return mTaskId;

copasi/sedml/SEDMLUtils.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class SedmlInfo
116116
bool isSupported();
117117

118118
/**
119-
* @return true, if the document is complex ( > 1 model, multiple
119+
* @return true, if the document is complex (> 1 model, multiple
120120
tasks of the same type ) requiring the user to choose
121121
which one to import.
122122
*/
@@ -136,6 +136,9 @@ class SedmlInfo
136136
std::vector< std::pair< std::string, std::string > > getReportsForTask(const std::string & taskId);
137137
std::vector< std::pair< std::string, std::string > > getPlotsForTask(const std::string & taskId);
138138

139+
bool hasOutputs(const std::string & taskId);
140+
bool isRecursiveWithoutOutputs(SedAbstractTask * task);
141+
139142
std::string getReportFileName(const std::string & reportId);
140143
void setReportFileName(const std::string & reportId, const std::string & fileName);
141144

@@ -146,7 +149,6 @@ class SedmlInfo
146149
static SedmlInfo forFile(const std::string & fileName);
147150
};
148151

149-
150152
/**
151153
* Utility methods for SED-ML Import / Export
152154
*/
@@ -236,7 +238,6 @@ class SEDMLUtils
236238
static int getAlphaFromArgb(const std::string & argb);
237239
static int getAlphaFromRgba(const std::string & rgba);
238240

239-
240241
/**
241242
* updates the libcombine temp directory to the COPASI temp path
242243
*/

copasi/sedml/SedmlImportOptions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SedmlImportOptions
1616
std::vector< std::string > mPlots;
1717
std::string mReportId;
1818
std::string mReportFile;
19+
bool mSkipModelImport;
1920

2021
public:
2122
SedmlImportOptions(
@@ -27,6 +28,9 @@ class SedmlImportOptions
2728

2829
SedmlImportOptions & operator=(const SedmlImportOptions & rhs);
2930

31+
void setSkipModelImport(bool skipModelLoading);
32+
bool skipModelImport() const;
33+
3034
const std::string & getTaskId() const;
3135
const std::string & getModelId() const;
3236
const std::string & getReportId() const;
@@ -36,8 +40,4 @@ class SedmlImportOptions
3640
bool isValid() const;
3741
};
3842

39-
4043
#endif // SEDML_IMPORT_OPTIONS_H
41-
42-
43-

tests/test_sedml.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ TEST_CASE("importing variables with terms", "[copasi,sedml]")
140140
CRootContainer::removeDatamodel(dm);
141141
}
142142

143-
TEST_CASE("export nested scan", "[copasi,sedml]")
143+
TEST_CASE("export / import nested scan", "[copasi,sedml]")
144144
{
145145
auto * dm = CRootContainer::addDatamodel();
146146
REQUIRE(dm != nullptr);
@@ -156,8 +156,25 @@ TEST_CASE("export nested scan", "[copasi,sedml]")
156156
REQUIRE(doc->getDataGenerator("Rtot_1_task3") == NULL);
157157
REQUIRE(doc->getDataGenerator("Rtot_1_task5") != NULL);
158158

159+
// the model has a timecourse, and a steady state scan with 3 variables, as such it should not be complex
160+
REQUIRE(SedmlInfo(doc).isComplex() == false);
161+
162+
// if we had another time course then it should be complex
163+
{
164+
auto * task = doc->getTask(0)->clone();
165+
task->setId("anotherTaks");
166+
doc->getListOfTasks()->appendAndOwn(task);
167+
REQUIRE(SedmlInfo(doc).isComplex() == true);
168+
}
169+
159170
delete doc;
160171

172+
// now import
173+
SedmlImportOptions opts;
174+
opts.setSkipModelImport(true);
175+
dm->importSEDMLFromString(sedml, "", NULL, true, &opts);
176+
REQUIRE(dynamic_cast< CScanProblem * >(dm->getTaskList()->operator[]("Scan").getProblem())->getNumberOfScanItems() == 3);
177+
161178
CRootContainer::removeDatamodel(dm);
162179
}
163180

0 commit comments

Comments
 (0)