KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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 <lset.h>
33#include <memory>
34
35#include <wx/dc.h>
36
37class COLOR_SETTINGS;
38
39namespace KIGFX
40{
41class VIEW_ITEM;
42
57{
58public:
60 virtual ~RENDER_SETTINGS();
61
62 virtual void LoadColors( const COLOR_SETTINGS* aSettings ) { }
63
70 inline void SetLayerIsHighContrast( int aLayerId, bool aEnabled = true )
71 {
72 if( aEnabled )
73 m_highContrastLayers.insert( aLayerId );
74 else
75 m_highContrastLayers.erase( aLayerId );
76 }
77
83 inline bool GetLayerIsHighContrast( int aLayerId ) const
84 {
85 return ( m_highContrastLayers.count( aLayerId ) > 0 );
86 }
87
91 const std::set<int> GetHighContrastLayers() const
92 {
94 }
95
103 {
104 for( int layer : m_highContrastLayers )
105 {
106 if( layer >= PCBNEW_LAYER_ID_START && layer < PCB_LAYER_ID_COUNT )
107 return (PCB_LAYER_ID) layer;
108 }
109
110 return UNDEFINED_LAYER;
111 }
112
114 void SetActiveLayer( PCB_LAYER_ID aLayer ) { m_activeLayer = aLayer; }
115
116 const wxString& GetLayerName() const { return m_layerName; }
117 void SetLayerName( const wxString& aLayerName ) { m_layerName = aLayerName; }
118
120 void SetPrintLayers( LSET aLayerSet ) { m_printLayers = aLayerSet; }
121
126 {
127 m_highContrastLayers.clear();
128 }
129
135 inline bool IsHighlightEnabled() const
136 {
137 return m_highlightEnabled;
138 }
139
145 inline const std::set<int>& GetHighlightNetCodes() const
146 {
147 return m_highlightNetcodes;
148 }
149
159 inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
160 {
161 m_highlightEnabled = aEnabled;
162
163 if( aEnabled )
164 {
165 if( !aMulti )
166 m_highlightNetcodes.clear();
167
168 m_highlightNetcodes.insert( aNetcode );
169 }
170 else
171 m_highlightNetcodes.clear();
172 }
173
179 inline void SetHighlight( std::set<int>& aHighlight, bool aEnabled = true )
180 {
181 m_highlightEnabled = aEnabled;
182
183 if( aEnabled )
184 m_highlightNetcodes = aHighlight;
185 else
186 m_highlightNetcodes.clear();
187 }
188
192 void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
193 bool GetHighContrast() const { return m_hiContrastEnabled; }
194
195 void SetDrawBoundingBoxes( bool aEnabled ) { m_drawBoundingBoxes = aEnabled; }
197
206 virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
207
209
210 int GetDefaultPenWidth() const { return m_defaultPenWidth; }
211 void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
212
213 int GetMinPenWidth() const { return m_minPenWidth; }
214 void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
215
216 double GetDashLengthRatio() const { return m_dashLengthRatio; }
217 void SetDashLengthRatio( double aRatio ) { m_dashLengthRatio = aRatio; }
218 double GetDashLength( int aLineWidth ) const;
219 double GetDotLength( int aLineWidth ) const;
220
221 double GetGapLengthRatio() const { return m_gapLengthRatio; }
222 void SetGapLengthRatio( double aRatio ) { m_gapLengthRatio = aRatio; }
223 double GetGapLength( int aLineWidth ) const;
224
225 virtual bool GetShowPageLimits() const { return true; }
226
227 bool IsPrinting() const { return m_isPrinting; }
228 void SetIsPrinting( bool isPrinting ) { m_isPrinting = isPrinting; }
229
231 void SetPrintBlackAndWhite( bool aPrintBlackAndWhite )
232 {
233 m_printBlackAndWite = aPrintBlackAndWhite;
234 }
235
237 {
239 }
240
244 virtual const COLOR4D& GetBackgroundColor() const = 0;
245
249 virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
250
254 virtual const COLOR4D& GetGridColor() = 0;
255
259 virtual const COLOR4D& GetCursorColor() = 0;
260
266 inline const COLOR4D& GetLayerColor( int aLayer ) const
267 {
268 // We don't (yet?) have a separate color for intersheet refs
269 if( aLayer == LAYER_INTERSHEET_REFS )
270 aLayer = LAYER_GLOBLABEL;
271
272 return m_layerColors[aLayer];
273 }
274
281 inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
282 {
283 m_layerColors[aLayer] = aColor;
284
285 update(); // recompute other shades of the color
286 }
287
288 virtual bool IsBackgroundDark() const
289 {
290 return false;
291 }
292
298 void SetOutlineWidth( float aWidth ) { m_outlineWidth = aWidth; }
299 float GetOutlineWidth() const { return m_outlineWidth; }
300
301 void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
302 void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
303
304 void SetDefaultFont( const wxString& aFont ) { m_defaultFont = aFont; }
305 const wxString& GetDefaultFont() const { return m_defaultFont; }
306
307 // TODO: these can go away once the drawing sheet is moved to Cairo-based printing
308 wxDC* GetPrintDC() const { return m_printDC; }
309 void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
310
311protected:
316 virtual void update();
317
318 PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
319 wxString m_layerName;
320 std::set<int> m_highContrastLayers; // High-contrast layers (both board layers and
321 // synthetic GAL layers)
323 COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
324 COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
325
326 COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
327 COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
328
329 COLOR4D m_backgroundColor; // The background color
330
332 bool m_hiContrastEnabled; // High contrast display mode on/off
333 float m_hiContrastFactor; // Factor used for computing high contrast color
334
335 bool m_highlightEnabled; // Highlight display mode on/off
336 std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
337 float m_highlightFactor; // Factor used for computing highlight color
338
339 bool m_drawBoundingBoxes; // Visual aid for debugging
340
341 float m_selectFactor; // Specifies how color of selected items is changed
342 float m_outlineWidth; // Line width used when drawing outlines
343 float m_drawingSheetLineWidth;// Line width used for borders and titleblock
344
346 int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
347 // lines. This sets an absolute minimum.
350
352
353 bool m_isPrinting; // true when draw to a printer
354 bool m_printBlackAndWite; // true if black and white printing is requested: some
355 // backgrounds are not printed to avoid not visible items
357
358 wxDC* m_printDC; // This can go away once the drawing sheet is moved to
359 // Cairo-based printing.
360};
361
362}
363
364#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 GetOutlineWidth() const
const std::set< int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
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
void SetPrintBlackAndWhite(bool aPrintBlackAndWhite)
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Set the background color.
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
bool PrintBlackAndWhiteReq() 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...
COLOR4D m_layerColorsSel[LAYER_ID_COUNT]
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)
bool IsPrintBlackAndWhite() const
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
std::set< int > m_highContrastLayers
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:84
LSET is a set of PCB_LAYER_IDs.
Definition: lset.h:36
constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START
Definition: layer_ids.h:138
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Definition: layer_ids.h:481
@ LAYER_GLOBLABEL
Definition: layer_ids.h:360
@ LAYER_INTERSHEET_REFS
Definition: layer_ids.h:367
PCB_LAYER_ID
A quick note on layer IDs:
Definition: layer_ids.h:60
@ UNDEFINED_LAYER
Definition: layer_ids.h:61
@ PCB_LAYER_ID_COUNT
Definition: layer_ids.h:135
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247