KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 The 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 <gal/painter.h>
33#include <padstack.h> // PAD_DRILL_SHAPE
34#include <pcb_display_options.h>
35#include <math/vector2d.h>
36#include <memory>
38
39
40class EDA_ITEM;
43class BOARD_ITEM;
44class PCB_ARC;
45class BOARD;
46class PCB_VIA;
47class PCB_TRACK;
48class PAD;
49class PCB_SHAPE;
50class PCB_GROUP;
51class FOOTPRINT;
52class ZONE;
54class PCB_TEXT;
55class PCB_FIELD;
56class PCB_TEXTBOX;
57class PCB_TABLE;
59class PCB_TARGET;
60class PCB_POINT;
61class PCB_MARKER;
62class NET_SETTINGS;
63class NETINFO_LIST;
64class TEXT_ATTRIBUTES;
66
67namespace KIFONT
68{
69class FONT;
70class METRICS;
71}
72
73namespace KIGFX
74{
75class GAL;
76
81{
82public:
83 friend class PCB_PAINTER;
84
86
93 void LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions );
94
95 void LoadColors( const COLOR_SETTINGS* aSettings ) override;
96
98 COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
99
101 COLOR4D GetColor( const BOARD_ITEM* aItem, int aLayer ) const;
102
104 COLOR4D GetColor( std::nullptr_t, int aLayer ) const
105 {
106 return GetColor( static_cast<const BOARD_ITEM*>( nullptr ), aLayer );
107 }
108
109 bool GetShowPageLimits() const override;
110
111 inline bool IsBackgroundDark() const override
112 {
113 auto it = m_layerColors.find( LAYER_PCB_BACKGROUND );
114
115 if( it == m_layerColors.end() )
116 return false;
117
118 return it->second.GetBrightness() < 0.5;
119 }
120
121 const COLOR4D& GetBackgroundColor() const override
122 {
123 auto it = m_layerColors.find( LAYER_PCB_BACKGROUND );
124 return it == m_layerColors.end() ? COLOR4D::BLACK : it->second;
125 }
126
127 void SetBackgroundColor( const COLOR4D& aColor ) override
128 {
130 }
131
132 const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GRID ]; }
133
134 const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
135
138
139 std::map<int, KIGFX::COLOR4D>& GetNetColorMap() { return m_netColors; }
140
141 std::set<int>& GetHiddenNets() { return m_hiddenNets; }
142 const std::set<int>& GetHiddenNets() const { return m_hiddenNets; }
143
144public:
147
150
151 PAD* m_PadEditModePad; // Pad currently in Pad Edit Mode (if any)
152
153protected:
155 static const double MAX_FONT_SIZE;
156
159
161 std::map<wxString, KIGFX::COLOR4D> m_netclassColors;
162
164 std::map<int, KIGFX::COLOR4D> m_netColors;
165
167 std::set<int> m_hiddenNets;
168
169 // These opacity overrides multiply with any opacity in the base layer color
176};
177
178
182class PCB_PAINTER : public PAINTER
183{
184public:
185 PCB_PAINTER( GAL* aGal, FRAME_T aFrameType );
186
189 {
190 return &m_pcbSettings;
191 }
192
194 virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
195
196protected:
198
199 // Drawing functions for various types of PCB-specific items
200 void draw( const PCB_TRACK* aTrack, int aLayer );
201 void draw( const PCB_ARC* aArc, int aLayer );
202 void draw( const PCB_VIA* aVia, int aLayer );
203 void draw( const PAD* aPad, int aLayer );
204 void draw( const PCB_SHAPE* aSegment, int aLayer );
205 void draw( const PCB_REFERENCE_IMAGE* aBitmap, int aLayer );
206 void draw( const PCB_FIELD* aField, int aLayer );
207 void draw( const PCB_TEXT* aText, int aLayer );
208 void draw( const PCB_TEXTBOX* aText, int aLayer );
209 void draw( const PCB_TABLE* aTable, int aLayer );
210 void draw( const FOOTPRINT* aFootprint, int aLayer );
211 void draw( const PCB_GROUP* aGroup, int aLayer );
212 void draw( const ZONE* aZone, int aLayer );
213 void draw( const PCB_DIMENSION_BASE* aDimension, int aLayer );
214 void draw( const PCB_POINT* aPoint, int aLayer );
215 void draw( const PCB_TARGET* aTarget );
216 void draw( const PCB_MARKER* aMarker, int aLayer );
217 void draw( const PCB_BOARD_OUTLINE* aBoardOutline, int aLayer );
218
225 int getLineThickness( int aActualThickness ) const;
226
230 virtual PAD_DRILL_SHAPE getDrillShape( const PAD* aPad ) const;
231
235 virtual SHAPE_SEGMENT getPadHoleShape( const PAD* aPad ) const;
236
240 virtual int getViaDrillSize( const PCB_VIA* aVia ) const;
241
242 void strokeText( const wxString& aText, const VECTOR2I& aPosition,
243 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics );
244
245 void renderNetNameForSegment( const SHAPE_SEGMENT& aSeg, const COLOR4D& aColor, const wxString& aNetName ) const;
246
247protected:
250
254};
255} // namespace KIGFX
256
257#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:79
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:317
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:98
FONT is an abstract base class for both outline and stroke fonts.
Definition font.h:131
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:104
static const COLOR4D BLACK
Definition color4d.h:402
Abstract interface for drawing on a 2D-surface.
PAINTER(GAL *aGal)
Initialize this object for painting on any of the polymorphic GRAPHICS_ABSTRACTION_LAYER* derivatives...
Definition painter.cpp:33
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.
void renderNetNameForSegment(const SHAPE_SEGMENT &aSeg, const COLOR4D &aColor, const wxString &aNetName) const
PCB_VIEWERS_SETTINGS_BASE * viewer_settings()
void draw(const PCB_TRACK *aTrack, int aLayer)
virtual PAD_DRILL_SHAPE getDrillShape(const PAD *aPad) const
Return drill shape of a pad.
PCB_RENDER_SETTINGS m_pcbSettings
virtual int getViaDrillSize(const PCB_VIA *aVia) const
Return drill diameter for a via (internal units).
void strokeText(const wxString &aText, const VECTOR2I &aPosition, const TEXT_ATTRIBUTES &aAttrs, const KIFONT::METRICS &aFontMetrics)
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:81
void SetNetColorMode(NET_COLOR_MODE aMode)
double m_zoneOpacity
Opacity override for filled zones.
double m_trackOpacity
Opacity override for all tracks.
const std::set< int > & GetHiddenNets() const
double m_imageOpacity
Opacity override for user images.
bool IsBackgroundDark() const override
std::set< int > & GetHiddenNets()
const COLOR4D & GetCursorColor() override
Return current cursor color settings.
double m_viaOpacity
Opacity override for all types of via.
ZONE_DISPLAY_MODE m_ZoneDisplayMode
const COLOR4D & GetBackgroundColor() const override
Return current background color settings.
NET_COLOR_MODE GetNetColorMode() const
void LoadColors(const COLOR_SETTINGS *aSettings) override
double m_padOpacity
Opacity override for SMD pads and PTHs.
const COLOR4D & GetGridColor() override
Return current grid color settings.
COLOR4D GetColor(std::nullptr_t, int aLayer) const
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
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
HIGH_CONTRAST_MODE m_ContrastModeDisplay
std::map< int, KIGFX::COLOR4D > m_netColors
Set of net codes that should not have their ratsnest displayed.
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
NET_COLOR_MODE m_netColorMode
Overrides for specific netclass colors.
static const double MAX_FONT_SIZE
< Maximum font size for netnames (and other dynamically shown strings)
double m_filledShapeOpacity
Opacity override for graphic shapes.
std::map< wxString, KIGFX::COLOR4D > m_netclassColors
Overrides for specific net colors, stored as netcodes for the ratsnest to access easily.
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...
std::map< int, COLOR4D > m_layerColors
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:86
Container for NETINFO_ITEM elements, which are the nets.
Definition netinfo.h:330
NET_SETTINGS stores various net-related settings in a project context.
Definition pad.h:54
Abstract dimension API.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:53
A PCB_POINT is a 0-dimensional point that is used to mark a position on a PCB, or more usually a foot...
Definition pcb_point.h:43
Object to handle a bitmap image that can be inserted in a PCB.
Handle a list of polygons defining a copper zone.
Definition zone.h:74
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:253
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition layer_ids.h:280
@ LAYER_CURSOR
PCB cursor.
Definition layer_ids.h:281
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:33
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition padstack.h:69
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695