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_module.h>
35 
36 namespace KIGFX {
37 PCB_VIEW::PCB_VIEW( bool aIsDynamic ) :
38  VIEW( aIsDynamic )
39 {
40  // Set m_boundary to define the max area size. The default value
41  // is acceptable for Pcbnew and Gerbview.
42  // However, ensure this area has the right size (max size allowed by integer coordinates)
43  // in case of the default value is changed.
44  // Could be a size depending on the worksheet size.
45  typedef std::numeric_limits<int> coord_limits;
46  double pos = coord_limits::lowest() / 2 + coord_limits::epsilon();
47  double size = coord_limits::max() - coord_limits::epsilon();
48  m_boundary.SetOrigin( pos, pos );
49  m_boundary.SetSize( size, size );
50 }
51 
52 
54 {
55 }
56 
57 
58 void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
59 {
60  auto item = static_cast<BOARD_ITEM*>( aItem );
61 
62  if( item->Type() == PCB_MODULE_T )
63  {
64  auto mod = static_cast<MODULE*>( item );
65  mod->RunOnChildren( [this] ( BOARD_ITEM* aModItem )
66  {
67  VIEW::Add( aModItem );
68  } );
69  }
70 
71  VIEW::Add( item, aDrawPriority );
72 }
73 
74 
76 {
77  auto item = static_cast<BOARD_ITEM*>( aItem );
78 
79 
80  if( item->Type() == PCB_MODULE_T )
81  {
82  auto mod = static_cast<MODULE*>( item );
83  mod->RunOnChildren([this] ( BOARD_ITEM* aModItem ) {
84  VIEW::Remove( aModItem );
85  } );
86  }
87 
88  VIEW::Remove( item );
89 }
90 
91 
92 void PCB_VIEW::Update( KIGFX::VIEW_ITEM* aItem, int aUpdateFlags )
93 {
94  BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aItem );
95 
96  if( item->Type() == PCB_MODULE_T )
97  {
98  MODULE* mod = static_cast<MODULE*>( item );
99 
100  mod->RunOnChildren( [this, aUpdateFlags] ( BOARD_ITEM* aModItem )
101  {
102  VIEW::Update( aModItem, aUpdateFlags );
103  } );
104  }
105 
106  VIEW::Update( item, aUpdateFlags );
107 }
108 
109 
111 {
112  PCB_VIEW::Update( aItem, KIGFX::ALL );
113 }
114 
115 
117 {
118  auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
119  auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
120 
121  settings->LoadDisplayOptions( aOptions, settings->GetShowPageLimits() );
122 }
123 }
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:92
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:380
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:75
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
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:116
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:1544
BOX2D m_boundary
View boundaries.
Definition: view.h:837
void SetOrigin(const Vec &pos)
Definition: box2.h:210
virtual ~PCB_VIEW()
Definition: pcb_view.cpp:53
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:350
VIEW.
Definition: view.h:61
Definition of PCB_DISPLAY_OPTIONS class.
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193