KiCad PCB EDA Suite
pcb_view.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-2017 CERN
5  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 
27 #include <functional>
28 using namespace std::placeholders;
29 
30 #include <pcb_view.h>
31 #include <pcb_display_options.h>
32 #include <pcb_painter.h>
33 
34 #include <class_pcb_group.h>
35 #include <class_module.h>
36 
37 namespace KIGFX {
38 PCB_VIEW::PCB_VIEW( bool aIsDynamic ) :
39  VIEW( aIsDynamic )
40 {
41  // Set m_boundary to define the max area size. The default value
42  // is acceptable for Pcbnew and Gerbview.
43  // However, ensure this area has the right size (max size allowed by integer coordinates)
44  // in case of the default value is changed.
45  // Could be a size depending on the worksheet size.
46  typedef std::numeric_limits<int> coord_limits;
47  double pos = coord_limits::lowest() / 2 + coord_limits::epsilon();
48  double size = coord_limits::max() - coord_limits::epsilon();
49  m_boundary.SetOrigin( pos, pos );
50  m_boundary.SetSize( size, size );
51 }
52 
53 
55 {
56 }
57 
58 
59 void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
60 {
61  auto item = static_cast<BOARD_ITEM*>( aItem );
62 
63  if( item->Type() == PCB_MODULE_T )
64  {
65  auto mod = static_cast<MODULE*>( item );
66  mod->RunOnChildren( [this] ( BOARD_ITEM* aModItem )
67  {
68  VIEW::Add( aModItem );
69  } );
70  }
71 
72  VIEW::Add( item, aDrawPriority );
73 }
74 
75 
77 {
78  auto item = static_cast<BOARD_ITEM*>( aItem );
79 
80 
81  if( item->Type() == PCB_MODULE_T )
82  {
83  auto mod = static_cast<MODULE*>( item );
84  mod->RunOnChildren([this] ( BOARD_ITEM* aModItem ) {
85  VIEW::Remove( aModItem );
86  } );
87  }
88 
89  VIEW::Remove( item );
90 }
91 
92 
93 void PCB_VIEW::Update( KIGFX::VIEW_ITEM* aItem, int aUpdateFlags )
94 {
95  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aItem );
96 
97  if( item->Type() == PCB_MODULE_T )
98  {
99  MODULE* mod = static_cast<MODULE*>( item );
100 
101  mod->RunOnChildren( [this, aUpdateFlags] ( BOARD_ITEM* aModItem )
102  {
103  VIEW::Update( aModItem, aUpdateFlags );
104  } );
105  }
106 
107  VIEW::Update( item, aUpdateFlags );
108 }
109 
110 
112 {
113  PCB_VIEW::Update( aItem, KIGFX::ALL );
114 }
115 
116 
118 {
119  auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
120  auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
121 
122  settings->LoadDisplayOptions( aOptions, settings->GetShowPageLimits() );
123 }
124 }
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction)
Function RunOnChildren.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:93
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:357
void SetSize(const Vec &size)
Definition: box2.h:212
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:85
Item needs to be redrawn.
Definition: view_item.h:63
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:76
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:201
class MODULE, a footprint
Definition: typeinfo.h:89
PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
void UpdateDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Definition: pcb_view.cpp:117
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1513
BOX2D m_boundary
View boundaries.
Definition: view.h:819
void SetOrigin(const Vec &pos)
Definition: box2.h:210
virtual ~PCB_VIEW()
Definition: pcb_view.cpp:54
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:59
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:327
VIEW.
Definition: view.h:63
Definition of PCB_DISPLAY_OPTIONS class.
Class to handle a set of BOARD_ITEMs.
KICAD_T Type() const
Function Type()
Definition: eda_item.h:182