KiCad PCB EDA Suite
Loading...
Searching...
No Matches
render_settings.cpp
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) 2020 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#include <render_settings.h>
25
26using namespace KIGFX;
27
28
30 m_highlightNetcodes(),
31 m_drawBoundingBoxes( false ),
32 m_dashLengthRatio( 12 ), // From ISO 128-2
33 m_gapLengthRatio( 3 ), // From ISO 128-2
34 m_printDC( nullptr )
35{
36 // Set the default initial values
38 m_highlightFactor = 0.5f;
39 m_selectFactor = 0.5f;
40 m_highlightEnabled = false;
41 m_hiContrastEnabled = false;
42 m_hiContrastFactor = 0.2f;
46 m_minPenWidth = 0;
47 m_isPrinting = false;
48 m_printBlackAndWite = false;
49}
50
51
53{
54}
55
56
57#if 0
58constexpr double correction = 0.8; // Looks best visually
59#else
60constexpr double correction = 1.0; // Matches ISO 128-2
61#endif
62
63
64double RENDER_SETTINGS::GetDashLength( int aLineWidth ) const
65{
66 return std::max( m_dashLengthRatio - correction, 1.0 ) * aLineWidth;
67}
68
69
70double RENDER_SETTINGS::GetDotLength( int aLineWidth ) const
71{
72 return ( 1.0 - correction ) * aLineWidth;
73}
74
75
76double RENDER_SETTINGS::GetGapLength( int aLineWidth ) const
77{
78 return std::max( m_gapLengthRatio + correction, 1.0 ) * aLineWidth;
79}
80
81
83{
84 // Calculate darkened/highlighted variants of layer colors
85 for( int i = 0; i < LAYER_ID_COUNT; i++ )
86 {
89
92
93 // Skip selection brightening for things close to black, and netname text
94 if( IsNetnameLayer( i ) || m_layerColors[i].GetBrightness() < 0.05 )
95 {
97 continue;
98 }
99
100 // Linear brightening doesn't work well for colors near white
101 double factor = ( m_selectFactor * 0.5 ) + pow( m_layerColors[i].GetBrightness(), 3 );
102 factor = std::min( 1.0, factor );
103
104 m_layerColorsSel[i] = m_layerColors[i].Brightened( factor );
105
106 // If we are maxed out on brightening as a highlight, fallback to darkening but keep
107 // the blue that acts as a "glowing" color
108 if( std::fabs( m_layerColorsSel[i].GetBrightness() - m_layerColors[i].GetBrightness() )
109 < 0.05 )
110 {
112 m_layerColorsSel[i].b = m_layerColors[i].b * ( 1.0 - factor ) + factor;
113 }
114
115 }
116}
117
COLOR4D Darkened(double aFactor) const
Return a color that is darker by a given factor, without modifying object.
Definition: color4d.h:282
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
Definition: color4d.h:268
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition: color4d.h:295
double b
Blue component.
Definition: color4d.h:394
COLOR4D m_hiContrastColor[LAYER_ID_COUNT]
double GetGapLength(int aLineWidth) const
COLOR4D m_layerColorsDark[LAYER_ID_COUNT]
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.
COLOR4D m_layerColors[LAYER_ID_COUNT]
double GetDashLength(int aLineWidth) const
bool m_hiContrastEnabled
Parameters for display modes.
#define LAYER_ID_COUNT
Must update this if you add any enums after GerbView!
Definition: layer_ids.h:478
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:224
bool IsNetnameLayer(int aLayer)
Test whether a layer is a netname layer.
Definition: layer_ids.h:1044
@ F_Cu
Definition: layer_ids.h:64
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
constexpr double correction