KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sim_plot_colors.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) 2021 Sylwester Kocjan <
[email protected]
>
5
* Copyright (C) 2023 CERN
6
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7
*
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public License
10
* as published by the Free Software Foundation; either version 3
11
* of the License, or (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public License
19
* along with this program; if not, you may find one here:
20
* https://www.gnu.org/licenses/gpl-3.0.html
21
* or you may search the http://www.gnu.org website for the version 3 license,
22
* or you may write to the Free Software Foundation, Inc.,
23
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24
*/
25
26
27
#include "
sim_plot_colors.h
"
28
#include <
sim/sim_plot_tab.h
>
29
#include <wx/stc/stc.h>
30
31
32
std::vector<wxColour>
SIM_PLOT_COLORS::m_colorList
;
33
34
35
inline
bool
operator<
(
SIM_PLOT_COLORS::COLOR_SET
& x,
SIM_PLOT_COLORS::COLOR_SET
& y )
36
{
37
return
static_cast<
int
>
( x ) <
static_cast<
int
>
( y );
38
}
39
40
41
inline
bool
operator>=
(
SIM_PLOT_COLORS::COLOR_SET
& x,
SIM_PLOT_COLORS::COLOR_SET
& y )
42
{
43
return
static_cast<
int
>
( x ) >=
static_cast<
int
>
( y );
44
}
45
46
47
inline
bool
operator<
(
SIM_PLOT_COLORS::COLOR_SET
& x,
int
y )
48
{
49
return
static_cast<
int
>
( x ) < y;
50
}
51
52
53
inline
bool
operator>=
(
SIM_PLOT_COLORS::COLOR_SET
& x,
int
y )
54
{
55
return
static_cast<
int
>
( x ) >= y;
56
}
57
58
59
inline
SIM_PLOT_COLORS::COLOR_SET
operator+
(
SIM_PLOT_COLORS::COLOR_SET
x,
60
SIM_PLOT_COLORS::COLOR_SET
y )
61
{
62
return
static_cast<
SIM_PLOT_COLORS::COLOR_SET
>
(
static_cast<
int
>
( x ) +
static_cast<
int
>
( y ) );
63
}
64
65
66
inline
SIM_PLOT_COLORS::COLOR_SET
operator-
(
SIM_PLOT_COLORS::COLOR_SET
x,
67
SIM_PLOT_COLORS::COLOR_SET
y )
68
{
69
return
static_cast<
SIM_PLOT_COLORS::COLOR_SET
>
(
static_cast<
int
>
( x ) -
static_cast<
int
>
( y ) );
70
}
71
72
73
inline
SIM_PLOT_COLORS::COLOR_SET
operator%
(
int
x,
SIM_PLOT_COLORS::COLOR_SET
y )
74
{
75
return
static_cast<
SIM_PLOT_COLORS::COLOR_SET
>
( x %
static_cast<
int
>
( y ) );
76
}
77
78
79
inline
SIM_PLOT_COLORS::COLOR_SET
&
operator++
(
SIM_PLOT_COLORS::COLOR_SET
& x )
80
{
81
x =
static_cast<
SIM_PLOT_COLORS::COLOR_SET
>
( (int) x + 1 );
82
return
x;
83
}
84
85
wxColour
SIM_PLOT_COLORS::GetPlotColor
(
COLOR_SET
aColorId )
86
{
87
// return the wxColor selected in color list or BLACK is not in list
88
if
( aColorId >= 0 && aColorId <
m_colorList
.size() )
89
return
m_colorList
[
static_cast<
int
>
( aColorId )];
90
91
return
wxColour( 0, 0, 0 );
92
}
93
94
95
void
SIM_PLOT_COLORS::FillDefaultColorList
(
bool
aDarkMode )
96
{
97
m_colorList
.clear();
98
99
if
( aDarkMode )
100
{
101
m_colorList
.emplace_back( 0, 0, 0 );
// Bg color
102
m_colorList
.emplace_back( 255, 255, 255 );
// Fg color (texts)
103
m_colorList
.emplace_back( 130, 130, 130 );
// Axis color
104
}
105
else
106
{
107
m_colorList
.emplace_back( 255, 255, 255 );
// Bg color
108
m_colorList
.emplace_back( 0, 0, 0 );
// Fg color (texts)
109
m_colorList
.emplace_back( 130, 130, 130 );
// Axis color
110
}
111
112
// Add a list of color for traces, starting at index SIM_TRACE_COLOR
113
m_colorList
.emplace_back( 0xE4, 0x1A, 0x1C );
114
m_colorList
.emplace_back( 0x37, 0x7E, 0xB8 );
115
m_colorList
.emplace_back( 0x4D, 0xAF, 0x4A );
116
m_colorList
.emplace_back( 0x98, 0x4E, 0xA3 );
117
m_colorList
.emplace_back( 0xFF, 0x7F, 0x00 );
118
m_colorList
.emplace_back( 0xFF, 0xFF, 0x33 );
119
m_colorList
.emplace_back( 0xA6, 0x56, 0x28 );
120
m_colorList
.emplace_back( 0xF7, 0x81, 0xBF );
121
m_colorList
.emplace_back( 0x66, 0xC2, 0xA5 );
122
m_colorList
.emplace_back( 0xFC, 0x8D, 0x62 );
123
m_colorList
.emplace_back( 0x8D, 0xA0, 0xCB );
124
m_colorList
.emplace_back( 0xE7, 0x8A, 0xC3 );
125
m_colorList
.emplace_back( 0xA6, 0xD8, 0x54 );
126
m_colorList
.emplace_back( 0xFF, 0xD9, 0x2F );
127
m_colorList
.emplace_back( 0xE5, 0xC4, 0x94 );
128
m_colorList
.emplace_back( 0xB3, 0xB3, 0xB3 );
129
}
130
131
132
wxColour
SIM_PLOT_COLORS::GenerateColor
( std::map<wxString, wxColour> aTraceColors )
133
{
134
for
(
COLOR_SET
i =
COLOR_SET::TRACE
; i <
getPlotColorCount
(); ++i )
135
{
136
bool
hasColor =
false
;
137
138
for
(
const
auto
& [ vectorName, traceColor ] : aTraceColors )
139
{
140
if
( traceColor ==
GetPlotColor
( i ) )
141
{
142
hasColor =
true
;
143
break
;
144
}
145
}
146
147
if
( !hasColor )
148
return
GetPlotColor
( i );
149
}
150
151
// If all colors are in use, choose a suitable color in list
152
COLOR_SET
idx = aTraceColors.size() % (
getPlotColorCount
() -
COLOR_SET::TRACE
);
153
return
GetPlotColor
(
COLOR_SET::TRACE
+ idx );
154
}
SIM_PLOT_COLORS::GetPlotColor
wxColour GetPlotColor(enum COLOR_SET aColorId)
Definition
sim_plot_colors.cpp:85
SIM_PLOT_COLORS::getPlotColorCount
enum COLOR_SET getPlotColorCount()
Definition
sim_plot_colors.h:80
SIM_PLOT_COLORS::m_colorList
static std::vector< wxColour > m_colorList
< The color list to draw traces, bg, fg, axis...
Definition
sim_plot_colors.h:84
SIM_PLOT_COLORS::FillDefaultColorList
static void FillDefaultColorList(bool aWhiteBg)
Fills m_colorList by a default set of colors.
Definition
sim_plot_colors.cpp:95
SIM_PLOT_COLORS::GenerateColor
wxColour GenerateColor(std::map< wxString, wxColour > aTraceColors)
Definition
sim_plot_colors.cpp:132
SIM_PLOT_COLORS::COLOR_SET
COLOR_SET
Definition
sim_plot_colors.h:50
SIM_PLOT_COLORS::COLOR_SET::TRACE
@ TRACE
Definition
sim_plot_colors.h:54
operator<
bool operator<(SIM_PLOT_COLORS::COLOR_SET &x, SIM_PLOT_COLORS::COLOR_SET &y)
Definition
sim_plot_colors.cpp:35
operator>=
bool operator>=(SIM_PLOT_COLORS::COLOR_SET &x, SIM_PLOT_COLORS::COLOR_SET &y)
Definition
sim_plot_colors.cpp:41
operator++
SIM_PLOT_COLORS::COLOR_SET & operator++(SIM_PLOT_COLORS::COLOR_SET &x)
Definition
sim_plot_colors.cpp:79
operator+
SIM_PLOT_COLORS::COLOR_SET operator+(SIM_PLOT_COLORS::COLOR_SET x, SIM_PLOT_COLORS::COLOR_SET y)
Definition
sim_plot_colors.cpp:59
operator%
SIM_PLOT_COLORS::COLOR_SET operator%(int x, SIM_PLOT_COLORS::COLOR_SET y)
Definition
sim_plot_colors.cpp:73
operator-
SIM_PLOT_COLORS::COLOR_SET operator-(SIM_PLOT_COLORS::COLOR_SET x, SIM_PLOT_COLORS::COLOR_SET y)
Definition
sim_plot_colors.cpp:66
sim_plot_colors.h
Class is responsible for providing colors for traces on simulation plot.
sim_plot_tab.h
src
eeschema
sim
sim_plot_colors.cpp
Generated on Sun Sep 21 2025 01:05:24 for KiCad PCB EDA Suite by
1.13.2