KiCad PCB EDA Suite
pcb_painter.h
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 CERN
5 * Copyright (C) 2016-2022 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Tomasz Wlostowski <[email protected]>
8 * @author Maciej Suminski <[email protected]>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, you may find one here:
22 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
23 * or you may search the http://www.gnu.org website for the version 2 license,
24 * or you may write to the Free Software Foundation, Inc.,
25 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26 */
27
28#ifndef PCB_PAINTER_H
29#define PCB_PAINTER_H
30
31#include <frame_type.h>
32#include <painter.h>
33#include <pcb_display_options.h>
34#include <math/vector2d.h>
35#include <memory>
37
38
39class EDA_ITEM;
42class BOARD_ITEM;
43class PCB_ARC;
44class BOARD;
45class PCB_VIA;
46class PCB_TRACK;
47class PAD;
48class PCB_SHAPE;
49class PCB_GROUP;
50class FOOTPRINT;
51class ZONE;
52class PCB_BITMAP;
53class PCB_TEXT;
54class PCB_TEXTBOX;
55class FP_TEXT;
56class FP_TEXTBOX;
58class PCB_TARGET;
59class PCB_MARKER;
60class NET_SETTINGS;
61class NETINFO_LIST;
62class TEXT_ATTRIBUTES;
63
64namespace KIGFX
65{
66class GAL;
67
72{
73public:
74 friend class PCB_PAINTER;
75
77
84 void LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions );
85
86 void LoadColors( const COLOR_SETTINGS* aSettings ) override;
87
89 COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
90
91 bool GetShowPageLimits() const override;
92
93 inline bool IsBackgroundDark() const override
94 {
96
97 return luma < 0.5;
98 }
99
100 const COLOR4D& GetBackgroundColor() const override { return m_layerColors[ LAYER_PCB_BACKGROUND ]; }
101
102 void SetBackgroundColor( const COLOR4D& aColor ) override
103 {
105 }
106
107 const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GRID ]; }
108
109 const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
110
113
114 std::map<wxString, KIGFX::COLOR4D>& GetNetclassColorMap() { return m_netclassColors; }
115
116 std::map<int, KIGFX::COLOR4D>& GetNetColorMap() { return m_netColors; }
117
118 std::set<int>& GetHiddenNets() { return m_hiddenNets; }
119 const std::set<int>& GetHiddenNets() const { return m_hiddenNets; }
120
121public:
123
126
127 PAD* m_PadEditModePad; // Pad currently in Pad Edit Mode (if any)
128
129protected:
131 static const double MAX_FONT_SIZE;
132
135
137 std::map<wxString, KIGFX::COLOR4D> m_netclassColors;
138
140 std::map<int, KIGFX::COLOR4D> m_netColors;
141
143 std::set<int> m_hiddenNets;
144
145 // These opacity overrides multiply with any opacity in the base layer color
151};
152
153
157class PCB_PAINTER : public PAINTER
158{
159public:
160 PCB_PAINTER( GAL* aGal, FRAME_T aFrameType );
161
164 {
165 return &m_pcbSettings;
166 }
167
169 virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
170
171protected:
173
174 // Drawing functions for various types of PCB-specific items
175 void draw( const PCB_TRACK* aTrack, int aLayer );
176 void draw( const PCB_ARC* aArc, int aLayer );
177 void draw( const PCB_VIA* aVia, int aLayer );
178 void draw( const PAD* aPad, int aLayer );
179 void draw( const PCB_SHAPE* aSegment, int aLayer );
180 void draw( const PCB_BITMAP* aBitmap, int aLayer );
181 void draw( const PCB_TEXT* aText, int aLayer );
182 void draw( const PCB_TEXTBOX* aText, int aLayer );
183 void draw( const FP_TEXT* aText, int aLayer );
184 void draw( const FP_TEXTBOX* aText, int aLayer );
185 void draw( const FOOTPRINT* aFootprint, int aLayer );
186 void draw( const PCB_GROUP* aGroup, int aLayer );
187 void draw( const ZONE* aZone, int aLayer );
188 void draw( const PCB_DIMENSION_BASE* aDimension, int aLayer );
189 void draw( const PCB_TARGET* aTarget );
190 void draw( const PCB_MARKER* aMarker, int aLayer );
191
198 int getLineThickness( int aActualThickness ) const;
199
203 virtual int getDrillShape( const PAD* aPad ) const;
204
208 virtual SHAPE_SEGMENT getPadHoleShape( const PAD* aPad ) const;
209
213 virtual int getViaDrillSize( const PCB_VIA* aVia ) const;
214
215 void strokeText( const wxString& aText, const VECTOR2I& aPosition,
216 const TEXT_ATTRIBUTES& aAttrs );
217
218protected:
221
225};
226} // namespace KIGFX
227
228#endif /* PCB_PAINTER_H */
HIGH_CONTRAST_MODE
Determine how inactive layers should be displayed.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:70
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
Color settings are a bit different than most of the settings objects in that there can be more than o...
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:85
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
Definition: color4d.h:349
Abstract interface for drawing on a 2D-surface.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:58
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:158
virtual SHAPE_SEGMENT getPadHoleShape(const PAD *aPad) const
Return hole shape for a pad (internal units).
PCB_PAINTER(GAL *aGal, FRAME_T aFrameType)
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
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:163
PCB_VIEWERS_SETTINGS_BASE * viewer_settings()
Definition: pcb_painter.cpp:80
void draw(const PCB_TRACK *aTrack, int aLayer)
void strokeText(const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs)
virtual int getDrillShape(const PAD *aPad) const
Return drill shape of a pad.
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:219
virtual int getViaDrillSize(const PCB_VIA *aVia) const
Return drill diameter for a via (internal units).
virtual bool Draw(const VIEW_ITEM *aItem, int aLayer) override
Takes an instance of VIEW_ITEM and passes it to a function that knows how to draw the item.
PCB specific render settings.
Definition: pcb_painter.h:72
void SetNetColorMode(NET_COLOR_MODE aMode)
Definition: pcb_painter.h:112
double m_zoneOpacity
Opacity override for filled zones.
Definition: pcb_painter.h:149
double m_trackOpacity
Opacity override for all tracks.
Definition: pcb_painter.h:146
const std::set< int > & GetHiddenNets() const
Definition: pcb_painter.h:119
double m_imageOpacity
Opacity override for user images.
Definition: pcb_painter.h:150
bool IsBackgroundDark() const override
Definition: pcb_painter.h:93
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:118
const COLOR4D & GetCursorColor() override
Return current cursor color settings.
Definition: pcb_painter.h:109
double m_viaOpacity
Opacity override for all types of via.
Definition: pcb_painter.h:147
ZONE_DISPLAY_MODE m_ZoneDisplayMode
Definition: pcb_painter.h:124
const COLOR4D & GetBackgroundColor() const override
Return current background color settings.
Definition: pcb_painter.h:100
NET_COLOR_MODE GetNetColorMode() const
Definition: pcb_painter.h:111
void LoadColors(const COLOR_SETTINGS *aSettings) override
double m_padOpacity
Opacity override for SMD pads and PTHs.
Definition: pcb_painter.h:148
const COLOR4D & GetGridColor() override
Return current grid color settings.
Definition: pcb_painter.h:107
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
Definition: pcb_painter.h:102
COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
std::set< int > m_hiddenNets
Definition: pcb_painter.h:143
HIGH_CONTRAST_MODE m_ContrastModeDisplay
Definition: pcb_painter.h:125
std::map< int, KIGFX::COLOR4D > m_netColors
Set of net codes that should not have their ratsnest displayed.
Definition: pcb_painter.h:140
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:116
NET_COLOR_MODE m_netColorMode
Overrides for specific netclass colors.
Definition: pcb_painter.h:134
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:114
static const double MAX_FONT_SIZE
< Maximum font size for netnames (and other dynamically shown strings)
Definition: pcb_painter.h:131
std::map< wxString, KIGFX::COLOR4D > m_netclassColors
Overrides for specific net colors, stored as netcodes for the ratsnest to access easily.
Definition: pcb_painter.h:137
bool GetShowPageLimits() const override
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Load settings related to display options (high-contrast mode, full or outline modes for vias/pads/tra...
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
COLOR4D m_layerColors[LAYER_ID_COUNT]
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:77
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:333
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:34
Definition: pad.h:59
Object to handle a bitmap image that can be inserted in a PCB.
Definition: pcb_bitmap.h:42
Abstract dimension API.
Definition: pcb_dimension.h:96
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:51
Handle a list of polygons defining a copper zone.
Definition: zone.h:57
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition: frame_type.h:33
@ LAYER_GRID
Definition: layer_ids.h:205
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:220
@ LAYER_CURSOR
PCB cursor.
Definition: layer_ids.h:221
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266