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 The 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, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef RENDER_SETTINGS_H
21#define RENDER_SETTINGS_H
22
23#include <map>
24#include <set>
25
26#include <gal/color4d.h>
27#include <layer_ids.h>
28#include <lset.h>
29#include <memory>
30
31#include <wx/dc.h>
32
33class COLOR_SETTINGS;
34
35namespace KIGFX
36{
37class VIEW_ITEM;
38
53{
54public:
56 virtual ~RENDER_SETTINGS();
57
58 virtual void LoadColors( const COLOR_SETTINGS* aSettings ) { }
59
66 inline void SetLayerIsHighContrast( int aLayerId, bool aEnabled = true )
67 {
68 if( aEnabled )
69 m_highContrastLayers.insert( aLayerId );
70 else
71 m_highContrastLayers.erase( aLayerId );
72 }
73
79 inline bool GetLayerIsHighContrast( int aLayerId ) const
80 {
81 return ( m_highContrastLayers.count( aLayerId ) > 0 );
82 }
83
87 const std::set<int> GetHighContrastLayers() const
88 {
90 }
91
99 {
100 for( int layer : m_highContrastLayers )
101 {
102 if( layer >= PCBNEW_LAYER_ID_START && layer < PCB_LAYER_ID_COUNT )
103 return (PCB_LAYER_ID) layer;
104 }
105
106 return UNDEFINED_LAYER;
107 }
108
110 void SetActiveLayer( PCB_LAYER_ID aLayer ) { m_activeLayer = aLayer; }
111
112 const wxString& GetLayerName() const { return m_layerName; }
113 void SetLayerName( const wxString& aLayerName ) { m_layerName = aLayerName; }
114
116 void SetPrintLayers( const LSET& aLayerSet ) { m_printLayers = aLayerSet; }
117
122 {
123 m_highContrastLayers.clear();
124 }
125
131 inline bool IsHighlightEnabled() const
132 {
133 return m_highlightEnabled;
134 }
135
141 inline const std::set<int>& GetHighlightNetCodes() const
142 {
143 return m_highlightNetcodes;
144 }
145
156 inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
157 {
158 m_highlightEnabled = aEnabled;
159
160 if( aEnabled )
161 {
162 if( !aMulti )
163 m_highlightNetcodes.clear();
164
165 m_highlightNetcodes.insert( aNetcode );
166 }
167 else
168 m_highlightNetcodes.clear();
169 }
170
176 inline void SetHighlight( std::set<int>& aHighlight, bool aEnabled = true )
177 {
178 m_highlightEnabled = aEnabled;
179
180 if( aEnabled )
181 m_highlightNetcodes = aHighlight;
182 else
183 m_highlightNetcodes.clear();
184 }
185
189 void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
190 bool GetHighContrast() const { return m_hiContrastEnabled; }
191
192 void SetDrawBoundingBoxes( bool aEnabled ) { m_drawBoundingBoxes = aEnabled; }
194
203 virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
204
214 virtual bool GetLayerDim( int aLayer, COLOR4D& aToward, double& aKeep ) const { return false; }
215
220 virtual bool IsDimExempt( const VIEW_ITEM* aItem ) const { return false; }
221
223
224 int GetDefaultPenWidth() const { return m_defaultPenWidth; }
225 void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
226
227 int GetMinPenWidth() const { return m_minPenWidth; }
228 void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
229
230 double GetDashLengthRatio() const { return m_dashLengthRatio; }
231 void SetDashLengthRatio( double aRatio ) { m_dashLengthRatio = aRatio; }
232 double GetDashLength( int aLineWidth ) const;
233 double GetDotLength( int aLineWidth ) const;
234
235 double GetGapLengthRatio() const { return m_gapLengthRatio; }
236 void SetGapLengthRatio( double aRatio ) { m_gapLengthRatio = aRatio; }
237 double GetGapLength( int aLineWidth ) const;
238
239 virtual bool GetShowPageLimits() const { return true; }
240
241 bool IsPrinting() const { return m_isPrinting; }
242 void SetIsPrinting( bool isPrinting ) { m_isPrinting = isPrinting; }
243
245 void SetPrintBlackAndWhite( bool aPrintBlackAndWhite )
246 {
247 m_printBlackAndWite = aPrintBlackAndWhite;
248 }
249
251 {
253 }
254
258 virtual const COLOR4D& GetBackgroundColor() const = 0;
259
263 virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
264
268 virtual const COLOR4D& GetGridColor() = 0;
269
273 virtual const COLOR4D& GetCursorColor() = 0;
274
280 inline const COLOR4D& GetLayerColor( int aLayer ) const
281 {
282 // We don't (yet?) have a separate color for intersheet refs
283 if( aLayer == LAYER_INTERSHEET_REFS )
284 aLayer = LAYER_GLOBLABEL;
285
286 return m_layerColors.count( aLayer ) ? m_layerColors.at( aLayer ) : COLOR4D::BLACK;
287 }
288
295 inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
296 {
297 m_layerColors[aLayer] = aColor;
298
299 update(); // recompute other shades of the color
300 }
301
302 virtual bool IsBackgroundDark() const
303 {
304 return false;
305 }
306
312 void SetOutlineWidth( float aWidth ) { m_outlineWidth = aWidth; }
313 float GetOutlineWidth() const { return m_outlineWidth; }
314
315 void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
316 void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
317
318 void SetDefaultFont( const wxString& aFont ) { m_defaultFont = aFont; }
319 const wxString& GetDefaultFont() const { return m_defaultFont; }
320
321 // TODO: these can go away once the drawing sheet is moved to Cairo-based printing
322 wxDC* GetPrintDC() const { return m_printDC; }
323 void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
324
325protected:
330 virtual void update();
331
332 PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
333 wxString m_layerName;
334 std::set<int> m_highContrastLayers; // High-contrast layers (both board layers and
335 // synthetic GAL layers)
336 std::map<int, COLOR4D> m_layerColors; // Layer colors
337 std::map<int, COLOR4D> m_layerColorsHi; // Layer colors for highlighted objects
338 std::map<int, COLOR4D> m_layerColorsSel; // Layer colors for selected objects
339 std::map<int, COLOR4D> m_hiContrastColor; // High-contrast mode layer colors
340 std::map<int, COLOR4D> m_layerColorsDark; // Darkened layer colors (for high-contrast mode)
341
342 COLOR4D m_backgroundColor; // The background color
343
345 bool m_hiContrastEnabled; // High contrast display mode on/off
346 float m_hiContrastFactor; // Factor used for computing high contrast color
347
348 bool m_highlightEnabled; // Highlight display mode on/off
349 std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
350 float m_highlightFactor; // Factor used for computing highlight color
351
352 bool m_drawBoundingBoxes; // Visual aid for debugging
353
354 float m_selectFactor; // Specifies how color of selected items is changed
355 float m_outlineWidth; // Line width used when drawing outlines
356 float m_drawingSheetLineWidth;// Line width used for borders and titleblock
357
359 int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
360 // lines. This sets an absolute minimum.
363
365
366 bool m_isPrinting; // true when draw to a printer
367 bool m_printBlackAndWite; // true if black and white printing is requested: some
368 // backgrounds are not printed to avoid not visible items
370
371 wxDC* m_printDC; // This can go away once the drawing sheet is moved to
372 // Cairo-based printing.
373};
374
375}
376
377#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:101
static const COLOR4D BLACK
Definition color4d.h:404
void SetOutlineWidth(float aWidth)
Set line width used for drawing outlines.
void SetDrawBoundingBoxes(bool aEnabled)
virtual bool IsBackgroundDark() const
const std::set< int > & GetHighlightNetCodes() const
Return the netcode of currently highlighted net.
virtual bool IsDimExempt(const VIEW_ITEM *aItem) const
Return true for an item that keeps its colour on a layer the canvas fades, such as a selected item in...
double GetGapLength(int aLineWidth) 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 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)
void SetPrintLayers(const LSET &aLayerSet)
virtual void SetBackgroundColor(const COLOR4D &aColor)=0
Set the background color.
bool PrintBlackAndWhiteReq() const
virtual bool GetLayerDim(int aLayer, COLOR4D &aToward, double &aKeep) const
Get how the canvas fades a whole layer, see GAL::SetSceneLayerDim().
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...
double GetDotLength(int aLineWidth) const
std::map< int, COLOR4D > m_layerColorsHi
virtual void update()
Precalculates extra colors for layers (e.g.
bool IsHighlightEnabled() const
Return current highlight setting.
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.
void SetMinPenWidth(int aWidth)
void SetIsPrinting(bool isPrinting)
void SetSelectFactor(float aFactor)
bool IsPrintBlackAndWhite() const
std::map< int, COLOR4D > m_hiContrastColor
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
std::map< int, COLOR4D > m_layerColorsDark
std::map< int, COLOR4D > m_layerColorsSel
std::set< int > m_highContrastLayers
void SetHighlight(std::set< int > &aHighlight, bool aEnabled=true)
Turns on highlighting and highlights multiple nets.
std::map< int, COLOR4D > m_layerColors
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:82
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START
Definition layer_ids.h:170
@ LAYER_GLOBLABEL
Definition layer_ids.h:484
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:491
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ UNDEFINED_LAYER
Definition layer_ids.h:57
@ PCB_LAYER_ID_COUNT
Definition layer_ids.h:167
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:30