KiCad PCB EDA Suite
gerbview_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) 2017 Jon Evans <jon@craftyjon.com>
5  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * This program is free software: you can redistribute it and/or modify it
8  * under the terms of the GNU General Public License as published by the
9  * Free Software Foundation, either version 3 of the License, or (at your
10  * option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef __GERBVIEW_PAINTER_H
22 #define __GERBVIEW_PAINTER_H
23 
24 #include <layer_ids.h>
25 #include <painter.h>
26 
27 #include <dcode.h>
28 #include <gbr_display_options.h>
30 
31 #include <memory>
32 
33 
34 class EDA_ITEM;
35 class GERBER_DRAW_ITEM;
36 class GERBER_FILE_IMAGE;
37 
38 
39 namespace KIGFX
40 {
41 class GAL;
42 
47 {
48 public:
49  friend class GERBVIEW_PAINTER;
50 
52 
53  void LoadColors( const COLOR_SETTINGS* aSettings ) override;
54 
60  void LoadDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions );
61 
63  virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
64 
70  inline const COLOR4D& GetLayerColor( int aLayer ) const
71  {
72  return m_layerColors[aLayer];
73  }
74 
81  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
82  {
83  m_layerColors[aLayer] = aColor;
84 
85  update(); // recompute other shades of the color
86  }
87 
88  const COLOR4D& GetBackgroundColor() override
89  {
91  }
92 
93  void SetBackgroundColor( const COLOR4D& aColor ) override
94  {
96  }
97 
98  const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GERBVIEW_GRID ]; }
99 
100  const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
101 
102  inline bool IsSpotFill() const
103  {
104  return m_spotFill;
105  }
106 
107  inline bool IsLineFill() const
108  {
109  return m_lineFill;
110  }
111 
112  inline bool IsPolygonFill() const
113  {
114  return m_polygonFill;
115  }
116 
117  inline bool IsShowNegativeItems() const
118  {
119  return m_showNegativeItems;
120  }
121 
122  inline bool IsShowCodes() const
123  {
124  return m_showCodes;
125  }
126 
127  inline bool IsDiffMode() const
128  {
129  return m_diffMode;
130  }
131 
134 
137 
140 
143 
147 
148 protected:
151 
154 
157 
160 
163 
166 
168  static const double MAX_FONT_SIZE;
169 };
170 
171 
175 class GERBVIEW_PAINTER : public PAINTER
176 {
177 public:
178  GERBVIEW_PAINTER( GAL* aGal );
179 
182  {
183  return &m_gerbviewSettings;
184  }
185 
187  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
188 
189 protected:
191 
192  // Drawing functions
193  void draw( /*const*/ GERBER_DRAW_ITEM* aVia, int aLayer );
194 
203  void drawPolygon( GERBER_DRAW_ITEM* aParent, const SHAPE_POLY_SET& aPolygon,
204  bool aFilled, bool aShift = false );
205 
207  void drawFlashedShape( GERBER_DRAW_ITEM* aItem, bool aFilled );
208 
210  void drawApertureMacro( GERBER_DRAW_ITEM* aParent, bool aFilled );
211 
218  int getLineThickness( int aActualThickness ) const;
219 };
220 } // namespace KIGFX
221 
222 #endif /* __GERBVIEW_PAINTER_H */
GERBVIEW_RENDER_SETTINGS m_gerbviewSettings
Class GBR_DISPLAY_OPTIONS is a helper class to handle display options (filling modes and afew other o...
bool m_showNegativeItems
Flag determining if negative items should be drawn with a "ghost" color.
const COLOR4D & GetBackgroundColor() override
Return current background color settings.
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:236
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
static const double MAX_FONT_SIZE
Maximum font size for D-Codes and other strings.
COLOR4D m_layerColors[LAYER_ID_COUNT]
const COLOR4D & GetGridColor() override
Return current grid color settings.
PCB cursor.
Definition: layer_ids.h:217
void draw(GERBER_DRAW_ITEM *aVia, int aLayer)
const COLOR4D & GetCursorColor() override
Return current cursor color settings.
bool m_lineFill
Flag determining if lines should be drawn with fill.
Hold the image data and parameters for one gerber file and layer parameters.
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.
void drawFlashedShape(GERBER_DRAW_ITEM *aItem, bool aFilled)
Helper to draw a flashed shape (aka spot)
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:76
int getLineThickness(int aActualThickness) const
Get the thickness to draw for a line (e.g.
bool m_spotFill
Flag determining if spots should be drawn with fill.
void SetBackgroundColor(const COLOR4D &aColor) override
Set the background color.
bool m_showCodes
Flag determining if D-Codes should be drawn.
void drawApertureMacro(GERBER_DRAW_ITEM *aParent, bool aFilled)
Helper to draw an aperture macro shape.
Contains all the knowledge about how to draw graphical object onto any particular output device.
Definition: painter.h:57
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...
wxString m_netHighlightString
If set to anything but an empty string, will highlight items with matching net.
wxString m_attributeHighlightString
If set to anything but an empty string, will highlight items with matching attribute.
Methods for drawing GerbView specific items.
virtual void update()
Precalculates extra colors for layers (e.g.
Represent a set of closed polygons.
void ClearHighlightSelections()
Clear all highlight selections (dcode, net, component, attribute selection)
wxString m_componentHighlightString
If set to anything but an empty string, will highlight items with matching component.
Store GerbView specific render settings.
virtual GERBVIEW_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
bool m_polygonFill
Flag determining if polygons should be drawn with fill.
void LoadColors(const COLOR_SETTINGS *aSettings) override
int m_dcodeHighlightValue
If set to anything but >0 (in fact 10 the min dcode value), will highlight items with matching dcode.
A base class for most all the KiCad significant classes used in schematics and boards.
Definition: eda_item.h:100
void drawPolygon(GERBER_DRAW_ITEM *aParent, const SHAPE_POLY_SET &aPolygon, bool aFilled, bool aShift=false)
Helper routine to draw a polygon.
void LoadDisplayOptions(const GBR_DISPLAY_OPTIONS &aOptions)
Load settings related to display options.
Color settings are a bit different than most of the settings objects in that there can be more than o...
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
bool m_diffMode
Flag determining if layers should be rendered in "diff" mode.
Abstract interface for drawing on a 2D-surface.
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103