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-2020 KiCad Developers, see AUTHORS.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>
31 #include <layer_ids.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 
56 {
57 public:
59  virtual ~RENDER_SETTINGS();
60 
61  virtual void LoadColors( const COLOR_SETTINGS* aSettings ) { }
62 
69  inline void SetLayerIsHighContrast( int aLayerId, bool aEnabled = true )
70  {
71  if( aEnabled )
72  m_highContrastLayers.insert( aLayerId );
73  else
74  m_highContrastLayers.erase( aLayerId );
75  }
76 
82  inline bool GetLayerIsHighContrast( int aLayerId ) const
83  {
84  return ( m_highContrastLayers.count( aLayerId ) > 0 );
85  }
86 
90  const std::set<unsigned int> GetHighContrastLayers() const
91  {
92  return m_highContrastLayers;
93  }
94 
102  {
103  for( int layer : m_highContrastLayers )
104  {
105  if( layer >= PCBNEW_LAYER_ID_START && layer < PCB_LAYER_ID_COUNT )
106  return (PCB_LAYER_ID) layer;
107  }
108 
109  return UNDEFINED_LAYER;
110  }
111 
113  void SetActiveLayer( PCB_LAYER_ID aLayer ) { m_activeLayer = aLayer; }
114 
119  {
120  m_highContrastLayers.clear();
121  }
122 
128  inline bool IsHighlightEnabled() const
129  {
130  return m_highlightEnabled;
131  }
132 
138  inline const std::set<int>& GetHighlightNetCodes() const
139  {
140  return m_highlightNetcodes;
141  }
142 
152  inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
153  {
154  m_highlightEnabled = aEnabled;
155 
156  if( aEnabled )
157  {
158  if( !aMulti )
159  m_highlightNetcodes.clear();
160 
161  m_highlightNetcodes.insert( aNetcode );
162  }
163  else
164  m_highlightNetcodes.clear();
165  }
166 
172  inline void SetHighlight( std::set<int>& aHighlight, bool aEnabled = true )
173  {
174  m_highlightEnabled = aEnabled;
175 
176  if( aEnabled )
177  m_highlightNetcodes = aHighlight;
178  else
179  m_highlightNetcodes.clear();
180  }
181 
185  void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
186  bool GetHighContrast() const { return m_hiContrastEnabled; }
187 
196  virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
197 
199 
200  int GetDefaultPenWidth() const { return m_defaultPenWidth; }
201  void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
202 
203  int GetMinPenWidth() const { return m_minPenWidth; }
204  void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
205 
206  bool GetShowPageLimits() const { return m_showPageLimits; }
207  void SetShowPageLimits( bool aDraw ) { m_showPageLimits = aDraw; }
208 
209  bool IsPrinting() const { return m_isPrinting; }
210  void SetIsPrinting( bool isPrinting ) { m_isPrinting = isPrinting; }
211 
215  virtual const COLOR4D& GetBackgroundColor() = 0;
216 
220  virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
221 
225  virtual const COLOR4D& GetGridColor() = 0;
226 
230  virtual const COLOR4D& GetCursorColor() = 0;
231 
237  inline const COLOR4D& GetLayerColor( int aLayer ) const
238  {
239  return m_layerColors[aLayer];
240  }
241 
248  inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
249  {
250  m_layerColors[aLayer] = aColor;
251 
252  update(); // recompute other shades of the color
253  }
254 
255  virtual bool IsBackgroundDark() const
256  {
257  return false;
258  }
259 
265  void SetOutlineWidth( float aWidth )
266  {
267  m_outlineWidth = aWidth;
268  }
269 
270  void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
271  void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
272  void SetHighContrastFactor( float aFactor ) { m_hiContrastFactor = aFactor; }
273 
274  // TODO: these can go away once the drawing sheet is moved to Cairo-based printing
275  wxDC* GetPrintDC() const { return m_printDC; }
276  void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
277 
278 protected:
283  virtual void update();
284 
285  PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
286  std::set<unsigned int> m_highContrastLayers; // High-contrast layers (both board layers and
287  // synthetic GAL layers)
289  COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
290  COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
291 
292  COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
293  COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
294 
295  COLOR4D m_backgroundColor; // The background color
296 
298  bool m_hiContrastEnabled; // High contrast display mode on/off
299  float m_hiContrastFactor; // Factor used for computing high contrast color
300 
301  bool m_highlightEnabled; // Highlight display mode on/off
302  std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
303  float m_highlightFactor; // Factor used for computing highlight color
304 
305  float m_selectFactor; // Specifies how color of selected items is changed
306  float m_outlineWidth; // Line width used when drawing outlines
307  float m_drawingSheetLineWidth;// Line width used for borders and titleblock
308 
310  int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
311  // lines. This sets an absolute minimum.
314 
315  wxDC* m_printDC; // This can go away once the drawing sheet is moved to
316  // Cairo-based printing.
317 };
318 
319 }
320 
321 #endif /* RENDER_SETTINGS_H */
const std::set< unsigned int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
virtual const COLOR4D & GetGridColor()=0
Return current grid 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.
virtual const COLOR4D & GetCursorColor()=0
Return current cursor color settings.
COLOR4D m_layerColorsHi[LAYER_ID_COUNT]
COLOR4D m_layerColors[LAYER_ID_COUNT]
virtual const COLOR4D & GetBackgroundColor()=0
Return current background color settings.
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
void SetHighlight(std::set< int > &aHighlight, bool aEnabled=true)
Turns on highlighting and highlights multiple nets.
bool GetShowPageLimits() const
bool IsHighlightEnabled() const
Return current highlight setting.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:76
float GetDrawingSheetLineWidth() const
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]
void SetHighContrastFactor(float aFactor)
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
bool m_hiContrastEnabled
Parameters for display modes.
virtual void update()
Precalculates extra colors for layers (e.g.
void SetMinPenWidth(int aWidth)
void SetHighContrast(bool aEnabled)
Turns on/off high contrast display mode.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
bool GetLayerIsHighContrast(int aLayerId) const
Return information whether the queried layer is marked as high-contrast.
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Set the specified layer as high-contrast.
wxDC * GetPrintDC() const
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
Set the background color.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:65
void SetIsPrinting(bool isPrinting)
void SetSelectFactor(float aFactor)
void SetHighlightFactor(float aFactor)
PCB_LAYER_ID GetActiveLayer() const
void ClearHighContrastLayers()
Clear 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
Return the netcode of currently highlighted net.
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
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)
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Definition: layer_ids.h:424
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
void SetShowPageLimits(bool aDraw)
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:103