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 
32 #include <memory>
33 
34 
35 class EDA_ITEM;
37 class BOARD_ITEM;
38 class ARC;
39 class BOARD;
40 class VIA;
41 class TRACK;
42 class D_PAD;
43 class DRAWSEGMENT;
44 class MODULE;
45 class ZONE_CONTAINER;
46 class TEXTE_PCB;
47 class TEXTE_MODULE;
48 class DIMENSION;
49 class PCB_TARGET;
50 class MARKER_PCB;
51 
52 namespace KIGFX
53 {
54 class GAL;
55 
61 {
62 public:
63  friend class PCB_PAINTER;
64 
67  {
68  CL_NONE = 0x00,
69 
70  // Object type
71  CL_PADS = 0x01,
72  CL_VIAS = 0x02,
73  CL_TRACKS = 0x04,
74 
75  // Existence
76  CL_NEW = 0x08,
77  CL_EDITED = 0x10,
78  CL_EXISTING = 0x20
79  };
80 
83  {
87  };
88 
90 
97  void LoadDisplayOptions( const PCB_DISPLAY_OPTIONS& aOptions, bool aShowPageLimits );
98 
99  virtual void LoadColors( const COLOR_SETTINGS* aSettings ) override;
100 
102  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
103 
111  inline void SetSketchMode( int aItemLayer, bool aEnabled )
112  {
113  m_sketchMode[aItemLayer] = aEnabled;
114  }
115 
121  inline bool GetSketchMode( int aItemLayer ) const
122  {
123  return m_sketchMode[aItemLayer];
124  }
125 
131  inline void SetSketchModeGraphicItems( bool aEnabled )
132  {
133  m_sketchBoardGfx = aEnabled;
134  }
135 
139  void EnableZoneOutlines( bool aEnabled )
140  {
141  m_zoneOutlines = aEnabled;
142  }
143 
144  inline bool IsBackgroundDark() const override
145  {
147 
148  return luma < 0.5;
149  }
150 
152 
153  void SetBackgroundColor( const COLOR4D& aColor ) override
154  {
156  }
157 
158  const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GRID ]; }
159 
160  const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
161 
162  inline bool GetCurvedRatsnestLinesEnabled() const
163  {
164  return m_curvedRatsnestlines;
165  }
166 
167  inline bool GetGlobalRatsnestLinesEnabled() const
168  {
169  return m_globalRatsnestlines;
170  }
171 
172 protected:
175 
178 
181 
184 
187 
190 
193 
196 
199 
202 
205 
207  static const double MAX_FONT_SIZE;
208 
211 
214 
217 };
218 
219 
224 class PCB_PAINTER : public PAINTER
225 {
226 public:
227  PCB_PAINTER( GAL* aGal );
228 
230  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override
231  {
232  m_pcbSettings = *static_cast<const PCB_RENDER_SETTINGS*>( aSettings );
233  }
234 
236  virtual PCB_RENDER_SETTINGS* GetSettings() override
237  {
238  return &m_pcbSettings;
239  }
240 
242  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
243 
244 protected:
246 
247  // Drawing functions for various types of PCB-specific items
248  void draw( const TRACK* aTrack, int aLayer );
249  void draw( const ARC* aArc, int aLayer );
250  void draw( const VIA* aVia, int aLayer );
251  void draw( const D_PAD* aPad, int aLayer );
252  void draw( const DRAWSEGMENT* aSegment, int aLayer );
253  void draw( const TEXTE_PCB* aText, int aLayer );
254  void draw( const TEXTE_MODULE* aText, int aLayer );
255  void draw( const MODULE* aModule, int aLayer );
256  void draw( const ZONE_CONTAINER* aZone, int aLayer );
257  void draw( const DIMENSION* aDimension, int aLayer );
258  void draw( const PCB_TARGET* aTarget );
259  void draw( const MARKER_PCB* aMarker );
260 
268  int getLineThickness( int aActualThickness ) const;
269 
273  virtual int getDrillShape( const D_PAD* aPad ) const;
274 
278  virtual VECTOR2D getDrillSize( const D_PAD* aPad ) const;
279 
283  virtual int getDrillSize( const VIA* aVia ) const;
284 };
285 } // namespace KIGFX
286 
287 #endif /* __CLASS_PAINTER_H */
bool GetGlobalRatsnestLinesEnabled() const
Definition: pcb_painter.h:167
ZONE_CONTAINER handles a list of polygons defining a copper zone.
Definition: class_zone.h:60
virtual void LoadColors(const COLOR_SETTINGS *aSettings) override
Definition: pcb_painter.cpp:76
double GetBrightness() const
Function GetBrightness Returns the brightness value of the color ranged from 0.0 to 1....
Definition: color4d.h:270
const COLOR4D & GetCursorColor() override
Function GetCursorColor Returns current cursor color settings.
Definition: pcb_painter.h:160
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:131
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Definition: painter.h:56
CLEARANCE_MODE
Flags to control clearance lines visibility
Definition: pcb_painter.h:66
BOARD_ITEM is a base class for any item which can be embedded within the BOARD container class,...
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:260
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:174
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:139
bool m_padNumbers
Flag determining if pad numbers should be visible
Definition: pcb_painter.h:186
bool m_sketchBoardGfx
Flag determining if board graphic items should be outlined or stroked
Definition: pcb_painter.h:177
DISPLAY_ZONE_MODE m_displayZone
Option for different display modes for zones
Definition: pcb_painter.h:210
bool m_sketchFpTxtfx
Flag determining if footprint text items should be outlined or stroked
Definition: pcb_painter.h:183
DISPLAY_ZONE_MODE
Determines how zones should be displayed
Definition: pcb_painter.h:82
PCB_RENDER_SETTINGS m_pcbSettings
Definition: pcb_painter.h:245
bool GetSketchMode(int aItemLayer) const
Function GetSketchMode Returns sketch mode setting for a given item layer.
Definition: pcb_painter.h:121
Add new GAL layers here.
COLOR4D m_selectionCandidateColor
Color used for highlighting selection candidates
Definition: pcb_painter.h:216
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:84
PCB_PAINTER Contains methods for drawing PCB-specific items.
Definition: pcb_painter.h:224
void SetSketchModeGraphicItems(bool aEnabled)
Turns on/off sketch mode for graphic items (DRAWSEGMENTs, texts).
Definition: pcb_painter.h:131
bool m_netNamesOnPads
Flag determining if net names should be visible for pads
Definition: pcb_painter.h:189
PCB_RENDER_SETTINGS Stores PCB specific render settings.
Definition: pcb_painter.h:60
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:308
bool IsBackgroundDark() const override
Definition: pcb_painter.h:144
int getLineThickness(int aActualThickness) const
Function getLineThickness() Get the thickness to draw for a line (e.g.
static const double MAX_FONT_SIZE
Maximum font size for netnames (and other dynamically shown strings)
Definition: pcb_painter.h:207
virtual PCB_RENDER_SETTINGS * GetSettings() override
Function GetSettings Returns pointer to current settings that are going to be used when drawing items...
Definition: pcb_painter.h:236
bool GetCurvedRatsnestLinesEnabled() const
Definition: pcb_painter.h:162
void SetBackgroundColor(const COLOR4D &aColor) override
Sets the background color.
Definition: pcb_painter.h:153
bool m_curvedRatsnestlines
Flag determining if ratsnest lines should be drawn curved
Definition: pcb_painter.h:201
bool m_sketchFpGfx
Flag determining if footprint graphic items should be outlined or stroked
Definition: pcb_painter.h:180
bool m_netNamesOnTracks
Flag determining if net names should be visible for tracks
Definition: pcb_painter.h:192
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:230
int m_clearance
Clearance visibility settings
Definition: pcb_painter.h:213
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:163
void SetSketchMode(int aItemLayer, bool aEnabled)
Function SetSketchMode Turns on/off sketch mode for given item layer.
Definition: pcb_painter.h:111
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:151
const COLOR4D & GetGridColor() override
Function GetGridColor Returns current grid color settings.
Definition: pcb_painter.h:158
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:166
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)
bool m_zoneOutlines
Flag determining if zones should have outlines drawn
Definition: pcb_painter.h:198
void draw(const TRACK *aTrack, int aLayer)
DIMENSION.
bool m_netNamesOnVias
Flag determining if net names should be visible for vias
Definition: pcb_painter.h:195
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:204
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:40