VTK  9.3.20240417
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 
19 #include "vtkAbstractContextItem.h"
20 #include "vtkContextScene.h"
21 
22 // STL headers
23 #include <vector> // Needed for STL vector.
24 
25 VTK_ABI_NAMESPACE_BEGIN
26 class vtkContext2D;
27 
28 //-----------------------------------------------------------------------------
29 class vtkContextScenePrivate : public std::vector<vtkAbstractContextItem*>
30 {
31 public:
36  : Scene(nullptr)
37  , Item(item)
38  {
39  }
40 
45 
47 
50  typedef std::vector<vtkAbstractContextItem*>::const_iterator const_iterator;
51  typedef std::vector<vtkAbstractContextItem*>::iterator iterator;
52  typedef std::vector<vtkAbstractContextItem*>::const_reverse_iterator const_reverse_iterator;
53  typedef std::vector<vtkAbstractContextItem*>::reverse_iterator reverse_iterator;
55 
59  void PaintItems(vtkContext2D* context)
60  {
61  for (const_iterator it = this->begin(); it != this->end(); ++it)
62  {
63  if ((*it)->GetVisible())
64  {
65  (*it)->Paint(context);
66  }
67  }
68  }
69 
71 
74  unsigned int AddItem(vtkAbstractContextItem* item)
75  {
76  item->Register(this->Scene);
77  item->SetScene(this->Scene);
78  item->SetParent(this->Item);
80 
81  this->push_back(item);
82  return static_cast<unsigned int>(this->size() - 1);
83  }
84 
86 
90  {
91  for (iterator it = this->begin(); it != this->end(); ++it)
92  {
93  if (item == *it)
94  {
95  item->SetParent(nullptr);
96  item->SetScene(nullptr);
97  (*it)->Delete();
98  this->erase(it);
99  return true;
100  }
101  }
102  return false;
103  }
105 
107 
110  bool RemoveItem(unsigned int index)
111  {
112  if (index < this->size())
113  {
114  return this->RemoveItem(this->at(index));
115  }
116  return false;
117  }
119 
121 
124  void Clear()
125  {
126  for (const_iterator it = this->begin(); it != this->end(); ++it)
127  {
128  (*it)->SetParent(nullptr);
129  (*it)->SetScene(nullptr);
130  // releases cache from 2D, 3D devices
131  (*it)->ReleaseGraphicsResources();
132  (*it)->Delete();
133  }
134  this->clear();
135  }
137 
139 
143  {
144  if (this->Scene == scene)
145  {
146  return;
147  }
148  this->Scene = scene;
149  for (const_iterator it = this->begin(); it != this->end(); ++it)
150  {
151  (*it)->SetScene(scene);
152  }
153  }
155 
160 
162 
168 };
169 
170 VTK_ABI_NAMESPACE_END
171 #endif // vtkContextScenePrivate_h
172 // 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:69
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.
void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
@ vector
Definition: vtkX3D.h:237
@ size
Definition: vtkX3D.h:253
@ index
Definition: vtkX3D.h:246