fw4spl
ui/uiIO/src/uiIO/action/SSeriesDBMerger.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 "uiIO/action/SSeriesDBMerger.hpp"
8 
9 #include <fwCom/Signal.hxx>
10 #include <fwCom/Slots.hpp>
11 #include <fwCom/Slots.hxx>
12 
13 #include <fwGui/Cursor.hpp>
14 
15 #include <fwIO/ioTypes.hpp>
16 
17 #include <fwJobs/IJob.hpp>
18 
19 #include <fwMedData/Series.hpp>
20 
21 #include <fwMedDataTools/helper/SeriesDB.hpp>
22 
23 #include <fwServices/macros.hpp>
24 #include <fwServices/op/Add.hpp>
25 #include <fwServices/registry/ServiceConfig.hpp>
26 
27 namespace uiIO
28 {
29 namespace action
30 {
31 
33 
34 static const ::fwCom::Signals::SignalKeyType JOB_CREATED_SIGNAL = "jobCreated";
35 static const ::fwCom::Slots::SlotKeyType FORWARD_JOB_SLOT = "forwardJob";
36 
37 static const ::fwServices::IService::KeyType s_SERIES_INOUT = "seriesDB";
38 
39 //------------------------------------------------------------------------------
40 
41 SSeriesDBMerger::SSeriesDBMerger( ) noexcept :
42  m_ioSelectorSrvConfig("IOSelectorServiceConfigVRRenderReader")
43 {
44  m_sigJobCreated = newSignal< JobCreatedSignalType >( JOB_CREATED_SIGNAL );
45  m_slotForwardJob = newSlot( FORWARD_JOB_SLOT, &SSeriesDBMerger::forwardJob, this );
46 }
47 
48 //------------------------------------------------------------------------------
49 
50 SSeriesDBMerger::~SSeriesDBMerger() noexcept
51 {
52 }
53 
54 //------------------------------------------------------------------------------
55 
56 void SSeriesDBMerger::info(std::ostream& _sstream )
57 {
58  _sstream << "Action for add SeriesDB" << std::endl;
59 }
60 
61 //------------------------------------------------------------------------------
62 
64 {
66 
68  std::vector < ConfigurationType > vectConfig = m_configuration->find("IOSelectorSrvConfig");
69  if(!vectConfig.empty())
70  {
71  ConfigurationType selectorConfig = vectConfig.at(0);
72  SLM_ASSERT("Missing 'name' attribute", selectorConfig->hasAttribute("name"));
73  m_ioSelectorSrvConfig = selectorConfig->getAttributeValue("name");
74  }
75 }
76 
77 //------------------------------------------------------------------------------
78 
80 {
82  ::fwGui::LockAction lock(this->getSptr());
83 
84  ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(s_SERIES_INOUT);
85  if (!seriesDB)
86  {
87  seriesDB = this->getObject< ::fwMedData::SeriesDB >();
88  FW_DEPRECATED_KEY(s_SERIES_INOUT, "inout", "18.0");
89  }
90  SLM_ASSERT("SeriesDB not instanced", seriesDB);
91 
92  // Create a new SeriesDB
93  ::fwMedData::SeriesDB::sptr localSeriesDB = ::fwMedData::SeriesDB::New();
94 
96 
97  // Get the config
98  ::fwRuntime::ConfigurationElement::csptr ioCfg;
99  ioCfg = ::fwServices::registry::ServiceConfig::getDefault()->getServiceConfig(m_ioSelectorSrvConfig,
100  "::uiIO::editor::SIOSelector");
101  SLM_ASSERT("There is no service configuration "
102  << m_ioSelectorSrvConfig
103  << " for ::uiIO::editor::SIOSelector", ioCfg);
104 
105  // Init and execute the service
106  ::fwServices::IService::sptr ioSelectorSrv;
107  ioSelectorSrv = ::fwServices::add("::uiIO::editor::SIOSelector");
108  ioSelectorSrv->registerInOut(localSeriesDB, ::fwIO::s_DATA_KEY);
109  ioSelectorSrv->setWorker(m_associatedWorker);
110 
111  auto jobCreatedSignal = ioSelectorSrv->signal("jobCreated");
112  if(jobCreatedSignal)
113  {
114  jobCreatedSignal->connect(m_slotForwardJob);
115  }
116 
117  ioSelectorSrv->setConfiguration( ::fwRuntime::ConfigurationElement::constCast(ioCfg) );
118  ioSelectorSrv->configure();
119  ioSelectorSrv->start();
120  ioSelectorSrv->update();
121  ioSelectorSrv->stop();
122  ::fwServices::OSR::unregisterService( ioSelectorSrv );
123 
124  ::fwMedDataTools::helper::SeriesDB sDBhelper(seriesDB);
125  sDBhelper.merge(localSeriesDB);
126  sDBhelper.notify();
127 }
128 
129 //------------------------------------------------------------------------------
130 
132 {
134 }
135 
136 //------------------------------------------------------------------------------
137 
139 {
141 }
142 
143 //------------------------------------------------------------------------------
144 
145 void SSeriesDBMerger::forwardJob(::fwJobs::IJob::sptr iJob)
146 {
147  m_sigJobCreated->emit(iJob);
148 }
149 
150 //------------------------------------------------------------------------------
151 //
152 } // namespace action
153 } // namespace uiIO
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Definition: spyLog.hpp:366
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
void updating() override
Show the SeriesDB reader selector, load the new SeriesDB and merge it the the current SeriesDB...
Defines an helper to modify an fwMedData::SeriesDB and create in parallel the message to announce thi...
std::shared_ptr< ::fwJobs::IJob > sptr
Cancel request callback type.
Definition: IJob.hpp:54
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
void info(std::ostream &_sstream) override
Write information in a stream.
#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
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
This action allows to load a new SeriesDB and merge it with the current SeriesDB. ...
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
FWMEDDATATOOLS_API void notify()
Send the signal of modification.
std::shared_ptr< ::fwThread::Worker > m_associatedWorker
Associated worker.
Definition: IService.hpp:699
static FWSERVICES_API ServiceConfig::sptr getDefault()
Return the default global instance of ServiceConfig.
void configuring() override
Configure action. Retrieves the IOSelector config.
The namespace uiIO contains a simple service to manipulate IO with IHM..
FWMEDDATATOOLS_API void merge(::fwMedData::SeriesDB::sptr seriesDBIn)
Merge seriesDBIn all series from seriesDBIn to the SeriesDB.