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 {
37 VIEW()
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, _1, aDrawPriority ),
66 RECURSE_MODE::NO_RECURSE );
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, this, _1 ),
83 RECURSE_MODE::NO_RECURSE );
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 RECURSE_MODE::NO_RECURSE );
109 }
110 }
111
112 VIEW::Update( aItem, aUpdateFlags );
113}
114
115
116void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
117{
119}
120
121
122void PCB_VIEW::UpdateCollidingItems( const std::vector<BOX2I>& aStaleAreas,
123 std::initializer_list<KICAD_T> aTypes )
124{
126 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
127 {
128 if( aItem->IsBOARD_ITEM() )
129 {
130 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aItem );
131
132 if( item->IsType( aTypes ) )
133 {
134 BOX2I itemBBox = item->GetBoundingBox();
135
136 for( const BOX2I& bbox : aStaleAreas )
137 {
138 if( itemBBox.Intersects( bbox ) )
139 return KIGFX::REPAINT;
140 }
141 }
142 }
143
144 return 0;
145 } );
146}
147
148
149void PCB_VIEW::UpdateDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions )
150{
151 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
152 KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
153
154 settings->LoadDisplayOptions( aOptions );
155}
156}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:79
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition: board_item.h:208
BOARD_ITEM_CONTAINER * GetParent() const
Definition: board_item.h:210
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:110
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:182
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:187
PCB specific render settings.
Definition: pcb_painter.h:80
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
void UpdateCollidingItems(const std::vector< BOX2I > &aStaleAreas, std::initializer_list< KICAD_T > aTypes)
Sets the KIGFX::REPAINT on all items matching aTypes which intersect aStaleAreas.
Definition: pcb_view.cpp:122
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:86
bool IsBOARD_ITEM() const
Definition: view_item.h:102
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition: view.h:66
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition: view.cpp:298
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:341
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:1685
BOX2D m_boundary
Definition: view.h:880
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
Definition: view.cpp:1571
The Cairo implementation of the graphics abstraction layer.
Definition: eda_group.h:33
@ ALL
All except INITIAL_ADD.
Definition: view_item.h:59
@ 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