42#include <wx/filedlg.h>
43#include <fmt/format.h>
51#define FORCE_UPDATE_PINS true
54bool equivalent( SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b )
65 std::vector<SCH_FIELD>& aFields ) :
70 m_libraryModelsMgr( &
Prj() ),
71 m_builtinModelsMgr( &
Prj() ),
72 m_prevModel( nullptr ),
74 m_scintillaTricksCode( nullptr ),
75 m_scintillaTricksSubckt( nullptr ),
76 m_firstCategory( nullptr ),
77 m_prevParamGridSelection( nullptr ),
78 m_lastParamGridWidth( 0 )
86 if( !
pin->GetParentSymbol()->HasAlternateBodyStyle() ||
pin->GetBodyStyle() < 2 )
94 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
109 grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
114 grid->DedicateKey( WXK_RETURN );
115 grid->DedicateKey( WXK_NUMPAD_ENTER );
116 grid->DedicateKey( WXK_UP );
117 grid->DedicateKey( WXK_DOWN );
119#if wxCHECK_VERSION( 3, 3, 0 )
120 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_RETURN );
121 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
122 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_NUMPAD_ENTER );
123 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
125 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
126 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
127 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_NUMPAD_ENTER );
128 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
146 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
157 m_pinAssignmentsGrid->PopEventHandler(
true );
159 delete m_scintillaTricksCode;
160 delete m_scintillaTricksSubckt;
167 wxCommandEvent dummyEvent;
170 wxString modelParams;
172 bool storeInValue =
false;
178 [&](
const wxString& aFieldName,
const wxString& aValue )
182 if( field.GetName() == aFieldName )
184 field.SetText( aValue );
189 m_fields.emplace_back( &m_symbol, -1, aFieldName );
190 m_fields.back().SetText( aValue );
195 &deviceType, &modelType, &modelParams, &pinMap ) )
199 if( !modelType.IsEmpty() )
210 m_fields[
VALUE_FIELD ].SetText( wxT(
"${SIM.PARAMS}" ) );
215 if( libraryFilename !=
"" )
218 m_rbLibraryModel->SetValue(
true );
220 if( !loadLibrary( libraryFilename, reporter ) )
223 m_infoBar->ShowMessage( msg );
225 m_libraryPathText->ChangeValue( libraryFilename );
228 m_libraryModelsMgr.CreateModel(
nullptr, m_sortedPartPins, m_fields, reporter );
230 m_modelListBox->Append(
_(
"<unknown>" ) );
231 m_modelListBox->SetSelection( 0 );
236 int modelIdx = m_modelListBox->FindString( modelName );
238 if( modelIdx == wxNOT_FOUND )
240 m_infoBar->ShowMessage( wxString::Format(
_(
"No model named '%s' in library." ),
244 m_modelListBox->SetSelection( 0 );
249 m_modelListBox->SetSelection( modelIdx );
252 m_curModelType = curModel().GetType();
255 if( isIbisLoaded() && ( m_modelListBox->GetSelection() >= 0 ) )
257 int idx = m_modelListBox->GetSelection();
258 auto ibismodel =
dynamic_cast<SIM_MODEL_IBIS*
>( &m_libraryModelsMgr.GetModels()[idx].get() );
262 onModelNameChoice( dummyEvent );
266 for(
const std::pair<std::string, std::string>& strs : ibismodel->GetIbisPins() )
272 ibismodel->ChangePin( *ibisLibrary, strs.first );
273 m_pinCombobox->SetSelection(
static_cast<int>( i ) );
279 if( i <
static_cast<int>( ibismodel->GetIbisPins().size() ) )
281 onPinCombobox( dummyEvent );
283 m_pinModelCombobox->SetStringSelection(
289 ibismodel->SwitchSingleEndedDiff(
true );
290 m_differentialCheckbox->SetValue(
true );
294 ibismodel->SwitchSingleEndedDiff(
false );
295 m_differentialCheckbox->SetValue(
false );
304 m_rbBuiltinModel->SetValue(
true );
313 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
315 if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
318 m_builtinModelsMgr.CreateModel( m_fields, m_sortedPartPins,
false, reporter );
323 + wxT(
"\n\n" ) + msg );
328 m_builtinModelsMgr.CreateModel( type, m_sortedPartPins, reporter );
333 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
334 m_curModelTypeOfDeviceType[deviceTypeT] = type;
338 curModel().SetIsStoredInValue(
true );
340 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
342 onRadioButton( dummyEvent );
343 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
350 m_pinAssignmentsGrid->CommitPendingChanges();
351 m_paramGrid->GetGrid()->CommitChangesFromEditor();
353 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
360 if( m_rbLibraryModel->GetValue() )
362 path = m_libraryPathText->GetValue();
363 wxFileName fn(
path );
365 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith(
".." ) )
366 path = fn.GetFullPath();
368 if( m_modelListBox->GetSelection() >= 0 )
369 name = m_modelListBox->GetStringSelection().ToStdString();
380 &m_libraryModelsMgr.GetModels().at( m_modelListBox->GetSelection() ).get() );
385 std::string modelName = std::string( m_pinModelCombobox->GetValue().c_str() );
386 std::string differential;
388 if( m_pinCombobox->GetSelection() >= 0 )
389 pins = ibismodel->
GetIbisPins().at( m_pinCombobox->GetSelection() ).first;
391 if( ibismodel->
CanDifferential() && m_differentialCheckbox->GetValue() )
400 if( model.
GetType() == SIM_MODEL::TYPE::RAWSPICE )
402 if( m_modelNotebook->GetSelection() == 0 )
403 updateModelCodeTab( &model );
405 wxString code = m_codePreview->GetText().Trim(
true ).Trim(
false );
406 model.
SetParamValue(
"model", std::string( code.ToUTF8() ) );
411 for(
int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
413 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( row, PIN_COLUMN::MODEL );
414 wxString symbolPinName = m_sortedPartPins.at( row )->GetShownNumber();
417 std::string( symbolPinName.ToUTF8() ) );
420 removeOrphanedPinAssignments( &model );
422 curModel().WriteFields( m_fields );
433 m_browseButton->Enable();
436 bool undetermined = !m_rbLibraryModel->GetValue() && !m_rbBuiltinModel->GetValue();
437 bool enableLibCtrls = m_rbLibraryModel->GetValue() || undetermined;
438 bool enableBuiltinCtrls = m_rbBuiltinModel->GetValue() || undetermined;
440 m_pathLabel->Enable( enableLibCtrls );
441 m_libraryPathText->Enable( enableLibCtrls );
442 m_modelNameLabel->Enable( enableLibCtrls );
443 m_modelFilter->Enable( enableLibCtrls && !isIbisLoaded() );
444 m_modelListBox->Enable( enableLibCtrls );
445 m_pinLabel->Enable( enableLibCtrls );
446 m_pinCombobox->Enable( enableLibCtrls );
447 m_differentialCheckbox->Enable( enableLibCtrls );
448 m_pinModelLabel->Enable( enableLibCtrls );
449 m_pinModelCombobox->Enable( enableLibCtrls );
450 m_waveformLabel->Enable( enableLibCtrls );
451 m_waveformChoice->Enable( enableLibCtrls );
453 m_deviceLabel->Enable( enableBuiltinCtrls );
454 m_deviceChoice->Enable( enableBuiltinCtrls );
455 m_deviceSubtypeLabel->Enable( enableBuiltinCtrls );
456 m_deviceSubtypeChoice->Enable( enableBuiltinCtrls );
460 updateIbisWidgets( model );
461 updateBuiltinModelWidgets( model );
462 updateModelParamsTab( model );
463 updateModelCodeTab( model );
464 updatePinAssignments( model,
false );
468 m_modelPanel->Layout();
469 m_pinAssignmentsPanel->Layout();
470 m_parametersPanel->Layout();
471 m_codePanel->Layout();
473 SendSizeEvent( wxSEND_EVENT_POST );
475 m_prevModel = &curModel();
485 m_pinLabel->Show( isIbisLoaded() );
486 m_pinCombobox->Show( isIbisLoaded() );
487 m_pinModelLabel->Show( isIbisLoaded() );
488 m_pinModelCombobox->Show( isIbisLoaded() );
489 m_waveformLabel->Show( isIbisLoaded() );
490 m_waveformChoice->Show( isIbisLoaded() );
492 if( aModel != m_prevModel )
494 m_waveformChoice->Clear();
498 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
499 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
500 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
501 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
511 if( type == aModel->
GetType() )
512 m_waveformChoice->SetSelection( m_waveformChoice->GetCount() - 1 );
518 m_differentialCheckbox->Show( isIbisLoaded() && modelibis && modelibis->
CanDifferential() );
519 m_modelNameLabel->SetLabel( isIbisLoaded() ?
_(
"Component:" ) :
_(
"Model:" ) );
527 if( aModel != m_prevModel )
529 m_deviceChoice->Clear();
530 m_deviceSubtypeChoice->Clear();
532 if( !m_rbLibraryModel->GetValue() )
534 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
542 m_deviceChoice->SetSelection( m_deviceChoice->GetCount() - 1 );
545 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
547 if( type == SIM_MODEL::TYPE::KIBIS_DEVICE
548 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
549 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
550 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS )
563 if( type == aModel->
GetType() )
564 m_deviceSubtypeChoice->SetSelection( m_deviceSubtypeChoice->GetCount() - 1 );
569 m_deviceSubtypeLabel->Show( m_deviceSubtypeChoice->GetCount() > 1 );
570 m_deviceSubtypeChoice->Show( m_deviceSubtypeChoice->GetCount() > 1 );
574 m_modelNotebook->SetSelection( 1 );
576 m_modelNotebook->SetSelection( 0 );
582 m_saveInValueCheckbox->SetLabel( wxString::Format(
_(
"Save parameter '%s (%s)' in Value "
586 m_saveInValueCheckbox->Enable(
true );
590 m_saveInValueCheckbox->SetLabel(
_(
"Save primary parameter in Value field" ) );
591 m_saveInValueCheckbox->SetValue(
false );
592 m_saveInValueCheckbox->Enable(
false );
600 if( aModel != m_prevModel )
605 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
607 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION,
_(
"Parameter" ) );
608 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT,
_(
"Unit" ) );
609 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT,
_(
"Default" ) );
610 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE,
_(
"Type" ) );
612 m_paramGridMgr->ShowHeader();
615 m_paramGrid->Clear();
617 m_firstCategory = m_paramGrid->Append(
new wxPropertyCategory(
"Geometry" ) );
618 m_paramGrid->HideProperty(
"Geometry" );
620 m_paramGrid->Append(
new wxPropertyCategory(
"AC" ) );
621 m_paramGrid->HideProperty(
"AC" );
623 m_paramGrid->Append(
new wxPropertyCategory(
"DC" ) );
624 m_paramGrid->HideProperty(
"DC" );
626 m_paramGrid->Append(
new wxPropertyCategory(
"S-Parameters" ) );
627 m_paramGrid->HideProperty(
"S-Parameters" );
629 m_paramGrid->Append(
new wxPropertyCategory(
"Capacitance" ) );
630 m_paramGrid->HideProperty(
"Capacitance" );
632 m_paramGrid->Append(
new wxPropertyCategory(
"Temperature" ) );
633 m_paramGrid->HideProperty(
"Temperature" );
635 m_paramGrid->Append(
new wxPropertyCategory(
"Noise" ) );
636 m_paramGrid->HideProperty(
"Noise" );
638 m_paramGrid->Append(
new wxPropertyCategory(
"Distributed Quantities" ) );
639 m_paramGrid->HideProperty(
"Distributed Quantities" );
641 m_paramGrid->Append(
new wxPropertyCategory(
"Waveform" ) );
642 m_paramGrid->HideProperty(
"Waveform" );
644 m_paramGrid->Append(
new wxPropertyCategory(
"Limiting Values" ) );
645 m_paramGrid->HideProperty(
"Limiting Values" );
647 m_paramGrid->Append(
new wxPropertyCategory(
"Advanced" ) );
648 m_paramGrid->HideProperty(
"Advanced" );
650 m_paramGrid->Append(
new wxPropertyCategory(
"Flags" ) );
651 m_paramGrid->HideProperty(
"Flags" );
653 m_paramGrid->CollapseAll();
656 addParamPropertyIfRelevant( aModel, i );
658 m_paramGrid->CollapseAll();
659 m_paramGrid->Expand(
"AC" );
660 m_paramGrid->Expand(
"Waveform" );
663 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(),
true );
667 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
669 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
670 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
672 for(
int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
674 ( *it )->GetCell( col ).SetBgCol( bgCol );
675 ( *it )->GetCell( col ).SetFgCol( fgCol );
689 ( *it )->SetValueFromString( param.
value );
703 item.
modelName = m_modelListBox->GetStringSelection();
705 if( m_rbBuiltinModel->GetValue() || item.
modelName ==
"" )
710 m_codePreview->SetText(
text );
711 m_codePreview->SelectNone();
718 if( m_pinAssignmentsGrid->GetNumberRows() == 0 )
720 m_pinAssignmentsGrid->AppendRows(
static_cast<int>( m_sortedPartPins.size() ) );
722 for(
int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
724 wxString symbolPinString = getSymbolPinString( ii );
726 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
727 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
730 aForceUpdatePins =
true;
733 if( aForceUpdatePins )
736 for(
int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
737 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL,
_(
"Not Connected" ) );
740 for(
int modelPinIndex = 0; modelPinIndex < aModel->
GetPinCount(); ++modelPinIndex )
744 if( symbolPinNumber ==
"" )
747 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
749 if( symbolPinRow == -1 )
752 wxString modelPinString = getModelPinString( aModel, modelPinIndex );
753 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
757 for(
int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
760 std::vector<BITMAPS> modelPinIcons;
761 wxArrayString modelPinChoices;
763 for(
int jj = 0; jj < aModel->
GetPinCount(); ++jj )
770 modelPinChoices.Add( getModelPinString( aModel, jj ) );
774 modelPinChoices.Add(
_(
"Not Connected" ) );
778 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
785 if( aModel->
GetType() == SIM_MODEL::TYPE::SUBCKT )
789 m_subckt->SetEditable(
false );
793 m_subcktLabel->Show(
false );
794 m_subckt->Show(
false );
814 if( m_prevLibrary == aLibraryPath && !aForceReload )
817 m_libraryModelsMgr.SetForceFullParse();
818 m_libraryModelsMgr.SetLibrary( aLibraryPath, aReporter );
825 for(
const auto& [baseModelName, baseModel] :
library()->GetModels() )
827 if( baseModelName == modelName )
828 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, aReporter );
830 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, aReporter );
833 m_rbLibraryModel->SetValue(
true );
834 m_libraryPathText->ChangeValue( aLibraryPath );
836 wxArrayString modelNames;
838 for(
const auto& [
name, model] :
library()->GetModels() )
839 modelNames.Add(
name );
843 m_modelListBox->Clear();
844 m_modelListBox->Append( modelNames );
848 wxArrayString emptyArray;
849 m_pinModelCombobox->Set( emptyArray );
850 m_pinCombobox->Set( emptyArray );
851 m_pinModelCombobox->SetSelection( -1 );
852 m_pinCombobox->SetSelection( -1 );
855 m_modelListBox->SetStringSelection( modelName );
857 if( m_modelListBox->GetSelection() < 0 && m_modelListBox->GetCount() > 0 )
858 m_modelListBox->SetSelection( 0 );
860 m_curModelType = curModel().GetType();
862 m_prevLibrary = aLibraryPath;
876 m_paramGrid->HideProperty(
"AC",
false );
877 m_paramGrid->AppendIn(
"AC", newParamProperty( aModel, aParamIndex ) );
881 m_paramGrid->HideProperty(
"DC",
false );
882 m_paramGrid->AppendIn(
"DC", newParamProperty( aModel, aParamIndex ) );
885 case CATEGORY::S_PARAM:
886 m_paramGrid->HideProperty(
"S-Parameters",
false );
887 m_paramGrid->AppendIn(
"S-Parameters", newParamProperty( aModel, aParamIndex ) );
890 case CATEGORY::CAPACITANCE:
891 m_paramGrid->HideProperty(
"Capacitance",
false );
892 m_paramGrid->AppendIn(
"Capacitance", newParamProperty( aModel, aParamIndex ) );
895 case CATEGORY::TEMPERATURE:
896 m_paramGrid->HideProperty(
"Temperature",
false );
897 m_paramGrid->AppendIn(
"Temperature", newParamProperty( aModel, aParamIndex ) );
900 case CATEGORY::NOISE:
901 m_paramGrid->HideProperty(
"Noise",
false );
902 m_paramGrid->AppendIn(
"Noise", newParamProperty( aModel, aParamIndex ) );
905 case CATEGORY::DISTRIBUTED_QUANTITIES:
906 m_paramGrid->HideProperty(
"Distributed Quantities",
false );
907 m_paramGrid->AppendIn(
"Distributed Quantities", newParamProperty( aModel, aParamIndex ) );
910 case CATEGORY::WAVEFORM:
911 m_paramGrid->HideProperty(
"Waveform",
false );
912 m_paramGrid->AppendIn(
"Waveform", newParamProperty( aModel, aParamIndex ) );
915 case CATEGORY::GEOMETRY:
916 m_paramGrid->HideProperty(
"Geometry",
false );
917 m_paramGrid->AppendIn(
"Geometry", newParamProperty( aModel, aParamIndex ) );
920 case CATEGORY::LIMITING_VALUES:
921 m_paramGrid->HideProperty(
"Limiting Values",
false );
922 m_paramGrid->AppendIn(
"Limiting Values", newParamProperty( aModel, aParamIndex ) );
925 case CATEGORY::ADVANCED:
926 m_paramGrid->HideProperty(
"Advanced",
false );
927 m_paramGrid->AppendIn(
"Advanced", newParamProperty( aModel, aParamIndex ) );
930 case CATEGORY::FLAGS:
931 m_paramGrid->HideProperty(
"Flags",
false );
932 m_paramGrid->AppendIn(
"Flags", newParamProperty( aModel, aParamIndex ) );
936 m_paramGrid->Insert( m_firstCategory, newParamProperty( aModel, aParamIndex ) );
939 case CATEGORY::INITIAL_CONDITIONS:
940 case CATEGORY::SUPERFLUOUS:
950 wxString paramDescription;
953 paramDescription = wxString::Format(
"%s", param.
info.
name );
957 wxPGProperty* prop =
nullptr;
964 prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX,
true );
986 wxArrayString inductors;
998 if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::L )
999 inductors.push_back( item.refName );
1003 [](
const wxString& a,
const wxString& b ) ->
int
1009 if( inductors.empty() )
1017 aParamIndex, inductors );
1027 wxArrayString values;
1030 values.Add(
string );
1038 prop =
new wxStringProperty( paramDescription, param.
info.
name );
1042 prop->SetAttribute( wxPG_ATTR_UNITS, wxString::FromUTF8( param.
info.
unit.c_str() ) );
1062 prop->SetCell( PARAM_COLUMN::TYPE, typeStr );
1068template <
typename T>
1071 for(
int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
1075 if(
pin->GetNumber() == aSymbolPinNumber )
1083template <
typename T>
1086 if( m_rbLibraryModel->GetValue() )
1088 if(
library() && m_modelListBox->GetSelection() >= 0 )
1089 return *
library()->FindModel( m_modelListBox->GetStringSelection().ToStdString() );
1093 if(
static_cast<int>( m_curModelType ) <
static_cast<int>( m_builtinModelsMgr.GetModels().size() ) )
1094 return m_builtinModelsMgr.GetModels().at(
static_cast<int>( m_curModelType ) );
1097 return m_builtinModelsMgr.GetModels().at(
static_cast<int>( SIM_MODEL::TYPE::NONE ) );
1101template <
typename T>
1104 if( m_libraryModelsMgr.GetLibraries().size() == 1 )
1105 return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
1111template <
typename T>
1114 SCH_PIN*
pin = m_sortedPartPins.at( symbolPinIndex );
1120 pinNumber =
pin->GetShownNumber();
1121 pinName =
pin->GetShownName();
1124 if( !pinName.IsEmpty() && pinName != pinNumber )
1125 pinNumber += wxString::Format( wxT(
" (%s)" ), pinName );
1131template <
typename T>
1138 wxString modelPinNumber = wxString::Format(
"%d", aModelPinIndex + 1 );
1140 if( !modelPinName.IsEmpty() && modelPinName != modelPinNumber )
1141 modelPinNumber += wxString::Format( wxT(
" (%s)" ), modelPinName );
1143 return modelPinNumber;
1147template <
typename T>
1150 if( aModelPinString ==
"Not Connected" )
1153 int length = aModelPinString.Find(
" " );
1155 if( length == wxNOT_FOUND )
1156 length =
static_cast<int>( aModelPinString.Length() );
1159 aModelPinString.Mid( 0, length ).ToCLong( &result );
1161 return static_cast<int>( result - 1 );
1165template <
typename T>
1168 m_prevModel =
nullptr;
1173template <
typename T>
1176 m_rbLibraryModel->SetValue(
true );
1180template <
typename T>
1183 m_rbLibraryModel->SetValue(
true );
1187 wxString
path = m_libraryPathText->GetValue();
1189 if( loadLibrary(
path, reporter,
true ) ||
path.IsEmpty() )
1192 m_infoBar->ShowMessage( msg );
1198template <
typename T>
1208 wxCommandEvent
dummy;
1209 onLibraryPathTextEnter(
dummy );
1216template <
typename T>
1219 static wxString s_mruPath;
1222 wxFileDialog dlg(
this,
_(
"Browse Models" ),
path );
1224 if( dlg.ShowModal() == wxID_CANCEL )
1227 m_rbLibraryModel->SetValue(
true );
1229 path = dlg.GetPath();
1230 wxFileName fn(
path );
1232 s_mruPath = fn.GetPath();
1234 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS(
".." ) ) )
1235 path = fn.GetFullPath();
1240 if( loadLibrary(
path, reporter,
true ) )
1243 m_infoBar->ShowMessage( msg );
1249template <
typename T>
1252 int sel = m_modelListBox->GetSelection();
1254 switch( aKeyStroke.GetKeyCode() )
1257 if( sel == wxNOT_FOUND )
1258 sel = m_modelListBox->GetCount() - 1;
1265 if( sel == wxNOT_FOUND )
1273 wxPostEvent(
this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
1281 if( sel >= 0 && sel < (
int) m_modelListBox->GetCount() )
1282 m_modelListBox->SetSelection( sel );
1286template <
typename T>
1289 wxArrayString modelNames;
1290 wxString current = m_modelListBox->GetStringSelection();
1291 wxString
filter = wxT(
"*" ) + m_modelFilter->GetValue() + wxT(
"*" );
1293 for(
const auto& [
name, model] :
library()->GetModels() )
1295 wxString wx_name(
name );
1297 if( wx_name.Matches(
filter ) )
1298 modelNames.Add( wx_name );
1303 m_modelListBox->Clear();
1304 m_modelListBox->Append( modelNames );
1306 if( !m_modelListBox->SetStringSelection( current ) )
1307 m_modelListBox->SetSelection( 0 );
1311template <
typename T>
1314 if( isIbisLoaded() )
1316 wxArrayString pinLabels;
1319 wxCHECK2( modelkibis,
return );
1321 for( std::pair<wxString, wxString> strs : modelkibis->
GetIbisPins() )
1322 pinLabels.Add( strs.first + wxT(
" - " ) + strs.second );
1324 m_pinCombobox->Set( pinLabels );
1326 wxArrayString emptyArray;
1327 m_pinModelCombobox->Set( emptyArray );
1330 m_rbLibraryModel->SetValue(
true );
1334 wxArrayString lines = wxSplit( fallback->GetSpiceCode(),
'\n' );
1337 for(
const wxString& line : lines )
1339 if( !line.StartsWith(
'*' ) )
1341 if( !code.IsEmpty() )
1348 m_infoBar->ShowMessage( wxString::Format(
_(
"Failed to parse:\n\n"
1350 "Using generic SPICE model." ),
1362template <
typename T>
1365 wxArrayString modelLabels;
1369 std::vector<std::pair<std::string, std::string>> strs = ibisModel.
GetIbisPins();
1370 std::string pinNumber = strs.at( m_pinCombobox->GetSelection() ).first;
1374 ibisModel.
ChangePin( *ibisLibrary, pinNumber );
1379 modelLabels.Add( modelName );
1381 m_pinModelCombobox->Set( modelLabels );
1383 if( m_pinModelCombobox->GetCount() == 1 )
1384 m_pinModelCombobox->SetSelection( 0 );
1386 m_pinModelCombobox->SetSelection( -1 );
1392template <
typename T>
1395 m_pinCombobox->SetSelection( m_pinCombobox->FindString( m_pinCombobox->GetValue() ) );
1397 onPinModelCombobox( aEvent );
1401template <
typename T>
1408template <
typename T>
1411 m_pinModelCombobox->SetSelection( m_pinModelCombobox->FindString( m_pinModelCombobox->GetValue() ) );
1414template <
typename T>
1419 bool diff = m_differentialCheckbox->GetValue() && modelibis->CanDifferential();
1420 modelibis->SwitchSingleEndedDiff( diff );
1427template <
typename T>
1430 m_rbBuiltinModel->SetValue(
true );
1432 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
1436 m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
1445template <
typename T>
1448 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1449 wxString typeDescription = m_waveformChoice->GetStringSelection();
1451 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
1452 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
1453 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
1454 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
1459 int idx = m_modelListBox->GetSelection();
1461 auto& baseModel =
static_cast<SIM_MODEL_IBIS&
>( m_libraryModelsMgr.GetModels()[idx].get() );
1463 m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_IBIS>( type, baseModel ) );
1467 m_libraryModelsMgr.GetModels()[idx].get().
ReadDataFields( &m_fields, m_sortedPartPins );
1474 m_curModelType = type;
1479 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1484template <
typename T>
1487 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1488 wxString typeDescription = m_deviceSubtypeChoice->GetStringSelection();
1490 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1495 m_curModelType = type;
1500 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1505template <
typename T>
1508 updateModelCodeTab( &curModel() );
1512template <
typename T>
1515 int symbolPinIndex = aEvent.GetRow();
1516 wxString oldModelPinName = aEvent.GetString();
1517 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
1519 int oldModelPinIndex = getModelPinIndex( oldModelPinName );
1520 int modelPinIndex = getModelPinIndex( modelPinName );
1523 curModel().AssignSymbolPinNumberToModelPin( oldModelPinIndex,
"" );
1527 SCH_PIN* symbolPin = m_sortedPartPins.at( symbolPinIndex );
1529 curModel().AssignSymbolPinNumberToModelPin( modelPinIndex, symbolPin->
GetShownNumber() );
1538template <
typename T>
1541 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
1544 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::MODEL, gridWidth / 2 );
1545 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::SYMBOL, gridWidth / 2 );
1551template <
typename T>
1557 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1558 wxPGProperty* selected =
grid->GetSelection();
1561 selected =
grid->wxPropertyGridInterface::GetFirst();
1563#if wxCHECK_VERSION( 3, 3, 0 )
1565 grid->DoSelectProperty( selected, wxPGSelectPropertyFlags::Focus );
1568 grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
1575template <
typename T>
1578 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1581 if(
grid->GetSelection() &&
grid->GetSelection()->IsCategory() )
1583 wxPGProperty* selection =
grid->GetSelection();
1588 wxPropertyGridIterator it =
grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
1591 wxKeyEvent* keyEvent =
new wxKeyEvent( wxEVT_KEY_DOWN );
1593 if( *it == m_prevParamGridSelection )
1595 if( !selection->IsExpanded() )
1597 grid->Expand( selection );
1598 keyEvent->m_keyCode = WXK_DOWN;
1599 wxQueueEvent(
grid, keyEvent );
1607 keyEvent->m_keyCode = WXK_UP;
1608 wxQueueEvent(
grid, keyEvent );
1613 if( !selection->IsExpanded() )
1614 grid->Expand( selection );
1616 keyEvent->m_keyCode = WXK_DOWN;
1617 wxQueueEvent(
grid, keyEvent );
1620 m_prevParamGridSelection =
grid->GetSelection();
1624 wxWindow* editorControl =
grid->GetEditorControl();
1626 if( !editorControl )
1628 m_prevParamGridSelection =
grid->GetSelection();
1633 editorControl->SetFocus();
1634 m_prevParamGridSelection =
grid->GetSelection();
1638template <
typename T>
1649 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1650 wxTextCtrl* ctrl =
grid->GetEditorTextCtrl();
1654 wxRect ctrlRect = ctrl->GetScreenRect();
1655 wxRect gridRect =
grid->GetScreenRect();
1657 if( ctrlRect.GetTop() < gridRect.GetTop() || ctrlRect.GetBottom() > gridRect.GetBottom() )
1658 grid->ClearSelection();
1664template <
typename T>
1667 wxPropertyGrid*
grid = m_paramGridMgr->GetGrid();
1671 if( aWidth != m_lastParamGridWidth || aForce )
1673 m_lastParamGridWidth = aWidth;
1677 std::vector<int> colWidths;
1679 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1681 if( ii == PARAM_COLUMN::DESCRIPTION )
1682 colWidths.push_back(
grid->GetState()->GetColumnWidth( ii ) + margin + indent );
1683 else if( ii == PARAM_COLUMN::VALUE )
1684 colWidths.push_back( std::max( 72,
grid->GetState()->GetColumnWidth( ii ) ) + margin );
1686 colWidths.push_back( 60 + margin );
1688 aWidth -= colWidths[ ii ];
1691 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1692 grid->SetColumnProportion( ii, colWidths[ ii ] );
1694 grid->ResetColumnSizes();
1695 grid->RefreshEditor();
1700template <
typename T>
1703 adjustParamGridColumns( event.GetSize().GetX(),
false );
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_SIM_MODEL_BASE.
wxStaticText * m_subcktLabel
wxPropertyGridManager * m_paramGridMgr
wxChoice * m_deviceSubtypeChoice
wxChoice * m_deviceChoice
wxChoice * m_waveformChoice
WX_GRID * m_pinAssignmentsGrid
STD_BITMAP_BUTTON * m_browseButton
wxStyledTextCtrl * m_subckt
wxPropertyGridPage * m_paramGrid
wxStyledTextCtrl * m_codePreview
void onTypeChoice(wxCommandEvent &aEvent) override
void onLibraryPathTextKillFocus(wxFocusEvent &aEvent) override
wxString getSymbolPinString(int aSymbolPinNumber) const
void updateBuiltinModelWidgets(SIM_MODEL *aModel)
void onPinAssignmentsGridCellChange(wxGridEvent &aEvent) override
void onFilterCharHook(wxKeyEvent &aKeyStroke) override
int findSymbolPinRow(const wxString &aSymbolPinNumber) const
void onModelNameChoice(wxCommandEvent &aEvent) override
void onRadioButton(wxCommandEvent &aEvent) override
SCINTILLA_TRICKS * m_scintillaTricksSubckt
bool loadLibrary(const wxString &aLibraryPath, REPORTER &aReporter, bool aForceReload=false)
int getModelPinIndex(const wxString &aModelPinString) const
void onModelFilter(wxCommandEvent &aEvent) override
void onLibraryPathText(wxCommandEvent &aEvent) override
void onDifferentialCheckbox(wxCommandEvent &event) override
void onParamGridSelectionChange(wxPropertyGridEvent &aEvent)
void removeOrphanedPinAssignments(SIM_MODEL *aModel)
void adjustParamGridColumns(int aWidth, bool aForce)
std::vector< SCH_PIN * > m_sortedPartPins
wxPGProperty * newParamProperty(SIM_MODEL *aModel, int aParamIndex) const
void onPinModelCombobox(wxCommandEvent &event) override
const SIM_LIBRARY * library() const
SIM_MODEL & curModel() const
void onBrowseButtonClick(wxCommandEvent &aEvent) override
void onPinComboboxTextEnter(wxCommandEvent &event) override
void onPinCombobox(wxCommandEvent &event) override
SCINTILLA_TRICKS * m_scintillaTricksCode
void updatePinAssignments(SIM_MODEL *aModel, bool aForceUpdatePins)
void onUpdateUI(wxUpdateUIEvent &aEvent)
DIALOG_SIM_MODEL(wxWindow *aParent, EDA_BASE_FRAME *aFrame, T &aSymbol, std::vector< SCH_FIELD > &aFields)
wxString getModelPinString(SIM_MODEL *aModel, int aModelPinIndex) const
void onPinAssignmentsGridSize(wxSizeEvent &aEvent) override
void updateIbisWidgets(SIM_MODEL *aModel)
void onParamGridSetFocus(wxFocusEvent &aEvent)
void updateModelParamsTab(SIM_MODEL *aModel)
bool TransferDataFromWindow() override
void updateModelCodeTab(SIM_MODEL *aModel)
void onSizeParamGrid(wxSizeEvent &event) override
void onPageChanging(wxNotebookEvent &event) override
void onWaveformChoice(wxCommandEvent &aEvent) override
void onPinModelComboboxTextEnter(wxCommandEvent &event) override
void onLibraryPathTextEnter(wxCommandEvent &aEvent) override
void onDeviceTypeChoice(wxCommandEvent &aEvent) override
bool TransferDataToWindow() override
void addParamPropertyIfRelevant(SIM_MODEL *aModel, int aParamIndex)
The base frame for deriving all KiCad main window classes.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
virtual bool ReadSchematicAndLibraries(unsigned aNetlistOptions, REPORTER &aReporter)
Process the schematic and Spice libraries to create net mapping and a list of SPICE_ITEMs.
const std::list< SPICE_ITEM > & GetItems() const
Return the list of items representing schematic symbols in the Spice world.
A singleton reporter that reports to nowhere.
virtual const wxString GetProjectPath() const
Return the full path of the project.
A pure virtual class used to derive REPORTER objects from.
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
Schematic editor (Eeschema) main window.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
wxString GetShownNumber() const
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
static constexpr auto MODEL_FIELD
static constexpr auto PIN_FIELD
static constexpr auto DIFF_FIELD
bool isPinDiff(const std::string &aComp, const std::string &aPinNumber) const
static constexpr auto LIBRARY_FIELD
static constexpr auto NAME_FIELD
std::vector< std::pair< std::string, std::string > > GetIbisPins() const
bool ChangePin(const SIM_LIBRARY_IBIS &aLib, std::string aPinNumber)
update the list of available models based on the pin number.
bool CanDifferential() const
std::vector< std::string > GetIbisModels() const
std::string GetComponentName() const
std::string GetSpiceCode() const
static TYPE ReadTypeFromFields(const std::vector< SCH_FIELD > &aFields, REPORTER &aReporter)
static INFO TypeInfo(TYPE aType)
static void SetFieldValue(std::vector< SCH_FIELD > &aFields, const wxString &aFieldName, const std::string &aValue)
void ReadDataFields(const std::vector< SCH_FIELD > *aFields, const std::vector< SCH_PIN * > &aPins)
const SPICE_GENERATOR & SpiceGenerator() const
virtual const PARAM & GetParam(unsigned aParamIndex) const
static bool InferSimModel(T &aSymbol, std::vector< SCH_FIELD > *aFields, bool aResolve, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
static std::string GetFieldValue(const std::vector< SCH_FIELD > *aFields, const wxString &aFieldName, bool aResolve=true)
int GetParamCount() const
void AssignSymbolPinNumberToModelPin(int aPinIndex, const wxString &aSymbolPinNumber)
DEVICE_INFO GetDeviceInfo() const
DEVICE_T GetDeviceType() const
static DEVICE_INFO DeviceInfo(DEVICE_T aDeviceType)
virtual bool HasAutofill() const
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
const SIM_MODEL_PIN & GetPin(unsigned aIndex) const
void SetIsStoredInValue(bool aIsStoredInValue)
virtual bool HasPrimaryValue() const
const SIM_MODEL::PARAM & GetParam() const
Special netlist exporter flavor that allows one to override simulation commands.
virtual std::string Preview(const SPICE_ITEM &aItem) const
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
A wrapper for reporting to a wxString object.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static bool empty(const wxTextEntryBase *aCtrl)
bool equivalent(SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b)
#define FORCE_UPDATE_PINS
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
@ NONE
No connection to this item.
#define SIM_REFERENCE_FIELD
#define SIM_DEVICE_SUBTYPE_FIELD
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
std::vector< std::string > enumValues
static constexpr auto NOT_CONNECTED
const std::string modelPinName
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".