Fraxinus  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),
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 }
boost::shared_ptr< class FileManagerService > FileManagerServicePtr
void removeFileReaderWriter(FileReaderWriterService *service)
vtkPolyDataPtr loadVtkPolyData(QString filename)
std::vector< DataPtr > read(const QString &filename)
FileManagerServiceProxy(ctkPluginContext *context)
static FileManagerServicePtr getNullObject()
std::vector< FileReaderWriterServicePtr > getImportersForDataType(QString dataType)
boost::shared_ptr< class Data > DataPtr
QString getFileReaderName(const QString &filename)
static FileManagerServicePtr create(ctkPluginContext *context)
vtkImageDataPtr loadVtkImageData(QString filename)
QString findDataTypeFromFile(QString filename)
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Helper class for listening to services being added, modified and removed.
DataPtr load(const QString &uid, const QString &filename)
std::vector< FileReaderWriterServicePtr > getExportersForDataType(QString dataType)
bool readInto(DataPtr data, QString path)
vtkSmartPointer< class vtkImageData > vtkImageDataPtr
void addFileReaderWriter(FileReaderWriterService *service)
void save(DataPtr data, const QString &filename)
bool canLoad(const QString &type, const QString &filename)
Namespace for all CustusX production code.