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, see <https://www.gnu.org/licenses/>.
20
*/
21
22
23
#include "
sim_plot_colors.h
"
24
#include <
sim/sim_plot_tab.h
>
25
#include <wx/stc/stc.h>
26
27
28
std::vector<wxColour>
SIM_PLOT_COLORS::m_colorList
;
29
30
31
inline
bool
operator<
(
SIM_PLOT_COLORS::COLOR_SET
& x,
SIM_PLOT_COLORS::COLOR_SET
& y )
32
{
33
return
static_cast<
int
>
( x ) <
static_cast<
int
>
( y );
34
}
35
36
37
inline
bool
operator>=
(
SIM_PLOT_COLORS::COLOR_SET
& x,
SIM_PLOT_COLORS::COLOR_SET
& y )
38
{
39
return
static_cast<
int
>
( x ) >=
static_cast<
int
>
( y );
40
}
41
42
43
inline
bool
operator<
(
SIM_PLOT_COLORS::COLOR_SET
& x,
int
y )
44
{
45
return
static_cast<
int
>
( x ) < y;
46
}
47
48
49
inline
bool
operator>=
(
SIM_PLOT_COLORS::COLOR_SET
& x,
int
y )
50
{
51
return
static_cast<
int
>
( x ) >= y;
52
}
53
54
55
inline
SIM_PLOT_COLORS::COLOR_SET
operator+
(
SIM_PLOT_COLORS::COLOR_SET
x,
56
SIM_PLOT_COLORS::COLOR_SET
y )
57
{
58
return
static_cast<
SIM_PLOT_COLORS::COLOR_SET
>
(
static_cast<
int
>
( x ) +
static_cast<
int
>
( y ) );
59
}
60
61
62
inline
SIM_PLOT_COLORS::COLOR_SET
operator-
(
SIM_PLOT_COLORS::COLOR_SET
x,
63
SIM_PLOT_COLORS::COLOR_SET
y )
64
{
65
return
static_cast<
SIM_PLOT_COLORS::COLOR_SET
>
(
static_cast<
int
>
( x ) -
static_cast<
int
>
( y ) );
66
}
67
68
69
inline
SIM_PLOT_COLORS::COLOR_SET
operator%
(
int
x,
SIM_PLOT_COLORS::COLOR_SET
y )
70
{
71
return
static_cast<
SIM_PLOT_COLORS::COLOR_SET
>
( x %
static_cast<
int
>
( y ) );
72
}
73
74
75
inline
SIM_PLOT_COLORS::COLOR_SET
&
operator++
(
SIM_PLOT_COLORS::COLOR_SET
& x )
76
{
77
x =
static_cast<
SIM_PLOT_COLORS::COLOR_SET
>
( (int) x + 1 );
78
return
x;
79
}
80
81
wxColour
SIM_PLOT_COLORS::GetPlotColor
(
COLOR_SET
aColorId )
82
{
83
// return the wxColor selected in color list or BLACK is not in list
84
if
( aColorId >= 0 && aColorId <
m_colorList
.size() )
85
return
m_colorList
[
static_cast<
int
>
( aColorId )];
86
87
return
wxColour( 0, 0, 0 );
88
}
89
90
91
void
SIM_PLOT_COLORS::FillDefaultColorList
(
bool
aDarkMode )
92
{
93
m_colorList
.clear();
94
95
if
( aDarkMode )
96
{
97
m_colorList
.emplace_back( 0, 0, 0 );
// Bg color
98
m_colorList
.emplace_back( 255, 255, 255 );
// Fg color (texts)
99
m_colorList
.emplace_back( 130, 130, 130 );
// Axis color
100
}
101
else
102
{
103
m_colorList
.emplace_back( 255, 255, 255 );
// Bg color
104
m_colorList
.emplace_back( 0, 0, 0 );
// Fg color (texts)
105
m_colorList
.emplace_back( 130, 130, 130 );
// Axis color
106
}
107
108
// Add a list of color for traces, starting at index SIM_TRACE_COLOR
109
m_colorList
.emplace_back( 0xE4, 0x1A, 0x1C );
110
m_colorList
.emplace_back( 0x37, 0x7E, 0xB8 );
111
m_colorList
.emplace_back( 0x4D, 0xAF, 0x4A );
112
m_colorList
.emplace_back( 0x98, 0x4E, 0xA3 );
113
m_colorList
.emplace_back( 0xFF, 0x7F, 0x00 );
114
m_colorList
.emplace_back( 0xFF, 0xFF, 0x33 );
115
m_colorList
.emplace_back( 0xA6, 0x56, 0x28 );
116
m_colorList
.emplace_back( 0xF7, 0x81, 0xBF );
117
m_colorList
.emplace_back( 0x66, 0xC2, 0xA5 );
118
m_colorList
.emplace_back( 0xFC, 0x8D, 0x62 );
119
m_colorList
.emplace_back( 0x8D, 0xA0, 0xCB );
120
m_colorList
.emplace_back( 0xE7, 0x8A, 0xC3 );
121
m_colorList
.emplace_back( 0xA6, 0xD8, 0x54 );
122
m_colorList
.emplace_back( 0xFF, 0xD9, 0x2F );
123
m_colorList
.emplace_back( 0xE5, 0xC4, 0x94 );
124
m_colorList
.emplace_back( 0xB3, 0xB3, 0xB3 );
125
}
126
127
128
wxColour
SIM_PLOT_COLORS::GenerateColor
( std::map<wxString, wxColour> aTraceColors )
129
{
130
for
(
COLOR_SET
i =
COLOR_SET::TRACE
; i <
getPlotColorCount
(); ++i )
131
{
132
bool
hasColor =
false
;
133
134
for
(
const
auto
& [ vectorName, traceColor ] : aTraceColors )
135
{
136
if
( traceColor ==
GetPlotColor
( i ) )
137
{
138
hasColor =
true
;
139
break
;
140
}
141
}
142
143
if
( !hasColor )
144
return
GetPlotColor
( i );
145
}
146
147
// If all colors are in use, choose a suitable color in list
148
COLOR_SET
idx = aTraceColors.size() % (
getPlotColorCount
() -
COLOR_SET::TRACE
);
149
return
GetPlotColor
(
COLOR_SET::TRACE
+ idx );
150
}
SIM_PLOT_COLORS::GetPlotColor
wxColour GetPlotColor(enum COLOR_SET aColorId)
Definition
sim_plot_colors.cpp:81
SIM_PLOT_COLORS::getPlotColorCount
enum COLOR_SET getPlotColorCount()
Definition
sim_plot_colors.h:76
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:80
SIM_PLOT_COLORS::FillDefaultColorList
static void FillDefaultColorList(bool aWhiteBg)
Fills m_colorList by a default set of colors.
Definition
sim_plot_colors.cpp:91
SIM_PLOT_COLORS::GenerateColor
wxColour GenerateColor(std::map< wxString, wxColour > aTraceColors)
Definition
sim_plot_colors.cpp:128
SIM_PLOT_COLORS::COLOR_SET
COLOR_SET
Definition
sim_plot_colors.h:46
SIM_PLOT_COLORS::COLOR_SET::TRACE
@ TRACE
Definition
sim_plot_colors.h:50
operator<
bool operator<(SIM_PLOT_COLORS::COLOR_SET &x, SIM_PLOT_COLORS::COLOR_SET &y)
Definition
sim_plot_colors.cpp:31
operator>=
bool operator>=(SIM_PLOT_COLORS::COLOR_SET &x, SIM_PLOT_COLORS::COLOR_SET &y)
Definition
sim_plot_colors.cpp:37
operator++
SIM_PLOT_COLORS::COLOR_SET & operator++(SIM_PLOT_COLORS::COLOR_SET &x)
Definition
sim_plot_colors.cpp:75
operator+
SIM_PLOT_COLORS::COLOR_SET operator+(SIM_PLOT_COLORS::COLOR_SET x, SIM_PLOT_COLORS::COLOR_SET y)
Definition
sim_plot_colors.cpp:55
operator%
SIM_PLOT_COLORS::COLOR_SET operator%(int x, SIM_PLOT_COLORS::COLOR_SET y)
Definition
sim_plot_colors.cpp:69
operator-
SIM_PLOT_COLORS::COLOR_SET operator-(SIM_PLOT_COLORS::COLOR_SET x, SIM_PLOT_COLORS::COLOR_SET y)
Definition
sim_plot_colors.cpp:62
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 Fri Jun 26 2026 00:05:36 for KiCad PCB EDA Suite by
1.13.2