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 KiCad Developers, see AUTHORS.txt for contributors.
6  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
22  * or you may search the http://www.gnu.org website for the version 2 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef __CLASS_PCB_PAINTER_H
28 #define __CLASS_PCB_PAINTER_H
29 
30 #include <painter.h>
31 #include <pcb_display_options.h>
32 #include <math/vector2d.h>
33 #include <memory>
34 
35 
36 class EDA_ITEM;
38 class BOARD_ITEM;
39 class ARC;
40 class BOARD;
41 class VIA;
42 class TRACK;
43 class D_PAD;
44 class PCB_SHAPE;
45 class PCB_GROUP;
46 class MODULE;
47 class ZONE_CONTAINER;
48 class PCB_TEXT;
49 class FP_TEXT;
50 class DIMENSION;
51 class PCB_TARGET;
52 class MARKER_PCB;
53 class NET_SETTINGS;
54 class NETINFO_LIST;
55 
56 namespace KIGFX
57 {
58 class GAL;
59 
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 
127  inline void SetSketchModeGraphicItems( bool aEnabled )
128  {
129  m_sketchGraphics = aEnabled;
130  }
131 
135  void EnableZoneOutlines( bool aEnabled )
136  {
137  m_zoneOutlines = aEnabled;
138  }
139 
140  inline bool IsBackgroundDark() const override
141  {
143 
144  return luma < 0.5;
145  }
146 
148 
149  void SetBackgroundColor( const COLOR4D& aColor ) override
150  {
152  }
153 
154  const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GRID ]; }
155 
156  const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
157 
162 
166 
167  inline bool GetCurvedRatsnestLinesEnabled() const { return m_curvedRatsnestlines; }
168 
169  inline bool GetGlobalRatsnestLinesEnabled() const { return m_globalRatsnestlines; }
170 
173 
175  void SetNetColorMode( NET_COLOR_MODE aMode ) { m_netColorMode = aMode; }
176 
179 
180  std::map<wxString, KIGFX::COLOR4D>& GetNetclassColorMap() { return m_netclassColors; }
181 
182  std::map<int, KIGFX::COLOR4D>& GetNetColorMap() { return m_netColors; }
183 
184  std::set<int>& GetHiddenNets() { return m_hiddenNets; }
185  const std::set<int>& GetHiddenNets() const { return m_hiddenNets; }
186 
188 
189 protected:
192 
195 
198 
201 
204 
207 
210 
213 
216 
219 
221 
223  static const double MAX_FONT_SIZE;
224 
227 
230 
233 
235  std::map<wxString, KIGFX::COLOR4D> m_netclassColors;
236 
238  std::map<int, KIGFX::COLOR4D> m_netColors;
239 
241  std::set<int> m_hiddenNets;
242 
245 
247 
248  // These opacity overrides multiply with any opacity in the base layer color
249  double m_trackOpacity;
250  double m_viaOpacity;
251  double m_padOpacity;
252  double m_zoneOpacity;
253 };
254 
255 
260 class PCB_PAINTER : public PAINTER
261 {
262 public:
263  PCB_PAINTER( GAL* aGal );
264 
266  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override
267  {
268  m_pcbSettings = *static_cast<const PCB_RENDER_SETTINGS*>( aSettings );
269  }
270 
272  virtual PCB_RENDER_SETTINGS* GetSettings() override
273  {
274  return &m_pcbSettings;
275  }
276 
278  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
279 
280 protected:
282 
283  // Drawing functions for various types of PCB-specific items
284  void draw( const TRACK* aTrack, int aLayer );
285  void draw( const ARC* aArc, int aLayer );
286  void draw( const VIA* aVia, int aLayer );
287  void draw( const D_PAD* aPad, int aLayer );
288  void draw( const PCB_SHAPE* aSegment, int aLayer );
289  void draw( const PCB_TEXT* aText, int aLayer );
290  void draw( const FP_TEXT* aText, int aLayer );
291  void draw( const MODULE* aModule, int aLayer );
292  void draw( const PCB_GROUP* aGroup, int aLayer );
293  void draw( const ZONE_CONTAINER* aZone, int aLayer );
294  void draw( const DIMENSION* aDimension, int aLayer );
295  void draw( const PCB_TARGET* aTarget );
296  void draw( const MARKER_PCB* aMarker, int aLayer );
297 
305  int getLineThickness( int aActualThickness ) const;
306 
310  virtual int getDrillShape( const D_PAD* aPad ) const;
311 
315  virtual VECTOR2D getDrillSize( const D_PAD* aPad ) const;
316 
320  virtual int getDrillSize( const VIA* aVia ) const;
321 };
322 } // namespace KIGFX
323 
324 #endif /* __CLASS_PAINTER_H */
bool GetGlobalRatsnestLinesEnabled() const
Definition: pcb_painter.h:169
void SetRatsnestDisplayMode(RATSNEST_MODE aMode)
Definition: pcb_painter.h:178
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:184
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:61
virtual void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: pcb_painter.cpp:87
double GetBrightness() const
Function GetBrightness Returns the brightness value of the color ranged from 0.0 to 1....
Definition: color4d.h:337
const COLOR4D & GetCursorColor() override
Function GetCursorColor Returns current cursor color settings.
Definition: pcb_painter.h:156
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
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:161
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
ZONE_DISPLAY_MODE
Determines how zones should be displayed
CLEARANCE_MODE
Flags to control clearance lines visibility
Definition: pcb_painter.h:70
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
double m_zoneOpacity
Opacity override for filled zones.
Definition: pcb_painter.h:252
COLOR4D m_layerColors[LAYER_ID_COUNT]
void SetNetColorMode(NET_COLOR_MODE aMode)
Definition: pcb_painter.h:175
PCB_GROUP is a set of BOARD_ITEMs (i.e., without duplicates)
bool m_sketchMode[GAL_LAYER_ID_END]
Flag determining if items on a given layer should be drawn as an outline or a filled item
Definition: pcb_painter.h:191
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:180
virtual VECTOR2D getDrillSize(const D_PAD *aPad) const
Return drill size for a pad (internal units).
void EnableZoneOutlines(bool aEnabled)
Turns on/off drawing outline and hatched lines for zones.
Definition: pcb_painter.h:135
bool m_padNumbers
Flag determining if pad numbers should be visible
Definition: pcb_painter.h:200
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:281
bool GetSketchMode(int aItemLayer) const
Function GetSketchMode Returns sketch mode setting for a given item layer.
Definition: pcb_painter.h:117
Add new GAL layers here.
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:85
RATSNEST_MODE GetRatsnestDisplayMode() const
Definition: pcb_painter.h:177
PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:260
NET_COLOR_MODE GetNetColorMode() const
Definition: pcb_painter.h:174
void SetSketchModeGraphicItems(bool aEnabled)
Turns on/off sketch mode for graphic items (DRAWSEGMENTs, texts).
Definition: pcb_painter.h:127
bool m_netNamesOnPads
Flag determining if net names should be visible for pads
Definition: pcb_painter.h:203
bool m_sketchGraphics
Flag determining if graphic items should be outlined or stroked
Definition: pcb_painter.h:194
HIGH_CONTRAST_MODE GetContrastModeDisplay()
return the contrast mode setting (HIGH_CONTRAST_MODE:NORMAL, DIMMED or HIDDEN )
Definition: pcb_painter.h:165
std::map< wxString, KIGFX::COLOR4D > m_netclassColors
Overrides for specific netclass colors
Definition: pcb_painter.h:235
NET_COLOR_MODE m_netColorMode
How to display nets and netclasses with color overrides
Definition: pcb_painter.h:232
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:64
PCB_DISPLAY_OPTIONS handles display options like enable/disable some optional drawings.
PAINTER contains all the knowledge about how to draw graphical object onto any particular output devi...
Definition: painter.h:57
bool IsBackgroundDark() const override
Definition: pcb_painter.h:140
int getLineThickness(int aActualThickness) const
Function getLineThickness() Get the thickness to draw for a line (e.g.
bool GetDrawIndividualViaLayers() const
Definition: pcb_painter.h:171
static const double MAX_FONT_SIZE
Maximum font size for netnames (and other dynamically shown strings)
Definition: pcb_painter.h:223
virtual PCB_RENDER_SETTINGS * GetSettings() override
Definition: pcb_painter.h:272
bool GetCurvedRatsnestLinesEnabled() const
Definition: pcb_painter.h:167
NETINFO_LIST is a container class for NETINFO_ITEM elements, which are the nets.
Definition: netinfo.h:422
void SetBackgroundColor(const COLOR4D &aColor) override
Sets the background color.
Definition: pcb_painter.h:149
const std::set< int > & GetHiddenNets() const
Definition: pcb_painter.h:185
HIGH_CONTRAST_MODE
Determines how inactive layers should be displayed.
RATSNEST_MODE m_ratsnestDisplayMode
Definition: pcb_painter.h:246
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:31
double m_viaOpacity
Opacity override for all types of via.
Definition: pcb_painter.h:250
NET_COLOR_MODE
Determines how net color overrides should be applied
void SetDrawIndividualViaLayers(bool aFlag)
Definition: pcb_painter.h:172
bool m_curvedRatsnestlines
Flag determining if ratsnest lines should be drawn curved
Definition: pcb_painter.h:215
bool m_sketchText
Flag determining if text items should be outlined or stroked
Definition: pcb_painter.h:197
bool m_netNamesOnTracks
Flag determining if net names should be visible for tracks
Definition: pcb_painter.h:206
double m_trackOpacity
Opacity override for all tracks.
Definition: pcb_painter.h:249
std::map< int, KIGFX::COLOR4D > m_netColors
Overrides for specific net colors, stored as netcodes for the ratsnest to access easily
Definition: pcb_painter.h:238
virtual void ApplySettings(const RENDER_SETTINGS *aSettings) override
Function ApplySettings Loads colors and display modes settings that are going to be used when drawing...
Definition: pcb_painter.h:266
int m_clearance
Clearance visibility settings
Definition: pcb_painter.h:229
Information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:186
void SetSketchMode(int aItemLayer, bool aEnabled)
Function SetSketchMode Turns on/off sketch mode for given item layer.
Definition: pcb_painter.h:107
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aShowPageLimits)
Function LoadDisplayOptions Loads settings related to display options (high-contrast mode,...
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
Function GetBackgroundColor Returns current background color settings.
Definition: pcb_painter.h:147
const COLOR4D & GetGridColor() override
Function GetGridColor Returns current grid color settings.
Definition: pcb_painter.h:154
HIGH_CONTRAST_MODE m_contrastModeDisplay
How to display inactive layers (HIGH_CONTRAST_MODE:NORMAL, DIMMED or HIDDEN )
Definition: pcb_painter.h:244
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: eda_item.h:148
virtual bool Draw(const VIEW_ITEM *aItem, int aLayer) override
Function Draw Takes an instance of VIEW_ITEM and passes it to a function that know how to draw the it...
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:251
bool m_zoneOutlines
Flag determining if zones should have outlines drawn
Definition: pcb_painter.h:212
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:182
void draw(const TRACK *aTrack, int aLayer)
RATSNEST_MODE
Determines how ratsnest lines are drawn
void SetZoneDisplayMode(ZONE_DISPLAY_MODE mode)
Definition: pcb_painter.h:187
Definition of PCB_DISPLAY_OPTIONS class.
ZONE_DISPLAY_MODE m_zoneDisplayMode
Option for different display modes for zones
Definition: pcb_painter.h:226
Abstract dimension API.
bool m_netNamesOnVias
Flag determining if net names should be visible for vias
Definition: pcb_painter.h:209
std::set< int > m_hiddenNets
Set of net codes that should not have their ratsnest displayed
Definition: pcb_painter.h:241
Class GAL is the abstract interface for drawing on a 2D-surface.
bool m_globalRatsnestlines
Flag determining if ratsnest lines are shown by default
Definition: pcb_painter.h:218
virtual int getDrillShape(const D_PAD *aPad) const
Return drill shape of a pad.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100