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) 2017 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 
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 
48 {
49 public:
50  friend class GERBVIEW_PAINTER;
51 
53 
54  void LoadColors( const COLOR_SETTINGS* aSettings ) override;
55 
61  void LoadDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions );
62 
64  virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
65 
71  inline const COLOR4D& GetLayerColor( int aLayer ) const
72  {
73  return m_layerColors[aLayer];
74  }
75 
82  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
83  {
84  m_layerColors[aLayer] = aColor;
85 
86  update(); // recompute other shades of the color
87  }
88 
90 
91  void SetBackgroundColor( const COLOR4D& aColor ) override
92  {
94  }
95 
96  const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GERBVIEW_GRID ]; }
97 
98  const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
99 
100  inline bool IsSpotFill() const
101  {
102  return m_spotFill;
103  }
104 
105  inline bool IsLineFill() const
106  {
107  return m_lineFill;
108  }
109 
110  inline bool IsPolygonFill() const
111  {
112  return m_polygonFill;
113  }
114 
115  inline bool IsShowNegativeItems() const
116  {
117  return m_showNegativeItems;
118  }
119 
120  inline bool IsShowCodes() const
121  {
122  return m_showCodes;
123  }
124 
125  inline bool IsDiffMode() const
126  {
127  return m_diffMode;
128  }
129 
132 
135 
138 
139 protected:
142 
145 
148 
151 
154 
157 
159  static const double MAX_FONT_SIZE;
160 };
161 
162 
167 class GERBVIEW_PAINTER : public PAINTER
168 {
169 public:
170  GERBVIEW_PAINTER( GAL* aGal );
171 
173  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override
174  {
175  m_gerbviewSettings = *static_cast<const GERBVIEW_RENDER_SETTINGS*>( aSettings );
176  }
177 
180  {
181  return &m_gerbviewSettings;
182  }
183 
185  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
186 
187 protected:
189 
190  // Drawing functions
191  void draw( /*const*/ GERBER_DRAW_ITEM* aVia, int aLayer );
192 
200  void drawPolygon( GERBER_DRAW_ITEM* aParent, const SHAPE_POLY_SET& aPolygon,
201  bool aFilled, bool aShift = false );
202 
204  void drawFlashedShape( GERBER_DRAW_ITEM* aItem, bool aFilled );
205 
207  void drawApertureMacro( GERBER_DRAW_ITEM* aParent, bool aFilled );
208 
216  int getLineThickness( int aActualThickness ) const;
217 };
218 } // namespace KIGFX
219 
220 #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.
virtual void ApplySettings(const RENDER_SETTINGS *aSettings) override
Function ApplySettings Loads colors and display modes settings that are going to be used when drawing...
const COLOR4D & GetBackgroundColor() override
Function GetBackgroundColor Returns current background color settings.
Class CAIRO_GAL is the cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:175
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
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
Function GetGridColor Returns current grid color settings.
void draw(GERBER_DRAW_ITEM *aVia, int aLayer)
const COLOR4D & GetCursorColor() override
Function GetCursorColor Returns current cursor color settings.
bool m_lineFill
Flag determining if lines should be drawn with fill.
GERBER_FILE_IMAGE holds the Image data and parameters for one gerber file and layer parameters (TODO:...
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...
void drawFlashedShape(GERBER_DRAW_ITEM *aItem, bool aFilled)
Helper to draw a flashed shape (aka spot)
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:85
int getLineThickness(int aActualThickness) const
Function getLineThickness() 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
Sets 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.
PAINTER contains all the knowledge about how to draw graphical object onto any particular output devi...
Definition: painter.h:58
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.
GERBVIEW_PAINTER Contains methods for drawing GerbView-specific items.
virtual void update()
Function update Precalculates extra colors for layers (e.g.
SHAPE_POLY_SET.
wxString m_componentHighlightString
If set to anything but an empty string, will highlight items with matching component.
GERBVIEW_RENDER_SETTINGS Stores GerbView specific render settings.
virtual GERBVIEW_RENDER_SETTINGS * GetSettings() override
bool m_polygonFill
Flag determining if polygons should be drawn with fill.
void LoadColors(const COLOR_SETTINGS *aSettings) override
Board layer functions and definitions.
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
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)
Function LoadDisplayOptions Loads 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
Function GetLayerColor Returns the color used to draw a layer.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
bool m_diffMode
Flag determining if layers should be rendered in "diff" mode.
Class GAL is the abstract interface for drawing on a 2D-surface.
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:99