fw4spl
ioITK/src/ioITK/SImageSeriesWriter.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 "ioITK/SImageSeriesWriter.hpp"
8 
9 #include "ioITK/InrImageWriterService.hpp"
10 
11 #include <fwCore/base.hpp>
12 
13 #include <fwData/Image.hpp>
14 #include <fwData/location/Folder.hpp>
15 #include <fwData/location/SingleFile.hpp>
16 
17 #include <fwGui/Cursor.hpp>
18 #include <fwGui/dialog/LocationDialog.hpp>
19 #include <fwGui/dialog/MessageDialog.hpp>
20 #include <fwGui/dialog/ProgressDialog.hpp>
21 
22 #include <fwIO/IWriter.hpp>
23 
24 #include <fwItkIO/ImageWriter.hpp>
25 
26 #include <fwMedData/ImageSeries.hpp>
27 
28 #include <fwServices/macros.hpp>
29 
30 namespace ioITK
31 {
32 
33 fwServicesRegisterMacro( ::fwIO::IWriter, ::ioITK::SImageSeriesWriter, ::fwMedData::ImageSeries );
34 
35 //------------------------------------------------------------------------------
36 
37 SImageSeriesWriter::SImageSeriesWriter() noexcept
38 {
39 }
40 
41 //------------------------------------------------------------------------------
42 
43 SImageSeriesWriter::~SImageSeriesWriter() noexcept
44 {
45 }
46 
47 //------------------------------------------------------------------------------
48 
50 {
51  return ::fwIO::FILE;
52 }
53 
54 //------------------------------------------------------------------------------
55 
57 {
59 }
60 
61 //------------------------------------------------------------------------------
62 //
64 {
66  static ::boost::filesystem::path _sDefaultPath;
67 
69  dialogFile.setTitle(m_windowTitle.empty() ? "Choose an inrimage file to save image" : m_windowTitle);
70  dialogFile.setDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
71  dialogFile.addFilter("Inrimage", "*.inr.gz");
72  dialogFile.setOption(::fwGui::dialog::ILocationDialog::WRITE);
73 
74  ::fwData::location::SingleFile::sptr result;
75  result = ::fwData::location::SingleFile::dynamicCast( dialogFile.show() );
76  if (result)
77  {
78  _sDefaultPath = result->getPath().parent_path();
79  this->setFile( result->getPath() );
80  dialogFile.saveDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
81  }
82  else
83  {
84  this->clearLocations();
85  }
86 }
87 
88 //------------------------------------------------------------------------------
89 
91 {
93 }
94 
95 //------------------------------------------------------------------------------
96 
98 {
100 }
101 
102 //------------------------------------------------------------------------------
103 
104 void SImageSeriesWriter::info(std::ostream& _sstream )
105 {
106  _sstream << "SImageSeriesWriter::info";
107 }
108 
109 //------------------------------------------------------------------------------
110 
112 {
113  SLM_TRACE_FUNC();
114 
115  if( this->hasLocationDefined() )
116  {
117  // Retrieve dataStruct associated with this service
118 
119  ::fwMedData::ImageSeries::csptr iseries = this->getInput< ::fwMedData::ImageSeries >(::fwIO::s_DATA_KEY);
120  if (!iseries)
121  {
122  FW_DEPRECATED_KEY(::fwIO::s_DATA_KEY, "inout", "18.0");
123  iseries = this->getObject< ::fwMedData::ImageSeries >();
124  }
125  const ::fwData::Image::csptr& associatedImage = iseries->getImage();
126  SLM_ASSERT("associatedImage not instanced", associatedImage);
127 
128  ::fwGui::Cursor cursor;
129  cursor.setCursor(::fwGui::ICursor::BUSY);
130  InrImageWriterService::saveImage(this->getFile(), associatedImage);
131  cursor.setDefaultCursor();
132  }
133 }
134 
135 //------------------------------------------------------------------------------
136 
137 } // namespace ioITK
virtual IOITK_API void stopping() override
Override.
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Definition: spyLog.hpp:366
virtual FWGUI_API void setCursor(::fwGui::ICursor::CursorType cursor) override
Set the cursor.
IOITK_API::fwIO::IOPathType getIOPathType() const override
Return managed file type, here FILE.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
virtual FWGUI_API void setDefaultLocation(::fwData::location::ILocation::sptr loc) override
Set the initial location for the dialog.
virtual IOITK_API void starting() override
Override.
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.
virtual IOITK_API void configuring() override
Override.
IOITK_API void updating() override
Override.
FWGUI_API void addFilter(const std::string &filterName, const std::string &wildcardList) override
specify some filtering when browsing files:
virtual IOITK_API void configureWithIHM() override
Override.
IOITK_API void info(std::ostream &_sstream) override
Override.
FWIO_API void setFile(const ::boost::filesystem::path &file)
Sets file path.
Definition: IWriter.cpp:49
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
IOPathType
IOPathType defines different type of paths used by service readers/writers.
Definition: ioTypes.hpp:19
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.
Defines the generic cursor for IHM. Use the Delegate design pattern.
FWGUI_API void saveDefaultLocation(::fwData::location::ILocation::sptr loc) override
Save the specified default location for the dialog in preferences (if available)
The namespace ioITK contains services for reader, writer and helper for itk image.
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 FWGUI_API void setDefaultCursor() override
Set the default cursor.
std::string m_windowTitle
Title of the window that will open when the configureWithIHM slot is called.
Definition: IWriter.hpp:171