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(nullptr), 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  typedef std::vector<vtkAbstractContextItem*>::const_reverse_iterator
68  typedef std::vector<vtkAbstractContextItem*>::reverse_iterator
71 
75  void PaintItems(vtkContext2D* context)
76  {
77  for(const_iterator it = this->begin(); it != this->end(); ++it)
78  {
79  if ((*it)->GetVisible())
80  {
81  (*it)->Paint(context);
82  }
83  }
84  }
85 
87 
90  unsigned int AddItem(vtkAbstractContextItem* item)
91  {
92  item->Register(this->Scene);
93  item->SetScene(this->Scene);
94  item->SetParent(this->Item);
96 
97  this->push_back(item);
98  return static_cast<unsigned int>(this->size()-1);
99  }
100 
102 
106  {
107  for(iterator it = this->begin(); it != this->end(); ++it)
108  {
109  if (item == *it)
110  {
111  item->SetParent(nullptr);
112  item->SetScene(nullptr);
113  (*it)->Delete();
114  this->erase(it);
115  return true;
116  }
117  }
118  return false;
119  }
121 
123 
126  bool RemoveItem(unsigned int index)
127  {
128  if (index < this->size())
129  {
130  return this->RemoveItem(this->at(index));
131  }
132  return false;
133  }
135 
137 
140  void Clear()
141  {
142  for(const_iterator it = this->begin(); it != this->end(); ++it)
143  {
144  (*it)->SetParent(nullptr);
145  (*it)->SetScene(nullptr);
146  (*it)->Delete();
147  }
148  this->clear();
149  }
151 
153 
157  {
158  if (this->Scene == scene)
159  {
160  return;
161  }
162  this->Scene = scene;
163  for(const_iterator it = this->begin(); it != this->end(); ++it)
164  {
165  (*it)->SetScene(scene);
166  }
167  }
169 
174 
176 
181 };
183 
184 #endif //vtkContextScenePrivate_h
185 // 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.
vtkContextScene * Scene
Store a reference to the scene.
bool RemoveItem(vtkAbstractContextItem *item)
Remove an item from the list.
std::vector< vtkAbstractContextItem * >::const_reverse_iterator const_reverse_iterator
A few standard defines.
std::vector< vtkAbstractContextItem * >::const_iterator const_iterator
A few standard defines.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:58
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.