fw4spl
TransformationMatrix3DWriterService.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/TransformationMatrix3DWriterService.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 
12 #include <fwCore/base.hpp>
13 
14 #include <fwData/location/Folder.hpp>
15 #include <fwData/location/SingleFile.hpp>
16 #include <fwData/TransformationMatrix3D.hpp>
17 
18 #include <fwDataIO/writer/TransformationMatrix3DWriter.hpp>
19 
20 #include <fwGui/dialog/LocationDialog.hpp>
21 
22 #include <fwServices/macros.hpp>
23 
24 #include <boost/filesystem/operations.hpp>
25 
26 #include <fstream>
27 #include <iostream>
28 
29 namespace ioData
30 {
31 
32 //-----------------------------------------------------------------------------
33 
36 
37 //-----------------------------------------------------------------------------
38 
39 void TransformationMatrix3DWriterService::info(std::ostream& _sstream )
40 {
41  this->SuperClass::info( _sstream );
42  _sstream << std::endl << " TransformationMatrix3D object writer";
43 }
44 
45 //-----------------------------------------------------------------------------
46 
48 {
50 }
51 
52 //------------------------------------------------------------------------------
53 
55 {
56  return ::fwIO::FILE;
57 }
58 
59 //-----------------------------------------------------------------------------
60 
62 {
64 }
65 
66 //------------------------------------------------------------------------------
67 
69 {
71  static ::boost::filesystem::path _sDefaultPath("");
72 
74  dialogFile.setTitle(m_windowTitle.empty() ? "Choose a file to save a transformation matrix" : m_windowTitle);
75  dialogFile.setDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
76  dialogFile.addFilter("TRF files", "*.trf");
77  dialogFile.setOption(::fwGui::dialog::ILocationDialog::WRITE);
78 
79  ::fwData::location::SingleFile::sptr result;
80  result = ::fwData::location::SingleFile::dynamicCast( dialogFile.show() );
81  if (result)
82  {
83  _sDefaultPath = result->getPath().parent_path();
84  dialogFile.saveDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
85  this->setFile(result->getPath());
86  }
87  else
88  {
89  this->clearLocations();
90  }
91 
92 }
93 
94 //-----------------------------------------------------------------------------
95 
97 {
99 }
100 
101 //-----------------------------------------------------------------------------
102 
104 {
105  SLM_TRACE_FUNC();
106  if(this->hasLocationDefined())
107  {
108  // Retrieve object
109  ::fwData::TransformationMatrix3D::csptr matrix =
110  this->getInput< ::fwData::TransformationMatrix3D >(::fwIO::s_DATA_KEY);
111  if (!matrix)
112  {
113  FW_DEPRECATED_KEY(::fwIO::s_DATA_KEY, "inout", "18.0");
114  matrix = this->getObject< ::fwData::TransformationMatrix3D >();
115  }
116  SLM_ASSERT("matrix not instanced", matrix);
117 
118  ::fwDataIO::writer::TransformationMatrix3DWriter::sptr writer =
119  ::fwDataIO::writer::TransformationMatrix3DWriter::New();
120  writer->setObject( matrix );
121  writer->setFile(this->getFile());
122  writer->write();
123  }
124 }
125 
126 //-----------------------------------------------------------------------------
127 
128 }
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Definition: spyLog.hpp:366
virtual IODATA_API::fwIO::IOPathType getIOPathType() const override
Return path type managed by the service, here FILE.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
virtual IODATA_API void stopping() override
Stopping method. This method is called by stop() from base service ( fwServices::IService ) ...
virtual IODATA_API void configuring() override
Configuring method : calls implementation from io::IWriter
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:
This service write a fwData::TransformationMatrix3D into a .trf file.
FWIO_API void setFile(const ::boost::filesystem::path &file)
Sets file path.
Definition: IWriter.cpp:49
virtual IODATA_API void info(std::ostream &_sstream) override
Info method.
virtual FWIO_API void configuring() override
This method proposes to parse xml configuration to retrieve file/files/folder paths.
Definition: IWriter.cpp:122
FWIO_APIconst::boost::filesystem::path & getFile() const
Returns the file path set by the user or set during service configuration.
Definition: IWriter.cpp:40
FWIO_API void clearLocations()
Clear any location set by the setFile/setFiles/setFolder setter.
Definition: IWriter.cpp:115
#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
virtual IODATA_API void configureWithIHM() override
Configure the matrix path.
Writer service API. It manages extension points definition and extension configuration.
Definition: IWriter.hpp:33
FWGUI_API void setTitle(const std::string &title) override
Set the title for the dialog.
Defines the generic file/folder selector dialog for IHM.
The namespace ioData contains reader and writer services for basic fwData::Object which doesn&#39;t need ...
FWGUI_API void saveDefaultLocation(::fwData::location::ILocation::sptr loc) override
Save the specified default location for the dialog in preferences (if available)
IODATA_API void updating() override
Updating method. This method is called by update() from base service ( fwServices::IService ) ...
FWIO_API bool hasLocationDefined() const
Returns if a location has been defined ( by the configuration process or directly by user ) ...
Definition: IWriter.cpp:184
virtual FWSERVICES_API void info(std::ostream &_sstream)
Write information in a stream.
Definition: IService.cpp:74
std::string m_windowTitle
Title of the window that will open when the configureWithIHM slot is called.
Definition: IWriter.hpp:171