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
206
207 int GetDefaultPenWidth() const { return m_defaultPenWidth; }
208 void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
209
210 int GetMinPenWidth() const { return m_minPenWidth; }
211 void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
212
213 double GetDashLengthRatio() const { return m_dashLengthRatio; }
214 void SetDashLengthRatio( double aRatio ) { m_dashLengthRatio = aRatio; }
215 double GetDashLength( int aLineWidth ) const;
216 double GetDotLength( int aLineWidth ) const;
217
218 double GetGapLengthRatio() const { return m_gapLengthRatio; }
219 void SetGapLengthRatio( double aRatio ) { m_gapLengthRatio = aRatio; }
220 double GetGapLength( int aLineWidth ) const;
221
222 virtual bool GetShowPageLimits() const { return true; }
223
224 bool IsPrinting() const { return m_isPrinting; }
225 void SetIsPrinting( bool isPrinting ) { m_isPrinting = isPrinting; }
226
228 void SetPrintBlackAndWhite( bool aPrintBlackAndWhite )
229 {
230 m_printBlackAndWite = aPrintBlackAndWhite;
231 }
232
234 {
236 }
237
241 virtual const COLOR4D& GetBackgroundColor() const = 0;
242
246 virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
247
251 virtual const COLOR4D& GetGridColor() = 0;
252
256 virtual const COLOR4D& GetCursorColor() = 0;
257
263 inline const COLOR4D& GetLayerColor( int aLayer ) const
264 {
265 // We don't (yet?) have a separate color for intersheet refs
266 if( aLayer == LAYER_INTERSHEET_REFS )
267 aLayer = LAYER_GLOBLABEL;
268
269 return m_layerColors.count( aLayer ) ? m_layerColors.at( aLayer ) : COLOR4D::BLACK;
270 }
271
278 inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
279 {
280 m_layerColors[aLayer] = aColor;
281
282 update(); // recompute other shades of the color
283 }
284
285 virtual bool IsBackgroundDark() const
286 {
287 return false;
288 }
289
295 void SetOutlineWidth( float aWidth ) { m_outlineWidth = aWidth; }
296 float GetOutlineWidth() const { return m_outlineWidth; }
297
298 void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
299 void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
300
301 void SetDefaultFont( const wxString& aFont ) { m_defaultFont = aFont; }
302 const wxString& GetDefaultFont() const { return m_defaultFont; }
303
304 // TODO: these can go away once the drawing sheet is moved to Cairo-based printing
305 wxDC* GetPrintDC() const { return m_printDC; }
306 void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
307
308protected:
313 virtual void update();
314
315 PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
316 wxString m_layerName;
317 std::set<int> m_highContrastLayers; // High-contrast layers (both board layers and
318 // synthetic GAL layers)
319 std::map<int, COLOR4D> m_layerColors; // Layer colors
320 std::map<int, COLOR4D> m_layerColorsHi; // Layer colors for highlighted objects
321 std::map<int, COLOR4D> m_layerColorsSel; // Layer colors for selected objects
322 std::map<int, COLOR4D> m_hiContrastColor; // High-contrast mode layer colors
323 std::map<int, COLOR4D> m_layerColorsDark; // Darkened layer colors (for high-contrast mode)
324
325 COLOR4D m_backgroundColor; // The background color
326
328 bool m_hiContrastEnabled; // High contrast display mode on/off
329 float m_hiContrastFactor; // Factor used for computing high contrast color
330
331 bool m_highlightEnabled; // Highlight display mode on/off
332 std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
333 float m_highlightFactor; // Factor used for computing highlight color
334
335 bool m_drawBoundingBoxes; // Visual aid for debugging
336
337 float m_selectFactor; // Specifies how color of selected items is changed
338 float m_outlineWidth; // Line width used when drawing outlines
339 float m_drawingSheetLineWidth;// Line width used for borders and titleblock
340
342 int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
343 // lines. This sets an absolute minimum.
346
348
349 bool m_isPrinting; // true when draw to a printer
350 bool m_printBlackAndWite; // true if black and white printing is requested: some
351 // backgrounds are not printed to avoid not visible items
353
354 wxDC* m_printDC; // This can go away once the drawing sheet is moved to
355 // Cairo-based printing.
356};
357
358}
359
360#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.
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 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:478
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:485
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