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 <[email protected]>
6 * @author Maciej Suminski <[email protected]>
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>
28using namespace std::placeholders;
29
30#include <pcb_view.h>
31#include <pcb_display_options.h>
32#include <pcb_painter.h>
33
34#include <pcb_group.h>
35#include <footprint.h>
36
37namespace KIGFX {
38PCB_VIEW::PCB_VIEW( bool aIsDynamic ) :
39 VIEW( aIsDynamic )
40{
41 // Set m_boundary to define the max area size. The default value is acceptable for Pcbnew
42 // and Gerbview.
43 // However, ensure this area has the right size (max size allowed by integer coordinates) in
44 // case of the default value is changed. Could be a size depending on the drawing-sheet 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
58void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
59{
60 BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem );
61
62 if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
63 {
64 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
65 footprint->RunOnChildren( [this]( BOARD_ITEM* aChild )
66 {
67 VIEW::Add( aChild );
68 } );
69 }
70
71 VIEW::Add( aItem, aDrawPriority );
72}
73
74
76{
77 BOARD_ITEM* boardItem = dynamic_cast<BOARD_ITEM*>( aItem );
78
79 if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
80 {
81 FOOTPRINT* footprint = static_cast<FOOTPRINT*>( boardItem );
82 footprint->RunOnChildren( [this]( BOARD_ITEM* aChild )
83 {
84 VIEW::Remove( aChild );
85 } );
86 }
87
88 VIEW::Remove( aItem );
89}
90
91
92void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
93{
94 const BOARD_ITEM* boardItem = dynamic_cast<const BOARD_ITEM*>( aItem );
95
96 if( boardItem && boardItem->Type() == PCB_FOOTPRINT_T )
97 {
98 const FOOTPRINT* footprint = static_cast<const FOOTPRINT*>( boardItem );
99 footprint->RunOnChildren(
100 [this, aUpdateFlags]( BOARD_ITEM* child )
101 {
102 VIEW::Update( child, aUpdateFlags );
103 } );
104 }
105 else if( boardItem && boardItem->Type() == PCB_GROUP_T )
106 {
107 const PCB_GROUP* group = static_cast<const PCB_GROUP*>( boardItem );
108 group->RunOnChildren(
109 [this, aUpdateFlags]( BOARD_ITEM* child )
110 {
111 Update( child, aUpdateFlags );
112 } );
113 }
114
115 VIEW::Update( aItem, aUpdateFlags );
116}
117
118
119void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
120{
122}
123
124
126{
127 auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
128 auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
129
130 settings->LoadDisplayOptions( aOptions );
131}
132}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:50
void SetOrigin(const Vec &pos)
Definition: box2.h:202
void SetSize(const Vec &size)
Definition: box2.h:213
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all BOARD_ITEMs that belong to the footprint (pads, drawings,...
Definition: footprint.cpp:1356
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:156
PCB specific render settings.
Definition: pcb_painter.h:71
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Load settings related to display options (high-contrast mode, full or outline modes for vias/pads/tra...
virtual ~PCB_VIEW()
Definition: pcb_view.cpp:53
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: pcb_view.cpp:92
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:75
PCB_VIEW(bool aIsDynamic=true)
Definition: pcb_view.cpp:38
void UpdateDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Definition: pcb_view.cpp:125
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:77
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:69
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:316
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:346
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition: view.cpp:1574
BOX2D m_boundary
Definition: view.h:849
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:213
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:51
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266
@ ALL
All except INITIAL_ADD.
Definition: view_item.h:53
@ PCB_GROUP_T
class PCB_GROUP, a set of BOARD_ITEMs
Definition: typeinfo.h:115
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86