fw4spl
SViewportUpdater.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 "scene2D/adaptor/SViewportUpdater.hpp"
8 
9 #include <fwRenderQt/data/Viewport.hpp>
10 #include <fwRenderQt/Scene2DGraphicsView.hpp>
11 
12 #include <fwServices/macros.hpp>
13 
14 fwServicesRegisterMacro( ::fwRenderQt::IAdaptor, ::scene2D::adaptor::SViewportUpdater);
15 
16 namespace scene2D
17 {
18 namespace adaptor
19 {
20 
21 static const ::fwServices::IService::KeyType s_VIEWPORT_INPUT = "viewport";
22 
23 SViewportUpdater::SViewportUpdater() noexcept
24 {
25 }
26 
27 //-----------------------------------------------------------------------------
28 
29 SViewportUpdater::~SViewportUpdater() noexcept
30 {
31 }
32 
33 //-----------------------------------------------------------------------------
34 
36 {
37  this->configureParams();
38 }
39 
40 //-----------------------------------------------------------------------------
41 
43 {
44  updating();
45 }
46 
47 //-----------------------------------------------------------------------------
48 
50 {
51 }
52 
53 //-----------------------------------------------------------------------------
54 
56 {
57  ::fwRenderQt::data::Viewport::sptr sceneViewport = this->getScene2DRender()->getViewport();
58  ::fwRenderQt::data::Viewport::csptr viewportObject =
59  this->getInput< ::fwRenderQt::data::Viewport>(s_VIEWPORT_INPUT);
60 
61  Point2DType pairCoord = this->mapAdaptorToScene(
62  Point2DType(viewportObject->getX(), viewportObject->getY() ), m_xAxis, m_yAxis );
63 
64  Point2DType pairSize = this->mapAdaptorToScene(
65  Point2DType(viewportObject->getWidth(), viewportObject->getHeight() ), m_xAxis, m_yAxis );
66 
67  sceneViewport->setX( pairCoord.first );
68  sceneViewport->setY( pairCoord.second );
69  sceneViewport->setWidth( pairSize.first );
70  sceneViewport->setHeight( viewportObject->getHeight() );
71 
72  this->getScene2DRender()->getView()->updateFromViewport();
73 }
74 
75 //-----------------------------------------------------------------------------
76 
78 {
79 
80 }
81 
82 //----------------------------------------------------------------------------------------------------------
83 
85 {
86  KeyConnectionsMap connections;
87  connections.push( s_VIEWPORT_INPUT, ::fwRenderQt::data::Viewport::s_MODIFIED_SIG, s_UPDATE_SLOT );
88  return connections;
89 }
90 
91 } // namespace adaptor
92 } // namespace scene2D
93 
SCENE2D_API void processInteraction(::fwRenderQt::data::Event &_event) override
Root class for all scene2d adaptors.
::fwRenderQt::data::Axis::sptr m_xAxis
The x Axis.
This class is a helper to define the connections of a service and its data.
Definition: IService.hpp:454
SCENE2D_API void starting() override
Initialize the service activity.
Adaptor implementation that manages the camera on the view (by updating the viewport object)...
FWRENDERQT_API Point2DType mapAdaptorToScene(const Point2DType &_xy, const ::fwRenderQt::data::Axis::sptr &_xAxis, const ::fwRenderQt::data::Axis::sptr &_yAxis) const
SCENE2D_API void configuring() override
Configure the service before starting. Apply the configuration to service.
FWRENDERQT_API std::shared_ptr< ::fwRenderQt::SRender > getScene2DRender() const
Get the render that manages the IAdaptor.
SCENE2D_API KeyConnectionsMap getAutoConnections() const override
Returns proposals to connect service slots to associated objects signals, this method is used for obj...
std::pair< double, double > Point2DType
Point2D coordinate <X, Y>
This bundles contains data and services used to display a 2D Qt scene.
SCENE2D_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
::fwRenderQt::data::Axis::sptr m_yAxis
The y Axis.
FWRENDERQT_API void configureParams()
Parse the xml configuration for Axis, z value and opacity.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
SCENE2D_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
This class manage events on the scene 2D (mouse event, keyboard event , ...).
Definition: Event.hpp:26
static FWSERVICES_APIconst::fwCom::Slots::SlotKeyType s_UPDATE_SLOT
Slot to call start method.
Definition: IService.hpp:177