NorMIT-nav  16.5
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxRepImpl.h
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 #ifndef CXREPIMPL_H_
35 #define CXREPIMPL_H_
36 
37 #include "cxResourceVisualizationExport.h"
38 
39 #include <set>
40 #include "cxRep.h"
41 #include "cxIndent.h"
42 #include <vtkSmartPointer.h>
43 class vtkObject;
44 typedef vtkSmartPointer<class vtkRenderer> vtkRendererPtr;
45 typedef vtkSmartPointer<class vtkCallbackCommand> vtkCallbackCommandPtr;
46 
47 namespace cx
48 {
49 typedef boost::weak_ptr<class View> ViewWeakPtr;
50 
63 class cxResourceVisualization_EXPORT RepImpl : public Rep
64 {
65  Q_OBJECT
66 public:
67  explicit RepImpl(const QString& uid="", const QString& name="");
68  virtual ~RepImpl();
69  virtual QString getType() const = 0;
70  virtual void connectToView(ViewPtr theView);
71  virtual void disconnectFromView(ViewPtr theView);
72  virtual bool isConnectedToView(ViewPtr theView) const;
73  void setName(QString name);
74  QString getName() const;
75  QString getUid() const;
76  virtual void printSelf(std::ostream & os, Indent indent);
77 
82  template<class REP>
83  static boost::shared_ptr<REP> wrap_new(REP* object, QString uid)
84  {
85  boost::shared_ptr<REP> retval(object);
86  if (uid.isEmpty())
87  uid = retval->getType() + "_" + reinterpret_cast<long>(retval.get());
88  retval->mUid = uid;
89  retval->mName = uid;
90  retval->mSelf = retval;
91  return retval;
92  }
93 
94 protected slots:
95  void setModified(); // set flag to get onModifiedStartRender() called before next render
96 
97 protected:
98  ViewPtr getView() const;
99  vtkRendererPtr getRenderer();
100  RepPtr getSelf() { return mSelf.lock(); }
101 
102 
103  virtual void onModifiedStartRender() {}
104  virtual void addRepActorsToViewRenderer(ViewPtr view) = 0;
105  virtual void removeRepActorsFromViewRenderer(ViewPtr view) = 0;
106 
107 private:
108 // RepImpl(); ///< not implemented
109  static void ProcessEvents(vtkObject* object,
110  unsigned long event,
111  void* clientdata,
112  void* calldata);
113  bool mModified;
114  vtkCallbackCommandPtr mCallbackCommand;
115  void onStartRenderPrivate();
116  ViewWeakPtr mView;
117  QString mName;
118  QString mUid;
119  RepWeakPtr mSelf;
120 
121 };
122 
123 
124 
125 } // namespace cx
126 
127 #endif /*CXREPIMPL_H_*/
RepPtr getSelf()
Definition: cxRepImpl.h:100
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:83
boost::shared_ptr< class View > ViewPtr
vtkSmartPointer< class vtkCallbackCommand > vtkCallbackCommandPtr
boost::weak_ptr< class Rep > RepWeakPtr
Definition: cxData.h:58
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Definition: cxRepImpl.h:43
vtkSmartPointer< class vtkCallbackCommand > vtkCallbackCommandPtr
Definition: cxRepImpl.h:45
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:49
boost::weak_ptr< class View > ViewWeakPtr
Definition: cxRepImpl.h:49
Default implementation of Rep.
Definition: cxRepImpl.h:63
virtual void onModifiedStartRender()
Definition: cxRepImpl.h:103
boost::shared_ptr< class Rep > RepPtr
Definition: cxRepManager.h:45
Abstract interface for entities that can be added to a View.
Definition: cxRep.h:64