| 530 | } |
| 531 | |
| 532 | tinyxml2::XMLElement *mitk::SceneIO::SaveBaseData(tinyxml2::XMLDocument &doc, BaseData *data, const std::string &filenamehint, bool &error) |
| 533 | { |
| 534 | assert(data); |
| 535 | error = true; |
| 536 | |
| 537 | // find correct serializer |
| 538 | // the serializer must |
| 539 | // - create a file containing all information to recreate the BaseData object --> needs to know where to put this |
| 540 | // file (and a filename?) |
| 541 | // - TODO what to do about writers that creates one file per timestep? |
| 542 | auto *element = doc.NewElement("data"); |
| 543 | element->SetAttribute("type", data->GetNameOfClass()); |
| 544 | |
| 545 | // construct name of serializer class |
| 546 | std::string serializername(data->GetNameOfClass()); |
| 547 | serializername += "Serializer"; |
| 548 | |
| 549 | std::list<itk::LightObject::Pointer> thingsThatCanSerializeThis = |
| 550 | itk::ObjectFactoryBase::CreateAllInstance(serializername.c_str()); |
| 551 | if (thingsThatCanSerializeThis.size() < 1) |
| 552 | { |
| 553 | MITK_ERROR << "No serializer found for " << data->GetNameOfClass() << ". Skipping object"; |
| 554 | } |
| 555 | |
| 556 | for (auto iter = thingsThatCanSerializeThis.begin(); |
| 557 | iter != thingsThatCanSerializeThis.end(); |
| 558 | ++iter) |
| 559 | { |
| 560 | if (auto *serializer = dynamic_cast<BaseDataSerializer *>(iter->GetPointer())) |
| 561 | { |
| 562 | serializer->SetData(data); |
| 563 | serializer->SetFilenameHint(filenamehint); |
| 564 | std::string defaultLocale_WorkingDirectory = Poco::Path::transcode( m_WorkingDirectory ); |
| 565 | serializer->SetWorkingDirectory(defaultLocale_WorkingDirectory); |
| 566 | try |
| 567 | { |
| 568 | std::string writtenfilename = serializer->Serialize(); |
| 569 | element->SetAttribute("file", writtenfilename.c_str()); |
| 570 | |
| 571 | if (!writtenfilename.empty()) |
| 572 | error = false; |
| 573 | } |
| 574 | catch (std::exception &e) |
| 575 | { |
| 576 | MITK_ERROR << "Serializer " << serializer->GetNameOfClass() << " failed: " << e.what(); |
| 577 | } |
| 578 | break; |
| 579 | } |
| 580 | } |
| 581 | element->SetAttribute("UID", data->GetUID().c_str()); |
| 582 | |
| 583 | return element; |
| 584 | } |
| 585 | |
| 586 | tinyxml2::XMLElement *mitk::SceneIO::SavePropertyList(tinyxml2::XMLDocument &doc, const IPropertyTransience *transience, PropertyList *propertyList, const BaseData *nodeData, const std::string &filenamehint) |
| 587 | { |
nothing calls this directly
no test coverage detected