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 wxColour gridLineColour = parent->GetBackgroundColour();
72
73 m_GridEseries112->SetGridLineColour( gridLineColour );
74 m_GridEseries112->EnableGridLines( true );
75
76 m_GridEseries112->SetColLabelSize( wxGRID_AUTOSIZE );
77 m_GridEseries112->AutoSize();
78
79 m_GridEseries2496->SetGridLineColour( gridLineColour );
80 m_GridEseries2496->EnableGridLines( true );
81
82 m_GridEseries2496->SetColLabelSize( wxGRID_AUTOSIZE );
83 m_GridEseries2496->AutoSize();
84
85 Layout();
86}
87
88
90{
91}
92
93
95{
96 // Calculate E1,E3,E6,E12,E24,E48,E96 column background colours
97 // Get appearances.
98 const wxSystemAppearance appearances = wxSystemSettings::GetAppearance();
99 const bool selectDark = appearances.IsDark();
100
101 recalculateColumnColours( selectDark );
102
103 // Set colours of smaller tree.
105
106 // Set colours of larger tree.
108}
109
110
112{
113}
114
115
117{
118}
119
120
122{
123 // if in a dark mode then darken colors significantly so that
124 // the white numerals on top stand out better
125 const int colourAdjust = aDarkModeOn ? s_darkAdjustValue : 100;
126
127 m_colourE1Column = wxColour( s_cE1BGR ).ChangeLightness( colourAdjust );
128 const wxColour colourE3Column( wxColour( s_cE3BGR ).ChangeLightness( colourAdjust ) );
129 const wxColour colourE6Column( wxColour( s_cE6BGR ).ChangeLightness( colourAdjust ) );
130 const wxColour colourE12Column( wxColour( s_cE12BGR ).ChangeLightness( colourAdjust ) );
131 const wxColour colourE24Column( wxColour( s_cE24BGR ).ChangeLightness( colourAdjust ) );
132 const wxColour colourE48Column( wxColour( s_cE48BGR ).ChangeLightness( colourAdjust ) );
133 const wxColour colourE96Column( wxColour( s_cE96BGR ).ChangeLightness( colourAdjust ) );
134
135 m_colourE3Pair[0] = colourE3Column;
136 m_colourE3Pair[1] = colourE3Column.ChangeLightness( s_altAdjustValue );
137 m_colourE6Pair[0] = colourE6Column;
138 m_colourE6Pair[1] = colourE6Column.ChangeLightness( s_altAdjustValue );
139 m_colourE12Pair[0] = colourE12Column;
140 m_colourE12Pair[1] = colourE12Column.ChangeLightness( s_altAdjustValue );
141 m_colourE24Pair[0] = colourE24Column;
142 m_colourE24Pair[1] = colourE24Column.ChangeLightness( s_altAdjustValue );
143 m_colourE48Pair[0] = colourE48Column;
144 m_colourE48Pair[1] = colourE48Column.ChangeLightness( s_altAdjustValue );
145 m_colourE96Pair[0] = colourE96Column;
146 m_colourE96Pair[1] = colourE96Column.ChangeLightness( s_altAdjustValue );
147
148 s_colourMatching = m_GridEseries2496->GetLabelBackgroundColour();
149}
150
151
153{
154 // Lay out E1, R3, E6, E12 tree.
156
157 int row = 0;
158 wxString value;
159
160 m_GridEseries112->BeginBatch();
161
162 m_GridEseries112->DeleteCols( 0, m_GridEseries112->GetNumberCols() );
163 m_GridEseries112->DeleteRows( 0, m_GridEseries112->GetNumberRows() );
164 m_GridEseries112->AppendCols( 4 ); // E1, E3, E6, E12
165 m_GridEseries112->AppendRows( 12 ); // Sufficient rows for all of E12
166
167 m_GridEseries112->SetColLabelValue( 0, "E1" );
168 m_GridEseries112->SetColLabelValue( 1, "E3" );
169 m_GridEseries112->SetColLabelValue( 2, "E6" );
170 m_GridEseries112->SetColLabelValue( 3, "E12" );
171
172 value = wxString( "" ) << eSeries12[0];
173
174 m_GridEseries112->SetCellValue( 0, 0, value );
175 m_GridEseries112->SetCellSize( 0, 0, 12, 1 );
176
177 for( const uint16_t& seriesEntry : eSeries12 )
178 {
179 value = wxString( "" ) << seriesEntry;
180
181 if( 0 == row % 4 )
182 {
183 // Set E3 column
184 m_GridEseries112->SetCellValue( row, 1, value );
185 m_GridEseries112->SetCellSize( row, 1, 4, 1 );
186 }
187
188 if( 0 == row % 2 )
189 {
190 // Set E6 column
191 m_GridEseries112->SetCellValue( row, 2, value );
192 m_GridEseries112->SetCellSize( row, 2, 2, 1 );
193 }
194
195 // Set E12 column
196 m_GridEseries112->SetCellValue( row, 3, value );
197
198 ++row;
199 }
200
201 for( int i = 0; i < 3; ++i )
202 {
203 // Resize data columns to fit data and set as minimum size
204 m_GridEseries112->AutoSizeColumn( i, true );
205 }
206
207 m_GridEseries112->EndBatch();
208}
209
210
212{
213 // Lay out E24, E48, E96 tree.
216
217 // This is the number of times the table is wrapped around into another
218 // column. Like in a newspaper. The term column is not used since
219 // the grid already has columns. The 96 in the second calculation
220 // is the number of entries in the largest series displayed (E96)
221 constexpr unsigned int numStripes = 4;
222 constexpr unsigned int stripeHeight = 96 / numStripes;
223
224 int idx = 0;
225 int stripe = 0;
226 wxString value;
227
228 m_GridEseries2496->BeginBatch();
229
230 m_GridEseries2496->DeleteCols( 0, m_GridEseries2496->GetNumberCols() );
231 m_GridEseries2496->DeleteRows( 0, m_GridEseries2496->GetNumberRows() );
232
233 // Column headers are E24, E48, E96, -
234 // repeated numStripes times over. And the last - is omitted.
235 m_GridEseries2496->AppendCols( numStripes * 4 - 1 );
236 m_GridEseries2496->AppendRows( stripeHeight );
237
238 m_GridEseries2496->SetColLabelValue( 0 + 0, "E24" );
239 m_GridEseries2496->SetColLabelValue( 1 + 0, "E48" );
240 m_GridEseries2496->SetColLabelValue( 2 + 0, "E96" );
241 m_GridEseries2496->SetColLabelValue( 3 + 0, "-" );
242
243 m_GridEseries2496->SetColLabelValue( 0 + 4, "E24" );
244 m_GridEseries2496->SetColLabelValue( 1 + 4, "E48" );
245 m_GridEseries2496->SetColLabelValue( 2 + 4, "E96" );
246 m_GridEseries2496->SetColLabelValue( 3 + 4, "-" );
247
248 m_GridEseries2496->SetColLabelValue( 0 + 8, "E24" );
249 m_GridEseries2496->SetColLabelValue( 1 + 8, "E48" );
250 m_GridEseries2496->SetColLabelValue( 2 + 8, "E96" );
251 m_GridEseries2496->SetColLabelValue( 3 + 8, "-" );
252
253 m_GridEseries2496->SetColLabelValue( 0 + 12, "E24" );
254 m_GridEseries2496->SetColLabelValue( 1 + 12, "E48" );
255 m_GridEseries2496->SetColLabelValue( 2 + 12, "E96" );
256
257 for( const uint16_t& seriesEntry : eSeries24 )
258 {
259 value = wxString( "" ) << seriesEntry;
260
261 int row = ( idx * 4 ) % stripeHeight;
262 int colOffset = ( ( idx * 4 ) / stripeHeight ) * 4;
263
264 m_GridEseries2496->SetCellValue( row, colOffset, value );
265 m_GridEseries2496->SetCellSize( row, colOffset, 4, 1 );
266
267 ++idx;
268 }
269
270 idx = 0;
271
272 for( const uint16_t& seriesEntry : eSeries96 )
273 {
274 value = wxString( "" ) << seriesEntry;
275
276 int row = idx % stripeHeight;
277 int colOffset = ( idx / stripeHeight ) * 4;
278
279 if( 0 == row % 2 )
280 {
281 // Set E48 column
282 m_GridEseries2496->SetCellValue( row, colOffset + 1, value );
283 m_GridEseries2496->SetCellSize( row, colOffset + 1, 2, 1 );
284 }
285
286 // Set E96 column
287 m_GridEseries2496->SetCellValue( row, colOffset + 2, value );
288 ++idx;
289 }
290
291 // cause the areas between stripes to appear more empty
292 // by making them a single cell the height of the stripe
293 // this causes the horizontal row lines rows to disappear
294 for( unsigned int stripeGap = 1; stripeGap < numStripes; ++stripeGap )
295 {
296 const int stripeColumn = -1 + stripeGap * 4;
297
298 m_GridEseries2496->SetCellSize( 0, stripeColumn, stripeHeight, 1 );
299 }
300
301 for( int i = 0; i < numStripes * 4 - 1; ++i )
302 {
303 // Resize the column to fit data and set as minimum size
304 m_GridEseries2496->AutoSizeColumn( i, true );
305 }
306
307 m_GridEseries2496->EndBatch();
308}
309
310
312{
313 const unsigned int numRows = m_GridEseries112->GetNumberRows();
314
315 m_GridEseries112->BeginBatch();
316
317 // Colouring E1 is easy. There is only one item.
318 m_GridEseries112->SetCellBackgroundColour( 0, 0, m_colourE1Column );
319
320 bool alternateColour = false;
321 int cellWidth = 0, cellHeight = 0;
322
323 // Colour E3 column
324 for( int row = 0; row < numRows; row += cellHeight )
325 {
326 m_GridEseries112->SetCellBackgroundColour( row, 1, m_colourE3Pair[alternateColour] );
327
328 // get height for iteration above
329 m_GridEseries112->GetCellSize( row, 1, &cellHeight, &cellWidth );
330 alternateColour = !alternateColour;
331
332 if( cellHeight < 1 )
333 cellHeight = 1; // Do not loop forever, always make progress.
334 }
335
336 // Colour E6 column
337 alternateColour = false;
338
339 for( int row = 0; row < numRows; row += cellHeight )
340 {
341 m_GridEseries112->SetCellBackgroundColour( row, 2, m_colourE6Pair[alternateColour] );
342
343 // get height for iteration above
344 m_GridEseries112->GetCellSize( row, 2, &cellHeight, &cellWidth );
345 alternateColour = !alternateColour;
346
347 if( cellHeight < 1 )
348 cellHeight = 1; // Do not loop forever, always make progress.
349 }
350
351 // Colour E12 column
352 alternateColour = false;
353
354 for( int row = 0; row < numRows; row += cellHeight )
355 {
356 m_GridEseries112->SetCellBackgroundColour( row, 3, m_colourE12Pair[alternateColour] );
357
358 // get height for iteration above
359 m_GridEseries112->GetCellSize( row, 3, &cellHeight, &cellWidth );
360 alternateColour = !alternateColour;
361
362 if( cellHeight < 1 )
363 cellHeight = 1; // Do not loop forever, always make progress.
364 }
365
366 m_GridEseries112->EndBatch();
367}
368
369
371{
372 const unsigned int numRows = m_GridEseries2496->GetNumberRows();
373 constexpr unsigned int numStripes = 4;
374 constexpr unsigned int stripeHeight = 96 / numStripes;
375
376 m_GridEseries2496->BeginBatch();
377
378 bool alternateColour = false;
379 int cellWidth = 0, cellHeight = 0;
380
381 // Colour E24 columns
382 for( int row = 0; row < numRows; row += cellHeight )
383 {
384 for( int stripe = 0; stripe < numStripes; ++stripe )
385 {
386 m_GridEseries2496->SetCellBackgroundColour( row, 0 + 4 * stripe,
387 m_colourE24Pair[alternateColour] );
388 }
389 // get height for iteration above
390 m_GridEseries2496->GetCellSize( row, 0, &cellHeight, &cellWidth );
391 alternateColour = !alternateColour;
392
393 if( cellHeight < 1 )
394 cellHeight = 1; // Do not loop forever, always make progress.
395 }
396
397 // Colour E48 columns
398 alternateColour = false;
399
400 for( int row = 0; row < numRows; row += cellHeight )
401 {
402 for( int stripe = 0; stripe < numStripes; ++stripe )
403 {
404 m_GridEseries2496->SetCellBackgroundColour( row, 1 + 4 * stripe,
405 m_colourE48Pair[alternateColour] );
406 }
407 // get height for iteration above
408 m_GridEseries2496->GetCellSize( row, 1, &cellHeight, &cellWidth );
409 alternateColour = !alternateColour;
410
411 if( cellHeight < 1 )
412 cellHeight = 1; // Do not loop forever, always make progress.
413 }
414
415 // Colour E96 columns
416 alternateColour = false;
417
418 for( int row = 0; row < numRows; row += cellHeight )
419 {
420 for( int stripe = 0; stripe < numStripes; ++stripe )
421 {
422 m_GridEseries2496->SetCellBackgroundColour( row, 2 + 4 * stripe,
423 m_colourE96Pair[alternateColour] );
424 }
425 // get height for iteration above
426 m_GridEseries2496->GetCellSize( row, 2, &cellHeight, &cellWidth );
427 alternateColour = !alternateColour;
428
429 if( cellHeight < 1 )
430 cellHeight = 1; // Do not loop forever, always make progress.
431 }
432
433 // recolour empty areas between columns to match label background
434 // to make them less eye-catching
435 for( unsigned int stripeGap = 1; stripeGap < numStripes; ++stripeGap )
436 {
437 const int stripeColumn = -1 + stripeGap * 4;
438
439 m_GridEseries2496->SetCellBackgroundColour( 0, stripeColumn, s_colourMatching );
440 }
441
442 m_GridEseries2496->EndBatch();
443}
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)