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 <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
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>
28 using namespace std::placeholders;
29 
30 #include <pcb_view.h>
31 #include <pcb_display_options.h>
32 #include <pcb_painter.h>
33 
34 #include <class_module.h>
35 
36 namespace KIGFX {
37 PCB_VIEW::PCB_VIEW( bool aIsDynamic ) :
38  VIEW( aIsDynamic )
39 {
40  // Set m_boundary to define the max area size. The default value
41  // is acceptable for Pcbnew and Gerbview.
42  // However, ensure this area has the right size (max size allowed by integer coordinates)
43  // in case of the default value is changed.
44  // Could be a size depending on the worksheet 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 
58 void PCB_VIEW::Add( KIGFX::VIEW_ITEM* aItem, int aDrawPriority )
59 {
60  auto item = static_cast<BOARD_ITEM*>( aItem );
61 
62  if( item->Type() == PCB_MODULE_T )
63  {
64  auto mod = static_cast<MODULE*>( item );
65  mod->RunOnChildren([this] ( BOARD_ITEM* aModItem ) {
66  VIEW::Add( aModItem );
67  } );
68  }
69 
70  VIEW::Add( item, aDrawPriority );
71 }
72 
73 
75 {
76  auto item = static_cast<BOARD_ITEM*>( aItem );
77 
78 
79  if( item->Type() == PCB_MODULE_T )
80  {
81  auto mod = static_cast<MODULE*>( item );
82  mod->RunOnChildren([this] ( BOARD_ITEM* aModItem ) {
83  VIEW::Remove( aModItem );
84  } );
85  }
86 
87  VIEW::Remove( item );
88 }
89 
90 
91 void PCB_VIEW::Update( KIGFX::VIEW_ITEM* aItem, int aUpdateFlags )
92 {
93  auto item = static_cast<BOARD_ITEM*>( aItem );
94 
95  if( item->Type() == PCB_MODULE_T )
96  {
97  auto mod = static_cast<MODULE*>( item );
98  mod->RunOnChildren([this, aUpdateFlags] ( BOARD_ITEM* aModItem ) {
99  VIEW::Update( aModItem, aUpdateFlags );
100  } );
101  }
102 
103  VIEW::Update( item, aUpdateFlags );
104 }
105 
106 
108 {
109  PCB_VIEW::Update( aItem, KIGFX::ALL );
110 }
111 
112 
114 {
115  auto painter = static_cast<KIGFX::PCB_PAINTER*>( GetPainter() );
116  auto settings = static_cast<KIGFX::PCB_RENDER_SETTINGS*>( painter->GetSettings() );
117 
118  settings->LoadDisplayOptions( aOptions, settings->GetShowPageLimits() );
119 }
120 }
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: class_module.h:58
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags) override
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: pcb_view.cpp:91
Class BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class...
virtual void Remove(VIEW_ITEM *aItem)
Function Remove() Removes a VIEW_ITEM from the view.
Definition: view.cpp:374
void SetSize(const Vec &size)
Definition: box2.h:210
Class VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW...
Definition: view_item.h:84
Item needs to be redrawn.
Definition: view_item.h:61
Class PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:211
virtual void Remove(VIEW_ITEM *aItem) override
Function Remove() Removes a VIEW_ITEM from the view.
Definition: pcb_view.cpp:74
Class PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:62
class MODULE, a footprint
Definition: typeinfo.h:89
Class PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings...
PAINTER * GetPainter() const
Function GetPainter() Returns the painter object used by the view for drawing VIEW_ITEMS.
Definition: view.h:199
void UpdateDisplayOptions(PCB_DISPLAY_OPTIONS *aOptions)
Definition: pcb_view.cpp:113
virtual void Update(VIEW_ITEM *aItem, int aUpdateFlags)
For dynamic VIEWs, informs the associated VIEW that the graphical representation of this item has cha...
Definition: view.cpp:1530
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS *aOptions, bool aShowPageLimits)
Function LoadDisplayOptions Loads settings related to display options (high-contrast mode...
#define max(a, b)
Definition: auxiliary.h:86
BOX2D m_boundary
View boundaries.
Definition: view.h:828
void SetOrigin(const Vec &pos)
Definition: box2.h:208
virtual ~PCB_VIEW()
Definition: pcb_view.cpp:53
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1) override
Function Add() Adds a VIEW_ITEM to the view.
Definition: pcb_view.cpp:58
virtual void Add(VIEW_ITEM *aItem, int aDrawPriority=-1)
Function Add() Adds a VIEW_ITEM to the view.
Definition: view.cpp:344
Module description (excepted pads)
Class VIEW.
Definition: view.h:61
Definition of PCB_DISPLAY_OPTIONS class.
#define mod(a, n)
Definition: greymap.cpp:24