fw4spl
Distance.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 "uiMeasurementQt/editor/Distance.hpp"
8 
9 #include <fwCom/Signal.hpp>
10 #include <fwCom/Signal.hxx>
11 
12 #include <fwCore/base.hpp>
13 
14 #include <fwData/Boolean.hpp>
15 #include <fwData/Composite.hpp>
16 #include <fwData/Image.hpp>
17 #include <fwData/String.hpp>
18 
19 #include <fwGuiQt/container/QtContainer.hpp>
20 
21 #include <fwRuntime/ConfigurationElement.hpp>
22 #include <fwRuntime/operations.hpp>
23 
24 #include <fwServices/IService.hpp>
25 #include <fwServices/macros.hpp>
26 
27 #include <boost/filesystem.hpp>
28 #include <boost/filesystem/convenience.hpp>
29 
30 #include <QIcon>
31 #include <QVBoxLayout>
32 
33 namespace uiMeasurementQt
34 {
35 namespace editor
36 {
37 
38 //------------------------------------------------------------------------------
39 
41 
42 const ::fwCom::Signals::SignalKeyType Distance::s_DISTANCE_REQUESTED_SIG = "distanceRequested";
43 
44 //------------------------------------------------------------------------------
45 
47 {
48  m_sigDistanceRequested = newSignal< DistanceRequestedSignalType >(s_DISTANCE_REQUESTED_SIG);
49 }
50 
51 //------------------------------------------------------------------------------
52 
54 {
55 }
56 
57 //------------------------------------------------------------------------------
58 
60 {
62 
63  ::fwGuiQt::container::QtContainer::sptr qtContainer = ::fwGuiQt::container::QtContainer::dynamicCast(
64  this->getContainer() );
65 
66  namespace fs = ::boost::filesystem;
67  fs::path pathImageDist = ::fwRuntime::getBundleResourceFilePath("uiMeasurementQt", "distance.png");
68  OSLM_ASSERT("Image "<< pathImageDist << "is missing", fs::exists(pathImageDist));
69 
70  QIcon imageDist(QString::fromStdString(pathImageDist.string()));
71 
72  m_distButton = new QPushButton( imageDist, tr(""));
73  m_distButton->setToolTip(tr("Distance"));
74 
75  QVBoxLayout* layout = new QVBoxLayout();
76  layout->addWidget( m_distButton, 1 );
77  layout->setContentsMargins(0, 0, 0, 0);
78  QObject::connect(m_distButton, SIGNAL(clicked()), this, SLOT(onDistanceButton()));
79 
80  qtContainer->setLayout( layout );
81 }
82 
83 //------------------------------------------------------------------------------
84 
86 {
87  QObject::disconnect(m_distButton, SIGNAL(clicked()), this, SLOT(onDistanceButton()));
88 
89  this->destroy();
90 }
91 
92 //------------------------------------------------------------------------------
93 
95 {
97 }
98 
99 //------------------------------------------------------------------------------
100 
102 {
103 }
104 
105 //------------------------------------------------------------------------------
106 
108 {
109  ::fwData::Image::sptr image = this->getInOut< ::fwData::Image >("image");
110  SLM_ASSERT("'image' key is not found.", image);
111 
112  // force distance to be shown
113  image->setField("ShowDistances", ::fwData::Boolean::New(true));
114 
115  m_sigDistanceRequested->asyncEmit();
116 }
117 
118 //------------------------------------------------------------------------------
119 } // namespace editor
120 } // namespace uiMeasurementQt
void onDistanceButton()
Notify the scene that a distance is added.
Definition: Distance.cpp:107
#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
Defines the service interface managing the editor service for object.
Definition: IEditor.hpp:25
FWGUI_API void destroy()
Stops sub-views and toobar services. Destroys view, sub-views and toolbar containers.
UIMEASUREMENTQT_API Distance() noexcept
Constructor. Do nothing.
Definition: Distance.cpp:46
virtual void starting() override
Install the layout.
Definition: Distance.cpp:59
virtual void configuring() override
Initialize the widget.
Definition: Distance.cpp:94
#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 create()
Creates view, sub-views and toolbar containers. Manages sub-views and toobar services.
virtual void updating() override
Do nothing.
Definition: Distance.cpp:101
virtual void stopping() override
Destroy the layout.
Definition: Distance.cpp:85
This class defines an image.
virtual UIMEASUREMENTQT_API ~Distance() noexcept override
Destructor. Do nothing.
Definition: Distance.cpp:53
Distance service is represented by a button. It allows to show distances in a generic scene...
Definition: Distance.hpp:44
FWGUI_API void initialize()
Initialize managers.