VTK
dox/Rendering/Context2D/vtkContextScenePrivate.h
Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Visualization Toolkit
00004   Module:    vtkContextScenePrivate.h
00005 
00006   Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
00007   All rights reserved.
00008   See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
00009 
00010      This software is distributed WITHOUT ANY WARRANTY; without even
00011      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00012      PURPOSE.  See the above copyright notice for more information.
00013 
00014 =========================================================================*/
00015 
00027 #ifndef __vtkContextScenePrivate_h
00028 #define __vtkContextScenePrivate_h
00029 
00030 #include "vtkAbstractContextItem.h"
00031 #include "vtkContextScene.h"
00032 
00033 // STL headers
00034 #include <vector> // Needed for STL vector.
00035 
00036 class vtkContext2D;
00037 
00038 //-----------------------------------------------------------------------------
00039 class vtkContextScenePrivate : public std::vector<vtkAbstractContextItem*>
00040 {
00041 public:
00043 
00044   vtkContextScenePrivate(vtkAbstractContextItem* item)
00045     : std::vector<vtkAbstractContextItem*>(), Scene(0), Item(item)
00046     {
00047     }
00049 
00051 
00052   ~vtkContextScenePrivate()
00053     {
00054     this->Clear();
00055     }
00057 
00059 
00060   typedef std::vector<vtkAbstractContextItem*>::const_iterator
00061     const_iterator;
00062   typedef std::vector<vtkAbstractContextItem*>::iterator iterator;
00063   // Older versions of GCC did not implement comparison operators for the
00064   // const_reverse_operator, the simplest thing to do is not use the const
00065   // form of the operator.
00066 #ifdef VTK_CONST_REVERSE_ITERATOR_COMPARISON
00067   typedef std::vector<vtkAbstractContextItem*>::const_reverse_iterator
00068     const_reverse_iterator;
00069 #else
00070   typedef std::vector<vtkAbstractContextItem*>::reverse_iterator
00071     const_reverse_iterator;
00072 #endif
00073   typedef std::vector<vtkAbstractContextItem*>::reverse_iterator
00074     reverse_iterator;
00076 
00078 
00079   void PaintItems(vtkContext2D* context)
00080     {
00081     for(const_iterator it = this->begin(); it != this->end(); ++it)
00082       {
00083       if ((*it)->GetVisible())
00084         {
00085         (*it)->Paint(context);
00086         }
00087       }
00088     }
00090 
00092 
00093   unsigned int AddItem(vtkAbstractContextItem* item)
00094     {
00095     item->Register(this->Scene);
00096     item->SetScene(this->Scene);
00097     item->SetParent(this->Item);
00099 
00100     this->push_back(item);
00101     return static_cast<unsigned int>(this->size()-1);
00102     }
00103 
00105 
00106   bool RemoveItem(vtkAbstractContextItem* item)
00107     {
00108     for(iterator it = this->begin(); it != this->end(); ++it)
00109       {
00110       if (item == *it)
00111         {
00112         item->SetParent(NULL);
00113         item->SetScene(NULL);
00114         (*it)->Delete();
00115         this->erase(it);
00116         return true;
00117         }
00118       }
00119     return false;
00120     }
00122 
00124 
00125   bool RemoveItem(unsigned int index)
00126     {
00127     if (index < this->size())
00128       {
00129       return this->RemoveItem(this->at(index));
00130       }
00131     return false;
00132     }
00134 
00136 
00137   void Clear()
00138     {
00139     for(const_iterator it = this->begin(); it != this->end(); ++it)
00140       {
00141       (*it)->SetParent(NULL);
00142       (*it)->SetScene(NULL);
00143       (*it)->Delete();
00144       }
00145     this->clear();
00146     }
00148 
00150 
00151   void SetScene(vtkContextScene* scene)
00152     {
00153     if (this->Scene == scene)
00154       {
00155       return;
00156       }
00157     this->Scene = scene;
00158     for(const_iterator it = this->begin(); it != this->end(); ++it)
00159       {
00160         (*it)->SetScene(scene);
00161       }
00162     }
00164 
00166   vtkContextScene* Scene;
00167 
00169 
00171   vtkAbstractContextItem* Item;
00172 };
00174 
00175 #endif //__vtkContextScenePrivate_h
00176 // VTK-HeaderTest-Exclude: vtkContextScenePrivate.h