Fraxinus  2023.01.05-dev+develop.0da12
An IGT application
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) 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 #ifndef CXREPIMPL_H_
14 #define CXREPIMPL_H_
15 
16 #include "cxResourceVisualizationExport.h"
17 
18 #include <set>
19 #include "cxRep.h"
20 #include "cxIndent.h"
21 #include <vtkSmartPointer.h>
22 class vtkObject;
23 typedef vtkSmartPointer<class vtkRenderer> vtkRendererPtr;
24 typedef vtkSmartPointer<class vtkCallbackCommand> vtkCallbackCommandPtr;
25 
26 namespace cx
27 {
28 typedef boost::weak_ptr<class View> ViewWeakPtr;
29 
42 class cxResourceVisualization_EXPORT RepImpl : public Rep
43 {
44  Q_OBJECT
45 public:
46  explicit RepImpl(const QString& uid="", const QString& name="");
47  virtual ~RepImpl();
48  virtual QString getType() const = 0;
49  virtual void connectToView(ViewPtr theView);
50  virtual void disconnectFromView(ViewPtr theView);
51  virtual bool isConnectedToView(ViewPtr theView) const;
52  void setName(QString name);
53  QString getName() const;
54  QString getUid() const;
55  virtual void printSelf(std::ostream & os, Indent indent);
56 
61  template<class REP>
62  static boost::shared_ptr<REP> wrap_new(REP* object, QString uid)
63  {
64  boost::shared_ptr<REP> retval(object);
65  if (uid.isEmpty())
66  uid = retval->getType() + "_" + reinterpret_cast<long long>(retval.get());
67  retval->mUid = uid;
68  retval->mName = uid;
69  retval->mSelf = retval;
70  return retval;
71  }
72 
73 protected slots:
74  void setModified(); // set flag to get onModifiedStartRender() called before next render
75 
76 protected:
77  ViewPtr getView() const;
78  vtkRendererPtr getRenderer();
79  RepPtr getSelf() { return mSelf.lock(); }
80 
81 
82  virtual void onModifiedStartRender() {}
83  virtual void addRepActorsToViewRenderer(ViewPtr view) = 0;
84  virtual void removeRepActorsFromViewRenderer(ViewPtr view) = 0;
85  virtual void onEveryRender() {}
86 
87 private:
88 // RepImpl(); ///< not implemented
89  static void ProcessEvents(vtkObject* object,
90  unsigned long event,
91  void* clientdata,
92  void* calldata);
93  bool mModified;
94  vtkCallbackCommandPtr mCallbackCommand;
95  void onStartRenderPrivate();
96  ViewWeakPtr mView;
97  QString mName;
98  QString mUid;
99  RepWeakPtr mSelf;
100 
101 };
102 
103 
104 
105 } // namespace cx
106 
107 #endif /*CXREPIMPL_H_*/
RepPtr getSelf()
Definition: cxRepImpl.h:79
virtual void onEveryRender()
Definition: cxRepImpl.h:85
static boost::shared_ptr< REP > wrap_new(REP *object, QString uid)
Definition: cxRepImpl.h:62
boost::shared_ptr< class View > ViewPtr
vtkSmartPointer< class vtkCallbackCommand > vtkCallbackCommandPtr
boost::weak_ptr< class Rep > RepWeakPtr
Definition: cxData.h:38
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
Definition: cxRepImpl.h:22
vtkSmartPointer< class vtkCallbackCommand > vtkCallbackCommandPtr
Definition: cxRepImpl.h:24
Formatting class for debug printing of the ssc library.
Definition: cxIndent.h:28
boost::weak_ptr< class View > ViewWeakPtr
Definition: cxRepImpl.h:28
Default implementation of Rep.
Definition: cxRepImpl.h:42
virtual void onModifiedStartRender()
Definition: cxRepImpl.h:82
boost::shared_ptr< class Rep > RepPtr
Definition: cxRepManager.h:24
Abstract interface for entities that can be added to a View.
Definition: cxRep.h:43
Namespace for all CustusX production code.