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-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
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 <painter.h>
32 #include <pcb_display_options.h>
33 #include <math/vector2d.h>
34 #include <memory>
35 
36 
37 class EDA_ITEM;
39 class BOARD_ITEM;
40 class PCB_ARC;
41 class BOARD;
42 class PCB_VIA;
43 class PCB_TRACK;
44 class PAD;
45 class PCB_SHAPE;
46 class PCB_GROUP;
47 class FOOTPRINT;
48 class ZONE;
49 class PCB_TEXT;
50 class FP_TEXT;
51 class PCB_DIMENSION_BASE;
52 class PCB_TARGET;
53 class PCB_MARKER;
54 class NET_SETTINGS;
55 class NETINFO_LIST;
56 
57 namespace KIGFX
58 {
59 class GAL;
60 
65 {
66 public:
67  friend class PCB_PAINTER;
68 
71  {
72  CL_NONE = 0x00,
73 
74  // Object type
75  CL_PADS = 0x01,
76  CL_VIAS = 0x02,
77  CL_TRACKS = 0x04,
78 
79  // Existence
80  CL_NEW = 0x08,
81  CL_EDITED = 0x10,
82  CL_EXISTING = 0x20
83  };
84 
86 
93  void LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aShowPageLimits );
94 
95  virtual void LoadColors( const COLOR_SETTINGS* aSettings ) override;
96 
98  virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
99 
107  inline void SetSketchMode( int aItemLayer, bool aEnabled )
108  {
109  m_sketchMode[aItemLayer] = aEnabled;
110  }
111 
117  inline bool GetSketchMode( int aItemLayer ) const
118  {
119  return m_sketchMode[aItemLayer];
120  }
121 
128  inline void SetSketchModeGraphicItems( bool aEnabled )
129  {
130  m_sketchGraphics = aEnabled;
131  }
132 
136  void EnableZoneOutlines( bool aEnabled )
137  {
138  m_zoneOutlines = aEnabled;
139  }
140 
141  inline bool IsBackgroundDark() const override
142  {
144 
145  return luma < 0.5;
146  }
147 
149 
150  void SetBackgroundColor( const COLOR4D& aColor ) override
151  {
153  }
154 
155  const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GRID ]; }
156 
157  const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
158 
164 
169 
170  inline bool GetCurvedRatsnestLinesEnabled() const { return m_curvedRatsnestlines; }
171 
172  inline bool GetGlobalRatsnestLinesEnabled() const { return m_globalRatsnestlines; }
173 
176 
178  void SetNetColorMode( NET_COLOR_MODE aMode ) { m_netColorMode = aMode; }
179 
182 
183  std::map<wxString, KIGFX::COLOR4D>& GetNetclassColorMap() { return m_netclassColors; }
184 
185  std::map<int, KIGFX::COLOR4D>& GetNetColorMap() { return m_netColors; }
186 
187  std::set<int>& GetHiddenNets() { return m_hiddenNets; }
188  const std::set<int>& GetHiddenNets() const { return m_hiddenNets; }
189 
191 
192 protected:
194  static const double MAX_FONT_SIZE;
195 
199 
204 
206 
209 
211 
215 
217 
220 
222  std::map<wxString, KIGFX::COLOR4D> m_netclassColors;
223 
225  std::map<int, KIGFX::COLOR4D> m_netColors;
226 
228  std::set<int> m_hiddenNets;
229 
230  // These opacity overrides multiply with any opacity in the base layer color
231  double m_trackOpacity;
232  double m_viaOpacity;
233  double m_padOpacity;
234  double m_zoneOpacity;
235 };
236 
237 
241 class PCB_PAINTER : public PAINTER
242 {
243 public:
244  PCB_PAINTER( GAL* aGal );
245 
247  virtual PCB_RENDER_SETTINGS* GetSettings() override
248  {
249  return &m_pcbSettings;
250  }
251 
253  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
254 
255 protected:
256  // Drawing functions for various types of PCB-specific items
257  void draw( const PCB_TRACK* aTrack, int aLayer );
258  void draw( const PCB_ARC* aArc, int aLayer );
259  void draw( const PCB_VIA* aVia, int aLayer );
260  void draw( const PAD* aPad, int aLayer );
261  void draw( const PCB_SHAPE* aSegment, int aLayer );
262  void draw( const PCB_TEXT* aText, int aLayer );
263  void draw( const FP_TEXT* aText, int aLayer );
264  void draw( const FOOTPRINT* aFootprint, int aLayer );
265  void draw( const PCB_GROUP* aGroup, int aLayer );
266  void draw( const ZONE* aZone, int aLayer );
267  void draw( const PCB_DIMENSION_BASE* aDimension, int aLayer );
268  void draw( const PCB_TARGET* aTarget );
269  void draw( const PCB_MARKER* aMarker, int aLayer );
270 
277  int getLineThickness( int aActualThickness ) const;
278 
282  virtual int getDrillShape( const PAD* aPad ) const;
283 
287  virtual VECTOR2D getDrillSize( const PAD* aPad ) const;
288 
292  virtual int getDrillSize( const PCB_VIA* aVia ) const;
293 
294 protected:
296 
299 };
300 } // namespace KIGFX
301 
302 #endif /* PCB_PAINTER_H */
bool GetGlobalRatsnestLinesEnabled() const
Definition: pcb_painter.h:172
void SetRatsnestDisplayMode(RATSNEST_MODE aMode)
Definition: pcb_painter.h:181
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:187
virtual void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: pcb_painter.cpp:90
double GetBrightness() const
Returns the brightness value of the color ranged from 0.0 to 1.0.
Definition: color4d.h:330
const COLOR4D & GetCursorColor() override
Return current cursor color settings.
Definition: pcb_painter.h:157
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
void SetContrastModeDisplay(HIGH_CONTRAST_MODE aMode)
Switch the contrast mode setting (HIGH_CONTRAST_MODE:NORMAL, DIMMED or HIDDEN ) to control how the no...
Definition: pcb_painter.h:163
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition: board_item.h:80
double m_zoneOpacity
Opacity override for filled zones.
Definition: pcb_painter.h:234
COLOR4D m_layerColors[LAYER_ID_COUNT]
PCB cursor.
Definition: layer_ids.h:216
void SetNetColorMode(NET_COLOR_MODE aMode)
Definition: pcb_painter.h:178
A set of BOARD_ITEMs (i.e., without duplicates).
Definition: pcb_group.h:50
bool m_sketchMode[GAL_LAYER_ID_END]
Definition: pcb_painter.h:196
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:183
void EnableZoneOutlines(bool aEnabled)
Turn on/off drawing outline and hatched lines for zones.
Definition: pcb_painter.h:136
Abstract dimension API.
Definition: pcb_dimension.h:95
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
bool GetSketchMode(int aItemLayer) const
Return sketch mode setting for a given item layer.
Definition: pcb_painter.h:117
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:81
RATSNEST_MODE GetRatsnestDisplayMode() const
Definition: pcb_painter.h:180
Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:241
NET_COLOR_MODE GetNetColorMode() const
Definition: pcb_painter.h:177
void SetSketchModeGraphicItems(bool aEnabled)
Turn on/off sketch mode for graphic items (DRAWSEGMENTs, texts).
Definition: pcb_painter.h:128
HIGH_CONTRAST_MODE GetContrastModeDisplay()
Definition: pcb_painter.h:168
virtual VECTOR2D getDrillSize(const PAD *aPad) const
Return drill size for a pad (internal units).
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:222
NET_COLOR_MODE m_netColorMode
Overrides for specific netclass colors.
Definition: pcb_painter.h:219
PCB specific render settings.
Definition: pcb_painter.h:64
Container for display options like enable/disable some optional drawings.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:57
bool IsBackgroundDark() const override
Definition: pcb_painter.h:141
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
bool GetDrawIndividualViaLayers() const
Definition: pcb_painter.h:174
static const double MAX_FONT_SIZE
< Maximum font size for netnames (and other dynamically shown strings)
Definition: pcb_painter.h:194
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:247
bool GetCurvedRatsnestLinesEnabled() const
Definition: pcb_painter.h:170
Container for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:315
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
Definition: pcb_painter.h:150
const std::set< int > & GetHiddenNets() const
Definition: pcb_painter.h:188
HIGH_CONTRAST_MODE
Determine how inactive layers should be displayed.
RATSNEST_MODE m_ratsnestDisplayMode
Definition: pcb_painter.h:214
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:32
Handle a list of polygons defining a copper zone.
Definition: zone.h:56
double m_viaOpacity
Opacity override for all types of via.
Definition: pcb_painter.h:232
void SetDrawIndividualViaLayers(bool aFlag)
Definition: pcb_painter.h:175
int m_clearanceDisplayFlags
How to display nets and netclasses with color overrides.
Definition: pcb_painter.h:216
double m_trackOpacity
Opacity override for all tracks.
Definition: pcb_painter.h:231
std::map< int, KIGFX::COLOR4D > m_netColors
Set of net codes that should not have their ratsnest displayed.
Definition: pcb_painter.h:225
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:190
void SetSketchMode(int aItemLayer, bool aEnabled)
Turn on/off sketch mode for given item layer.
Definition: pcb_painter.h:107
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aShowPageLimits)
Load settings related to display options (high-contrast mode, full or outline modes for vias/pads/tra...
virtual 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...
const COLOR4D & GetBackgroundColor() override
Return current background color settings.
Definition: pcb_painter.h:148
const COLOR4D & GetGridColor() override
Return current grid color settings.
Definition: pcb_painter.h:155
HIGH_CONTRAST_MODE m_contrastModeDisplay
Definition: pcb_painter.h:213
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
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 background color.
Definition: layer_ids.h:215
PCB_PAINTER(GAL *aGal)
Color settings are a bit different than most of the settings objects in that there can be more than o...
double m_padOpacity
Opacity override for SMD pads and PTHs.
Definition: pcb_painter.h:233
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:185
Definition: pad.h:57
virtual int getDrillShape(const PAD *aPad) const
Return drill shape of a pad.
void SetZoneDisplayMode(ZONE_DISPLAY_MODE mode)
Definition: pcb_painter.h:190
Definition of PCB_DISPLAY_OPTIONS class.
ZONE_DISPLAY_MODE m_zoneDisplayMode
Definition: pcb_painter.h:212
void draw(const PCB_TRACK *aTrack, int aLayer)
std::set< int > m_hiddenNets
Definition: pcb_painter.h:228
Abstract interface for drawing on a 2D-surface.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103