KiCad PCB EDA Suite
Loading...
Searching...
No Matches
simulator_frame_ui.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) 2016-2023 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * https://www.gnu.org/licenses/gpl-3.0.html
22 * or you may search the http://www.gnu.org website for the version 3 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <algorithm>
28#include <memory>
29#include <type_traits>
30
31#include <wx/event.h>
32#include <fmt/format.h>
33#include <wx/wfstream.h>
34#include <wx/stdstream.h>
35#include <wx/debug.h>
36#include <wx/clipbrd.h>
37#include <wx/log.h>
38
40#include <sch_edit_frame.h>
41#include <confirm.h>
45#include <widgets/wx_grid.h>
46#include <grid_tricks.h>
47#include <eda_pattern_match.h>
48#include <string_utils.h>
49#include <pgm_base.h>
51#include <sim/simulator_frame.h>
52#include <sim/sim_plot_tab.h>
53#include <sim/spice_simulator.h>
56#include <eeschema_settings.h>
57#include <advanced_config.h>
58#include <magic_enum.hpp>
59
60
62{
63 int res = static_cast<int>( aFirst ) | static_cast<int>( aSecond);
64
65 return static_cast<SIM_TRACE_TYPE>( res );
66}
67
68
77
78
86
87
94
95
96enum
97{
107
110};
111
112
114{
115public:
117 GRID_TRICKS( aGrid ),
118 m_parent( aParent ),
119 m_menuRow( 0 ),
120 m_menuCol( 0 )
121 {}
122
123protected:
124 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
125 void doPopupSelection( wxCommandEvent& event ) override;
126
127protected:
131};
132
133
134void SIGNALS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
135{
136 SIM_TAB* panel = m_parent->GetCurrentSimTab();
137
138 if( !panel )
139 return;
140
141 m_menuRow = aEvent.GetRow();
142 m_menuCol = aEvent.GetCol();
143
145 {
146 if( !( m_grid->IsInSelection( m_menuRow, m_menuCol ) ) )
147 m_grid->ClearSelection();
148
149 m_grid->SetGridCursor( m_menuRow, m_menuCol );
150
151 if( panel->GetSimType() == ST_TRAN || panel->GetSimType() == ST_AC
152 || panel->GetSimType() == ST_DC || panel->GetSimType() == ST_SP )
153 {
154 menu.Append( MYID_MEASURE_MIN, _( "Measure Min" ) );
155 menu.Append( MYID_MEASURE_MAX, _( "Measure Max" ) );
156 menu.Append( MYID_MEASURE_AVG, _( "Measure Average" ) );
157 menu.Append( MYID_MEASURE_RMS, _( "Measure RMS" ) );
158 menu.Append( MYID_MEASURE_PP, _( "Measure Peak-to-peak" ) );
159
160 if( panel->GetSimType() == ST_AC || panel->GetSimType() == ST_SP )
161 {
162 menu.Append( MYID_MEASURE_MIN_AT, _( "Measure Frequency of Min" ) );
163 menu.Append( MYID_MEASURE_MAX_AT, _( "Measure Frequency of Max" ) );
164 }
165 else
166 {
167 menu.Append( MYID_MEASURE_MIN_AT, _( "Measure Time of Min" ) );
168 menu.Append( MYID_MEASURE_MAX_AT, _( "Measure Time of Max" ) );
169 }
170
171 menu.Append( MYID_MEASURE_INTEGRAL, _( "Measure Integral" ) );
172
173 if( panel->GetSimType() == ST_TRAN )
174 {
175 menu.AppendSeparator();
176 menu.Append( MYID_FOURIER, _( "Perform Fourier Analysis..." ) );
177 }
178
179 menu.AppendSeparator();
180 menu.Append( GRIDTRICKS_ID_COPY, _( "Copy Signal Name" ) + "\tCtrl+C" );
181
182 menu.AppendSeparator();
183 menu.Append( GRIDTRICKS_ID_SELECT, _( "Create new cursor..." ) );
184
185 m_grid->PopupMenu( &menu );
186 }
187 }
188 else if( m_menuCol > static_cast<int>( COL_CURSOR_2 ) )
189 {
190 menu.Append( GRIDTRICKS_ID_SELECT, _( "Create new cursor..." ) );
191
192 menu.AppendSeparator();
193
194 wxString msg = m_grid->GetColLabelValue( m_grid->GetNumberCols() - 1 );
195
196 menu.AppendSeparator();
197 menu.Append( GRIDTRICKS_ID_DELETE, wxString::Format( _( "Delete %s..." ), msg ) );
198
199 m_grid->PopupMenu( &menu );
200 }
201 else
202 {
203 menu.Append( GRIDTRICKS_ID_SELECT, _( "Create new cursor..." ) );
204
205 m_grid->PopupMenu( &menu );
206 }
207}
208
209
210void SIGNALS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
211{
212 std::vector<wxString> signals;
213
214 wxGridCellCoordsArray cells1 = m_grid->GetSelectionBlockTopLeft();
215 wxGridCellCoordsArray cells2 = m_grid->GetSelectionBlockBottomRight();
216
217 for( size_t i = 0; i < cells1.Count(); i++ )
218 {
219 if( cells1[i].GetCol() == COL_SIGNAL_NAME )
220 {
221 for( int j = cells1[i].GetRow(); j < cells2[i].GetRow() + 1; j++ )
222 {
223 signals.push_back( m_grid->GetCellValue( j, cells1[i].GetCol() ) );
224 }
225 }
226 }
227
228 wxGridCellCoordsArray cells3 = m_grid->GetSelectedCells();
229
230 for( size_t i = 0; i < cells3.Count(); i++ )
231 {
232 if( cells3[i].GetCol() == COL_SIGNAL_NAME )
233 signals.push_back( m_grid->GetCellValue( cells3[i].GetRow(), cells3[i].GetCol() ) );
234 }
235
236 if( signals.size() < 1 )
237 signals.push_back( m_grid->GetCellValue( m_menuRow, m_menuCol ) );
238
239 auto addMeasurement =
240 [this]( const wxString& cmd, wxString signal )
241 {
242 if( signal.EndsWith( _( " (phase)" ) ) )
243 return;
244
245 if( signal.EndsWith( _( " (gain)" ) ) || signal.EndsWith( _( " (amplitude)" ) ) )
246 {
247 signal = signal.Left( signal.length() - 7 );
248
249 if( signal.Upper().StartsWith( wxS( "V(" ) ) )
250 signal = wxS( "vdb" ) + signal.Mid( 1 );
251 }
252
253 m_parent->AddMeasurement( cmd + wxS( " " ) + signal );
254 };
255
256 if( event.GetId() == MYID_MEASURE_MIN )
257 {
258 for( const wxString& signal : signals )
259 addMeasurement( wxS( "MIN" ), signal );
260 }
261 else if( event.GetId() == MYID_MEASURE_MAX )
262 {
263 for( const wxString& signal : signals )
264 addMeasurement( wxS( "MAX" ), signal );
265 }
266 else if( event.GetId() == MYID_MEASURE_AVG )
267 {
268 for( const wxString& signal : signals )
269 addMeasurement( wxS( "AVG" ), signal );
270 }
271 else if( event.GetId() == MYID_MEASURE_RMS )
272 {
273 for( const wxString& signal : signals )
274 addMeasurement( wxS( "RMS" ), signal );
275 }
276 else if( event.GetId() == MYID_MEASURE_PP )
277 {
278 for( const wxString& signal : signals )
279 addMeasurement( wxS( "PP" ), signal );
280 }
281 else if( event.GetId() == MYID_MEASURE_MIN_AT )
282 {
283 for( const wxString& signal : signals )
284 addMeasurement( wxS( "MIN_AT" ), signal );
285 }
286 else if( event.GetId() == MYID_MEASURE_MAX_AT )
287 {
288 for( const wxString& signal : signals )
289 addMeasurement( wxS( "MAX_AT" ), signal );
290 }
291 else if( event.GetId() == MYID_MEASURE_INTEGRAL )
292 {
293 for( const wxString& signal : signals )
294 addMeasurement( wxS( "INTEG" ), signal );
295 }
296 else if( event.GetId() == MYID_FOURIER )
297 {
298 wxString title;
299 wxString fundamental = wxT( "1K" );
300
301 if( signals.size() == 1 )
302 title.Printf( _( "Fourier Analysis of %s" ), signals[0] );
303 else
304 title = _( "Fourier Analyses of Multiple Signals" );
305
306 WX_TEXT_ENTRY_DIALOG dlg( m_parent, _( "Fundamental frequency:" ), title, fundamental );
307
308 if( dlg.ShowModal() != wxID_OK )
309 return;
310
311 if( !dlg.GetValue().IsEmpty() )
312 fundamental = dlg.GetValue();
313
314 for( const wxString& signal : signals )
315 m_parent->DoFourier( signal, fundamental );
316 }
317 else if( event.GetId() == GRIDTRICKS_ID_COPY )
318 {
319 wxLogNull doNotLog; // disable logging of failed clipboard actions
320 wxString txt;
321
322 for( const wxString& signal : signals )
323 {
324 if( !txt.IsEmpty() )
325 txt += '\r';
326
327 txt += signal;
328 }
329
330 if( wxTheClipboard->Open() )
331 {
332 wxTheClipboard->SetData( new wxTextDataObject( txt ) );
333 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
334 wxTheClipboard->Close();
335 }
336 }
337 else if( event.GetId() == GRIDTRICKS_ID_SELECT )
338 {
339 m_parent->CreateNewCursor();
340 }
341 else if( event.GetId() == GRIDTRICKS_ID_DELETE )
342 {
343 m_parent->DeleteCursor();
344 }
345}
346
347
349{
350public:
352 GRID_TRICKS( aGrid ),
353 m_parent( aParent ),
354 m_menuRow( 0 ),
355 m_menuCol( 0 )
356 {}
357
358protected:
359 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
360 void doPopupSelection( wxCommandEvent& event ) override;
361
362protected:
366};
367
368
369void CURSORS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
370{
371 m_menuRow = aEvent.GetRow();
372 m_menuCol = aEvent.GetCol();
373
375 {
376 wxString msg = m_grid->GetColLabelValue( m_menuCol );
377
378 menu.Append( MYID_FORMAT_VALUE, wxString::Format( _( "Format %s..." ), msg ) );
379 menu.AppendSeparator();
380 }
381
382 GRID_TRICKS::showPopupMenu( menu, aEvent );
383}
384
385
386void CURSORS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
387{
388 auto getSignalName =
389 [this]( int row ) -> wxString
390 {
391 wxString signal = m_grid->GetCellValue( row, COL_CURSOR_SIGNAL );
392
393 if( signal.EndsWith( "[2 - 1]" ) )
394 signal = signal.Left( signal.length() - 7 );
395
396 return signal;
397 };
398
399 if( event.GetId() == MYID_FORMAT_VALUE )
400 {
401 int axis = m_menuCol - COL_CURSOR_X;
402 SPICE_VALUE_FORMAT format = m_parent->GetCursorFormat( m_menuRow, axis );
403 DIALOG_SIM_FORMAT_VALUE formatDialog( m_parent, &format );
404
405 if( formatDialog.ShowModal() == wxID_OK )
406 {
407 for( int row = 0; row < m_grid->GetNumberRows(); ++row )
408 {
409 if( getSignalName( row ) == getSignalName( m_menuRow ) )
410 m_parent->SetCursorFormat( row, axis, format );
411 }
412 }
413 }
414 else
415 {
417 }
418}
419
420
422{
423public:
425 GRID_TRICKS( aGrid ),
426 m_parent( aParent ),
427 m_menuRow( 0 ),
428 m_menuCol( 0 )
429 {}
430
431protected:
432 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
433 void doPopupSelection( wxCommandEvent& event ) override;
434
435protected:
439};
440
441
442void MEASUREMENTS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
443{
444 m_menuRow = aEvent.GetRow();
445 m_menuCol = aEvent.GetCol();
446
447 if( !( m_grid->IsInSelection( m_menuRow, m_menuCol ) ) )
448 m_grid->ClearSelection();
449
450 m_grid->SetGridCursor( m_menuRow, m_menuCol );
451
453 menu.Append( MYID_FORMAT_VALUE, _( "Format Value..." ) );
454
455 if( m_menuRow < ( m_grid->GetNumberRows() - 1 ) )
456 menu.Append( MYID_DELETE_MEASUREMENT, _( "Delete Measurement" ) );
457
458 menu.AppendSeparator();
459
460 GRID_TRICKS::showPopupMenu( menu, aEvent );
461}
462
463
465{
466 if( event.GetId() == MYID_FORMAT_VALUE )
467 {
468 SPICE_VALUE_FORMAT format = m_parent->GetMeasureFormat( m_menuRow );
469 DIALOG_SIM_FORMAT_VALUE formatDialog( m_parent, &format );
470
471 if( formatDialog.ShowModal() == wxID_OK )
472 {
473 m_parent->SetMeasureFormat( m_menuRow, format );
474 m_parent->UpdateMeasurement( m_menuRow );
475 m_parent->OnModify();
476 }
477 }
478 else if( event.GetId() == MYID_DELETE_MEASUREMENT )
479 {
480 std::vector<int> measurements;
481
482 wxGridCellCoordsArray cells1 = m_grid->GetSelectionBlockTopLeft();
483 wxGridCellCoordsArray cells2 = m_grid->GetSelectionBlockBottomRight();
484
485 for( size_t i = 0; i < cells1.Count(); i++ )
486 {
487 if( cells1[i].GetCol() == COL_MEASUREMENT )
488 {
489 for( int j = cells1[i].GetRow(); j < cells2[i].GetRow() + 1; j++ )
490 measurements.push_back( j );
491 }
492 }
493
494 wxGridCellCoordsArray cells3 = m_grid->GetSelectedCells();
495
496 for( size_t i = 0; i < cells3.Count(); i++ )
497 {
498 if( cells3[i].GetCol() == COL_MEASUREMENT )
499 measurements.push_back( cells3[i].GetRow() );
500 }
501
502 if( measurements.size() < 1 )
503 measurements.push_back( m_menuRow );
504
505 // When deleting a row, we'll change the indexes.
506 // To avoid problems, we can start with the highest indexes.
507 sort( measurements.begin(), measurements.end(), std::greater<>() );
508
509 for( int row : measurements )
510 m_parent->DeleteMeasurement( row );
511
512 m_grid->ClearSelection();
513
514 m_parent->OnModify();
515 }
516 else
517 {
519 }
520}
521
522
524{
525public:
527 m_frame( aFrame )
528 {
529 m_frame->m_SuppressGridEvents++;
530 }
531
533 {
534 m_frame->m_SuppressGridEvents--;
535 }
536
537private:
539};
540
541
542#define ID_SIM_REFRESH 10207
543#define REFRESH_INTERVAL 50 // 20 frames/second.
544
545
547 SCH_EDIT_FRAME* aSchematicFrame ) :
548 SIMULATOR_FRAME_UI_BASE( aSimulatorFrame ),
550 m_simulatorFrame( aSimulatorFrame ),
551 m_schematicFrame( aSchematicFrame ),
552 m_darkMode( true ),
553 m_plotNumber( 0 ),
555{
556 // Get the previous size and position of windows:
557 LoadSettings( m_schematicFrame->eeconfig() );
558
559 m_filter->SetHint( _( "Filter" ) );
560
561 m_signalsGrid->wxGrid::SetLabelFont( KIUI::GetStatusFont( this ) );
562 m_cursorsGrid->wxGrid::SetLabelFont( KIUI::GetStatusFont( this ) );
563 m_measurementsGrid->wxGrid::SetLabelFont( KIUI::GetStatusFont( this ) );
564
565 m_signalsGrid->PushEventHandler( new SIGNALS_GRID_TRICKS( this, m_signalsGrid ) );
566 m_cursorsGrid->PushEventHandler( new CURSORS_GRID_TRICKS( this, m_cursorsGrid ) );
567 m_measurementsGrid->PushEventHandler( new MEASUREMENTS_GRID_TRICKS( this, m_measurementsGrid ) );
568
569 wxGridCellAttr* attr = new wxGridCellAttr;
570 attr->SetReadOnly();
571 m_signalsGrid->SetColAttr( COL_SIGNAL_NAME, attr );
572
573 attr = new wxGridCellAttr;
574 attr->SetReadOnly();
575 m_cursorsGrid->SetColAttr( COL_CURSOR_NAME, attr );
576
577 attr = new wxGridCellAttr;
578 attr->SetReadOnly();
579 m_cursorsGrid->SetColAttr( COL_CURSOR_SIGNAL, attr );
580
581 attr = new wxGridCellAttr;
582 attr->SetReadOnly();
583 m_cursorsGrid->SetColAttr( COL_CURSOR_Y, attr );
584
586
587 attr = new wxGridCellAttr;
588 attr->SetReadOnly();
589 m_measurementsGrid->SetColAttr( COL_MEASUREMENT_VALUE, attr );
590
591 // Prepare the color list to plot traces
593
594 Bind( EVT_SIM_CURSOR_UPDATE, &SIMULATOR_FRAME_UI::onPlotCursorUpdate, this );
595
596 Bind( wxEVT_TIMER,
597 [&]( wxTimerEvent& aEvent )
598 {
599 OnSimRefresh( false );
600
601 if( m_simulatorFrame->GetSimulator()->IsRunning() )
602 m_refreshTimer.Start( REFRESH_INTERVAL, wxTIMER_ONE_SHOT );
603 },
604 m_refreshTimer.GetId() );
605
606#ifndef wxHAS_NATIVE_TABART
607 // Default non-native tab art has ugly gradients we don't want
608 m_plotNotebook->SetArtProvider( new wxAuiSimpleTabArt() );
609#endif
610}
611
612
614{
615 // Delete the GRID_TRICKS.
616 m_signalsGrid->PopEventHandler( true );
617 m_cursorsGrid->PopEventHandler( true );
618 m_measurementsGrid->PopEventHandler( true );
619}
620
621
623{
624 for( auto& m_cursorFormat : m_cursorFormats )
625 {
626 m_cursorFormat[0] = { 3, wxS( "~s" ) };
627 m_cursorFormat[1] = { 3, wxS( "~V" ) };
628 }
629
630 // proper init and transfer/copy m_cursorFormats
631 // we work on m_cursorFormatsDyn from now on.
632 // TODO: rework +- LOC when m_cursorFormatsDyn and m_cursorFormats get merged.
633 m_cursorFormatsDyn.clear();
634 m_cursorFormatsDyn.resize( std::size( m_cursorFormats ) );
635
636 for( size_t index = 0; index < std::size( m_cursorFormats ); index++ )
637 {
638 for( size_t index2 = 0; index2 < std::size( m_cursorFormats[0] ); index2++ )
639 {
640 m_cursorFormatsDyn[index].push_back( m_cursorFormats[index][index2] );
641 }
642 }
643
644 // Dump string helper, tries to get the current higher cursor name to form the next one.
645 // Based on the column labeling
646 // TODO: "Cursor n" may translate as "n Cursor" in other languages
647 // TBD how to handle; just forbid for now.
648 int nameMax = 0;
649
650 for( int i = 0; i < m_signalsGrid->GetNumberCols(); i++ )
651 {
652 wxString maxCursor = m_signalsGrid->GetColLabelValue( i );
653
654 maxCursor.Replace( _( "Cursor " ), "" );
655
656 int tmpMax = wxAtoi( maxCursor );
657
658 if( nameMax < tmpMax )
659 nameMax = tmpMax;
660 }
661
662 m_customCursorsCnt = nameMax + 1; // Init with a +1 on top of current cursor 2, defaults to 3
663}
664
665
667{
668 std::vector<SPICE_VALUE_FORMAT> tmp;
669 // m_cursorFormatsDyn should be equal with m_cursorFormats on first entry here.
670 m_cursorFormatsDyn.emplace_back( tmp );
671
672 m_cursorFormatsDyn[m_customCursorsCnt].push_back( { 3, wxS( "~s" ) } );
673 m_cursorFormatsDyn[m_customCursorsCnt].push_back( { 3, wxS( "~V" ) } );
674
675 wxString cursor_name = wxString( _( "Cursor " ) ) << m_customCursorsCnt;
676
677 m_signalsGrid->InsertCols( m_signalsGrid->GetNumberCols() , 1, true );
678 m_signalsGrid->SetColLabelValue( m_signalsGrid->GetNumberCols() - 1, cursor_name );
679
680 wxGridCellAttr* attr = new wxGridCellAttr;
681 m_signalsGrid->SetColAttr( COL_CURSOR_2 + m_customCursorsCnt, attr );
682
684
687 OnModify();
688}
689
690
692{
693 int col = m_signalsGrid->GetNumberCols();
694 int rows = m_signalsGrid->GetNumberRows();
695
696 if( col > COL_CURSOR_2 )
697 {
698 // Now we need to find the active cursor and deactivate before removing the column,
699 // Send the dummy event to update the UI
700 for( int i = 0; i < rows; i++ )
701 {
702 if( m_signalsGrid->GetCellValue( i, col - 1 ) == wxS( "1" ) )
703 {
704 m_signalsGrid->SetCellValue( i, col - 1, wxEmptyString );
705 wxGridEvent aDummy( wxID_ANY, wxEVT_GRID_CELL_CHANGED, m_signalsGrid, i, col - 1 );
706 onSignalsGridCellChanged( aDummy );
707 break;
708 }
709
710 }
711
712 m_signalsGrid->DeleteCols( col - 1, 1, false );
713 m_cursorFormatsDyn.pop_back();
715 m_plotNotebook->Refresh();
718 OnModify();
719 }
720}
721
722
724{
725 for( int ii = 0; ii < static_cast<int>( m_plotNotebook->GetPageCount() ); ++ii )
726 {
727 if( SIM_TAB* simTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( ii ) ) )
728 {
729 simTab->OnLanguageChanged();
730
731 wxString pageTitle( simulator()->TypeToName( simTab->GetSimType(), true ) );
732 pageTitle.Prepend( wxString::Format( _( "Analysis %u - " ), ii+1 /* 1-based */ ) );
733
734 m_plotNotebook->SetPageText( ii, pageTitle );
735 }
736 }
737
738 m_filter->SetHint( _( "Filter" ) );
739
740 m_signalsGrid->SetColLabelValue( COL_SIGNAL_NAME, _( "Signal" ) );
741 m_signalsGrid->SetColLabelValue( COL_SIGNAL_SHOW, _( "Plot" ) );
742 m_signalsGrid->SetColLabelValue( COL_SIGNAL_COLOR, _( "Color" ) );
743 m_signalsGrid->SetColLabelValue( COL_CURSOR_1, _( "Cursor 1" ) );
744 m_signalsGrid->SetColLabelValue( COL_CURSOR_2, _( "Cursor 2" ) );
745
746 m_cursorsGrid->SetColLabelValue( COL_CURSOR_NAME, _( "Cursor" ) );
747 m_cursorsGrid->SetColLabelValue( COL_CURSOR_SIGNAL, _( "Signal" ) );
748 m_cursorsGrid->SetColLabelValue( COL_CURSOR_X, _( "Time" ) );
749 m_cursorsGrid->SetColLabelValue( COL_CURSOR_Y, _( "Value" ) );
751
752 for( TUNER_SLIDER* tuner : m_tuners )
753 tuner->ShowChangedLanguage();
754}
755
756
771
772
774{
776
777 settings.view.plot_panel_width = m_splitterLeftRight->GetSashPosition();
778 settings.view.plot_panel_height = m_splitterPlotAndConsole->GetSashPosition();
779 settings.view.signal_panel_height = m_splitterSignals->GetSashPosition();
780 settings.view.cursors_panel_height = m_splitterCursors->GetSashPosition();
781 settings.view.measurements_panel_height = m_splitterMeasurements->GetSashPosition();
782 settings.view.white_background = !m_darkMode;
783}
784
785
787{
788 m_preferences = aPrefs;
789
790 for( std::size_t i = 0; i < m_plotNotebook->GetPageCount(); ++i )
791 {
792 if( SIM_TAB* simTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( i ) ) )
793 simTab->ApplyPreferences( aPrefs );
794 }
795}
796
797
799{
800 if( !simulator()->Settings()->GetWorkbookFilename().IsEmpty() )
801 {
802 wxFileName filename = simulator()->Settings()->GetWorkbookFilename();
803 filename.SetPath( m_schematicFrame->Prj().GetProjectPath() );
804
805 if( !LoadWorkbook( filename.GetFullPath() ) )
807 }
808 else if( m_simulatorFrame->LoadSimulator( wxEmptyString, 0 ) )
809 {
810 wxString schTextSimCommand = circuitModel()->GetSchTextSimCommand();
811
812 if( !schTextSimCommand.IsEmpty() )
813 {
814 SIM_TAB* simTab = NewSimTab( schTextSimCommand );
816 }
817
819 rebuildSignalsGrid( m_filter->GetValue() );
820 }
821}
822
823
841
842
843void sortSignals( std::vector<wxString>& signals )
844{
845 std::sort( signals.begin(), signals.end(),
846 []( const wxString& lhs, const wxString& rhs )
847 {
848 // Sort voltages first
849 if( lhs.Upper().StartsWith( 'V' ) && !rhs.Upper().StartsWith( 'V' ) )
850 return true;
851 else if( !lhs.Upper().StartsWith( 'V' ) && rhs.Upper().StartsWith( 'V' ) )
852 return false;
853
854 return StrNumCmp( lhs, rhs, true /* ignore case */ ) < 0;
855 } );
856}
857
858
860{
861 SUPPRESS_GRID_CELL_EVENTS raii( this );
862
863 m_signalsGrid->ClearRows();
864
865 SIM_PLOT_TAB* plotPanel = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
866
867 if( !plotPanel )
868 return;
869
870 SIM_TYPE simType = plotPanel->GetSimType();
871 std::vector<wxString> signals;
872
873 if( plotPanel->GetSimType() == ST_FFT )
874 {
875 wxStringTokenizer tokenizer( plotPanel->GetSimCommand(), " \t\r\n", wxTOKEN_STRTOK );
876
877 while( tokenizer.HasMoreTokens() && tokenizer.GetNextToken().Lower() != wxT( "fft" ) )
878 {};
879
880 while( tokenizer.HasMoreTokens() )
881 signals.emplace_back( tokenizer.GetNextToken() );
882 }
883 else
884 {
885 // NB: m_signals are already broken out into gain/phase, but m_userDefinedSignals are
886 // as the user typed them
887
888 for( const wxString& signal : m_signals )
889 signals.push_back( signal );
890
891 for( const auto& [ id, signal ] : m_userDefinedSignals )
892 {
893 if( simType == ST_AC )
894 {
895 signals.push_back( signal + _( " (gain)" ) );
896 signals.push_back( signal + _( " (phase)" ) );
897 }
898 else if( simType == ST_SP )
899 {
900 signals.push_back( signal + _( " (amplitude)" ) );
901 signals.push_back( signal + _( " (phase)" ) );
902 }
903 else
904 {
905 signals.push_back( signal );
906 }
907 }
908
909 sortSignals( signals );
910 }
911
912 if( aFilter.IsEmpty() )
913 aFilter = wxS( "*" );
914
915 EDA_COMBINED_MATCHER matcher( aFilter.Upper(), CTX_SIGNAL );
916 int row = 0;
917
918 for( const wxString& signal : signals )
919 {
920 if( matcher.Find( signal.Upper() ) )
921 {
922 int traceType = SPT_UNKNOWN;
923 wxString vectorName = vectorNameFromSignalName( plotPanel, signal, &traceType );
924 TRACE* trace = plotPanel->GetTrace( vectorName, traceType );
925
926 m_signalsGrid->AppendRows( 1 );
927 m_signalsGrid->SetCellValue( row, COL_SIGNAL_NAME, signal );
928
929 wxGridCellAttr* attr = new wxGridCellAttr;
930 attr->SetRenderer( new wxGridCellBoolRenderer() );
931 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
932 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
933 m_signalsGrid->SetAttr( row, COL_SIGNAL_SHOW, attr );
934
935 if( !trace )
936 {
937 attr = new wxGridCellAttr;
938 attr->SetReadOnly();
939 m_signalsGrid->SetAttr( row, COL_SIGNAL_COLOR, attr );
940 m_signalsGrid->SetCellValue( row, COL_SIGNAL_COLOR, wxEmptyString );
941
942 attr = new wxGridCellAttr;
943 attr->SetReadOnly();
944 m_signalsGrid->SetAttr( row, COL_CURSOR_1, attr );
945
946 attr = new wxGridCellAttr;
947 attr->SetReadOnly();
948 m_signalsGrid->SetAttr( row, COL_CURSOR_2, attr );
949
950 if( m_customCursorsCnt > 3 )
951 {
952 for( int i = 1; i <= m_customCursorsCnt - 3; i++ )
953 {
954 attr = new wxGridCellAttr;
955 attr->SetReadOnly();
956 m_signalsGrid->SetAttr( row, COL_CURSOR_2 + i, attr );
957 }
958 }
959 }
960 else
961 {
962 m_signalsGrid->SetCellValue( row, COL_SIGNAL_SHOW, wxS( "1" ) );
963
964 attr = new wxGridCellAttr;
965 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( this ) );
966 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( this, m_signalsGrid ) );
967 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
968 m_signalsGrid->SetAttr( row, COL_SIGNAL_COLOR, attr );
969 KIGFX::COLOR4D color( trace->GetPen().GetColour() );
970 m_signalsGrid->SetCellValue( row, COL_SIGNAL_COLOR, color.ToCSSString() );
971
972 attr = new wxGridCellAttr;
973 attr->SetRenderer( new wxGridCellBoolRenderer() );
974 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
975 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
976 m_signalsGrid->SetAttr( row, COL_CURSOR_1, attr );
977 m_signalsGrid->SetCellValue( row, COL_CURSOR_1, trace->GetCursor( 1 ) ? "1" : "0" );
978
979 attr = new wxGridCellAttr;
980 attr->SetRenderer( new wxGridCellBoolRenderer() );
981 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
982 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
983 m_signalsGrid->SetAttr( row, COL_CURSOR_2, attr );
984 m_signalsGrid->SetCellValue( row, COL_CURSOR_2, trace->GetCursor( 2 ) ? "1" : "0" );
985
986 if( m_customCursorsCnt > 3 )
987 {
988 for( int i = 1; i <= m_customCursorsCnt - 3; i++ )
989 {
990 attr = new wxGridCellAttr;
991 attr->SetRenderer( new wxGridCellBoolRenderer() );
992 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
993 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
994 m_signalsGrid->SetAttr( row, COL_CURSOR_2 + i, attr );
995 m_signalsGrid->SetCellValue( row, COL_CURSOR_2 + i,
996 trace->GetCursor( i ) ? "1" : "0" );
997 }
998 }
999 }
1000 row++;
1001 }
1002 }
1003}
1004
1005
1007{
1008 m_signals.clear();
1009
1010 int options = m_simulatorFrame->GetCurrentOptions();
1011 SIM_TYPE simType = m_simulatorFrame->GetCurrentSimType();
1012 wxString unconnected = wxString( wxS( "unconnected-(" ) );
1013
1014 if( simType == ST_UNKNOWN )
1015 simType = ST_TRAN;
1016
1017 unconnected.Replace( '(', '_' ); // Convert to SPICE markup
1018
1019 auto addSignal =
1020 [&]( const wxString& aSignalName )
1021 {
1022 if( simType == ST_AC )
1023 {
1024 m_signals.push_back( aSignalName + _( " (gain)" ) );
1025 m_signals.push_back( aSignalName + _( " (phase)" ) );
1026 }
1027 else if( simType == ST_SP )
1028 {
1029 m_signals.push_back( aSignalName + _( " (amplitude)" ) );
1030 m_signals.push_back( aSignalName + _( " (phase)" ) );
1031 }
1032 else
1033 {
1034 m_signals.push_back( aSignalName );
1035 }
1036 };
1037
1039 && ( simType == ST_TRAN || simType == ST_DC || simType == ST_AC || simType == ST_FFT) )
1040 {
1041 for( const wxString& net : circuitModel()->GetNets() )
1042 {
1043 // netnames are escaped (can contain "{slash}" for '/') Unscape them:
1044 wxString netname = UnescapeString( net );
1046
1047 if( netname == "GND" || netname == "0" || netname.StartsWith( unconnected ) )
1048 continue;
1049
1050 m_netnames.emplace_back( netname );
1051 addSignal( wxString::Format( wxS( "V(%s)" ), netname ) );
1052 }
1053 }
1054
1056 && ( simType == ST_TRAN || simType == ST_DC || simType == ST_AC ) )
1057 {
1058 for( const SPICE_ITEM& item : circuitModel()->GetItems() )
1059 {
1060 // Add all possible currents for the device.
1061 for( const std::string& name : item.model->SpiceGenerator().CurrentNames( item ) )
1062 addSignal( name );
1063 }
1064 }
1065
1067 && ( simType == ST_TRAN || simType == ST_DC ) )
1068 {
1069 for( const SPICE_ITEM& item : circuitModel()->GetItems() )
1070 {
1071 if( item.model->GetPinCount() >= 2 )
1072 {
1073 wxString name = item.model->SpiceGenerator().ItemName( item );
1074 addSignal( wxString::Format( wxS( "P(%s)" ), name ) );
1075 }
1076 }
1077 }
1078
1079 if( simType == ST_NOISE )
1080 {
1081 addSignal( wxS( "inoise_spectrum" ) );
1082 addSignal( wxS( "onoise_spectrum" ) );
1083 }
1084
1085 if( simType == ST_SP )
1086 {
1087 std::vector<std::string> portnums;
1088
1089 for( const SPICE_ITEM& item : circuitModel()->GetItems() )
1090 {
1091 wxString name = item.model->SpiceGenerator().ItemName( item );
1092
1093 // We are only looking for voltage sources in .SP mode
1094 if( !name.StartsWith( "V" ) )
1095 continue;
1096
1097 std::string portnum = "";
1098
1099 if( const SIM_MODEL::PARAM* portnum_param = item.model->FindParam( "portnum" ) )
1100 portnum = SIM_VALUE::ToSpice( portnum_param->value );
1101
1102 if( portnum != "" )
1103 portnums.push_back( portnum );
1104 }
1105
1106 for( const std::string& portnum1 : portnums )
1107 {
1108 for( const std::string& portnum2 : portnums )
1109 {
1110 addSignal( wxString::Format( wxS( "S_%s_%s" ), portnum1, portnum2 ) );
1111 }
1112 }
1113 }
1114
1115 // Add .SAVE and .PROBE directives
1116 for( const wxString& directive : circuitModel()->GetDirectives() )
1117 {
1118 wxStringTokenizer directivesTokenizer( directive, "\r\n", wxTOKEN_STRTOK );
1119
1120 while( directivesTokenizer.HasMoreTokens() )
1121 {
1122 wxString line = directivesTokenizer.GetNextToken().Upper();
1123 wxString directiveParams;
1124
1125 if( line.StartsWith( wxS( ".SAVE" ), &directiveParams )
1126 || line.StartsWith( wxS( ".PROBE" ), &directiveParams ) )
1127 {
1128 wxStringTokenizer paramsTokenizer( directiveParams, " \t", wxTOKEN_STRTOK );
1129
1130 while( paramsTokenizer.HasMoreTokens() )
1131 addSignal( paramsTokenizer.GetNextToken() );
1132 }
1133 }
1134 }
1135}
1136
1137
1138SIM_TAB* SIMULATOR_FRAME_UI::NewSimTab( const wxString& aSimCommand )
1139{
1140 SIM_TAB* simTab = nullptr;
1141 SIM_TYPE simType = SPICE_CIRCUIT_MODEL::CommandToSimType( aSimCommand );
1142
1143 if( SIM_TAB::IsPlottable( simType ) )
1144 {
1145 SIM_PLOT_TAB* panel = new SIM_PLOT_TAB( aSimCommand, m_plotNotebook );
1146 simTab = panel;
1148 }
1149 else
1150 {
1151 simTab = new SIM_NOPLOT_TAB( aSimCommand, m_plotNotebook );
1152 }
1153
1154 wxString pageTitle( simulator()->TypeToName( simType, true ) );
1155 pageTitle.Prepend( wxString::Format( _( "Analysis %u - " ), static_cast<unsigned int>( ++m_plotNumber ) ) );
1156
1157 m_plotNotebook->AddPage( simTab, pageTitle, true );
1158
1159 return simTab;
1160}
1161
1162
1163void SIMULATOR_FRAME_UI::OnFilterText( wxCommandEvent& aEvent )
1164{
1165 rebuildSignalsGrid( m_filter->GetValue() );
1166}
1167
1168
1169void SIMULATOR_FRAME_UI::OnFilterMouseMoved( wxMouseEvent& aEvent )
1170{
1171#if defined( __WXOSX__ ) || wxCHECK_VERSION( 3, 3, 0 ) // Doesn't work properly on other ports
1172 wxPoint pos = aEvent.GetPosition();
1173 wxRect ctrlRect = m_filter->GetScreenRect();
1174 int buttonWidth = ctrlRect.GetHeight(); // Presume buttons are square
1175
1176 if( m_filter->IsSearchButtonVisible() && pos.x < buttonWidth )
1177 SetCursor( wxCURSOR_ARROW );
1178 else if( m_filter->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
1179 SetCursor( wxCURSOR_ARROW );
1180 else
1181 SetCursor( wxCURSOR_IBEAM );
1182#endif
1183}
1184
1185
1186wxString vectorNameFromSignalId( int aUserDefinedSignalId )
1187{
1188 return wxString::Format( wxS( "user%d" ), aUserDefinedSignalId );
1189}
1190
1191
1197 const wxString& aSignalName,
1198 int* aTraceType )
1199{
1200 auto looksLikePower = []( const wxString& aExpression ) -> bool
1201 {
1202 wxString exprUpper = aExpression.Upper();
1203
1204 if( exprUpper.Contains( wxS( ":POWER" ) ) )
1205 return true;
1206
1207 if( exprUpper.Find( '*' ) == wxNOT_FOUND )
1208 return false;
1209
1210 if( !exprUpper.Contains( wxS( "V(" ) ) )
1211 return false;
1212
1213 if( !exprUpper.Contains( wxS( "I(" ) ) )
1214 return false;
1215
1216 return true;
1217 };
1218
1219 std::map<wxString, int> suffixes;
1220 suffixes[ _( " (amplitude)" ) ] = SPT_SP_AMP;
1221 suffixes[ _( " (gain)" ) ] = SPT_AC_GAIN;
1222 suffixes[ _( " (phase)" ) ] = SPT_AC_PHASE;
1223
1224 if( aTraceType )
1225 {
1226 if( aPlotTab && aPlotTab->GetSimType() == ST_NOISE )
1227 {
1228 if( getNoiseSource().Upper().StartsWith( 'I' ) )
1229 *aTraceType = SPT_CURRENT;
1230 else
1231 *aTraceType = SPT_VOLTAGE;
1232 }
1233 else
1234 {
1235 wxUniChar firstChar = aSignalName.Upper()[0];
1236
1237 if( firstChar == 'V' )
1238 *aTraceType = SPT_VOLTAGE;
1239 else if( firstChar == 'I' )
1240 *aTraceType = SPT_CURRENT;
1241 else if( firstChar == 'P' )
1242 *aTraceType = SPT_POWER;
1243 }
1244 }
1245
1246 wxString name = aSignalName;
1247
1248 for( const auto& [ candidate, type ] : suffixes )
1249 {
1250 if( name.EndsWith( candidate ) )
1251 {
1252 name = name.Left( name.Length() - candidate.Length() );
1253
1254 if( aTraceType )
1255 *aTraceType |= type;
1256
1257 break;
1258 }
1259 }
1260
1261 for( const auto& [ id, signal ] : m_userDefinedSignals )
1262 {
1263 if( name == signal )
1264 {
1265 if( aTraceType && looksLikePower( signal ) )
1266 {
1267 int suffixBits = *aTraceType & ( SPT_AC_GAIN | SPT_AC_PHASE | SPT_SP_AMP );
1268 *aTraceType = suffixBits | SPT_POWER;
1269 }
1270
1271 return vectorNameFromSignalId( id );
1272 }
1273 }
1274
1275 return name;
1276};
1277
1278
1280{
1281 if( m_SuppressGridEvents > 0 )
1282 return;
1283
1284 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
1285
1286 if( !plotTab )
1287 return;
1288
1289 int row = aEvent.GetRow();
1290 int col = aEvent.GetCol();
1291 wxString text = m_signalsGrid->GetCellValue( row, col );
1292 wxString signalName = m_signalsGrid->GetCellValue( row, COL_SIGNAL_NAME );
1293 int traceType = SPT_UNKNOWN;
1294 wxString vectorName = vectorNameFromSignalName( plotTab, signalName, &traceType );
1295
1296 if( col == COL_SIGNAL_SHOW )
1297 {
1298 if( text == wxS( "1" ) )
1299 updateTrace( vectorName, traceType, plotTab );
1300 else
1301 plotTab->DeleteTrace( vectorName, traceType );
1302
1303 plotTab->GetPlotWin()->UpdateAll();
1304
1305 // Update enabled/visible states of other controls
1308 OnModify();
1309 }
1310 else if( col == COL_SIGNAL_COLOR )
1311 {
1312 KIGFX::COLOR4D color( m_signalsGrid->GetCellValue( row, COL_SIGNAL_COLOR ) );
1313 TRACE* trace = plotTab->GetTrace( vectorName, traceType );
1314
1315 if( trace )
1316 {
1317 trace->SetTraceColour( color.ToColour() );
1318 plotTab->UpdateTraceStyle( trace );
1319 plotTab->UpdatePlotColors();
1320 OnModify();
1321 }
1322 }
1323 else if( col == COL_CURSOR_1 || col == COL_CURSOR_2
1324 || ( ( std::size( m_cursorFormatsDyn ) > std::size( m_cursorFormats ) )
1325 && col > COL_CURSOR_2 ) )
1326 {
1327 int id = col == COL_CURSOR_1 ? 1 : 2;
1328
1329 if( col > COL_CURSOR_2 ) // TODO: clean up logic
1330 {
1331 id = col - 2; // enum SIGNALS_GRID_COLUMNS offset for Cursor n
1332 }
1333
1334 TRACE* activeTrace = nullptr;
1335
1336 if( text == wxS( "1" ) )
1337 {
1338 signalName = m_signalsGrid->GetCellValue( row, COL_SIGNAL_NAME );
1339 vectorName = vectorNameFromSignalName( plotTab, signalName, &traceType );
1340 activeTrace = plotTab->GetTrace( vectorName, traceType );
1341
1342 if( activeTrace )
1343 plotTab->EnableCursor( activeTrace, id, signalName );
1344
1345 OnModify();
1346 }
1347
1348 // Turn off cursor on other signals.
1349 for( const auto& [name, trace] : plotTab->GetTraces() )
1350 {
1351 if( trace != activeTrace && trace->HasCursor( id ) )
1352 {
1353 plotTab->DisableCursor( trace, id );
1354 OnModify();
1355 }
1356 }
1357
1358 // Update cursor checkboxes (which are really radio buttons)
1360 }
1361}
1362
1363
1365{
1366 if( m_SuppressGridEvents > 0 )
1367 return;
1368
1369 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
1370
1371 if( !plotTab )
1372 return;
1373
1374 int row = aEvent.GetRow();
1375 int col = aEvent.GetCol();
1376 wxString text = m_cursorsGrid->GetCellValue( row, col );
1377 wxString cursorName = m_cursorsGrid->GetCellValue( row, COL_CURSOR_NAME );
1378
1379 double value = SPICE_VALUE( text ).ToDouble();
1380
1381 if( col == COL_CURSOR_X )
1382 {
1383 CURSOR* cursor1 = nullptr;
1384 CURSOR* cursor2 = nullptr;
1385
1386 std::vector<CURSOR*> cursorsVec;
1387 cursorsVec.clear();
1388
1389 for( const auto& [name, trace] : plotTab->GetTraces() )
1390 {
1391 if( CURSOR* cursor = trace->GetCursor( 1 ) )
1392 cursor1 = cursor;
1393
1394 if( CURSOR* cursor = trace->GetCursor( 2 ) )
1395 cursor2 = cursor;
1396
1397 int tmp = 3;
1398
1399 if( !cursor1 )
1400 tmp--;
1401 if( !cursor2 )
1402 tmp--;
1403
1404 for( int i = tmp; i < m_customCursorsCnt; i++ )
1405 {
1406 if( CURSOR* cursor = trace->GetCursor( i ) )
1407 {
1408 cursorsVec.emplace_back( cursor );
1409
1410 if( cursorName == ( wxString( "" ) << i ) && cursor )
1411 cursor->SetCoordX( value );
1412 }
1413 }
1414 }
1415
1416 //double value = SPICE_VALUE( text ).ToDouble();
1417
1418 if( cursorName == wxS( "1" ) && cursor1 )
1419 cursor1->SetCoordX( value );
1420 else if( cursorName == wxS( "2" ) && cursor2 )
1421 cursor2->SetCoordX( value );
1422 else if( cursorName == _( "Diff" ) && cursor1 && cursor2 )
1423 cursor2->SetCoordX( cursor1->GetCoords().x + value );
1424
1426 OnModify();
1427 }
1428 else
1429 {
1430 wxFAIL_MSG( wxT( "All other columns are supposed to be read-only!" ) );
1431 }
1432}
1433
1434
1436{
1438 result.FromString( m_measurementsGrid->GetCellValue( aRow, COL_MEASUREMENT_FORMAT ) );
1439 return result;
1440}
1441
1442
1444{
1445 m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_FORMAT, aFormat.ToString() );
1446}
1447
1448
1450{
1451 if( aRow < ( m_measurementsGrid->GetNumberRows() - 1 ) )
1452 m_measurementsGrid->DeleteRows( aRow, 1 );
1453}
1454
1455
1457{
1458 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
1459
1460 if( !plotTab )
1461 return;
1462
1463 int row = aEvent.GetRow();
1464 int col = aEvent.GetCol();
1465
1466 if( col == COL_MEASUREMENT )
1467 {
1468 UpdateMeasurement( row );
1470 OnModify();
1471 }
1472 else
1473 {
1474 wxFAIL_MSG( wxT( "All other columns are supposed to be read-only!" ) );
1475 }
1476
1477 // Always leave a single empty row for type-in
1478
1479 int rowCount = static_cast<int>( m_measurementsGrid->GetNumberRows() );
1480 int emptyRows = 0;
1481
1482 for( row = rowCount - 1; row >= 0; row-- )
1483 {
1484 if( m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
1485 emptyRows++;
1486 else
1487 break;
1488 }
1489
1490 if( emptyRows > 1 )
1491 {
1492 int killRows = emptyRows - 1;
1493 m_measurementsGrid->DeleteRows( rowCount - killRows, killRows );
1494 }
1495 else if( emptyRows == 0 )
1496 {
1497 m_measurementsGrid->AppendRows( 1 );
1498 }
1499}
1500
1501
1502void SIMULATOR_FRAME_UI::OnUpdateUI( wxUpdateUIEvent& event )
1503{
1504 if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
1505 {
1506 if( plotTab->GetLegendPosition() != plotTab->m_LastLegendPosition )
1507 {
1508 plotTab->m_LastLegendPosition = plotTab->GetLegendPosition();
1509 OnModify();
1510 }
1511 }
1512}
1513
1514
1530{
1531 static wxRegEx measureParamsRegEx( wxT( "^"
1532 " *"
1533 "([a-zA-Z_]+)"
1534 " +"
1535 "([a-zA-Z]*)\\(([^\\)]+)\\)" ) );
1536
1537 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
1538
1539 if( !plotTab )
1540 return;
1541
1542 wxString text = m_measurementsGrid->GetCellValue( aRow, COL_MEASUREMENT );
1543
1544 if( text.IsEmpty() )
1545 {
1546 m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_VALUE, wxEmptyString );
1547 return;
1548 }
1549
1550 wxString simType = simulator()->TypeToName( plotTab->GetSimType(), true );
1551 wxString resultName = wxString::Format( wxS( "meas_result_%u" ), aRow );
1552 wxString result = wxS( "?" );
1553
1554 if( measureParamsRegEx.Matches( text ) )
1555 {
1556 wxString func = measureParamsRegEx.GetMatch( text, 1 ).Upper();
1557 wxString signalType = measureParamsRegEx.GetMatch( text, 2 ).Upper();
1558 wxString deviceName = measureParamsRegEx.GetMatch( text, 3 );
1559 wxString units;
1561
1562 if( signalType.EndsWith( wxS( "DB" ) ) )
1563 {
1564 units = wxS( "dB" );
1565 }
1566 else if( signalType.StartsWith( 'I' ) )
1567 {
1568 units = wxS( "A" );
1569 }
1570 else if( signalType.StartsWith( 'P' ) )
1571 {
1572 units = wxS( "W" );
1573 // Our syntax is different from ngspice for power signals
1574 text = func + " " + deviceName + ":power";
1575 }
1576 else
1577 {
1578 units = wxS( "V" );
1579 }
1580
1581 if( func.EndsWith( wxS( "_AT" ) ) )
1582 {
1583 if( plotTab->GetSimType() == ST_AC || plotTab->GetSimType() == ST_SP )
1584 units = wxS( "Hz" );
1585 else
1586 units = wxS( "s" );
1587 }
1588 else if( func.StartsWith( wxS( "INTEG" ) ) )
1589 {
1590 switch( plotTab->GetSimType() )
1591 {
1592 case ST_TRAN:
1593 if ( signalType.StartsWith( 'P' ) )
1594 units = wxS( "J" );
1595 else
1596 units += wxS( ".s" );
1597
1598 break;
1599
1600 case ST_AC:
1601 case ST_SP:
1602 case ST_DISTO:
1603 case ST_NOISE:
1604 case ST_FFT:
1605 case ST_SENS: // If there is a vector, it is frequency
1606 units += wxS( "·Hz" );
1607 break;
1608
1609 case ST_DC: // Could be a lot of things : V, A, deg C, ohm, ...
1610 case ST_OP: // There is no vector for integration
1611 case ST_PZ: // There is no vector for integration
1612 case ST_TF: // There is no vector for integration
1613 default:
1614 units += wxS( "·?" );
1615 break;
1616 }
1617 }
1618
1619 fmt.UpdateUnits( units );
1620 SetMeasureFormat( aRow, fmt );
1621
1623 }
1624
1625 if( m_simulatorFrame->SimFinished() )
1626 {
1627 wxString cmd = wxString::Format( wxS( "meas %s %s %s" ), simType, resultName, text );
1628 simulator()->Command( "echo " + cmd.ToStdString() );
1629 simulator()->Command( cmd.ToStdString() );
1630
1631 std::vector<double> resultVec = simulator()->GetGainVector( resultName.ToStdString() );
1632
1633 if( resultVec.size() > 0 )
1634 result = SPICE_VALUE( resultVec[0] ).ToString( GetMeasureFormat( aRow ) );
1635 }
1636
1637 m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_VALUE, result );
1638}
1639
1640
1641void SIMULATOR_FRAME_UI::AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol )
1642{
1643 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
1644
1645 if( !plotTab )
1646 {
1647 DisplayErrorMessage( nullptr, _( "The current analysis must have a plot in order to tune "
1648 "the value of a passive R, L, C model or voltage or "
1649 "current source." ) );
1650 return;
1651 }
1652
1653 wxString ref = aSymbol->GetRef( &aSheetPath );
1654
1655 // Do not add multiple instances for the same component.
1656 for( TUNER_SLIDER* tuner : m_tuners )
1657 {
1658 if( tuner->GetSymbolRef() == ref )
1659 return;
1660 }
1661
1662 if( [[maybe_unused]] const SPICE_ITEM* item = GetExporter()->FindItem( ref ) )
1663 {
1664 try
1665 {
1666 TUNER_SLIDER* tuner = new TUNER_SLIDER( this, m_panelTuners, aSheetPath, aSymbol );
1667 m_sizerTuners->Add( tuner );
1668 m_tuners.push_back( tuner );
1669 m_panelTuners->Layout();
1670 OnModify();
1671 }
1672 catch( const KI_PARAM_ERROR& e )
1673 {
1674 DisplayErrorMessage( nullptr, e.What() );
1675 }
1676 }
1677}
1678
1679
1680void SIMULATOR_FRAME_UI::UpdateTunerValue( const SCH_SHEET_PATH& aSheetPath, const KIID& aSymbol,
1681 const wxString& aRef, const wxString& aValue )
1682{
1683 SCH_ITEM* item = aSheetPath.ResolveItem( aSymbol );
1684 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
1685
1686 if( !symbol )
1687 {
1688 DisplayErrorMessage( this, _( "Could not apply tuned value(s):" ) + wxS( " " )
1689 + wxString::Format( _( "%s not found" ), aRef ) );
1690 return;
1691 }
1692
1693 NULL_REPORTER devnull;
1694 SIM_LIB_MGR mgr( &m_schematicFrame->Prj() );
1695
1696 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
1697 embeddedFilesStack.push_back( m_schematicFrame->Schematic().GetEmbeddedFiles() );
1698
1699 if( EMBEDDED_FILES* symbolEmbeddedFiles = symbol->GetEmbeddedFiles() )
1700 embeddedFilesStack.push_back( symbolEmbeddedFiles );
1701
1702 mgr.SetFilesStack( std::move( embeddedFilesStack ) );
1703
1704 SIM_MODEL& model = mgr.CreateModel( &aSheetPath, *symbol, true, 0, devnull ).model;
1705
1706 const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam();
1707
1708 if( !tunerParam )
1709 {
1710 DisplayErrorMessage( this, _( "Could not apply tuned value(s):" ) + wxS( " " )
1711 + wxString::Format( _( "%s is not tunable" ), aRef ) );
1712 return;
1713 }
1714
1715 model.SetParamValue( tunerParam->info.name, std::string( aValue.ToUTF8() ) );
1716 model.WriteFields( symbol->GetFields() );
1717
1718 m_schematicFrame->UpdateItem( symbol, false, true );
1719 m_schematicFrame->OnModify();
1720}
1721
1722
1724{
1725 m_tuners.remove( aTuner );
1726
1727 if( std::find( m_multiRunState.tuners.begin(), m_multiRunState.tuners.end(), aTuner )
1728 != m_multiRunState.tuners.end() )
1729 clearMultiRunState( true );
1730
1731 m_tunerOverrides.erase( aTuner );
1732
1733 aTuner->Destroy();
1734 m_panelTuners->Layout();
1735 OnModify();
1736}
1737
1738
1739void SIMULATOR_FRAME_UI::AddMeasurement( const wxString& aCmd )
1740{
1741 // -1 because the last one is for user input
1742 for( int i = 0; i < m_measurementsGrid->GetNumberRows(); i++ )
1743 {
1744 if ( m_measurementsGrid->GetCellValue( i, COL_MEASUREMENT ) == aCmd )
1745 return; // Don't create duplicates
1746 }
1747
1748 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
1749
1750 if( !plotTab )
1751 return;
1752
1753 int row;
1754
1755 for( row = 0; row < m_measurementsGrid->GetNumberRows(); ++row )
1756 {
1757 if( m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
1758 break;
1759 }
1760
1761 if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
1762 {
1763 m_measurementsGrid->AppendRows( 1 );
1764 row = m_measurementsGrid->GetNumberRows() - 1;
1765 }
1766
1767 m_measurementsGrid->SetCellValue( row, COL_MEASUREMENT, aCmd );
1768
1769 UpdateMeasurement( row );
1771 OnModify();
1772
1773 // Always leave at least one empty row for type-in:
1774 row = m_measurementsGrid->GetNumberRows() - 1;
1775
1776 if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
1777 m_measurementsGrid->AppendRows( 1 );
1778}
1779
1780
1781void SIMULATOR_FRAME_UI::DoFourier( const wxString& aSignal, const wxString& aFundamental )
1782{
1783 wxString cmd = wxString::Format( wxS( "fourier %s %s" ),
1784 SPICE_VALUE( aFundamental ).ToSpiceString(),
1785 aSignal );
1786
1787 simulator()->Command( cmd.ToStdString() );
1788}
1789
1790
1792{
1793 return circuitModel().get();
1794}
1795
1796
1797void SIMULATOR_FRAME_UI::AddTrace( const wxString& aName, SIM_TRACE_TYPE aType )
1798{
1799 if( !GetCurrentSimTab() )
1800 {
1801 m_simConsole->AppendText( _( "Error: no current simulation.\n" ) );
1802 m_simConsole->SetInsertionPointEnd();
1803 return;
1804 }
1805
1806 SIM_TYPE simType = SPICE_CIRCUIT_MODEL::CommandToSimType( GetCurrentSimTab()->GetSimCommand() );
1807
1808 if( simType == ST_UNKNOWN )
1809 {
1810 m_simConsole->AppendText( _( "Error: simulation type not defined.\n" ) );
1811 m_simConsole->SetInsertionPointEnd();
1812 return;
1813 }
1814 else if( !SIM_TAB::IsPlottable( simType ) )
1815 {
1816 m_simConsole->AppendText( _( "Error: simulation type doesn't support plotting.\n" ) );
1817 m_simConsole->SetInsertionPointEnd();
1818 return;
1819 }
1820
1821 if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
1822 {
1823 if( simType == ST_AC )
1824 {
1825 updateTrace( aName, aType | SPT_AC_GAIN, plotTab );
1826 updateTrace( aName, aType | SPT_AC_PHASE, plotTab );
1827 }
1828 else if( simType == ST_SP )
1829 {
1830 updateTrace( aName, aType | SPT_AC_GAIN, plotTab );
1831 updateTrace( aName, aType | SPT_AC_PHASE, plotTab );
1832 }
1833 else
1834 {
1835 updateTrace( aName, aType, plotTab );
1836 }
1837
1838 plotTab->GetPlotWin()->UpdateAll();
1839 }
1840
1842 OnModify();
1843}
1844
1845
1846void SIMULATOR_FRAME_UI::SetUserDefinedSignals( const std::map<int, wxString>& aNewSignals )
1847{
1848 for( size_t ii = 0; ii < m_plotNotebook->GetPageCount(); ++ii )
1849 {
1850 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( m_plotNotebook->GetPage( ii ) );
1851
1852 if( !plotTab )
1853 continue;
1854
1855 for( const auto& [ id, existingSignal ] : m_userDefinedSignals )
1856 {
1857 int traceType = SPT_UNKNOWN;
1858 wxString vectorName = vectorNameFromSignalName( plotTab, existingSignal, &traceType );
1859
1860 if( aNewSignals.count( id ) == 0 )
1861 {
1862 if( plotTab->GetSimType() == ST_AC )
1863 {
1864 for( int subType : { SPT_AC_GAIN, SPT_AC_PHASE } )
1865 plotTab->DeleteTrace( vectorName, traceType | subType );
1866 }
1867 else if( plotTab->GetSimType() == ST_SP )
1868 {
1869 for( int subType : { SPT_SP_AMP, SPT_AC_PHASE } )
1870 plotTab->DeleteTrace( vectorName, traceType | subType );
1871 }
1872 else
1873 {
1874 plotTab->DeleteTrace( vectorName, traceType );
1875 }
1876 }
1877 else
1878 {
1879 if( plotTab->GetSimType() == ST_AC )
1880 {
1881 for( int subType : { SPT_AC_GAIN, SPT_AC_PHASE } )
1882 {
1883 if( TRACE* trace = plotTab->GetTrace( vectorName, traceType | subType ) )
1884 trace->SetName( aNewSignals.at( id ) );
1885 }
1886 }
1887 else if( plotTab->GetSimType() == ST_SP )
1888 {
1889 for( int subType : { SPT_SP_AMP, SPT_AC_PHASE } )
1890 {
1891 if( TRACE* trace = plotTab->GetTrace( vectorName, traceType | subType ) )
1892 trace->SetName( aNewSignals.at( id ) );
1893 }
1894 }
1895 else
1896 {
1897 if( TRACE* trace = plotTab->GetTrace( vectorName, traceType ) )
1898 trace->SetName( aNewSignals.at( id ) );
1899 }
1900 }
1901 }
1902 }
1903
1904 m_userDefinedSignals = aNewSignals;
1905
1906 if( m_simulatorFrame->SimFinished() )
1908
1910 rebuildSignalsGrid( m_filter->GetValue() );
1913 OnModify();
1914}
1915
1916
1917void SIMULATOR_FRAME_UI::updateTrace( const wxString& aVectorName, int aTraceType,
1918 SIM_PLOT_TAB* aPlotTab, std::vector<double>* aDataX,
1919 bool aClearData )
1920{
1921 if( !m_simulatorFrame->SimFinished() && !simulator()->IsRunning())
1922 {
1923 aPlotTab->GetOrAddTrace( aVectorName, aTraceType );
1924 return;
1925 }
1926
1928
1929 aTraceType &= aTraceType & SPT_Y_AXIS_MASK;
1930 aTraceType |= getXAxisType( simType );
1931
1932 wxString simVectorName = aVectorName;
1933
1934 if( aTraceType & SPT_POWER )
1935 simVectorName = simVectorName.AfterFirst( '(' ).BeforeLast( ')' ) + wxS( ":power" );
1936
1937 if( !SIM_TAB::IsPlottable( simType ) )
1938 {
1939 // There is no plot to be shown
1940 simulator()->Command( wxString::Format( wxT( "print %s" ), aVectorName ).ToStdString() );
1941
1942 return;
1943 }
1944
1945 std::vector<double> data_x;
1946 std::vector<double> data_y;
1947
1948 if( !aDataX || aClearData )
1949 aDataX = &data_x;
1950
1951 // First, handle the x axis
1952 if( aDataX->empty() && !aClearData )
1953 {
1954 wxString xAxisName( simulator()->GetXAxis( simType ) );
1955
1956 if( xAxisName.IsEmpty() )
1957 return;
1958
1959 *aDataX = simulator()->GetGainVector( (const char*) xAxisName.c_str() );
1960 }
1961
1962 unsigned int size = aDataX->size();
1963
1964 switch( simType )
1965 {
1966 case ST_AC:
1967 if( aTraceType & SPT_AC_GAIN )
1968 data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str(), size );
1969 else if( aTraceType & SPT_AC_PHASE )
1970 data_y = simulator()->GetPhaseVector( (const char*) simVectorName.c_str(), size );
1971 else
1972 wxFAIL_MSG( wxT( "Plot type missing AC_PHASE or AC_MAG bit" ) );
1973
1974 break;
1975 case ST_SP:
1976 if( aTraceType & SPT_SP_AMP )
1977 data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str(), size );
1978 else if( aTraceType & SPT_AC_PHASE )
1979 data_y = simulator()->GetPhaseVector( (const char*) simVectorName.c_str(), size );
1980 else
1981 wxFAIL_MSG( wxT( "Plot type missing AC_PHASE or SPT_SP_AMP bit" ) );
1982
1983 break;
1984
1985 case ST_DC:
1986 data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str(), -1 );
1987 break;
1988
1989 case ST_NOISE:
1990 case ST_TRAN:
1991 case ST_FFT:
1992 data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str(), size );
1993 break;
1994
1995 default:
1996 wxFAIL_MSG( wxT( "Unhandled plot type" ) );
1997 }
1998
1999 SPICE_DC_PARAMS source1, source2;
2000 int sweepCount = 1;
2001 size_t sweepSize = std::numeric_limits<size_t>::max();
2002
2003 if( simType == ST_DC
2004 && circuitModel()->ParseDCCommand( aPlotTab->GetSimCommand(), &source1, &source2 )
2005 && !source2.m_source.IsEmpty() )
2006 {
2007 SPICE_VALUE v = ( source2.m_vend - source2.m_vstart ) / source2.m_vincrement;
2008
2009 sweepCount = KiROUND( v.ToDouble() ) + 1;
2010 sweepSize = aDataX->size() / sweepCount;
2011 }
2012
2013 if( m_multiRunState.storePending )
2014 recordMultiRunData( aVectorName, aTraceType, *aDataX, data_y );
2015
2016 if( hasMultiRunTrace( aVectorName, aTraceType ) )
2017 {
2018 const std::string key = multiRunTraceKey( aVectorName, aTraceType );
2019 const auto traceIt = m_multiRunState.traces.find( key );
2020
2021 if( traceIt != m_multiRunState.traces.end() )
2022 {
2023 const MULTI_RUN_TRACE& traceData = traceIt->second;
2024
2025 if( !traceData.xValues.empty() && !traceData.yValues.empty() )
2026 {
2027 size_t sweepSizeMulti = traceData.xValues.size();
2028 size_t runCount = traceData.yValues.size();
2029
2030 if( sweepSizeMulti > 0 && runCount > 0 )
2031 {
2032 std::vector<double> combinedX;
2033 std::vector<double> combinedY;
2034
2035 combinedX.reserve( sweepSizeMulti * runCount );
2036 combinedY.reserve( sweepSizeMulti * runCount );
2037
2038 for( const std::vector<double>& runY : traceData.yValues )
2039 {
2040 if( runY.size() != sweepSizeMulti )
2041 continue;
2042
2043 combinedX.insert( combinedX.end(), traceData.xValues.begin(), traceData.xValues.end() );
2044 combinedY.insert( combinedY.end(), runY.begin(), runY.end() );
2045 }
2046
2047 if( TRACE* trace = aPlotTab->GetOrAddTrace( aVectorName, aTraceType ) )
2048 {
2049 if( combinedY.size() >= combinedX.size() && sweepSizeMulti > 0 )
2050 {
2051 int sweepCountCombined = combinedX.empty() ? 0 : static_cast<int>( combinedY.size() / sweepSizeMulti );
2052
2053 if( sweepCountCombined > 0 )
2054 {
2055 // Generate labels for each run based on tuner values
2056 std::vector<wxString> labels;
2057 labels.reserve( sweepCountCombined );
2058
2059 for( int i = 0; i < sweepCountCombined && i < (int)m_multiRunState.steps.size(); ++i )
2060 {
2061 const MULTI_RUN_STEP& step = m_multiRunState.steps[i];
2062 wxString label;
2063
2064 for( auto it = step.overrides.begin(); it != step.overrides.end(); ++it )
2065 {
2066 if( it != step.overrides.begin() )
2067 label += wxS( ", " );
2068
2069 const TUNER_SLIDER* tuner = it->first;
2070 double value = it->second;
2071
2072 SPICE_VALUE spiceVal( value );
2073 label += tuner->GetSymbolRef() + wxS( "=" ) + spiceVal.ToSpiceString();
2074 }
2075
2076 labels.push_back( label );
2077 }
2078
2079 aPlotTab->SetTraceData( trace, combinedX, combinedY, sweepCountCombined,
2080 sweepSizeMulti, true, labels );
2081 }
2082 }
2083 }
2084
2085 return;
2086 }
2087 }
2088 }
2089 }
2090
2091 if( TRACE* trace = aPlotTab->GetOrAddTrace( aVectorName, aTraceType ) )
2092 {
2093 if( data_y.size() >= size )
2094 aPlotTab->SetTraceData( trace, *aDataX, data_y, sweepCount, sweepSize );
2095 }
2096}
2097
2098
2099// TODO make sure where to instantiate and how to style correct
2100// Better ask someone..
2102 SIGNALS_GRID_COLUMNS, int, int );
2103
2104template <typename T, typename U, typename R>
2105void SIMULATOR_FRAME_UI::signalsGridCursorUpdate( T t, U u, R r ) // t=cursor type/signals' grid col, u=cursor number/cursor "id", r=table's row
2106{
2107 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
2108
2109 wxString signalName = m_signalsGrid->GetCellValue( r, COL_SIGNAL_NAME );
2110 int traceType = SPT_UNKNOWN;
2111 wxString vectorName = vectorNameFromSignalName( plotTab, signalName, &traceType );
2112
2113 wxGridCellAttrPtr attr = m_signalsGrid->GetOrCreateCellAttrPtr( r, static_cast<int>( t ) );
2114
2115 if( TRACE* trace = plotTab ? plotTab->GetTrace( vectorName, traceType ) : nullptr )
2116 {
2117 attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
2118
2120 {
2121 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
2122 }
2123
2124 if constexpr ( std::is_enum<T>::value )
2125 {
2127 {
2128 m_signalsGrid->SetCellValue( r, static_cast<int>( t ), wxS( "1" ) );
2129 }
2131 {
2132 if( !attr->HasRenderer() )
2133 attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( this ) );
2134
2135 if( !attr->HasEditor() )
2136 attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( this, m_signalsGrid ) );
2137
2138 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
2139 attr->SetReadOnly( false );
2140
2141 KIGFX::COLOR4D color( trace->GetPen().GetColour() );
2142 m_signalsGrid->SetCellValue( r, COL_SIGNAL_COLOR, color.ToCSSString() );
2143 }
2147 {
2148 if( !attr->HasRenderer() )
2149 attr->SetRenderer( new wxGridCellBoolRenderer() );
2150
2151 if( u > 0 && trace->HasCursor( u ) )
2152 m_signalsGrid->SetCellValue( r, static_cast<int>( t ), wxS( "1" ) );
2153 else
2154 m_signalsGrid->SetCellValue( r, static_cast<int>( t ), wxEmptyString );
2155 }
2156 }
2157 }
2158 else
2159 {
2160 if constexpr ( std::is_enum<T>::value )
2161 {
2163 {
2164 m_signalsGrid->SetCellValue( r, static_cast<int>( t ), wxEmptyString );
2165 }
2170 {
2171 attr->SetEditor( nullptr );
2172 attr->SetRenderer( nullptr );
2173 attr->SetReadOnly();
2174 m_signalsGrid->SetCellValue( r, static_cast<int>( t ), wxEmptyString );
2175 }
2176 }
2177 }
2178}
2179
2180
2182{
2183 for( int row = 0; row < m_signalsGrid->GetNumberRows(); ++row )
2184 {
2189
2190 if( ( m_signalsGrid->GetNumberCols() - 1 ) > COL_CURSOR_2 )
2191 {
2192 for( int i = 3; i < m_customCursorsCnt; i++ )
2193 {
2194 int tm = i + 2;
2196 static_cast<SIGNALS_GRID_COLUMNS>( tm ),
2197 i,
2198 row );
2199 }
2200 }
2201 }
2202 m_signalsGrid->Refresh();
2203}
2204
2205
2207{
2208 auto quoteNetNames = [&]( wxString aExpression ) -> wxString
2209 {
2210 std::vector<bool> mask( aExpression.length(), false );
2211
2212 auto isNetnameChar = []( wxUniChar aChar ) -> bool
2213 {
2214 wxUint32 value = aChar.GetValue();
2215
2216 if( ( value >= '0' && value <= '9' ) || ( value >= 'A' && value <= 'Z' )
2217 || ( value >= 'a' && value <= 'z' ) )
2218 {
2219 return true;
2220 }
2221
2222 switch( value )
2223 {
2224 case '_':
2225 case '/':
2226 case '+':
2227 case '-':
2228 case '~':
2229 case '.':
2230 return true;
2231 default:
2232 break;
2233 }
2234
2235 return false;
2236 };
2237
2238 for( const auto& netname : m_netnames )
2239 {
2240 size_t pos = aExpression.find( netname );
2241
2242 while( pos != wxString::npos )
2243 {
2244 for( size_t i = 0; i < netname.length(); ++i )
2245 {
2246 mask[pos + i] = true; // Mark the positions of the netname
2247 }
2248 pos = aExpression.find( netname, pos + 1 ); // Find the next occurrence
2249 }
2250 }
2251
2252 for( size_t i = 0; i < aExpression.length(); ++i )
2253 {
2254 if( !mask[i] || ( i > 0 && mask[i - 1] ) )
2255 continue;
2256
2257 size_t j = i + 1;
2258
2259 while( j < aExpression.length() )
2260 {
2261 if( mask[j] )
2262 {
2263 ++j;
2264 continue;
2265 }
2266
2267 if( isNetnameChar( aExpression[j] ) )
2268 {
2269 mask[j] = true;
2270 ++j;
2271 }
2272 else
2273 {
2274 break;
2275 }
2276 }
2277 }
2278
2279 wxString quotedNetnames = "";
2280 bool startQuote = true;
2281
2282 // put quotes around all the positions that were found above
2283 for( size_t i = 0; i < aExpression.length(); i++ )
2284 {
2285 if( mask[i] && startQuote )
2286 {
2287 quotedNetnames = quotedNetnames + "\"";
2288 startQuote = false;
2289 }
2290 else if( !mask[i] && !startQuote )
2291 {
2292 quotedNetnames = quotedNetnames + "\"";
2293 startQuote = true;
2294 }
2295 wxString ch = aExpression[i];
2296 quotedNetnames = quotedNetnames + ch;
2297 }
2298
2299 if( !startQuote )
2300 {
2301 quotedNetnames = quotedNetnames + "\"";
2302 }
2303 return quotedNetnames;
2304 };
2305
2306 for( const auto& [ id, signal ] : m_userDefinedSignals )
2307 {
2308 constexpr const char* cmd = "let user{} = {}";
2309
2310 simulator()->Command( "echo " + fmt::format( cmd, id, signal.ToStdString() ) );
2311 simulator()->Command( fmt::format( cmd, id, quoteNetNames( signal ).ToStdString() ) );
2312 }
2313}
2314
2315
2317{
2318 WX_STRING_REPORTER reporter;
2319
2320 for( const TUNER_SLIDER* tuner : m_tuners )
2321 {
2322 SCH_SHEET_PATH sheetPath;
2323 wxString ref = tuner->GetSymbolRef();
2324 KIID symbolId = tuner->GetSymbol( &sheetPath );
2325 SCH_ITEM* schItem = sheetPath.ResolveItem( symbolId );
2326 SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( schItem );
2327
2328 if( !symbol )
2329 {
2330 reporter.Report( wxString::Format( _( "%s not found" ), ref ) );
2331 continue;
2332 }
2333
2334 const SPICE_ITEM* item = GetExporter()->FindItem( tuner->GetSymbolRef() );
2335
2336 if( !item || !item->model->GetTunerParam() )
2337 {
2338 reporter.Report( wxString::Format( _( "%s is not tunable" ), ref ) );
2339 continue;
2340 }
2341
2342 double floatVal;
2343
2344 auto overrideIt = m_tunerOverrides.find( tuner );
2345
2346 if( overrideIt != m_tunerOverrides.end() )
2347 floatVal = overrideIt->second;
2348 else
2349 floatVal = tuner->GetValue().ToDouble();
2350
2351 simulator()->Command( item->model->SpiceGenerator().TunerCommand( *item, floatVal ) );
2352 }
2353
2354 if( reporter.HasMessage() )
2355 DisplayErrorMessage( this, _( "Could not apply tuned value(s):" ) + wxS( "\n" )
2356 + reporter.GetMessages() );
2357}
2358
2359bool SIMULATOR_FRAME_UI::LoadWorkbook( const wxString& aPath )
2360{
2361 wxTextFile file( aPath );
2362
2363 if( !file.Open() )
2364 return false;
2365
2366 wxString firstLine = file.GetFirstLine();
2367 long dummy;
2368 bool legacy = firstLine.StartsWith( wxT( "version " ) ) || firstLine.ToLong( &dummy );
2369
2370 file.Close();
2371
2372 m_plotNotebook->DeleteAllPages();
2373 m_userDefinedSignals.clear();
2374
2375 if( legacy )
2376 {
2377 if( !loadLegacyWorkbook( aPath ) )
2378 return false;
2379 }
2380 else
2381 {
2382 if( !loadJsonWorkbook( aPath ) )
2383 return false;
2384 }
2385
2387
2388 rebuildSignalsGrid( m_filter->GetValue() );
2392
2393 wxFileName filename( aPath );
2394 filename.MakeRelativeTo( m_schematicFrame->Prj().GetProjectPath() );
2395
2396 // Remember the loaded workbook filename.
2397 simulator()->Settings()->SetWorkbookFilename( filename.GetFullPath() );
2398
2399 return true;
2400}
2401
2402
2403bool SIMULATOR_FRAME_UI::loadJsonWorkbook( const wxString& aPath )
2404{
2405 wxFFileInputStream fp( aPath, wxT( "rt" ) );
2406 wxStdInputStream fstream( fp );
2407
2408 if( !fp.IsOk() )
2409 return false;
2410
2411 try
2412 {
2413 nlohmann::json js = nlohmann::json::parse( fstream, nullptr, true, true );
2414
2415 std::map<SIM_PLOT_TAB*, nlohmann::json> traceInfo;
2416
2417 for( const nlohmann::json& tab_js : js[ "tabs" ] )
2418 {
2419 wxString simCommand;
2422
2423 for( const nlohmann::json& cmd : tab_js[ "commands" ] )
2424 {
2425 if( cmd == ".kicad adjustpaths" )
2427 else if( cmd == ".save all" )
2429 else if( cmd == ".probe alli" )
2431 else if( cmd == ".probe allp" )
2433 else if( cmd == ".kicad esavenone" )
2434 simOptions &= ~NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_EVENTS;
2435 else
2436 simCommand += wxString( cmd.get<wxString>() ).Trim();
2437 }
2438
2439 SIM_TAB* simTab = NewSimTab( simCommand );
2440 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( simTab );
2441
2442 simTab->SetSimOptions( simOptions );
2443
2444 if( plotTab )
2445 {
2446 if( tab_js.contains( "traces" ) )
2447 traceInfo[plotTab] = tab_js[ "traces" ];
2448
2449 if( tab_js.contains( "measurements" ) )
2450 {
2451 for( const nlohmann::json& m_js : tab_js[ "measurements" ] )
2452 plotTab->Measurements().emplace_back( m_js[ "expr" ], m_js[ "format" ] );
2453 }
2454
2455 plotTab->SetDottedSecondary( tab_js[ "dottedSecondary" ] );
2456 plotTab->ShowGrid( tab_js[ "showGrid" ] );
2457
2458 if( tab_js.contains( "fixedY1scale" ) )
2459 {
2460 const nlohmann::json& scale_js = tab_js[ "fixedY1scale" ];
2461 plotTab->SetY1Scale( true, scale_js[ "min" ], scale_js[ "max" ] );
2462 plotTab->GetPlotWin()->LockY( true );
2463 }
2464
2465 if( tab_js.contains( "fixedY2scale" ) )
2466 {
2467 const nlohmann::json& scale_js = tab_js[ "fixedY2scale" ];
2468 plotTab->SetY2Scale( true, scale_js[ "min" ], scale_js[ "max" ] );
2469 plotTab->GetPlotWin()->LockY( true );
2470 }
2471
2472 if( tab_js.contains( "fixedY3scale" ) )
2473 {
2474 plotTab->EnsureThirdYAxisExists();
2475 const nlohmann::json& scale_js = tab_js[ "fixedY3scale" ];
2476 plotTab->SetY3Scale( true, scale_js[ "min" ], scale_js[ "max" ] );
2477 plotTab->GetPlotWin()->LockY( true );
2478 }
2479
2480 if( tab_js.contains( "legend" ) )
2481 {
2482 const nlohmann::json& legend_js = tab_js[ "legend" ];
2483 plotTab->SetLegendPosition( wxPoint( legend_js[ "x" ], legend_js[ "y" ] ) );
2484 plotTab->ShowLegend( true );
2485 }
2486
2487 if( tab_js.contains( "margins" ) )
2488 {
2489 const nlohmann::json& margins_js = tab_js[ "margins" ];
2490 plotTab->GetPlotWin()->SetMargins( margins_js[ "top" ],
2491 margins_js[ "right" ],
2492 margins_js[ "bottom" ],
2493 margins_js[ "left" ] );
2494 }
2495 }
2496 }
2497
2498 int ii = 0;
2499
2500 if( js.contains( "user_defined_signals" ) )
2501 {
2502 for( const nlohmann::json& signal_js : js[ "user_defined_signals" ] )
2503 m_userDefinedSignals[ii++] = wxString( signal_js.get<wxString>() );
2504 }
2505
2506 if( SIM_TAB* simTab = GetCurrentSimTab() )
2507 {
2508 m_simulatorFrame->LoadSimulator( simTab->GetSimCommand(), simTab->GetSimOptions() );
2509
2510 if( SIM_TAB* firstTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( 0 ) ) )
2511 firstTab->SetLastSchTextSimCommand( js["last_sch_text_sim_command"] );
2512 }
2513
2514 int tempCustomCursorsCnt = 0;
2515
2516 if( js.contains( "custom_cursors" ) )
2517 tempCustomCursorsCnt = js["custom_cursors"];
2518 else
2519 tempCustomCursorsCnt = 2; // Kind of virtual, for the initial loading of the new setting
2520
2521 if( ( tempCustomCursorsCnt > m_customCursorsCnt ) && m_customCursorsCnt > 2 )
2522 tempCustomCursorsCnt = 2 * tempCustomCursorsCnt - m_customCursorsCnt;
2523
2524 for( int yy = 0; yy <= ( tempCustomCursorsCnt - m_customCursorsCnt ); yy++ )
2526
2527 auto addCursor =
2528 [=,this]( SIM_PLOT_TAB* aPlotTab, TRACE* aTrace, const wxString& aSignalName,
2529 int aCursorId, const nlohmann::json& aCursor_js )
2530 {
2531 if( aCursorId >= 1 )
2532 {
2533 CURSOR* cursor = new CURSOR( aTrace, aPlotTab );
2534
2535 cursor->SetName( aSignalName );
2536 cursor->SetCoordX( aCursor_js[ "position" ] );
2537
2538 aTrace->SetCursor( aCursorId, cursor );
2539 aPlotTab->GetPlotWin()->AddLayer( cursor );
2540 }
2541
2542 if( aCursorId == -1 )
2543 {
2544 // We are a "cursorD"
2545 m_cursorFormatsDyn[2][0].FromString( aCursor_js["x_format"] );
2546 m_cursorFormatsDyn[2][1].FromString( aCursor_js["y_format"] );
2547 }
2548 else
2549 {
2550 if( aCursorId < 3 )
2551 {
2552 m_cursorFormatsDyn[aCursorId - 1][0].FromString(
2553 aCursor_js["x_format"] );
2554 m_cursorFormatsDyn[aCursorId - 1][1].FromString(
2555 aCursor_js["y_format"] );
2556 }
2557 else
2558 {
2559 m_cursorFormatsDyn[aCursorId][0].FromString( aCursor_js["x_format"] );
2560 m_cursorFormatsDyn[aCursorId][1].FromString( aCursor_js["y_format"] );
2561 }
2562 }
2563 };
2564
2565 for( const auto& [ plotTab, traces_js ] : traceInfo )
2566 {
2567 for( const nlohmann::json& trace_js : traces_js )
2568 {
2569 wxString signalName = trace_js[ "signal" ];
2570 wxString vectorName = vectorNameFromSignalName( plotTab, signalName, nullptr );
2571 TRACE* trace = plotTab->GetOrAddTrace( vectorName, trace_js[ "trace_type" ] );
2572
2573 if( trace )
2574 {
2575 if( trace_js.contains( "cursorD" ) )
2576 addCursor( plotTab, trace, signalName, -1, trace_js[ "cursorD" ] );
2577
2578 std::vector<const char*> aVec;
2579 aVec.clear();
2580
2581 for( int i = 1; i <= tempCustomCursorsCnt; i++ )
2582 {
2583 wxString str = "cursor" + std::to_string( i );
2584 aVec.emplace_back( str.c_str() );
2585
2586 if( trace_js.contains( aVec[i - 1] ) )
2587 addCursor( plotTab, trace, signalName, i, trace_js[aVec[i - 1]] );
2588 }
2589
2590 if( trace_js.contains( "color" ) )
2591 {
2592 wxColour color;
2593 color.Set( wxString( trace_js["color"].get<wxString>() ) );
2594 trace->SetTraceColour( color );
2595 plotTab->UpdateTraceStyle( trace );
2596 }
2597 }
2598 }
2599
2600 plotTab->UpdatePlotColors();
2601 }
2602 }
2603 catch( nlohmann::json::parse_error& error )
2604 {
2605 wxLogTrace( traceSettings, wxT( "Json parse error reading %s: %s" ), aPath, error.what() );
2606
2607 return false;
2608 }
2609 catch( nlohmann::json::type_error& error )
2610 {
2611 wxLogTrace( traceSettings, wxT( "Json type error reading %s: %s" ), aPath, error.what() );
2612
2613 return false;
2614 }
2615 catch( nlohmann::json::invalid_iterator& error )
2616 {
2617 wxLogTrace( traceSettings, wxT( "Json invalid_iterator error reading %s: %s" ), aPath, error.what() );
2618
2619 return false;
2620 }
2621 catch( nlohmann::json::out_of_range& error )
2622 {
2623 wxLogTrace( traceSettings, wxT( "Json out_of_range error reading %s: %s" ), aPath, error.what() );
2624
2625 return false;
2626 }
2627 catch( ... )
2628 {
2629 wxLogTrace( traceSettings, wxT( "Error reading %s" ), aPath );
2630 return false;
2631 }
2632
2633 return true;
2634}
2635
2636void SIMULATOR_FRAME_UI::SaveCursorToWorkbook( nlohmann::json& aTraceJs, TRACE* aTrace, int aCursorId )
2637{
2638 int cursorIdAfterD = aCursorId;
2639
2640 if( aCursorId > 3 )
2641 cursorIdAfterD = cursorIdAfterD - 1;
2642
2643
2644 if( CURSOR* cursor = aTrace->GetCursor( aCursorId ) )
2645 {
2646 aTraceJs["cursor" + wxString( "" ) << aCursorId] =
2647 nlohmann::json( { { "position", cursor->GetCoords().x },
2648 { "x_format", m_cursorFormatsDyn[cursorIdAfterD][0].ToString() },
2649 { "y_format", m_cursorFormatsDyn[cursorIdAfterD][1].ToString() } } );
2650 }
2651
2652 if( cursorIdAfterD < 3 && ( aTrace->GetCursor( 1 ) || aTrace->GetCursor( 2 ) ) )
2653 {
2654 aTraceJs["cursorD"] =
2655 nlohmann::json( { { "x_format", m_cursorFormatsDyn[2][0].ToString() },
2656 { "y_format", m_cursorFormatsDyn[2][1].ToString() } } );
2657 }
2658}
2659
2660
2661bool SIMULATOR_FRAME_UI::SaveWorkbook( const wxString& aPath )
2662{
2664
2665 wxFileName filename = aPath;
2666 filename.SetExt( FILEEXT::WorkbookFileExtension );
2667
2668 wxFile file;
2669
2670 file.Create( filename.GetFullPath(), true /* overwrite */ );
2671
2672 if( !file.IsOpened() )
2673 return false;
2674
2675 nlohmann::json tabs_js = nlohmann::json::array();
2676
2677 for( size_t i = 0; i < m_plotNotebook->GetPageCount(); i++ )
2678 {
2679 SIM_TAB* simTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( i ) );
2680
2681 if( !simTab )
2682 continue;
2683
2684 SIM_TYPE simType = simTab->GetSimType();
2685
2686 nlohmann::json commands_js = nlohmann::json::array();
2687
2688 commands_js.push_back( simTab->GetSimCommand() );
2689
2690 int options = simTab->GetSimOptions();
2691
2693 commands_js.push_back( ".kicad adjustpaths" );
2694
2696 commands_js.push_back( ".save all" );
2697
2699 commands_js.push_back( ".probe alli" );
2700
2702 commands_js.push_back( ".probe allp" );
2703
2705 commands_js.push_back( ".kicad esavenone" );
2706
2707 nlohmann::json tab_js = nlohmann::json(
2708 { { "analysis", SPICE_SIMULATOR::TypeToName( simType, true ) },
2709 { "commands", commands_js } } );
2710
2711 if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( simTab ) )
2712 {
2713 nlohmann::json traces_js = nlohmann::json::array();
2714
2715 auto findSignalName =
2716 [&]( const wxString& aVectorName ) -> wxString
2717 {
2718 wxString vectorName;
2719 wxString suffix;
2720
2721 if( aVectorName.EndsWith( _( " (phase)" ) ) )
2722 suffix = _( " (phase)" );
2723 else if( aVectorName.EndsWith( _( " (gain)" ) ) )
2724 suffix = _( " (gain)" );
2725
2726 vectorName = aVectorName.Left( aVectorName.Length() - suffix.Length() );
2727
2728 for( const auto& [ id, signal ] : m_userDefinedSignals )
2729 {
2730 if( vectorName == vectorNameFromSignalId( id ) )
2731 return signal + suffix;
2732 }
2733
2734 return aVectorName;
2735 };
2736
2737 for( const auto& [name, trace] : plotTab->GetTraces() )
2738 {
2739 nlohmann::json trace_js = nlohmann::json(
2740 { { "trace_type", (int) trace->GetType() },
2741 { "signal", findSignalName( trace->GetDisplayName() ) },
2742 { "color", COLOR4D( trace->GetTraceColour() ).ToCSSString() } } );
2743
2744 for( int ii = 1; ii <= m_customCursorsCnt; ii++ )
2745 SaveCursorToWorkbook( trace_js, trace, ii );
2746
2747 if( trace->GetCursor( 1 ) || trace->GetCursor( 2 ) )
2748 {
2749 trace_js["cursorD"] = nlohmann::json(
2750 { { "x_format", m_cursorFormatsDyn[2][0].ToString() },
2751 { "y_format", m_cursorFormatsDyn[2][1].ToString() } } );
2752 }
2753
2754 traces_js.push_back( trace_js );
2755 }
2756
2757 nlohmann::json measurements_js = nlohmann::json::array();
2758
2759 for( const auto& [ measurement, format ] : plotTab->Measurements() )
2760 {
2761 measurements_js.push_back( nlohmann::json( { { "expr", measurement },
2762 { "format", format } } ) );
2763 }
2764
2765 tab_js[ "traces" ] = traces_js;
2766 tab_js[ "measurements" ] = measurements_js;
2767 tab_js[ "dottedSecondary" ] = plotTab->GetDottedSecondary();
2768 tab_js[ "showGrid" ] = plotTab->IsGridShown();
2769
2770 double min, max;
2771
2772 if( plotTab->GetY1Scale( &min, &max ) )
2773 tab_js[ "fixedY1scale" ] = nlohmann::json( { { "min", min }, { "max", max } } );
2774
2775 if( plotTab->GetY2Scale( &min, &max ) )
2776 tab_js[ "fixedY2scale" ] = nlohmann::json( { { "min", min }, { "max", max } } );
2777
2778 if( plotTab->GetY3Scale( &min, &max ) )
2779 tab_js[ "fixedY3scale" ] = nlohmann::json( { { "min", min }, { "max", max } } );
2780
2781 if( plotTab->IsLegendShown() )
2782 {
2783 tab_js[ "legend" ] = nlohmann::json( { { "x", plotTab->GetLegendPosition().x },
2784 { "y", plotTab->GetLegendPosition().y } } );
2785 }
2786
2787 mpWindow* plotWin = plotTab->GetPlotWin();
2788
2789 tab_js[ "margins" ] = nlohmann::json( { { "left", plotWin->GetMarginLeft() },
2790 { "right", plotWin->GetMarginRight() },
2791 { "top", plotWin->GetMarginTop() },
2792 { "bottom", plotWin->GetMarginBottom() } } );
2793 }
2794
2795 tabs_js.push_back( tab_js );
2796 }
2797
2798 nlohmann::json userDefinedSignals_js = nlohmann::json::array();
2799
2800 for( const auto& [ id, signal ] : m_userDefinedSignals )
2801 userDefinedSignals_js.push_back( signal );
2802
2803 // clang-format off
2804 nlohmann::json js = nlohmann::json( { { "version", 7 },
2805 { "tabs", tabs_js },
2806 { "user_defined_signals", userDefinedSignals_js },
2807 { "custom_cursors", m_customCursorsCnt - 1 } } ); // Since we start +1 on init
2808 // clang-format on
2809
2810 // Store the value of any simulation command found on the schematic sheet in a SCH_TEXT
2811 // object. If this changes we want to warn the user and ask them if they want to update
2812 // the corresponding panel's sim command.
2813 if( m_plotNotebook->GetPageCount() > 0 )
2814 {
2815 SIM_TAB* simTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( 0 ) );
2816 js[ "last_sch_text_sim_command" ] = simTab->GetLastSchTextSimCommand();
2817 }
2818
2819 std::stringstream buffer;
2820 buffer << std::setw( 2 ) << js << std::endl;
2821
2822 bool res = file.Write( buffer.str() );
2823 file.Close();
2824
2825 // Store the filename of the last saved workbook.
2826 if( res )
2827 {
2828 filename.MakeRelativeTo( m_schematicFrame->Prj().GetProjectPath() );
2829 simulator()->Settings()->SetWorkbookFilename( filename.GetFullPath() );
2830 }
2831
2832 return res;
2833}
2834
2835
2837{
2838 switch( aType )
2839 {
2841 case ST_AC: return SPT_LIN_FREQUENCY;
2842 case ST_SP: return SPT_LIN_FREQUENCY;
2843 case ST_FFT: return SPT_LIN_FREQUENCY;
2844 case ST_DC: return SPT_SWEEP;
2845 case ST_TRAN: return SPT_TIME;
2846 case ST_NOISE: return SPT_LIN_FREQUENCY;
2847
2848 default:
2849 wxFAIL_MSG( wxString::Format( wxS( "Unhandled simulation type: %d" ), (int) aType ) );
2850 return SPT_UNKNOWN;
2851 }
2852}
2853
2854
2856{
2857 wxString output;
2858 wxString ref;
2859 wxString source;
2860 wxString scale;
2861 SPICE_VALUE pts;
2862 SPICE_VALUE fStart;
2863 SPICE_VALUE fStop;
2864 bool saveAll;
2865
2866 if( GetCurrentSimTab() )
2867 {
2868 circuitModel()->ParseNoiseCommand( GetCurrentSimTab()->GetSimCommand(), &output, &ref,
2869 &source, &scale, &pts, &fStart, &fStop, &saveAll );
2870 }
2871
2872 return source;
2873}
2874
2875
2876void SIMULATOR_FRAME_UI::TogglePanel( wxPanel* aPanel, wxSplitterWindow* aSplitterWindow,
2877 int& aSashPosition )
2878{
2879 bool isShown = aPanel->IsShown();
2880
2881 if( isShown )
2882 aSashPosition = aSplitterWindow->GetSashPosition();
2883
2884 aPanel->Show( !isShown );
2885
2886 aSplitterWindow->SetSashInvisible( isShown );
2887 aSplitterWindow->SetSashPosition( isShown ? -1 : aSashPosition, true );
2888
2889 aSplitterWindow->UpdateSize();
2890 m_parent->Refresh();
2891 m_parent->Layout();
2892}
2893
2894
2896{
2897 return m_panelConsole->IsShown();
2898}
2899
2900
2905
2906
2908{
2909 return m_sidePanel->IsShown();
2910}
2911
2912
2917
2918
2920{
2922
2923 // Rebuild the color list to plot traces
2925
2926 // Now send changes to all SIM_PLOT_TAB
2927 for( size_t page = 0; page < m_plotNotebook->GetPageCount(); page++ )
2928 {
2929 wxWindow* curPage = m_plotNotebook->GetPage( page );
2930
2931 // ensure it is truly a plot plotTab and not the (zero plots) placeholder
2932 // which is only SIM_TAB
2933 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( curPage );
2934
2935 if( plotTab )
2936 plotTab->UpdatePlotColors();
2937 }
2938}
2939
2940
2941void SIMULATOR_FRAME_UI::onPlotClose( wxAuiNotebookEvent& event )
2942{
2943 OnModify();
2944}
2945
2946
2947void SIMULATOR_FRAME_UI::onPlotClosed( wxAuiNotebookEvent& event )
2948{
2949 CallAfter( [this]()
2950 {
2952 rebuildSignalsGrid( m_filter->GetValue() );
2954
2955 SIM_TAB* panel = GetCurrentSimTab();
2956
2957 if( !panel || panel->GetSimType() != ST_OP )
2958 {
2959 SCHEMATIC& schematic = m_schematicFrame->Schematic();
2960 schematic.ClearOperatingPoints();
2961 m_schematicFrame->RefreshOperatingPointDisplay();
2962 m_schematicFrame->GetCanvas()->Refresh();
2963 }
2964 } );
2965}
2966
2967
2969{
2970 if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
2971 {
2972 std::vector<std::pair<wxString, wxString>>& measurements = plotTab->Measurements();
2973
2974 measurements.clear();
2975
2976 for( int row = 0; row < m_measurementsGrid->GetNumberRows(); ++row )
2977 {
2978 if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
2979 {
2980 measurements.emplace_back( m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ),
2981 m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT_FORMAT ) );
2982 }
2983 }
2984 }
2985}
2986
2987
2988void SIMULATOR_FRAME_UI::onPlotChanging( wxAuiNotebookEvent& event )
2989{
2990 m_measurementsGrid->ClearRows();
2991
2992 event.Skip();
2993}
2994
2995
2997{
2999 rebuildSignalsGrid( m_filter->GetValue() );
3001
3003
3004 for( int row = 0; row < m_measurementsGrid->GetNumberRows(); ++row )
3005 UpdateMeasurement( row );
3006}
3007
3008
3009void SIMULATOR_FRAME_UI::onPlotChanged( wxAuiNotebookEvent& event )
3010{
3011 if( SIM_TAB* simTab = GetCurrentSimTab() )
3012 simulator()->Command( "setplot " + simTab->GetSpicePlotName().ToStdString() );
3013
3015
3016 event.Skip();
3017}
3018
3019
3021{
3022 m_measurementsGrid->ClearRows();
3023
3024 if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
3025 {
3026 for( const auto& [ measurement, format ] : plotTab->Measurements() )
3027 {
3028 int row = m_measurementsGrid->GetNumberRows();
3029 m_measurementsGrid->AppendRows();
3030 m_measurementsGrid->SetCellValue( row, COL_MEASUREMENT, measurement );
3031 m_measurementsGrid->SetCellValue( row, COL_MEASUREMENT_FORMAT, format );
3032 }
3033
3034 if( plotTab->GetSimType() == ST_TRAN || plotTab->GetSimType() == ST_AC
3035 || plotTab->GetSimType() == ST_DC || plotTab->GetSimType() == ST_SP )
3036 {
3037 m_measurementsGrid->AppendRows(); // Empty row at end
3038 }
3039 }
3040}
3041
3042
3043void SIMULATOR_FRAME_UI::onPlotDragged( wxAuiNotebookEvent& event )
3044{
3045}
3046
3047
3048std::shared_ptr<SPICE_SIMULATOR> SIMULATOR_FRAME_UI::simulator() const
3049{
3050 return m_simulatorFrame->GetSimulator();
3051}
3052
3053
3054std::shared_ptr<SPICE_CIRCUIT_MODEL> SIMULATOR_FRAME_UI::circuitModel() const
3055{
3056 return m_simulatorFrame->GetCircuitModel();
3057}
3058
3059
3061{
3062 SUPPRESS_GRID_CELL_EVENTS raii( this );
3063
3064 m_cursorsGrid->ClearRows();
3065
3066 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
3067
3068 if( !plotTab )
3069 return;
3070
3071 // Update cursor values
3072 CURSOR* cursor1 = nullptr;
3073 wxString cursor1Name;
3074 wxString cursor1Units;
3075 CURSOR* cursor2 = nullptr;
3076 wxString cursor2Name;
3077 wxString cursor2Units;
3078
3079 auto getUnitsY =
3080 [&]( TRACE* aTrace ) -> wxString
3081 {
3082 if( plotTab->GetSimType() == ST_AC )
3083 {
3084 if( aTrace->GetType() & SPT_AC_PHASE )
3085 return plotTab->GetUnitsY2();
3086 else
3087 return plotTab->GetUnitsY1();
3088 }
3089 else
3090 {
3091 if( aTrace->GetType() & SPT_POWER )
3092 return plotTab->GetUnitsY3();
3093 else if( aTrace->GetType() & SPT_CURRENT )
3094 return plotTab->GetUnitsY2();
3095 else
3096 return plotTab->GetUnitsY1();
3097 }
3098 };
3099
3100 auto getNameY =
3101 [&]( TRACE* aTrace ) -> wxString
3102 {
3103 if( plotTab->GetSimType() == ST_AC )
3104 {
3105 if( aTrace->GetType() & SPT_AC_PHASE )
3106 return plotTab->GetLabelY2();
3107 else
3108 return plotTab->GetLabelY1();
3109 }
3110 else
3111 {
3112 if( aTrace->GetType() & SPT_POWER )
3113 return plotTab->GetLabelY3();
3114 else if( aTrace->GetType() & SPT_CURRENT )
3115 return plotTab->GetLabelY2();
3116 else
3117 return plotTab->GetLabelY1();
3118 }
3119 };
3120
3121 auto formatValue =
3122 [this]( double aValue, int aCursorId, int aCol ) -> wxString
3123 {
3124 if( ( !m_simulatorFrame->SimFinished() && aCol == 1 ) || std::isnan( aValue ) )
3125 return wxS( "--" );
3126 else
3127 return SPICE_VALUE( aValue ).ToString( m_cursorFormatsDyn[ aCursorId ][ aCol ] );
3128 };
3129
3130 for( const auto& [name, trace] : plotTab->GetTraces() )
3131 {
3132 if( CURSOR* cursor = trace->GetCursor( 1 ) )
3133 {
3134 cursor1 = cursor;
3135 cursor1Name = getNameY( trace );
3136 cursor1Units = getUnitsY( trace );
3137
3138 wxRealPoint coords = cursor->GetCoords();
3139 int row = m_cursorsGrid->GetNumberRows();
3140
3141 m_cursorFormatsDyn[0][0].UpdateUnits( plotTab->GetUnitsX() );
3142 m_cursorFormatsDyn[0][1].UpdateUnits( cursor1Units );
3143
3144 m_cursorsGrid->AppendRows( 1 );
3145 m_cursorsGrid->SetCellValue( row, COL_CURSOR_NAME, wxS( "1" ) );
3146 m_cursorsGrid->SetCellValue( row, COL_CURSOR_SIGNAL, cursor->GetName() );
3147 m_cursorsGrid->SetCellValue( row, COL_CURSOR_X, formatValue( coords.x, 0, 0 ) );
3148 m_cursorsGrid->SetCellValue( row, COL_CURSOR_Y, formatValue( coords.y, 0, 1 ) );
3149 break;
3150 }
3151 }
3152
3153 for( const auto& [name, trace] : plotTab->GetTraces() )
3154 {
3155 if( CURSOR* cursor = trace->GetCursor( 2 ) )
3156 {
3157 cursor2 = cursor;
3158 cursor2Name = getNameY( trace );
3159 cursor2Units = getUnitsY( trace );
3160
3161 wxRealPoint coords = cursor->GetCoords();
3162 int row = m_cursorsGrid->GetNumberRows();
3163
3164 m_cursorFormatsDyn[1][0].UpdateUnits( plotTab->GetUnitsX() );
3165 m_cursorFormatsDyn[1][1].UpdateUnits( cursor2Units );
3166
3167 m_cursorsGrid->AppendRows( 1 );
3168 m_cursorsGrid->SetCellValue( row, COL_CURSOR_NAME, wxS( "2" ) );
3169 m_cursorsGrid->SetCellValue( row, COL_CURSOR_SIGNAL, cursor->GetName() );
3170 m_cursorsGrid->SetCellValue( row, COL_CURSOR_X, formatValue( coords.x, 1, 0 ) );
3171 m_cursorsGrid->SetCellValue( row, COL_CURSOR_Y, formatValue( coords.y, 1, 1 ) );
3172 break;
3173 }
3174 }
3175
3176 if( cursor1 && cursor2 && cursor1Units == cursor2Units )
3177 {
3178 wxRealPoint coords = cursor2->GetCoords() - cursor1->GetCoords();
3179 wxString signal;
3180
3181 m_cursorFormatsDyn[2][0].UpdateUnits( plotTab->GetUnitsX() );
3182 m_cursorFormatsDyn[2][1].UpdateUnits( cursor1Units );
3183
3184 if( cursor1->GetName() == cursor2->GetName() )
3185 signal = wxString::Format( wxS( "%s[2 - 1]" ), cursor2->GetName() );
3186 else
3187 signal = wxString::Format( wxS( "%s - %s" ), cursor2->GetName(), cursor1->GetName() );
3188
3189 m_cursorsGrid->AppendRows( 1 );
3190 m_cursorsGrid->SetCellValue( 2, COL_CURSOR_NAME, _( "Diff" ) );
3191 m_cursorsGrid->SetCellValue( 2, COL_CURSOR_SIGNAL, signal );
3192 m_cursorsGrid->SetCellValue( 2, COL_CURSOR_X, formatValue( coords.x, 2, 0 ) );
3193 m_cursorsGrid->SetCellValue( 2, COL_CURSOR_Y, formatValue( coords.y, 2, 1 ) );
3194 }
3195 // Set up the labels
3196 m_cursorsGrid->SetColLabelValue( COL_CURSOR_X, plotTab->GetLabelX() );
3197
3198 wxString valColName = _( "Value" );
3199
3200 if( !cursor1Name.IsEmpty() )
3201 {
3202 if( cursor2Name.IsEmpty() || cursor1Name == cursor2Name )
3203 valColName = cursor1Name;
3204 }
3205 else if( !cursor2Name.IsEmpty() )
3206 {
3207 valColName = cursor2Name;
3208 }
3209
3210 m_cursorsGrid->SetColLabelValue( COL_CURSOR_Y, valColName );
3211
3212 if( m_customCursorsCnt > 3 ) // 2 for the default hardocded cursors plus the initial + 1
3213 {
3214 for( int i = 3; i < m_customCursorsCnt; i++ )
3215 {
3216 for( const auto& [name, trace] : plotTab->GetTraces() )
3217 {
3218 if( CURSOR* cursor = trace->GetCursor( i ) )
3219 {
3220 CURSOR* curs = cursor;
3221 wxString cursName = getNameY( trace );
3222 wxString cursUnits = getUnitsY( trace );
3223
3224 wxRealPoint coords = cursor->GetCoords();
3225 int row = m_cursorsGrid->GetNumberRows();
3226
3227 m_cursorFormatsDyn[i][0].UpdateUnits( plotTab->GetUnitsX() );
3228 m_cursorFormatsDyn[i][1].UpdateUnits( cursUnits );
3229
3230 m_cursorsGrid->AppendRows( 1 );
3231 m_cursorsGrid->SetCellValue( row, COL_CURSOR_NAME, wxS( "" ) + wxString( "" ) << i );
3232 m_cursorsGrid->SetCellValue( row, COL_CURSOR_SIGNAL, curs->GetName() );
3233 m_cursorsGrid->SetCellValue( row, COL_CURSOR_X, formatValue( coords.x, i, 0 ) );
3234 m_cursorsGrid->SetCellValue( row, COL_CURSOR_Y, formatValue( coords.y, i, 1 ) );
3235
3236 // Set up the labels
3237 m_cursorsGrid->SetColLabelValue( COL_CURSOR_X, plotTab->GetLabelX() );
3238
3239 valColName = _( "Value" );
3240
3241 if( !cursName.IsEmpty()
3242 && ( m_cursorsGrid->GetColLabelValue( COL_CURSOR_Y ) == cursName ) )
3243 {
3244 valColName = cursName;
3245 }
3246 m_cursorsGrid->SetColLabelValue( COL_CURSOR_Y, valColName );
3247 break;
3248 }
3249 }
3250 }
3251 }
3252}
3253
3254
3255void SIMULATOR_FRAME_UI::onPlotCursorUpdate( wxCommandEvent& aEvent )
3256{
3258 OnModify();
3259}
3260
3261
3263{
3264 if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
3265 plotTab->ResetScales( true );
3266
3267 m_simConsole->Clear();
3268
3270
3271 // Do not export netlist, it is already stored in the simulator
3272 applyTuners();
3273
3274 m_refreshTimer.Start( REFRESH_INTERVAL, wxTIMER_ONE_SHOT );
3275}
3276
3277
3278void SIMULATOR_FRAME_UI::OnSimReport( const wxString& aMsg )
3279{
3280 m_simConsole->AppendText( aMsg + "\n" );
3281 m_simConsole->SetInsertionPointEnd();
3282}
3283
3284
3285std::vector<wxString> SIMULATOR_FRAME_UI::SimPlotVectors() const
3286{
3287 std::vector<wxString> signals;
3288
3289 for( const std::string& vec : simulator()->AllVectors() )
3290 signals.emplace_back( vec );
3291
3292 return signals;
3293}
3294
3295
3296std::vector<wxString> SIMULATOR_FRAME_UI::Signals() const
3297{
3298 std::vector<wxString> signals;
3299
3300 for( const wxString& signal : m_signals )
3301 signals.emplace_back( signal );
3302
3303 for( const auto& [ id, signal ] : m_userDefinedSignals )
3304 signals.emplace_back( signal );
3305
3306 sortSignals( signals );
3307
3308 return signals;
3309}
3310
3311
3313{
3314 if( aFinal )
3315 m_refreshTimer.Stop();
3316
3317 SIM_TAB* simTab = GetCurrentSimTab();
3318
3319 if( !simTab )
3320 return;
3321
3322 bool storeMultiRun = false;
3323
3324 if( aFinal && m_multiRunState.active )
3325 {
3326 if( m_multiRunState.currentStep < m_multiRunState.steps.size() )
3327 {
3328 storeMultiRun = true;
3329 m_multiRunState.storePending = true;
3330 }
3331 }
3332 else
3333 {
3334 m_multiRunState.storePending = false;
3335 }
3336
3337 SIM_TYPE simType = simTab->GetSimType();
3338 wxString msg;
3339
3340 if( aFinal )
3341 {
3344 }
3345
3346 // If there are any signals plotted, update them
3347 if( SIM_TAB::IsPlottable( simType ) )
3348 {
3349 simTab->SetSpicePlotName( simulator()->CurrentPlotName() );
3350
3351 if( simType == ST_NOISE && aFinal )
3352 {
3353 m_simConsole->AppendText( _( "\n\nSimulation results:\n\n" ) );
3354 m_simConsole->SetInsertionPointEnd();
3355
3356 // The simulator will create noise1 & noise2 on the first run, noise3 and noise4
3357 // on the second, etc. The first plot for each run contains the spectral density
3358 // noise vectors and second contains the integrated noise.
3359 long number;
3360 simulator()->CurrentPlotName().Mid( 5 ).ToLong( &number );
3361
3362 for( const std::string& vec : simulator()->AllVectors() )
3363 {
3364 std::vector<double> val_list = simulator()->GetRealVector( vec, 1 );
3365 wxString value = SPICE_VALUE( val_list[ 0 ] ).ToSpiceString();
3366
3367 msg.Printf( wxS( "%s: %sV\n" ), vec, value );
3368
3369 m_simConsole->AppendText( msg );
3370 m_simConsole->SetInsertionPointEnd();
3371 }
3372
3373 simulator()->Command( fmt::format( "setplot noise{}", number - 1 ) );
3374 simTab->SetSpicePlotName( simulator()->CurrentPlotName() );
3375 }
3376
3377 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( simTab );
3378 wxCHECK_RET( plotTab, wxString::Format( wxT( "No SIM_PLOT_TAB for: %s" ),
3379 magic_enum::enum_name( simType ) ) );
3380
3381 struct TRACE_INFO
3382 {
3383 wxString Vector;
3384 int TraceType;
3385 bool ClearData;
3386 };
3387
3388 std::map<TRACE*, TRACE_INFO> traceMap;
3389
3390 for( const auto& [ name, trace ] : plotTab->GetTraces() )
3391 traceMap[ trace ] = { wxEmptyString, SPT_UNKNOWN, false };
3392
3393 // NB: m_signals are already broken out into gain/phase, but m_userDefinedSignals are
3394 // as the user typed them
3395
3396 for( const wxString& signal : m_signals )
3397 {
3398 int traceType = SPT_UNKNOWN;
3399 wxString vectorName = vectorNameFromSignalName( plotTab, signal, &traceType );
3400
3401 if( TRACE* trace = plotTab->GetTrace( vectorName, traceType ) )
3402 traceMap[ trace ] = { vectorName, traceType, false };
3403 }
3404
3405 for( const auto& [ id, signal ] : m_userDefinedSignals )
3406 {
3407 int traceType = SPT_UNKNOWN;
3408 wxString vectorName = vectorNameFromSignalName( plotTab, signal, &traceType );
3409
3410 if( simType == ST_AC )
3411 {
3412 int baseType = traceType &= ~( SPT_AC_GAIN | SPT_AC_PHASE );
3413
3414 for( int subType : { baseType | SPT_AC_GAIN, baseType | SPT_AC_PHASE } )
3415 {
3416 if( TRACE* trace = plotTab->GetTrace( vectorName, subType ) )
3417 traceMap[ trace ] = { vectorName, subType, !aFinal };
3418 }
3419 }
3420 else if( simType == ST_SP )
3421 {
3422 int baseType = traceType &= ~( SPT_SP_AMP | SPT_AC_PHASE );
3423
3424 for( int subType : { baseType | SPT_SP_AMP, baseType | SPT_AC_PHASE } )
3425 {
3426 if( TRACE* trace = plotTab->GetTrace( vectorName, subType ) )
3427 traceMap[trace] = { vectorName, subType, !aFinal };
3428 }
3429 }
3430 else
3431 {
3432 if( TRACE* trace = plotTab->GetTrace( vectorName, traceType ) )
3433 traceMap[ trace ] = { vectorName, traceType, !aFinal };
3434 }
3435 }
3436
3437 // Two passes so that DC-sweep sub-traces get deleted and re-created:
3438
3439 for( const auto& [ trace, traceInfo ] : traceMap )
3440 {
3441 if( traceInfo.Vector.IsEmpty() )
3442 plotTab->DeleteTrace( trace );
3443 }
3444
3445 for( const auto& [ trace, info ] : traceMap )
3446 {
3447 std::vector<double> data_x;
3448
3449 if( !info.Vector.IsEmpty() )
3450 updateTrace( info.Vector, info.TraceType, plotTab, &data_x, info.ClearData );
3451 }
3452
3453 plotTab->GetPlotWin()->UpdateAll();
3454
3455 if( aFinal )
3456 {
3457 for( int row = 0; row < m_measurementsGrid->GetNumberRows(); ++row )
3458 UpdateMeasurement( row );
3459
3460 plotTab->ResetScales( true );
3461 }
3462
3463 plotTab->GetPlotWin()->Fit();
3464
3466 }
3467 else if( simType == ST_OP && aFinal )
3468 {
3469 m_simConsole->AppendText( _( "\n\nSimulation results:\n\n" ) );
3470 m_simConsole->SetInsertionPointEnd();
3471
3472 for( const std::string& vec : simulator()->AllVectors() )
3473 {
3474 std::vector<double> val_list = simulator()->GetRealVector( vec, 1 );
3475
3476 if( val_list.empty() )
3477 continue;
3478
3479 wxString value = SPICE_VALUE( val_list[ 0 ] ).ToSpiceString();
3480 wxString signal;
3481 SIM_TRACE_TYPE type = circuitModel()->VectorToSignal( vec, signal );
3482
3483 const size_t tab = 25; //characters
3484 size_t padding = ( signal.length() < tab ) ? ( tab - signal.length() ) : 1;
3485
3486 switch( type )
3487 {
3488 case SPT_VOLTAGE: value.Append( wxS( "V" ) ); break;
3489 case SPT_CURRENT: value.Append( wxS( "A" ) ); break;
3490 case SPT_POWER: value.Append( wxS( "W" ) ); break;
3491 default: value.Append( wxS( "?" ) ); break;
3492 }
3493
3494 msg.Printf( wxT( "%s%s\n" ),
3495 ( signal + wxT( ":" ) ).Pad( padding, wxUniChar( ' ' ) ),
3496 value );
3497
3498 m_simConsole->AppendText( msg );
3499 m_simConsole->SetInsertionPointEnd();
3500
3501 if( type == SPT_VOLTAGE || type == SPT_CURRENT || type == SPT_POWER )
3502 signal = signal.SubString( 2, signal.Length() - 2 );
3503
3504 if( type == SPT_POWER )
3505 signal += wxS( ":power" );
3506
3507 m_schematicFrame->Schematic().SetOperatingPoint( signal, val_list.at( 0 ) );
3508 }
3509 }
3510 else if( simType == ST_PZ && aFinal )
3511 {
3512 m_simConsole->AppendText( _( "\n\nSimulation results:\n\n" ) );
3513 m_simConsole->SetInsertionPointEnd();
3514 simulator()->Command( "print all" );
3515 }
3516
3517 if( storeMultiRun )
3518 {
3519 m_multiRunState.storePending = false;
3520 m_multiRunState.storedSteps = m_multiRunState.currentStep + 1;
3521 }
3522
3523 if( aFinal && m_multiRunState.active )
3524 {
3525 if( m_multiRunState.currentStep + 1 < m_multiRunState.steps.size() )
3526 {
3527 m_multiRunState.currentStep++;
3528
3529 wxQueueEvent( m_simulatorFrame, new wxCommandEvent( EVT_SIM_UPDATE ) );
3530 }
3531 else
3532 {
3533 m_multiRunState.active = false;
3534 m_multiRunState.steps.clear();
3535 m_multiRunState.currentStep = 0;
3536 m_multiRunState.storePending = false;
3537 m_tunerOverrides.clear();
3538
3539 if( !m_multiRunState.traces.empty() )
3540 {
3541 auto iter = m_multiRunState.traces.begin();
3542
3543 if( iter != m_multiRunState.traces.end() )
3544 m_multiRunState.storedSteps = iter->second.yValues.size();
3545 }
3546 }
3547 }
3548}
3549
3550
3552{
3553 m_multiRunState.active = false;
3554 m_multiRunState.tuners.clear();
3555 m_multiRunState.steps.clear();
3556 m_multiRunState.currentStep = 0;
3557 m_multiRunState.storePending = false;
3558
3559 if( aClearTraces )
3560 {
3561 m_multiRunState.traces.clear();
3562 m_multiRunState.storedSteps = 0;
3563 }
3564
3565 m_tunerOverrides.clear();
3566}
3567
3568
3570{
3571 m_tunerOverrides.clear();
3572
3573 std::vector<TUNER_SLIDER*> multiTuners;
3574
3575 for( TUNER_SLIDER* tuner : m_tuners )
3576 {
3577 if( tuner->GetRunMode() == TUNER_SLIDER::RUN_MODE::MULTI )
3578 multiTuners.push_back( tuner );
3579 }
3580
3581 if( multiTuners.empty() )
3582 {
3583 clearMultiRunState( true );
3584 return;
3585 }
3586
3587 bool tunersChanged = multiTuners != m_multiRunState.tuners;
3588
3589 if( m_multiRunState.active && tunersChanged )
3590 clearMultiRunState( true );
3591
3592 if( !m_multiRunState.active )
3593 {
3594 if( tunersChanged || m_multiRunState.storedSteps > 0 || !m_multiRunState.traces.empty() )
3595 {
3596 clearMultiRunState( true );
3597 }
3598
3599 m_multiRunState.tuners = multiTuners;
3600 m_multiRunState.steps = calculateMultiRunSteps( multiTuners );
3601 m_multiRunState.currentStep = 0;
3602 m_multiRunState.storePending = false;
3603
3604 if( m_multiRunState.steps.size() >= 2 )
3605 {
3606 m_multiRunState.active = true;
3607 m_multiRunState.storedSteps = 0;
3608 }
3609 else
3610 {
3611 m_multiRunState.steps.clear();
3612 return;
3613 }
3614 }
3615 else if( tunersChanged )
3616 {
3617 m_multiRunState.tuners = multiTuners;
3618 }
3619
3620 if( m_multiRunState.active && m_multiRunState.currentStep < m_multiRunState.steps.size() )
3621 {
3622 const MULTI_RUN_STEP& step = m_multiRunState.steps[m_multiRunState.currentStep];
3623
3624 for( const auto& entry : step.overrides )
3625 m_tunerOverrides[entry.first] = entry.second;
3626 }
3627}
3628
3629
3630std::vector<SIMULATOR_FRAME_UI::MULTI_RUN_STEP> SIMULATOR_FRAME_UI::calculateMultiRunSteps(
3631 const std::vector<TUNER_SLIDER*>& aTuners ) const
3632{
3633 std::vector<MULTI_RUN_STEP> steps;
3634
3635 if( aTuners.empty() )
3636 return steps;
3637
3638 std::vector<std::vector<double>> tunerValues;
3639 tunerValues.reserve( aTuners.size() );
3640
3641 for( TUNER_SLIDER* tuner : aTuners )
3642 {
3643 if( !tuner )
3644 return steps;
3645
3646 double startValue = tuner->GetMin().ToDouble();
3647 double endValue = tuner->GetMax().ToDouble();
3648 int stepCount = std::max( 2, tuner->GetStepCount() );
3649
3650 if( stepCount < 2 )
3651 stepCount = 2;
3652
3653 double increment = ( endValue - startValue ) / static_cast<double>( stepCount - 1 );
3654
3655 std::vector<double> values;
3656 values.reserve( stepCount );
3657
3658 for( int ii = 0; ii < stepCount; ++ii )
3659 values.push_back( startValue + increment * ii );
3660
3661 tunerValues.push_back( std::move( values ) );
3662 }
3663
3665
3666 if( limit < 1 )
3667 limit = 1;
3668
3669 std::vector<double> currentValues( aTuners.size(), 0.0 );
3670
3671 auto generate = [&]( auto&& self, size_t depth ) -> void
3672 {
3673 if( steps.size() >= static_cast<size_t>( limit ) )
3674 return;
3675
3676 if( depth == aTuners.size() )
3677 {
3678 MULTI_RUN_STEP step;
3679
3680 for( size_t ii = 0; ii < aTuners.size(); ++ii )
3681 step.overrides.emplace( aTuners[ii], currentValues[ii] );
3682
3683 steps.push_back( std::move( step ) );
3684 return;
3685 }
3686
3687 for( double value : tunerValues[depth] )
3688 {
3689 currentValues[depth] = value;
3690 self( self, depth + 1 );
3691
3692 if( steps.size() >= static_cast<size_t>( limit ) )
3693 return;
3694 }
3695 };
3696
3697 generate( generate, 0 );
3698
3699 return steps;
3700}
3701
3702
3703std::string SIMULATOR_FRAME_UI::multiRunTraceKey( const wxString& aVectorName, int aTraceType ) const
3704{
3705 return fmt::format( "{}|{}", aVectorName.ToStdString(), aTraceType );
3706}
3707
3708
3709void SIMULATOR_FRAME_UI::recordMultiRunData( const wxString& aVectorName, int aTraceType,
3710 const std::vector<double>& aX,
3711 const std::vector<double>& aY )
3712{
3713 if( aX.empty() || aY.empty() )
3714 return;
3715
3716 std::string key = multiRunTraceKey( aVectorName, aTraceType );
3717 MULTI_RUN_TRACE& trace = m_multiRunState.traces[key];
3718
3719 trace.traceType = aTraceType;
3720
3721 if( trace.xValues.empty() )
3722 trace.xValues = aX;
3723
3724 if( trace.xValues.size() != aX.size() )
3725 return;
3726
3727 size_t index = m_multiRunState.currentStep;
3728
3729 if( trace.yValues.size() <= index )
3730 trace.yValues.resize( index + 1 );
3731
3732 trace.yValues[index] = aY;
3733}
3734
3735
3736bool SIMULATOR_FRAME_UI::hasMultiRunTrace( const wxString& aVectorName, int aTraceType ) const
3737{
3738 std::string key = multiRunTraceKey( aVectorName, aTraceType );
3739 auto it = m_multiRunState.traces.find( key );
3740
3741 if( it == m_multiRunState.traces.end() )
3742 return false;
3743
3744 const MULTI_RUN_TRACE& trace = it->second;
3745
3746 return !trace.xValues.empty() && !trace.yValues.empty();
3747}
3748
3749
3751{
3752 m_simulatorFrame->OnModify();
3753}
int color
const char * name
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
Definition box2.h:990
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
void doPopupSelection(wxCommandEvent &event) override
SIMULATOR_FRAME_UI * m_parent
CURSORS_GRID_TRICKS(SIMULATOR_FRAME_UI *aParent, WX_GRID *aGrid)
The SIMULATOR_FRAME holds the main user-interface for running simulations.
const wxRealPoint & GetCoords() const
void SetCoordX(double aValue)
int ShowModal() override
bool Find(const wxString &aTerm, int &aMatchersTriggered, int &aPosition)
Look in all existing matchers, return the earliest match of any of the existing.
GRID_TRICKS(WX_GRID *aGrid)
virtual void doPopupSelection(wxCommandEvent &event)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
WX_GRID * m_grid
I don't own the grid, but he owns me.
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:104
wxString ToCSSString() const
Definition color4d.cpp:147
Definition kiid.h:49
Hold a translatable error message and may be used when throwing exceptions containing a translated er...
const wxString What() const
void doPopupSelection(wxCommandEvent &event) override
void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
SIMULATOR_FRAME_UI * m_parent
MEASUREMENTS_GRID_TRICKS(SIMULATOR_FRAME_UI *aParent, WX_GRID *aGrid)
static void ConvertToSpiceMarkup(wxString *aNetName)
Remove formatting wrappers and replace illegal spice net name characters with underscores.
const SPICE_ITEM * FindItem(const wxString &aRefName) const
Find and return the item corresponding to aRefName.
A singleton reporter that reports to nowhere.
Definition reporter.h:216
virtual bool HasMessage() const
Returns true if any messages were reported.
Definition reporter.h:134
Holds all the data relating to one schematic.
Definition schematic.h:88
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition schematic.h:274
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition sch_item.h:167
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_ITEM * ResolveItem(const KIID &aID) const
Fetch a SCH_ITEM by ID.
Schematic symbol object.
Definition sch_symbol.h:75
EMBEDDED_FILES * GetEmbeddedFiles() override
SCH_SYMBOLs don't currently support embedded files, but their LIB_SYMBOL counterparts do.
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly) const override
Populate a std::vector with SCH_FIELDs, sorted in ordinal order.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
void doPopupSelection(wxCommandEvent &event) override
void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent) override
SIMULATOR_FRAME_UI * m_parent
SIGNALS_GRID_TRICKS(SIMULATOR_FRAME_UI *aParent, WX_GRID *aGrid)
wxSplitterWindow * m_splitterLeftRight
wxSplitterWindow * m_splitterMeasurements
wxSplitterWindow * m_splitterCursors
wxSplitterWindow * m_splitterPlotAndConsole
SIMULATOR_FRAME_UI_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
wxSplitterWindow * m_splitterSignals
The SIMULATOR_FRAME_UI holds the main user-interface for running simulations.
SIM_TAB * NewSimTab(const wxString &aSimCommand)
Create a new simulation tab for a given simulation type.
std::string multiRunTraceKey(const wxString &aVectorName, int aTraceType) const
void SetUserDefinedSignals(const std::map< int, wxString > &aSignals)
void updatePlotCursors()
Update the cursor values (in the grid) and graphics (in the plot window).
void OnSimRefresh(bool aFinal)
void onPlotClose(wxAuiNotebookEvent &event) override
void CustomCursorsInit()
Init handler for custom cursors.
void recordMultiRunData(const wxString &aVectorName, int aTraceType, const std::vector< double > &aX, const std::vector< double > &aY)
std::vector< MULTI_RUN_STEP > calculateMultiRunSteps(const std::vector< TUNER_SLIDER * > &aTuners) const
void TogglePanel(wxPanel *aPanel, wxSplitterWindow *aSplitterWindow, int &aSashPosition)
A common toggler for the two main wxSplitterWindow s.
void onPlotChanged(wxAuiNotebookEvent &event) override
void rebuildSignalsGrid(wxString aFilter)
Rebuild the filtered list of signals in the signals grid.
std::vector< std::vector< SPICE_VALUE_FORMAT > > m_cursorFormatsDyn
void DoFourier(const wxString &aSignal, const wxString &aFundamental)
void rebuildMeasurementsGrid()
Rebuild the measurements grid for the current plot.
std::list< TUNER_SLIDER * > m_tuners
void rebuildSignalsList()
Rebuild the list of signals available from the netlist.
bool loadLegacyWorkbook(const wxString &aPath)
MULTI_RUN_STATE m_multiRunState
SPICE expressions need quoted versions of the netnames since KiCad allows '-' and '/' in netnames.
void UpdateMeasurement(int aRow)
Update a measurement in the measurements grid.
wxString getNoiseSource() const
std::vector< wxString > SimPlotVectors() const
void SetSubWindowsSashSize()
Adjust the sash dimension of splitter windows after reading the config settings must be called after ...
void applyUserDefinedSignals()
Apply user-defined signals to the SPICE session.
SIM_PREFERENCES m_preferences
void DeleteMeasurement(int aRow)
Delete a row from the measurements grid.
SCH_EDIT_FRAME * m_schematicFrame
wxString vectorNameFromSignalName(SIM_PLOT_TAB *aPlotTab, const wxString &aSignalName, int *aTraceType)
Get the simulator output vector name for a given signal name and type.
void updateSignalsGrid()
Update the values in the signals grid.
void onCursorsGridCellChanged(wxGridEvent &aEvent) override
void onPlotDragged(wxAuiNotebookEvent &event) override
std::vector< wxString > Signals() const
bool SaveWorkbook(const wxString &aPath)
Save plot, signal, cursor, measurement, etc.
bool hasMultiRunTrace(const wxString &aVectorName, int aTraceType) const
std::vector< wxString > m_signals
SIM_TAB * GetCurrentSimTab() const
Return the currently opened plot panel (or NULL if there is none).
void SaveCursorToWorkbook(nlohmann::json &aTraceJs, TRACE *aTrace, int aCursorId)
bool LoadWorkbook(const wxString &aPath)
Load plot, signal, cursor, measurement, etc.
SPICE_VALUE_FORMAT GetMeasureFormat(int aRow) const
Get/Set the format of a value in the measurements grid.
std::map< int, wxString > m_userDefinedSignals
void UpdateTunerValue(const SCH_SHEET_PATH &aSheetPath, const KIID &aSymbol, const wxString &aRef, const wxString &aValue)
Safely update a field of the associated symbol without dereferencing the symbol.
std::vector< wxString > m_netnames
void AddTrace(const wxString &aName, SIM_TRACE_TYPE aType)
Add a new trace to the current plot.
void onPlotClosed(wxAuiNotebookEvent &event) override
void RemoveTuner(TUNER_SLIDER *aTuner)
Remove an existing tuner.
void SaveSettings(EESCHEMA_SETTINGS *aCfg)
std::shared_ptr< SPICE_CIRCUIT_MODEL > circuitModel() const
void OnFilterText(wxCommandEvent &aEvent) override
void onMeasurementsGridCellChanged(wxGridEvent &aEvent) override
void DeleteCursor()
Deletes last m_signalsGrid "Cursor n" column, removes vector's m_cursorFormatsDyn last entry,...
void CreateNewCursor()
Creates a column at the end of m_signalsGrid named "Cursor n" ( n = m_customCursorsCnt ),...
void applyTuners()
Apply component values specified using tuner sliders to the current netlist.
bool loadJsonWorkbook(const wxString &aPath)
void clearMultiRunState(bool aClearTraces)
void OnFilterMouseMoved(wxMouseEvent &aEvent) override
void AddMeasurement(const wxString &aCmd)
Add a measurement to the measurements grid.
void onPlotChanging(wxAuiNotebookEvent &event) override
std::map< const TUNER_SLIDER *, double > m_tunerOverrides
std::shared_ptr< SPICE_SIMULATOR > simulator() const
void onPlotCursorUpdate(wxCommandEvent &aEvent)
void onSignalsGridCellChanged(wxGridEvent &aEvent) override
void InitWorkbook()
Load the currently active workbook stored in the project settings.
SIM_TRACE_TYPE getXAxisType(SIM_TYPE aType) const
Return X axis for a given simulation type.
void signalsGridCursorUpdate(T t, U u, R r)
Updates m_signalsGrid cursor widget, column rendering and attributes.
void SetMeasureFormat(int aRow, const SPICE_VALUE_FORMAT &aFormat)
void OnSimReport(const wxString &aMsg)
void ApplyPreferences(const SIM_PREFERENCES &aPrefs)
Called when settings are changed via the common Preferences dialog.
const SPICE_CIRCUIT_MODEL * GetExporter() const
Return the netlist exporter object used for simulations.
SIMULATOR_FRAME * m_simulatorFrame
void AddTuner(const SCH_SHEET_PATH &aSheetPath, SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
void OnUpdateUI(wxUpdateUIEvent &event) override
void updateTrace(const wxString &aVectorName, int aTraceType, SIM_PLOT_TAB *aPlotTab, std::vector< double > *aDataX=nullptr, bool aClearData=false)
Update a trace in a particular SIM_PLOT_TAB.
SIMULATOR_FRAME_UI(SIMULATOR_FRAME *aSimulatorFrame, SCH_EDIT_FRAME *aSchematicFrame)
SPICE_VALUE_FORMAT m_cursorFormats[3][2]
void LoadSettings(EESCHEMA_SETTINGS *aCfg)
The SIMULATOR_FRAME holds the main user-interface for running simulations.
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< SCH_PIN * > &aPins, REPORTER &aReporter)
void SetFilesStack(std::vector< EMBEDDED_FILES * > aFilesStack)
Definition sim_lib_mgr.h:48
virtual const PARAM * GetTunerParam() const
Definition sim_model.h:480
const SPICE_GENERATOR & SpiceGenerator() const
Definition sim_model.h:431
void WriteFields(std::vector< SCH_FIELD > &aFields) const
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
static void FillDefaultColorList(bool aWhiteBg)
Fills m_colorList by a default set of colors.
bool DeleteTrace(const wxString &aVectorName, int aTraceType)
wxString GetLabelY1() const
mpWindow * GetPlotWin() const
void ShowGrid(bool aEnable)
void SetTraceData(TRACE *aTrace, std::vector< double > &aX, std::vector< double > &aY, int aSweepCount, size_t aSweepSize, bool aIsMultiRun=false, const std::vector< wxString > &aMultiRunLabels={})
wxString GetUnitsY2() const
void SetY2Scale(bool aLock, double aMin, double aMax)
TRACE * GetTrace(const wxString &aVecName, int aType) const
wxString GetLabelX() const
const std::map< wxString, TRACE * > & GetTraces() const
wxString GetLabelY3() const
void SetY1Scale(bool aLock, double aMin, double aMax)
void SetY3Scale(bool aLock, double aMin, double aMax)
std::vector< std::pair< wxString, wxString > > & Measurements()
void UpdateTraceStyle(TRACE *trace)
Update plot colors.
void SetLegendPosition(const wxPoint &aPosition)
void ResetScales(bool aIncludeX)
Update trace line style.
void UpdatePlotColors()
void ShowLegend(bool aEnable)
wxString GetLabelY2() const
void EnableCursor(TRACE *aTrace, int aCursorId, const wxString &aSignalName)
wxString GetUnitsX() const
void EnsureThirdYAxisExists()
TRACE * GetOrAddTrace(const wxString &aVectorName, int aType)
void SetDottedSecondary(bool aEnable)
Draw secondary signal traces (current or phase) with dotted lines.
void ApplyPreferences(const SIM_PREFERENCES &aPrefs) override
wxString GetUnitsY1() const
void DisableCursor(TRACE *aTrace, int aCursorId)
Reset scale ranges to fit the current traces.
wxString GetUnitsY3() const
int GetSimOptions() const
Definition sim_tab.h:55
SIM_TYPE GetSimType() const
Definition sim_tab.cpp:75
const wxString & GetSimCommand() const
Definition sim_tab.h:52
static bool IsPlottable(SIM_TYPE aSimType)
Definition sim_tab.cpp:53
void SetSimOptions(int aOptions)
Definition sim_tab.h:56
wxString GetLastSchTextSimCommand() const
Definition sim_tab.h:58
void SetSpicePlotName(const wxString &aPlotName)
Definition sim_tab.h:62
static std::string ToSpice(const std::string &aString)
Special netlist exporter flavor that allows one to override simulation commands.
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Return simulation type basing on a simulation command directive.
bool ParseNoiseCommand(const wxString &aCmd, wxString *aOutput, wxString *aRef, wxString *aSource, wxString *aScale, SPICE_VALUE *aPts, SPICE_VALUE *aFStart, SPICE_VALUE *aFStop, bool *aSaveAll)
wxString GetSchTextSimCommand()
Return simulation command directives placed in schematic sheets (if any).
SIM_TRACE_TYPE VectorToSignal(const std::string &aVector, wxString &aSignal) const
Return name of Spice dataset for a specific trace.
virtual std::string TunerCommand(const SPICE_ITEM &aItem, double aValue) const
wxString GetWorkbookFilename() const
void SetWorkbookFilename(const wxString &aFilename)
virtual bool Command(const std::string &aCmd)=0
Execute a Spice command as if it was typed into console.
static wxString TypeToName(SIM_TYPE aType, bool aShortName)
Return a string with simulation name based on enum.
std::shared_ptr< SPICE_SETTINGS > & Settings()
Return the simulator configuration settings.
virtual wxString CurrentPlotName() const =0
virtual std::vector< double > GetRealVector(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with real values.
virtual std::vector< double > GetGainVector(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with magnitude values.
virtual std::vector< double > GetPhaseVector(const std::string &aName, int aMaxLen=-1)=0
Return a requested vector with phase values.
Helper class to recognize Spice formatted values.
Definition spice_value.h:56
wxString ToString() const
Return string value as when converting double to string (e.g.
wxString ToSpiceString() const
Return string value in Spice format (e.g.
double ToDouble() const
SUPPRESS_GRID_CELL_EVENTS(SIMULATOR_FRAME_UI *aFrame)
void SetTraceColour(const wxColour &aColour)
bool HasCursor(int aCursorId)
CURSOR * GetCursor(int aCursorId)
Custom widget to handle quick component values modification and simulation on the fly.
wxString GetSymbolRef() const
A wrapper for reporting to a wxString object.
Definition reporter.h:191
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
Definition reporter.cpp:68
const wxString & GetMessages() const
Definition reporter.cpp:77
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
const wxString & GetName() const
Get layer name.
Definition mathplot.h:239
const wxPen & GetPen() const
Get pen set for this layer.
Definition mathplot.h:254
Canvas for plotting mpLayer implementations.
Definition mathplot.h:910
int GetMarginLeft() const
Definition mathplot.h:1221
void SetMargins(int top, int right, int bottom, int left)
Set window margins, creating a blank area where some kinds of layers cannot draw.
int GetMarginTop() const
Definition mathplot.h:1215
void UpdateAll()
Refresh display.
int GetMarginRight() const
Definition mathplot.h:1217
int GetMarginBottom() const
Definition mathplot.h:1219
void LockY(bool aLock)
Definition mathplot.h:1265
bool AddLayer(mpLayer *layer, bool refreshDisplay=true)
Add a plot layer to the canvas.
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:194
This file is part of the common library.
#define _(s)
Abstract pattern-matching tool and implementations.
@ CTX_SIGNAL
@ GRIDTRICKS_ID_SELECT
Definition grid_tricks.h:46
@ GRIDTRICKS_ID_COPY
Definition grid_tricks.h:43
@ GRIDTRICKS_ID_DELETE
Definition grid_tricks.h:44
@ GRIDTRICKS_FIRST_CLIENT_ID
Definition grid_tricks.h:48
int m_SimulatorMultiRunCombinationLimit
Maximum number of tuner combinations simulated when using multi-run mode.
static const std::string WorkbookFileExtension
#define traceSettings
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
see class PGM_BASE
SIM_TRACE_TYPE
Definition sim_types.h:50
@ SPT_TIME
Definition sim_types.h:61
@ SPT_AC_PHASE
Definition sim_types.h:54
@ SPT_SWEEP
Definition sim_types.h:64
@ SPT_UNKNOWN
Definition sim_types.h:67
@ SPT_AC_GAIN
Definition sim_types.h:55
@ SPT_Y_AXIS_MASK
Definition sim_types.h:58
@ SPT_SP_AMP
Definition sim_types.h:57
@ SPT_VOLTAGE
Definition sim_types.h:52
@ SPT_POWER
Definition sim_types.h:56
@ SPT_CURRENT
Definition sim_types.h:53
@ SPT_LIN_FREQUENCY
Definition sim_types.h:62
SIM_TYPE
< Possible simulation types
Definition sim_types.h:32
@ ST_SP
Definition sim_types.h:43
@ ST_TRAN
Definition sim_types.h:42
@ ST_UNKNOWN
Definition sim_types.h:33
@ ST_NOISE
Definition sim_types.h:37
@ ST_AC
Definition sim_types.h:34
@ ST_DISTO
Definition sim_types.h:36
@ ST_TF
Definition sim_types.h:41
@ ST_SENS
Definition sim_types.h:40
@ ST_DC
Definition sim_types.h:35
@ ST_OP
Definition sim_types.h:38
@ ST_FFT
Definition sim_types.h:44
@ ST_PZ
Definition sim_types.h:39
void sortSignals(std::vector< wxString > &signals)
wxString vectorNameFromSignalId(int aUserDefinedSignalId)
MEASUREMENTS_GIRD_COLUMNS
@ COL_MEASUREMENT_FORMAT
@ COL_MEASUREMENT_VALUE
@ COL_MEASUREMENT
CURSORS_GRID_COLUMNS
@ COL_CURSOR_NAME
@ COL_CURSOR_SIGNAL
@ COL_CURSOR_X
@ COL_CURSOR_Y
SIGNALS_GRID_COLUMNS
@ COL_SIGNAL_SHOW
@ COL_SIGNAL_NAME
@ COL_CURSOR_1
@ COL_SIGNAL_COLOR
@ COL_CURSOR_2
#define ID_SIM_REFRESH
@ MYID_MEASURE_INTEGRAL
@ MYID_MEASURE_MAX_AT
@ MYID_MEASURE_AVG
@ MYID_MEASURE_MAX
@ MYID_FORMAT_VALUE
@ MYID_MEASURE_RMS
@ MYID_DELETE_MEASUREMENT
@ MYID_MEASURE_MIN
@ MYID_MEASURE_MIN_AT
@ MYID_MEASURE_PP
SIM_TRACE_TYPE operator|(SIM_TRACE_TYPE aFirst, SIM_TRACE_TYPE aSecond)
#define REFRESH_INTERVAL
const int scale
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
std::map< const TUNER_SLIDER *, double > overrides
std::vector< std::vector< double > > yValues
const INFO & info
Definition sim_model.h:401
Contains preferences pertaining to the simulator.
const SIM_MODEL * model
A SPICE_VALUE_FORMAT holds precision and range info for formatting values.Helper class to handle Spic...
Definition spice_value.h:43
wxString ToString() const
void UpdateUnits(const wxString &aUnits)
VECTOR3I res
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.