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) 2024 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, but can creates issues on GTK and MSW:
61 // "dots" are not always visible depending on the zoom level
62 // because they create 0 lenght lines
63 // So they will drawn as segments, even with correction = 1.0
64#endif
65
66
67double RENDER_SETTINGS::GetDashLength( int aLineWidth ) const
68{
69 return std::max( m_dashLengthRatio - correction, 1.0 ) * aLineWidth;
70}
71
72
73double RENDER_SETTINGS::GetDotLength( int aLineWidth ) const
74{
75 // The minimal length scale is arbitrary set to 0.2 after trials
76 // 0 lenght can create drawing issues
77 return std::max( ( 1.0 - correction ), 0.2 ) * aLineWidth;
78}
79
80
81double RENDER_SETTINGS::GetGapLength( int aLineWidth ) const
82{
83 return std::max( m_gapLengthRatio + correction, 1.0 ) * aLineWidth;
84}
85
86
88{
89 // Calculate darkened/highlighted variants of layer colors
90 for( int i = 0; i < LAYER_ID_COUNT; i++ )
91 {
94
96 m_layerColorsDark[i] = m_layerColors[i].Darkened( 1.0 - m_highlightFactor );
97
98 // Skip selection brightening for things close to black, and netname text
99 if( IsNetnameLayer( i ) || m_layerColors[i].GetBrightness() < 0.05 )
100 {
102 continue;
103 }
104
105 // Linear brightening doesn't work well for colors near white
106 double factor = ( m_selectFactor * 0.5 ) + pow( m_layerColors[i].GetBrightness(), 3 );
107 factor = std::min( 1.0, factor );
108
109 m_layerColorsSel[i] = m_layerColors[i].Brightened( factor );
110
111 // If we are maxed out on brightening as a highlight, fallback to darkening but keep
112 // the blue that acts as a "glowing" color
113 if( std::fabs( m_layerColorsSel[i].GetBrightness() - m_layerColors[i].GetBrightness() )
114 < 0.05 )
115 {
116 m_layerColorsSel[i] = m_layerColors[i].Darkened( m_selectFactor * 0.4 );
117 m_layerColorsSel[i].b = m_layerColors[i].b * ( 1.0 - factor ) + factor;
118 }
119
120 }
121}
122
double GetGapLength(int aLineWidth) const
double GetDotLength(int aLineWidth) const
std::map< int, COLOR4D > m_layerColorsHi
virtual void update()
Precalculates extra colors for layers (e.g.
std::map< int, COLOR4D > m_hiContrastColor
double GetDashLength(int aLineWidth) const
std::map< int, COLOR4D > m_layerColorsDark
std::map< int, COLOR4D > m_layerColorsSel
std::map< int, COLOR4D > m_layerColors
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:481
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition: layer_ids.h:221
bool IsNetnameLayer(int aLayer)
Test whether a layer is a netname layer.
Definition: layer_ids.h:721
@ F_Cu
Definition: layer_ids.h:64
The Cairo implementation of the graphics abstraction layer.
Definition: color4d.cpp:247
constexpr double correction