NorMIT-nav  22.09
An IGT application
cxRepImpl.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 
13 #include "cxRepImpl.h"
14 #include "cxTypeConversions.h"
15 #include "cxView.h"
16 #include "vtkCallbackCommand.h"
17 #include "vtkRenderer.h"
18 
19 namespace cx
20 {
21 
22 RepImpl::RepImpl(const QString& uid, const QString& name) :
23  mName(name), mUid(uid)
24 {
25  mModified = true;
26  this->mCallbackCommand = vtkCallbackCommandPtr::New();
27  this->mCallbackCommand->SetClientData(this);
28  this->mCallbackCommand->SetCallback(RepImpl::ProcessEvents);
29 }
30 
32 {
33 }
34 
35 void RepImpl::setName(QString name)
36 {
37  mName = name;
38 }
39 
40 QString RepImpl::getName() const
41 {
42  return mName;
43 }
44 
45 QString RepImpl::getUid() const
46 {
47  return mUid;
48 }
49 
51 {
52  return this->getView()==theView;
53 }
54 
56 {
57  mView = theView;
58 
59  vtkRendererPtr renderer = this->getView()->getRenderer();
60  renderer->AddObserver(vtkCommand::StartEvent, this->mCallbackCommand, 1.0);
61 
62  this->addRepActorsToViewRenderer(theView);
63 }
64 
66 {
67  vtkRendererPtr renderer = this->getRenderer();
68  if (renderer)
69  {
70  renderer->RemoveObserver(this->mCallbackCommand);
71  this->removeRepActorsFromViewRenderer(theView);
72  }
73  mView.reset();
74 }
75 
76 void RepImpl::printSelf(std::ostream & os, Indent indent)
77 {
78  os << indent << "mUid: " << mUid << std::endl;
79  os << indent << "mName: " << mName << std::endl;
80  os << indent << "Type: " << getType() << std::endl;
81 }
82 
84 {
85  return mView.lock();
86 }
87 
89 {
90  if (!this->getView())
91  return vtkRendererPtr();
92  return this->getView()->getRenderer();
93 }
94 
95 
96 void RepImpl::ProcessEvents(vtkObject* vtkNotUsed(object), unsigned long event, void* clientdata,
97  void* vtkNotUsed(calldata))
98 {
99  RepImpl* self = reinterpret_cast<RepImpl*>(clientdata);
100  self->onStartRenderPrivate();
101  self->onEveryRender();
102 }
103 
104 void RepImpl::onStartRenderPrivate()
105 {
106  if (!mModified)
107  return;
108  this->onModifiedStartRender();
109  mModified = false;
110 }
111 
113 {
114  mModified = true;
115  if (this->getView())
116  this->getView()->setModified();
117 }
118 
119 
120 } // namespace cx
cx::RepImpl::setName
void setName(QString name)
Definition: cxRepImpl.cpp:35
cxRepImpl.h
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::RepImpl::getUid
QString getUid() const
Definition: cxRepImpl.cpp:45
cx::RepImpl::getRenderer
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
cx::RepImpl::addRepActorsToViewRenderer
virtual void addRepActorsToViewRenderer(ViewPtr view)=0
cx::RepImpl::getView
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
cx::RepImpl::~RepImpl
virtual ~RepImpl()
Definition: cxRepImpl.cpp:31
cx::RepImpl::disconnectFromView
virtual void disconnectFromView(ViewPtr theView)
Definition: cxRepImpl.cpp:65
cxTypeConversions.h
cxView.h
cx::RepImpl::isConnectedToView
virtual bool isConnectedToView(ViewPtr theView) const
Definition: cxRepImpl.cpp:50
cx::ViewPtr
boost::shared_ptr< class View > ViewPtr
Definition: cxForwardDeclarations.h:110
cx::RepImpl::removeRepActorsFromViewRenderer
virtual void removeRepActorsFromViewRenderer(ViewPtr view)=0
cx::RepImpl
Default implementation of Rep.
Definition: cxRepImpl.h:42
cx::RepImpl::setModified
void setModified()
Definition: cxRepImpl.cpp:112
cx::RepImpl::onModifiedStartRender
virtual void onModifiedStartRender()
Definition: cxRepImpl.h:82
cx::RepImpl::RepImpl
RepImpl(const QString &uid="", const QString &name="")
Definition: cxRepImpl.cpp:22
cx::RepImpl::getType
virtual QString getType() const =0
cx::RepImpl::getName
QString getName() const
Definition: cxRepImpl.cpp:40
cx::Indent
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:28
cx::RepImpl::printSelf
virtual void printSelf(std::ostream &os, Indent indent)
Definition: cxRepImpl.cpp:76
vtkRendererPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Definition: vtkForwardDeclarations.h:122
cx::RepImpl::connectToView
virtual void connectToView(ViewPtr theView)
Definition: cxRepImpl.cpp:55