fw4spl
SSeriesSignal.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2016-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 "activities/SSeriesSignal.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Slot.hpp>
12 #include <fwCom/Slots.hpp>
13 #include <fwCom/Slots.hxx>
14 
15 #include <fwMedData/ActivitySeries.hpp>
16 
17 #include <fwRuntime/Convert.hpp>
18 #include <fwRuntime/operations.hpp>
19 
20 #include <fwServices/macros.hpp>
21 
22 #include <boost/foreach.hpp>
23 
24 namespace activities
25 {
26 
27 //------------------------------------------------------------------------------
28 
30 
31 //------------------------------------------------------------------------------
32 
33 const ::fwCom::Slots::SlotKeyType SSeriesSignal::s_REPORT_SERIES_SLOT = "reportSeries";
34 const ::fwCom::Signals::SignalKeyType SSeriesSignal::s_SERIES_ADDED_SIG = "seriesAdded";
35 
36 //------------------------------------------------------------------------------
37 
39 {
40  m_sigSeriesAdded = newSignal< SeriesAddedSignalType >(s_SERIES_ADDED_SIG);
41 
42  newSlot(s_REPORT_SERIES_SLOT, &SSeriesSignal::reportSeries, this);
43 }
44 
45 //------------------------------------------------------------------------------
46 
48 {
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
61 }
62 
63 //------------------------------------------------------------------------------
64 
66 {
67 
68  const ::fwServices::IService::ConfigType srvconfig = this->getConfigTree();
69 
70  if(srvconfig.count("filter") == 1 )
71  {
72  const ::fwServices::IService::ConfigType& configFilter = srvconfig.get_child("filter");
73  SLM_ASSERT("A maximum of 1 <mode> tag is allowed", configFilter.count("mode") < 2);
74 
75  const std::string mode = configFilter.get< std::string >("mode");
76  SLM_ASSERT("'" + mode + "' value for <mode> tag isn't valid. Allowed values are : 'include', 'exclude'.",
77  mode == "include" || mode == "exclude");
78  m_filterMode = mode;
79 
80  BOOST_FOREACH( const ConfigType::value_type& v, configFilter.equal_range("type") )
81  {
82  m_types.push_back(v.second.get<std::string>(""));
83  }
84  }
85  SLM_ASSERT("A maximum of 1 <filter> tag is allowed", srvconfig.count("filter") < 2);
86 }
87 
88 //------------------------------------------------------------------------------
89 
90 void SSeriesSignal::reportSeries(::fwMedData::SeriesDB::ContainerType addedSeries)
91 {
92  for(const ::fwMedData::Series::sptr& series : addedSeries)
93  {
94  const bool isIncludeMode = m_filterMode == "include";
95 
96  std::string classname = series->getClassname();
97  TypesType::iterator keyIt = std::find(m_types.begin(), m_types.end(), classname);
98 
99  if(keyIt != m_types.end() && isIncludeMode)
100  {
101  m_sigSeriesAdded->asyncEmit(series);
102  }
103  else if(keyIt == m_types.end() && !isIncludeMode)
104  {
105  m_sigSeriesAdded->asyncEmit(series);
106  }
107  }
108 }
109 
110 //------------------------------------------------------------------------------
111 
113 {
114 }
115 
116 //------------------------------------------------------------------------------
117 
119 {
120  KeyConnectionsType connections;
121  connections.push_back( std::make_pair( ::fwMedData::SeriesDB::s_ADDED_SERIES_SIG, s_REPORT_SERIES_SLOT ) );
122 
123  return connections;
124 }
125 
126 //------------------------------------------------------------------------------
127 
129 {
130  KeyConnectionsMap connections;
131 
132  // FIXME hack to support old getObject (with any 'in' or 'inout' key)
133  if (!this->getInput< ::fwMedData::SeriesDB >("seriesDB"))
134  {
135  FW_DEPRECATED_KEY("seriesDB", "in", "18.0");
136  }
137  else
138  {
139  connections.push("seriesDB", ::fwMedData::SeriesDB::s_ADDED_SERIES_SIG, s_REPORT_SERIES_SLOT );
140  }
141 
142  return connections;
143 }
144 
145 //------------------------------------------------------------------------------
146 
147 } // namespace activities
ACTIVITIES_API SSeriesSignal() noexcept
Constructor. Do nothing.
#define FW_DEPRECATED_KEY(newKey, access, version)
Use this macro when deprecating a service key to warn the developer.
Definition: spyLog.hpp:366
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
virtual void configuring() override
Parse XML configuration.
This service emits a signal for each added series (the signal contains the added series) ...
static const std::string & classname()
return object&#39;s classname without its namespace, i.e. BaseObject
virtual ACTIVITIES_API ~SSeriesSignal() noexcept
Destructor. Do nothing.
static FWMEDDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_SERIES_SIG
Type of signal when series are added.
ACTIVITIES_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
This interface defines control service API. Does nothing particularly, can be considered as a default...
Definition: IController.hpp:23
virtual ACTIVITIES_API KeyConnectionsType getObjSrvConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
virtual void stopping() override
Do nothing.
#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
The namespace activities contains helpers and services allowing to launch activities.
::fwCom::helper::SigSlotConnection::KeyConnectionsType KeyConnectionsType
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
Definition: IService.hpp:449
virtual void updating() override
Do nothing.
virtual void starting() override
Do nothing.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247