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, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef PCB_PAINTER_H
25#define PCB_PAINTER_H
26
27#include <frame_type.h>
28#include <gal/definitions.h>
29#include <gal/painter.h>
30#include <kiid.h>
31#include <padstack.h> // PAD_DRILL_SHAPE
32#include <pcb_display_options.h>
33#include <math/vector2d.h>
34#include <bitset>
35#include <memory>
36#include <set>
37#include <unordered_set>
39
40
41class EDA_ITEM;
43class PCBNEW_SETTINGS;
45class BOARD_ITEM;
46class PCB_ARC;
47class BOARD;
48class PCB_VIA;
49class PCB_TRACK;
50class PAD;
51class PCB_SHAPE;
52class PCB_GROUP;
53class FOOTPRINT;
54class ZONE;
56class PCB_TEXT;
57class PCB_FIELD;
58class PCB_TEXTBOX;
59class PCB_DRILL_CHART;
60class PCB_DRILL_MAP;
61class PCB_TABLE;
63class PCB_BARCODE;
64class PCB_TARGET;
65class PCB_POINT;
66class PCB_MARKER;
67class NET_SETTINGS;
68class NETINFO_LIST;
69class TEXT_ATTRIBUTES;
71class PCB_GRID_ITEM;
73
78
79
80namespace KIFONT
81{
82class FONT;
83class METRICS;
84}
85
86namespace KIGFX
87{
88class GAL;
89
94{
95public:
96 friend class PCB_PAINTER;
97
99
106 void LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions );
107
108 void LoadColors( const COLOR_SETTINGS* aSettings ) override;
109
111 COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
112
114 COLOR4D GetColor( const BOARD_ITEM* aItem, int aLayer ) const;
115
117 COLOR4D GetColor( std::nullptr_t, int aLayer ) const
118 {
119 return GetColor( static_cast<const BOARD_ITEM*>( nullptr ), aLayer );
120 }
121
126 void SetCanvasFadedLayers( const std::bitset<MAX_LAYERS_FOR_VIEW>& aLayers ) { m_canvasFadedLayers = aLayers; }
127
128 bool IsCanvasFadedLayer( int aLayer ) const;
129
130 bool HasCanvasFadedLayers() const { return m_canvasFadedLayers.any(); }
131
135 bool GetLayerDim( int aLayer, COLOR4D& aToward, double& aKeep ) const override;
136
140 bool IsDimExempt( const VIEW_ITEM* aItem ) const override;
141
142 bool GetShowPageLimits() const override;
143
144 inline bool IsBackgroundDark() const override
145 {
146 auto it = m_layerColors.find( LAYER_PCB_BACKGROUND );
147
148 if( it == m_layerColors.end() )
149 return false;
150
151 return it->second.GetBrightness() < 0.5;
152 }
153
154 const COLOR4D& GetBackgroundColor() const override
155 {
156 auto it = m_layerColors.find( LAYER_PCB_BACKGROUND );
157 return it == m_layerColors.end() ? COLOR4D::BLACK : it->second;
158 }
159
160 void SetBackgroundColor( const COLOR4D& aColor ) override
161 {
163 }
164
165 const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GRID ]; }
166
167 const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
168
171
172 std::map<int, KIGFX::COLOR4D>& GetNetColorMap() { return m_netColors; }
173
174 std::set<int>& GetHiddenNets() { return m_hiddenNets; }
175 const std::set<int>& GetHiddenNets() const { return m_hiddenNets; }
176
177 // Net chain highlight support (grouped nets). Empty when no chain highlight active.
178 const wxString& GetHighlightedNetChain() const { return m_highlightedNetChain; }
179 void SetHighlightedNetChain( const wxString& aNetChain ) { m_highlightedNetChain = aNetChain; }
180
181 // Items referenced by geometric constraint shadow layer draws only for these
182 // refreshed each board-wide diagnosis
183 const std::unordered_set<KIID>& GetConstrainedItems() const { return m_constrainedItems; }
184 void SetConstrainedItems( std::unordered_set<KIID> aItems ) { m_constrainedItems = std::move( aItems ); }
185
186 // Members of badge-selected constraint shadows drawn brighter and thicker
187 const std::unordered_set<KIID>& GetHighlightedConstraintMembers() const
188 {
190 }
191
192 void SetHighlightedConstraintMembers( std::unordered_set<KIID> aItems )
193 {
194 m_highlightedConstraintMembers = std::move( aItems );
195 }
196
197public:
200
203
204 PAD* m_PadEditModePad; // Pad currently in Pad Edit Mode (if any)
205
206protected:
208 static const double MAX_FONT_SIZE;
209
212
214 std::map<wxString, KIGFX::COLOR4D> m_netclassColors;
215
217 std::map<int, KIGFX::COLOR4D> m_netColors;
218
220 std::set<int> m_hiddenNets;
221
222 // These opacity overrides multiply with any opacity in the base layer color
229
231
233 std::unordered_set<KIID> m_constrainedItems;
234
236 std::unordered_set<KIID> m_highlightedConstraintMembers;
237
239 std::bitset<MAX_LAYERS_FOR_VIEW> m_canvasFadedLayers;
240};
241
242
246class PCB_PAINTER : public PAINTER
247{
248public:
249 PCB_PAINTER( GAL* aGal, FRAME_T aFrameType );
250
252 {
253 return &m_pcbSettings;
254 }
255
256 virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
257
258 virtual bool HasUniformColor( const VIEW_ITEM* aItem, int aLayer ) const override;
259
260protected:
262
266 bool zoneOutlineOnly( const ZONE* aZone ) const;
267
268 // Drawing functions for various types of PCB-specific items
269 void draw( const PCB_TRACK* aTrack, int aLayer );
270 void draw( const PCB_ARC* aArc, int aLayer );
271 void draw( const PCB_VIA* aVia, int aLayer );
272 void draw( const PAD* aPad, int aLayer );
273
274 void drawDrillSymbol( const BOARD_ITEM* aItem, int aLayer );
275
280 void drawDrillMarks( const PCB_DRILL_MAP* aMap, const std::vector<DRILL_SYMBOL_ENTRY>& aEntries,
281 const COLOR4D& aColor, const KIFONT::METRICS& aFontMetrics );
282
283 void draw( const PCB_DRILL_MAP* aMap, int aLayer );
284
285 void drawChartSymbols( const PCB_DRILL_CHART* aChart, int aLayer );
286 void draw( const PCB_SHAPE* aSegment, int aLayer );
287 void draw( const PCB_REFERENCE_IMAGE* aBitmap, int aLayer );
288 void draw( const PCB_FIELD* aField, int aLayer );
289 void draw( const PCB_TEXT* aText, int aLayer );
290 void draw( const PCB_TEXTBOX* aText, int aLayer );
291 void draw( const PCB_TABLE* aTable, int aLayer );
292 void draw( const FOOTPRINT* aFootprint, int aLayer );
293 void draw( const PCB_GROUP* aGroup, int aLayer );
294 void draw( const ZONE* aZone, int aLayer );
295 void draw( const PCB_BARCODE* aBarcode, int aLayer );
296 void draw( const PCB_DIMENSION_BASE* aDimension, int aLayer );
297 void draw( const PCB_POINT* aPoint, int aLayer );
298 void draw( const PCB_TARGET* aTarget );
299 void draw( const PCB_MARKER* aMarker, int aLayer );
300 void draw( const PCB_BOARD_OUTLINE* aBoardOutline, int aLayer );
301 void draw( const PCB_GRID_ITEM* aGridItem, int aLayer );
302
309 int getLineThickness( int aActualThickness ) const;
310
314 virtual PAD_DRILL_SHAPE getDrillShape( const PAD* aPad ) const;
315
319 virtual SHAPE_SEGMENT getPadHoleShape( const PAD* aPad ) const;
320
324 virtual int getViaDrillSize( const PCB_VIA* aVia ) const;
325
326 void strokeText( const wxString& aText, const VECTOR2I& aPosition,
327 const TEXT_ATTRIBUTES& aAttrs, const KIFONT::METRICS& aFontMetrics );
328
329 void renderNetNameForSegment( const SHAPE_SEGMENT& aSeg, const COLOR4D& aColor, const wxString& aNetName ) const;
330
340 void drawBackdrillIndicator( const BOARD_ITEM* aItem, const VECTOR2D& aCenter,
341 int aDrillSize, PCB_LAYER_ID aStartLayer,
342 PCB_LAYER_ID aEndLayer );
343
351 void drawPostMachiningIndicator( const BOARD_ITEM* aItem, const VECTOR2D& aCenter, PCB_LAYER_ID aLayer );
352
353protected:
356
360};
361
362
370bool ZoneOutlineDrawnOnLayer( bool aOutlineOnly, int aLayer );
371
372} // namespace KIGFX
373
374#endif /* PCB_PAINTER_H */
HIGH_CONTRAST_MODE
Determine how inactive layers should be displayed.
NET_COLOR_MODE
Determine how net color overrides should be applied.
ZONE_DISPLAY_MODE
Determine how zones 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:85
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
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:94
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
static const COLOR4D BLACK
Definition color4d.h:404
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:29
void drawPostMachiningIndicator(const BOARD_ITEM *aItem, const VECTOR2D &aCenter, PCB_LAYER_ID aLayer)
Draw post-machining indicator (dashed circle) at the given center point.
virtual SHAPE_SEGMENT getPadHoleShape(const PAD *aPad) const
Return hole shape for a pad (internal units).
void drawChartSymbols(const PCB_DRILL_CHART *aChart, int aLayer)
PCB_PAINTER(GAL *aGal, FRAME_T aFrameType)
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
void drawDrillSymbol(const BOARD_ITEM *aItem, int aLayer)
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
virtual bool HasUniformColor(const VIEW_ITEM *aItem, int aLayer) const override
Return false when drawing the item on the given layer emits more than one colour, so a cached group o...
void renderNetNameForSegment(const SHAPE_SEGMENT &aSeg, const COLOR4D &aColor, const wxString &aNetName) const
bool zoneOutlineOnly(const ZONE *aZone) const
True when a zone's only visual is its outline, as for a rule area or outline-only display.
PCB_VIEWERS_SETTINGS_BASE * viewer_settings()
void draw(const PCB_TRACK *aTrack, int aLayer)
void drawDrillMarks(const PCB_DRILL_MAP *aMap, const std::vector< DRILL_SYMBOL_ENTRY > &aEntries, const COLOR4D &aColor, const KIFONT::METRICS &aFontMetrics)
One hole's marks for one map.
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)
void drawBackdrillIndicator(const BOARD_ITEM *aItem, const VECTOR2D &aCenter, int aDrillSize, PCB_LAYER_ID aStartLayer, PCB_LAYER_ID aEndLayer)
Draw backdrill indicator (two semi-circles) at the given center point.
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:94
void SetHighlightedConstraintMembers(std::unordered_set< KIID > aItems)
void SetNetColorMode(NET_COLOR_MODE aMode)
double m_zoneOpacity
Opacity override for filled zones.
double m_trackOpacity
Opacity override for all tracks.
void SetHighlightedNetChain(const wxString &aNetChain)
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.
std::unordered_set< KIID > m_highlightedConstraintMembers
Selected constraint members shadow highlighted.
COLOR4D GetColor(std::nullptr_t, int aLayer) const
nullptr version
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
const wxString & GetHighlightedNetChain() const
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
Set of net codes that should not have their ratsnest displayed.
void SetCanvasFadedLayers(const std::bitset< MAX_LAYERS_FOR_VIEW > &aLayers)
Let the canvas fade these VIEW layers as a whole for high contrast, see GAL::SetSceneLayerDim().
HIGH_CONTRAST_MODE m_ContrastModeDisplay
std::unordered_set< KIID > m_constrainedItems
Gates the constraint-shadow draw.
void SetConstrainedItems(std::unordered_set< KIID > aItems)
std::map< int, KIGFX::COLOR4D > m_netColors
Overrides for specific net colors, stored as netcodes for the ratsnest to access easily.
const std::unordered_set< KIID > & GetHighlightedConstraintMembers() const
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
wxString m_highlightedNetChain
Active highlighted chain name (if any)
NET_COLOR_MODE m_netColorMode
How to display nets and netclasses with color overrides.
const std::unordered_set< KIID > & GetConstrainedItems() const
static const double MAX_FONT_SIZE
Maximum font size for netnames (and other dynamically shown strings)
double m_filledShapeOpacity
Opacity override for graphic shapes.
bool IsDimExempt(const VIEW_ITEM *aItem) const override
Return true for an item that keeps its colour on a layer the canvas fades, such as a selected item in...
std::map< wxString, KIGFX::COLOR4D > m_netclassColors
Overrides for specific netclass colors.
bool GetShowPageLimits() const override
std::bitset< MAX_LAYERS_FOR_VIEW > m_canvasFadedLayers
Layers the canvas fades for high contrast, see SetCanvasFadedLayers()
bool HasCanvasFadedLayers() const
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions)
Load settings related to display options (high-contrast mode, full or outline modes for vias/pads/tra...
bool GetLayerDim(int aLayer, COLOR4D &aToward, double &aKeep) const override
Get how the canvas fades a whole layer, see GAL::SetSceneLayerDim().
bool IsCanvasFadedLayer(int aLayer) const
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:82
Container for NETINFO_ITEM elements, which are the nets.
Definition netinfo.h:232
NET_SETTINGS stores various net-related settings in a project context.
Definition pad.h:61
Abstract dimension API.
A drill chart placed on the board, kept in step with the holes.
Turns on drill symbols at the holes, for one layer.
A set of BOARD_ITEMs (i.e., without duplicates).
Definition pcb_group.h:51
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:39
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:70
FRAME_T
The set of EDA_BASE_FRAME derivatives, typically stored in EDA_BASE_FRAME::m_Ident.
Definition frame_type.h:29
@ LAYER_GRID
Definition layer_ids.h:250
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition layer_ids.h:277
@ LAYER_CURSOR
PCB cursor.
Definition layer_ids.h:278
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30
bool ZoneOutlineDrawnOnLayer(bool aOutlineOnly, int aLayer)
Decide which GAL draw pass paints a zone's outline.
PAD_DRILL_SHAPE
The set of pad drill shapes, used with PAD::{Set,Get}DrillShape()
Definition padstack.h:68
PCBNEW_SETTINGS * pcbconfig()
One drawable mark, with the geometry the renderer needs to place it.
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707