Fraxinus  16.5.0-fx-rc1
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
33 
34 #include "cxRepImpl.h"
35 #include "cxTypeConversions.h"
36 #include "cxView.h"
37 #include "vtkCallbackCommand.h"
38 #include "vtkRenderer.h"
39 
40 namespace cx
41 {
42 
43 RepImpl::RepImpl(const QString& uid, const QString& name) :
44  mName(name), mUid(uid)
45 {
46  mModified = true;
47  this->mCallbackCommand = vtkCallbackCommandPtr::New();
48  this->mCallbackCommand->SetClientData(this);
49  this->mCallbackCommand->SetCallback(RepImpl::ProcessEvents);
50 }
51 
53 {
54 }
55 
56 void RepImpl::setName(QString name)
57 {
58  mName = name;
59 }
60 
61 QString RepImpl::getName() const
62 {
63  return mName;
64 }
65 
66 QString RepImpl::getUid() const
67 {
68  return mUid;
69 }
70 
72 {
73  return this->getView()==theView;
74 }
75 
77 {
78  mView = theView;
79 
80  vtkRendererPtr renderer = this->getView()->getRenderer();
81  renderer->AddObserver(vtkCommand::StartEvent, this->mCallbackCommand, 1.0);
82 
83  this->addRepActorsToViewRenderer(theView);
84 }
85 
87 {
88  vtkRendererPtr renderer = this->getRenderer();
89  if (renderer)
90  {
91  renderer->RemoveObserver(this->mCallbackCommand);
92  this->removeRepActorsFromViewRenderer(theView);
93  }
94  mView.reset();
95 }
96 
97 void RepImpl::printSelf(std::ostream & os, Indent indent)
98 {
99  os << indent << "mUid: " << mUid << std::endl;
100  os << indent << "mName: " << mName << std::endl;
101  os << indent << "Type: " << getType() << std::endl;
102 }
103 
105 {
106  return mView.lock();
107 }
108 
110 {
111  if (!this->getView())
112  return vtkRendererPtr();
113  return this->getView()->getRenderer();
114 }
115 
116 
117 void RepImpl::ProcessEvents(vtkObject* vtkNotUsed(object), unsigned long event, void* clientdata,
118  void* vtkNotUsed(calldata))
119 {
120  RepImpl* self = reinterpret_cast<RepImpl*>(clientdata);
121  self->onStartRenderPrivate();
122 }
123 
124 void RepImpl::onStartRenderPrivate()
125 {
126  if (!mModified)
127  return;
128  this->onModifiedStartRender();
129  mModified = false;
130 }
131 
133 {
134  mModified = true;
135  if (this->getView())
136  this->getView()->setModified();
137 }
138 
139 
140 } // namespace cx
ViewPtr getView() const
Definition: cxRepImpl.cpp:104
virtual ~RepImpl()
Definition: cxRepImpl.cpp:52
void setName(QString name)
Definition: cxRepImpl.cpp:56
vtkRendererPtr getRenderer()
Definition: cxRepImpl.cpp:109
RepImpl(const QString &uid="", const QString &name="")
Definition: cxRepImpl.cpp:43
virtual QString getType() const =0
virtual void removeRepActorsFromViewRenderer(ViewPtr view)=0
QString getUid() const
Definition: cxRepImpl.cpp:66
virtual void connectToView(ViewPtr theView)
Definition: cxRepImpl.cpp:76
boost::shared_ptr< class View > ViewPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
virtual void disconnectFromView(ViewPtr theView)
Definition: cxRepImpl.cpp:86
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:49
virtual void printSelf(std::ostream &os, Indent indent)
Definition: cxRepImpl.cpp:97
Default implementation of Rep.
Definition: cxRepImpl.h:63
virtual void onModifiedStartRender()
Definition: cxRepImpl.h:103
virtual void addRepActorsToViewRenderer(ViewPtr view)=0
QString getName() const
Definition: cxRepImpl.cpp:61
virtual bool isConnectedToView(ViewPtr theView) const
Definition: cxRepImpl.cpp:71
void setModified()
Definition: cxRepImpl.cpp:132