fw4spl
SDicomSeriesConverter.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 "ioGdcm/SDicomSeriesConverter.hpp"
8 
9 #include <fwCom/HasSignals.hpp>
10 #include <fwCom/Signal.hpp>
11 #include <fwCom/Signal.hxx>
12 
13 #include <fwGdcmIO/reader/SeriesDB.hpp>
14 
15 #include <fwGui/dialog/LoggerDialog.hpp>
16 #include <fwGui/dialog/MessageDialog.hpp>
17 #include <fwGui/dialog/ProgressDialog.hpp>
18 
19 #include <fwJobs/IJob.hpp>
20 #include <fwJobs/Observer.hpp>
21 
22 #include <fwMedDataTools/helper/SeriesDB.hpp>
23 
24 #include <fwServices/macros.hpp>
25 
26 #include <boost/foreach.hpp>
27 
28 namespace ioGdcm
29 {
30 
32 
33 static const ::fwCom::Signals::SignalKeyType JOB_CREATED_SIGNAL = "jobCreated";
34 
35 //------------------------------------------------------------------------------
36 
38 {
39  m_sigJobCreated = newSignal<JobCreatedSignal>( JOB_CREATED_SIGNAL );
40 }
41 //------------------------------------------------------------------------------
42 
44 {
45 }
46 
47 //------------------------------------------------------------------------------
48 
49 void SDicomSeriesConverter::info(std::ostream& _sstream )
50 {
51  _sstream << "SDicomSeriesConverter::info";
52 }
53 
54 //------------------------------------------------------------------------------
55 
57 {
58 }
59 
60 //------------------------------------------------------------------------------
61 
63 {
64 }
65 
66 //------------------------------------------------------------------------------
67 
69 {
70 }
71 
72 //------------------------------------------------------------------------------
73 
75 {
76  // Get Destination SeriesDB
77  ::fwMedData::SeriesDB::sptr destinationSeriesDB = this->getInOut< ::fwMedData::SeriesDB>("target");
78  SLM_ASSERT("The 'target' key doesn't exist.", destinationSeriesDB);
79 
80  ::fwMedData::SeriesDB::csptr dicomSeriesDB = this->getInput< ::fwMedData::SeriesDB >("source");
81  ::fwMedData::SeriesDB::sptr dummy = ::fwMedData::SeriesDB::New();
82 
83  if(dicomSeriesDB->empty())
84  {
86  messageBox.setIcon(::fwGui::dialog::IMessageDialog::INFO);
87  messageBox.addButton(::fwGui::dialog::IMessageDialog::OK);
88  messageBox.setTitle("Read DICOM series");
89  messageBox.setMessage( "There is no DICOM series that can be read." );
90  messageBox.show();
91  }
92  else
93  {
94  ::fwGdcmIO::reader::SeriesDB::sptr reader = ::fwGdcmIO::reader::SeriesDB::New();
95  reader->setObject(dummy);
96  auto job = reader->getJob();
97  m_sigJobCreated->emit(job);
98 
99  try
100  {
101  reader->readFromDicomSeriesDB(dicomSeriesDB, this->getSptr());
102 
103  ::fwLog::Logger::sptr logger = reader->getLogger();
104  logger->sort();
105 
106  std::stringstream ss;
107  ss << "The reading process is over : <b>" << dummy->size() << " series</b> "
108  << ((dummy->size() > 1) ? "have" : "has") << " been found. "
109  << "<br>Please verify the log report to be informed of the potential errors.";
110 
111  bool result = false;
112  if(!job->cancelRequested())
113  {
114  result = ::fwGui::dialog::LoggerDialog::showLoggerDialog("Reading process over", ss.str(), logger);
115  }
116 
117  // If the user cancel the reading process we delete the loaded series
118  if(!result || job->cancelRequested())
119  {
120  ::fwMedDataTools::helper::SeriesDB sDBhelper(dummy);
121  sDBhelper.clear();
122  }
123  else
124  {
125  ::fwMedDataTools::helper::SeriesDB sDBhelper(destinationSeriesDB);
126  sDBhelper.merge(dummy);
127  sDBhelper.notify();
128  }
129  }
130  catch (const std::exception& e)
131  {
132  std::stringstream ss;
133  ss << "Warning during loading : " << e.what();
135  "Warning", ss.str(), ::fwGui::dialog::IMessageDialog::WARNING);
136  }
137  catch( ... )
138  {
140  "Warning", "Warning during loading", ::fwGui::dialog::IMessageDialog::WARNING);
141  }
142  }
143 }
144 
145 //------------------------------------------------------------------------------
146 
147 } // namespace ioGdcm
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.
static FWGUI_API IMessageDialog::Buttons showMessageDialog(const std::string &title, const std::string &message,::fwGui::dialog::IMessageDialog::Icons icon=INFO)
Defines an helper to modify an fwMedData::SeriesDB and create in parallel the message to announce thi...
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
std::shared_ptr< JobCreatedSignal > m_sigJobCreated
Signal emitted when a job is created.
virtual IOGDCM_API ~SDicomSeriesConverter() noexcept override
Destructor.
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
FWMEDDATATOOLS_API void clear()
Clear all series in the SeriesDB.
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
IOGDCM_API void info(std::ostream &_sstream) override
Override.
#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
virtual IOGDCM_API void configuring() override
Configuring method. This method is used to configure the service.
virtual IOGDCM_API void starting() override
Override.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
ioGdcm contains services use to deal with DICOM using the GDCM library.
IOGDCM_API void updating() override
Override.
FWMEDDATATOOLS_API void notify()
Send the signal of modification.
virtual IOGDCM_API void stopping() override
Override.
static FWGUI_API bool showLoggerDialog(const std::string &title, const std::string &message, const ::fwLog::Logger::sptr &logger)
This service is used to convert DicomSeries from source SeriesDB and push result (ImageSeries, ModelSeries, ...) in target SeriesDB.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.
FWMEDDATATOOLS_API void merge(::fwMedData::SeriesDB::sptr seriesDBIn)
Merge seriesDBIn all series from seriesDBIn to the SeriesDB.
IOGDCM_API SDicomSeriesConverter() noexcept
Constructor.