VTK  9.0.20210422
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:
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
vtkX3D::vector
@ vector
Definition: vtkX3D.h:243
vtkContextScenePrivate::AddItem
unsigned int AddItem(vtkAbstractContextItem *item)
Add an item to the list - ensure it is not already in the list.
Definition: vtkContextScenePrivate.h:86
vtkObjectBase::Register
virtual void Register(vtkObjectBase *o)
Increase the reference count (mark as used by another object).
vtkAbstractContextItem
base class for items that are part of a vtkContextScene.
Definition: vtkAbstractContextItem.h:41
vtkContextScene.h
vtkContext2D
Class for drawing 2D primitives to a graphical context.
Definition: vtkContext2D.h:54
vtkContextScenePrivate::iterator
std::vector< vtkAbstractContextItem * >::iterator iterator
A few standard defines.
Definition: vtkContextScenePrivate.h:63
vtkContextScenePrivate::PaintItems
void PaintItems(vtkContext2D *context)
Paint all items in the list.
Definition: vtkContextScenePrivate.h:71
vtkContextScenePrivate::RemoveItem
bool RemoveItem(unsigned int index)
Remove an item from the list.
Definition: vtkContextScenePrivate.h:122
vtkContextScene
Provides a 2D scene for vtkContextItem objects.
Definition: vtkContextScene.h:48
vtkContextScenePrivate::Item
vtkAbstractContextItem * Item
Store a reference to the item that these children are part of.
Definition: vtkContextScenePrivate.h:176
vtkX3D::size
@ size
Definition: vtkX3D.h:259
vtkContextScenePrivate::vtkContextScenePrivate
vtkContextScenePrivate(vtkAbstractContextItem *item)
Default constructor.
Definition: vtkContextScenePrivate.h:46
vtkContextScenePrivate::reverse_iterator
std::vector< vtkAbstractContextItem * >::reverse_iterator reverse_iterator
A few standard defines.
Definition: vtkContextScenePrivate.h:65
vtkContextScenePrivate
Private implementation for scene/items.
Definition: vtkContextScenePrivate.h:41
vtkContextScenePrivate::const_reverse_iterator
std::vector< vtkAbstractContextItem * >::const_reverse_iterator const_reverse_iterator
A few standard defines.
Definition: vtkContextScenePrivate.h:64
vtkContextScenePrivate::const_iterator
std::vector< vtkAbstractContextItem * >::const_iterator const_iterator
A few standard defines.
Definition: vtkContextScenePrivate.h:62
vtkAbstractContextItem.h
vtkContextScenePrivate::Scene
vtkContextScene * Scene
Store a reference to the scene.
Definition: vtkContextScenePrivate.h:169
vtkContextScenePrivate::RemoveItem
bool RemoveItem(vtkAbstractContextItem *item)
Remove an item from the list.
Definition: vtkContextScenePrivate.h:101
vtkAbstractContextItem::SetScene
virtual void SetScene(vtkContextScene *scene)
Set the vtkContextScene for the item, always set for an item in a scene.
vtkAbstractContextItem::SetParent
virtual void SetParent(vtkAbstractContextItem *parent)
Set the parent item.
vtkContextScenePrivate::~vtkContextScenePrivate
~vtkContextScenePrivate()
Destructor.
Definition: vtkContextScenePrivate.h:56
vtkX3D::index
@ index
Definition: vtkX3D.h:252
vtkContextScenePrivate::SetScene
void SetScene(vtkContextScene *scene)
Set the scene for the instance (and its items).
Definition: vtkContextScenePrivate.h:152
vtkContextScenePrivate::Clear
void Clear()
Clear all items from the list - unregister.
Definition: vtkContextScenePrivate.h:136