KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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#include <footprint.h>
34
35namespace KIGFX {
36PCB_VIEW::PCB_VIEW( bool aIsDynamic ) :
37 VIEW( aIsDynamic )
38{
39 // Set m_boundary to define the max area size. The default value is acceptable for Pcbnew
40 // and Gerbview.
41 // However, ensure this area has the right size (max size allowed by integer coordinates) in
42 // case of the default value is changed. Could be a size depending on the drawing-sheet size.
43 typedef std::numeric_limits<int> coord_limits;
44 double pos = coord_limits::lowest() + coord_limits::epsilon();
45 double size = static_cast<double>( coord_limits::max() - coord_limits::epsilon() )
46 - static_cast<double>( coord_limits::min() + coord_limits::epsilon() );
47 m_boundary.SetOrigin( pos, pos );
48 m_boundary.SetSize( size, size );
49}
50
51
53{
54}
55
56
57void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
58{
59 if( aItem->IsBOARD_ITEM() )
60 {
61 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
62
63 if( boardItem->Type() == PCB_FOOTPRINT_T )
64 {
65 static_cast<FOOTPRINT*>( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Add, this,
66 _1, aDrawPriority ) );
67 }
68 }
69
70 VIEW::Add( aItem, aDrawPriority );
71}
72
73
75{
76 if( aItem->IsBOARD_ITEM() )
77 {
78 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
79
80 if( boardItem->Type() == PCB_FOOTPRINT_T )
81 {
82 static_cast<FOOTPRINT*>( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Remove,
83 this, _1 ) );
84 }
85 }
86
87 VIEW::Remove( aItem );
88}
89
90
91void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
92{
93 if( aItem->IsBOARD_ITEM() )
94 {
95 const BOARD_ITEM* boardItem = static_cast<const BOARD_ITEM*>( aItem );
96
97 if( boardItem->Type() == PCB_TABLECELL_T )
98 {
99 VIEW::Update( boardItem->GetParent() );
100 }
101 else
102 {
103 boardItem->RunOnChildren(
104 [this, aUpdateFlags]( BOARD_ITEM* child )
105 {
106 VIEW::Update( child, aUpdateFlags );
107 } );
108 }
109 }
110
111 VIEW::Update( aItem, aUpdateFlags );
112}
113
114
115void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
116{
118}
119
120
122{
123 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
124 KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
125
126 settings->LoadDisplayOptions( aOptions );
127}
128}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:215
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction) const
Invoke a function on all children.
Definition: board_item.h:206
constexpr void SetOrigin(const Vec &pos)
Definition: box2.h:237
constexpr void SetSize(const SizeVec &size)
Definition: box2.h:248
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:101
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:173
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
Definition: pcb_painter.h:178
PCB specific render settings.
Definition: pcb_painter.h:78
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:52
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:91
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition: pcb_view.cpp:57
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
PCB_VIEW(bool aIsDynamic=true)
Definition: pcb_view.cpp:36
void UpdateDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Definition: pcb_view.cpp:121
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
bool IsBOARD_ITEM() const
Definition: view_item.h:100
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:68
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:317
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:357
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:1687
BOX2D m_boundary
Definition: view.h:864
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:221
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
@ ALL
All except INITIAL_ADD.
Definition: view_item.h:58
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition: typeinfo.h:95
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition: typeinfo.h:86