fw4spl
SJpgImageSeriesWriter.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/SJpgImageSeriesWriter.hpp"
8 
9 #include "ioITK/JpgImageWriterService.hpp"
10 
11 #include <fwCore/base.hpp>
12 
13 #include <fwData/Image.hpp>
14 #include <fwData/location/Folder.hpp>
15 
16 #include <fwGui/Cursor.hpp>
17 #include <fwGui/dialog/LocationDialog.hpp>
18 #include <fwGui/dialog/MessageDialog.hpp>
19 #include <fwGui/dialog/ProgressDialog.hpp>
20 
21 #include <fwIO/IWriter.hpp>
22 
23 #include <fwMedData/ImageSeries.hpp>
24 
25 #include <fwServices/macros.hpp>
26 
27 namespace ioITK
28 {
29 
30 fwServicesRegisterMacro( ::fwIO::IWriter, ::ioITK::SJpgImageSeriesWriter, ::fwMedData::ImageSeries );
31 
32 //------------------------------------------------------------------------------
33 
34 SJpgImageSeriesWriter::SJpgImageSeriesWriter() noexcept
35 {
36 }
37 
38 //------------------------------------------------------------------------------
39 
40 SJpgImageSeriesWriter::~SJpgImageSeriesWriter() noexcept
41 {
42 }
43 
44 //------------------------------------------------------------------------------
45 
47 {
48  return ::fwIO::FOLDER;
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 {
63  static ::boost::filesystem::path _sDefaultPath;
64 
66  dialog.setTitle(m_windowTitle.empty() ? "Choose a directory to save image" : m_windowTitle);
67  dialog.setDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
68  dialog.setOption(::fwGui::dialog::ILocationDialog::WRITE);
69  dialog.setType(::fwGui::dialog::ILocationDialog::FOLDER);
70 
71  ::fwData::location::Folder::sptr result;
72 
73  while (result = ::fwData::location::Folder::dynamicCast( dialog.show() ))
74  {
75  if( ::boost::filesystem::is_empty(result->getFolder()) )
76  {
77  break;
78  }
79  // message box
81  messageBox.setTitle("Overwrite confirmation");
82  messageBox.setMessage("The selected directory is not empty. Write anyway ?");
83  messageBox.setIcon(::fwGui::dialog::IMessageDialog::QUESTION);
84  messageBox.addButton(::fwGui::dialog::IMessageDialog::YES);
85  messageBox.addButton(::fwGui::dialog::IMessageDialog::CANCEL);
86  if( messageBox.show() == ::fwGui::dialog::IMessageDialog::YES)
87  {
88  break;
89  }
90  }
91 
92  if (result)
93  {
94  _sDefaultPath = result->getFolder().parent_path();
95  dialog.saveDefaultLocation( ::fwData::location::Folder::New(_sDefaultPath) );
96  this->setFolder(result->getFolder());
97  }
98  else
99  {
100  this->clearLocations();
101  }
102 }
103 
104 //------------------------------------------------------------------------------
105 
107 {
108  SLM_TRACE_FUNC();
109 }
110 
111 //------------------------------------------------------------------------------
112 
114 {
115  SLM_TRACE_FUNC();
116 }
117 
118 //------------------------------------------------------------------------------
119 
120 void SJpgImageSeriesWriter::info(std::ostream& _sstream )
121 {
122  _sstream << "SJpgImageSeriesWriter::info";
123 }
124 
125 //------------------------------------------------------------------------------
126 
128 {
129  SLM_TRACE_FUNC();
130 
131  if( this->hasLocationDefined() )
132  {
133  // Retrieve dataStruct associated with this service
134  ::fwMedData::ImageSeries::csptr imageSeries = this->getInput< ::fwMedData::ImageSeries >(::fwIO::s_DATA_KEY);
135  if (!imageSeries)
136  {
137  FW_DEPRECATED_KEY(::fwIO::s_DATA_KEY, "inout", "18.0");
138  imageSeries = this->getObject< ::fwMedData::ImageSeries >();
139  }
140  SLM_ASSERT("Image series is not instanced", imageSeries);
141  SLM_ASSERT("Image from image series is not instanced", imageSeries->getImage());
142 
143  ::fwGui::Cursor cursor;
144  cursor.setCursor(::fwGui::ICursor::BUSY);
145  JpgImageWriterService::saveImage(this->getFolder(), imageSeries->getImage());
146  cursor.setDefaultCursor();
147  }
148 }
149 
150 //------------------------------------------------------------------------------
151 
152 } // namespace ioITK
#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.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
Defines the generic message box for IHM. Use the Delegate design pattern.
virtual FWGUI_API void setDefaultLocation(::fwData::location::ILocation::sptr loc) override
Set the initial location for the dialog.
virtual IOITK_API void stopping() 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.
IOITK_API::fwIO::IOPathType getIOPathType() const override
Return managed file type, here FOLDER.
IOITK_API void info(std::ostream &_sstream) override
Override.
virtual IOITK_API void configuring() override
Override.
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
virtual IOITK_API void configureWithIHM() override
Override.
virtual FWIO_API void configuring() override
This method proposes to parse xml configuration to retrieve file/files/folder paths.
Definition: IWriter.cpp:122
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
FWIO_APIconst::boost::filesystem::path & getFolder() const
Returns folder path set by the user or set during service configuration.
Definition: IWriter.cpp:75
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
IOPathType
IOPathType defines different type of paths used by service readers/writers.
Definition: ioTypes.hpp:19
Write an image to jpg format.
virtual IOITK_API void starting() override
Override.
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.
FWIO_API void setFolder(const ::boost::filesystem::path &folder)
Sets folder path.
Definition: IWriter.cpp:84
FWGUI_API void setType(::fwGui::dialog::ILocationDialog::Types type) override
Set the type of location for the dialog (SINGLE_FILE, FORLDER, MULTI_FILES)
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.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
FWIO_API bool hasLocationDefined() const
Returns if a location has been defined ( by the configuration process or directly by user ) ...
Definition: IWriter.cpp:184
IOITK_API void updating() override
Override.
std::string m_windowTitle
Title of the window that will open when the configureWithIHM slot is called.
Definition: IWriter.hpp:171