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
155 inline void SetHighlight( bool aEnabled, int aNetcode = -1, bool aMulti = false )
156 {
157 m_highlightEnabled = aEnabled;
158
159 if( aEnabled )
160 {
161 if( !aMulti )
162 m_highlightNetcodes.clear();
163
164 m_highlightNetcodes.insert( aNetcode );
165 }
166 else
167 m_highlightNetcodes.clear();
168 }
169
175 inline void SetHighlight( std::set<int>& aHighlight, bool aEnabled = true )
176 {
177 m_highlightEnabled = aEnabled;
178
179 if( aEnabled )
180 m_highlightNetcodes = aHighlight;
181 else
182 m_highlightNetcodes.clear();
183 }
184
188 void SetHighContrast( bool aEnabled ) { m_hiContrastEnabled = aEnabled; }
189 bool GetHighContrast() const { return m_hiContrastEnabled; }
190
191 void SetDrawBoundingBoxes( bool aEnabled ) { m_drawBoundingBoxes = aEnabled; }
193
202 virtual COLOR4D GetColor( const VIEW_ITEM* aItem, int aLayer ) const = 0;
203
205
206 int GetDefaultPenWidth() const { return m_defaultPenWidth; }
207 void SetDefaultPenWidth( int aWidth ) { m_defaultPenWidth = aWidth; }
208
209 int GetMinPenWidth() const { return m_minPenWidth; }
210 void SetMinPenWidth( int aWidth ) { m_minPenWidth = aWidth; }
211
212 double GetDashLengthRatio() const { return m_dashLengthRatio; }
213 void SetDashLengthRatio( double aRatio ) { m_dashLengthRatio = aRatio; }
214 double GetDashLength( int aLineWidth ) const;
215 double GetDotLength( int aLineWidth ) const;
216
217 double GetGapLengthRatio() const { return m_gapLengthRatio; }
218 void SetGapLengthRatio( double aRatio ) { m_gapLengthRatio = aRatio; }
219 double GetGapLength( int aLineWidth ) const;
220
221 virtual bool GetShowPageLimits() const { return true; }
222
223 bool IsPrinting() const { return m_isPrinting; }
224 void SetIsPrinting( bool isPrinting ) { m_isPrinting = isPrinting; }
225
227 void SetPrintBlackAndWhite( bool aPrintBlackAndWhite )
228 {
229 m_printBlackAndWite = aPrintBlackAndWhite;
230 }
231
233 {
235 }
236
240 virtual const COLOR4D& GetBackgroundColor() const = 0;
241
245 virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
246
250 virtual const COLOR4D& GetGridColor() = 0;
251
255 virtual const COLOR4D& GetCursorColor() = 0;
256
262 inline const COLOR4D& GetLayerColor( int aLayer ) const
263 {
264 // We don't (yet?) have a separate color for intersheet refs
265 if( aLayer == LAYER_INTERSHEET_REFS )
266 aLayer = LAYER_GLOBLABEL;
267
268 return m_layerColors.count( aLayer ) ? m_layerColors.at( aLayer ) : COLOR4D::BLACK;
269 }
270
277 inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
278 {
279 m_layerColors[aLayer] = aColor;
280
281 update(); // recompute other shades of the color
282 }
283
284 virtual bool IsBackgroundDark() const
285 {
286 return false;
287 }
288
294 void SetOutlineWidth( float aWidth ) { m_outlineWidth = aWidth; }
295 float GetOutlineWidth() const { return m_outlineWidth; }
296
297 void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
298 void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
299
300 void SetDefaultFont( const wxString& aFont ) { m_defaultFont = aFont; }
301 const wxString& GetDefaultFont() const { return m_defaultFont; }
302
303 // TODO: these can go away once the drawing sheet is moved to Cairo-based printing
304 wxDC* GetPrintDC() const { return m_printDC; }
305 void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
306
307protected:
312 virtual void update();
313
314 PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
315 wxString m_layerName;
316 std::set<int> m_highContrastLayers; // High-contrast layers (both board layers and
317 // synthetic GAL layers)
318 std::map<int, COLOR4D> m_layerColors; // Layer colors
319 std::map<int, COLOR4D> m_layerColorsHi; // Layer colors for highlighted objects
320 std::map<int, COLOR4D> m_layerColorsSel; // Layer colors for selected objects
321 std::map<int, COLOR4D> m_hiContrastColor; // High-contrast mode layer colors
322 std::map<int, COLOR4D> m_layerColorsDark; // Darkened layer colors (for high-contrast mode)
323
324 COLOR4D m_backgroundColor; // The background color
325
327 bool m_hiContrastEnabled; // High contrast display mode on/off
328 float m_hiContrastFactor; // Factor used for computing high contrast color
329
330 bool m_highlightEnabled; // Highlight display mode on/off
331 std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
332 float m_highlightFactor; // Factor used for computing highlight color
333
334 bool m_drawBoundingBoxes; // Visual aid for debugging
335
336 float m_selectFactor; // Specifies how color of selected items is changed
337 float m_outlineWidth; // Line width used when drawing outlines
338 float m_drawingSheetLineWidth;// Line width used for borders and titleblock
339
341 int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
342 // lines. This sets an absolute minimum.
345
347
348 bool m_isPrinting; // true when draw to a printer
349 bool m_printBlackAndWite; // true if black and white printing is requested: some
350 // backgrounds are not printed to avoid not visible items
352
353 wxDC* m_printDC; // This can go away once the drawing sheet is moved to
354 // Cairo-based printing.
355};
356
357}
358
359#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:402
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:454
@ LAYER_INTERSHEET_REFS
Definition layer_ids.h:461
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:29