MCPcopy Create free account
hub / github.com/computationalpathologygroup/ASAP / loadFromRepo

Method loadFromRepo

annotation/XmlRepository.cpp:98–188  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96}
97
98bool XmlRepository::loadFromRepo()
99{
100 if (!_list) {
101 return false;
102 }
103
104 _list->removeAllAnnotations();
105 _list->removeAllGroups();
106
107 pugi::xml_document xml_doc;
108 pugi::xml_parse_result tree = xml_doc.load_file(_source.c_str());
109 pugi::xml_node root = xml_doc.child("ASAP_Annotations");
110 if (root.empty()) {
111 root = xml_doc.root();
112 }
113 std::map<std::string, std::shared_ptr<AnnotationGroup> > nameToGroup;
114 std::map<std::string, std::string> groupToParent;
115 pugi::xml_node groups = root.child("AnnotationGroups");
116 for (pugi::xml_node_iterator it = groups.begin(); it != groups.end(); ++it)
117 {
118 std::shared_ptr<AnnotationGroup> group = std::make_shared<AnnotationGroup>();
119 std::string groupName = it->attribute("Name").value();
120 group->setName(groupName);
121 std::string groupColor = it->attribute("Color").value();
122 if (!groupColor.empty()) {
123 group->setColor(groupColor);
124 }
125 std::string parentGroupName = it->attribute("PartOfGroup").value();
126 if (parentGroupName != "None") {
127 groupToParent[groupName] = parentGroupName;
128 }
129 nameToGroup[groupName] = group;
130 pugi::xml_node groupAttributes = it->child("Attributes");
131 for (pugi::xml_node_iterator itAttNode = groupAttributes.begin(); itAttNode != groupAttributes.end(); ++itAttNode) {
132 for (pugi::xml_attribute_iterator itAttAtrributes = itAttNode->attributes_begin(); itAttAtrributes != itAttNode->attributes_end(); ++itAttAtrributes) {
133 group->setAttribute<std::string>(itAttAtrributes->name(), itAttAtrributes->value());
134 }
135 }
136 _list->addGroup(group);
137 }
138
139 // Now add the parent groups to each group
140 std::vector<std::shared_ptr<AnnotationGroup> > grps = _list->getGroups();
141 for (std::vector<std::shared_ptr<AnnotationGroup> >::iterator it = grps.begin(); it != grps.end(); ++it) {
142 if (groupToParent.find((*it)->getName()) != groupToParent.end()) {
143 (*it)->setGroup(nameToGroup[groupToParent[(*it)->getName()]]);
144 }
145 }
146
147 pugi::xml_node annotations = root.child("Annotations");
148 for (pugi::xml_node_iterator it = annotations.begin(); it != annotations.end(); ++it)
149 {
150 std::shared_ptr<Annotation> annotation = std::make_shared<Annotation>();
151
152 annotation->setName(it->attribute("Name").value());
153 annotation->setTypeFromString(it->attribute("Type").value());
154 std::string annotColor = it->attribute("Color").value();
155 if (!annotColor.empty()) {

Callers

nothing calls this directly

Calls 14

removeAllAnnotationsMethod · 0.80
removeAllGroupsMethod · 0.80
emptyMethod · 0.80
setNameMethod · 0.80
setColorMethod · 0.80
addGroupMethod · 0.80
getGroupsMethod · 0.80
getNameMethod · 0.80
setGroupMethod · 0.80
setTypeFromStringMethod · 0.80
sizeMethod · 0.80
addAnnotationMethod · 0.80

Tested by

no test coverage detected