16 #include <QDomDocument> 19 #include <QTextStream> 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 (
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 +
"].");
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();
boost::shared_ptr< class SpaceProvider > SpaceProviderPtr
QString qstring_cast(const T &val)
DataFactoryPtr mDataFactory
cxResource_EXPORT ProfilePtr profile()
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
void rMprChanged()
emitted when the transformation between patient reference and (data) reference is set ...
FileManagerServicePtr mFileManagerService
int findUniqueUidNumber(QString uidBase) const
virtual void removeData(const QString &uid, QString basePath)
remove data from datamanger, emit signal
void reportError(QString msg)
virtual CLINICAL_VIEW getClinicalApplication() const
boost::shared_ptr< class RegistrationHistory > RegistrationHistoryPtr
std::map< QString, VideoSourcePtr > mStreams
void operatingTableChanged()
OperatingTable getOperatingTable() const
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
OperatingTable mOperatingTable
virtual std::map< QString, LandmarkProperty > getLandmarkProperties() const
boost::shared_ptr< class TransferFunctions3DPresets > PresetTransferFunctions3DPtr
virtual void setLandmarkName(QString uid, QString name)
boost::shared_ptr< class Image > ImagePtr
virtual VideoSourcePtr getStream(const QString &uid) const
boost::shared_ptr< class DataManagerImpl > DataManagerImplPtr
void deleteFiles(DataPtr data, QString basePath)
virtual void generateUidAndName(QString *_uid, QString *_name)
virtual MeshPtr getMesh(const QString &uid) const
boost::shared_ptr< class ActiveData > ActiveDataPtr
void landmarkPropertiesChanged()
emitted when global info about a landmark changed
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
void centerChanged()
emitted when center is changed.
ActiveDataPtr mActiveData
virtual LandmarksPtr getPatientLandmarks()
virtual void addXml(QDomNode &parentNode)
adds xml information about the datamanger and its variabels
void setServices(SpaceProviderPtr spaceProvider, FileManagerServicePtr filemanager)
boost::shared_ptr< class Landmarks > LandmarksPtr
PresetTransferFunctions3DPtr mPresetTransferFunctions3D
void setValue(const QString &key, const QVariant &value)
boost::shared_ptr< class Data > DataPtr
DataManagerImpl(ActiveDataPtr activeData)
virtual void parseXml(QDomNode &datamangerNode, QString absolutePath=QString())
Use a XML node to load data.
virtual StreamMap getStreams() const
static DataManagerImplPtr create(ActiveDataPtr activeData)
virtual std::map< QString, ImagePtr > getImages() const
virtual void setLandmarkNames(std::vector< QString > names)
void reportWarning(QString msg)
virtual void setClinicalApplication(CLINICAL_VIEW application)
std::map< QString, DataPtr > getData() const
void dataAddedOrRemoved()
void parseXml(QDomNode &dataNode)
virtual PresetTransferFunctions3DPtr getPresetTransferFunctions3D() const
boost::shared_ptr< class VideoSource > VideoSourcePtr
virtual Transform3D get_rMpr() const
get the patient registration transform
static QString findConfigFilePath(QString fileName, QString pathRelativeToConfigRoot, QString alternativeAbsolutePath="")
RegistrationHistoryPtr m_rMpr_History
transform from the patient reference to the reference, along with historical data.
Settings * settings()
Shortcut for accessing the settings instance.
virtual void setLandmarkActive(QString uid, bool active)
static LandmarksPtr create()
Transform3D rMot
Transform from OT to reference space.
void setOperatingTable(const OperatingTable &ot)
virtual void deleteLandmarks()
LandmarksPtr mPatientLandmarks
in space patient reference.
virtual Vector3D getCenter() const
current common center point for user viewing.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
virtual void setCenter(const Vector3D ¢er)
virtual ImagePtr getImage(const QString &uid) const
QString changeExtension(QString name, QString ext)
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void setDataFactory(DataFactoryPtr dataFactory)
virtual SpaceProviderPtr getSpaceProvider()
virtual void set_rMpr(const Transform3D &val)
set the transform from patient to reference space
virtual std::map< QString, MeshPtr > getMeshes() const
virtual QString addLandmark()
CLINICAL_VIEW mClinicalApplication
The OperatingTable class.
LandmarkPropertyMap mLandmarkProperties
uid and name
SpaceProviderPtr mSpaceProvider
boost::shared_ptr< class DataFactory > DataFactoryPtr
boost::shared_ptr< class Mesh > MeshPtr
void loadData(DataPtr data)
void clinicalApplicationChanged()
virtual void loadStream(VideoSourcePtr stream)
A history of registration events.
Helper class for xml files used to store ssc/cx data.
Handles transfer function presets.
virtual void clear()
remove all stuff from manager
virtual DataFactoryPtr getDataFactory()
virtual RegistrationHistoryPtr get_rMpr_History() const
virtual ~DataManagerImpl()
Namespace for all CustusX production code.
std::map< QString, VideoSourcePtr > StreamMap