VTK
vtkContextScenePrivate.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkContextScenePrivate.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
15 
27 #ifndef vtkContextScenePrivate_h
28 #define vtkContextScenePrivate_h
29 
30 #include "vtkAbstractContextItem.h"
31 #include "vtkContextScene.h"
32 
33 // STL headers
34 #include <vector> // Needed for STL vector.
35 
36 class vtkContext2D;
37 
38 //-----------------------------------------------------------------------------
39 class vtkContextScenePrivate : public std::vector<vtkAbstractContextItem*>
40 {
41 public:
43 
45  : std::vector<vtkAbstractContextItem*>(), Scene(0), Item(item)
46  {
47  }
49 
51 
53  {
54  this->Clear();
55  }
57 
59 
60  typedef std::vector<vtkAbstractContextItem*>::const_iterator
62  typedef std::vector<vtkAbstractContextItem*>::iterator iterator;
63  // Older versions of GCC did not implement comparison operators for the
64  // const_reverse_operator, the simplest thing to do is not use the const
65  // form of the operator.
66 #ifdef VTK_CONST_REVERSE_ITERATOR_COMPARISON
67  typedef std::vector<vtkAbstractContextItem*>::const_reverse_iterator
69 #else
70  typedef std::vector<vtkAbstractContextItem*>::reverse_iterator
72 #endif
73  typedef std::vector<vtkAbstractContextItem*>::reverse_iterator
76 
78 
79  void PaintItems(vtkContext2D* context)
80  {
81  for(const_iterator it = this->begin(); it != this->end(); ++it)
82  {
83  if ((*it)->GetVisible())
84  {
85  (*it)->Paint(context);
86  }
87  }
88  }
90 
92 
93  unsigned int AddItem(vtkAbstractContextItem* item)
94  {
95  item->Register(this->Scene);
96  item->SetScene(this->Scene);
97  item->SetParent(this->Item);
99 
100  this->push_back(item);
101  return static_cast<unsigned int>(this->size()-1);
102  }
103 
105 
107  {
108  for(iterator it = this->begin(); it != this->end(); ++it)
109  {
110  if (item == *it)
111  {
112  item->SetParent(NULL);
113  item->SetScene(NULL);
114  (*it)->Delete();
115  this->erase(it);
116  return true;
117  }
118  }
119  return false;
120  }
122 
124 
125  bool RemoveItem(unsigned int index)
126  {
127  if (index < this->size())
128  {
129  return this->RemoveItem(this->at(index));
130  }
131  return false;
132  }
134 
136 
137  void Clear()
138  {
139  for(const_iterator it = this->begin(); it != this->end(); ++it)
140  {
141  (*it)->SetParent(NULL);
142  (*it)->SetScene(NULL);
143  (*it)->Delete();
144  }
145  this->clear();
146  }
148 
150 
152  {
153  if (this->Scene == scene)
154  {
155  return;
156  }
157  this->Scene = scene;
158  for(const_iterator it = this->begin(); it != this->end(); ++it)
159  {
160  (*it)->SetScene(scene);
161  }
162  }
164 
167 
169 
172 };
174 
175 #endif //vtkContextScenePrivate_h
176 // VTK-HeaderTest-Exclude: vtkContextScenePrivate.h
virtual void SetParent(vtkAbstractContextItem *parent)
virtual void Register(vtkObjectBase *o)
Private implementation for scene/items.
std::vector< vtkAbstractContextItem * >::reverse_iterator const_reverse_iterator
bool RemoveItem(vtkAbstractContextItem *item)
std::vector< vtkAbstractContextItem * >::const_iterator const_iterator
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:56
virtual void SetScene(vtkContextScene *scene)
Provides a 2D scene for vtkContextItem objects.
void PaintItems(vtkContext2D *context)
bool RemoveItem(unsigned int index)
std::vector< vtkAbstractContextItem * >::iterator iterator
void SetScene(vtkContextScene *scene)
base class for items that are part of a vtkContextScene.
unsigned int AddItem(vtkAbstractContextItem *item)
vtkContextScenePrivate(vtkAbstractContextItem *item)
vtkAbstractContextItem * Item
std::vector< vtkAbstractContextItem * >::reverse_iterator reverse_iterator