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, see <https://www.gnu.org/licenses/>.
20 */
21
22
23#include <functional>
24using namespace std::placeholders;
25
26#include <pcb_view.h>
27#include <pcb_display_options.h>
28#include <pcb_painter.h>
29#include <footprint.h>
30
31namespace KIGFX {
33 VIEW()
34{
35 // Set m_boundary to define the max area size. The default value is acceptable for Pcbnew
36 // and Gerbview.
37 // However, ensure this area has the right size (max size allowed by integer coordinates) in
38 // case of the default value is changed. Could be a size depending on the drawing-sheet size.
39 typedef std::numeric_limits<int> coord_limits;
40 double pos = coord_limits::lowest() + coord_limits::epsilon();
41 double size = static_cast<double>( coord_limits::max() - coord_limits::epsilon() )
42 - static_cast<double>( coord_limits::min() + coord_limits::epsilon() );
43 m_boundary.SetOrigin( pos, pos );
44 m_boundary.SetSize( size, size );
45}
46
47
51
52
53void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
54{
55 if( aItem->IsBOARD_ITEM() )
56 {
57 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
58
59 if( boardItem->Type() == PCB_FOOTPRINT_T )
60 {
61 static_cast<FOOTPRINT*>( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Add, this, _1, aDrawPriority ),
63 }
64 }
65
66 VIEW::Add( aItem, aDrawPriority );
67}
68
69
71{
72 if( aItem->IsBOARD_ITEM() )
73 {
74 BOARD_ITEM* boardItem = static_cast<BOARD_ITEM*>( aItem );
75
76 if( boardItem->Type() == PCB_FOOTPRINT_T )
77 {
78 static_cast<FOOTPRINT*>( boardItem )->RunOnChildren( std::bind( &PCB_VIEW::Remove, this, _1 ),
80 }
81 }
82
83 VIEW::Remove( aItem );
84}
85
86
87void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
88{
89 if( aItem->IsBOARD_ITEM() )
90 {
91 const BOARD_ITEM* boardItem = static_cast<const BOARD_ITEM*>( aItem );
92
93 if( boardItem->Type() == PCB_TABLECELL_T )
94 {
95 VIEW::Update( boardItem->GetParent() );
96 }
97 else
98 {
99 boardItem->RunOnChildren(
100 [this, aUpdateFlags]( BOARD_ITEM* child )
101 {
102 VIEW::Update( child, aUpdateFlags );
103 },
105 }
106 }
107
108 VIEW::Update( aItem, aUpdateFlags );
109}
110
111
112void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
113{
115}
116
117
118void PCB_VIEW::UpdateCollidingItems( const std::vector<BOX2I>& aStaleAreas,
119 std::initializer_list<KICAD_T> aTypes )
120{
122 [&]( KIGFX::VIEW_ITEM* aItem ) -> int
123 {
124 if( aItem->IsBOARD_ITEM() )
125 {
126 BOARD_ITEM* item = static_cast<BOARD_ITEM*>( aItem );
127
128 if( item->IsType( aTypes ) )
129 {
130 BOX2I itemBBox = item->GetBoundingBox();
131
132 for( const BOX2I& bbox : aStaleAreas )
133 {
134 if( itemBBox.Intersects( bbox ) )
135 return KIGFX::REPAINT;
136 }
137 }
138 }
139
140 return 0;
141 } );
142}
143
144
146{
147 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
148 KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
149
150 settings->LoadDisplayOptions( aOptions );
151}
152}
BOX2< VECTOR2I > BOX2I
Definition box2.h:918
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:81
virtual void RunOnChildren(const std::function< void(BOARD_ITEM *)> &aFunction, RECURSE_MODE aMode) const
Invoke a function on all children.
Definition board_item.h:229
BOARD_ITEM_CONTAINER * GetParent() const
Definition board_item.h:231
constexpr bool Intersects(const BOX2< Vec > &aRect) const
Definition box2.h:307
virtual const BOX2I GetBoundingBox() const
Return the orthogonal bounding box of this object for display purposes.
Definition eda_item.cpp:135
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:108
virtual bool IsType(const std::vector< KICAD_T > &aScanTypes) const
Check whether the item is one of the listed types.
Definition eda_item.h:202
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
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:48
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:87
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Add a VIEW_ITEM to the view.
Definition pcb_view.cpp:53
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:118
virtual void Remove(VIEW_ITEM *aItem) override
Remove a VIEW_ITEM from the view.
Definition pcb_view.cpp:70
void UpdateDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Definition pcb_view.cpp:145
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
bool IsBOARD_ITEM() const
Definition view_item.h:98
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Add a VIEW_ITEM to the view.
Definition view.cpp:300
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition view.cpp:404
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:1835
BOX2D m_boundary
Definition view.h:905
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition view.h:225
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:1702
@ NO_RECURSE
Definition eda_item.h:50
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ ALL
All except INITIAL_ADD.
Definition view_item.h:55
@ PCB_TABLECELL_T
class PCB_TABLECELL, PCB_TEXTBOX for use in tables
Definition typeinfo.h:88
@ PCB_FOOTPRINT_T
class FOOTPRINT, a footprint
Definition typeinfo.h:79