fw4spl
BookmarkSrv.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
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/BookmarkSrv.hpp"
8 
9 #include <fwData/String.hpp>
10 #include <fwServices/macros.hpp>
11 #include <fwTools/Bookmarks.hpp>
12 
13 namespace ctrlSelection
14 {
15 
16 //-----------------------------------------------------------------------------
17 
18 fwServicesRegisterMacro( ::fwServices::IController, ::ctrlSelection::BookmarkSrv, ::fwData::Object );
19 
20 //-----------------------------------------------------------------------------
21 
22 BookmarkSrv::BookmarkSrv() noexcept
23 {
24  //handlingEventOff();
25 }
26 
27 //-----------------------------------------------------------------------------
28 
29 BookmarkSrv::~BookmarkSrv() noexcept
30 {
31 }
32 
33 //-----------------------------------------------------------------------------
34 
36 {
37  ::fwRuntime::ConfigurationElement::sptr config = m_configuration->findConfigurationElement("bookmark");
38  SLM_ASSERT("Problem with configuration for BookmarkSrv type, one element \"bookmark\" must be present", m_configuration->findAllConfigurationElement(
39  "bookmark").size() == 1 );
40 
41  m_bookmarkName = "";
42 
43  if (config->hasAttribute("fromString"))
44  {
45  std::string uid = config->getExistingAttributeValue("fromString");
46  OSLM_ASSERT("Object '" << uid << "' does not exist", ::fwTools::fwID::exist(uid));
47  ::fwData::String::sptr str = ::fwData::String::dynamicCast(::fwTools::fwID::getObject(uid));
48  OSLM_ASSERT("Object '" << uid << "' is not a '::fwData::String'", str);
49  m_bookmarkName = str->value();
50  }
51  if (config->hasAttribute("fromString") && config->hasAttribute("name"))
52  {
53  m_bookmarkName += "_";
54  }
55  if (config->hasAttribute("name"))
56  {
57  m_bookmarkName += config->getExistingAttributeValue("name");
58  }
59 }
60 
61 //-----------------------------------------------------------------------------
62 
64 {
65  ::fwTools::Bookmarks::add( m_bookmarkName, this->getObject());
66 }
67 
68 //-----------------------------------------------------------------------------
69 
71 {
72  OSLM_WARN_IF("Bookmark \""<< m_bookmarkName << "\" already removed", ::fwTools::Bookmarks::exist( m_bookmarkName ));
73  if(::fwTools::Bookmarks::exist( m_bookmarkName ))
74  {
75  ::fwTools::Bookmarks::remove( m_bookmarkName);
76  }
77 }
78 
79 //-----------------------------------------------------------------------------
80 
82 {
83 }
84 
85 //-----------------------------------------------------------------------------
86 
88 {
89 }
90 
91 //-----------------------------------------------------------------------------
92 
94 {
95 }
96 
97 //-----------------------------------------------------------------------------
98 
99 void BookmarkSrv::info( std::ostream &_sstream )
100 {
101 }
102 
103 //-----------------------------------------------------------------------------
104 
105 } // ctrlSelection
virtual CTRLSELECTION_API void info(std::ostream &_sstream) override
Write information in a stream.
Definition: BookmarkSrv.cpp:99
#define OSLM_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:310
virtual CTRLSELECTION_API void starting() override
Adds the object in bookmark.
Definition: BookmarkSrv.cpp:63
static FWTOOLS_API bool exist(IDType _id)
Definition: fwID.cpp:33
virtual CTRLSELECTION_API void swapping() override
Do nothing.
Definition: BookmarkSrv.cpp:81
virtual CTRLSELECTION_API void updating() override
Do nothing.
Definition: BookmarkSrv.cpp:93
This service bookmark its object with the name given in configuration.
Definition: BookmarkSrv.hpp:21
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
static FWTOOLS_API bool exist(BookmarkName _bookmark)
Tests if the given id exist (i.e recorded in Bookmarks dictionary)
Definition: Bookmarks.cpp:29
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
virtual CTRLSELECTION_API void reconfiguring() override
Do nothing.
Definition: BookmarkSrv.cpp:87
static FWTOOLS_API void remove(Bookmarks::BookmarkName _bookmark)
silently remove given bookmark
Definition: Bookmarks.cpp:44
FWSERVICES_API::fwData::Object::sptr getObject()
Return the object associated to service.
Definition: IService.cpp:101
virtual CTRLSELECTION_API void stopping() override
Removes the object from bookmark.
Definition: BookmarkSrv.cpp:70
The namespace ctrlSelection contains several interfaces for manager, updater and wrapper.
Definition: BookmarkSrv.hpp:15
#define OSLM_WARN_IF(message, cond)
Definition: spyLog.hpp:267
virtual CTRLSELECTION_API void configuring() override
Definition: BookmarkSrv.cpp:35
static FWTOOLS_API std::shared_ptr< ::fwTools::Object > getObject(IDType requestID)
Retrieve the object attached to the given id. Return a null sptr if no correspondence exist...
Definition: fwID.cpp:117