KiCad PCB EDA Suite
render_settings.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) 2019 KiCad Developers, see CHANGELOG.TXT for contributors.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, you may find one here:
18  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19  * or you may search the http://www.gnu.org website for the version 2 license,
20  * or you may write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22  */
23 
24 #ifndef RENDER_SETTINGS_H
25 #define RENDER_SETTINGS_H
26 
27 #include <map>
28 #include <set>
29 
30 #include <gal/color4d.h>
32 #include <memory>
33 
34 #include <wx/dc.h>
35 
36 class COLOR_SETTINGS;
37 
38 namespace KIGFX
39 {
40 class VIEW_ITEM;
41 
54 {
55 public:
57  virtual ~RENDER_SETTINGS();
58 
59  virtual void LoadColors( const COLOR_SETTINGS* aSettings ) { }
60 
67  inline void SetLayerIsHighContrast( int aLayerId, bool aEnabled = true )
68  {
69  if( aEnabled )
70  m_highContrastLayers.insert( aLayerId );
71  else
72  m_highContrastLayers.erase( aLayerId );
73  }
74 
80  inline bool GetLayerIsHighContrast( int aLayerId ) const
81  {
82  return ( m_highContrastLayers.count( aLayerId ) > 0 );
83  }
84 
89  const std::set<unsigned int> GetHighContrastLayers() const
90  {
91  return m_highContrastLayers;
92  }
93 
100  {
101  for( int layer : m_highContrastLayers )
102  {
103  if( layer >= PCBNEW_LAYER_ID_START && layer < PCB_LAYER_ID_COUNT )
104  return (PCB_LAYER_ID) layer;
105  }
106 
107  return UNDEFINED_LAYER;
108  }
109 
111  void SetActiveLayer( PCB_LAYER_ID aLayer ) { m_activeLayer = aLayer; }
112 
118  {
119  m_highContrastLayers.clear();
120  }
121 
127  inline bool IsHighlightEnabled() const
128  {
129  return m_highlightEnabled;
130  }
131 
137  inline const std::set<int>& GetHighlightNetCodes() const
138  {
139  return m_highlightNetcodes;
140  }
141 
149  inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
150  {
151  m_highlightEnabled = aEnabled;
152 
153  if( aEnabled )
154  {
155  if( !aMulti )
156  m_highlightNetcodes.clear();
157 
158  m_highlightNetcodes.insert( aNetcode );
159  }
160  else
161  m_highlightNetcodes.clear();
162  }
163 
168  void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
169  bool GetHighContrast() const { return m_hiContrastEnabled; }
170 
178  virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
179 
180  float GetWorksheetLineWidth() const { return m_worksheetLineWidth; }
181 
182  int GetDefaultPenWidth() const { return m_defaultPenWidth; }
183  void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
184 
185  int GetMinPenWidth() const { return m_minPenWidth; }
186  void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
187 
188  bool GetShowPageLimits() const { return m_showPageLimits; }
189  void SetShowPageLimits( bool aDraw ) { m_showPageLimits = aDraw; }
190 
195  virtual const COLOR4D& GetBackgroundColor() = 0;
196 
200  virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
201 
206  virtual const COLOR4D& GetGridColor() = 0;
207 
212  virtual const COLOR4D& GetCursorColor() = 0;
213 
219  inline const COLOR4D& GetLayerColor( int aLayer ) const
220  {
221  return m_layerColors[aLayer];
222  }
223 
230  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
231  {
232  m_layerColors[aLayer] = aColor;
233 
234  update(); // recompute other shades of the color
235  }
236 
237  virtual bool IsBackgroundDark() const
238  {
239  return false;
240  }
241 
247  void SetOutlineWidth( float aWidth )
248  {
249  m_outlineWidth = aWidth;
250  }
251 
252  void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
253  void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
254  void SetHighContrastFactor( float aFactor ) { m_hiContrastFactor = aFactor; }
255 
256  // TODO: these can go away once the worksheet is moved to Cairo-based printing
257  wxDC* GetPrintDC() { return m_printDC; }
258  void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
259 
260 protected:
266  virtual void update();
267 
268  PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
269  std::set<unsigned int> m_highContrastLayers; // High-contrast layers (both board layers and
270  // synthetic GAL layers)
272  COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
273  COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
274 
275  COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
276  COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
277 
278  COLOR4D m_backgroundColor; // The background color
279 
281  bool m_hiContrastEnabled; // High contrast display mode on/off
282  float m_hiContrastFactor; // Factor used for computing high contrast color
283 
284  bool m_highlightEnabled; // Highlight display mode on/off
285  std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
286  float m_highlightFactor; // Factor used for computing highlight color
287 
288  float m_selectFactor; // Specifies how color of selected items is changed
289  float m_outlineWidth; // Line width used when drawing outlines
290  float m_worksheetLineWidth; // Line width used when drawing worksheet
291 
293  int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
294  // lines. This sets an absolute minimum.
296 
297  wxDC* m_printDC; // This can go away once the worksheet is moved to
298  // Cairo-based printing.
299 };
300 
301 }
302 
303 #endif /* RENDER_SETTINGS_H */
const std::set< unsigned int > GetHighContrastLayers() const
Function GetHighContrastLayers() Returns the set of currently high-contrast layers.
virtual const COLOR4D & GetGridColor()=0
Function GetGridColor Returns current grid 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...
virtual const COLOR4D & GetCursorColor()=0
Function GetCursorColor Returns current cursor color settings.
COLOR4D m_layerColorsHi[LAYER_ID_COUNT]
COLOR4D m_layerColors[LAYER_ID_COUNT]
virtual const COLOR4D & GetBackgroundColor()=0
Function GetBackgroundColor Returns current background color settings.
const COLOR4D & GetLayerColor(int aLayer) const
Function GetLayerColor Returns the color used to draw a layer.
bool GetShowPageLimits() const
bool IsHighlightEnabled() const
Function IsHighlightEnabled Returns current highlight setting.
VIEW_ITEM - is an abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:85
void SetOutlineWidth(float aWidth)
Set line width used for drawing outlines.
virtual bool IsBackgroundDark() const
std::set< unsigned int > m_highContrastLayers
COLOR4D m_hiContrastColor[LAYER_ID_COUNT]
PCB_LAYER_ID
A quick note on layer IDs:
void SetHighContrastFactor(float aFactor)
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
bool m_hiContrastEnabled
Parameters for display modes.
virtual void update()
Function update Precalculates extra colors for layers (e.g.
void SetMinPenWidth(int aWidth)
void SetHighContrast(bool aEnabled)
Function SetHighContrast Turns on/off high contrast display mode.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Function SetLayerColor Changes the color used to draw a layer.
bool GetLayerIsHighContrast(int aLayerId) const
Function GetLayerIsHighContrast Returns information whether the queried layer is marked as high-contr...
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Function SetLayerIsHighContrast Sets the specified layer as high-contrast.
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
virtual COLOR4D GetColor(const VIEW_ITEM *aItem, int aLayer) const =0
Returns the color that should be used to draw the specific VIEW_ITEM on the specific layer using curr...
bool GetHighContrast() const
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Sets the background color.
Board layer functions and definitions.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Function SetHighlight Turns on/off highlighting - it may be done for the active layer or the specifie...
float GetWorksheetLineWidth() const
void SetSelectFactor(float aFactor)
void SetHighlightFactor(float aFactor)
PCB_LAYER_ID GetActiveLayer() const
void ClearHighContrastLayers()
Function ClearHighContrastLayers Clears the list of active layers.
int GetDefaultPenWidth() const
Color settings are a bit different than most of the settings objects in that there can be more than o...
const std::set< int > & GetHighlightNetCodes() const
Function GetHighlightNetCode Returns netcode of currently highlighted net.
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Returns the board layer which is in high-contrast.
void SetDefaultPenWidth(int aWidth)
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
void SetActiveLayer(PCB_LAYER_ID aLayer)
std::set< int > m_highlightNetcodes
void SetPrintDC(wxDC *aDC)
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
void SetShowPageLimits(bool aDraw)
COLOR4D is the color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:100