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( ITEM_GAL_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 VIEW_ITEM *VIEW_GROUP::GetItem(unsigned int idx) const
86 {
87  return m_groupItems[idx];
88 }
89 
91 {
92  BOX2I maxBox;
93 
94  maxBox.SetMaximum();
95  return maxBox;
96 }
97 
98 
99 void VIEW_GROUP::ViewDraw( int aLayer, VIEW* aView ) const
100 {
101  auto gal = aView->GetGAL();
102  PAINTER* painter = aView->GetPainter();
103 
104  const auto drawList = updateDrawList();
105 
106  // Draw all items immediately (without caching)
107  for( auto item : drawList )
108  {
109  gal->PushDepth();
110 
111  int layers[VIEW::VIEW_MAX_LAYERS], layers_count;
112  item->ViewGetLayers( layers, layers_count );
113  aView->SortLayers( layers, layers_count );
114 
115  for( int i = 0; i < layers_count; i++ )
116  {
117  if( aView->IsLayerVisible( layers[i] ) )
118  {
119  gal->AdvanceDepth();
120 
121  if( !painter->Draw( item, layers[i] ) )
122  item->ViewDraw( layers[i], aView ); // Alternative drawing method
123  }
124  }
125 
126  gal->PopDepth();
127  }
128 }
129 
130 
131 void VIEW_GROUP::ViewGetLayers( int aLayers[], int& aCount ) const
132 {
133  // Everything is displayed on a single layer
134  aLayers[0] = m_layer;
135  aCount = 1;
136 }
137 
138 
140 {
141  for( unsigned int i = 0 ; i < GetSize(); i++ )
142  delete GetItem( i );
143 
144  Clear();
145 }
146 
147 
149 {
150  return m_groupItems;
151 }
152 
153 
154 /*void VIEW_GROUP::ItemsSetVisibility( bool aVisible )
155 {
156  for(unsigned int i = 0 ; i < GetSize(); i++)
157  GetItem(i)->ViewSetVisible( aVisible );
158 }
159 
160 
161 void VIEW_GROUP::ItemsViewUpdate( VIEW_ITEM::VIEW_UPDATE_FLAGS aFlags )
162 {
163  for(unsigned int i = 0 ; i < GetSize(); i++)
164  GetItem(i)->ViewUpdate( aFlags );
165 }*/
166 
167 
169 {
170 
171 }
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:56
virtual VIEW_ITEM * GetItem(unsigned int aIdx) const
Definition: view_group.cpp:85
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:148
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:82
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:99
virtual const BOX2I ViewBBox() const override
Function ViewBBox() Returns the bounding box for all stored items covering all its layers...
Definition: view_group.cpp:90
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:602
Class PAINTER contains all the knowledge about how to draw graphical object onto any particular outpu...
Definition: painter.h:277
void FreeItems()
Function FreeItems() Frees all the items that were added to the group.
Definition: view_group.cpp:139
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:640
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.
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
#define ITEM_GAL_LAYER(layer)
macro for obtaining layer number for specific item (eg. pad or text)
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:131
general purpose overlay
Class VIEW.
Definition: view.h:58