fw4spl
ShowLandmark.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 "uiMeasurement/action/ShowLandmark.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Slot.hpp>
12 #include <fwCom/Slot.hxx>
13 #include <fwCom/Slots.hpp>
14 #include <fwCom/Slots.hxx>
15 
16 #include <fwCore/base.hpp>
17 
18 #include <fwData/Boolean.hpp>
19 
20 #include <fwDataTools/fieldHelper/Image.hpp>
21 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp>
22 
23 #include <fwServices/macros.hpp>
24 #include <fwServices/registry/ObjectService.hpp>
25 
26 #include <exception>
27 
28 namespace uiMeasurement
29 {
30 namespace action
31 {
32 
34 
35 static const ::fwCom::Slots::SlotKeyType s_SHOW_LANDMARK_SLOT = "showLandmark";
36 
37 //------------------------------------------------------------------------------
38 
39 ShowLandmark::ShowLandmark( ) noexcept
40 {
41  newSlot(s_SHOW_LANDMARK_SLOT, &ShowLandmark::showLandmark, this);
42 }
43 
44 //------------------------------------------------------------------------------
45 
46 ShowLandmark::~ShowLandmark() noexcept
47 {
48 }
49 
50 //------------------------------------------------------------------------------
51 
52 void ShowLandmark::info(std::ostream& _sstream )
53 {
54  _sstream << "Action for show distance" << std::endl;
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
62 
63  ::fwData::Image::sptr image = this->getObject< ::fwData::Image >();
66  {
68  return;
69  }
70 
71  ::fwData::Boolean::sptr showLandmarks = image->getField< ::fwData::Boolean >("ShowLandmarks", ::fwData::Boolean::New(
72  true));
73  bool isShown = showLandmarks->value();
74 
75  bool toShow = !isShown;
76  image->setField("ShowLandmarks", ::fwData::Boolean::New(toShow));
77 
78  auto services = ::fwServices::OSR::getServices < ::fwServices::IService > (image);
79 
80  this->::fwGui::IActionSrv::setIsActive(isShown);
81 
82  // notify
84  {
85  ::fwCom::Connection::Blocker block(sig->getConnection(this->slot(s_SHOW_LANDMARK_SLOT)));
86  sig->asyncEmit(isShown);
87  }
88 }
89 
90 //------------------------------------------------------------------------------
91 
93 {
95  ::fwData::Image::csptr img = this->getObject< ::fwData::Image >();
96  ::fwData::Boolean::sptr showLandmarks =
97  img->getField< ::fwData::Boolean >("ShowLandmarks", ::fwData::Boolean::New(true));
98 
99  // set check correctly
100  this->::fwGui::IActionSrv::setIsActive( !(showLandmarks->value()) );
101 }
102 
103 //------------------------------------------------------------------------------
104 
105 void ShowLandmark::showLandmark(bool)
106 {
107  this->swapping();
108 }
109 
110 //------------------------------------------------------------------------------
111 
113 {
115 }
116 
117 //------------------------------------------------------------------------------
118 
120 {
121  FW_DEPRECATED_MSG("This service is deprecated", "18.0.");
123 }
124 
125 //------------------------------------------------------------------------------
126 
128 {
130 }
131 
132 //------------------------------------------------------------------------------
133 
135 {
136  KeyConnectionsMap connections;
137  connections.push( "image", ::fwData::Image::s_LANDMARK_DISPLAYED_SIG, s_SHOW_LANDMARK_SLOT );
138 
139  return connections;
140 }
141 
142 //------------------------------------------------------------------------------
143 
144 } // namespace action
145 } // namespace uiMeasurement
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
void starting() override
Initialize the service activity.
Class allowing to block a Connection.
Definition: Connection.hpp:20
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Definition: spyLog.hpp:329
The namespace uiMeasurement contains actions to add/show/remove distances and landmarks.
Definition: AddDistance.hpp:13
UIMEASUREMENT_API void info(std::ostream &_sstream) override
Write information in a stream.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
#define FW_DEPRECATED_MSG(message, version)
Use this macro when deprecating a function to warn the developer.
Definition: spyLog.hpp:360
This action allows to show/hide image landmarks.
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_LANDMARK_DISPLAYED_SIG
Type of signal when image&#39;s buffer is added.
T & value() noexcept
Get the value (mutable version).
void configuring() override
Configure the service before starting. Apply the configuration to service.
virtual FWGUI_API void setIsActive(bool isActive)
Set the action service is active/inactive.
Definition: IActionSrv.cpp:168
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
static FWDATATOOLS_API bool checkImageValidity(::fwData::Image::csptr _pImg)
Check if the image is valid.
This class defines an image.
virtual UIMEASUREMENT_API::fwServices::IService::KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
This class contains a boolean value.
UIMEASUREMENT_API void swapping() override
Swap the service from associated object to another object.