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 )
85 if( !
pin->GetParentSymbol()->HasAlternateBodyStyle() ||
pin->GetBodyStyle() < 2 )
93 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
108 grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
113 grid->DedicateKey( WXK_RETURN );
114 grid->DedicateKey( WXK_NUMPAD_ENTER );
115 grid->DedicateKey( WXK_UP );
116 grid->DedicateKey( WXK_DOWN );
118#if wxCHECK_VERSION( 3, 3, 0 )
119 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_RETURN );
120 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
121 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_NUMPAD_ENTER );
122 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
124 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
125 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
126 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_NUMPAD_ENTER );
127 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
145 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
156 m_pinAssignmentsGrid->PopEventHandler(
true );
158 delete m_scintillaTricksCode;
159 delete m_scintillaTricksSubckt;
166 wxCommandEvent dummyEvent;
169 wxString modelParams;
171 bool storeInValue =
false;
177 [&](
const wxString& aFieldName,
const wxString& aValue )
181 if( field.GetName() == aFieldName )
183 field.SetText( aValue );
188 m_fields.emplace_back( &m_symbol, -1, aFieldName );
189 m_fields.back().SetText( aValue );
194 &deviceType, &modelType, &modelParams, &pinMap ) )
198 if( !modelType.IsEmpty() )
209 m_fields[
VALUE_FIELD ].SetText( wxT(
"${SIM.PARAMS}" ) );
214 if( libraryFilename !=
"" )
217 m_rbLibraryModel->SetValue(
true );
219 if( !loadLibrary( libraryFilename, reporter ) )
222 m_infoBar->ShowMessage( msg );
224 m_libraryPathText->ChangeValue( libraryFilename );
227 m_libraryModelsMgr.CreateModel(
nullptr, m_sortedPartPins, m_fields, reporter );
229 m_modelNameChoice->Append(
_(
"<unknown>" ) );
230 m_modelNameChoice->SetSelection( 0 );
235 int modelIdx = m_modelNameChoice->FindString( modelName );
237 if( modelIdx == wxNOT_FOUND )
239 m_infoBar->ShowMessage( wxString::Format(
_(
"No model named '%s' in library." ),
243 m_modelNameChoice->SetSelection( 0 );
248 m_modelNameChoice->SetSelection( modelIdx );
251 m_curModelType = curModel().GetType();
254 if( isIbisLoaded() && ( m_modelNameChoice->GetSelection() >= 0 ) )
256 int idx = m_modelNameChoice->GetSelection();
257 auto ibismodel =
dynamic_cast<SIM_MODEL_IBIS*
>( &m_libraryModelsMgr.GetModels()[idx].get() );
261 onModelNameChoice( dummyEvent );
265 for(
const std::pair<std::string, std::string>& strs : ibismodel->GetIbisPins() )
271 ibismodel->ChangePin( *ibisLibrary, strs.first );
272 m_pinCombobox->SetSelection(
static_cast<int>( i ) );
278 if( i <
static_cast<int>( ibismodel->GetIbisPins().size() ) )
280 onPinCombobox( dummyEvent );
282 m_pinModelCombobox->SetStringSelection(
288 ibismodel->SwitchSingleEndedDiff(
true );
289 m_differentialCheckbox->SetValue(
true );
293 ibismodel->SwitchSingleEndedDiff(
false );
294 m_differentialCheckbox->SetValue(
false );
303 m_rbBuiltinModel->SetValue(
true );
312 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
314 if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
317 m_builtinModelsMgr.CreateModel( m_fields, m_sortedPartPins,
false, reporter );
322 + wxT(
"\n\n" ) + msg );
327 m_builtinModelsMgr.CreateModel( type, m_sortedPartPins, reporter );
332 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
333 m_curModelTypeOfDeviceType[deviceTypeT] = type;
337 curModel().SetIsStoredInValue(
true );
339 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
341 onRadioButton( dummyEvent );
342 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
349 m_pinAssignmentsGrid->CommitPendingChanges();
350 m_paramGrid->GetGrid()->CommitChangesFromEditor();
352 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
359 if( m_rbLibraryModel->GetValue() )
361 path = m_libraryPathText->GetValue();
362 wxFileName fn(
path );
364 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith(
".." ) )
365 path = fn.GetFullPath();
367 if( !m_modelNameChoice->IsEmpty() )
368 name = m_modelNameChoice->GetStringSelection().ToStdString();
379 &m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get() );
384 std::string modelName = std::string( m_pinModelCombobox->GetValue().c_str() );
385 std::string differential;
387 if( m_pinCombobox->GetSelection() >= 0 )
388 pins = ibismodel->
GetIbisPins().at( m_pinCombobox->GetSelection() ).first;
390 if( ibismodel->
CanDifferential() && m_differentialCheckbox->GetValue() )
399 if( model.
GetType() == SIM_MODEL::TYPE::RAWSPICE )
401 if( m_modelNotebook->GetSelection() == 0 )
402 updateModelCodeTab( &model );
404 wxString code = m_codePreview->GetText().Trim(
true ).Trim(
false );
405 model.
SetParamValue(
"model", std::string( code.ToUTF8() ) );
410 for(
int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
412 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( row, PIN_COLUMN::MODEL );
413 wxString symbolPinName = m_sortedPartPins.at( row )->GetShownNumber();
416 std::string( symbolPinName.ToUTF8() ) );
419 removeOrphanedPinAssignments( &model );
421 curModel().WriteFields( m_fields );
432 m_browseButton->Enable();
435 bool undetermined = !m_rbLibraryModel->GetValue() && !m_rbBuiltinModel->GetValue();
436 bool enableLibCtrls = m_rbLibraryModel->GetValue() || undetermined;
437 bool enableBuiltinCtrls = m_rbBuiltinModel->GetValue() || undetermined;
439 m_pathLabel->Enable( enableLibCtrls );
440 m_libraryPathText->Enable( enableLibCtrls );
441 m_modelNameLabel->Enable( enableLibCtrls );
442 m_modelNameChoice->Enable( enableLibCtrls );
443 m_pinLabel->Enable( enableLibCtrls );
444 m_pinCombobox->Enable( enableLibCtrls );
445 m_differentialCheckbox->Enable( enableLibCtrls );
446 m_pinModelLabel->Enable( enableLibCtrls );
447 m_pinModelCombobox->Enable( enableLibCtrls );
448 m_waveformLabel->Enable( enableLibCtrls );
449 m_waveformChoice->Enable( enableLibCtrls );
451 m_deviceLabel->Enable( enableBuiltinCtrls );
452 m_deviceChoice->Enable( enableBuiltinCtrls );
453 m_deviceSubtypeLabel->Enable( enableBuiltinCtrls );
454 m_deviceSubtypeChoice->Enable( enableBuiltinCtrls );
458 updateIbisWidgets( model );
459 updateBuiltinModelWidgets( model );
460 updateModelParamsTab( model );
461 updateModelCodeTab( model );
462 updatePinAssignments( model,
false );
466 m_modelPanel->Layout();
467 m_pinAssignmentsPanel->Layout();
468 m_parametersPanel->Layout();
469 m_codePanel->Layout();
471 SendSizeEvent( wxSEND_EVENT_POST );
473 m_prevModel = &curModel();
483 m_pinLabel->Show( isIbisLoaded() );
484 m_pinCombobox->Show( isIbisLoaded() );
485 m_pinModelLabel->Show( isIbisLoaded() );
486 m_pinModelCombobox->Show( isIbisLoaded() );
487 m_waveformLabel->Show( isIbisLoaded() );
488 m_waveformChoice->Show( isIbisLoaded() );
490 if( aModel != m_prevModel )
492 m_waveformChoice->Clear();
496 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
497 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
498 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
499 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
509 if( type == aModel->
GetType() )
510 m_waveformChoice->SetSelection( m_waveformChoice->GetCount() - 1 );
516 m_differentialCheckbox->Show( isIbisLoaded() && modelibis && modelibis->
CanDifferential() );
517 m_modelNameLabel->SetLabel( isIbisLoaded() ?
_(
"Component:" ) :
_(
"Model:" ) );
525 if( aModel != m_prevModel )
527 m_deviceChoice->Clear();
528 m_deviceSubtypeChoice->Clear();
530 if( !m_rbLibraryModel->GetValue() )
532 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
540 m_deviceChoice->SetSelection( m_deviceChoice->GetCount() - 1 );
543 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
545 if( type == SIM_MODEL::TYPE::KIBIS_DEVICE
546 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
547 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
548 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS )
561 if( type == aModel->
GetType() )
562 m_deviceSubtypeChoice->SetSelection( m_deviceSubtypeChoice->GetCount() - 1 );
567 m_deviceSubtypeLabel->Show( m_deviceSubtypeChoice->GetCount() > 1 );
568 m_deviceSubtypeChoice->Show( m_deviceSubtypeChoice->GetCount() > 1 );
572 m_modelNotebook->SetSelection( 1 );
574 m_modelNotebook->SetSelection( 0 );
580 m_saveInValueCheckbox->SetLabel( wxString::Format(
_(
"Save parameter '%s (%s)' in Value "
584 m_saveInValueCheckbox->Enable(
true );
588 m_saveInValueCheckbox->SetLabel(
_(
"Save primary parameter in Value field" ) );
589 m_saveInValueCheckbox->SetValue(
false );
590 m_saveInValueCheckbox->Enable(
false );
598 if( aModel != m_prevModel )
603 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
605 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION,
_(
"Parameter" ) );
606 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT,
_(
"Unit" ) );
607 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT,
_(
"Default" ) );
608 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE,
_(
"Type" ) );
610 m_paramGridMgr->ShowHeader();
613 m_paramGrid->Clear();
615 m_firstCategory = m_paramGrid->Append(
new wxPropertyCategory(
"Geometry" ) );
616 m_paramGrid->HideProperty(
"Geometry" );
618 m_paramGrid->Append(
new wxPropertyCategory(
"AC" ) );
619 m_paramGrid->HideProperty(
"AC" );
621 m_paramGrid->Append(
new wxPropertyCategory(
"DC" ) );
622 m_paramGrid->HideProperty(
"DC" );
624 m_paramGrid->Append(
new wxPropertyCategory(
"S-Parameters" ) );
625 m_paramGrid->HideProperty(
"S-Parameters" );
627 m_paramGrid->Append(
new wxPropertyCategory(
"Capacitance" ) );
628 m_paramGrid->HideProperty(
"Capacitance" );
630 m_paramGrid->Append(
new wxPropertyCategory(
"Temperature" ) );
631 m_paramGrid->HideProperty(
"Temperature" );
633 m_paramGrid->Append(
new wxPropertyCategory(
"Noise" ) );
634 m_paramGrid->HideProperty(
"Noise" );
636 m_paramGrid->Append(
new wxPropertyCategory(
"Distributed Quantities" ) );
637 m_paramGrid->HideProperty(
"Distributed Quantities" );
639 m_paramGrid->Append(
new wxPropertyCategory(
"Waveform" ) );
640 m_paramGrid->HideProperty(
"Waveform" );
642 m_paramGrid->Append(
new wxPropertyCategory(
"Limiting Values" ) );
643 m_paramGrid->HideProperty(
"Limiting Values" );
645 m_paramGrid->Append(
new wxPropertyCategory(
"Advanced" ) );
646 m_paramGrid->HideProperty(
"Advanced" );
648 m_paramGrid->Append(
new wxPropertyCategory(
"Flags" ) );
649 m_paramGrid->HideProperty(
"Flags" );
651 m_paramGrid->CollapseAll();
654 addParamPropertyIfRelevant( aModel, i );
656 m_paramGrid->CollapseAll();
657 m_paramGrid->Expand(
"AC" );
658 m_paramGrid->Expand(
"Waveform" );
661 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(),
true );
665 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
667 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
668 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
670 for(
int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
672 ( *it )->GetCell( col ).SetBgCol( bgCol );
673 ( *it )->GetCell( col ).SetFgCol( fgCol );
687 ( *it )->SetValueFromString( param.
value );
701 item.
modelName = m_modelNameChoice->GetStringSelection();
703 if( m_rbBuiltinModel->GetValue() || item.
modelName ==
"" )
708 m_codePreview->SetText(
text );
709 m_codePreview->SelectNone();
716 if( m_pinAssignmentsGrid->GetNumberRows() == 0 )
718 m_pinAssignmentsGrid->AppendRows(
static_cast<int>( m_sortedPartPins.size() ) );
720 for(
int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
722 wxString symbolPinString = getSymbolPinString( ii );
724 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
725 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
728 aForceUpdatePins =
true;
731 if( aForceUpdatePins )
734 for(
int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
735 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL,
_(
"Not Connected" ) );
738 for(
int modelPinIndex = 0; modelPinIndex < aModel->
GetPinCount(); ++modelPinIndex )
742 if( symbolPinNumber ==
"" )
745 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
747 if( symbolPinRow == -1 )
750 wxString modelPinString = getModelPinString( aModel, modelPinIndex );
751 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
755 for(
int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
758 std::vector<BITMAPS> modelPinIcons;
759 wxArrayString modelPinChoices;
761 for(
int jj = 0; jj < aModel->
GetPinCount(); ++jj )
768 modelPinChoices.Add( getModelPinString( aModel, jj ) );
772 modelPinChoices.Add(
_(
"Not Connected" ) );
776 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
783 if( aModel->
GetType() == SIM_MODEL::TYPE::SUBCKT )
787 m_subckt->SetEditable(
false );
791 m_subcktLabel->Show(
false );
792 m_subckt->Show(
false );
812 if( m_prevLibrary == aLibraryPath && !aForceReload )
815 m_libraryModelsMgr.SetForceFullParse();
816 m_libraryModelsMgr.SetLibrary( aLibraryPath, aReporter );
823 for(
const auto& [baseModelName, baseModel] :
library()->GetModels() )
825 if( baseModelName == modelName )
826 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, aReporter );
828 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, aReporter );
831 m_rbLibraryModel->SetValue(
true );
832 m_libraryPathText->ChangeValue( aLibraryPath );
834 wxArrayString modelNames;
836 for(
const auto& [
name, model] :
library()->GetModels() )
837 modelNames.Add(
name );
839 m_modelNameChoice->Clear();
840 m_modelNameChoice->Append( modelNames );
844 wxArrayString emptyArray;
845 m_pinModelCombobox->Set( emptyArray );
846 m_pinCombobox->Set( emptyArray );
847 m_pinModelCombobox->SetSelection( -1 );
848 m_pinCombobox->SetSelection( -1 );
851 m_prevLibrary = aLibraryPath;
865 m_paramGrid->HideProperty(
"AC",
false );
866 m_paramGrid->AppendIn(
"AC", newParamProperty( aModel, aParamIndex ) );
870 m_paramGrid->HideProperty(
"DC",
false );
871 m_paramGrid->AppendIn(
"DC", newParamProperty( aModel, aParamIndex ) );
874 case CATEGORY::S_PARAM:
875 m_paramGrid->HideProperty(
"S-Parameters",
false );
876 m_paramGrid->AppendIn(
"S-Parameters", newParamProperty( aModel, aParamIndex ) );
879 case CATEGORY::CAPACITANCE:
880 m_paramGrid->HideProperty(
"Capacitance",
false );
881 m_paramGrid->AppendIn(
"Capacitance", newParamProperty( aModel, aParamIndex ) );
884 case CATEGORY::TEMPERATURE:
885 m_paramGrid->HideProperty(
"Temperature",
false );
886 m_paramGrid->AppendIn(
"Temperature", newParamProperty( aModel, aParamIndex ) );
889 case CATEGORY::NOISE:
890 m_paramGrid->HideProperty(
"Noise",
false );
891 m_paramGrid->AppendIn(
"Noise", newParamProperty( aModel, aParamIndex ) );
894 case CATEGORY::DISTRIBUTED_QUANTITIES:
895 m_paramGrid->HideProperty(
"Distributed Quantities",
false );
896 m_paramGrid->AppendIn(
"Distributed Quantities", newParamProperty( aModel, aParamIndex ) );
899 case CATEGORY::WAVEFORM:
900 m_paramGrid->HideProperty(
"Waveform",
false );
901 m_paramGrid->AppendIn(
"Waveform", newParamProperty( aModel, aParamIndex ) );
904 case CATEGORY::GEOMETRY:
905 m_paramGrid->HideProperty(
"Geometry",
false );
906 m_paramGrid->AppendIn(
"Geometry", newParamProperty( aModel, aParamIndex ) );
909 case CATEGORY::LIMITING_VALUES:
910 m_paramGrid->HideProperty(
"Limiting Values",
false );
911 m_paramGrid->AppendIn(
"Limiting Values", newParamProperty( aModel, aParamIndex ) );
914 case CATEGORY::ADVANCED:
915 m_paramGrid->HideProperty(
"Advanced",
false );
916 m_paramGrid->AppendIn(
"Advanced", newParamProperty( aModel, aParamIndex ) );
919 case CATEGORY::FLAGS:
920 m_paramGrid->HideProperty(
"Flags",
false );
921 m_paramGrid->AppendIn(
"Flags", newParamProperty( aModel, aParamIndex ) );
925 m_paramGrid->Insert( m_firstCategory, newParamProperty( aModel, aParamIndex ) );
928 case CATEGORY::INITIAL_CONDITIONS:
929 case CATEGORY::SUPERFLUOUS:
939 wxString paramDescription;
942 paramDescription = wxString::Format(
"%s", param.
info.
name );
946 wxPGProperty* prop =
nullptr;
953 prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX,
true );
975 wxArrayString inductors;
987 if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::L )
988 inductors.push_back( item.refName );
992 [](
const wxString& a,
const wxString& b ) ->
int
998 if( inductors.empty() )
1006 aParamIndex, inductors );
1016 wxArrayString values;
1019 values.Add(
string );
1027 prop =
new wxStringProperty( paramDescription, param.
info.
name );
1031 prop->SetAttribute( wxPG_ATTR_UNITS, wxString::FromUTF8( param.
info.
unit.c_str() ) );
1051 prop->SetCell( PARAM_COLUMN::TYPE, typeStr );
1057template <
typename T>
1060 for(
int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
1064 if(
pin->GetNumber() == aSymbolPinNumber )
1072template <
typename T>
1075 if( m_rbLibraryModel->GetValue() )
1077 int sel = m_modelNameChoice->GetSelection();
1079 if( sel >= 0 && sel <
static_cast<int>( m_libraryModelsMgr.GetModels().size() ) )
1080 return m_libraryModelsMgr.GetModels().at( sel ).get();
1084 if(
static_cast<int>( m_curModelType ) <
static_cast<int>( m_builtinModelsMgr.GetModels().size() ) )
1085 return m_builtinModelsMgr.GetModels().at(
static_cast<int>( m_curModelType ) );
1088 return m_builtinModelsMgr.GetModels().at(
static_cast<int>( SIM_MODEL::TYPE::NONE ) );
1092template <
typename T>
1095 if( m_libraryModelsMgr.GetLibraries().size() == 1 )
1096 return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
1102template <
typename T>
1105 SCH_PIN*
pin = m_sortedPartPins.at( symbolPinIndex );
1111 pinNumber =
pin->GetShownNumber();
1112 pinName =
pin->GetShownName();
1115 if( !pinName.IsEmpty() && pinName != pinNumber )
1116 pinNumber += wxString::Format( wxT(
" (%s)" ), pinName );
1122template <
typename T>
1129 wxString modelPinNumber = wxString::Format(
"%d", aModelPinIndex + 1 );
1131 if( !modelPinName.IsEmpty() && modelPinName != modelPinNumber )
1132 modelPinNumber += wxString::Format( wxT(
" (%s)" ), modelPinName );
1134 return modelPinNumber;
1138template <
typename T>
1141 if( aModelPinString ==
"Not Connected" )
1144 int length = aModelPinString.Find(
" " );
1146 if( length == wxNOT_FOUND )
1147 length =
static_cast<int>( aModelPinString.Length() );
1150 aModelPinString.Mid( 0, length ).ToCLong( &result );
1152 return static_cast<int>( result - 1 );
1156template <
typename T>
1159 m_prevModel =
nullptr;
1164template <
typename T>
1167 m_rbLibraryModel->SetValue(
true );
1171template <
typename T>
1174 m_rbLibraryModel->SetValue(
true );
1178 wxString
path = m_libraryPathText->GetValue();
1180 if( loadLibrary(
path, reporter,
true ) )
1183 m_infoBar->ShowMessage( msg );
1189template <
typename T>
1199 wxCommandEvent
dummy;
1200 onLibraryPathTextEnter(
dummy );
1205template <
typename T>
1208 static wxString s_mruPath;
1211 wxFileDialog dlg(
this,
_(
"Browse Models" ),
path );
1213 if( dlg.ShowModal() == wxID_CANCEL )
1216 m_rbLibraryModel->SetValue(
true );
1218 path = dlg.GetPath();
1219 wxFileName fn(
path );
1221 s_mruPath = fn.GetPath();
1223 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS(
".." ) ) )
1224 path = fn.GetFullPath();
1229 if( loadLibrary(
path, reporter,
true ) )
1232 m_infoBar->ShowMessage( msg );
1238template <
typename T>
1241 if( isIbisLoaded() )
1243 wxArrayString pinLabels;
1246 wxCHECK2( modelkibis,
return );
1248 for( std::pair<wxString, wxString> strs : modelkibis->
GetIbisPins() )
1249 pinLabels.Add( strs.first + wxT(
" - " ) + strs.second );
1251 m_pinCombobox->Set( pinLabels );
1253 wxArrayString emptyArray;
1254 m_pinModelCombobox->Set( emptyArray );
1257 m_rbLibraryModel->SetValue(
true );
1262template <
typename T>
1265 wxArrayString modelLabels;
1269 std::vector<std::pair<std::string, std::string>> strs = ibisModel.
GetIbisPins();
1270 std::string pinNumber = strs.at( m_pinCombobox->GetSelection() ).first;
1274 ibisModel.
ChangePin( *ibisLibrary, pinNumber );
1279 modelLabels.Add( modelName );
1281 m_pinModelCombobox->Set( modelLabels );
1283 if( m_pinModelCombobox->GetCount() == 1 )
1284 m_pinModelCombobox->SetSelection( 0 );
1286 m_pinModelCombobox->SetSelection( -1 );
1292template <
typename T>
1295 m_pinCombobox->SetSelection( m_pinCombobox->FindString( m_pinCombobox->GetValue() ) );
1297 onPinModelCombobox( aEvent );
1301template <
typename T>
1308template <
typename T>
1311 m_pinModelCombobox->SetSelection( m_pinModelCombobox->FindString( m_pinModelCombobox->GetValue() ) );
1314template <
typename T>
1319 wxCHECK( modelibis, );
1321 bool diff = m_differentialCheckbox->GetValue() && modelibis->
CanDifferential();
1328template <
typename T>
1331 m_rbBuiltinModel->SetValue(
true );
1333 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
1337 m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
1346template <
typename T>
1349 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1350 wxString typeDescription = m_waveformChoice->GetStringSelection();
1352 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
1353 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
1354 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
1355 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
1360 int idx = m_modelNameChoice->GetSelection();
1362 auto& baseModel =
static_cast<SIM_MODEL_IBIS&
>( m_libraryModelsMgr.GetModels()[idx].get() );
1364 m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_IBIS>( type, baseModel ) );
1368 m_libraryModelsMgr.GetModels()[idx].get().
ReadDataFields( &m_fields, m_sortedPartPins );
1375 m_curModelType = type;
1380 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1385template <
typename T>
1388 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1389 wxString typeDescription = m_deviceSubtypeChoice->GetStringSelection();
1391 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1396 m_curModelType = type;
1401 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1406template <
typename T>
1409 updateModelCodeTab( &curModel() );
1413template <
typename T>
1416 int symbolPinIndex = aEvent.GetRow();
1417 wxString oldModelPinName = aEvent.GetString();
1418 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
1420 int oldModelPinIndex = getModelPinIndex( oldModelPinName );
1421 int modelPinIndex = getModelPinIndex( modelPinName );
1424 curModel().AssignSymbolPinNumberToModelPin( oldModelPinIndex,
"" );
1428 SCH_PIN* symbolPin = m_sortedPartPins.at( symbolPinIndex );
1430 curModel().AssignSymbolPinNumberToModelPin( modelPinIndex, symbolPin->
GetShownNumber() );
1439template <
typename T>
1442 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
1445 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::MODEL, gridWidth / 2 );
1446 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::SYMBOL, gridWidth / 2 );
1452template <
typename T>
1458 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1459 wxPGProperty* selected =
grid->GetSelection();
1462 selected =
grid->wxPropertyGridInterface::GetFirst();
1464#if wxCHECK_VERSION( 3, 3, 0 )
1466 grid->DoSelectProperty( selected, wxPGSelectPropertyFlags::Focus );
1469 grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
1476template <
typename T>
1479 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1482 if(
grid->GetSelection() &&
grid->GetSelection()->IsCategory() )
1484 wxPGProperty* selection =
grid->GetSelection();
1489 wxPropertyGridIterator it =
grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
1492 wxKeyEvent* keyEvent =
new wxKeyEvent( wxEVT_KEY_DOWN );
1494 if( *it == m_prevParamGridSelection )
1496 if( !selection->IsExpanded() )
1498 grid->Expand( selection );
1499 keyEvent->m_keyCode = WXK_DOWN;
1500 wxQueueEvent(
grid, keyEvent );
1508 keyEvent->m_keyCode = WXK_UP;
1509 wxQueueEvent(
grid, keyEvent );
1514 if( !selection->IsExpanded() )
1515 grid->Expand( selection );
1517 keyEvent->m_keyCode = WXK_DOWN;
1518 wxQueueEvent(
grid, keyEvent );
1521 m_prevParamGridSelection =
grid->GetSelection();
1525 wxWindow* editorControl =
grid->GetEditorControl();
1527 if( !editorControl )
1529 m_prevParamGridSelection =
grid->GetSelection();
1534 editorControl->SetFocus();
1535 m_prevParamGridSelection =
grid->GetSelection();
1539template <
typename T>
1550 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1551 wxTextCtrl* ctrl =
grid->GetEditorTextCtrl();
1555 wxRect ctrlRect = ctrl->GetScreenRect();
1556 wxRect gridRect =
grid->GetScreenRect();
1558 if( ctrlRect.GetTop() < gridRect.GetTop() || ctrlRect.GetBottom() > gridRect.GetBottom() )
1559 grid->ClearSelection();
1565template <
typename T>
1568 wxPropertyGrid*
grid = m_paramGridMgr->GetGrid();
1572 if( aWidth != m_lastParamGridWidth || aForce )
1574 m_lastParamGridWidth = aWidth;
1578 std::vector<int> colWidths;
1580 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1582 if( ii == PARAM_COLUMN::DESCRIPTION )
1583 colWidths.push_back(
grid->GetState()->GetColumnWidth( ii ) + margin + indent );
1584 else if( ii == PARAM_COLUMN::VALUE )
1585 colWidths.push_back( std::max( 72,
grid->GetState()->GetColumnWidth( ii ) ) + margin );
1587 colWidths.push_back( 60 + margin );
1589 aWidth -= colWidths[ ii ];
1592 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1593 grid->SetColumnProportion( ii, colWidths[ ii ] );
1595 grid->ResetColumnSizes();
1596 grid->RefreshEditor();
1601template <
typename T>
1604 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
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 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
void SwitchSingleEndedDiff(bool aDiff) override
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...
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".