KiCad PCB EDA Suite
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
29RENDER_SETTINGS::RENDER_SETTINGS() :
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}
49
50
52{
53}
54
55
56#if 0
57constexpr double correction = 0.8; // Looks best visually
58#else
59constexpr double correction = 1.0; // Matches ISO 128-2
60#endif
61
62
63double RENDER_SETTINGS::GetDashLength( int aLineWidth ) const
64{
65 return std::max( m_dashLengthRatio - correction, 1.0 ) * aLineWidth;
66}
67
68
69double RENDER_SETTINGS::GetDotLength( int aLineWidth ) const
70{
71 return ( 1.0 - correction ) * aLineWidth;
72}
73
74
75double RENDER_SETTINGS::GetGapLength( int aLineWidth ) const
76{
77 return std::max( m_gapLengthRatio + correction, 1.0 ) * aLineWidth;
78}
79
80
82{
83 // Calculate darkened/highlighted variants of layer colors
84 for( int i = 0; i < LAYER_ID_COUNT; i++ )
85 {
88
91
92 if( IsNetnameLayer( i ) || IsHoleLayer( i ) )
93 {
95 continue;
96 }
97
98 // Linear brightening doesn't work well for colors near white
99 double factor = ( m_selectFactor * 0.5 ) + pow( m_layerColors[i].GetBrightness(), 3 );
100 factor = std::min( 1.0, factor );
101
102 m_layerColorsSel[i] = m_layerColors[i].Brightened( factor );
103
104 // If we are maxed out on brightening as a highlight, fallback to darkening but keep
105 // the blue that acts as a "glowing" color
106 if( std::fabs( m_layerColorsSel[i].GetBrightness() - m_layerColors[i].GetBrightness() )
107 < 0.05 )
108 {
110 m_layerColorsSel[i].b = m_layerColors[i].b * ( 1.0 - factor ) + factor;
111 }
112
113 }
114}
115
COLOR4D Darkened(double aFactor) const
Return a color that is darker by a given factor, without modifying object.
Definition: color4d.h:298
COLOR4D Brightened(double aFactor) const
Return a color that is brighter by a given factor, without modifying object.
Definition: color4d.h:284
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition: color4d.h:311
double b
Blue component.
Definition: color4d.h:392
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:449
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:220
bool IsNetnameLayer(int aLayer)
Test whether a layer is a netname layer.
Definition: layer_ids.h:989
bool IsHoleLayer(int aLayer)
Definition: layer_ids.h:864
@ F_Cu
Definition: layer_ids.h:64
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:266
constexpr double correction