fw4spl
TransformationMatrix3DReaderService.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "ioData/TransformationMatrix3DReaderService.hpp"
8 
9 #include <fwCore/base.hpp>
10 
11 #include <fwData/location/Folder.hpp>
12 #include <fwData/location/SingleFile.hpp>
13 #include <fwData/TransformationMatrix3D.hpp>
14 
15 #include <fwDataIO/reader/TransformationMatrix3DReader.hpp>
16 
17 #include <fwGui/dialog/LocationDialog.hpp>
18 
19 #include <fwIO/IReader.hpp>
20 
21 #include <fwServices/macros.hpp>
22 
23 #include <boost/filesystem/operations.hpp>
24 
25 #include <fstream>
26 #include <iostream>
27 
28 namespace ioData
29 {
30 
31 //-----------------------------------------------------------------------------
32 
35 
36 //------------------------------------------------------------------------------
37 
39 {
40  return ::fwIO::FILE;
41 }
42 
43 //-----------------------------------------------------------------------------
44 
45 void TransformationMatrix3DReaderService::info(std::ostream& _sstream )
46 {
47  this->SuperClass::info( _sstream );
48  _sstream << std::endl << " TransformationMatrix3D object reader";
49 }
50 
51 //-----------------------------------------------------------------------------
52 
54 {
55  std::vector< std::string > extensions;
56  extensions.push_back(".trf");
57  return extensions;
58 }
59 
60 //-----------------------------------------------------------------------------
61 
63 {
65 }
66 
67 //-----------------------------------------------------------------------------
68 
70 {
72 }
73 
74 //------------------------------------------------------------------------------
75 
77 {
79  static ::boost::filesystem::path _sDefaultPath;
80 
82  dialogFile.setTitle(m_windowTitle.empty() ? "Choose a file to load a transformation matrix" : m_windowTitle);
83  dialogFile.setDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
84  dialogFile.addFilter("TRF files", "*.trf");
85  dialogFile.setOption(::fwGui::dialog::ILocationDialog::READ);
86 
87  ::fwData::location::SingleFile::sptr result;
88  result = ::fwData::location::SingleFile::dynamicCast( dialogFile.show() );
89  if (result)
90  {
91  _sDefaultPath = result->getPath().parent_path();
92  dialogFile.saveDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
93  this->setFile(result->getPath());
94  }
95  else
96  {
97  this->clearLocations();
98  }
99 }
100 
101 //-----------------------------------------------------------------------------
102 
104 {
105  SLM_TRACE_FUNC();
106 }
107 
108 //-----------------------------------------------------------------------------
109 
111 {
112  SLM_TRACE_FUNC();
113  if(this->hasLocationDefined())
114  {
115  // Retrieve object
116  ::fwData::TransformationMatrix3D::sptr matrix =
117  this->getInOut< ::fwData::TransformationMatrix3D >(::fwIO::s_DATA_KEY);
118  if (!matrix)
119  {
120  FW_DEPRECATED_KEY(::fwIO::s_DATA_KEY, "inout", "18.0");
121  matrix = this->getObject< ::fwData::TransformationMatrix3D >();
122  }
123  SLM_ASSERT("matrix not instanced", matrix);
124 
125  ::fwDataIO::reader::TransformationMatrix3DReader::sptr reader =
126  ::fwDataIO::reader::TransformationMatrix3DReader::New();
127  reader->setObject( matrix );
128  reader->setFile(this->getFile());
129  reader->read();
130 
131  // Notify reading
132  auto sig = matrix->signal< ::fwData::Object::ModifiedSignalType >(
134  {
135  ::fwCom::Connection::Blocker block(sig->getConnection(m_slotUpdate));
136  sig->asyncEmit();
137  }
138  }
139 }
140 
141 //-----------------------------------------------------------------------------
142 
143 }
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Definition: spyLog.hpp:366
std::string m_windowTitle
Title of the window that will open when the configureWithIHM slot is called.
Definition: IReader.hpp:207
virtual IODATA_API void configuring() override
Configuring method : calls implementation from io::IReader
Class allowing to block a Connection.
Definition: Connection.hpp:20
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
This service read a fwData::TransformationMatrix3D from a .trf file.
FWIO_API bool hasLocationDefined() const
Returns if a location has been defined ( by the configuration process or directly by user ) ...
Definition: IReader.cpp:233
virtual FWIO_API void configuring() override
This method proposes to parse xml configuration to retrieve file/files/folder paths.
Definition: IReader.cpp:144
virtual IODATA_API std::vector< std::string > getSupportedExtensions() override
returns (filename) extension
virtual IODATA_API void starting() override
Starting method. This method is called by start() from base service ( fwServices::IService ) ...
virtual FWGUI_API void setDefaultLocation(::fwData::location::ILocation::sptr loc) override
Set the initial location for the dialog.
FWGUI_API::fwGui::dialog::ILocationDialog & setOption(::fwGui::dialog::ILocationDialog::Options option) override
allow to set option to the file dialog mode=READ/WRITE, check=FILE_MUST_EXIST
FWGUI_API::fwData::location::ILocation::sptr show() override
Display the dialog.
FWGUI_API void addFilter(const std::string &filterName, const std::string &wildcardList) override
specify some filtering when browsing files:
virtual IODATA_API void stopping() override
Stopping method. This method is called by stop() from base service ( fwServices::IService ) ...
virtual IODATA_API::fwIO::IOPathType getIOPathType() const override
Return path type managed by the service, here FILE.
FWIO_APIconst::boost::filesystem::path & getFile() const
Returns the file path set by the user or set during service configuration.
Definition: IReader.cpp:62
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
Definition: IService.hpp:690
FWIO_API void setFile(const ::boost::filesystem::path &file)
Sets file path.
Definition: IReader.cpp:71
IODATA_API void updating() override
Updating method. This method is called by update() from base service ( fwServices::IService ) ...
Reader service API. It manages extension points definition and extension configuration.
Definition: IReader.hpp:34
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
This class represents a 3D transformation matrix (4x4).
IOPathType
IOPathType defines different type of paths used by service readers/writers.
Definition: ioTypes.hpp:19
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
Defines the generic file/folder selector dialog for IHM.
virtual IODATA_API void configureWithIHM() override
Configure the image path.
The namespace ioData contains reader and writer services for basic fwData::Object which doesn&#39;t need ...
virtual IODATA_API void info(std::ostream &_sstream) override
Info method.
FWIO_API void clearLocations()
Clear any location set by the setFile/setFiles/setFolder setter.
Definition: IReader.cpp:137
FWGUI_API void saveDefaultLocation(::fwData::location::ILocation::sptr loc) override
Save the specified default location for the dialog in preferences (if available)
virtual FWSERVICES_API void info(std::ostream &_sstream)
Write information in a stream.
Definition: IService.cpp:74