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;
36 
37 class GERBER_DRAW_ITEM;
38 class GERBER_FILE_IMAGE;
39 
40 
41 namespace KIGFX
42 {
43 class GAL;
44 
50 {
51 public:
52  friend class GERBVIEW_PAINTER;
53 
55 
57  void ImportLegacyColors( const COLORS_DESIGN_SETTINGS* aSettings ) override;
58 
64  void LoadDisplayOptions( const GBR_DISPLAY_OPTIONS& aOptions );
65 
67  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const override;
68 
74  inline const COLOR4D& GetLayerColor( int aLayer ) const
75  {
76  return m_layerColors[aLayer];
77  }
78 
85  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
86  {
87  m_layerColors[aLayer] = aColor;
88 
89  update(); // recompute other shades of the color
90  }
91 
93 
94  void SetBackgroundColor( const COLOR4D& aColor ) override
95  {
97  }
98 
99  const COLOR4D& GetGridColor() override { return m_layerColors[ LAYER_GRID ]; }
100 
101  const COLOR4D& GetCursorColor() override { return m_layerColors[ LAYER_CURSOR ]; }
102 
103  inline bool IsSpotFill() const
104  {
105  return m_spotFill;
106  }
107 
108  inline bool IsLineFill() const
109  {
110  return m_lineFill;
111  }
112 
113  inline bool IsPolygonFill() const
114  {
115  return m_polygonFill;
116  }
117 
118  inline bool IsShowNegativeItems() const
119  {
120  return m_showNegativeItems;
121  }
122 
123  inline bool IsShowCodes() const
124  {
125  return m_showCodes;
126  }
127 
128  inline bool IsDiffMode() const
129  {
130  return m_diffMode;
131  }
132 
135 
138 
141 
142 protected:
145 
148 
151 
154 
157 
160 
162  static const double MAX_FONT_SIZE;
163 };
164 
165 
170 class GERBVIEW_PAINTER : public PAINTER
171 {
172 public:
173  GERBVIEW_PAINTER( GAL* aGal );
174 
176  virtual void ApplySettings( const RENDER_SETTINGS* aSettings ) override
177  {
178  m_gerbviewSettings = *static_cast<const GERBVIEW_RENDER_SETTINGS*>( aSettings );
179  }
180 
183  {
184  return &m_gerbviewSettings;
185  }
186 
188  virtual bool Draw( const VIEW_ITEM* aItem, int aLayer ) override;
189 
190 protected:
192 
193  // Drawing functions
194  void draw( /*const*/ GERBER_DRAW_ITEM* aVia, int aLayer );
195 
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 
219  int getLineThickness( int aActualThickness ) const;
220 };
221 } // namespace KIGFX
222 
223 #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...
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...
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:131
RENDER_SETTINGS Contains all the knowledge about how graphical objects are drawn on any output surfac...
Definition: painter.h:56
static const double MAX_FONT_SIZE
Maximum font size for D-Codes and other strings.
COLOR4D m_layerColors[LAYER_ID_COUNT]
Colors for all layers (normal)
Definition: painter.h:265
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:84
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:313
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.
Definition: painter.cpp:54
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
Function GetSettings Returns 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.
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:163
void drawPolygon(GERBER_DRAW_ITEM *aParent, const SHAPE_POLY_SET &aPolygon, bool aFilled, bool aShift=false)
Helper routine to draw a polygon.
COLORS_DESIGN_SETTINGS is a list of color settings for designs in Pcbnew.
void LoadDisplayOptions(const GBR_DISPLAY_OPTIONS &aOptions)
Function LoadDisplayOptions Loads settings related to display options.
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.
void ImportLegacyColors(const COLORS_DESIGN_SETTINGS *aSettings) override
Function ImportLegacyColors Loads a list of color settings for layers.
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:39