31#include <fmt/format.h>
32#include <wx/wfstream.h>
33#include <wx/stdstream.h>
35#include <wx/clipbrd.h>
56#include <magic_enum.hpp>
61 int res =
static_cast<int>( aFirst ) |
static_cast<int>( aSecond);
122 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
override;
173 menu.AppendSeparator();
174 menu.Append(
MYID_FOURIER,
_(
"Perform Fourier Analysis..." ) );
177 menu.AppendSeparator();
180 menu.AppendSeparator();
183 m_grid->PopupMenu( &menu );
190 menu.AppendSeparator();
192 wxString msg =
m_grid->GetColLabelValue(
m_grid->GetNumberCols() - 1 );
194 menu.AppendSeparator();
197 m_grid->PopupMenu( &menu );
203 m_grid->PopupMenu( &menu );
210 std::vector<wxString> signals;
212 wxGridCellCoordsArray cells1 =
m_grid->GetSelectionBlockTopLeft();
213 wxGridCellCoordsArray cells2 =
m_grid->GetSelectionBlockBottomRight();
215 for(
size_t i = 0; i < cells1.Count(); i++ )
219 for(
int j = cells1[i].GetRow(); j < cells2[i].GetRow() + 1; j++ )
221 signals.push_back(
m_grid->GetCellValue( j, cells1[i].GetCol() ) );
226 wxGridCellCoordsArray cells3 =
m_grid->GetSelectedCells();
228 for(
size_t i = 0; i < cells3.Count(); i++ )
231 signals.push_back(
m_grid->GetCellValue( cells3[i].GetRow(), cells3[i].GetCol() ) );
234 if( signals.size() < 1 )
237 auto addMeasurement =
238 [
this](
const wxString& cmd, wxString signal )
240 if( signal.EndsWith(
_(
" (phase)" ) ) )
243 if( signal.EndsWith(
_(
" (gain)" ) ) || signal.EndsWith(
_(
" (amplitude)" ) ) )
245 signal = signal.Left( signal.length() - 7 );
247 if( signal.Upper().StartsWith( wxS(
"V(" ) ) )
248 signal = wxS(
"vdb" ) + signal.Mid( 1 );
251 m_parent->AddMeasurement( cmd + wxS(
" " ) + signal );
256 for(
const wxString& signal : signals )
257 addMeasurement( wxS(
"MIN" ), signal );
261 for(
const wxString& signal : signals )
262 addMeasurement( wxS(
"MAX" ), signal );
266 for(
const wxString& signal : signals )
267 addMeasurement( wxS(
"AVG" ), signal );
271 for(
const wxString& signal : signals )
272 addMeasurement( wxS(
"RMS" ), signal );
276 for(
const wxString& signal : signals )
277 addMeasurement( wxS(
"PP" ), signal );
281 for(
const wxString& signal : signals )
282 addMeasurement( wxS(
"MIN_AT" ), signal );
286 for(
const wxString& signal : signals )
287 addMeasurement( wxS(
"MAX_AT" ), signal );
291 for(
const wxString& signal : signals )
292 addMeasurement( wxS(
"INTEG" ), signal );
297 wxString fundamental = wxT(
"1K" );
299 if( signals.size() == 1 )
300 title.Printf(
_(
"Fourier Analysis of %s" ), signals[0] );
302 title =
_(
"Fourier Analyses of Multiple Signals" );
312 for(
const wxString& signal : signals )
313 m_parent->DoFourier( signal, fundamental );
320 for(
const wxString& signal : signals )
328 if( wxTheClipboard->Open() )
330 wxTheClipboard->SetData(
new wxTextDataObject( txt ) );
331 wxTheClipboard->Flush();
332 wxTheClipboard->Close();
357 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
override;
377 menu.AppendSeparator();
387 [
this](
int row ) -> wxString
391 if( signal.EndsWith(
"[2 - 1]" ) )
392 signal = signal.Left( signal.length() - 7 );
403 if( formatDialog.
ShowModal() == wxID_OK )
405 for(
int row = 0; row <
m_grid->GetNumberRows(); ++row )
407 if( getSignalName( row ) == getSignalName(
m_menuRow ) )
408 m_parent->SetCursorFormat( row, axis, format );
430 void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
override;
456 menu.AppendSeparator();
469 if( formatDialog.
ShowModal() == wxID_OK )
478 std::vector<int> measurements;
480 wxGridCellCoordsArray cells1 =
m_grid->GetSelectionBlockTopLeft();
481 wxGridCellCoordsArray cells2 =
m_grid->GetSelectionBlockBottomRight();
483 for(
size_t i = 0; i < cells1.Count(); i++ )
487 for(
int j = cells1[i].GetRow(); j < cells2[i].GetRow() + 1; j++ )
488 measurements.push_back( j );
492 wxGridCellCoordsArray cells3 =
m_grid->GetSelectedCells();
494 for(
size_t i = 0; i < cells3.Count(); i++ )
497 measurements.push_back( cells3[i].GetRow() );
500 if( measurements.size() < 1 )
505 sort( measurements.begin(), measurements.end(), std::greater<>() );
507 for(
int row : measurements )
527 m_frame->m_SuppressGridEvents++;
532 m_frame->m_SuppressGridEvents--;
540#define ID_SIM_REFRESH 10207
541#define REFRESH_INTERVAL 50
567 wxGridCellAttr* attr =
new wxGridCellAttr;
571 attr =
new wxGridCellAttr;
575 attr =
new wxGridCellAttr;
579 attr =
new wxGridCellAttr;
585 attr =
new wxGridCellAttr;
595 [&]( wxTimerEvent& aEvent )
604#ifndef wxHAS_NATIVE_TABART
624 m_cursorFormat[0] = { 3, wxS(
"~s" ) };
625 m_cursorFormat[1] = { 3, wxS(
"~V" ) };
636 for(
size_t index2 = 0; index2 < std::size(
m_cursorFormats[0] ); index2++ )
652 maxCursor.Replace(
_(
"Cursor " ),
"" );
654 int tmpMax = wxAtoi( maxCursor );
656 if( nameMax < tmpMax )
666 std::vector<SPICE_VALUE_FORMAT> tmp;
678 wxGridCellAttr* attr =
new wxGridCellAttr;
698 for(
int i = 0; i < rows; i++ )
700 if(
m_signalsGrid->GetCellValue( i, col - 1 ) == wxS(
"1" ) )
703 wxGridEvent aDummy( wxID_ANY, wxEVT_GRID_CELL_CHANGED,
m_signalsGrid, i, col - 1 );
723 for(
int ii = 0; ii < static_cast<int>(
m_plotNotebook->GetPageCount() ); ++ii )
727 simTab->OnLanguageChanged();
729 wxString pageTitle(
simulator()->TypeToName( simTab->GetSimType(),
true ) );
730 pageTitle.Prepend( wxString::Format(
_(
"Analysis %u - " ), ii+1 ) );
751 tuner->ShowChangedLanguage();
791 simTab->ApplyPreferences( aPrefs );
798 if( !
simulator()->Settings()->GetWorkbookFilename().IsEmpty() )
810 if( !schTextSimCommand.IsEmpty() )
843 std::sort( signals.begin(), signals.end(),
844 [](
const wxString& lhs,
const wxString& rhs )
847 if( lhs.Upper().StartsWith(
'V' ) && !rhs.Upper().StartsWith(
'V' ) )
849 else if( !lhs.Upper().StartsWith(
'V' ) && rhs.Upper().StartsWith(
'V' ) )
852 return StrNumCmp( lhs, rhs, true ) < 0;
869 std::vector<wxString> signals;
873 wxStringTokenizer tokenizer( plotPanel->
GetSimCommand(),
" \t\r\n", wxTOKEN_STRTOK );
875 while( tokenizer.HasMoreTokens() && tokenizer.GetNextToken().Lower() != wxT(
"fft" ) )
878 while( tokenizer.HasMoreTokens() )
879 signals.emplace_back( tokenizer.GetNextToken() );
886 for(
const wxString& signal :
m_signals )
887 signals.push_back( signal );
891 if( simType ==
ST_AC )
893 signals.push_back( signal +
_(
" (gain)" ) );
894 signals.push_back( signal +
_(
" (phase)" ) );
896 else if( simType ==
ST_SP )
898 signals.push_back( signal +
_(
" (amplitude)" ) );
899 signals.push_back( signal +
_(
" (phase)" ) );
903 signals.push_back( signal );
910 if( aFilter.IsEmpty() )
911 aFilter = wxS(
"*" );
916 for(
const wxString& signal : signals )
918 if( matcher.
Find( signal.Upper() ) )
927 wxGridCellAttr* attr =
new wxGridCellAttr;
928 attr->SetRenderer(
new wxGridCellBoolRenderer() );
930 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
935 attr =
new wxGridCellAttr;
940 attr =
new wxGridCellAttr;
944 attr =
new wxGridCellAttr;
952 attr =
new wxGridCellAttr;
962 attr =
new wxGridCellAttr;
965 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
970 attr =
new wxGridCellAttr;
971 attr->SetRenderer(
new wxGridCellBoolRenderer() );
973 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
977 attr =
new wxGridCellAttr;
978 attr->SetRenderer(
new wxGridCellBoolRenderer() );
980 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
988 attr =
new wxGridCellAttr;
989 attr->SetRenderer(
new wxGridCellBoolRenderer() );
991 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
1010 wxString unconnected = wxString( wxS(
"unconnected-(" ) );
1015 unconnected.Replace(
'(',
'_' );
1018 [&](
const wxString& aSignalName )
1020 if( simType ==
ST_AC )
1022 m_signals.push_back( aSignalName +
_(
" (gain)" ) );
1023 m_signals.push_back( aSignalName +
_(
" (phase)" ) );
1025 else if( simType ==
ST_SP )
1027 m_signals.push_back( aSignalName +
_(
" (amplitude)" ) );
1028 m_signals.push_back( aSignalName +
_(
" (phase)" ) );
1045 if( netname ==
"GND" || netname ==
"0" || netname.StartsWith( unconnected ) )
1049 addSignal( wxString::Format( wxS(
"V(%s)" ), netname ) );
1059 for(
const std::string&
name : item.model->SpiceGenerator().CurrentNames( item ) )
1069 if( item.model->GetPinCount() >= 2 )
1071 wxString
name = item.model->SpiceGenerator().ItemName( item );
1072 addSignal( wxString::Format( wxS(
"P(%s)" ),
name ) );
1079 addSignal( wxS(
"inoise_spectrum" ) );
1080 addSignal( wxS(
"onoise_spectrum" ) );
1083 if( simType ==
ST_SP )
1085 std::vector<std::string> portnums;
1089 wxString
name = item.model->SpiceGenerator().ItemName( item );
1092 if( !
name.StartsWith(
"V" ) )
1095 std::string portnum =
"";
1097 if(
const SIM_MODEL::PARAM* portnum_param = item.model->FindParam(
"portnum" ) )
1101 portnums.push_back( portnum );
1104 for(
const std::string& portnum1 : portnums )
1106 for(
const std::string& portnum2 : portnums )
1108 addSignal( wxString::Format( wxS(
"S_%s_%s" ), portnum1, portnum2 ) );
1114 for(
const wxString& directive :
circuitModel()->GetDirectives() )
1116 wxStringTokenizer directivesTokenizer( directive,
"\r\n", wxTOKEN_STRTOK );
1118 while( directivesTokenizer.HasMoreTokens() )
1120 wxString line = directivesTokenizer.GetNextToken().Upper();
1121 wxString directiveParams;
1123 if( line.StartsWith( wxS(
".SAVE" ), &directiveParams )
1124 || line.StartsWith( wxS(
".PROBE" ), &directiveParams ) )
1126 wxStringTokenizer paramsTokenizer( directiveParams,
" \t", wxTOKEN_STRTOK );
1128 while( paramsTokenizer.HasMoreTokens() )
1129 addSignal( paramsTokenizer.GetNextToken() );
1152 wxString pageTitle(
simulator()->TypeToName( simType,
true ) );
1153 pageTitle.Prepend( wxString::Format(
_(
"Analysis %u - " ),
static_cast<unsigned int>( ++
m_plotNumber ) ) );
1169#if defined( __WXOSX__ ) || wxCHECK_VERSION( 3, 3, 0 )
1170 wxPoint pos = aEvent.GetPosition();
1171 wxRect ctrlRect =
m_filter->GetScreenRect();
1172 int buttonWidth = ctrlRect.GetHeight();
1174 if(
m_filter->IsSearchButtonVisible() && pos.x < buttonWidth )
1175 SetCursor( wxCURSOR_ARROW );
1176 else if(
m_filter->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
1177 SetCursor( wxCURSOR_ARROW );
1179 SetCursor( wxCURSOR_IBEAM );
1186 return wxString::Format( wxS(
"user%d" ), aUserDefinedSignalId );
1195 const wxString& aSignalName,
1198 std::map<wxString, int> suffixes;
1214 wxUniChar firstChar = aSignalName.Upper()[0];
1216 if( firstChar ==
'V' )
1218 else if( firstChar ==
'I' )
1220 else if( firstChar ==
'P' )
1225 wxString
name = aSignalName;
1227 for(
const auto& [ candidate, type ] : suffixes )
1229 if(
name.EndsWith( candidate ) )
1231 name =
name.Left(
name.Length() - candidate.Length() );
1234 *aTraceType |= type;
1242 if(
name == signal )
1260 int row = aEvent.GetRow();
1261 int col = aEvent.GetCol();
1269 if(
text == wxS(
"1" ) )
1305 TRACE* activeTrace =
nullptr;
1307 if(
text == wxS(
"1" ) )
1311 activeTrace = plotTab->
GetTrace( vectorName, traceType );
1322 if( trace != activeTrace && trace->
HasCursor(
id ) )
1345 int row = aEvent.GetRow();
1346 int col = aEvent.GetCol();
1354 CURSOR* cursor1 =
nullptr;
1355 CURSOR* cursor2 =
nullptr;
1357 std::vector<CURSOR*> cursorsVec;
1379 cursorsVec.emplace_back(
cursor );
1381 if( cursorName == ( wxString(
"" ) << i ) &&
cursor )
1382 cursor->SetCoordX( value );
1389 if( cursorName == wxS(
"1" ) && cursor1 )
1391 else if( cursorName == wxS(
"2" ) && cursor2 )
1393 else if( cursorName ==
_(
"Diff" ) && cursor1 && cursor2 )
1401 wxFAIL_MSG( wxT(
"All other columns are supposed to be read-only!" ) );
1434 int row = aEvent.GetRow();
1435 int col = aEvent.GetCol();
1445 wxFAIL_MSG( wxT(
"All other columns are supposed to be read-only!" ) );
1453 for( row = rowCount - 1; row >= 0; row-- )
1463 int killRows = emptyRows - 1;
1466 else if( emptyRows == 0 )
1477 if( plotTab->GetLegendPosition() != plotTab->m_LastLegendPosition )
1479 plotTab->m_LastLegendPosition = plotTab->GetLegendPosition();
1502 static wxRegEx measureParamsRegEx( wxT(
"^"
1506 "([a-zA-Z]*)\\(([^\\)]+)\\)" ) );
1515 if(
text.IsEmpty() )
1522 wxString resultName = wxString::Format( wxS(
"meas_result_%u" ), aRow );
1523 wxString
result = wxS(
"?" );
1525 if( measureParamsRegEx.Matches(
text ) )
1527 wxString func = measureParamsRegEx.GetMatch(
text, 1 ).Upper();
1528 wxString signalType = measureParamsRegEx.GetMatch(
text, 2 ).Upper();
1529 wxString deviceName = measureParamsRegEx.GetMatch(
text, 3 );
1533 if( signalType.EndsWith( wxS(
"DB" ) ) )
1535 units = wxS(
"dB" );
1537 else if( signalType.StartsWith(
'I' ) )
1541 else if( signalType.StartsWith(
'P' ) )
1545 text = func +
" " + deviceName +
":power";
1552 if( func.EndsWith( wxS(
"_AT" ) ) )
1555 units = wxS(
"Hz" );
1559 else if( func.StartsWith( wxS(
"INTEG" ) ) )
1564 if ( signalType.StartsWith(
'P' ) )
1567 units += wxS(
".s" );
1577 units += wxS(
"·Hz" );
1585 units += wxS(
"·?" );
1598 wxString cmd = wxString::Format( wxS(
"meas %s %s %s" ), simType, resultName,
text );
1604 if( resultVec.size() > 0 )
1619 "the value of a passive R, L, C model or voltage or "
1620 "current source." ) );
1624 wxString ref = aSymbol->
GetRef( &aSheetPath );
1629 if( tuner->GetSymbolRef() == ref )
1652 const wxString& aRef,
const wxString& aValue )
1660 + wxString::Format(
_(
"%s not found" ), aRef ) );
1667 std::vector<EMBEDDED_FILES*> embeddedFilesStack;
1668 embeddedFilesStack.push_back(
m_schematicFrame->Schematic().GetEmbeddedFiles() );
1671 embeddedFilesStack.push_back( symbolEmbeddedFiles );
1682 + wxString::Format(
_(
"%s is not tunable" ), aRef ) );
1747 wxString cmd = wxString::Format( wxS(
"fourier %s %s" ),
1765 m_simConsole->AppendText(
_(
"Error: no current simulation.\n" ) );
1774 m_simConsole->AppendText(
_(
"Error: simulation type not defined.\n" ) );
1780 m_simConsole->AppendText(
_(
"Error: simulation type doesn't support plotting.\n" ) );
1787 if( simType ==
ST_AC )
1792 else if( simType ==
ST_SP )
1802 plotTab->GetPlotWin()->UpdateAll();
1824 if( aNewSignals.count(
id ) == 0 )
1829 plotTab->
DeleteTrace( vectorName, traceType | subType );
1834 plotTab->
DeleteTrace( vectorName, traceType | subType );
1847 if(
TRACE* trace = plotTab->
GetTrace( vectorName, traceType | subType ) )
1848 trace->SetName( aNewSignals.at(
id ) );
1855 if(
TRACE* trace = plotTab->
GetTrace( vectorName, traceType | subType ) )
1856 trace->SetName( aNewSignals.at(
id ) );
1861 if(
TRACE* trace = plotTab->
GetTrace( vectorName, traceType ) )
1862 trace->SetName( aNewSignals.at(
id ) );
1896 wxString simVectorName = aVectorName;
1899 simVectorName = simVectorName.AfterFirst(
'(' ).BeforeLast(
')' ) + wxS(
":power" );
1904 simulator()->
Command( wxString::Format( wxT(
"print %s" ), aVectorName ).ToStdString() );
1909 std::vector<double> data_x;
1910 std::vector<double> data_y;
1912 if( !aDataX || aClearData )
1916 if( aDataX->empty() && !aClearData )
1918 wxString xAxisName(
simulator()->GetXAxis( simType ) );
1920 if( xAxisName.IsEmpty() )
1926 unsigned int size = aDataX->size();
1936 wxFAIL_MSG( wxT(
"Plot type missing AC_PHASE or AC_MAG bit" ) );
1945 wxFAIL_MSG( wxT(
"Plot type missing AC_PHASE or SPT_SP_AMP bit" ) );
1960 wxFAIL_MSG( wxT(
"Unhandled plot type" ) );
1965 size_t sweepSize = std::numeric_limits<size_t>::max();
1967 if( simType ==
ST_DC
1974 sweepSize = aDataX->size() / sweepCount;
1979 if( data_y.size() >= size )
1980 aPlotTab->
SetTraceData( trace, *aDataX, data_y, sweepCount, sweepSize );
1990template <
typename T,
typename U,
typename R>
1999 wxGridCellAttrPtr attr =
m_signalsGrid->GetOrCreateCellAttrPtr( r,
static_cast<int>( t ) );
2001 if(
TRACE* trace = plotTab ? plotTab->
GetTrace( vectorName, traceType ) :
nullptr )
2003 attr->SetReadOnly();
2007 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
2010 if constexpr ( std::is_enum<T>::value )
2014 m_signalsGrid->SetCellValue( r,
static_cast<int>( t ), wxS(
"1" ) );
2018 if( !attr->HasRenderer() )
2021 if( !attr->HasEditor() )
2024 attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
2025 attr->SetReadOnly(
false );
2034 if( !attr->HasRenderer() )
2035 attr->SetRenderer(
new wxGridCellBoolRenderer() );
2037 if( u > 0 && trace->HasCursor( u ) )
2038 m_signalsGrid->SetCellValue( r,
static_cast<int>( t ), wxS(
"1" ) );
2040 m_signalsGrid->SetCellValue( r,
static_cast<int>( t ), wxEmptyString );
2046 if constexpr ( std::is_enum<T>::value )
2050 m_signalsGrid->SetCellValue( r,
static_cast<int>( t ), wxEmptyString );
2057 attr->SetEditor(
nullptr );
2058 attr->SetRenderer(
nullptr );
2059 attr->SetReadOnly();
2060 m_signalsGrid->SetCellValue( r,
static_cast<int>( t ), wxEmptyString );
2069 for(
int row = 0; row <
m_signalsGrid->GetNumberRows(); ++row )
2094 auto quoteNetNames = [&]( wxString aExpression ) -> wxString
2096 std::vector<bool> mask( aExpression.length(),
false );
2100 size_t pos = aExpression.find( netname );
2102 while( pos != wxString::npos )
2104 for(
size_t i = 0; i < netname.length(); ++i )
2106 mask[pos + i] =
true;
2108 pos = aExpression.find( netname, pos + 1 );
2112 wxString quotedNetnames =
"";
2113 bool startQuote =
true;
2116 for(
size_t i = 0; i < aExpression.length(); i++ )
2118 if( mask[i] && startQuote )
2120 quotedNetnames = quotedNetnames +
"\"";
2123 else if( !mask[i] && !startQuote )
2125 quotedNetnames = quotedNetnames +
"\"";
2128 wxString ch = aExpression[i];
2129 quotedNetnames = quotedNetnames + ch;
2134 quotedNetnames = quotedNetnames +
"\"";
2136 return quotedNetnames;
2141 constexpr const char* cmd =
"let user{} = {}";
2143 simulator()->
Command(
"echo " + fmt::format( cmd,
id, signal.ToStdString() ) );
2144 simulator()->
Command( fmt::format( cmd,
id, quoteNetNames( signal ).ToStdString() ) );
2156 wxString ref = tuner->GetSymbolRef();
2157 KIID symbolId = tuner->GetSymbol( &sheetPath );
2163 reporter.
Report( wxString::Format(
_(
"%s not found" ), ref ) );
2171 reporter.
Report( wxString::Format(
_(
"%s is not tunable" ), ref ) );
2175 double floatVal = tuner->GetValue().ToDouble();
2187 wxTextFile file( aPath );
2192 wxString firstLine = file.GetFirstLine();
2194 bool legacy = firstLine.StartsWith( wxT(
"version " ) ) || firstLine.ToLong( &
dummy );
2219 wxFileName filename( aPath );
2231 wxFFileInputStream fp( aPath, wxT(
"rt" ) );
2232 wxStdInputStream fstream( fp );
2239 nlohmann::json js = nlohmann::json::parse( fstream,
nullptr,
true,
true );
2241 std::map<SIM_PLOT_TAB*, nlohmann::json> traceInfo;
2243 for(
const nlohmann::json& tab_js : js[
"tabs" ] )
2245 wxString simCommand;
2249 for(
const nlohmann::json& cmd : tab_js[
"commands" ] )
2251 if( cmd ==
".kicad adjustpaths" )
2253 else if( cmd ==
".save all" )
2255 else if( cmd ==
".probe alli" )
2257 else if( cmd ==
".probe allp" )
2259 else if( cmd ==
".kicad esavenone" )
2262 simCommand += wxString( cmd.get<wxString>() ).Trim();
2272 if( tab_js.contains(
"traces" ) )
2273 traceInfo[plotTab] = tab_js[
"traces" ];
2275 if( tab_js.contains(
"measurements" ) )
2277 for(
const nlohmann::json& m_js : tab_js[
"measurements" ] )
2278 plotTab->
Measurements().emplace_back( m_js[
"expr" ], m_js[
"format" ] );
2282 plotTab->
ShowGrid( tab_js[
"showGrid" ] );
2284 if( tab_js.contains(
"fixedY1scale" ) )
2286 const nlohmann::json& scale_js = tab_js[
"fixedY1scale" ];
2287 plotTab->
SetY1Scale(
true, scale_js[
"min" ], scale_js[
"max" ] );
2291 if( tab_js.contains(
"fixedY2scale" ) )
2293 const nlohmann::json& scale_js = tab_js[
"fixedY2scale" ];
2294 plotTab->
SetY2Scale(
true, scale_js[
"min" ], scale_js[
"max" ] );
2298 if( tab_js.contains(
"fixedY3scale" ) )
2301 const nlohmann::json& scale_js = tab_js[
"fixedY3scale" ];
2302 plotTab->
SetY3Scale(
true, scale_js[
"min" ], scale_js[
"max" ] );
2306 if( tab_js.contains(
"legend" ) )
2308 const nlohmann::json& legend_js = tab_js[
"legend" ];
2313 if( tab_js.contains(
"margins" ) )
2315 const nlohmann::json& margins_js = tab_js[
"margins" ];
2317 margins_js[
"right" ],
2318 margins_js[
"bottom" ],
2319 margins_js[
"left" ] );
2326 if( js.contains(
"user_defined_signals" ) )
2328 for(
const nlohmann::json& signal_js : js[
"user_defined_signals" ] )
2334 m_simulatorFrame->LoadSimulator( simTab->GetSimCommand(), simTab->GetSimOptions() );
2337 firstTab->SetLastSchTextSimCommand( js[
"last_sch_text_sim_command"] );
2340 int tempCustomCursorsCnt = 0;
2342 if( js.contains(
"custom_cursors" ) )
2343 tempCustomCursorsCnt = js[
"custom_cursors"];
2345 tempCustomCursorsCnt = 2;
2355 int aCursorId,
const nlohmann::json& aCursor_js )
2357 if( aCursorId >= 1 )
2361 cursor->SetName( aSignalName );
2362 cursor->SetCoordX( aCursor_js[
"position" ] );
2364 aTrace->SetCursor( aCursorId,
cursor );
2368 if( aCursorId == -1 )
2379 aCursor_js[
"x_format"] );
2381 aCursor_js[
"y_format"] );
2391 for(
const auto& [ plotTab, traces_js ] : traceInfo )
2393 for(
const nlohmann::json& trace_js : traces_js )
2395 wxString signalName = trace_js[
"signal" ];
2397 TRACE* trace = plotTab->GetOrAddTrace( vectorName, trace_js[
"trace_type" ] );
2401 if( trace_js.contains(
"cursorD" ) )
2402 addCursor( plotTab, trace, signalName, -1, trace_js[
"cursorD" ] );
2404 std::vector<const char*> aVec;
2407 for(
int i = 1; i <= tempCustomCursorsCnt; i++ )
2409 wxString str =
"cursor" + std::to_string( i );
2410 aVec.emplace_back( str.c_str() );
2412 if( trace_js.contains( aVec[i - 1] ) )
2413 addCursor( plotTab, trace, signalName, i, trace_js[aVec[i - 1]] );
2416 if( trace_js.contains(
"color" ) )
2419 color.Set( wxString( trace_js[
"color"].get<wxString>() ) );
2421 plotTab->UpdateTraceStyle( trace );
2426 plotTab->UpdatePlotColors();
2429 catch( nlohmann::json::parse_error& error )
2431 wxLogTrace(
traceSettings, wxT(
"Json parse error reading %s: %s" ), aPath, error.what() );
2435 catch( nlohmann::json::type_error& error )
2437 wxLogTrace(
traceSettings, wxT(
"Json type error reading %s: %s" ), aPath, error.what() );
2441 catch( nlohmann::json::invalid_iterator& error )
2443 wxLogTrace(
traceSettings, wxT(
"Json invalid_iterator error reading %s: %s" ), aPath, error.what() );
2447 catch( nlohmann::json::out_of_range& error )
2449 wxLogTrace(
traceSettings, wxT(
"Json out_of_range error reading %s: %s" ), aPath, error.what() );
2455 wxLogTrace(
traceSettings, wxT(
"Error reading %s" ), aPath );
2464 int cursorIdAfterD = aCursorId;
2467 cursorIdAfterD = cursorIdAfterD - 1;
2472 aTraceJs[
"cursor" + wxString(
"" ) << aCursorId] =
2473 nlohmann::json( { {
"position",
cursor->GetCoords().x },
2480 aTraceJs[
"cursorD"] =
2491 wxFileName filename = aPath;
2496 file.Create( filename.GetFullPath(),
true );
2498 if( !file.IsOpened() )
2501 nlohmann::json tabs_js = nlohmann::json::array();
2512 nlohmann::json commands_js = nlohmann::json::array();
2519 commands_js.push_back(
".kicad adjustpaths" );
2522 commands_js.push_back(
".save all" );
2525 commands_js.push_back(
".probe alli" );
2528 commands_js.push_back(
".probe allp" );
2531 commands_js.push_back(
".kicad esavenone" );
2533 nlohmann::json tab_js = nlohmann::json(
2535 {
"commands", commands_js } } );
2539 nlohmann::json traces_js = nlohmann::json::array();
2541 auto findSignalName =
2542 [&](
const wxString& aVectorName ) -> wxString
2544 wxString vectorName;
2547 if( aVectorName.EndsWith(
_(
" (phase)" ) ) )
2548 suffix =
_(
" (phase)" );
2549 else if( aVectorName.EndsWith(
_(
" (gain)" ) ) )
2550 suffix =
_(
" (gain)" );
2552 vectorName = aVectorName.Left( aVectorName.Length() - suffix.Length() );
2557 return signal + suffix;
2563 for(
const auto& [
name, trace] : plotTab->GetTraces() )
2565 nlohmann::json trace_js = nlohmann::json(
2566 { {
"trace_type", (int) trace->GetType() },
2567 {
"signal", findSignalName( trace->GetDisplayName() ) },
2573 if( trace->GetCursor( 1 ) || trace->GetCursor( 2 ) )
2575 trace_js[
"cursorD"] = nlohmann::json(
2580 traces_js.push_back( trace_js );
2583 nlohmann::json measurements_js = nlohmann::json::array();
2585 for(
const auto& [
measurement, format ] : plotTab->Measurements() )
2587 measurements_js.push_back( nlohmann::json( { {
"expr",
measurement },
2588 {
"format", format } } ) );
2591 tab_js[
"traces" ] = traces_js;
2592 tab_js[
"measurements" ] = measurements_js;
2593 tab_js[
"dottedSecondary" ] = plotTab->GetDottedSecondary();
2594 tab_js[
"showGrid" ] = plotTab->IsGridShown();
2598 if( plotTab->GetY1Scale( &min, &max ) )
2599 tab_js[
"fixedY1scale" ] = nlohmann::json( { {
"min", min }, {
"max", max } } );
2601 if( plotTab->GetY2Scale( &min, &max ) )
2602 tab_js[
"fixedY2scale" ] = nlohmann::json( { {
"min", min }, {
"max", max } } );
2604 if( plotTab->GetY3Scale( &min, &max ) )
2605 tab_js[
"fixedY3scale" ] = nlohmann::json( { {
"min", min }, {
"max", max } } );
2607 if( plotTab->IsLegendShown() )
2609 tab_js[
"legend" ] = nlohmann::json( { {
"x", plotTab->GetLegendPosition().x },
2610 {
"y", plotTab->GetLegendPosition().y } } );
2613 mpWindow* plotWin = plotTab->GetPlotWin();
2615 tab_js[
"margins" ] = nlohmann::json( { {
"left", plotWin->
GetMarginLeft() },
2621 tabs_js.push_back( tab_js );
2624 nlohmann::json userDefinedSignals_js = nlohmann::json::array();
2627 userDefinedSignals_js.push_back( signal );
2630 nlohmann::json js = nlohmann::json( { {
"version", 7 },
2631 {
"tabs", tabs_js },
2632 {
"user_defined_signals", userDefinedSignals_js },
2645 std::stringstream buffer;
2646 buffer << std::setw( 2 ) << js << std::endl;
2648 bool res = file.Write( buffer.str() );
2675 wxFAIL_MSG( wxString::Format( wxS(
"Unhandled simulation type: %d" ), (
int) aType ) );
2695 &source, &
scale, &pts, &fStart, &fStop, &saveAll );
2703 int& aSashPosition )
2705 bool isShown = aPanel->IsShown();
2708 aSashPosition = aSplitterWindow->GetSashPosition();
2710 aPanel->Show( !isShown );
2712 aSplitterWindow->SetSashInvisible( isShown );
2713 aSplitterWindow->SetSashPosition( isShown ? -1 : aSashPosition,
true );
2715 aSplitterWindow->UpdateSize();
2716 m_parent->Refresh();
2753 for(
size_t page = 0; page <
m_plotNotebook->GetPageCount(); page++ )
2798 std::vector<std::pair<wxString, wxString>>& measurements = plotTab->Measurements();
2800 measurements.clear();
2838 simulator()->
Command(
"setplot " + simTab->GetSpicePlotName().ToStdString() );
2852 for(
const auto& [
measurement, format ] : plotTab->Measurements() )
2860 if( plotTab->GetSimType() ==
ST_TRAN || plotTab->GetSimType() ==
ST_AC
2861 || plotTab->GetSimType() ==
ST_DC || plotTab->GetSimType() ==
ST_SP )
2898 CURSOR* cursor1 =
nullptr;
2899 wxString cursor1Name;
2900 wxString cursor1Units;
2901 CURSOR* cursor2 =
nullptr;
2902 wxString cursor2Name;
2903 wxString cursor2Units;
2906 [&](
TRACE* aTrace ) -> wxString
2927 [&](
TRACE* aTrace ) -> wxString
2948 [
this](
double aValue,
int aCursorId,
int aCol ) -> wxString
2950 if( ( !
m_simulatorFrame->SimFinished() && aCol == 1 ) || std::isnan( aValue ) )
2961 cursor1Name = getNameY( trace );
2962 cursor1Units = getUnitsY( trace );
2964 wxRealPoint coords =
cursor->GetCoords();
2984 cursor2Name = getNameY( trace );
2985 cursor2Units = getUnitsY( trace );
2987 wxRealPoint coords =
cursor->GetCoords();
3002 if( cursor1 && cursor2 && cursor1Units == cursor2Units )
3011 signal = wxString::Format( wxS(
"%s[2 - 1]" ), cursor2->
GetName() );
3013 signal = wxString::Format( wxS(
"%s - %s" ), cursor2->
GetName(), cursor1->
GetName() );
3024 wxString valColName =
_(
"Value" );
3026 if( !cursor1Name.IsEmpty() )
3028 if( cursor2Name.IsEmpty() || cursor1Name == cursor2Name )
3029 valColName = cursor1Name;
3031 else if( !cursor2Name.IsEmpty() )
3033 valColName = cursor2Name;
3047 wxString cursName = getNameY( trace );
3048 wxString cursUnits = getUnitsY( trace );
3050 wxRealPoint coords =
cursor->GetCoords();
3065 valColName =
_(
"Value" );
3067 if( !cursName.IsEmpty()
3070 valColName = cursName;
3091 plotTab->ResetScales(
true );
3111 std::vector<wxString> signals;
3113 for(
const std::string& vec :
simulator()->AllVectors() )
3114 signals.emplace_back( vec );
3122 std::vector<wxString> signals;
3124 for(
const wxString& signal :
m_signals )
3125 signals.emplace_back( signal );
3128 signals.emplace_back( signal );
3160 if( simType ==
ST_NOISE && aFinal )
3162 m_simConsole->AppendText(
_(
"\n\nSimulation results:\n\n" ) );
3171 for(
const std::string& vec :
simulator()->AllVectors() )
3176 msg.Printf( wxS(
"%s: %sV\n" ), vec, value );
3187 wxCHECK_RET( plotTab, wxString::Format( wxT(
"No SIM_PLOT_TAB for: %s" ),
3188 magic_enum::enum_name( simType ) ) );
3197 std::map<TRACE*, TRACE_INFO> traceMap;
3200 traceMap[ trace ] = { wxEmptyString,
SPT_UNKNOWN,
false };
3205 for(
const wxString& signal :
m_signals )
3210 if(
TRACE* trace = plotTab->
GetTrace( vectorName, traceType ) )
3211 traceMap[ trace ] = { vectorName, traceType,
false };
3219 if( simType ==
ST_AC )
3225 if(
TRACE* trace = plotTab->
GetTrace( vectorName, subType ) )
3226 traceMap[ trace ] = { vectorName, subType, !aFinal };
3229 else if( simType ==
ST_SP )
3235 if(
TRACE* trace = plotTab->
GetTrace( vectorName, subType ) )
3236 traceMap[trace] = { vectorName, subType, !aFinal };
3241 if(
TRACE* trace = plotTab->
GetTrace( vectorName, traceType ) )
3242 traceMap[ trace ] = { vectorName, traceType, !aFinal };
3248 for(
const auto& [ trace, traceInfo ] : traceMap )
3250 if( traceInfo.Vector.IsEmpty() )
3254 for(
const auto& [ trace,
info ] : traceMap )
3256 std::vector<double> data_x;
3258 if( !
info.Vector.IsEmpty() )
3276 else if( simType ==
ST_OP && aFinal )
3278 m_simConsole->AppendText(
_(
"\n\nSimulation results:\n\n" ) );
3281 for(
const std::string& vec :
simulator()->AllVectors() )
3285 if( val_list.empty() )
3292 const size_t tab = 25;
3293 size_t padding = ( signal.length() < tab ) ? ( tab - signal.length() ) : 1;
3297 case SPT_VOLTAGE: value.Append( wxS(
"V" ) );
break;
3298 case SPT_CURRENT: value.Append( wxS(
"A" ) );
break;
3299 case SPT_POWER: value.Append( wxS(
"W" ) );
break;
3300 default: value.Append( wxS(
"?" ) );
break;
3303 msg.Printf( wxT(
"%s%s\n" ),
3304 ( signal + wxT(
":" ) ).Pad( padding, wxUniChar(
' ' ) ),
3311 signal = signal.SubString( 2, signal.Length() - 2 );
3314 signal += wxS(
":power" );
3316 m_schematicFrame->Schematic().SetOperatingPoint( signal, val_list.at( 0 ) );
3319 else if( simType ==
ST_PZ && aFinal )
3321 m_simConsole->AppendText(
_(
"\n\nSimulation results:\n\n" ) );
constexpr BOX2I KiROUND(const BOX2D &aBoxD)
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)
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.
wxString ToCSSString() const
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.
@ OPTION_SAVE_ALL_CURRENTS
@ OPTION_SAVE_ALL_VOLTAGES
@ OPTION_SAVE_ALL_DISSIPATIONS
@ OPTION_ADJUST_INCLUDE_PATHS
@ OPTION_ADJUST_PASSIVE_VALS
const SPICE_ITEM * FindItem(const wxString &aRefName) const
Find and return the item corresponding to aRefName.
A singleton reporter that reports to nowhere.
virtual bool HasMessage() const
Returns true if any messages were reported.
Holds all the data relating to one schematic.
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Schematic editor (Eeschema) main window.
Base class for any item which can be embedded within the SCHEMATIC container class,...
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.
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)
wxBoxSizer * m_sizerTuners
WX_GRID * m_measurementsGrid
wxSplitterWindow * m_splitterLeftRight
wxSplitterWindow * m_splitterMeasurements
wxTextCtrl * m_simConsole
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
wxAuiNotebook * m_plotNotebook
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.
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.
int m_splitterTuneValuesSashPosition
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
SPICE expressions need quoted versions of the netnames since KiCad allows '-' and '/' in netnames.
void rebuildSignalsList()
Rebuild the list of signals available from the netlist.
bool loadLegacyWorkbook(const wxString &aPath)
int m_splitterCursorsSashPosition
void ToggleSimSidePanel()
void UpdateMeasurement(int aRow)
Update a measurement in the measurements grid.
wxString getNoiseSource() const
std::vector< wxString > SimPlotVectors() const
unsigned int m_plotNumber
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.
int m_splitterLeftRightSashPosition
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.
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)
void updateMeasurementsFromGrid()
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 OnFilterMouseMoved(wxMouseEvent &aEvent) override
void AddMeasurement(const wxString &aCmd)
Add a measurement to the measurements grid.
void onPlotChanging(wxAuiNotebookEvent &event) override
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.
void ToggleDarkModePlots()
SIM_TRACE_TYPE getXAxisType(SIM_TYPE aType) const
Return X axis for a given simulation type.
void OnPlotSettingsChanged()
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)
int m_splitterSignalsSashPosition
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.
int m_splitterPlotAndConsoleSashPosition
SIMULATOR_FRAME * m_simulatorFrame
void ShowChangedLanguage()
void AddTuner(const SCH_SHEET_PATH &aSheetPath, SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
bool IsSimSidePanelShown()
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)
virtual const PARAM * GetTunerParam() const
const SPICE_GENERATOR & SpiceGenerator() const
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)
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 ShowLegend(bool aEnable)
wxString GetLabelY2() const
void SetTraceData(TRACE *aTrace, std::vector< double > &aX, std::vector< double > &aY, int aSweepCount, size_t aSweepSize)
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
SIM_TYPE GetSimType() const
const wxString & GetSimCommand() const
static bool IsPlottable(SIM_TYPE aSimType)
void SetSimOptions(int aOptions)
wxString GetLastSchTextSimCommand() const
void SetSpicePlotName(const wxString &aPlotName)
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.
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.
~SUPPRESS_GRID_CELL_EVENTS()
SUPPRESS_GRID_CELL_EVENTS(SIMULATOR_FRAME_UI *aFrame)
SIMULATOR_FRAME_UI * m_frame
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.
A wrapper for reporting to a wxString object.
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
const wxString & GetMessages() const
A KICAD version of wxTextEntryDialog which supports the various improvements/work-arounds from DIALOG...
wxString GetValue() const
const wxString & GetName() const
Get layer name.
const wxPen & GetPen() const
Get pen set for this layer.
Canvas for plotting mpLayer implementations.
int GetMarginLeft() const
void SetMargins(int top, int right, int bottom, int left)
Set window margins, creating a blank area where some kinds of layers cannot draw.
void UpdateAll()
Refresh display.
int GetMarginRight() const
int GetMarginBottom() const
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.
This file is part of the common library.
Abstract pattern-matching tool and implementations.
@ GRIDTRICKS_FIRST_CLIENT_ID
static const std::string WorkbookFileExtension
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
SIM_TYPE
< Possible simulation types
void sortSignals(std::vector< wxString > &signals)
wxString vectorNameFromSignalId(int aUserDefinedSignalId)
MEASUREMENTS_GIRD_COLUMNS
@ MYID_DELETE_MEASUREMENT
SIM_TRACE_TYPE operator|(SIM_TRACE_TYPE aFirst, SIM_TRACE_TYPE aSecond)
std::vector< FAB_LAYER_COLOR > dummy
wxString UnescapeString(const wxString &aSource)
int measurements_panel_height
SIM_PREFERENCES preferences
Contains preferences pertaining to the simulator.
wxString result
Test unit parsing edge cases and error handling.
Definition of file extensions used in Kicad.