fw4spl
SAddField.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2017-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 "ctrlSelection/SAddField.hpp"
8 
9 #include <fwDataTools/helper/Field.hpp>
10 
11 #include <fwServices/macros.hpp>
12 
13 #include <boost/foreach.hpp>
14 
15 fwServicesRegisterMacro(::fwServices::IController, ::ctrlSelection::SAddField);
16 
17 namespace ctrlSelection
18 {
19 
20 // ----------------------------------------------------------------------------
21 
23 {
24 }
25 
26 // ----------------------------------------------------------------------------
27 
29 {
30 }
31 
32 // ----------------------------------------------------------------------------
33 
35 {
36  auto srvConfig = this->getConfigTree();
37 
38  BOOST_FOREACH(const ::fwServices::IService::ConfigType::value_type& v, srvConfig.equal_range("inout"))
39  {
40  const ::fwServices::IService::ConfigType& inout = v.second;
41  const ::fwServices::IService::ConfigType& attrInOut = inout.get_child("<xmlattr>");
42  if(attrInOut.get("group", "" ) == "source")
43  {
44  BOOST_FOREACH(const ::fwServices::IService::ConfigType::value_type& v, inout.equal_range("key"))
45  {
46  const ::fwServices::IService::ConfigType& specAssoc = v.second;
47  const ::fwServices::IService::ConfigType& attr = specAssoc.get_child("<xmlattr>");
48  const std::string field = attr.get("field", "");
49  m_fields.push_back(field);
50  }
51  }
52  }
53 }
54 
55 // ----------------------------------------------------------------------------
56 
58 {
59  FW_DEPRECATED("::ctrlSelection::SAddField", "::crrlSelection::SManage", "18.0");
60 }
61 
62 // ----------------------------------------------------------------------------
63 
65 {
66 }
67 
68 // ----------------------------------------------------------------------------
69 
71 {
72  ::fwData::Object::sptr target = this->getInOut< ::fwData::Object>("target");
73  SLM_ASSERT("Missing 'target' object", target);
74 
75  ::fwDataTools::helper::Field helper(target);
76  size_t i = 0;
77  for(const auto& elt : m_fields)
78  {
79  ::fwData::Object::sptr fieldObject = this->getInOut< ::fwData::Object>("source", i++);
80  SLM_ASSERT("'source' object for field '" + elt + "'not found.", fieldObject);
81  helper.setField(elt, fieldObject);
82  }
83  helper.notify();
84 }
85 
86 // ----------------------------------------------------------------------------
87 
88 } // namespace ctrlSelection
virtual ~SAddField() noexcept
Destructor.
Definition: SAddField.cpp:28
CTRLSELECTION_API void updating() override
Add the source object as fields of the target object.
Definition: SAddField.cpp:70
Defines a helper to modify field on a fwData::Object and create a message notifying this modification...
Definition: Field.hpp:22
FWDATATOOLS_API void notify()
Send the built message and clear the internal maps.
Definition: Field.cpp:148
Add one or several fields to an object.
Definition: SAddField.hpp:40
CTRLSELECTION_API void starting() override
Do nothing.
Definition: SAddField.cpp:57
This interface defines control service API. Does nothing particularly, can be considered as a default...
Definition: IController.hpp:23
#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
FWDATATOOLS_API void setField(const ::fwData::Object::FieldNameType &name,::fwData::Object::sptr obj)
Register field with specified name. If the name does already exist, the matching field will be replac...
Definition: Field.cpp:41
CTRLSELECTION_API void configuring() override
Configure the service.
Definition: SAddField.cpp:34
CTRLSELECTION_API SAddField() noexcept
Constructor.
Definition: SAddField.cpp:22
CTRLSELECTION_API void stopping() override
Do nothing.
Definition: SAddField.cpp:64
The namespace ctrlSelection contains several interfaces for manager, updater and wrapper.
Definition: BookmarkSrv.hpp:15
#define FW_DEPRECATED(oldFnName, newFnName, version)
Use this macro when deprecating a function to warn the developer.
Definition: spyLog.hpp:344
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247