KiCad PCB EDA Suite
view_group.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2013 CERN
5  * @author Maciej Suminski <maciej.suminski@cern.ch>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, you may find one here:
19  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20  * or you may search the http://www.gnu.org website for the version 2 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  *
24  */
25 
33 #include <set>
34 #include <algorithm>
35 #include <view/view_group.h>
36 #include <view/view.h>
37 #include <painter.h>
40 
41 using namespace KIGFX;
42 
44  m_layer( LAYER_GP_OVERLAY )
45 {
46 }
47 
48 
50 {
51  // VIEW_ITEM destructor removes the object from its parent view
52 }
53 
54 
55 void VIEW_GROUP::Add( VIEW_ITEM* aItem )
56 {
57  m_groupItems.push_back( aItem );
58 }
59 
60 
62 {
63  for( auto iter = m_groupItems.begin(); iter != m_groupItems.end(); ++iter )
64  {
65  if( aItem == *iter )
66  {
67  m_groupItems.erase( iter );
68  break;
69  }
70  }
71 }
72 
73 
75 {
76  m_groupItems.clear();
77 }
78 
79 
80 unsigned int VIEW_GROUP::GetSize() const
81 {
82  return m_groupItems.size();
83 }
84 
85 
86 VIEW_ITEM *VIEW_GROUP::GetItem( unsigned int idx ) const
87 {
88  return m_groupItems[idx];
89 }
90 
91 
93 {
94  BOX2I maxBox;
95 
96  maxBox.SetMaximum();
97  return maxBox;
98 }
99 
100 
101 void VIEW_GROUP::ViewDraw( int aLayer, VIEW* aView ) const
102 {
103  auto gal = aView->GetGAL();
104  PAINTER* painter = aView->GetPainter();
105 
106  const auto drawList = updateDrawList();
107 
108  // Draw all items immediately (without caching)
109  for( auto item : drawList )
110  {
111  gal->PushDepth();
112 
113  int layers[VIEW::VIEW_MAX_LAYERS], layers_count;
114  item->ViewGetLayers( layers, layers_count );
115  aView->SortLayers( layers, layers_count );
116 
117  for( int i = 0; i < layers_count; i++ )
118  {
119  if( aView->IsLayerVisible( layers[i] ) )
120  {
121  gal->AdvanceDepth();
122 
123  if( !painter->Draw( item, layers[i] ) )
124  item->ViewDraw( layers[i], aView ); // Alternative drawing method
125  }
126  }
127 
128  gal->PopDepth();
129  }
130 }
131 
132 
133 void VIEW_GROUP::ViewGetLayers( int aLayers[], int& aCount ) const
134 {
135  // Everything is displayed on a single layer
136  aLayers[0] = m_layer;
137  aCount = 1;
138 }
139 
140 
142 {
143  for( unsigned int i = 0 ; i < GetSize(); i++ )
144  delete GetItem( i );
145 
146  Clear();
147 }
148 
149 
151 {
152  return m_groupItems;
153 }
154 
155 
156 /*void VIEW_GROUP::ItemsSetVisibility( bool aVisible )
157 {
158  for(unsigned int i = 0 ; i < GetSize(); i++)
159  GetItem(i)->ViewSetVisible( aVisible );
160 }
161 
162 
163 void VIEW_GROUP::ItemsViewUpdate( VIEW_ITEM::VIEW_UPDATE_FLAGS aFlags )
164 {
165  for(unsigned int i = 0 ; i < GetSize(); i++)
166  GetItem(i)->ViewUpdate( aFlags );
167 }*/
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
virtual VIEW_ITEM * GetItem(unsigned int aIdx) const
Definition: view_group.cpp:86
bool IsLayerVisible(int aLayer) const
Function IsLayerVisible() Returns information about visibility of a particular layer.
Definition: view.h:404
virtual const ITEMS updateDrawList() const
Definition: view_group.cpp:150
virtual void Clear()
Function Clear() Removes all the stored items from the group.
Definition: view_group.cpp:74
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:83
virtual void ViewDraw(int aLayer, VIEW *aView) const override
Function ViewDraw() Draws all the stored items in the group on the given layer.
Definition: view_group.cpp:101
virtual const BOX2I ViewBBox() const override
Function ViewBBox() Returns the bounding box for all stored items covering all its layers...
Definition: view_group.cpp:92
void SortLayers(int aLayers[], int &aCount) const
Function SortLayers() Changes the order of given layer ids, so after sorting the order corresponds to...
Definition: view.cpp:604
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:278
void FreeItems()
Function FreeItems() Frees all the items that were added to the group.
Definition: view_group.cpp:141
GAL * GetGAL() const
Function GetGAL() Returns the GAL this view is using to draw graphical primitives.
Definition: view.h:177
void SetMaximum()
Definition: box2.h:61
static const int VIEW_MAX_LAYERS
maximum number of layers that may be shown
Definition: view.h:652
int m_layer
Layer on which the group is drawn.
Definition: view_group.h:131
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes an item from the group.
Definition: view_group.cpp:61
VIEW_GROUP extends VIEW_ITEM by possibility of grouping items into a single object.
general purpose overlay
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:196
virtual void Add(VIEW_ITEM *aItem)
Function Add() Adds an item to the group.
Definition: view_group.cpp:55
VIEW_GROUP(VIEW *aView=NULL)
Definition: view_group.cpp:43
virtual unsigned int GetSize() const
Function GetSize() Returns the number of stored items.
Definition: view_group.cpp:80
virtual ~VIEW_GROUP()
Definition: view_group.cpp:49
virtual bool Draw(const VIEW_ITEM *aItem, int aLayer)=0
Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the it...
std::vector< VIEW_ITEM * > ITEMS
Definition: view_group.h:45
Board layer functions and definitions.
ITEMS m_groupItems
Container for storing VIEW_ITEMs.
Definition: view_group.h:135
virtual void ViewGetLayers(int aLayers[], int &aCount) const override
Function ViewGetLayers() Returns all the layers used by the stored items.
Definition: view_group.cpp:133
Class VIEW.
Definition: view.h:58