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 (C) 2016-2023 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
32std::vector<wxColour> SIM_PLOT_COLORS::m_colorList;
33
34
36{
37 return static_cast<int>( x ) < static_cast<int>( y );
38}
39
40
42{
43 return static_cast<int>( x ) >= static_cast<int>( y );
44}
45
46
47inline bool operator<( SIM_PLOT_COLORS::COLOR_SET& x, int y )
48{
49 return static_cast<int>( x ) < y;
50}
51
52
53inline bool operator>=( SIM_PLOT_COLORS::COLOR_SET& x, int y )
54{
55 return static_cast<int>( x ) >= y;
56}
57
58
61{
62 return static_cast<SIM_PLOT_COLORS::COLOR_SET>( static_cast<int>( x ) + static_cast<int>( y ) );
63}
64
65
68{
69 return static_cast<SIM_PLOT_COLORS::COLOR_SET>( static_cast<int>( x ) - static_cast<int>( y ) );
70}
71
72
74{
75 return static_cast<SIM_PLOT_COLORS::COLOR_SET>( x % static_cast<int>( y ) );
76}
77
78
80{
81 x = static_cast<SIM_PLOT_COLORS::COLOR_SET>( (int) x + 1 );
82 return x;
83}
84
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
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
132wxColour 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}
wxColour GetPlotColor(enum COLOR_SET aColorId)
enum COLOR_SET getPlotColorCount()
static std::vector< wxColour > m_colorList
< The color list to draw traces, bg, fg, axis...
static void FillDefaultColorList(bool aWhiteBg)
Fills m_colorList by a default set of colors.
wxColour GenerateColor(std::map< wxString, wxColour > aTraceColors)
bool operator<(SIM_PLOT_COLORS::COLOR_SET &x, SIM_PLOT_COLORS::COLOR_SET &y)
bool operator>=(SIM_PLOT_COLORS::COLOR_SET &x, SIM_PLOT_COLORS::COLOR_SET &y)
SIM_PLOT_COLORS::COLOR_SET & operator++(SIM_PLOT_COLORS::COLOR_SET &x)
SIM_PLOT_COLORS::COLOR_SET operator+(SIM_PLOT_COLORS::COLOR_SET x, SIM_PLOT_COLORS::COLOR_SET y)
SIM_PLOT_COLORS::COLOR_SET operator%(int x, SIM_PLOT_COLORS::COLOR_SET y)
SIM_PLOT_COLORS::COLOR_SET operator-(SIM_PLOT_COLORS::COLOR_SET x, SIM_PLOT_COLORS::COLOR_SET y)
Class is responsible for providing colors for traces on simulation plot.