fw4spl
SAddLabeledPoint.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/SAddLabeledPoint.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 #include <fwCom/Signals.hpp>
12 
13 #include <fwCore/base.hpp>
14 
15 #include <fwData/Boolean.hpp>
16 #include <fwData/Point.hpp>
17 #include <fwData/PointList.hpp>
18 #include <fwData/String.hpp>
19 
20 #include <fwDataTools/fieldHelper/Image.hpp>
21 
22 #include <fwGui/dialog/InputDialog.hpp>
23 #include <fwGui/dialog/MessageDialog.hpp>
24 
25 #include <fwServices/macros.hpp>
26 
27 #include <exception>
28 
29 namespace uiMeasurement
30 {
31 namespace action
32 {
33 
35 
36 static const ::fwServices::IService::KeyType s_POINTLIST_INOUT = "pointlist";
37 
38 //------------------------------------------------------------------------------
39 
40 SAddLabeledPoint::SAddLabeledPoint( ) noexcept :
41  m_count(1)
42 {
43 }
44 
45 //------------------------------------------------------------------------------
46 
47 SAddLabeledPoint::~SAddLabeledPoint() noexcept
48 {
49 }
50 
51 //------------------------------------------------------------------------------
52 
53 void SAddLabeledPoint::info(std::ostream& _sstream )
54 {
55  _sstream << "Action for remove distance" << std::endl;
56 }
57 
58 //------------------------------------------------------------------------------
59 
60 // return true if label setting is NOT Canceled , name is modified !!!
61 bool SAddLabeledPoint::defineLabel(std::string& name)
62 {
63  bool res = false;
64  name = "Label" + ::boost::lexical_cast< std::string >(m_count);
65 
66  ::fwData::String::sptr url = ::fwData::String::New();
68  inputDlg.setTitle("Label");
69  inputDlg.setMessage("Which label for the point?");
70  inputDlg.setInput(name);
71  std::string inputText = inputDlg.getInput();
72 
73  if(!inputText.empty())
74  {
75  name = inputText;
76  m_count++;
77  res = true;
78  }
79  return res;
80 }
81 
82 //------------------------------------------------------------------------------
83 
85 {
86  ::fwData::PointList::sptr landmarks = this->getInOut< ::fwData::PointList >(s_POINTLIST_INOUT);
87  if (!landmarks)
88  {
89  FW_DEPRECATED_KEY(s_POINTLIST_INOUT, "inout", "18.0");
90  landmarks = this->getObject< ::fwData::PointList >();
91  }
92  SLM_ASSERT("landmarks not instanced", landmarks);
93 
94  std::string value;
95  if ( this->defineLabel(value) )
96  {
97  // create a new point
98  ::fwData::Point::sptr newPoint = ::fwData::Point::New();
99 
100  // append to landmark
101  landmarks->getPoints().push_back( newPoint );
102 
103  // append to point the label
104  ::fwData::String::sptr label = ::fwData::String::New();
105  label->value() = value;
106  newPoint->setField( ::fwDataTools::fieldHelper::Image::m_labelId, label );
107 
108  // notify
109  auto sig =
111  {
112  ::fwCom::Connection::Blocker block(sig->getConnection(m_slotUpdate));
113  sig->asyncEmit(newPoint);
114  }
115  }
116 }
117 
118 //------------------------------------------------------------------------------
119 
121 {
123 }
124 
125 //------------------------------------------------------------------------------
126 
128 {
130 }
131 
132 //------------------------------------------------------------------------------
133 
135 {
137 }
138 
139 //------------------------------------------------------------------------------
140 
141 } // namespace action
142 
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
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
virtual FWGUI_API void setMessage(const std::string &msg) override
Set the message.
UIMEASUREMENT_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
This action adds labeled point into a PointList.
FWGUI_API void actionServiceStopping()
Method called when the action service is stopping.
Definition: IActionSrv.cpp:153
virtual FWGUI_API void setTitle(const std::string &title) override
Set the title of the input dialog.
virtual FWGUI_API std::string getInput() override
Get the input text in the input field.
Defines the service interface managing the menu items.
Definition: IActionSrv.hpp:24
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_POINT_ADDED_SIG
Signal emitted when a Point is added.
UpdateSlotType::sptr m_slotUpdate
Slot to call update method.
Definition: IService.hpp:690
UIMEASUREMENT_API void configuring() override
Configure the service before starting. Apply the configuration to service.
#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
FWGUI_API void initialize()
Initialize the action.
Definition: IActionSrv.cpp:69
Defines the generic input dialog for IHM. Use the Delegate design pattern.
static FWDATATOOLS_API const std::string m_labelId
to assign a label
UIMEASUREMENT_API void info(std::ostream &_sstream) override
Write information in a stream.
This class defines a list of points.
UIMEASUREMENT_API void starting() override
Initialize the service activity.
UIMEASUREMENT_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
virtual FWGUI_API void setInput(const std::string &text) override
Set the input text in the input field.