fw4spl
SExportWithSeriesDB.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/SExportWithSeriesDB.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 #include <fwMedData/SeriesDB.hpp>
21 
22 #include <fwServices/macros.hpp>
23 #include <fwServices/op/Add.hpp>
24 #include <fwServices/registry/ServiceConfig.hpp>
25 
26 namespace uiIO
27 {
28 namespace action
29 {
30 
31 fwServicesRegisterMacro( ::fwGui::IActionSrv, ::uiIO::action::SExportWithSeriesDB, ::fwData::Object );
32 
33 static const ::fwCom::Signals::SignalKeyType JOB_CREATED_SIGNAL = "jobCreated";
34 static const ::fwCom::Slots::SlotKeyType FORWARD_JOB_SLOT = "forwardJob";
35 
36 static const ::fwServices::IService::KeyType s_SERIES_INOUT = "series";
37 
38 //------------------------------------------------------------------------------
39 
40 SExportWithSeriesDB::SExportWithSeriesDB( ) noexcept :
41  m_ioSelectorSrvConfig("IOSelectorServiceConfigVRRenderReader")
42 {
43  m_sigJobCreated = newSignal< JobCreatedSignalType >( JOB_CREATED_SIGNAL );
44  m_slotForwardJob = newSlot( FORWARD_JOB_SLOT, &SExportWithSeriesDB::forwardJob, this );
45 }
46 
47 //------------------------------------------------------------------------------
48 
49 SExportWithSeriesDB::~SExportWithSeriesDB() noexcept
50 {
51 }
52 
53 //------------------------------------------------------------------------------
54 
55 void SExportWithSeriesDB::info(std::ostream& _sstream )
56 {
57  _sstream << "Action for add SeriesDB" << std::endl;
58 }
59 
60 //------------------------------------------------------------------------------
61 
63 {
65  std::vector < ConfigurationType > vectConfig = m_configuration->find("IOSelectorSrvConfig");
66  if(!vectConfig.empty())
67  {
68  ConfigurationType selectorConfig = vectConfig.at(0);
69  SLM_ASSERT("Missing 'name' attribute", selectorConfig->hasAttribute("name"));
70  m_ioSelectorSrvConfig = selectorConfig->getAttributeValue("name");
71  }
72 }
73 
74 //------------------------------------------------------------------------------
75 
77 {
78  ::fwGui::LockAction lock(this->getSptr());
79 
80  ::fwMedData::Series::sptr series = this->getInOut< ::fwMedData::Series >(s_SERIES_INOUT);
81 
82  if (!series)
83  {
84  FW_DEPRECATED_KEY(s_SERIES_INOUT, "inout", "18.0");
85  series = this->getObject< ::fwMedData::Series >();
86  }
87  // Create a new SeriesDB
88  ::fwMedData::SeriesDB::sptr localSeriesDB = ::fwMedData::SeriesDB::New();
89  localSeriesDB->getContainer().push_back(series);
90 
92 
93  // Get the config
94  ::fwRuntime::ConfigurationElement::csptr ioCfg;
95  ioCfg = ::fwServices::registry::ServiceConfig::getDefault()->getServiceConfig(m_ioSelectorSrvConfig,
96  "::uiIO::editor::SIOSelector");
97  SLM_ASSERT("There is no service configuration "
98  << m_ioSelectorSrvConfig
99  << " for ::uiIO::editor::SIOSelector", ioCfg);
100 
101  // Init and execute the service
102  ::fwServices::IService::sptr ioSelectorSrv;
103  ioSelectorSrv = ::fwServices::add( "::uiIO::editor::SIOSelector");
104  ioSelectorSrv->registerInOut(localSeriesDB, ::fwIO::s_DATA_KEY);
105 
106  ioSelectorSrv->setWorker(m_associatedWorker);
107 
108  auto jobCreatedSignal = ioSelectorSrv->signal("jobCreated");
109  if(jobCreatedSignal)
110  {
111  jobCreatedSignal->connect(m_slotForwardJob);
112  }
113 
114  ioSelectorSrv->setConfiguration( ::fwRuntime::ConfigurationElement::constCast(ioCfg) );
115  ioSelectorSrv->configure();
116  ioSelectorSrv->start();
117  ioSelectorSrv->update();
118  ioSelectorSrv->stop();
119  ::fwServices::OSR::unregisterService( ioSelectorSrv );
120 }
121 
122 //------------------------------------------------------------------------------
123 
125 {
127 
128  ::fwMedData::Series::sptr series = this->getInOut< ::fwMedData::Series >(s_SERIES_INOUT);
129 
130  if (!series)
131  {
132  FW_DEPRECATED_KEY(s_SERIES_INOUT, "inout", "18.0");
133  series = this->getObject< ::fwMedData::Series >();
134  }
135  SLM_FATAL_IF( "The associated object must be a ::fwMedData::Series.", !series);
136 }
137 
138 //------------------------------------------------------------------------------
139 
141 {
143 }
144 
145 //------------------------------------------------------------------------------
146 
147 void SExportWithSeriesDB::forwardJob(::fwJobs::IJob::sptr iJob)
148 {
149  m_sigJobCreated->emit(iJob);
150 }
151 
152 //------------------------------------------------------------------------------
153 //
154 } // namespace action
155 } // 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
void configuring() override
Configure action. Retrieves the IOSelector config.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
This action allows to export the current series using a temporary seriesDB.
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 starting() override
Start action.
void stopping() override
Stop action.
void info(std::ostream &_sstream) override
Write information in a stream.
void updating() override
Show the SeriesDB reader selector, load the new SeriesDB and merge it the the current SeriesDB...
#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
Base class for each data object.
::fwRuntime::ConfigurationElement::sptr m_configuration
Configuration element used to configure service internal state using a generic XML like structure TOD...
Definition: IService.hpp:670
#define SLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:287
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.
The namespace uiIO contains a simple service to manipulate IO with IHM..