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-2022 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
36class COLOR_SETTINGS;
37
38namespace KIGFX
39{
40class VIEW_ITEM;
41
56{
57public:
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 {
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
115 const wxString& GetLayerName() const { return m_layerName; }
116 void SetLayerName( const wxString& aLayerName ) { m_layerName = aLayerName; }
117
119 void SetPrintLayers( LSET aLayerSet ) { m_printLayers = aLayerSet; }
120
125 {
126 m_highContrastLayers.clear();
127 }
128
134 inline bool IsHighlightEnabled() const
135 {
136 return m_highlightEnabled;
137 }
138
144 inline const std::set<int>& GetHighlightNetCodes() const
145 {
146 return m_highlightNetcodes;
147 }
148
158 inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
159 {
160 m_highlightEnabled = aEnabled;
161
162 if( aEnabled )
163 {
164 if( !aMulti )
165 m_highlightNetcodes.clear();
166
167 m_highlightNetcodes.insert( aNetcode );
168 }
169 else
170 m_highlightNetcodes.clear();
171 }
172
178 inline void SetHighlight( std::set<int>& aHighlight, bool aEnabled = true )
179 {
180 m_highlightEnabled = aEnabled;
181
182 if( aEnabled )
183 m_highlightNetcodes = aHighlight;
184 else
185 m_highlightNetcodes.clear();
186 }
187
191 void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
192 bool GetHighContrast() const { return m_hiContrastEnabled; }
193
194 void SetDrawBoundingBoxes( bool aEnabled ) { m_drawBoundingBoxes = aEnabled; }
196
205 virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
206
208
209 int GetDefaultPenWidth() const { return m_defaultPenWidth; }
210 void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
211
212 int GetMinPenWidth() const { return m_minPenWidth; }
213 void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
214
215 double GetDashLengthRatio() const { return m_dashLengthRatio; }
216 void SetDashLengthRatio( double aRatio ) { m_dashLengthRatio = aRatio; }
217 double GetDashLength( int aLineWidth ) const;
218 double GetDotLength( int aLineWidth ) const;
219
220 double GetGapLengthRatio() const { return m_gapLengthRatio; }
221 void SetGapLengthRatio( double aRatio ) { m_gapLengthRatio = aRatio; }
222 double GetGapLength( int aLineWidth ) const;
223
224 virtual bool GetShowPageLimits() const { return true; }
225
226 bool IsPrinting() const { return m_isPrinting; }
227 void SetIsPrinting( bool isPrinting ) { m_isPrinting = isPrinting; }
228
232 virtual const COLOR4D& GetBackgroundColor() const = 0;
233
237 virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
238
242 virtual const COLOR4D& GetGridColor() = 0;
243
247 virtual const COLOR4D& GetCursorColor() = 0;
248
254 inline const COLOR4D& GetLayerColor( int aLayer ) const
255 {
256 // We don't (yet?) have a separate color for intersheet refs
257 if( aLayer == LAYER_INTERSHEET_REFS )
258 aLayer = LAYER_GLOBLABEL;
259
260 return m_layerColors[aLayer];
261 }
262
269 inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
270 {
271 m_layerColors[aLayer] = aColor;
272
273 update(); // recompute other shades of the color
274 }
275
276 virtual bool IsBackgroundDark() const
277 {
278 return false;
279 }
280
286 void SetOutlineWidth( float aWidth )
287 {
288 m_outlineWidth = aWidth;
289 }
290
291 void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
292 void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
293
294 void SetDefaultFont( const wxString& aFont ) { m_defaultFont = aFont; }
295 const wxString& GetDefaultFont() const { return m_defaultFont; }
296
297 // TODO: these can go away once the drawing sheet is moved to Cairo-based printing
298 wxDC* GetPrintDC() const { return m_printDC; }
299 void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
300
301protected:
306 virtual void update();
307
308 PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
309 wxString m_layerName;
310 std::set<unsigned int> m_highContrastLayers; // High-contrast layers (both board layers and
311 // synthetic GAL layers)
313 COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
314 COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
315
316 COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
317 COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
318
319 COLOR4D m_backgroundColor; // The background color
320
322 bool m_hiContrastEnabled; // High contrast display mode on/off
323 float m_hiContrastFactor; // Factor used for computing high contrast color
324
325 bool m_highlightEnabled; // Highlight display mode on/off
326 std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
327 float m_highlightFactor; // Factor used for computing highlight color
328
329 bool m_drawBoundingBoxes; // Visual aid for debugging
330
331 float m_selectFactor; // Specifies how color of selected items is changed
332 float m_outlineWidth; // Line width used when drawing outlines
333 float m_drawingSheetLineWidth;// Line width used for borders and titleblock
334
336 int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
337 // lines. This sets an absolute minimum.
340
342
345
346 wxDC* m_printDC; // This can go away once the drawing sheet is moved to
347 // Cairo-based printing.
348};
349
350}
351
352#endif /* RENDER_SETTINGS_H */
Color settings are a bit different than most of the settings objects in that there can be more than o...
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
void SetOutlineWidth(float aWidth)
Set line width used for drawing outlines.
void SetDrawBoundingBoxes(bool aEnabled)
virtual bool IsBackgroundDark() const
COLOR4D m_hiContrastColor[LAYER_ID_COUNT]
const std::set< int > & GetHighlightNetCodes() const
Return the netcode of currently highlighted net.
double GetGapLength(int aLineWidth) const
int GetDefaultPenWidth() const
double GetGapLengthRatio() const
void SetDefaultPenWidth(int aWidth)
void ClearHighContrastLayers()
Clear the list of active layers.
void SetLayerColor(int aLayer, const COLOR4D &aColor)
Change the color used to draw a layer.
virtual const COLOR4D & GetGridColor()=0
Return current grid color settings.
void SetHighContrast(bool aEnabled)
Turns on/off high contrast display mode.
virtual void LoadColors(const COLOR_SETTINGS *aSettings)
float GetDrawingSheetLineWidth() const
void SetPrintLayers(LSET aLayerSet)
void SetDefaultFont(const wxString &aFont)
PCB_LAYER_ID GetPrimaryHighContrastLayer() const
Return the board layer which is in high-contrast mode.
void SetActiveLayer(PCB_LAYER_ID aLayer)
void SetGapLengthRatio(double aRatio)
const wxString & GetDefaultFont() const
const COLOR4D & GetLayerColor(int aLayer) const
Return the color used to draw a layer.
PCB_LAYER_ID GetActiveLayer() const
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Set the background color.
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
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...
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
std::set< unsigned int > m_highContrastLayers
double GetDotLength(int aLineWidth) const
COLOR4D m_layerColorsHi[LAYER_ID_COUNT]
virtual void update()
Precalculates extra colors for layers (e.g.
bool IsHighlightEnabled() const
Return current highlight setting.
bool GetHighContrast() const
void SetLayerName(const wxString &aLayerName)
void SetDashLengthRatio(double aRatio)
void SetPrintDC(wxDC *aDC)
void SetHighlightFactor(float aFactor)
virtual const COLOR4D & GetBackgroundColor() const =0
Return current background color settings.
COLOR4D m_layerColors[LAYER_ID_COUNT]
void SetMinPenWidth(int aWidth)
void SetIsPrinting(bool isPrinting)
void SetSelectFactor(float aFactor)
const std::set< unsigned int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
void SetLayerIsHighContrast(int aLayerId, bool aEnabled=true)
Set the specified layer as high-contrast.
const wxString & GetLayerName() const
bool GetLayerIsHighContrast(int aLayerId) const
Return information whether the queried layer is marked as high-contrast.
std::set< int > m_highlightNetcodes
virtual const COLOR4D & GetCursorColor()=0
Return current cursor color settings.
double GetDashLength(int aLineWidth) const
wxDC * GetPrintDC() const
void SetHighlight(std::set< int > &aHighlight, bool aEnabled=true)
Turns on highlighting and highlights multiple nets.
bool m_hiContrastEnabled
Parameters for display modes.
void SetHighlight(bool aEnabled, int aNetcode=-1, bool aMulti=false)
Turns on/off highlighting.
virtual bool GetShowPageLimits() const
double GetDashLengthRatio() const
bool GetDrawBoundingBoxes() const
An abstract base class for deriving all objects that can be added to a VIEW.
Definition: view_item.h:77
LSET is a set of PCB_LAYER_IDs.
Definition: layer_ids.h:530
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Definition: layer_ids.h:449
@ LAYER_GLOBLABEL
Definition: layer_ids.h:348
@ LAYER_INTERSHEET_REFS
Definition: layer_ids.h:355
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:59
@ PCBNEW_LAYER_ID_START
Definition: layer_ids.h:63
@ UNDEFINED_LAYER
Definition: layer_ids.h:60
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:137
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266