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( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aItem ) )
60 footprint->RunOnChildren( std::bind( &PCB_VIEW::Add, this, _1, aDrawPriority ) );
61
62 VIEW::Add( aItem, aDrawPriority );
63}
64
65
67{
68 if( FOOTPRINT* footprint = dynamic_cast<FOOTPRINT*>( aItem ) )
69 footprint->RunOnChildren( std::bind( &PCB_VIEW::Remove, this, _1 ) );
70
71 VIEW::Remove( aItem );
72}
73
74
75void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem, int aUpdateFlags ) const
76{
77 if( const BOARD_ITEM* boardItem = dynamic_cast<const BOARD_ITEM*>( aItem ) )
78 {
79 if( boardItem->Type() == PCB_TABLECELL_T )
80 {
81 VIEW::Update( boardItem->GetParent() );
82 }
83 else
84 {
85 boardItem->RunOnChildren(
86 [this, aUpdateFlags]( BOARD_ITEM* child )
87 {
88 VIEW::Update( child, aUpdateFlags );
89 } );
90 }
91 }
92
93 VIEW::Update( aItem, aUpdateFlags );
94}
95
96
97void PCB_VIEW::Update( const KIGFX::VIEW_ITEM* aItem ) const
98{
100}
101
102
104{
105 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
106 KIGFX::PCB_RENDER_SETTINGS* settings = painter->GetSettings();
107
108 settings->LoadDisplayOptions( aOptions );
109}
110}
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:77
void SetOrigin(const Vec &pos)
Definition: box2.h:227
void SetSize(const SizeVec &size)
Definition: box2.h:238
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:164
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:169
PCB specific render settings.
Definition: pcb_painter.h:77
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:75
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:66
PCB_VIEW(bool aIsDynamic=true)
Definition: pcb_view.cpp:36
void UpdateDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Definition: pcb_view.cpp:103
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
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:315
virtual void Remove(VIEW_ITEM *aItem)
Remove a VIEW_ITEM from the view.
Definition: view.cpp:354
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:1631
BOX2D m_boundary
Definition: view.h:858
PAINTER * GetPainter() const
Return the painter object used by the view for drawing #VIEW_ITEMS.
Definition: view.h:215
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