| 76 | } |
| 77 | |
| 78 | bool mitk::SceneReaderV1::LoadScene(tinyxml2::XMLDocument &document, const std::string &workingDirectory, DataStorage *storage) |
| 79 | { |
| 80 | assert(storage); |
| 81 | bool error(false); |
| 82 | |
| 83 | // TODO prepare to detect errors (such as cycles) from wrongly written or edited xml files |
| 84 | |
| 85 | // Get number of elements to initialize progress bar |
| 86 | // 1. if there is a <data type="..." file="..."> element, |
| 87 | // - construct a name for the appropriate serializer |
| 88 | // - try to instantiate this serializer via itk object factory |
| 89 | // - if serializer could be created, use it to read the file into a BaseData object |
| 90 | // - if successful, call the new node's SetData(..) |
| 91 | |
| 92 | // create a node for the tag "data" and test if node was created |
| 93 | typedef std::vector<mitk::DataNode::Pointer> DataNodeVector; |
| 94 | DataNodeVector DataNodes; |
| 95 | unsigned int listSize = 0; |
| 96 | for (auto *element = document.FirstChildElement("node"); element != nullptr; |
| 97 | element = element->NextSiblingElement("node")) |
| 98 | { |
| 99 | ++listSize; |
| 100 | } |
| 101 | |
| 102 | ProgressBar::GetInstance()->AddStepsToDo(listSize * 2); |
| 103 | |
| 104 | // Deserialize base data properties before reading the actual data to be |
| 105 | // able to provide them as read-only meta data to the data reader. |
| 106 | std::map<std::string, PropertyList::Pointer> baseDataPropertyLists; |
| 107 | |
| 108 | for (auto *nodeElement = document.FirstChildElement("node"); nodeElement != nullptr; |
| 109 | nodeElement = nodeElement->NextSiblingElement("node")) |
| 110 | { |
| 111 | const auto *uid = nodeElement->Attribute("UID"); |
| 112 | |
| 113 | if (uid == nullptr) |
| 114 | continue; |
| 115 | |
| 116 | auto *dataElement = nodeElement->FirstChildElement("data"); |
| 117 | |
| 118 | if (dataElement != nullptr) |
| 119 | { |
| 120 | auto properties = DeserializeProperties(dataElement->FirstChildElement("properties"), workingDirectory); |
| 121 | |
| 122 | if (properties.IsNotNull()) |
| 123 | baseDataPropertyLists[uid] = properties; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | for (auto *element = document.FirstChildElement("node"); element != nullptr; |
| 128 | element = element->NextSiblingElement("node")) |
| 129 | { |
| 130 | mitk::PropertyList* properties = nullptr; |
| 131 | const auto *uid = element->Attribute("UID"); |
| 132 | |
| 133 | if (uid != nullptr) |
| 134 | { |
| 135 | auto iter = baseDataPropertyLists.find(uid); |
nothing calls this directly
no test coverage detected