CustusX  22.04-rc5
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
ViewPtr getView() const
Definition: cxRepImpl.cpp:83
virtual ~RepImpl()
Definition: cxRepImpl.cpp:31
void setName(QString name)
Definition: cxRepImpl.cpp:35
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:88
RepImpl(const QString &uid="", const QString &name="")
Definition: cxRepImpl.cpp:22
virtual QString getType() const =0
virtual void removeRepActorsFromViewRenderer(ViewPtr view)=0
QString getUid() const
Definition: cxRepImpl.cpp:45
virtual void connectToView(ViewPtr theView)
Definition: cxRepImpl.cpp:55
boost::shared_ptr< class View > ViewPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
virtual void disconnectFromView(ViewPtr theView)
Definition: cxRepImpl.cpp:65
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:28
virtual void printSelf(std::ostream &os, Indent indent)
Definition: cxRepImpl.cpp:76
Default implementation of Rep.
Definition: cxRepImpl.h:42
virtual void onModifiedStartRender()
Definition: cxRepImpl.h:82
virtual void addRepActorsToViewRenderer(ViewPtr view)=0
QString getName() const
Definition: cxRepImpl.cpp:40
virtual bool isConnectedToView(ViewPtr theView) const
Definition: cxRepImpl.cpp:50
void setModified()
Definition: cxRepImpl.cpp:112
Namespace for all CustusX production code.