fw4spl
ShowDistance.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/ShowDistance.hpp"
8 
9 #include <fwCom/Slot.hpp>
10 #include <fwCom/Slot.hxx>
11 #include <fwCom/Slots.hpp>
12 #include <fwCom/Slots.hxx>
13 
14 #include <fwCore/base.hpp>
15 
16 #include <fwData/Boolean.hpp>
17 #include <fwData/Point.hpp>
18 #include <fwData/PointList.hpp>
19 
20 #include <fwDataTools/fieldHelper/Image.hpp>
21 #include <fwDataTools/fieldHelper/MedicalImageHelpers.hpp>
22 
23 #include <fwServices/macros.hpp>
24 
25 #include <exception>
26 
27 namespace uiMeasurement
28 {
29 namespace action
30 {
31 
33 
34 static const ::fwCom::Slots::SlotKeyType s_SHOW_DISTANCE_SLOT = "showDistance";
35 
36 static const ::fwServices::IService::KeyType s_IMAGE_INOUT = "image";
37 
38 //------------------------------------------------------------------------------
39 
40 ShowDistance::ShowDistance( ) noexcept
41 {
42  newSlot(s_SHOW_DISTANCE_SLOT, &ShowDistance::showDistance, this);
43 }
44 
45 //------------------------------------------------------------------------------
46 
47 ShowDistance::~ShowDistance() noexcept
48 {
49 }
50 
51 //------------------------------------------------------------------------------
52 
53 void ShowDistance::info(std::ostream& _sstream )
54 {
55  _sstream << "Action for show distance" << std::endl;
56 }
57 
58 //------------------------------------------------------------------------------
59 
61 {
62  ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
63  if (!image)
64  {
65  FW_DEPRECATED_KEY(s_IMAGE_INOUT, "inout", "18.0");
66  image = this->getObject< ::fwData::Image >();
67  }
69  {
71  }
72  else
73  {
74  ::fwData::Boolean::sptr showDistances =
75  image->getField< ::fwData::Boolean >("ShowDistances", ::fwData::Boolean::New(true));
76  bool isShown = showDistances->value();
77 
78  bool toShow = !isShown;
79  image->setField("ShowDistances", ::fwData::Boolean::New(toShow));
80 
81  // auto manage hide/show : use Field Information instead let gui manage checking
82  this->::fwGui::IActionSrv::setIsActive(!toShow);
83 
84  auto sig = image->signal< ::fwData::Image::DistanceDisplayedSignalType >(
86  {
87  ::fwCom::Connection::Blocker block(sig->getConnection(this->slot(s_SHOW_DISTANCE_SLOT)));
88  sig->asyncEmit(toShow);
89  }
90  }
91 }
92 
93 //------------------------------------------------------------------------------
94 
95 void ShowDistance::showDistance(bool)
96 {
97  ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >(s_IMAGE_INOUT);
98  if (!image)
99  {
100  FW_DEPRECATED_KEY(s_IMAGE_INOUT, "inout", "18.0");
101  image = this->getObject< ::fwData::Image >();
102  }
103  ::fwData::Boolean::sptr showDistances =
104  image->getField< ::fwData::Boolean >("ShowDistances", ::fwData::Boolean::New(true));
105 
106  this->::fwGui::IActionSrv::setIsActive( !(showDistances->value()) );
107 }
108 
109 //------------------------------------------------------------------------------
110 
112 {
114 }
115 
116 //------------------------------------------------------------------------------
117 
119 {
121 }
122 
123 //------------------------------------------------------------------------------
124 
126 {
128 }
129 
130 //------------------------------------------------------------------------------
131 
133 {
134  KeyConnectionsMap connections;
135  connections.push( s_IMAGE_INOUT, ::fwData::Image::s_DISTANCE_DISPLAYED_SIG, s_SHOW_DISTANCE_SLOT );
136 
137  return connections;
138 }
139 
140 //------------------------------------------------------------------------------
141 
142 } // namespace action
143 } // namespace uiMeasurement
#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
FWGUI_API void actionServiceStarting()
Method called when the action service is starting.
Definition: IActionSrv.cpp:160
Class allowing to block a Connection.
Definition: Connection.hpp:20
The namespace uiMeasurement contains actions to add/show/remove distances and landmarks.
Definition: AddDistance.hpp:13
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
T & value() noexcept
Get the value (mutable version).
virtual FWGUI_API void setIsActive(bool isActive)
Set the action service is active/inactive.
Definition: IActionSrv.cpp:168
void info(std::ostream &_sstream) override
Write information in a stream.
void starting() override
Initialize the service activity.
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
virtual UIMEASUREMENT_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated object signals, this method is used for obj/...
void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
static FWDATATOOLS_API bool checkImageValidity(::fwData::Image::csptr _pImg)
Check if the image is valid.
This class defines an image.
void configuring() override
Configure the service before starting. Apply the configuration to service.
This action allows to show/hide image distances.
This class contains a boolean value.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_DISTANCE_DISPLAYED_SIG
Type of signal when image&#39;s buffer is added.