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 <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<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
230 void SetPrintBlackAndWhite( bool aPrintBlackAndWhite )
231 {
232 m_printBlackAndWite = aPrintBlackAndWhite;
233 }
234
236 {
238 }
239
243 virtual const COLOR4D& GetBackgroundColor() const = 0;
244
248 virtual void SetBackgroundColor( const COLOR4D& aColor ) = 0;
249
253 virtual const COLOR4D& GetGridColor() = 0;
254
258 virtual const COLOR4D& GetCursorColor() = 0;
259
265 inline const COLOR4D& GetLayerColor( int aLayer ) const
266 {
267 // We don't (yet?) have a separate color for intersheet refs
268 if( aLayer == LAYER_INTERSHEET_REFS )
269 aLayer = LAYER_GLOBLABEL;
270
271 return m_layerColors[aLayer];
272 }
273
280 inline void SetLayerColor( int aLayer, const COLOR4D& aColor )
281 {
282 m_layerColors[aLayer] = aColor;
283
284 update(); // recompute other shades of the color
285 }
286
287 virtual bool IsBackgroundDark() const
288 {
289 return false;
290 }
291
297 void SetOutlineWidth( float aWidth ) { m_outlineWidth = aWidth; }
298 float GetOutlineWidth() const { return m_outlineWidth; }
299
300 void SetHighlightFactor( float aFactor ) { m_highlightFactor = aFactor; }
301 void SetSelectFactor( float aFactor ) { m_selectFactor = aFactor; }
302
303 void SetDefaultFont( const wxString& aFont ) { m_defaultFont = aFont; }
304 const wxString& GetDefaultFont() const { return m_defaultFont; }
305
306 // TODO: these can go away once the drawing sheet is moved to Cairo-based printing
307 wxDC* GetPrintDC() const { return m_printDC; }
308 void SetPrintDC( wxDC* aDC ) { m_printDC = aDC; }
309
310protected:
315 virtual void update();
316
317 PCB_LAYER_ID m_activeLayer; // The active layer (as shown by appearance mgr)
318 wxString m_layerName;
319 std::set<int> m_highContrastLayers; // High-contrast layers (both board layers and
320 // synthetic GAL layers)
322 COLOR4D m_layerColorsHi[LAYER_ID_COUNT]; // Layer colors for highlighted objects
323 COLOR4D m_layerColorsSel[LAYER_ID_COUNT]; // Layer colors for selected objects
324
325 COLOR4D m_hiContrastColor[LAYER_ID_COUNT]; // High-contrast mode layer colors
326 COLOR4D m_layerColorsDark[LAYER_ID_COUNT]; // Darkened layer colors (for high-contrast mode)
327
328 COLOR4D m_backgroundColor; // The background color
329
331 bool m_hiContrastEnabled; // High contrast display mode on/off
332 float m_hiContrastFactor; // Factor used for computing high contrast color
333
334 bool m_highlightEnabled; // Highlight display mode on/off
335 std::set<int> m_highlightNetcodes; // Set of net cods to be highlighted
336 float m_highlightFactor; // Factor used for computing highlight color
337
338 bool m_drawBoundingBoxes; // Visual aid for debugging
339
340 float m_selectFactor; // Specifies how color of selected items is changed
341 float m_outlineWidth; // Line width used when drawing outlines
342 float m_drawingSheetLineWidth;// Line width used for borders and titleblock
343
345 int m_minPenWidth; // Some clients (such as PDF) don't like ultra-thin
346 // lines. This sets an absolute minimum.
349
351
352 bool m_isPrinting; // true when draw to a printer
353 bool m_printBlackAndWite; // true if black and white printing is requested: some
354 // backgrounds are not printed to avoid not visible items
356
357 wxDC* m_printDC; // This can go away once the drawing sheet is moved to
358 // Cairo-based printing.
359};
360
361}
362
363#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: layer_ids.h:574
constexpr PCB_LAYER_ID PCBNEW_LAYER_ID_START
Definition: layer_ids.h:140
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Definition: layer_ids.h:478
@ 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:137
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247