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 
28 #ifndef vtkContextScenePrivate_h
29 #define vtkContextScenePrivate_h
30 
31 #include "vtkAbstractContextItem.h"
32 #include "vtkContextScene.h"
33 
34 // STL headers
35 #include <vector> // Needed for STL vector.
36 
37 class vtkContext2D;
38 
39 //-----------------------------------------------------------------------------
40 class vtkContextScenePrivate : public std::vector<vtkAbstractContextItem*>
41 {
42 public:
47  : std::vector<vtkAbstractContextItem*>(), Scene(0), Item(item)
48  {
49  }
50 
55  {
56  this->Clear();
57  }
58 
60 
63  typedef std::vector<vtkAbstractContextItem*>::const_iterator
65  typedef std::vector<vtkAbstractContextItem*>::iterator iterator;
66  // Older versions of GCC did not implement comparison operators for the
67  // const_reverse_operator, the simplest thing to do is not use the const
68  // form of the operator.
69 #ifdef VTK_CONST_REVERSE_ITERATOR_COMPARISON
70  typedef std::vector<vtkAbstractContextItem*>::const_reverse_iterator
72 #else
73  typedef std::vector<vtkAbstractContextItem*>::reverse_iterator
75 #endif
76  typedef std::vector<vtkAbstractContextItem*>::reverse_iterator
79 
83  void PaintItems(vtkContext2D* context)
84  {
85  for(const_iterator it = this->begin(); it != this->end(); ++it)
86  {
87  if ((*it)->GetVisible())
88  {
89  (*it)->Paint(context);
90  }
91  }
92  }
93 
95 
98  unsigned int AddItem(vtkAbstractContextItem* item)
99  {
100  item->Register(this->Scene);
101  item->SetScene(this->Scene);
102  item->SetParent(this->Item);
104 
105  this->push_back(item);
106  return static_cast<unsigned int>(this->size()-1);
107  }
108 
110 
114  {
115  for(iterator it = this->begin(); it != this->end(); ++it)
116  {
117  if (item == *it)
118  {
119  item->SetParent(NULL);
120  item->SetScene(NULL);
121  (*it)->Delete();
122  this->erase(it);
123  return true;
124  }
125  }
126  return false;
127  }
129 
131 
134  bool RemoveItem(unsigned int index)
135  {
136  if (index < this->size())
137  {
138  return this->RemoveItem(this->at(index));
139  }
140  return false;
141  }
143 
145 
148  void Clear()
149  {
150  for(const_iterator it = this->begin(); it != this->end(); ++it)
151  {
152  (*it)->SetParent(NULL);
153  (*it)->SetScene(NULL);
154  (*it)->Delete();
155  }
156  this->clear();
157  }
159 
161 
165  {
166  if (this->Scene == scene)
167  {
168  return;
169  }
170  this->Scene = scene;
171  for(const_iterator it = this->begin(); it != this->end(); ++it)
172  {
173  (*it)->SetScene(scene);
174  }
175  }
177 
182 
184 
189 };
191 
192 #endif //vtkContextScenePrivate_h
193 // VTK-HeaderTest-Exclude: vtkContextScenePrivate.h
virtual void SetParent(vtkAbstractContextItem *parent)
Set the parent item.
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
void Clear()
Clear all items from the list - unregister.
Private implementation for scene/items.
std::vector< vtkAbstractContextItem * >::reverse_iterator const_reverse_iterator
A few standard defines.
vtkContextScene * Scene
Store a reference to the scene.
bool RemoveItem(vtkAbstractContextItem *item)
Remove an item from the list.
std::vector< vtkAbstractContextItem * >::const_iterator const_iterator
A few standard defines.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:57
virtual void SetScene(vtkContextScene *scene)
Set the vtkContextScene for the item, always set for an item in a scene.
Provides a 2D scene for vtkContextItem objects.
void PaintItems(vtkContext2D *context)
Paint all items in the list.
bool RemoveItem(unsigned int index)
Remove an item from the list.
std::vector< vtkAbstractContextItem * >::iterator iterator
A few standard defines.
void SetScene(vtkContextScene *scene)
Set the scene for the instance (and its items).
base class for items that are part of a vtkContextScene.
unsigned int AddItem(vtkAbstractContextItem *item)
Add an item to the list - ensure it is not already in the list.
vtkContextScenePrivate(vtkAbstractContextItem *item)
Default constructor.
vtkAbstractContextItem * Item
Store a reference to the item that these children are part of.
std::vector< vtkAbstractContextItem * >::reverse_iterator reverse_iterator
A few standard defines.