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 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#include <render_settings.h>
21
22using namespace KIGFX;
23
24
27 m_drawBoundingBoxes( false ),
28 m_dashLengthRatio( 12 ), // From ISO 128-2
29 m_gapLengthRatio( 3 ), // From ISO 128-2
30 m_printDC( nullptr )
31{
32 // Set the default initial values
34 m_highlightFactor = 0.5f;
35 m_selectFactor = 0.5f;
36 m_highlightEnabled = false;
37 m_hiContrastEnabled = false;
38 m_hiContrastFactor = 0.2f;
42 m_minPenWidth = 0;
43 m_isPrinting = false;
44 m_printBlackAndWite = false;
45}
46
47
51
52
53#if 0
54constexpr double correction = 0.8; // Looks best visually
55#else
56constexpr double correction = 1.0; // Matches ISO 128-2, but can creates issues on GTK and MSW:
57 // "dots" are not always visible depending on the zoom level
58 // because they create 0 lenght lines
59 // So they will drawn as segments, even with correction = 1.0
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 // The minimal length scale is arbitrary set to 0.2 after trials
72 // 0 lenght can create drawing issues
73 return std::max( ( 1.0 - correction ), 0.2 ) * aLineWidth;
74}
75
76
77double RENDER_SETTINGS::GetGapLength( int aLineWidth ) const
78{
79 return std::max( m_gapLengthRatio + correction, 1.0 ) * aLineWidth;
80}
81
82
84{
85 // Calculate darkened/highlighted variants of layer colors
86 for( int i = 0; i < LAYER_ID_COUNT; i++ )
87 {
90
92 m_layerColorsDark[i] = m_layerColors[i].Darkened( 1.0 - m_highlightFactor );
93
94 // Skip selection brightening for things close to black, and netname text
95 if( IsNetnameLayer( i ) || m_layerColors[i].GetBrightness() < 0.05 )
96 {
98 continue;
99 }
100
101 // Linear brightening doesn't work well for colors near white
102 double factor = ( m_selectFactor * 0.5 ) + pow( m_layerColors[i].GetBrightness(), 3 );
103 factor = std::min( 1.0, factor );
104
105 m_layerColorsSel[i] = m_layerColors[i].Brightened( factor );
106
107 // If we are maxed out on brightening as a highlight, fallback to darkening but keep
108 // the blue that acts as a "glowing" color
109 if( std::fabs( m_layerColorsSel[i].GetBrightness() - m_layerColors[i].GetBrightness() )
110 < 0.05 )
111 {
112 m_layerColorsSel[i] = m_layerColors[i].Darkened( m_selectFactor * 0.4 );
113 m_layerColorsSel[i].b = m_layerColors[i].b * ( 1.0 - factor ) + factor;
114 }
115
116 }
117}
118
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
std::set< int > m_highlightNetcodes
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:624
@ LAYER_PCB_BACKGROUND
PCB background color.
Definition layer_ids.h:277
bool IsNetnameLayer(int aLayer)
Test whether a layer is a netname layer.
Definition layer_ids.h:867
@ F_Cu
Definition layer_ids.h:60
The Cairo implementation of the graphics abstraction layer.
Definition eda_group.h:29
constexpr double correction