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 
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 DRAWSEGMENT;
45 class MODULE;
46 class ZONE_CONTAINER;
47 class TEXTE_PCB;
48 class TEXTE_MODULE;
49 class DIMENSION;
50 class PCB_TARGET;
51 class MARKER_PCB;
52 class NET_SETTINGS;
53 class NETINFO_LIST;
54 
55 namespace KIGFX
56 {
57 class GAL;
58 
64 {
65 public:
66  friend class PCB_PAINTER;
67 
70  {
71  CL_NONE = 0x00,
72 
73  // Object type
74  CL_PADS = 0x01,
75  CL_VIAS = 0x02,
76  CL_TRACKS = 0x04,
77 
78  // Existence
79  CL_NEW = 0x08,
80  CL_EDITED = 0x10,
81  CL_EXISTING = 0x20
82  };
83 
86  {
90  };
91 
93  enum class NET_COLOR_MODE
94  {
95  OFF,
96  RATSNEST,
97  ALL
98  };
99 
101 
108  void LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aShowPageLimits );
109 
116  void LoadNetSettings( const NET_SETTINGS& aSettings, const NETINFO_LIST& aList,
117  const std::set<int>& aHiddenNets );
118 
119  virtual void LoadColors( const COLOR_SETTINGS* aSettings ) override;
120 
122  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
123 
131  inline void SetSketchMode( int aItemLayer, bool aEnabled )
132  {
133  m_sketchMode[aItemLayer] = aEnabled;
134  }
135 
141  inline bool GetSketchMode( int aItemLayer ) const
142  {
143  return m_sketchMode[aItemLayer];
144  }
145 
151  inline void SetSketchModeGraphicItems( bool aEnabled )
152  {
153  m_sketchGraphics = aEnabled;
154  }
155 
159  void EnableZoneOutlines( bool aEnabled )
160  {
161  m_zoneOutlines = aEnabled;
162  }
163 
164  inline bool IsBackgroundDark() const override
165  {
167 
168  return luma < 0.5;
169  }
170 
172 
173  void SetBackgroundColor( const COLOR4D& aColor ) override
174  {
176  }
177 
178  const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GRID ]; }
179 
180  const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
181 
186 
190 
191  inline bool GetCurvedRatsnestLinesEnabled() const { return m_curvedRatsnestlines; }
192 
193  inline bool GetGlobalRatsnestLinesEnabled() const { return m_globalRatsnestlines; }
194 
197 
199  void SetNetColorMode( NET_COLOR_MODE aMode ) { m_netColorMode = aMode; }
200 
201  std::map<wxString, KIGFX::COLOR4D>& GetNetclassColorMap() { return m_netclassColors; }
202 
203  std::map<int, KIGFX::COLOR4D>& GetNetColorMap() { return m_netColors; }
204 
205  std::set<int>& GetHiddenNets() { return m_hiddenNets; }
206  const std::set<int>& GetHiddenNets() const { return m_hiddenNets; }
207 
208 protected:
211 
214 
217 
220 
223 
226 
229 
232 
235 
238 
240 
242  static const double MAX_FONT_SIZE;
243 
246 
249 
252 
255 
257  std::map<wxString, KIGFX::COLOR4D> m_netclassColors;
258 
260  std::map<int, KIGFX::COLOR4D> m_netColors;
261 
263  std::set<int> m_hiddenNets;
264 
267 };
268 
269 
274 class PCB_PAINTER : public PAINTER
275 {
276 public:
277  PCB_PAINTER( GAL* aGal );
278 
280  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override
281  {
282  m_pcbSettings = *static_cast<const PCB_RENDER_SETTINGS*>( aSettings );
283  }
284 
286  virtual PCB_RENDER_SETTINGS* GetSettings() override
287  {
288  return &m_pcbSettings;
289  }
290 
292  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
293 
294 protected:
296 
297  // Drawing functions for various types of PCB-specific items
298  void draw( const TRACK* aTrack, int aLayer );
299  void draw( const ARC* aArc, int aLayer );
300  void draw( const VIA* aVia, int aLayer );
301  void draw( const D_PAD* aPad, int aLayer );
302  void draw( const DRAWSEGMENT* aSegment, int aLayer );
303  void draw( const TEXTE_PCB* aText, int aLayer );
304  void draw( const TEXTE_MODULE* aText, int aLayer );
305  void draw( const MODULE* aModule, int aLayer );
306  void draw( const ZONE_CONTAINER* aZone, int aLayer );
307  void draw( const DIMENSION* aDimension, int aLayer );
308  void draw( const PCB_TARGET* aTarget );
309  void draw( const MARKER_PCB* aMarker );
310 
318  int getLineThickness( int aActualThickness ) const;
319 
323  virtual int getDrillShape( const D_PAD* aPad ) const;
324 
328  virtual VECTOR2D getDrillSize( const D_PAD* aPad ) const;
329 
333  virtual int getDrillSize( const VIA* aVia ) const;
334 };
335 } // namespace KIGFX
336 
337 #endif /* __CLASS_PAINTER_H */
bool GetGlobalRatsnestLinesEnabled() const
Definition: pcb_painter.h:193
std::set< int > & GetHiddenNets()
Definition: pcb_painter.h:205
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:78
double GetBrightness() const
Function GetBrightness Returns the brightness value of the color ranged from 0.0 to 1....
Definition: color4d.h:329
const COLOR4D & GetCursorColor() override
Function GetCursorColor Returns current cursor color settings.
Definition: pcb_painter.h:180
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:185
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
CLEARANCE_MODE
Flags to control clearance lines visibility
Definition: pcb_painter.h:69
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
COLOR4D m_layerColors[LAYER_ID_COUNT]
void SetNetColorMode(NET_COLOR_MODE aMode)
Definition: pcb_painter.h:199
Net (and netclass) colors are not shown.
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:210
std::map< wxString, KIGFX::COLOR4D > & GetNetclassColorMap()
Definition: pcb_painter.h:201
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const override
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
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:159
bool m_padNumbers
Flag determining if pad numbers should be visible
Definition: pcb_painter.h:219
DISPLAY_ZONE_MODE m_displayZone
Option for different display modes for zones
Definition: pcb_painter.h:245
DISPLAY_ZONE_MODE
Determines how zones should be displayed
Definition: pcb_painter.h:85
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:295
bool GetSketchMode(int aItemLayer) const
Function GetSketchMode Returns sketch mode setting for a given item layer.
Definition: pcb_painter.h:141
Add new GAL layers here.
COLOR4D m_selectionCandidateColor
Color used for highlighting selection candidates
Definition: pcb_painter.h:251
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:85
PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:274
NET_COLOR_MODE GetNetColorMode() const
Definition: pcb_painter.h:198
void SetSketchModeGraphicItems(bool aEnabled)
Turns on/off sketch mode for graphic items (DRAWSEGMENTs, texts).
Definition: pcb_painter.h:151
bool m_netNamesOnPads
Flag determining if net names should be visible for pads
Definition: pcb_painter.h:222
bool m_sketchGraphics
Flag determining if graphic items should be outlined or stroked
Definition: pcb_painter.h:213
HIGH_CONTRAST_MODE GetContrastModeDisplay()
return the contrast mode setting (HIGH_CONTRAST_MODE:NORMAL, DIMMED or HIDDEN )
Definition: pcb_painter.h:189
std::map< wxString, KIGFX::COLOR4D > m_netclassColors
Overrides for specific netclass colors
Definition: pcb_painter.h:257
NET_COLOR_MODE
Determines how net color overrides should be applied
Definition: pcb_painter.h:93
NET_COLOR_MODE m_netColorMode
How to display nets and netclasses with color overrides
Definition: pcb_painter.h:254
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:63
Net/netclass colors are shown on ratsnest lines only.
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:58
bool IsBackgroundDark() const override
Definition: pcb_painter.h:164
int getLineThickness(int aActualThickness) const
Function getLineThickness() Get the thickness to draw for a line (e.g.
bool GetDrawIndividualViaLayers() const
Definition: pcb_painter.h:195
static const double MAX_FONT_SIZE
Maximum font size for netnames (and other dynamically shown strings)
Definition: pcb_painter.h:242
virtual PCB_RENDER_SETTINGS * GetSettings() override
Definition: pcb_painter.h:286
bool GetCurvedRatsnestLinesEnabled() const
Definition: pcb_painter.h:191
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:173
void LoadNetSettings(const NET_SETTINGS &aSettings, const NETINFO_LIST &aList, const std::set< int > &aHiddenNets)
Loads net-specific render settings.
const std::set< int > & GetHiddenNets() const
Definition: pcb_painter.h:206
HIGH_CONTRAST_MODE
Determines how inactive layers should be displayed.
NET_SETTINGS stores various net-related settings in a project context.
Definition: net_settings.h:31
void SetDrawIndividualViaLayers(bool aFlag)
Definition: pcb_painter.h:196
bool m_curvedRatsnestlines
Flag determining if ratsnest lines should be drawn curved
Definition: pcb_painter.h:234
bool m_sketchText
Flag determining if text items should be outlined or stroked
Definition: pcb_painter.h:216
bool m_netNamesOnTracks
Flag determining if net names should be visible for tracks
Definition: pcb_painter.h:225
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:260
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:280
int m_clearance
Clearance visibility settings
Definition: pcb_painter.h:248
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:180
void SetSketchMode(int aItemLayer, bool aEnabled)
Function SetSketchMode Turns on/off sketch mode for given item layer.
Definition: pcb_painter.h:131
void LoadDisplayOptions(const PCB_DISPLAY_OPTIONS &aOptions, bool aShowPageLimits)
Function LoadDisplayOptions Loads settings related to display options (high-contrast mode,...
const COLOR4D & GetBackgroundColor() override
Function GetBackgroundColor Returns current background color settings.
Definition: pcb_painter.h:171
const COLOR4D & GetGridColor() override
Function GetGridColor Returns current grid color settings.
Definition: pcb_painter.h:178
HIGH_CONTRAST_MODE m_contrastModeDisplay
How to display inactive layers (HIGH_CONTRAST_MODE:NORMAL, DIMMED or HIDDEN )
Definition: pcb_painter.h:266
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
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...
bool m_zoneOutlines
Flag determining if zones should have outlines drawn
Definition: pcb_painter.h:231
std::map< int, KIGFX::COLOR4D > & GetNetColorMap()
Definition: pcb_painter.h:203
void draw(const TRACK *aTrack, int aLayer)
Definition of PCB_DISPLAY_OPTIONS class.
DIMENSION.
bool m_netNamesOnVias
Flag determining if net names should be visible for vias
Definition: pcb_painter.h:228
std::set< int > m_hiddenNets
Set of net codes that should not have their ratsnest displayed
Definition: pcb_painter.h:263
Net/netclass colors are shown on all net copper.
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:237
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:99