16 #include <QDomDocument>
19 #include <QTextStream>
57 mActiveData(activeData)
63 connect(
settings(), SIGNAL(valueChangedFor(QString)),
this, SLOT(settingsChangedSlot(QString)));
130 mStreams[stream->getUid()] = stream;
163 for (
unsigned i = 0; i < names.size(); ++i)
174 std::map<QString, LandmarkProperty>::iterator iter;
212 if (
mData.count(uid))
217 reportError(
"DataManagerImpl::loadData() Got no DataFactory");
222 reportError(
"Failed to find loaded for: [" + path +
"]");
232 reportError(
"Failed to load file: [" + path +
"]");
242 if (data->getUid().contains(
'%'))
244 QString uid = data->getUid();
245 QString name = data->getName();
253 if (!overWrite &&
mData.count(data->getUid()) &&
mData[data->getUid()]!=data)
254 reportError(QString(
"Overwriting Data with uid=%1 with new object into PasM").arg(data->getUid()));
256 mData[data->getUid()] = data;
263 DataMap::const_iterator iter =
mData.find(uid);
264 if (iter ==
mData.end())
276 std::map<QString, ImagePtr> retval;
277 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
282 retval[iter->first] = image;
289 std::map<QString, MeshPtr> retval;
290 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
295 retval[iter->first] = mesh;
302 QDomDocument doc = parentNode.ownerDocument();
303 QDomElement dataManagerNode = doc.createElement(
"datamanager");
304 parentNode.appendChild(dataManagerNode);
308 QDomElement landmarkPropsNode = doc.createElement(
"landmarkprops");
312 QDomElement landmarkPropNode = doc.createElement(
"landmarkprop");
313 it->second.addXml(landmarkPropNode);
314 landmarkPropsNode.appendChild(landmarkPropNode);
316 dataManagerNode.appendChild(landmarkPropsNode);
318 QDomElement landmarksNode = doc.createElement(
"landmarks");
320 dataManagerNode.appendChild(landmarksNode);
322 QDomElement centerNode = doc.createElement(
"center");
324 dataManagerNode.appendChild(centerNode);
326 QDomElement otNode = doc.createElement(
"operatingTable");
328 dataManagerNode.appendChild(otNode);
330 for (DataMap::const_iterator iter =
mData.begin(); iter !=
mData.end(); ++iter)
332 QDomElement dataNode = doc.createElement(
"data");
333 dataManagerNode.appendChild(dataNode);
334 iter->second->addXml(dataNode);
341 QDomNode toolManagerNode = dataManagerNode.parentNode().namedItem(
"toolManager");
343 QDomNode registrationHistory = dataManagerNode.namedItem(
"registrationHistory");
344 if (registrationHistory.isNull())
345 registrationHistory = toolManagerNode.namedItem(
"registrationHistory");
348 QDomNode landmarksNode = dataManagerNode.namedItem(
"landmarkprops");
349 QDomElement landmarkNode = landmarksNode.firstChildElement(
"landmarkprop");
350 for (; !landmarkNode.isNull(); landmarkNode = landmarkNode.nextSiblingElement(
"landmarkprop"))
353 landmarkProp.
parseXml(landmarkNode);
359 QDomNode patientLandmarksNode = dataManagerNode.namedItem(
"landmarks");
360 if (patientLandmarksNode.isNull())
361 patientLandmarksNode = toolManagerNode.namedItem(
"landmarks");
365 std::map<DataPtr, QDomNode> datanodes;
367 QDomNode child = dataManagerNode.firstChild();
368 for (; !child.isNull(); child = child.nextSibling())
370 if (child.nodeName() ==
"data")
374 datanodes[data] = child.toElement();
380 for (std::map<DataPtr, QDomNode>::iterator iter = datanodes.begin(); iter != datanodes.end(); ++iter)
382 iter->first->parseXml(iter->second);
388 child = dataManagerNode.firstChild();
389 while (!child.isNull())
391 if (child.toElement().tagName() ==
"center")
393 const QString centerString = child.toElement().text();
394 if (!centerString.isEmpty())
396 Vector3D center = Vector3D::fromString(centerString);
400 if (child.toElement().tagName() ==
"operatingTable")
402 const QString ot = child.toElement().text();
410 child = child.nextSibling();
416 QString uid = node.toElement().attribute(
"uid");
417 QString name = node.toElement().attribute(
"name");
418 QString type = node.toElement().attribute(
"type");
420 QDir relativePath = this->findRelativePath(node, rootPath);
421 QString absolutePath = this->findAbsolutePath(relativePath, rootPath);
423 if (
mData.count(uid))
429 reportWarning(QString(
"Unknown type: %1 for file %2").arg(type).arg(absolutePath));
442 data->setFilename(relativePath.path());
447 QString newPath = rootPath+
"/"+data->getFilename();
448 if (QDir::cleanPath(absolutePath) != QDir::cleanPath(newPath))
450 reportWarning(QString(
"Detected old data format, converting from %1 to %2").arg(absolutePath).arg(newPath));
457 QDir DataManagerImpl::findRelativePath(QDomElement node, QString rootPath)
459 QString path = this->findPath(node);
460 QDir relativePath = QDir(QString(path));
462 QDir patientDataDir(rootPath);
463 relativePath.setPath(patientDataDir.relativeFilePath(relativePath.path()));
468 QString DataManagerImpl::findPath(QDomElement node)
470 QDomElement filePathNode = node.namedItem(
"filePath").toElement();
472 if (filePathNode.isNull())
475 QString path = filePathNode.text();
481 QString DataManagerImpl::findAbsolutePath(QDir relativePath, QString rootPath)
483 QString absolutePath = relativePath.path();
484 if (!rootPath.isEmpty())
485 absolutePath = rootPath +
"/" + relativePath.path();
506 void DataManagerImpl::settingsChangedSlot(QString key)
508 if (key ==
"View/clinicalView")
517 QString val =
settings()->
value(
"View/clinicalView", defVal).toString();
518 CLINICAL_VIEW view = string2enum<CLINICAL_VIEW>(val);
526 if (!uidBase.contains(
"%"))
529 size_t numMatches = 1;
534 while (numMatches != 0)
549 QString& uid = *_uid;
550 QString& name = *_name;
554 if (uid.contains(
"%"))
556 uid = uid.arg(recNumber);
559 if (name.contains(
"%"))
564 name = name.arg(recNumber);
578 report(
"Removed data [" + uid +
"].");
585 ImagePtr image = boost::dynamic_pointer_cast<Image>(data);
587 if (!data->getFilename().isEmpty())
589 files << QDir(basePath).absoluteFilePath(data->getFilename());
594 for (
int i=0; i<files.size(); ++i)
596 if (!QFileInfo(files[i]).exists())
598 report(QString(
"Removing %1 from disk").arg(files[i]));
599 QFile(files[i]).remove();