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