VTK  9.1.0
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
32#include "vtkContextScene.h"
33
34// STL headers
35#include <vector> // Needed for STL vector.
36
37class vtkContext2D;
38
39//-----------------------------------------------------------------------------
40class vtkContextScenePrivate : public std::vector<vtkAbstractContextItem*>
41{
42public:
48 , Scene(nullptr)
49 , Item(item)
50 {
51 }
52
57
59
62 typedef std::vector<vtkAbstractContextItem*>::const_iterator const_iterator;
63 typedef std::vector<vtkAbstractContextItem*>::iterator iterator;
64 typedef std::vector<vtkAbstractContextItem*>::const_reverse_iterator const_reverse_iterator;
65 typedef std::vector<vtkAbstractContextItem*>::reverse_iterator reverse_iterator;
67
71 void PaintItems(vtkContext2D* context)
72 {
73 for (const_iterator it = this->begin(); it != this->end(); ++it)
74 {
75 if ((*it)->GetVisible())
76 {
77 (*it)->Paint(context);
78 }
79 }
80 }
81
83
86 unsigned int AddItem(vtkAbstractContextItem* item)
87 {
88 item->Register(this->Scene);
89 item->SetScene(this->Scene);
90 item->SetParent(this->Item);
92
93 this->push_back(item);
94 return static_cast<unsigned int>(this->size() - 1);
95 }
96
98
102 {
103 for (iterator it = this->begin(); it != this->end(); ++it)
104 {
105 if (item == *it)
106 {
107 item->SetParent(nullptr);
108 item->SetScene(nullptr);
109 (*it)->Delete();
110 this->erase(it);
111 return true;
112 }
113 }
114 return false;
115 }
117
119
122 bool RemoveItem(unsigned int index)
123 {
124 if (index < this->size())
125 {
126 return this->RemoveItem(this->at(index));
127 }
128 return false;
129 }
131
133
136 void Clear()
137 {
138 for (const_iterator it = this->begin(); it != this->end(); ++it)
139 {
140 (*it)->SetParent(nullptr);
141 (*it)->SetScene(nullptr);
142 (*it)->Delete();
143 }
144 this->clear();
145 }
147
149
153 {
154 if (this->Scene == scene)
155 {
156 return;
157 }
158 this->Scene = scene;
159 for (const_iterator it = this->begin(); it != this->end(); ++it)
160 {
161 (*it)->SetScene(scene);
162 }
163 }
165
170
172
178};
179
180#endif // vtkContextScenePrivate_h
181// VTK-HeaderTest-Exclude: vtkContextScenePrivate.h
base class for items that are part of a vtkContextScene.
virtual void SetParent(vtkAbstractContextItem *parent)
Set the parent item.
virtual void SetScene(vtkContextScene *scene)
Set the vtkContextScene for the item, always set for an item in a scene.
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:73
Private implementation for scene/items.
unsigned int AddItem(vtkAbstractContextItem *item)
Add an item to the list - ensure it is not already in the list.
bool RemoveItem(unsigned int index)
Remove an item from the list.
vtkAbstractContextItem * Item
Store a reference to the item that these children are part of.
bool RemoveItem(vtkAbstractContextItem *item)
Remove an item from the list.
std::vector< vtkAbstractContextItem * >::const_iterator const_iterator
A few standard defines.
void SetScene(vtkContextScene *scene)
Set the scene for the instance (and its items).
void PaintItems(vtkContext2D *context)
Paint all items in the list.
void Clear()
Clear all items from the list - unregister.
vtkContextScene * Scene
Store a reference to the scene.
std::vector< vtkAbstractContextItem * >::iterator iterator
A few standard defines.
std::vector< vtkAbstractContextItem * >::reverse_iterator reverse_iterator
A few standard defines.
std::vector< vtkAbstractContextItem * >::const_reverse_iterator const_reverse_iterator
A few standard defines.
vtkContextScenePrivate(vtkAbstractContextItem *item)
Default constructor.
Provides a 2D scene for vtkContextItem objects.
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
@ vector
Definition: vtkX3D.h:243
@ size
Definition: vtkX3D.h:259
@ index
Definition: vtkX3D.h:252