NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxFileManagerServiceProxy.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 
13 #include "boost/bind.hpp"
14 #include "cxNullDeleter.h"
15 
16 namespace cx
17 {
18 
20 {
22 }
23 
25  mPluginContext(context),
26  mService(FileManagerService::getNullObject())
27 {
28  this->initServiceListener();
29 }
30 
31 
33 {}
34 
36 {
37  return mService->isNull();
38 }
39 
40 bool FileManagerServiceProxy::canLoad(const QString &type, const QString &filename)
41 {
42  return mService->canLoad(type, filename);
43 }
44 
45 DataPtr FileManagerServiceProxy::load(const QString &uid, const QString &filename)
46 {
47  return mService->load(uid, filename);
48 }
49 
51 {
52  return mService->canLoadDataType();
53 }
54 
55 std::vector<DataPtr> FileManagerServiceProxy::read(const QString &filename)
56 {
57  return mService->read(filename);
58 }
59 
61 {
62  return mService->readInto(data, path);
63 }
64 
66 {
67  return mService->findDataTypeFromFile(filename);
68 }
69 
70 void FileManagerServiceProxy::initServiceListener()
71 {
72  mServiceListener.reset(new ServiceTrackerListener<FileManagerService>(
73  mPluginContext,
74  boost::bind(&FileManagerServiceProxy::onServiceAdded, this, _1),
75  boost::function<void (FileManagerService*)>(),
76  boost::bind(&FileManagerServiceProxy::onServiceRemoved, this, _1)
77  ));
78  mServiceListener->open();
79 
80 }
81 
82 void FileManagerServiceProxy::onServiceAdded(FileManagerService *service)
83 {
84  mService.reset(service, null_deleter());
85  //std::cout << "FileManagerServiceProxy added: " << service->objectName().toStdString() << " this (filemanagerservice): " << service << std::endl;
86 }
87 
88 void FileManagerServiceProxy::onServiceRemoved(FileManagerService *service)
89 {
91  //std::cout << "FileManagerServiceProxy removed" << std::endl;
92 }
93 
95 {
96  return mService->loadVtkImageData(filename);
97 }
98 
100 {
101  return mService->loadVtkPolyData(filename);
102 }
103 
104 void FileManagerServiceProxy::save(DataPtr data, const QString &filename)
105 {
106  mService->save(data, filename);
107 }
108 
110 {
111  mService->addFileReaderWriter(service);
112 }
113 
115 {
116  mService->removeFileReaderWriter(service);
117 }
118 
119 std::vector<cx::FileReaderWriterServicePtr> FileManagerServiceProxy::getExportersForDataType(QString dataType)
120 {
121  return mService->getExportersForDataType(dataType);
122 }
123 
124 std::vector<FileReaderWriterServicePtr> FileManagerServiceProxy::getImportersForDataType(QString dataType)
125 {
126  return mService->getImportersForDataType(dataType);
127 }
128 
129 QString FileManagerServiceProxy::getFileReaderName(const QString &filename)
130 {
131  return mService->getFileReaderName(filename);
132 }
133 }
cx::FileManagerServiceProxy::addFileReaderWriter
void addFileReaderWriter(FileReaderWriterService *service)
Definition: cxFileManagerServiceProxy.cpp:109
cx::FileManagerServiceProxy::getFileReaderName
QString getFileReaderName(const QString &filename)
Definition: cxFileManagerServiceProxy.cpp:129
cx::FileManagerServiceProxy::readInto
bool readInto(DataPtr data, QString path)
Definition: cxFileManagerServiceProxy.cpp:60
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::FileManagerServiceProxy::canLoadDataType
QString canLoadDataType() const
Definition: cxFileManagerServiceProxy.cpp:50
cx::ServiceTrackerListener
Helper class for listening to services being added, modified and removed.
Definition: cxServiceTrackerListener.h:53
cx::FileManagerServiceProxy::loadVtkPolyData
vtkPolyDataPtr loadVtkPolyData(QString filename)
Definition: cxFileManagerServiceProxy.cpp:99
vtkImageDataPtr
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
Definition: cxVideoConnectionWidget.h:30
cx::FileManagerServiceProxy::FileManagerServiceProxy
FileManagerServiceProxy(ctkPluginContext *context)
Definition: cxFileManagerServiceProxy.cpp:24
cx::FileManagerServiceProxy::removeFileReaderWriter
void removeFileReaderWriter(FileReaderWriterService *service)
Definition: cxFileManagerServiceProxy.cpp:114
cx::FileManagerServicePtr
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
Definition: cxLogicManager.h:31
cx::FileManagerServiceProxy::~FileManagerServiceProxy
virtual ~FileManagerServiceProxy()
Definition: cxFileManagerServiceProxy.cpp:32
cx::FileManagerServiceProxy::findDataTypeFromFile
QString findDataTypeFromFile(QString filename)
Definition: cxFileManagerServiceProxy.cpp:65
cx::FileManagerServiceProxy::save
void save(DataPtr data, const QString &filename)
Definition: cxFileManagerServiceProxy.cpp:104
cx::FileManagerServiceProxy::isNull
virtual bool isNull()
Definition: cxFileManagerServiceProxy.cpp:35
cxNullDeleter.h
cx::FileManagerServiceProxy::getExportersForDataType
std::vector< FileReaderWriterServicePtr > getExportersForDataType(QString dataType)
Definition: cxFileManagerServiceProxy.cpp:119
cx::FileManagerServiceProxy::read
std::vector< DataPtr > read(const QString &filename)
Definition: cxFileManagerServiceProxy.cpp:55
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cx::FileManagerServiceProxy::create
static FileManagerServicePtr create(ctkPluginContext *context)
Definition: cxFileManagerServiceProxy.cpp:19
cx::vtkPolyDataPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Definition: cxCenterlineRegistration.h:42
cx::FileManagerServiceProxy::canLoad
bool canLoad(const QString &type, const QString &filename)
Definition: cxFileManagerServiceProxy.cpp:40
cx::FileManagerServiceProxy::getImportersForDataType
std::vector< FileReaderWriterServicePtr > getImportersForDataType(QString dataType)
Definition: cxFileManagerServiceProxy.cpp:124
cx::FileManagerServiceProxy::load
DataPtr load(const QString &uid, const QString &filename)
Definition: cxFileManagerServiceProxy.cpp:45
cx::FileManagerServiceProxy::loadVtkImageData
vtkImageDataPtr loadVtkImageData(QString filename)
Definition: cxFileManagerServiceProxy.cpp:94
cxFileManagerServiceProxy.h
cx::FileManagerService::getNullObject
static FileManagerServicePtr getNullObject()
Definition: cxFileManagerService.cpp:19
cx::FileManagerService
Definition: cxFileManagerService.h:28
cx::FileReaderWriterService
Definition: cxFileReaderWriterService.h:30