fw4spl
SInteractorStyle.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 "visuVTKAdaptor/SInteractorStyle.hpp"
8 
9 #include <fwRenderVTK/IInteractorStyle.hpp>
10 
11 #include <fwServices/macros.hpp>
12 
13 #include <vtkInstantiator.h>
14 #include <vtkInteractorStyleImage.h>
15 #include <vtkRenderWindowInteractor.h>
16 
17 fwServicesRegisterMacro( ::fwRenderVTK::IAdaptor, ::visuVTKAdaptor::SInteractorStyle);
18 
19 namespace visuVTKAdaptor
20 {
21 
22 //------------------------------------------------------------------------------
23 
24 SInteractorStyle::SInteractorStyle() noexcept :
25  m_interactorStyle(nullptr)
26 {
27 }
28 
29 //------------------------------------------------------------------------------
30 
31 SInteractorStyle::~SInteractorStyle() noexcept
32 {
33  SLM_ASSERT("SInteractorStyle should be NULL", !m_interactorStyle);
34 }
35 
36 //------------------------------------------------------------------------------
37 
39 {
40  this->configureParams();
41 
42  const ConfigType config = this->getConfigTree().get_child("config.<xmlattr>");
43 
44  SLM_ASSERT("Missing attribute 'style'", config.count("style"));
45  m_configuredStyle = config.get<std::string>("style");
46 }
47 
48 //------------------------------------------------------------------------------
49 
51 {
52  this->initialize();
53 
54  vtkObject* objectStyle = vtkInstantiator::CreateInstance(m_configuredStyle.c_str());
55  vtkInteractorStyle* interactor = vtkInteractorStyle::SafeDownCast(objectStyle);
56  SLM_ASSERT("InsteractorStyle adaptor is waiting for a vtkInteractorStyle object, but '"
57  + m_configuredStyle + "' has been given.", interactor);
58  this->setInteractorStyle(interactor);
59 }
60 
61 //------------------------------------------------------------------------------
62 
64 {
65 }
66 
67 //------------------------------------------------------------------------------
68 
70 {
71  this->setInteractorStyle(nullptr);
72 }
73 
74 //------------------------------------------------------------------------------
75 
76 void SInteractorStyle::setInteractorStyle(vtkInteractorStyle* interactor)
77 {
78  if ( m_interactorStyle != nullptr )
79  {
80  m_interactorStyle->Delete();
81  m_interactorStyle = nullptr;
82  }
83 
84  ::fwRenderVTK::IInteractorStyle* fwInteractor = dynamic_cast< ::fwRenderVTK::IInteractorStyle* >(interactor);
85  if(fwInteractor)
86  {
87  fwInteractor->setAutoRender(this->getAutoRender());
88  }
89 
90  m_interactorStyle = interactor;
91 
92  this->getInteractor()->SetInteractorStyle(nullptr);
93  this->getInteractor()->SetInteractorStyle(m_interactorStyle);
94  this->setVtkPipelineModified();
95 }
96 
97 //------------------------------------------------------------------------------
98 
99 } //namespace visuVTKAdaptor
FWRENDERVTK_API vtkRenderWindowInteractor * getInteractor()
Returns the render interactor.
IInteractorStyle is an interface dedicated to hold some flags for class inherited from vtkInteractorS...
VISUVTKADAPTOR_API void starting() override
Initialize the service activity.
The namespace visuVTKAdaptor contains the list of adaptors available for the generic scene...
VISUVTKADAPTOR_API void stopping() override
Uninitialize the service activity. The stop() method is always invoked before destroying a service...
VISUVTKADAPTOR_API void configuring() override
Configure the service before starting. Apply the configuration to service.
FWRENDERVTK_API void configureParams()
Parse the xml configuration for renderer, picker and transform.
FWRENDERVTK_API bool getAutoRender() const
Returns true if the service automatically triggers the rendering.
FWRENDERVTK_API void setVtkPipelineModified()
End-user have to call this method when a vtk structure has been modified, thus a render request will ...
void setAutoRender(bool _autoRender)
Set the autorender flag.
#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
FWRENDERVTK_API void initialize()
Initialize the adaptor with the associated render service. (must be call in starting).
VISUVTKADAPTOR_API void updating() override
Perform some computations according to object (this service is attached to) attribute values and its ...
Managing vtk interactor style.
FWSERVICES_API ConfigType getConfigTree() const
Return the configuration, in an boost property tree.
Definition: IService.cpp:247