NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxFileReaderWriterService.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
14 #include "cxNullDeleter.h"
15 #include <QFileInfo>
16 #include <QUuid>
18 #include "cxTime.h"
19 #include "cxUtilHelpers.h"
20 
21 namespace cx
22 {
23 
25 {
26  static FileReaderWriterServicePtr mNull;
27  if (!mNull)
28  mNull.reset(new FileReaderWriterServiceNull, null_deleter());
29  return mNull;
30 }
31 
32 //----------------------------
33 
34 bool sameSuffix(QString suffix1, QString suffix2)
35 {
36  return (suffix1.compare(suffix2, Qt::CaseInsensitive) == 0 || suffix1.compare(suffix2, Qt::CaseInsensitive) == 0);
37 }
38 
39 FileReaderWriterImplService::FileReaderWriterImplService(QString name, QString canReadDataType, QString canWriteDataType, QString fileSuffix, PatientModelServicePtr patientModelService) :
40  mName(name),
41  mCanReadDataType(canReadDataType),
42  mCanWriteDataType(canWriteDataType),
43  mFileSuffix(fileSuffix),
44  mPatientModelService(patientModelService)
45 {
46  this->setObjectName(mName);
47 }
48 
50 {
51  return mName;
52 }
53 
55 {
56  return mFileSuffix;
57 }
58 
59 bool FileReaderWriterImplService::canReadInternal(const QString &type, const QString &filename) const
60 {
61  QString fileType = QFileInfo(filename).suffix();
62  bool rightFileType = sameSuffix(fileType, mFileSuffix);
63  bool rightDataType = (type == mCanReadDataType);
64  return rightFileType;
65 }
66 
67 bool FileReaderWriterImplService::canWriteInternal(const QString &type, const QString &filename) const
68 {
69  QString fileType = QFileInfo(filename).suffix();
70  bool rightFileType = sameSuffix(fileType, mFileSuffix);
71  bool rightDataType = (type == mCanWriteDataType);
72  return rightFileType;
73 }
74 
75 DataPtr FileReaderWriterImplService::createData(QString type, QString filename, QString name) const
76 {
77  QFileInfo fileInfo(filename);
78  QString strippedFilename = changeExtension(fileInfo.fileName(), "");
79  QString unique = QUuid::createUuid().toString();
80  //std::cout << "unique: " << unique.toStdString().c_str() << std::endl;
81  QString uid = strippedFilename + "_" + unique + "_" +QDateTime::currentDateTime().toString(timestampSecondsFormat());
82  if(name.isEmpty())
83  name = strippedFilename;
84 
85  DataPtr data = mPatientModelService->createData(type, uid, name);
86 
87  return data;
88 }
89 
90 
91 }
cx::null_deleter
Definition: cxNullDeleter.h:8
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::FileReaderWriterServiceNull
Definition: cxFileReaderWriterServiceNull.h:20
cxUtilHelpers.h
cxFileReaderWriterServiceNull.h
cx::FileReaderWriterImplService::canReadInternal
bool canReadInternal(const QString &type, const QString &filename) const
Definition: cxFileReaderWriterService.cpp:59
cxFileReaderWriterService.h
cxNullDeleter.h
cxPatientModelServiceProxy.h
cx::PatientModelServicePtr
boost::shared_ptr< class PatientModelService > PatientModelServicePtr
Definition: cxLogicManager.h:25
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cx::changeExtension
QString changeExtension(QString name, QString ext)
Definition: cxUtilHelpers.cpp:53
cx::timestampSecondsFormat
QString timestampSecondsFormat()
Definition: cxTime.cpp:18
cx::FileReaderWriterService::getNullObject
static FileReaderWriterServicePtr getNullObject()
Definition: cxFileReaderWriterService.cpp:24
cx::FileReaderWriterImplService::getFileSuffix
virtual QString getFileSuffix() const
Definition: cxFileReaderWriterService.cpp:54
cxTime.h
cx::FileReaderWriterImplService::getName
virtual QString getName() const
Definition: cxFileReaderWriterService.cpp:49
cx::sameSuffix
bool sameSuffix(QString suffix1, QString suffix2)
Definition: cxFileReaderWriterService.cpp:34
cx::FileReaderWriterImplService::createData
DataPtr createData(QString type, QString filename, QString name="") const
Definition: cxFileReaderWriterService.cpp:75
cx::FileReaderWriterServicePtr
boost::shared_ptr< class FileReaderWriterService > FileReaderWriterServicePtr
Definition: cxForwardDeclarations.h:118
cx::FileReaderWriterImplService::FileReaderWriterImplService
FileReaderWriterImplService(QString name, QString canReadDataType, QString canWriteDataType, QString fileSuffix, PatientModelServicePtr patientModelService)
Definition: cxFileReaderWriterService.cpp:39
cx::FileReaderWriterImplService::canWriteInternal
bool canWriteInternal(const QString &type, const QString &filename) const
Definition: cxFileReaderWriterService.cpp:67