42#include <wx/filedlg.h>
43#include <fmt/format.h>
50#define FORCE_UPDATE_PINS true
53bool equivalent( SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b )
64 std::vector<SCH_FIELD>& aFields ) :
69 m_libraryModelsMgr( &
Prj() ),
70 m_builtinModelsMgr( &
Prj() ),
71 m_prevModel( nullptr ),
73 m_scintillaTricksCode( nullptr ),
74 m_scintillaTricksSubckt( nullptr ),
75 m_firstCategory( nullptr ),
76 m_prevParamGridSelection( nullptr ),
77 m_lastParamGridWidth( 0 ),
78 m_inKillFocus( false )
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 ) )
221 m_libraryPathText->ChangeValue( libraryFilename );
225 m_libraryModelsMgr.CreateModel(
nullptr, m_sortedPartPins, m_fields, reporter );
227 m_modelNameChoice->Append(
_(
"<unknown>" ) );
228 m_modelNameChoice->SetSelection( 0 );
233 int modelIdx = m_modelNameChoice->FindString( modelName );
235 if( modelIdx == wxNOT_FOUND )
241 m_modelNameChoice->SetSelection( 0 );
245 m_modelNameChoice->SetSelection( modelIdx );
248 m_curModelType = curModel().GetType();
251 if( isIbisLoaded() && ( m_modelNameChoice->GetSelection() >= 0 ) )
253 int idx = m_modelNameChoice->GetSelection();
254 auto kibismodel =
dynamic_cast<SIM_MODEL_KIBIS*
>( &m_libraryModelsMgr.GetModels()[idx].get() );
258 onModelNameChoice( dummyEvent );
262 for(
const std::pair<std::string, std::string>& strs : kibismodel->GetIbisPins() )
268 kibismodel->ChangePin( *kibisLibrary, strs.first );
269 m_pinCombobox->SetSelection(
static_cast<int>( i ) );
275 if( i <
static_cast<int>( kibismodel->GetIbisPins().size() ) )
277 onPinCombobox( dummyEvent );
279 m_pinModelCombobox->SetStringSelection(
285 kibismodel->SwitchSingleEndedDiff(
true );
286 m_differentialCheckbox->SetValue(
true );
290 kibismodel->SwitchSingleEndedDiff(
false );
291 m_differentialCheckbox->SetValue(
false );
300 m_rbBuiltinModel->SetValue(
true );
309 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
311 if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
314 m_builtinModelsMgr.CreateModel( m_fields, m_sortedPartPins,
false, reporter );
319 + wxT(
"\n\n" ) + msg );
324 m_builtinModelsMgr.CreateModel( type, m_sortedPartPins, reporter );
329 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
330 m_curModelTypeOfDeviceType[deviceTypeT] = type;
334 curModel().SetIsStoredInValue(
true );
336 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
338 onRadioButton( dummyEvent );
339 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
346 m_pinAssignmentsGrid->CommitPendingChanges();
347 m_paramGrid->GetGrid()->CommitChangesFromEditor();
349 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
356 if( m_rbLibraryModel->GetValue() )
358 path = m_libraryPathText->GetValue();
359 wxFileName fn(
path );
361 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith(
".." ) )
362 path = fn.GetFullPath();
364 if( !m_modelNameChoice->IsEmpty() )
365 name = m_modelNameChoice->GetStringSelection().ToStdString();
376 &m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get() );
381 std::string modelName = std::string( m_pinModelCombobox->GetValue().c_str() );
382 std::string differential;
384 if( m_pinCombobox->GetSelection() >= 0 )
385 pins = ibismodel->
GetIbisPins().at( m_pinCombobox->GetSelection() ).first;
387 if( ibismodel->
CanDifferential() && m_differentialCheckbox->GetValue() )
396 if( model.
GetType() == SIM_MODEL::TYPE::RAWSPICE )
398 if( m_modelNotebook->GetSelection() == 0 )
399 updateModelCodeTab( &model );
401 wxString code = m_codePreview->GetText().Trim(
true ).Trim(
false );
402 model.
SetParamValue(
"model", std::string( code.ToUTF8() ) );
407 for(
int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
409 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( row, PIN_COLUMN::MODEL );
410 wxString symbolPinName = m_sortedPartPins.at( row )->GetShownNumber();
413 std::string( symbolPinName.ToUTF8() ) );
416 removeOrphanedPinAssignments( &model );
418 curModel().WriteFields( m_fields );
429 m_browseButton->Enable();
432 bool undetermined = !m_rbLibraryModel->GetValue() && !m_rbBuiltinModel->GetValue();
433 bool enableLibCtrls = m_rbLibraryModel->GetValue() || undetermined;
434 bool enableBuiltinCtrls = m_rbBuiltinModel->GetValue() || undetermined;
436 m_pathLabel->Enable( enableLibCtrls );
437 m_libraryPathText->Enable( enableLibCtrls );
438 m_modelNameLabel->Enable( enableLibCtrls );
439 m_modelNameChoice->Enable( enableLibCtrls );
440 m_pinLabel->Enable( enableLibCtrls );
441 m_pinCombobox->Enable( enableLibCtrls );
442 m_differentialCheckbox->Enable( enableLibCtrls );
443 m_pinModelLabel->Enable( enableLibCtrls );
444 m_pinModelCombobox->Enable( enableLibCtrls );
445 m_waveformLabel->Enable( enableLibCtrls );
446 m_waveformChoice->Enable( enableLibCtrls );
448 m_deviceLabel->Enable( enableBuiltinCtrls );
449 m_deviceChoice->Enable( enableBuiltinCtrls );
450 m_deviceSubtypeLabel->Enable( enableBuiltinCtrls );
451 m_deviceSubtypeChoice->Enable( enableBuiltinCtrls );
455 updateIbisWidgets( model );
456 updateBuiltinModelWidgets( model );
457 updateModelParamsTab( model );
458 updateModelCodeTab( model );
459 updatePinAssignments( model,
false );
463 m_modelPanel->Layout();
464 m_pinAssignmentsPanel->Layout();
465 m_parametersPanel->Layout();
466 m_codePanel->Layout();
468 SendSizeEvent( wxSEND_EVENT_POST );
470 m_prevModel = &curModel();
480 m_pinLabel->Show( isIbisLoaded() );
481 m_pinCombobox->Show( isIbisLoaded() );
482 m_pinModelLabel->Show( isIbisLoaded() );
483 m_pinModelCombobox->Show( isIbisLoaded() );
484 m_waveformLabel->Show( isIbisLoaded() );
485 m_waveformChoice->Show( isIbisLoaded() );
487 if( aModel != m_prevModel )
489 m_waveformChoice->Clear();
493 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
494 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
495 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
496 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
506 if( type == aModel->
GetType() )
507 m_waveformChoice->SetSelection( m_waveformChoice->GetCount() - 1 );
513 m_differentialCheckbox->Show( isIbisLoaded() && modelkibis && modelkibis->
CanDifferential() );
514 m_modelNameLabel->SetLabel( isIbisLoaded() ?
_(
"Component:" ) :
_(
"Model:" ) );
522 if( aModel != m_prevModel )
524 m_deviceChoice->Clear();
525 m_deviceSubtypeChoice->Clear();
527 if( !m_rbLibraryModel->GetValue() )
529 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
537 m_deviceChoice->SetSelection( m_deviceChoice->GetCount() - 1 );
540 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
542 if( type == SIM_MODEL::TYPE::KIBIS_DEVICE
543 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
544 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
545 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS )
558 if( type == aModel->
GetType() )
559 m_deviceSubtypeChoice->SetSelection( m_deviceSubtypeChoice->GetCount() - 1 );
564 m_deviceSubtypeLabel->Show( m_deviceSubtypeChoice->GetCount() > 1 );
565 m_deviceSubtypeChoice->Show( m_deviceSubtypeChoice->GetCount() > 1 );
569 m_modelNotebook->SetSelection( 1 );
571 m_modelNotebook->SetSelection( 0 );
577 m_saveInValueCheckbox->SetLabel( wxString::Format(
_(
"Save parameter '%s (%s)' in Value "
581 m_saveInValueCheckbox->Enable(
true );
585 m_saveInValueCheckbox->SetLabel(
_(
"Save primary parameter in Value field" ) );
586 m_saveInValueCheckbox->SetValue(
false );
587 m_saveInValueCheckbox->Enable(
false );
595 if( aModel != m_prevModel )
600 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
602 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION,
_(
"Parameter" ) );
603 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT,
_(
"Unit" ) );
604 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT,
_(
"Default" ) );
605 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE,
_(
"Type" ) );
607 m_paramGridMgr->ShowHeader();
610 m_paramGrid->Clear();
612 m_firstCategory = m_paramGrid->Append(
new wxPropertyCategory(
"Geometry" ) );
613 m_paramGrid->HideProperty(
"Geometry" );
615 m_paramGrid->Append(
new wxPropertyCategory(
"AC" ) );
616 m_paramGrid->HideProperty(
"AC" );
618 m_paramGrid->Append(
new wxPropertyCategory(
"DC" ) );
619 m_paramGrid->HideProperty(
"DC" );
621 m_paramGrid->Append(
new wxPropertyCategory(
"S-Parameters" ) );
622 m_paramGrid->HideProperty(
"S-Parameters" );
624 m_paramGrid->Append(
new wxPropertyCategory(
"Capacitance" ) );
625 m_paramGrid->HideProperty(
"Capacitance" );
627 m_paramGrid->Append(
new wxPropertyCategory(
"Temperature" ) );
628 m_paramGrid->HideProperty(
"Temperature" );
630 m_paramGrid->Append(
new wxPropertyCategory(
"Noise" ) );
631 m_paramGrid->HideProperty(
"Noise" );
633 m_paramGrid->Append(
new wxPropertyCategory(
"Distributed Quantities" ) );
634 m_paramGrid->HideProperty(
"Distributed Quantities" );
636 m_paramGrid->Append(
new wxPropertyCategory(
"Waveform" ) );
637 m_paramGrid->HideProperty(
"Waveform" );
639 m_paramGrid->Append(
new wxPropertyCategory(
"Limiting Values" ) );
640 m_paramGrid->HideProperty(
"Limiting Values" );
642 m_paramGrid->Append(
new wxPropertyCategory(
"Advanced" ) );
643 m_paramGrid->HideProperty(
"Advanced" );
645 m_paramGrid->Append(
new wxPropertyCategory(
"Flags" ) );
646 m_paramGrid->HideProperty(
"Flags" );
648 m_paramGrid->CollapseAll();
651 addParamPropertyIfRelevant( aModel, i );
653 m_paramGrid->CollapseAll();
654 m_paramGrid->Expand(
"AC" );
655 m_paramGrid->Expand(
"Waveform" );
658 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(),
true );
662 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
664 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
665 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
667 for(
int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
669 ( *it )->GetCell( col ).SetBgCol( bgCol );
670 ( *it )->GetCell( col ).SetFgCol( fgCol );
684 ( *it )->SetValueFromString( param.
value );
698 item.
modelName = m_modelNameChoice->GetStringSelection();
700 if( m_rbBuiltinModel->GetValue() || item.
modelName ==
"" )
705 m_codePreview->SetText(
text );
706 m_codePreview->SelectNone();
713 if( m_pinAssignmentsGrid->GetNumberRows() == 0 )
715 m_pinAssignmentsGrid->AppendRows(
static_cast<int>( m_sortedPartPins.size() ) );
717 for(
int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
719 wxString symbolPinString = getSymbolPinString( ii );
721 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
722 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
725 aForceUpdatePins =
true;
728 if( aForceUpdatePins )
731 for(
int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
732 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL,
_(
"Not Connected" ) );
735 for(
int modelPinIndex = 0; modelPinIndex < aModel->
GetPinCount(); ++modelPinIndex )
739 if( symbolPinNumber ==
"" )
742 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
744 if( symbolPinRow == -1 )
747 wxString modelPinString = getModelPinString( aModel, modelPinIndex );
748 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
752 for(
int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
755 std::vector<BITMAPS> modelPinIcons;
756 wxArrayString modelPinChoices;
758 for(
int jj = 0; jj < aModel->
GetPinCount(); ++jj )
765 modelPinChoices.Add( getModelPinString( aModel, jj ) );
769 modelPinChoices.Add(
_(
"Not Connected" ) );
773 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
780 if( aModel->
GetType() == SIM_MODEL::TYPE::SUBCKT )
784 m_subckt->SetEditable(
false );
788 m_subcktLabel->Show(
false );
789 m_subckt->Show(
false );
808 if( m_prevLibrary == aLibraryPath && !aForceReload )
814 m_libraryModelsMgr.SetForceFullParse();
815 m_libraryModelsMgr.SetLibrary( aLibraryPath, reporter );
825 for(
const auto& [baseModelName, baseModel] :
library()->GetModels() )
827 if( baseModelName == modelName )
828 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, reporter );
830 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, reporter );
836 m_rbLibraryModel->SetValue(
true );
837 m_libraryPathText->ChangeValue( aLibraryPath );
839 wxArrayString modelNames;
841 for(
const auto& [
name, model] :
library()->GetModels() )
842 modelNames.Add(
name );
844 m_modelNameChoice->Clear();
845 m_modelNameChoice->Append( modelNames );
849 wxArrayString emptyArray;
850 m_pinModelCombobox->Set( emptyArray );
851 m_pinCombobox->Set( emptyArray );
852 m_pinModelCombobox->SetSelection( -1 );
853 m_pinCombobox->SetSelection( -1 );
856 m_prevLibrary = aLibraryPath;
870 m_paramGrid->HideProperty(
"AC",
false );
871 m_paramGrid->AppendIn(
"AC", newParamProperty( aModel, aParamIndex ) );
875 m_paramGrid->HideProperty(
"DC",
false );
876 m_paramGrid->AppendIn(
"DC", newParamProperty( aModel, aParamIndex ) );
879 case CATEGORY::S_PARAM:
880 m_paramGrid->HideProperty(
"S-Parameters",
false );
881 m_paramGrid->AppendIn(
"S-Parameters", newParamProperty( aModel, aParamIndex ) );
884 case CATEGORY::CAPACITANCE:
885 m_paramGrid->HideProperty(
"Capacitance",
false );
886 m_paramGrid->AppendIn(
"Capacitance", newParamProperty( aModel, aParamIndex ) );
889 case CATEGORY::TEMPERATURE:
890 m_paramGrid->HideProperty(
"Temperature",
false );
891 m_paramGrid->AppendIn(
"Temperature", newParamProperty( aModel, aParamIndex ) );
894 case CATEGORY::NOISE:
895 m_paramGrid->HideProperty(
"Noise",
false );
896 m_paramGrid->AppendIn(
"Noise", newParamProperty( aModel, aParamIndex ) );
899 case CATEGORY::DISTRIBUTED_QUANTITIES:
900 m_paramGrid->HideProperty(
"Distributed Quantities",
false );
901 m_paramGrid->AppendIn(
"Distributed Quantities", newParamProperty( aModel, aParamIndex ) );
904 case CATEGORY::WAVEFORM:
905 m_paramGrid->HideProperty(
"Waveform",
false );
906 m_paramGrid->AppendIn(
"Waveform", newParamProperty( aModel, aParamIndex ) );
909 case CATEGORY::GEOMETRY:
910 m_paramGrid->HideProperty(
"Geometry",
false );
911 m_paramGrid->AppendIn(
"Geometry", newParamProperty( aModel, aParamIndex ) );
914 case CATEGORY::LIMITING_VALUES:
915 m_paramGrid->HideProperty(
"Limiting Values",
false );
916 m_paramGrid->AppendIn(
"Limiting Values", newParamProperty( aModel, aParamIndex ) );
919 case CATEGORY::ADVANCED:
920 m_paramGrid->HideProperty(
"Advanced",
false );
921 m_paramGrid->AppendIn(
"Advanced", newParamProperty( aModel, aParamIndex ) );
924 case CATEGORY::FLAGS:
925 m_paramGrid->HideProperty(
"Flags",
false );
926 m_paramGrid->AppendIn(
"Flags", newParamProperty( aModel, aParamIndex ) );
930 m_paramGrid->Insert( m_firstCategory, newParamProperty( aModel, aParamIndex ) );
933 case CATEGORY::INITIAL_CONDITIONS:
934 case CATEGORY::SUPERFLUOUS:
944 wxString paramDescription;
947 paramDescription = wxString::Format(
"%s", param.
info.
name );
951 wxPGProperty* prop =
nullptr;
958 prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX,
true );
980 wxArrayString inductors;
992 if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::L )
993 inductors.push_back( item.refName );
997 [](
const wxString& a,
const wxString& b ) ->
int
1003 if( inductors.empty() )
1011 aParamIndex, inductors );
1021 wxArrayString values;
1024 values.Add(
string );
1032 prop =
new wxStringProperty( paramDescription, param.
info.
name );
1036 prop->SetAttribute( wxPG_ATTR_UNITS, wxString::FromUTF8( param.
info.
unit.c_str() ) );
1056 prop->SetCell( PARAM_COLUMN::TYPE, typeStr );
1062template <
typename T>
1065 for(
int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
1069 if(
pin->GetNumber() == aSymbolPinNumber )
1077template <
typename T>
1080 if( m_rbLibraryModel->GetValue() )
1082 int sel = m_modelNameChoice->GetSelection();
1084 if( sel >= 0 && sel < (
int) m_libraryModelsMgr.GetModels().size() )
1085 return m_libraryModelsMgr.GetModels().at( sel ).get();
1089 if( (
int) m_curModelType < (
int) m_builtinModelsMgr.GetModels().size() )
1090 return m_builtinModelsMgr.GetModels().at( (
int) m_curModelType );
1093 return m_builtinModelsMgr.GetModels().at( (
int) SIM_MODEL::TYPE::NONE );
1097template <
typename T>
1100 if( m_libraryModelsMgr.GetLibraries().size() == 1 )
1101 return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
1107template <
typename T>
1110 LIB_PIN*
pin = m_sortedPartPins.at( symbolPinIndex );
1116 pinNumber =
pin->GetShownNumber();
1117 pinName =
pin->GetShownName();
1120 if( !pinName.IsEmpty() && pinName != pinNumber )
1121 pinNumber += wxString::Format( wxT(
" (%s)" ), pinName );
1127template <
typename T>
1130 const wxString& pinName = aModel->
GetPin( aModelPinIndex ).
name;
1134 wxString pinNumber = wxString::Format(
"%d", aModelPinIndex + 1 );
1136 if( !pinName.IsEmpty() && pinName != pinNumber )
1137 pinNumber += wxString::Format( wxT(
" (%s)" ), pinName );
1143template <
typename T>
1146 if( aModelPinString ==
"Not Connected" )
1149 int length = aModelPinString.Find(
" " );
1151 if( length == wxNOT_FOUND )
1152 length =
static_cast<int>( aModelPinString.Length() );
1155 aModelPinString.Mid( 0, length ).ToCLong( &result );
1157 return static_cast<int>( result - 1 );
1161template <
typename T>
1164 m_prevModel =
nullptr;
1169template <
typename T>
1172 m_rbLibraryModel->SetValue(
true );
1177template <
typename T>
1180 if( m_rbLibraryModel->GetValue() )
1182 wxString
path = m_libraryPathText->GetValue();
1184 if( !
path.IsEmpty() )
1188 loadLibrary(
path );
1200template <
typename T>
1203 if( !m_inKillFocus )
1205 m_inKillFocus =
true;
1207 wxCommandEvent
dummy;
1208 onLibraryPathTextEnter(
dummy );
1210 m_inKillFocus =
false;
1215template <
typename T>
1218 static wxString s_mruPath;
1221 wxFileDialog dlg(
this,
_(
"Browse Models" ),
path );
1223 if( dlg.ShowModal() == wxID_CANCEL )
1226 m_rbLibraryModel->SetValue(
true );
1228 path = dlg.GetPath();
1229 wxFileName fn(
path );
1231 s_mruPath = fn.GetPath();
1233 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS(
".." ) ) )
1234 path = fn.GetFullPath();
1236 loadLibrary(
path,
true );
1241template <
typename T>
1244 if( isIbisLoaded() )
1246 wxArrayString pinLabels;
1249 wxCHECK2( modelkibis,
return );
1251 for( std::pair<wxString, wxString> strs : modelkibis->
GetIbisPins() )
1252 pinLabels.Add( strs.first + wxT(
" - " ) + strs.second );
1254 m_pinCombobox->Set( pinLabels );
1256 wxArrayString emptyArray;
1257 m_pinModelCombobox->Set( emptyArray );
1260 m_rbLibraryModel->SetValue(
true );
1265template <
typename T>
1268 wxArrayString modelLabels;
1272 std::vector<std::pair<std::string, std::string>> strs = ibisModel.
GetIbisPins();
1273 std::string pinNumber = strs.at( m_pinCombobox->GetSelection() ).first;
1277 ibisModel.
ChangePin( *ibisLibrary, pinNumber );
1282 modelLabels.Add( modelName );
1284 m_pinModelCombobox->Set( modelLabels );
1286 if( m_pinModelCombobox->GetCount() == 1 )
1287 m_pinModelCombobox->SetSelection( 0 );
1289 m_pinModelCombobox->SetSelection( -1 );
1295template <
typename T>
1298 m_pinCombobox->SetSelection( m_pinCombobox->FindString( m_pinCombobox->GetValue() ) );
1300 onPinModelCombobox( aEvent );
1304template <
typename T>
1311template <
typename T>
1314 m_pinModelCombobox->SetSelection( m_pinModelCombobox->FindString( m_pinModelCombobox->GetValue() ) );
1317template <
typename T>
1322 wxCHECK( modelkibis, );
1324 bool diff = m_differentialCheckbox->GetValue() && modelkibis->
CanDifferential();
1331template <
typename T>
1334 m_rbBuiltinModel->SetValue(
true );
1336 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
1340 m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
1349template <
typename T>
1352 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1353 wxString typeDescription = m_waveformChoice->GetStringSelection();
1355 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
1356 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
1357 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
1358 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
1363 int idx = m_modelNameChoice->GetSelection();
1365 auto& baseModel =
static_cast<SIM_MODEL_KIBIS&
>( m_libraryModelsMgr.GetModels()[idx].get() );
1367 m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_KIBIS>( type, baseModel ) );
1371 m_libraryModelsMgr.GetModels()[idx].get().
ReadDataFields( &m_fields, m_sortedPartPins );
1378 m_curModelType = type;
1383 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1388template <
typename T>
1391 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1392 wxString typeDescription = m_deviceSubtypeChoice->GetStringSelection();
1394 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1399 m_curModelType = type;
1404 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1409template <
typename T>
1412 updateModelCodeTab( &curModel() );
1416template <
typename T>
1419 int symbolPinIndex = aEvent.GetRow();
1420 wxString oldModelPinName = aEvent.GetString();
1421 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
1423 int oldModelPinIndex = getModelPinIndex( oldModelPinName );
1424 int modelPinIndex = getModelPinIndex( modelPinName );
1427 curModel().SetPinSymbolPinNumber( oldModelPinIndex,
"" );
1431 curModel().SetPinSymbolPinNumber( modelPinIndex,
1432 std::string( m_sortedPartPins.at( symbolPinIndex )->GetShownNumber().ToUTF8() ) );
1441template <
typename T>
1444 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
1447 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::MODEL, gridWidth / 2 );
1448 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::SYMBOL, gridWidth / 2 );
1454template <
typename T>
1460 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1461 wxPGProperty* selected =
grid->GetSelection();
1464 selected =
grid->wxPropertyGridInterface::GetFirst();
1466#if wxCHECK_VERSION( 3, 3, 0 )
1468 grid->DoSelectProperty( selected, wxPGSelectPropertyFlags::Focus );
1471 grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
1478template <
typename T>
1481 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1484 if(
grid->GetSelection() &&
grid->GetSelection()->IsCategory() )
1486 wxPGProperty* selection =
grid->GetSelection();
1491 wxPropertyGridIterator it =
grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
1494 wxKeyEvent* keyEvent =
new wxKeyEvent( wxEVT_KEY_DOWN );
1496 if( *it == m_prevParamGridSelection )
1498 if( !selection->IsExpanded() )
1500 grid->Expand( selection );
1501 keyEvent->m_keyCode = WXK_DOWN;
1502 wxQueueEvent(
grid, keyEvent );
1510 keyEvent->m_keyCode = WXK_UP;
1511 wxQueueEvent(
grid, keyEvent );
1516 if( !selection->IsExpanded() )
1517 grid->Expand( selection );
1519 keyEvent->m_keyCode = WXK_DOWN;
1520 wxQueueEvent(
grid, keyEvent );
1523 m_prevParamGridSelection =
grid->GetSelection();
1527 wxWindow* editorControl =
grid->GetEditorControl();
1529 if( !editorControl )
1531 m_prevParamGridSelection =
grid->GetSelection();
1536 editorControl->SetFocus();
1537 m_prevParamGridSelection =
grid->GetSelection();
1541template <
typename T>
1552 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1553 wxTextCtrl* ctrl =
grid->GetEditorTextCtrl();
1557 wxRect ctrlRect = ctrl->GetScreenRect();
1558 wxRect gridRect =
grid->GetScreenRect();
1560 if( ctrlRect.GetTop() < gridRect.GetTop() || ctrlRect.GetBottom() > gridRect.GetBottom() )
1561 grid->ClearSelection();
1567template <
typename T>
1570 wxPropertyGrid*
grid = m_paramGridMgr->GetGrid();
1574 if( aWidth != m_lastParamGridWidth || aForce )
1576 m_lastParamGridWidth = aWidth;
1580 std::vector<int> colWidths;
1582 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1584 if( ii == PARAM_COLUMN::DESCRIPTION )
1585 colWidths.push_back(
grid->GetState()->GetColumnWidth( ii ) + margin + indent );
1586 else if( ii == PARAM_COLUMN::VALUE )
1587 colWidths.push_back( std::max( 72,
grid->GetState()->GetColumnWidth( ii ) ) + margin );
1589 colWidths.push_back( 60 + margin );
1591 aWidth -= colWidths[ ii ];
1594 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1595 grid->SetColumnProportion( ii, colWidths[ ii ] );
1597 grid->ResetColumnSizes();
1598 grid->RefreshEditor();
1603template <
typename T>
1606 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
int getModelPinIndex(const wxString &aModelPinString) const
void onDifferentialCheckbox(wxCommandEvent &event) override
void onParamGridSelectionChange(wxPropertyGridEvent &aEvent)
void removeOrphanedPinAssignments(SIM_MODEL *aModel)
void adjustParamGridColumns(int aWidth, bool aForce)
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
std::vector< LIB_PIN * > m_sortedPartPins
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
bool loadLibrary(const wxString &aLibraryPath, bool aForceReload=false)
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)
void onLibrarayPathText(wxCommandEvent &aEvent) override
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.
Schematic editor (Eeschema) main window.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
bool isPinDiff(const std::string &aComp, const std::string &aPinNumber) const
static constexpr auto DIFF_FIELD
static constexpr auto MODEL_FIELD
static constexpr auto PIN_FIELD
static constexpr auto LIBRARY_FIELD
static constexpr auto NAME_FIELD
bool ChangePin(const SIM_LIBRARY_KIBIS &aLib, std::string aPinNumber)
update the list of available models based on the pin number.
std::vector< std::string > GetIbisModels() const
std::string GetComponentName() const
bool CanDifferential() const
void SwitchSingleEndedDiff(bool aDiff) override
std::vector< std::pair< std::string, std::string > > GetIbisPins() const
std::string GetSpiceCode() const
void ReadDataFields(const std::vector< SCH_FIELD > *aFields, const std::vector< LIB_PIN * > &aPins)
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)
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 SetPinSymbolPinNumber(int aPinIndex, const std::string &aSymbolPinNumber)
DEVICE_INFO GetDeviceInfo() const
DEVICE_T GetDeviceType() const
static DEVICE_INFO DeviceInfo(DEVICE_T aDeviceType)
const PIN & GetPin(unsigned aIndex) const
virtual bool HasAutofill() const
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
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)
#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
std::string symbolPinNumber
static constexpr auto NOT_CONNECTED
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".