VTK  9.4.20241202
vtkContextScenePrivate.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
3
16#ifndef vtkContextScenePrivate_h
17#define vtkContextScenePrivate_h
18
20#include "vtkContextScene.h"
21
22// STL headers
23#include <vector> // Needed for STL vector.
24
25VTK_ABI_NAMESPACE_BEGIN
26class vtkContext2D;
27
28//-----------------------------------------------------------------------------
29class vtkContextScenePrivate : public std::vector<vtkAbstractContextItem*>
30{
31public:
36 : Scene(nullptr)
37 , Item(item)
38 {
39 }
40
45
46 void PrintSelf(ostream& os, vtkIndent indent)
47 {
48 os << indent << "Number of children: " << this->size() << '\n';
49 os << indent << "Scene: " << this->Scene << '\n';
50 for (const_iterator it = this->begin(); it != this->end(); ++it)
51 {
52 (*it)->PrintSelf(os, indent.GetNextIndent());
53 }
54 }
55
57
60 typedef std::vector<vtkAbstractContextItem*>::const_iterator const_iterator;
61 typedef std::vector<vtkAbstractContextItem*>::iterator iterator;
62 typedef std::vector<vtkAbstractContextItem*>::const_reverse_iterator const_reverse_iterator;
63 typedef std::vector<vtkAbstractContextItem*>::reverse_iterator reverse_iterator;
65
69 void PaintItems(vtkContext2D* context)
70 {
71 for (const_iterator it = this->begin(); it != this->end(); ++it)
72 {
73 if ((*it)->GetVisible())
74 {
75 (*it)->Paint(context);
76 }
77 }
78 }
79
81
84 unsigned int AddItem(vtkAbstractContextItem* item)
85 {
86 item->Register(this->Scene);
87 item->SetScene(this->Scene);
88 item->SetParent(this->Item);
90
91 this->push_back(item);
92 return static_cast<unsigned int>(this->size() - 1);
93 }
94
96
100 {
101 for (iterator it = this->begin(); it != this->end(); ++it)
102 {
103 if (item == *it)
104 {
105 item->SetParent(nullptr);
106 item->SetScene(nullptr);
107 (*it)->Delete();
108 this->erase(it);
109 return true;
110 }
111 }
112 return false;
113 }
115
117
120 bool RemoveItem(unsigned int index)
121 {
122 if (index < this->size())
123 {
124 return this->RemoveItem(this->at(index));
125 }
126 return false;
127 }
129
131
134 void Clear()
135 {
136 for (const_iterator it = this->begin(); it != this->end(); ++it)
137 {
138 (*it)->SetParent(nullptr);
139 (*it)->SetScene(nullptr);
140 // releases cache from 2D, 3D devices
141 (*it)->ReleaseGraphicsResources();
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
180VTK_ABI_NAMESPACE_END
181#endif // vtkContextScenePrivate_h
182// 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.
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.
void PrintSelf(ostream &os, vtkIndent indent)
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.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
a simple class to control print indentation
Definition vtkIndent.h:108
vtkIndent GetNextIndent()
Determine the next indentation level.
void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).