KiCad PCB EDA Suite
Loading...
Searching...
No Matches
panel_eseries_display.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) 2023 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 3
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 along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <math.h>
21
24#include <string_utils.h>
25#include <wx/msgdlg.h>
26#include <wx/settings.h> // for IsDark
27#include <eseries.h>
28
29#include <i18n_utility.h> // For _HKI definition in eseries_display_help.h
30wxString eseries_display_help =
32
33
34PANEL_ESERIES_DISPLAY::PANEL_ESERIES_DISPLAY( wxWindow * parent, wxWindowID id,
35 const wxPoint& pos, const wxSize& size,
36 long style, const wxString& name ) :
37 PANEL_ESERIES_DISPLAY_BASE( parent, id, pos, size, style, name )
38{
39 // show markdown stuff in lower help panel
40 wxString msg;
41
42 ConvertMarkdown2Html( wxGetTranslation( eseries_display_help ), msg );
43 m_panelESeriesHelp->SetPage( msg );
44
45 // Calculate E1,E3,E6,E12,E24,E48,E96 column background colours
46 // Get appearances. Note that I believe these panels will not be
47 // re-constructed on a mode change so this only works if you open
48 // the window *after* you set your dark mode.
49 const wxSystemAppearance appearances = wxSystemSettings::GetAppearance();
50 const bool selectDark = appearances.IsDark();
51
52 recalculateColumnColours( selectDark );
53
54 // Lay out the smaller tree containing E1,E3,E6, and E12
55 populateE112Tree();
56
57 // Set colours of smaller tree.
58 recolourE112Tree();
59
60 // Lay out the larger tree containing E24, R48 and E96
61 populateE2496Tree();
62
63 // Set colours of larger tree.
64 recolourE2496Tree();
65
66 // Needed on wxWidgets 3.0 to ensure sizers are correctly set
67 GetSizer()->SetSizeHints( this );
68
69 // Make the grid lines disappear into the window background
70 // making the value boxes appear to be separated from each other.
71 // Also force text to always be black so it is visible against the light
72 // colored cells in both light and dark modes.
73 wxColour gridLineColour = parent->GetBackgroundColour();
74
75 m_GridEseries112->SetDefaultCellTextColour( *wxBLACK );
76 m_GridEseries112->SetGridLineColour( gridLineColour );
77 m_GridEseries112->EnableGridLines( true );
78
79 m_GridEseries112->SetColLabelSize( wxGRID_AUTOSIZE );
80 m_GridEseries112->AutoSize();
81
82 m_GridEseries2496->SetDefaultCellTextColour( *wxBLACK );
83 m_GridEseries2496->SetGridLineColour( gridLineColour );
84 m_GridEseries2496->EnableGridLines( true );
85
86 m_GridEseries2496->SetColLabelSize( wxGRID_AUTOSIZE );
87 m_GridEseries2496->AutoSize();
88
89 Layout();
90}
91
92
94{
95}
96
97
99{
100 // Calculate E1,E3,E6,E12,E24,E48,E96 column background colours
101 // Get appearances.
102 const wxSystemAppearance appearances = wxSystemSettings::GetAppearance();
103 const bool selectDark = appearances.IsDark();
104
105 recalculateColumnColours( selectDark );
106
107 // Set colours of smaller tree.
109
110 // Set colours of larger tree.
112}
113
114
116{
117}
118
119
121{
122}
123
124
126{
127 // if in a dark mode then darken colors significantly so that
128 // the white numerals on top stand out better
129 const int colourAdjust = aDarkModeOn ? s_darkAdjustValue : 100;
130
131 m_colourE1Column = wxColour( s_cE1BGR ).ChangeLightness( colourAdjust );
132 const wxColour colourE3Column( wxColour( s_cE3BGR ).ChangeLightness( colourAdjust ) );
133 const wxColour colourE6Column( wxColour( s_cE6BGR ).ChangeLightness( colourAdjust ) );
134 const wxColour colourE12Column( wxColour( s_cE12BGR ).ChangeLightness( colourAdjust ) );
135 const wxColour colourE24Column( wxColour( s_cE24BGR ).ChangeLightness( colourAdjust ) );
136 const wxColour colourE48Column( wxColour( s_cE48BGR ).ChangeLightness( colourAdjust ) );
137 const wxColour colourE96Column( wxColour( s_cE96BGR ).ChangeLightness( colourAdjust ) );
138
139 m_colourE3Pair[0] = colourE3Column;
140 m_colourE3Pair[1] = colourE3Column.ChangeLightness( s_altAdjustValue );
141 m_colourE6Pair[0] = colourE6Column;
142 m_colourE6Pair[1] = colourE6Column.ChangeLightness( s_altAdjustValue );
143 m_colourE12Pair[0] = colourE12Column;
144 m_colourE12Pair[1] = colourE12Column.ChangeLightness( s_altAdjustValue );
145 m_colourE24Pair[0] = colourE24Column;
146 m_colourE24Pair[1] = colourE24Column.ChangeLightness( s_altAdjustValue );
147 m_colourE48Pair[0] = colourE48Column;
148 m_colourE48Pair[1] = colourE48Column.ChangeLightness( s_altAdjustValue );
149 m_colourE96Pair[0] = colourE96Column;
150 m_colourE96Pair[1] = colourE96Column.ChangeLightness( s_altAdjustValue );
151
152 s_colourMatching = m_GridEseries2496->GetLabelBackgroundColour();
153}
154
155
157{
158 // Lay out E1, R3, E6, E12 tree.
160
161 int row = 0;
162 wxString value;
163
164 m_GridEseries112->BeginBatch();
165
166 m_GridEseries112->DeleteCols( 0, m_GridEseries112->GetNumberCols() );
167 m_GridEseries112->DeleteRows( 0, m_GridEseries112->GetNumberRows() );
168 m_GridEseries112->AppendCols( 4 ); // E1, E3, E6, E12
169 m_GridEseries112->AppendRows( 12 ); // Sufficient rows for all of E12
170
171 m_GridEseries112->SetColLabelValue( 0, "E1" );
172 m_GridEseries112->SetColLabelValue( 1, "E3" );
173 m_GridEseries112->SetColLabelValue( 2, "E6" );
174 m_GridEseries112->SetColLabelValue( 3, "E12" );
175
176 value = wxString( "" ) << eSeries12[0];
177
178 m_GridEseries112->SetCellValue( 0, 0, value );
179 m_GridEseries112->SetCellSize( 0, 0, 12, 1 );
180
181 for( const uint16_t& seriesEntry : eSeries12 )
182 {
183 value = wxString( "" ) << seriesEntry;
184
185 if( 0 == row % 4 )
186 {
187 // Set E3 column
188 m_GridEseries112->SetCellValue( row, 1, value );
189 m_GridEseries112->SetCellSize( row, 1, 4, 1 );
190 }
191
192 if( 0 == row % 2 )
193 {
194 // Set E6 column
195 m_GridEseries112->SetCellValue( row, 2, value );
196 m_GridEseries112->SetCellSize( row, 2, 2, 1 );
197 }
198
199 // Set E12 column
200 m_GridEseries112->SetCellValue( row, 3, value );
201
202 ++row;
203 }
204
205 for( int i = 0; i < 3; ++i )
206 {
207 // Resize data columns to fit data and set as minimum size
208 m_GridEseries112->AutoSizeColumn( i, true );
209 }
210
211 m_GridEseries112->EndBatch();
212}
213
214
216{
217 // Lay out E24, E48, E96 tree.
220
221 // This is the number of times the table is wrapped around into another
222 // column. Like in a newspaper. The term column is not used since
223 // the grid already has columns. The 96 in the second calculation
224 // is the number of entries in the largest series displayed (E96)
225 constexpr unsigned int numStripes = 4;
226 constexpr unsigned int stripeHeight = 96 / numStripes;
227
228 int idx = 0;
229 int stripe = 0;
230 wxString value;
231
232 m_GridEseries2496->BeginBatch();
233
234 m_GridEseries2496->DeleteCols( 0, m_GridEseries2496->GetNumberCols() );
235 m_GridEseries2496->DeleteRows( 0, m_GridEseries2496->GetNumberRows() );
236
237 // Column headers are E24, E48, E96, -
238 // repeated numStripes times over. And the last - is omitted.
239 m_GridEseries2496->AppendCols( numStripes * 4 - 1 );
240 m_GridEseries2496->AppendRows( stripeHeight );
241
242 m_GridEseries2496->SetColLabelValue( 0 + 0, "E24" );
243 m_GridEseries2496->SetColLabelValue( 1 + 0, "E48" );
244 m_GridEseries2496->SetColLabelValue( 2 + 0, "E96" );
245 m_GridEseries2496->SetColLabelValue( 3 + 0, "-" );
246
247 m_GridEseries2496->SetColLabelValue( 0 + 4, "E24" );
248 m_GridEseries2496->SetColLabelValue( 1 + 4, "E48" );
249 m_GridEseries2496->SetColLabelValue( 2 + 4, "E96" );
250 m_GridEseries2496->SetColLabelValue( 3 + 4, "-" );
251
252 m_GridEseries2496->SetColLabelValue( 0 + 8, "E24" );
253 m_GridEseries2496->SetColLabelValue( 1 + 8, "E48" );
254 m_GridEseries2496->SetColLabelValue( 2 + 8, "E96" );
255 m_GridEseries2496->SetColLabelValue( 3 + 8, "-" );
256
257 m_GridEseries2496->SetColLabelValue( 0 + 12, "E24" );
258 m_GridEseries2496->SetColLabelValue( 1 + 12, "E48" );
259 m_GridEseries2496->SetColLabelValue( 2 + 12, "E96" );
260
261 for( const uint16_t& seriesEntry : eSeries24 )
262 {
263 value = wxString( "" ) << seriesEntry;
264
265 int row = ( idx * 4 ) % stripeHeight;
266 int colOffset = ( ( idx * 4 ) / stripeHeight ) * 4;
267
268 m_GridEseries2496->SetCellValue( row, colOffset, value );
269 m_GridEseries2496->SetCellSize( row, colOffset, 4, 1 );
270
271 ++idx;
272 }
273
274 idx = 0;
275
276 for( const uint16_t& seriesEntry : eSeries96 )
277 {
278 value = wxString( "" ) << seriesEntry;
279
280 int row = idx % stripeHeight;
281 int colOffset = ( idx / stripeHeight ) * 4;
282
283 if( 0 == row % 2 )
284 {
285 // Set E48 column
286 m_GridEseries2496->SetCellValue( row, colOffset + 1, value );
287 m_GridEseries2496->SetCellSize( row, colOffset + 1, 2, 1 );
288 }
289
290 // Set E96 column
291 m_GridEseries2496->SetCellValue( row, colOffset + 2, value );
292 ++idx;
293 }
294
295 // cause the areas between stripes to appear more empty
296 // by making them a single cell the height of the stripe
297 // this causes the horizontal row lines rows to disappear
298 for( unsigned int stripeGap = 1; stripeGap < numStripes; ++stripeGap )
299 {
300 const int stripeColumn = -1 + stripeGap * 4;
301
302 m_GridEseries2496->SetCellSize( 0, stripeColumn, stripeHeight, 1 );
303 }
304
305 for( int i = 0; i < numStripes * 4 - 1; ++i )
306 {
307 // Resize the column to fit data and set as minimum size
308 m_GridEseries2496->AutoSizeColumn( i, true );
309 }
310
311 m_GridEseries2496->EndBatch();
312}
313
314
316{
317 const unsigned int numRows = m_GridEseries112->GetNumberRows();
318
319 m_GridEseries112->BeginBatch();
320
321 // Colouring E1 is easy. There is only one item.
322 m_GridEseries112->SetCellBackgroundColour( 0, 0, m_colourE1Column );
323
324 bool alternateColour = false;
325 int cellWidth = 0, cellHeight = 0;
326
327 // Colour E3 column
328 for( int row = 0; row < numRows; row += cellHeight )
329 {
330 m_GridEseries112->SetCellBackgroundColour( row, 1, m_colourE3Pair[alternateColour] );
331
332 // get height for iteration above
333 m_GridEseries112->GetCellSize( row, 1, &cellHeight, &cellWidth );
334 alternateColour = !alternateColour;
335
336 if( cellHeight < 1 )
337 cellHeight = 1; // Do not loop forever, always make progress.
338 }
339
340 // Colour E6 column
341 alternateColour = false;
342
343 for( int row = 0; row < numRows; row += cellHeight )
344 {
345 m_GridEseries112->SetCellBackgroundColour( row, 2, m_colourE6Pair[alternateColour] );
346
347 // get height for iteration above
348 m_GridEseries112->GetCellSize( row, 2, &cellHeight, &cellWidth );
349 alternateColour = !alternateColour;
350
351 if( cellHeight < 1 )
352 cellHeight = 1; // Do not loop forever, always make progress.
353 }
354
355 // Colour E12 column
356 alternateColour = false;
357
358 for( int row = 0; row < numRows; row += cellHeight )
359 {
360 m_GridEseries112->SetCellBackgroundColour( row, 3, m_colourE12Pair[alternateColour] );
361
362 // get height for iteration above
363 m_GridEseries112->GetCellSize( row, 3, &cellHeight, &cellWidth );
364 alternateColour = !alternateColour;
365
366 if( cellHeight < 1 )
367 cellHeight = 1; // Do not loop forever, always make progress.
368 }
369
370 m_GridEseries112->EndBatch();
371}
372
373
375{
376 const unsigned int numRows = m_GridEseries2496->GetNumberRows();
377 constexpr unsigned int numStripes = 4;
378 constexpr unsigned int stripeHeight = 96 / numStripes;
379
380 m_GridEseries2496->BeginBatch();
381
382 bool alternateColour = false;
383 int cellWidth = 0, cellHeight = 0;
384
385 // Colour E24 columns
386 for( int row = 0; row < numRows; row += cellHeight )
387 {
388 for( int stripe = 0; stripe < numStripes; ++stripe )
389 {
390 m_GridEseries2496->SetCellBackgroundColour( row, 0 + 4 * stripe,
391 m_colourE24Pair[alternateColour] );
392 }
393 // get height for iteration above
394 m_GridEseries2496->GetCellSize( row, 0, &cellHeight, &cellWidth );
395 alternateColour = !alternateColour;
396
397 if( cellHeight < 1 )
398 cellHeight = 1; // Do not loop forever, always make progress.
399 }
400
401 // Colour E48 columns
402 alternateColour = false;
403
404 for( int row = 0; row < numRows; row += cellHeight )
405 {
406 for( int stripe = 0; stripe < numStripes; ++stripe )
407 {
408 m_GridEseries2496->SetCellBackgroundColour( row, 1 + 4 * stripe,
409 m_colourE48Pair[alternateColour] );
410 }
411 // get height for iteration above
412 m_GridEseries2496->GetCellSize( row, 1, &cellHeight, &cellWidth );
413 alternateColour = !alternateColour;
414
415 if( cellHeight < 1 )
416 cellHeight = 1; // Do not loop forever, always make progress.
417 }
418
419 // Colour E96 columns
420 alternateColour = false;
421
422 for( int row = 0; row < numRows; row += cellHeight )
423 {
424 for( int stripe = 0; stripe < numStripes; ++stripe )
425 {
426 m_GridEseries2496->SetCellBackgroundColour( row, 2 + 4 * stripe,
427 m_colourE96Pair[alternateColour] );
428 }
429 // get height for iteration above
430 m_GridEseries2496->GetCellSize( row, 2, &cellHeight, &cellWidth );
431 alternateColour = !alternateColour;
432
433 if( cellHeight < 1 )
434 cellHeight = 1; // Do not loop forever, always make progress.
435 }
436
437 // recolour empty areas between columns to match label background
438 // to make them less eye-catching
439 for( unsigned int stripeGap = 1; stripeGap < numStripes; ++stripeGap )
440 {
441 const int stripeColumn = -1 + stripeGap * 4;
442
443 m_GridEseries2496->SetCellBackgroundColour( 0, stripeColumn, s_colourMatching );
444 }
445
446 m_GridEseries2496->EndBatch();
447}
const char * name
Definition: DXF_plotter.cpp:57
Class PANEL_ESERIES_DISPLAY_BASE.
wxColour m_colourE48Pair[2]
Calculated colours for E48 column in current (light,dark) theme.
static constexpr uint32_t s_cE96BGR
Colour for E96 column in light theme. Passed to wxColour constructor.
wxColour m_colourE6Pair[2]
Calculated colours for E6 column in current (light,dark) theme.
wxColour m_colourE12Pair[2]
Calculated colours for E12 column in current (light,dark) theme.
wxColour s_colourMatching
Calculated matching colour for empty columns. Same as background of labels.
void recolourE2496Tree()
Colour large E-series tree according to current theme.
static constexpr uint32_t s_cE3BGR
Colour for E3 column in light theme. Passed to wxColour constructor.
static constexpr int s_darkAdjustValue
Adjustment factor to create darker grid cells in dark theme.
void LoadSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Load the settings into the panel.
void populateE2496Tree()
Fill larger E-series tree with values.
static constexpr uint32_t s_cE1BGR
Colour for E1 column in light theme. Passed to wxColour constructor.
static constexpr uint32_t s_cE48BGR
Colour for E48 column in light theme. Passed to wxColour constructor.
wxColour m_colourE24Pair[2]
Calculated colours for E24 column in current (light,dark) theme.
wxColour m_colourE1Column
Calculated colour for E1 column in current (light,dark) theme.
static constexpr uint32_t s_cE6BGR
Colour for E6 column in light theme. Passed to wxColour constructor.
static constexpr int s_altAdjustValue
Adjustment factor to create alternating R-series table entry colours.
void ThemeChanged() override
Update UI elements of the panel when the theme changes to ensure the images and fonts/colors are appr...
void recolourE112Tree()
Colour small E-series tree according to current theme.
void recalculateColumnColours(bool aDarkModeOn)
Recalculate colours used to highlight the E-series columns.
static constexpr uint32_t s_cE24BGR
Colour for E24 column in light theme. Passed to wxColour constructor.
void SaveSettings(PCB_CALCULATOR_SETTINGS *aCfg) override
Save the settings from the panel.
PANEL_ESERIES_DISPLAY(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxColour m_colourE96Pair[2]
Calculated colours for E96 column in current (light,dark) theme.
static constexpr uint32_t s_cE12BGR
Colour for E12 column in light theme. Passed to wxColour constructor.
wxColour m_colourE3Pair[2]
Calculated colours for E3 column in current (light,dark) theme.
void populateE112Tree()
Fill small E-series tree with values.
Some functions to handle hotkeys in KiCad.
@ E24
Definition: eseries.h:74
@ E12
Definition: eseries.h:73
@ E96
Definition: eseries.h:76
void ConvertMarkdown2Html(const wxString &aMarkdownInput, wxString &aHtmlOutput)