fw4spl
io/ioDicom/src/ioDicom/SSeriesDBMerger.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 "ioDicom/SSeriesDBMerger.hpp"
8 
9 #include <fwData/Vector.hpp>
10 
11 #include <fwGui/dialog/MessageDialog.hpp>
12 
13 #include <fwMedDataTools/helper/SeriesDB.hpp>
14 
15 #include <fwServices/macros.hpp>
16 
17 #include <boost/foreach.hpp>
18 
19 namespace ioDicom
20 {
21 
22 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::ioDicom::SSeriesDBMerger, ::fwData::Vector );
23 
24 //------------------------------------------------------------------------------
25 
27 {
28 }
29 
30 //------------------------------------------------------------------------------
31 
33 {
34 }
35 
36 //------------------------------------------------------------------------------
37 
38 void SSeriesDBMerger::info(std::ostream& _sstream )
39 {
40  _sstream << "SSeriesDBMerger::info";
41 }
42 
43 //------------------------------------------------------------------------------
44 
46 {
47 }
48 
49 //------------------------------------------------------------------------------
50 
52 {
53 }
54 
55 //------------------------------------------------------------------------------
56 
58 {
59 }
60 
61 //------------------------------------------------------------------------------
62 
64 {
65  auto destinationSeriesDB = this->getInOut< ::fwMedData::SeriesDB>("seriesDB");
66  SLM_ASSERT("'seriesDB' key is not found.", destinationSeriesDB);
67 
68  ::fwMedDataTools::helper::SeriesDB sDBhelper(destinationSeriesDB);
69  ::fwMedData::SeriesDB::ContainerType container = destinationSeriesDB->getContainer();
70  ::fwData::Vector::csptr selectedSeries = this->getInput< ::fwData::Vector >("selectedSeries");
71 
72  // Save added series in this container in order to display information on the push
73  std::vector< ::fwMedData::Series::sptr > addedSeries;
74 
75  // Loop through all selected series
76  for(const ::fwData::Object::sptr& obj: selectedSeries->getContainer())
77  {
78  ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast(obj);
79 
80  if(series && std::find(container.begin(),container.end(), series) == container.end())
81  {
82  sDBhelper.add(series);
83  addedSeries.push_back(series);
84  }
85  }
86  sDBhelper.notify();
87 
88  // Display the informations
90  messageBox.setIcon(::fwGui::dialog::IMessageDialog::INFO);
91  messageBox.addButton(::fwGui::dialog::IMessageDialog::OK);
92  messageBox.setTitle("Push Series");
93 
94  if(selectedSeries->empty())
95  {
96  messageBox.setMessage( "Unable to push series, there is no series selected." );
97  }
98  else if(addedSeries.empty())
99  {
100  messageBox.setMessage( "Unable to push series, the series are already present in the database." );
101  }
102  else
103  {
104  std::stringstream ss;
105  if(addedSeries.size()==1)
106  {
107  ss << addedSeries.size() << " series has been correctly pushed in the database:\n";
108  }
109  else
110  {
111  ss << addedSeries.size() << " series have been correctly pushed in the database:\n";
112  }
113 
114  for(const ::fwMedData::Series::sptr& series: addedSeries)
115  {
116  std::string description = series->getDescription();
117  description = (description.empty()) ? "[No description]" : description;
118  ss << "- " << description << std::endl;
119  }
120  messageBox.setMessage( ss.str() );
121  }
122 
123  messageBox.show();
124 }
125 
126 //------------------------------------------------------------------------------
127 
128 } // namespace ioDicom
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.
FWMEDDATATOOLS_API void add(::fwMedData::Series::sptr newSeries)
Add a Series in the SeriesDB.
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
IODICOM_API SSeriesDBMerger() noexcept
Constructor.
This class defines a vector of objects.
virtual FWGUI_API void addButton(IMessageDialog::Buttons button) override
Add a button (OK, YES_NO, YES, NO, CANCEL)
This service is used to merge selected series with a SeriesDB. All the series in the vector are pushe...
virtual FWGUI_API IMessageDialog::Buttons show() override
Show the message box and return the clicked button.
ioDicom contains services used to deal with the DICOM standard.
#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 IODICOM_API ~SSeriesDBMerger() noexcept
Destructor.
virtual FWGUI_API void setIcon(IMessageDialog::Icons icon) override
Set the icon (CRITICAL, WARNING, INFO or QUESTION)
IODICOM_API void info(std::ostream &_sstream) override
Override.
FWMEDDATATOOLS_API void notify()
Send the signal of modification.
virtual IODICOM_API void starting() override
Override.
virtual IODICOM_API void configuring() override
Do nothing.
IODICOM_API void updating() override
Override.
virtual IODICOM_API void stopping() override
Override.
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the message box.