43#include <wx/filedlg.h>
44#include <wx/textfile.h>
45#include <fmt/format.h>
50bool equivalent( SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b )
59template <
typename T_symbol,
typename T_field>
61 std::vector<T_field>& aFields )
65 m_libraryModelsMgr( &
Prj() ),
66 m_builtinModelsMgr( &
Prj() ),
67 m_prevModel( nullptr ),
69 m_scintillaTricks( nullptr ),
70 m_firstCategory( nullptr ),
71 m_prevParamGridSelection( nullptr ),
72 m_lastParamGridWidth( 0 ),
73 m_inKillFocus( false )
80 if( !
pin->GetParent()->HasConversion() ||
pin->GetConvert() < 2 )
88 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
100 grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
105 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
106 grid->DedicateKey( WXK_RETURN );
107 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
109 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_NUMPAD_ENTER );
110 grid->DedicateKey( WXK_NUMPAD_ENTER );
111 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
113 grid->DedicateKey( WXK_UP );
114 grid->DedicateKey( WXK_DOWN );
125template <
typename T_symbol,
typename T_field>
130 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
141 m_pinAssignmentsGrid->PopEventHandler(
true );
143 delete m_scintillaTricks;
147template <
typename T_symbol,
typename T_field>
150 wxCommandEvent dummyEvent;
153 wxString modelParams;
155 bool storeInValue =
false;
162 &deviceType, &modelType, &modelParams, &pinMap ) )
165 m_fields.back().SetText( deviceType );
167 if( !modelType.IsEmpty() )
170 m_fields.back().SetText( modelType );
174 m_fields.back().SetText( modelParams );
177 m_fields.back().SetText( pinMap );
183 m_fields[
VALUE_FIELD ].SetText( wxT(
"${SIM.PARAMS}" ) );
188 if( libraryFilename !=
"" )
191 m_rbLibraryModel->SetValue(
true );
193 if( !loadLibrary( libraryFilename ) )
195 m_libraryPathText->ChangeValue( libraryFilename );
197 m_libraryModelsMgr.CreateModel(
nullptr, m_sortedPartPins, m_fields );
199 m_modelNameChoice->Append(
_(
"<unknown>" ) );
200 m_modelNameChoice->SetSelection( 0 );
205 int modelIdx = m_modelNameChoice->FindString( modelName );
207 if( modelIdx == wxNOT_FOUND )
213 m_modelNameChoice->SetSelection( 0 );
217 m_modelNameChoice->SetSelection( modelIdx );
220 m_curModelType = curModel().GetType();
223 if( isIbisLoaded() && ( m_modelNameChoice->GetSelection() >= 0 ) )
225 int idx = m_modelNameChoice->GetSelection();
226 auto kibismodel =
dynamic_cast<SIM_MODEL_KIBIS*
>( &m_libraryModelsMgr.GetModels()[idx].get() );
230 onModelNameChoice( dummyEvent );
234 for(
const std::pair<std::string, std::string>& strs : kibismodel->GetIbisPins() )
240 kibismodel->ChangePin( *kibisLibrary, strs.first );
241 m_ibisPinCombobox->SetSelection(
static_cast<int>( i ) );
247 if( i <
static_cast<int>( kibismodel->GetIbisPins().size() ) )
249 onIbisPinCombobox( dummyEvent );
251 m_ibisModelCombobox->SetStringSelection(
257 kibismodel->SwitchSingleEndedDiff(
true );
258 m_differentialCheckbox->SetValue(
true );
262 kibismodel->SwitchSingleEndedDiff(
false );
263 m_differentialCheckbox->SetValue(
false );
272 m_rbBuiltinModel->SetValue(
true );
281 m_builtinModelsMgr.SetReporter( &reporter );
283 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
285 if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
288 m_builtinModelsMgr.CreateModel( m_fields, m_sortedPartPins,
false );
293 + wxT(
"\n\n" ) + msg );
298 m_builtinModelsMgr.CreateModel( type, m_sortedPartPins );
303 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
304 m_curModelTypeOfDeviceType[deviceTypeT] = type;
308 curModel().SetIsStoredInValue(
true );
310 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
312 onRadioButton( dummyEvent );
313 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
317template <
typename T_symbol,
typename T_field>
320 m_pinAssignmentsGrid->CommitPendingChanges();
322 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
328 if( m_rbLibraryModel->GetValue() )
330 path = m_libraryPathText->GetValue();
331 wxFileName fn(
path );
333 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith(
".." ) )
334 path = fn.GetFullPath();
336 if( !m_modelNameChoice->IsEmpty() )
337 name = m_modelNameChoice->GetStringSelection().ToStdString();
348 &m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get() );
353 std::string modelName = std::string( m_ibisModelCombobox->GetValue().c_str() );
354 std::string differential;
356 if( m_ibisPinCombobox->GetSelection() >= 0 )
357 pins = ibismodel->
GetIbisPins().at( m_ibisPinCombobox->GetSelection() ).first;
359 if( ibismodel->
CanDifferential() && m_differentialCheckbox->GetValue() )
368 if( curModel().GetType() == SIM_MODEL::TYPE::RAWSPICE )
370 if( m_modelNotebook->GetSelection() == 0 )
371 updateModelCodeTab( &curModel() );
373 wxString code = m_codePreview->GetText().Trim(
true ).Trim(
false );
374 curModel().SetParamValue(
"model", std::string( code.ToUTF8() ) );
377 curModel().SetIsStoredInValue( m_saveInValueCheckbox->GetValue() );
379 curModel().WriteFields( m_fields );
385template <
typename T_symbol,
typename T_field>
390 updateIbisWidgets( model );
391 updateBuiltinModelWidgets( model );
392 updateModelParamsTab( model );
393 updateModelCodeTab( model );
394 updatePinAssignments( model );
398 m_modelPanel->Layout();
399 m_pinAssignmentsPanel->Layout();
400 m_parametersPanel->Layout();
401 m_codePanel->Layout();
403 SendSizeEvent( wxSEND_EVENT_POST );
405 m_prevModel = &curModel();
409template <
typename T_symbol,
typename T_field>
415 m_ibisModelCombobox->Show( isIbisLoaded() );
416 m_ibisPinCombobox->Show( isIbisLoaded() );
417 m_ibisModelLabel->Show( isIbisLoaded() );
418 m_ibisPinLabel->Show( isIbisLoaded() );
420 m_differentialCheckbox->Show( isIbisLoaded() && modelkibis && modelkibis->
CanDifferential() );
421 m_modelNameLabel->SetLabel( isIbisLoaded() ?
_(
"Component:" ) :
_(
"Model:" ) );
425template <
typename T_symbol,
typename T_field>
429 if( aModel != m_prevModel )
431 m_deviceTypeChoice->Clear();
433 if( m_rbLibraryModel->GetValue() )
435 m_deviceTypeChoice->Append( aModel->
GetDeviceInfo().description );
436 m_deviceTypeChoice->SetSelection( 0 );
440 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
448 m_deviceTypeChoice->SetSelection( m_deviceTypeChoice->GetCount() - 1 );
452 m_typeChoice->Clear();
454 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
463 if( type == aModel->
GetType() )
464 m_typeChoice->SetSelection( m_typeChoice->GetCount() - 1 );
469 m_typeChoice->Enable( !m_rbLibraryModel->GetValue() || isIbisLoaded() );
472 m_modelNotebook->SetSelection( 1 );
474 m_modelNotebook->SetSelection( 0 );
480 m_saveInValueCheckbox->SetLabel( wxString::Format(
_(
"Save parameter '%s (%s)' in Value "
484 m_saveInValueCheckbox->Enable(
true );
488 m_saveInValueCheckbox->SetLabel(
_(
"Save primary parameter in Value field" ) );
489 m_saveInValueCheckbox->SetValue(
false );
490 m_saveInValueCheckbox->Enable(
false );
495template <
typename T_symbol,
typename T_field>
498 if( aModel != m_prevModel )
503 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
505 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION,
_(
"Parameter" ) );
506 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT,
_(
"Unit" ) );
507 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT,
_(
"Default" ) );
508 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE,
_(
"Type" ) );
510 m_paramGridMgr->ShowHeader();
513 m_paramGrid->Clear();
515 m_firstCategory = m_paramGrid->Append(
new wxPropertyCategory(
"Geometry" ) );
516 m_paramGrid->HideProperty(
"Geometry" );
518 m_paramGrid->Append(
new wxPropertyCategory(
"AC" ) );
519 m_paramGrid->HideProperty(
"AC" );
521 m_paramGrid->Append(
new wxPropertyCategory(
"DC" ) );
522 m_paramGrid->HideProperty(
"DC" );
524 m_paramGrid->Append(
new wxPropertyCategory(
"Capacitance" ) );
525 m_paramGrid->HideProperty(
"Capacitance" );
527 m_paramGrid->Append(
new wxPropertyCategory(
"Temperature" ) );
528 m_paramGrid->HideProperty(
"Temperature" );
530 m_paramGrid->Append(
new wxPropertyCategory(
"Noise" ) );
531 m_paramGrid->HideProperty(
"Noise" );
533 m_paramGrid->Append(
new wxPropertyCategory(
"Distributed Quantities" ) );
534 m_paramGrid->HideProperty(
"Distributed Quantities" );
536 m_paramGrid->Append(
new wxPropertyCategory(
"Waveform" ) );
537 m_paramGrid->HideProperty(
"Waveform" );
539 m_paramGrid->Append(
new wxPropertyCategory(
"Limiting Values" ) );
540 m_paramGrid->HideProperty(
"Limiting Values" );
542 m_paramGrid->Append(
new wxPropertyCategory(
"Advanced" ) );
543 m_paramGrid->HideProperty(
"Advanced" );
545 m_paramGrid->Append(
new wxPropertyCategory(
"Flags" ) );
546 m_paramGrid->HideProperty(
"Flags" );
548 m_paramGrid->CollapseAll();
551 addParamPropertyIfRelevant( aModel, i );
553 m_paramGrid->CollapseAll();
554 m_paramGrid->Expand(
"AC" );
555 m_paramGrid->Expand(
"Waveform" );
558 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(),
true );
562 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
564 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
565 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
567 for(
int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
569 ( *it )->GetCell( col ).SetBgCol( bgCol );
570 ( *it )->GetCell( col ).SetFgCol( fgCol );
584 ( *it )->SetValueFromString( param.
value );
589template <
typename T_symbol,
typename T_field>
598 item.
modelName = m_modelNameChoice->GetStringSelection();
600 if( m_rbBuiltinModel->GetValue() || item.
modelName ==
"" )
605 m_codePreview->SetText(
text );
606 m_codePreview->SelectNone();
610template <
typename T_symbol,
typename T_field>
613 removeOrphanedPinAssignments( aModel );
617 m_pinAssignmentsGrid->ClearRows();
618 m_pinAssignmentsGrid->AppendRows(
static_cast<int>( m_sortedPartPins.size() ) );
620 for(
int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
621 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL,
_(
"Not Connected" ) );
624 for(
int modelPinIndex = 0; modelPinIndex < aModel->
GetPinCount(); ++modelPinIndex )
628 if( symbolPinNumber ==
"" )
631 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
633 if( symbolPinRow == -1 )
636 wxString modelPinString = getModelPinString( aModel, modelPinIndex );
637 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
641 for(
int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
643 wxString symbolPinString = getSymbolPinString( ii );
645 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
646 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
648 wxString curModelPinString = m_pinAssignmentsGrid->GetCellValue( ii, PIN_COLUMN::MODEL );
650 std::vector<BITMAPS> modelPinIcons;
651 wxArrayString modelPinChoices;
653 for(
int jj = 0; jj < aModel->
GetPinCount(); ++jj )
660 modelPinChoices.Add( getModelPinString( aModel, jj ) );
664 modelPinChoices.Add(
_(
"Not Connected" ) );
668 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
675 if( aModel->
GetType() == SIM_MODEL::TYPE::SUBCKT )
682 m_subcktLabel->Show(
false );
683 m_subckt->Show(
false );
688template <
typename T_symbol,
typename T_field>
699template <
typename T_symbol,
typename T_field>
703 if( m_prevLibrary == aLibraryPath && !aForceReload )
709 m_libraryModelsMgr.SetReporter( &reporter );
710 m_libraryModelsMgr.SetForceFullParse();
711 m_libraryModelsMgr.SetLibrary( aLibraryPath );
721 for(
const auto& [baseModelName, baseModel] :
library()->GetModels() )
723 if( baseModelName == modelName )
724 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields );
726 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins );
732 m_rbLibraryModel->SetValue(
true );
733 m_libraryPathText->ChangeValue( aLibraryPath );
735 wxArrayString modelNames;
737 for(
const auto& [
name, model] :
library()->GetModels() )
738 modelNames.Add(
name );
740 m_modelNameChoice->Clear();
741 m_modelNameChoice->Append( modelNames );
745 wxArrayString emptyArray;
746 m_ibisModelCombobox->Set( emptyArray );
747 m_ibisPinCombobox->Set( emptyArray );
748 m_ibisModelCombobox->SetSelection( -1 );
749 m_ibisPinCombobox->SetSelection( -1 );
752 m_prevLibrary = aLibraryPath;
757template <
typename T_symbol,
typename T_field>
767 m_paramGrid->HideProperty(
"AC",
false );
768 m_paramGrid->AppendIn(
"AC", newParamProperty( aModel, aParamIndex ) );
772 m_paramGrid->HideProperty(
"DC",
false );
773 m_paramGrid->AppendIn(
"DC", newParamProperty( aModel, aParamIndex ) );
776 case CATEGORY::CAPACITANCE:
777 m_paramGrid->HideProperty(
"Capacitance",
false );
778 m_paramGrid->AppendIn(
"Capacitance", newParamProperty( aModel, aParamIndex ) );
781 case CATEGORY::TEMPERATURE:
782 m_paramGrid->HideProperty(
"Temperature",
false );
783 m_paramGrid->AppendIn(
"Temperature", newParamProperty( aModel, aParamIndex ) );
786 case CATEGORY::NOISE:
787 m_paramGrid->HideProperty(
"Noise",
false );
788 m_paramGrid->AppendIn(
"Noise", newParamProperty( aModel, aParamIndex ) );
791 case CATEGORY::DISTRIBUTED_QUANTITIES:
792 m_paramGrid->HideProperty(
"Distributed Quantities",
false );
793 m_paramGrid->AppendIn(
"Distributed Quantities", newParamProperty( aModel, aParamIndex ) );
796 case CATEGORY::WAVEFORM:
797 m_paramGrid->HideProperty(
"Waveform",
false );
798 m_paramGrid->AppendIn(
"Waveform", newParamProperty( aModel, aParamIndex ) );
801 case CATEGORY::GEOMETRY:
802 m_paramGrid->HideProperty(
"Geometry",
false );
803 m_paramGrid->AppendIn(
"Geometry", newParamProperty( aModel, aParamIndex ) );
806 case CATEGORY::LIMITING_VALUES:
807 m_paramGrid->HideProperty(
"Limiting Values",
false );
808 m_paramGrid->AppendIn(
"Limiting Values", newParamProperty( aModel, aParamIndex ) );
811 case CATEGORY::ADVANCED:
812 m_paramGrid->HideProperty(
"Advanced",
false );
813 m_paramGrid->AppendIn(
"Advanced", newParamProperty( aModel, aParamIndex ) );
816 case CATEGORY::FLAGS:
817 m_paramGrid->HideProperty(
"Flags",
false );
818 m_paramGrid->AppendIn(
"Flags", newParamProperty( aModel, aParamIndex ) );
822 m_paramGrid->Insert( m_firstCategory, newParamProperty( aModel, aParamIndex ) );
825 case CATEGORY::INITIAL_CONDITIONS:
826 case CATEGORY::SUPERFLUOUS:
832template <
typename T_symbol,
typename T_field>
834 int aParamIndex )
const
837 wxString paramDescription;
840 paramDescription = wxString::Format(
"%s", param.
info.
name );
844 wxPGProperty* prop =
nullptr;
851 prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX,
true );
880 prop =
new wxStringProperty( paramDescription, param.
info.
name );
884 prop->SetAttribute( wxPG_ATTR_UNITS, wxString::FromUTF8( param.
info.
unit.c_str() ) );
887 #if wxCHECK_VERSION( 3, 1, 0 )
908 prop->SetCell( PARAM_COLUMN::TYPE, typeStr );
914template <
typename T_symbol,
typename T_field>
917 for(
int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
921 if(
pin->GetNumber() == aSymbolPinNumber )
929template <
typename T_symbol,
typename T_field>
932 if( m_rbLibraryModel->GetValue() )
934 int sel = m_modelNameChoice->GetSelection();
936 if( sel >= 0 && sel < (
int) m_libraryModelsMgr.GetModels().size() )
937 return m_libraryModelsMgr.GetModels().at( sel ).get();
941 if( (
int) m_curModelType < (
int) m_builtinModelsMgr.GetModels().size() )
942 return m_builtinModelsMgr.GetModels().at( (
int) m_curModelType );
945 return m_builtinModelsMgr.GetModels().at( (
int) SIM_MODEL::TYPE::NONE );
949template <
typename T_symbol,
typename T_field>
952 if( m_libraryModelsMgr.GetLibraries().size() == 1 )
953 return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
959template <
typename T_symbol,
typename T_field>
962 LIB_PIN*
pin = m_sortedPartPins.at( symbolPinIndex );
968 pinNumber =
pin->GetShownNumber();
969 pinName =
pin->GetShownName();
972 if( !pinName.IsEmpty() && pinName != pinNumber )
973 pinNumber += wxString::Format( wxT(
" (%s)" ), pinName );
979template <
typename T_symbol,
typename T_field>
981 int aModelPinIndex )
const
983 const wxString& pinName = aModel->
GetPin( aModelPinIndex ).
name;
987 wxString pinNumber = wxString::Format(
"%d", aModelPinIndex + 1 );
989 if( !pinName.IsEmpty() && pinName != pinNumber )
990 pinNumber += wxString::Format( wxT(
" (%s)" ), pinName );
996template <
typename T_symbol,
typename T_field>
999 if( aModelPinString ==
"Not Connected" )
1002 int length = aModelPinString.Find(
" " );
1004 if( length == wxNOT_FOUND )
1005 length =
static_cast<int>( aModelPinString.Length() );
1008 aModelPinString.Mid( 0, length ).ToCLong( &result );
1010 return static_cast<int>( result - 1 );
1014template <
typename T_symbol,
typename T_field>
1017 bool fromLibrary = m_rbLibraryModel->GetValue();
1019 m_pathLabel->Enable( fromLibrary );
1020 m_libraryPathText->Enable( fromLibrary );
1021 m_browseButton->Enable( fromLibrary );
1022 m_modelNameLabel->Enable( fromLibrary );
1023 m_modelNameChoice->Enable( fromLibrary );
1024 m_ibisPinLabel->Enable( fromLibrary );
1025 m_ibisPinCombobox->Enable( fromLibrary );
1026 m_differentialCheckbox->Enable( fromLibrary );
1027 m_ibisModelLabel->Enable( fromLibrary );
1028 m_ibisModelCombobox->Enable( fromLibrary );
1030 m_staticTextDevType->Enable( !fromLibrary );
1031 m_deviceTypeChoice->Enable( !fromLibrary );
1032 m_staticTextSpiceType->Enable( !fromLibrary );
1038template <
typename T_symbol,
typename T_field>
1041 if( m_rbLibraryModel->GetValue() )
1043 wxString
path = m_libraryPathText->GetValue();
1045 if( !
path.IsEmpty() )
1049 loadLibrary(
path );
1061template <
typename T_symbol,
typename T_field>
1064 if( !m_inKillFocus )
1066 m_inKillFocus =
true;
1068 wxCommandEvent
dummy;
1069 onLibraryPathTextEnter(
dummy );
1071 m_inKillFocus =
false;
1076template <
typename T_symbol,
typename T_field>
1079 static wxString s_mruPath;
1082 wxFileDialog dlg(
this,
_(
"Browse Models" ),
path );
1084 if( dlg.ShowModal() == wxID_CANCEL )
1087 path = dlg.GetPath();
1088 wxFileName fn(
path );
1090 s_mruPath = fn.GetPath();
1092 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS(
".." ) ) )
1093 path = fn.GetFullPath();
1095 loadLibrary(
path,
true );
1100template <
typename T_symbol,
typename T_field>
1103 if( isIbisLoaded() )
1105 wxArrayString pinLabels;
1108 wxCHECK2( modelkibis,
return );
1110 for( std::pair<wxString, wxString> strs : modelkibis->
GetIbisPins() )
1111 pinLabels.Add( strs.first + wxT(
" - " ) + strs.second );
1113 m_ibisPinCombobox->Set( pinLabels );
1115 wxArrayString emptyArray;
1116 m_ibisModelCombobox->Set( emptyArray );
1123template <
typename T_symbol,
typename T_field>
1126 if( isIbisLoaded() )
1128 wxArrayString modelLabels;
1132 std::vector<std::pair<std::string, std::string>> strs = ibisModel.
GetIbisPins();
1133 std::string pinNumber = strs.at( m_ibisPinCombobox->GetSelection() ).first;
1137 ibisModel.
ChangePin( *ibisLibrary, pinNumber );
1142 modelLabels.Add( modelName );
1144 m_ibisModelCombobox->Set( modelLabels );
1151template <
typename T_symbol,
typename T_field>
1154 m_ibisPinCombobox->SetSelection(
1155 m_ibisPinCombobox->FindString( m_ibisPinCombobox->GetValue() ) );
1157 onIbisPinCombobox( aEvent );
1161template <
typename T_symbol,
typename T_field>
1168template <
typename T_symbol,
typename T_field>
1171 m_ibisModelCombobox->SetSelection(
1172 m_ibisModelCombobox->FindString( m_ibisModelCombobox->GetValue() ) );
1174 onIbisPinCombobox( aEvent );
1177template <
typename T_symbol,
typename T_field>
1180 if( isIbisLoaded() )
1184 wxCHECK( modelkibis, );
1186 bool diff = m_differentialCheckbox->GetValue() && modelkibis->
CanDifferential();
1194template <
typename T_symbol,
typename T_field>
1197 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
1201 m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
1210template <
typename T_symbol,
typename T_field>
1213 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1214 wxString typeDescription = m_typeChoice->GetString( m_typeChoice->GetSelection() );
1216 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1222 && ( type == SIM_MODEL::TYPE::KIBIS_DEVICE
1223 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
1224 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
1225 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS ) )
1227 int idx = m_modelNameChoice->GetSelection();
1229 auto& baseModel =
static_cast<SIM_MODEL_KIBIS&
>( m_libraryModelsMgr.GetModels()[idx].get() );
1231 m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_KIBIS>( type, baseModel ) );
1235 m_libraryModelsMgr.GetModels()[idx].get().
ReadDataFields( &m_fields,
1244 m_curModelType = type;
1249 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1254template <
typename T_symbol,
typename T_field>
1257 updateModelCodeTab( &curModel() );
1261template <
typename T_symbol,
typename T_field>
1264 int symbolPinIndex = aEvent.GetRow();
1265 wxString oldModelPinName = aEvent.GetString();
1266 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
1268 int oldModelPinIndex = getModelPinIndex( oldModelPinName );
1269 int modelPinIndex = getModelPinIndex( modelPinName );
1272 curModel().SetPinSymbolPinNumber( oldModelPinIndex,
"" );
1276 curModel().SetPinSymbolPinNumber( modelPinIndex,
1277 std::string( m_sortedPartPins.at( symbolPinIndex )->GetShownNumber().ToUTF8() ) );
1280 updatePinAssignments( &curModel() );
1286template <
typename T_symbol,
typename T_field>
1289 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
1292 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::MODEL, gridWidth / 2 );
1293 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::SYMBOL, gridWidth / 2 );
1299template <
typename T_symbol,
typename T_field>
1305 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1306 wxPGProperty* selected =
grid->GetSelection();
1309 selected =
grid->wxPropertyGridInterface::GetFirst();
1311#if wxCHECK_VERSION( 3, 3, 0 )
1313 grid->DoSelectProperty( selected, wxPGSelectPropertyFlags::Focus );
1316 grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
1323template <
typename T_symbol,
typename T_field>
1326 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1329 if(
grid->GetSelection() &&
grid->GetSelection()->IsCategory() )
1331 wxPGProperty* selection =
grid->GetSelection();
1336 wxPropertyGridIterator it =
grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
1339 wxKeyEvent* keyEvent =
new wxKeyEvent( wxEVT_KEY_DOWN );
1341 if( *it == m_prevParamGridSelection )
1343 if( !selection->IsExpanded() )
1345 grid->Expand( selection );
1346 keyEvent->m_keyCode = WXK_DOWN;
1347 wxQueueEvent(
grid, keyEvent );
1355 keyEvent->m_keyCode = WXK_UP;
1356 wxQueueEvent(
grid, keyEvent );
1361 if( !selection->IsExpanded() )
1362 grid->Expand( selection );
1364 keyEvent->m_keyCode = WXK_DOWN;
1365 wxQueueEvent(
grid, keyEvent );
1368 m_prevParamGridSelection =
grid->GetSelection();
1372 wxWindow* editorControl =
grid->GetEditorControl();
1374 if( !editorControl )
1376 m_prevParamGridSelection =
grid->GetSelection();
1381 editorControl->SetFocus();
1382 m_prevParamGridSelection =
grid->GetSelection();
1386template <
typename T_symbol,
typename T_field>
1397 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1398 wxTextCtrl* ctrl =
grid->GetEditorTextCtrl();
1402 wxRect ctrlRect = ctrl->GetScreenRect();
1403 wxRect gridRect =
grid->GetScreenRect();
1405 if( ctrlRect.GetTop() < gridRect.GetTop() || ctrlRect.GetBottom() > gridRect.GetBottom() )
1406 grid->ClearSelection();
1412template <
typename T_symbol,
typename T_field>
1415 wxPropertyGrid*
grid = m_paramGridMgr->GetGrid();
1419 if( aWidth != m_lastParamGridWidth || aForce )
1421 m_lastParamGridWidth = aWidth;
1425 std::vector<int> colWidths;
1427 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1429 if( ii == PARAM_COLUMN::DESCRIPTION )
1430 colWidths.push_back(
grid->GetState()->GetColumnWidth( ii ) + margin + indent );
1431 else if( ii == PARAM_COLUMN::VALUE )
1432 colWidths.push_back( std::max( 72,
grid->GetState()->GetColumnWidth( ii ) ) + margin );
1434 colWidths.push_back( 60 + margin );
1436 aWidth -= colWidths[ ii ];
1439 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1440 grid->SetColumnProportion( ii, colWidths[ ii ] );
1442 grid->ResetColumnSizes();
1443 grid->RefreshEditor();
1448template <
typename T_symbol,
typename T_field>
1451 adjustParamGridColumns( event.GetSize().GetX(),
false );
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
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
WX_GRID * m_pinAssignmentsGrid
STD_BITMAP_BUTTON * m_browseButton
wxPropertyGridPage * m_paramGrid
wxStyledTextCtrl * m_codePreview
void onTypeChoice(wxCommandEvent &aEvent) override
void onRadioButton(wxCommandEvent &aEvent) override
void updateBuiltinModelWidgets(SIM_MODEL *aModel)
std::vector< LIB_PIN * > m_sortedPartPins
SCINTILLA_TRICKS * m_scintillaTricks
DIALOG_SIM_MODEL(wxWindow *aParent, T_symbol &aSymbol, std::vector< T_field > &aFields)
bool loadLibrary(const wxString &aLibraryPath, bool aForceReload=false)
wxString getModelPinString(SIM_MODEL *aModel, int aModelPinIndex) const
void removeOrphanedPinAssignments(SIM_MODEL *aModel)
void onPinAssignmentsGridCellChange(wxGridEvent &aEvent) override
void onPageChanging(wxNotebookEvent &event) override
void onParamGridSelectionChange(wxPropertyGridEvent &aEvent)
void onUpdateUI(wxUpdateUIEvent &aEvent)
int findSymbolPinRow(const wxString &aSymbolPinNumber) const
void adjustParamGridColumns(int aWidth, bool aForce)
void updateIbisWidgets(SIM_MODEL *aModel)
void onDeviceTypeChoice(wxCommandEvent &aEvent) override
const SIM_LIBRARY * library() const
SIM_MODEL & curModel() const
int getModelPinIndex(const wxString &aModelPinString) const
void onSizeParamGrid(wxSizeEvent &event) override
void updateModelCodeTab(SIM_MODEL *aModel)
bool TransferDataToWindow() override
void onLibraryPathTextEnter(wxCommandEvent &aEvent) override
void onBrowseButtonClick(wxCommandEvent &aEvent) override
void addParamPropertyIfRelevant(SIM_MODEL *aModel, int aParamIndex)
wxString getSymbolPinString(int aSymbolPinNumber) const
void onIbisModelCombobox(wxCommandEvent &event) override
wxPGProperty * newParamProperty(SIM_MODEL *aModel, int aParamIndex) const
bool TransferDataFromWindow() override
void onDifferentialCheckbox(wxCommandEvent &event) override
void onIbisModelComboboxTextEnter(wxCommandEvent &event) override
void onLibraryPathTextKillFocus(wxFocusEvent &aEvent) override
void onIbisPinComboboxTextEnter(wxCommandEvent &event) override
void onModelNameChoice(wxCommandEvent &aEvent) override
void updateModelParamsTab(SIM_MODEL *aModel)
void onParamGridSetFocus(wxFocusEvent &aEvent)
void onIbisPinCombobox(wxCommandEvent &event) override
void onPinAssignmentsGridSize(wxSizeEvent &aEvent) override
void updatePinAssignments(SIM_MODEL *aModel)
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 const wxString GetProjectPath() const
Return the full path of the project.
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
static bool InferSimModel(T_symbol &aSymbol, std::vector< T_field > *aFields, bool aResolve, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
static INFO TypeInfo(TYPE aType)
void ReadDataFields(const std::vector< T > *aFields, const std::vector< LIB_PIN * > &aPins)
static void SetFieldValue(std::vector< T > &aFields, const wxString &aFieldName, const std::string &aValue)
const SPICE_GENERATOR & SpiceGenerator() const
static std::string GetFieldValue(const std::vector< T > *aFields, const wxString &aFieldName, bool aResolve=true)
virtual const PARAM & GetParam(unsigned aParamIndex) const
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
static TYPE ReadTypeFromFields(const std::vector< T > &aFields, REPORTER *aReporter)
virtual bool HasPrimaryValue() const
const SIM_MODEL::PARAM & GetParam() const
virtual std::string Preview(const SPICE_ITEM &aItem) const
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)
wxFont GetInfoFont(wxWindow *aWindow)
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
#define SIM_DEVICE_TYPE_FIELD
#define SIM_REFERENCE_FIELD
std::vector< FAB_LAYER_COLOR > dummy
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".