7 #include "ctrlSelection/SManage.hpp" 9 #include <fwCom/Slot.hpp> 10 #include <fwCom/Slot.hxx> 11 #include <fwCom/Slots.hpp> 12 #include <fwCom/Slots.hxx> 14 #include <fwData/Composite.hpp> 15 #include <fwData/Exception.hpp> 16 #include <fwData/Vector.hpp> 18 #include <fwDataTools/helper/Composite.hpp> 19 #include <fwDataTools/helper/Field.hpp> 20 #include <fwDataTools/helper/Vector.hpp> 22 #include <fwMedData/Series.hpp> 23 #include <fwMedData/SeriesDB.hpp> 25 #include <fwMedDataTools/helper/SeriesDB.hpp> 27 #include <fwServices/macros.hpp> 40 const ::fwServices::IService::KeyType s_COMPOSITE_INOUT =
"composite";
41 const ::fwServices::IService::KeyType s_VECTOR_INOUT =
"vector";
42 const ::fwServices::IService::KeyType s_SERIESDB_INOUT =
"seriesDB";
43 const ::fwServices::IService::KeyType s_FIELD_HOLDER_INOUT =
"fieldHolder";
44 const ::fwServices::IService::KeyType s_OBJECT_INOUT =
"object";
69 ::fwServices::IService::ConfigType config = this->
getConfigTree();
71 m_compositeKey = config.get(
"compositeKey",
"");
72 m_fieldName = config.get(
"field",
"");
113 ::fwData::Object::sptr obj = this->getInOut< ::fwData::Object >(s_OBJECT_INOUT);
114 SLM_ASSERT(
"Object '" + s_OBJECT_INOUT +
"' is missing.", obj);
116 ::fwData::Composite::sptr composite = this->getInOut< ::fwData::Composite >(s_COMPOSITE_INOUT);
117 ::fwData::Vector::sptr vector = this->getInOut< ::fwData::Vector >(s_VECTOR_INOUT);
118 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(s_SERIESDB_INOUT);
119 ::fwData::Object::sptr fieldHolder = this->getInOut< ::fwData::Object >(s_FIELD_HOLDER_INOUT);
121 SLM_ASSERT(
"Target object is missing, required one of 'composite', 'vector', 'seriesDB', or 'fieldHolder'",
122 vector || composite || seriesDB || fieldHolder);
125 SLM_ASSERT(
"Only one target object is managed", !vector && !seriesDB && !fieldHolder);
127 if (composite->find(m_compositeKey) == composite->end())
129 helper.
add(m_compositeKey, obj);
133 helper.
swap(m_compositeKey, obj);
140 SLM_ASSERT(
"Only one target object is managed", !composite && !seriesDB && !fieldHolder);
141 auto iter = std::find(vector->begin(), vector->end(), obj);
142 if (iter == vector->end())
148 SLM_WARN_IF(
"Object already exists in the Vector, does nothing.", iter != vector->end());
152 ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast(obj);
153 SLM_ASSERT(
"Target object is a SeriesDB, so object must be a Series.", series);
154 SLM_ASSERT(
"Only one target object is managed", !composite && !vector && !fieldHolder);
156 auto iter = std::find(seriesDB->begin(), seriesDB->end(), series);
157 if (iter == seriesDB->end())
163 SLM_WARN_IF(
"Object already exists in the SeriesDB, does nothing.", iter != seriesDB->end());
165 else if (fieldHolder)
167 SLM_ASSERT(
"Only one target object is managed", !vector && !composite && !seriesDB);
180 ::fwData::Object::sptr obj = this->getInOut< ::fwData::Object >(s_OBJECT_INOUT);
181 SLM_ASSERT(
"Object '" + s_OBJECT_INOUT +
"' is missing.", obj);
183 ::fwData::Composite::sptr composite = this->getInOut< ::fwData::Composite >(s_COMPOSITE_INOUT);
184 ::fwData::Object::sptr fieldHolder = this->getInOut< ::fwData::Object >(s_FIELD_HOLDER_INOUT);
186 SLM_ASSERT(
"'swap' slot is only managed for 'composite' or 'fieldHolder'",
187 composite || fieldHolder);
190 SLM_ASSERT(
"Only one target object is managed", !fieldHolder);
192 helper.
swap(m_compositeKey, obj);
195 else if (fieldHolder)
197 SLM_ASSERT(
"Only one target object is managed", !composite);
199 helper.
swap(m_fieldName, obj);
210 ::fwData::Object::sptr obj = this->getInOut< ::fwData::Object >(s_OBJECT_INOUT);
212 ::fwData::Composite::sptr composite = this->getInOut< ::fwData::Composite >(s_COMPOSITE_INOUT);
213 ::fwData::Vector::sptr vector = this->getInOut< ::fwData::Vector >(s_VECTOR_INOUT);
214 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(s_SERIESDB_INOUT);
215 ::fwData::Object::sptr fieldHolder = this->getInOut< ::fwData::Object >(s_FIELD_HOLDER_INOUT);
217 SLM_ASSERT(
"Target object is missing, required one of 'composite', 'vector', 'seriesDB', or 'fieldHolder'",
218 vector || composite || seriesDB || fieldHolder);
221 SLM_ASSERT(
"Only one target object is managed", !vector && !seriesDB && !fieldHolder);
223 helper.
remove(m_compositeKey);
228 SLM_ASSERT(
"Only one target object is managed", !composite && !seriesDB && !fieldHolder);
229 SLM_ASSERT(
"Object '" + s_OBJECT_INOUT +
"' is missing.", obj);
236 SLM_ASSERT(
"Object '" + s_OBJECT_INOUT +
"' is missing.", obj);
237 ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast(obj);
238 SLM_ASSERT(
"Target object is a SeriesDB, so object must be a Series.", series);
239 SLM_ASSERT(
"Only one target object is managed", !composite && !vector && !fieldHolder);
245 else if (fieldHolder)
247 SLM_ASSERT(
"Only one target object is managed", !vector && !composite && !seriesDB);
249 helper.
remove(m_fieldName);
260 ::fwData::Object::sptr obj = this->getInOut< ::fwData::Object >(s_OBJECT_INOUT);
262 ::fwData::Composite::sptr composite = this->getInOut< ::fwData::Composite >(s_COMPOSITE_INOUT);
263 ::fwData::Vector::sptr vector = this->getInOut< ::fwData::Vector >(s_VECTOR_INOUT);
264 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(s_SERIESDB_INOUT);
265 ::fwData::Object::sptr fieldHolder = this->getInOut< ::fwData::Object >(s_FIELD_HOLDER_INOUT);
267 SLM_ASSERT(
"Target object is missing, required one of 'composite', 'vector', 'seriesDB', or 'fieldHolder'",
268 vector || composite || seriesDB || fieldHolder);
271 SLM_ASSERT(
"Only one target object is managed", !vector && !seriesDB && !fieldHolder);
273 if (composite->find(m_compositeKey) != composite->end())
275 helper.
remove(m_compositeKey);
281 SLM_ASSERT(
"Only one target object is managed", !composite && !seriesDB && !fieldHolder);
282 SLM_ASSERT(
"Object '" + s_OBJECT_INOUT +
"' is missing.", obj);
283 auto iter = std::find(vector->begin(), vector->end(), obj);
284 if (iter != vector->end())
290 SLM_WARN_IF(
"Object does not exist in the Vector, does nothing.", iter == vector->end());
294 SLM_ASSERT(
"Object '" + s_OBJECT_INOUT +
"' is missing.", obj);
295 ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast(obj);
296 SLM_ASSERT(
"Target object is a SeriesDB, so object must be a Series.", series);
297 SLM_ASSERT(
"Only one target object is managed", !composite && !vector && !fieldHolder);
299 auto iter = std::find(seriesDB->begin(), seriesDB->end(), series);
300 if (iter != seriesDB->end())
306 SLM_WARN_IF(
"Object does not exist in the SeriesDB, does nothing.", iter == seriesDB->end());
308 else if (fieldHolder)
310 SLM_ASSERT(
"Only one target object is managed", !vector && !composite && !seriesDB);
314 helper.
remove(m_fieldName);
330 ::fwData::Composite::sptr composite = this->getInOut< ::fwData::Composite >(s_COMPOSITE_INOUT);
331 ::fwData::Vector::sptr vector = this->getInOut< ::fwData::Vector >(s_VECTOR_INOUT);
332 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(s_SERIESDB_INOUT);
333 ::fwData::Object::sptr fieldHolder = this->getInOut< ::fwData::Object >(s_FIELD_HOLDER_INOUT);
335 SLM_ASSERT(
"Target object is missing, required one of 'composite', 'vector', 'seriesDB', or 'fieldHolder'",
336 vector || composite || seriesDB || fieldHolder);
339 SLM_ASSERT(
"Only one target object is managed", !vector && !seriesDB && !fieldHolder);
346 SLM_ASSERT(
"Only one target object is managed", !composite && !seriesDB && !fieldHolder);
357 else if (fieldHolder)
359 SLM_ASSERT(
"Only one target object is managed", !vector && !composite && !seriesDB);
368 void SManage::internalAdd(
bool _copy)
372 ::fwData::Object::sptr obj = this->getInOut< ::fwData::Object >(s_OBJECT_INOUT);
373 SLM_ASSERT(
"Object '" + s_OBJECT_INOUT +
"' is missing.", obj);
380 ::fwData::Composite::sptr composite = this->getInOut< ::fwData::Composite >(s_COMPOSITE_INOUT);
381 ::fwData::Vector::sptr vector = this->getInOut< ::fwData::Vector >(s_VECTOR_INOUT);
382 ::fwMedData::SeriesDB::sptr seriesDB = this->getInOut< ::fwMedData::SeriesDB >(s_SERIESDB_INOUT);
383 ::fwData::Object::sptr fieldHolder = this->getInOut< ::fwData::Object >(s_FIELD_HOLDER_INOUT);
385 SLM_ASSERT(
"Target object is missing, required one of 'composite', 'vector', 'seriesDB', or 'fieldHolder'",
386 vector || composite || seriesDB || fieldHolder);
389 SLM_ASSERT(
"Only one target object is managed", !vector && !seriesDB && !fieldHolder);
391 helper.
add(m_compositeKey, obj);
396 SLM_ASSERT(
"Only one target object is managed", !composite && !seriesDB && !fieldHolder);
403 ::fwMedData::Series::sptr series = ::fwMedData::Series::dynamicCast(obj);
404 SLM_ASSERT(
"Target object is a SeriesDB, so object must be a Series.", series);
405 SLM_ASSERT(
"Only one target object is managed", !composite && !vector && !fieldHolder);
410 else if (fieldHolder)
412 SLM_ASSERT(
"Only one target object is managed", !vector && !composite && !seriesDB);
414 helper.
add(m_fieldName, obj);
void addCopy()
Adds a copy of object into the composite with the key given by config.
void clear()
Removes all objects.
virtual CTRLSELECTION_API void starting() override
Implements starting method derived from IService. Do nothing.
virtual CTRLSELECTION_API void configuring() override
Configures the service.
static const ::fwCom::Slots::SlotKeyType s_CLEAR_SLOT
Adds the object into the composite with the key given by config.
Implements data exception class.
static const ::fwCom::Slots::SlotKeyType s_ADD_OR_SWAP_SLOT
Adds the object into the composite with the key given by config.
static const ::fwCom::Slots::SlotKeyType s_REMOVE_SLOT
Adds the object into the composite with the key given by config.
virtual CTRLSELECTION_API void updating() override
Implements updating method derived from IService. Do nothing.
void swap()
Swaps the object into the composite with the key given by config.
CTRLSELECTION_API SManage() noexcept
Constructor. Do nothing.
static const ::fwCom::Slots::SlotKeyType s_ADD_SLOT
Adds the object into the composite with the key given by config.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
static FWDATA_API::fwData::Object::sptr copy(const ::fwData::Object::csptr &source)
return a copy of the source. if source is a null pointer, return a null pointer.
static const ::fwCom::Slots::SlotKeyType s_REMOVE_IF_PRESENT_SLOT
Adds the object into the composite with the key given by config.
static const ::fwCom::Slots::SlotKeyType s_SWAP_OBJ_SLOT
Adds the object into the composite with the key given by config.
virtual CTRLSELECTION_API ~SManage() noexcept
Destructor. Do nothing.
void remove()
Removes the object from the composite at the key given by config.
void addOrSwap()
Adds or swap the object into the composite with the key given by config.
static const ::fwCom::Slots::SlotKeyType s_ADD_COPY_SLOT
Adds the object into the composite with the key given by config.
void removeIfPresent()
Removes the object from the composite at the key given by config if it is present.
The namespace ctrlSelection contains several interfaces for manager, updater and wrapper.
void add()
Adds the object into the composite with the key given by config.
virtual CTRLSELECTION_API void stopping() override
Implements stopping method derived from IService. Do nothing.
#define SLM_WARN_IF(message, cond)
FWSERVICES_API bool isStarted() const noexcept
Test if the service is started or not.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.