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 class EDA_ITEM;
35 class COLOR_SETTINGS;
36 
37 namespace KIGFX
38 {
39 class VIEW_ITEM;
40 
53 {
54 public:
56  virtual ~RENDER_SETTINGS();
57 
58  virtual void LoadColors( const COLOR_SETTINGS* aSettings ) { }
59 
67  inline void SetActiveLayer( int aLayerId, bool aEnabled = true )
68  {
69  if( aEnabled )
70  m_activeLayers.insert( aLayerId );
71  else
72  m_activeLayers.erase( aLayerId );
73  }
74 
80  const std::set<unsigned int> GetActiveLayers() const
81  {
82  return m_activeLayers;
83  }
84 
89  inline void ClearActiveLayers()
90  {
91  m_activeLayers.clear();
92  }
93 
99  inline bool IsActiveLayer( int aLayerId ) const
100  {
101  return ( m_activeLayers.count( aLayerId ) > 0 );
102  }
103 
109  inline bool IsHighlightEnabled() const
110  {
111  return m_highlightEnabled;
112  }
113 
119  inline const std::set<int>& GetHighlightNetCodes() const
120  {
121  return m_highlightNetcodes;
122  }
123 
131  inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
132  {
133  m_highlightEnabled = aEnabled;
134 
135  if( aEnabled )
136  {
137  if( !aMulti )
138  m_highlightNetcodes.clear();
139 
140  m_highlightNetcodes.insert( aNetcode );
141  }
142  else
143  m_highlightNetcodes.clear();
144  }
145 
150  void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
151  bool GetHighContrast() const { return m_hiContrastEnabled; }
152 
161  virtual const COLOR4D& GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
162 
163  float GetWorksheetLineWidth() const { return m_worksheetLineWidth; }
164 
165  int GetDefaultPenWidth() const { return m_defaultPenWidth; }
166  void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
167 
168  bool GetShowPageLimits() const { return m_showPageLimits; }
169  void SetShowPageLimits( bool aDraw ) { m_showPageLimits = aDraw; }
170 
175  virtual const COLOR4D& GetBackgroundColor() = 0;
176 
180  virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
181 
186  virtual const COLOR4D& GetGridColor() = 0;
187 
192  virtual const COLOR4D& GetCursorColor() = 0;
193 
199  inline const COLOR4D& GetLayerColor( int aLayer ) const
200  {
201  return m_layerColors[aLayer];
202  }
203 
210  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
211  {
212  m_layerColors[aLayer] = aColor;
213 
214  update(); // recompute other shades of the color
215  }
216 
217  virtual bool IsBackgroundDark() const
218  {
219  return false;
220  }
221 
227  void SetOutlineWidth( float aWidth )
228  {
229  m_outlineWidth = aWidth;
230  }
231 
232  // TODO: these can go away once we have Cairo-based printing
233  wxDC* GetPrintDC() { return m_printDC; }
234  void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
235 
236 protected:
242  virtual void update();
243 
244  std::set<unsigned int> m_activeLayers;
245 
247  COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
248  COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
249 
250  COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
251  COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
252 
253  COLOR4D m_backgroundColor; // The background color
254 
256  bool m_hiContrastEnabled; // High contrast display mode on/off
257  float m_hiContrastFactor; // Factor used for computing high contrast color
258 
259  bool m_highlightEnabled; // Highlight display mode on/off
260  std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
261  float m_highlightFactor; // Factor used for computing highlight color
262 
263  float m_selectFactor; // Specifies how color of selected items is changed
264  float m_outlineWidth; // Line width used when drawing outlines
265  float m_worksheetLineWidth; // Line width used when drawing worksheet
266 
269 
270  wxDC* m_printDC; // This can go away once we have Cairo-based printing.
271 };
272 
273 }
274 
275 #endif /* RENDER_SETTINGS_H */
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 IsActiveLayer(int aLayerId) const
Function IsActiveLayer Returns information whether the queried layer is marked as active.
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
void SetActiveLayer(int aLayerId, bool aEnabled=true)
Function SetActiveLayer Sets the specified layer as active - it means that it can be drawn in a speci...
virtual const COLOR4D & GetColor(const VIEW_ITEM *aItem, int aLayer) const =0
Function GetColor Returns the color that should be used to draw the specific VIEW_ITEM on the specifi...
COLOR4D m_hiContrastColor[LAYER_ID_COUNT]
std::set< unsigned int > m_activeLayers
Stores active layers number.
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
void ClearActiveLayers()
Function ClearActiveLayers Clears the list of active layers.
bool m_hiContrastEnabled
Parameters for display modes.
virtual void update()
Function update Precalculates extra colors for layers (e.g.
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.
const std::set< unsigned int > GetActiveLayers() const
Function GetActiveLayers() Returns the set of currently active layers.
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
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
EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boards.
Definition: base_struct.h:159
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.
void SetDefaultPenWidth(int aWidth)
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
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:99