43#include <wx/filedlg.h>
44#include <wx/textfile.h>
45#include <fmt/format.h>
50template <
typename T_symbol,
typename T_field>
52 std::vector<T_field>& aFields )
56 m_libraryModelsMgr( &
Prj() ),
57 m_builtinModelsMgr( &
Prj() ),
58 m_prevModel( nullptr ),
60 m_scintillaTricks( nullptr ),
61 m_firstCategory( nullptr ),
62 m_prevParamGridSelection( nullptr ),
63 m_lastParamGridWidth( 0 ),
64 m_inKillFocus( false )
74 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
84 m_paramGrid->SetValidationFailureBehavior( wxPG_VFB_STAY_IN_PROPERTY
86 | wxPG_VFB_MARK_CELL );
94 grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
98 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
99 grid->DedicateKey( WXK_RETURN );
100 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
102 grid->DedicateKey( WXK_UP );
103 grid->DedicateKey( WXK_DOWN );
114template <
typename T_symbol,
typename T_field>
119 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
130 m_pinAssignmentsGrid->PopEventHandler(
true );
132 delete m_scintillaTricks;
136template <
typename T_symbol,
typename T_field>
139 wxCommandEvent dummyEvent;
142 wxString modelParams;
144 bool storeInValue =
false;
148 &deviceType, &modelType, &modelParams, &pinMap ) )
151 m_fields.back().SetText( deviceType );
153 if( !modelType.IsEmpty() )
156 m_fields.back().SetText( modelType );
160 m_fields.back().SetText( modelParams );
163 m_fields.back().SetText( pinMap );
169 m_fields[
VALUE_FIELD ].SetText( wxT(
"${SIM.PARAMS}" ) );
174 if( libraryFilename !=
"" )
177 m_useLibraryModelRadioButton->SetValue(
true );
179 if( !loadLibrary( libraryFilename ) )
181 m_libraryPathText->ChangeValue( libraryFilename );
182 m_modelNameChoice->SetSelection( -1 );
188 int modelIdx = m_modelNameChoice->FindString( modelName );
190 if( modelIdx == wxNOT_FOUND )
196 m_modelNameChoice->SetSelection( 0 );
200 m_modelNameChoice->SetSelection( modelIdx );
203 m_curModelType = curModel().GetType();
206 if( isIbisLoaded() && ( m_modelNameChoice->GetSelection() >= 0 ) )
208 int idx = m_modelNameChoice->GetSelection();
209 auto kibismodel =
dynamic_cast<SIM_MODEL_KIBIS*
>( &m_libraryModelsMgr.GetModels().at( idx ).get() );
213 onModelNameChoice( dummyEvent );
217 for(
const std::pair<std::string, std::string>& strs : kibismodel->GetIbisPins() )
223 kibismodel->ChangePin( *kibisLibrary, strs.first );
224 m_ibisPinCombobox->SetSelection(
static_cast<int>( i ) );
230 if( i <
static_cast<int>( kibismodel->GetIbisPins().size() ) )
232 onIbisPinCombobox( dummyEvent );
234 m_ibisModelCombobox->SetStringSelection(
240 kibismodel->SwitchSingleEndedDiff(
true );
241 m_differentialCheckbox->SetValue(
true );
245 kibismodel->SwitchSingleEndedDiff(
false );
246 m_differentialCheckbox->SetValue(
false );
254 m_useInstanceModelRadioButton->SetValue(
true );
258 std::vector<LIB_PIN*> sourcePins = m_symbol.GetAllLibPins();
260 std::sort( sourcePins.begin(), sourcePins.end(),
263 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
271 m_builtinModelsMgr.SetReporter( &reporter );
273 if( m_useInstanceModelRadioButton->GetValue() && type == m_curModelType )
274 m_builtinModelsMgr.CreateModel( m_fields, sourcePins,
false );
276 m_builtinModelsMgr.CreateModel( type, sourcePins );
281 + wxT(
"\n\n" ) + msg );
286 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
287 m_curModelTypeOfDeviceType[deviceTypeT] = type;
291 curModel().SetIsStoredInValue(
true );
293 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
295 onRadioButton( dummyEvent );
296 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
300template <
typename T_symbol,
typename T_field>
303 m_pinAssignmentsGrid->CommitPendingChanges();
307 m_paramGrid->GetGrid()->EditorsValueWasModified();
308 m_paramGrid->GetGrid()->CommitChangesFromEditor();
310 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
313 if( !m_modelNameChoice->IsEmpty() )
315 std::string modelName = m_modelNameChoice->GetStringSelection().ToStdString();
322 if( m_useLibraryModelRadioButton->GetValue() || isIbisLoaded() )
324 path = m_libraryPathText->GetValue();
325 wxFileName fn(
path );
327 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith(
".." ) )
328 path = fn.GetFullPath();
336 &m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get() );
342 ibismodel->
GetIbisPins().at( m_ibisPinCombobox->GetSelection() ).first );
346 std::string( m_ibisModelCombobox->GetValue().c_str() ) );
350 ibismodel->
CanDifferential() && m_differentialCheckbox->GetValue() ?
"1" :
"" );
354 if( curModel().GetType() == SIM_MODEL::TYPE::RAWSPICE )
356 wxString code = m_codePreview->GetText().Trim(
true ).Trim(
false );
357 curModel().SetParamValue(
"model", std::string( code.ToUTF8() ) );
360 curModel().SetIsStoredInValue( m_saveInValueCheckbox->GetValue() );
362 curModel().WriteFields( m_fields );
368template <
typename T_symbol,
typename T_field>
372 updateInstanceWidgets();
373 updateModelParamsTab();
374 updateModelCodeTab();
375 updatePinAssignments();
379 m_modelPanel->Layout();
380 m_pinAssignmentsPanel->Layout();
381 m_parametersPanel->Layout();
382 m_codePanel->Layout();
384 SendSizeEvent( wxSEND_EVENT_POST );
386 m_prevModel = &curModel();
390template <
typename T_symbol,
typename T_field>
396 m_ibisModelCombobox->Show( isIbisLoaded() );
397 m_ibisPinCombobox->Show( isIbisLoaded() );
398 m_ibisModelLabel->Show( isIbisLoaded() );
399 m_ibisPinLabel->Show( isIbisLoaded() );
401 m_differentialCheckbox->Show( isIbisLoaded() && modelkibis && modelkibis->
CanDifferential() );
402 m_modelNameLabel->SetLabel( isIbisLoaded() ?
_(
"Component:" ) :
_(
"Model:" ) );
406template <
typename T_symbol,
typename T_field>
410 if( &curModel() != m_prevModel )
412 m_deviceTypeChoice->Clear();
414 if( m_useLibraryModelRadioButton->GetValue() )
416 m_deviceTypeChoice->Append( curModel().GetDeviceInfo().description );
417 m_deviceTypeChoice->SetSelection( 0 );
421 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
428 if( deviceType == curModel().GetDeviceType() )
429 m_deviceTypeChoice->SetSelection( m_deviceTypeChoice->GetCount() - 1 );
433 m_typeChoice->Clear();
441 if( type == curModel().GetType() )
442 m_typeChoice->SetSelection( m_typeChoice->GetCount() - 1 );
447 m_typeChoice->Enable( !m_useLibraryModelRadioButton->GetValue() || isIbisLoaded() );
452 m_modelNotebook->SetSelection( 1 );
456 m_modelNotebook->SetSelection( 0 );
459 if( curModel().HasPrimaryValue() )
463 m_saveInValueCheckbox->SetLabel(
wxString::Format(
_(
"Save parameter '%s (%s)' in Value "
467 m_saveInValueCheckbox->Enable(
true );
471 m_saveInValueCheckbox->SetLabel(
_(
"Save primary parameter in Value field" ) );
472 m_saveInValueCheckbox->SetValue(
false );
473 m_saveInValueCheckbox->Enable(
false );
478template <
typename T_symbol,
typename T_field>
481 if( &curModel() != m_prevModel )
486 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
488 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION,
_(
"Parameter" ) );
489 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT,
_(
"Unit" ) );
490 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT,
_(
"Default" ) );
493 m_paramGridMgr->ShowHeader();
496 m_paramGrid->Clear();
498 m_firstCategory = m_paramGrid->Append(
new wxPropertyCategory(
"Geometry" ) );
499 m_paramGrid->HideProperty(
"Geometry" );
501 m_paramGrid->Append(
new wxPropertyCategory(
"AC" ) );
502 m_paramGrid->HideProperty(
"AC" );
504 m_paramGrid->Append(
new wxPropertyCategory(
"DC" ) );
505 m_paramGrid->HideProperty(
"DC" );
507 m_paramGrid->Append(
new wxPropertyCategory(
"Capacitance" ) );
508 m_paramGrid->HideProperty(
"Capacitance" );
510 m_paramGrid->Append(
new wxPropertyCategory(
"Temperature" ) );
511 m_paramGrid->HideProperty(
"Temperature" );
513 m_paramGrid->Append(
new wxPropertyCategory(
"Noise" ) );
514 m_paramGrid->HideProperty(
"Noise" );
516 m_paramGrid->Append(
new wxPropertyCategory(
"Distributed Quantities" ) );
517 m_paramGrid->HideProperty(
"Distributed Quantities" );
519 m_paramGrid->Append(
new wxPropertyCategory(
"Waveform" ) );
520 m_paramGrid->HideProperty(
"Waveform" );
522 m_paramGrid->Append(
new wxPropertyCategory(
"Limiting Values" ) );
523 m_paramGrid->HideProperty(
"Limiting Values" );
525 m_paramGrid->Append(
new wxPropertyCategory(
"Advanced" ) );
526 m_paramGrid->HideProperty(
"Advanced" );
528 m_paramGrid->Append(
new wxPropertyCategory(
"Flags" ) );
529 m_paramGrid->HideProperty(
"Flags" );
531 m_paramGrid->CollapseAll();
533 for(
int i = 0; i < curModel().GetParamCount(); ++i )
534 addParamPropertyIfRelevant( i );
536 m_paramGrid->CollapseAll();
537 m_paramGrid->Expand(
"AC" );
538 m_paramGrid->Expand(
"Waveform" );
541 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(),
true );
545 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
547 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
548 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
550 for(
int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
552 ( *it )->GetCell( col ).SetBgCol( bgCol );
553 ( *it )->GetCell( col ).SetFgCol( fgCol );
566 if( curModel().HasAutofill() )
567 ( *it )->SetValueFromString( param.
value->ToString() );
572template <
typename T_symbol,
typename T_field>
578 item.
modelName = m_modelNameChoice->GetStringSelection();
580 if( m_useInstanceModelRadioButton->GetValue() || item.
modelName ==
"" )
583 text << curModel().SpiceGenerator().Preview( item );
585 m_codePreview->SetText(
text );
586 m_codePreview->SelectNone();
590template <
typename T_symbol,
typename T_field>
593 removeOrphanedPinAssignments();
597 m_pinAssignmentsGrid->ClearRows();
598 m_pinAssignmentsGrid->AppendRows(
static_cast<int>( m_sortedPartPins.size() ) );
600 for(
int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
601 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL,
_(
"Not Connected" ) );
604 for(
int modelPinIndex = 0; modelPinIndex < curModel().GetPinCount(); ++modelPinIndex )
606 wxString symbolPinNumber = curModel().GetPin( modelPinIndex ).symbolPinNumber;
608 if( symbolPinNumber ==
"" )
611 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
613 if( symbolPinRow == -1 )
616 wxString modelPinString = getModelPinString( modelPinIndex );
617 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
621 for(
int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
623 wxString symbolPinString = getSymbolPinString( ii );
625 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
626 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
628 wxString curModelPinString = m_pinAssignmentsGrid->GetCellValue( ii, PIN_COLUMN::MODEL );
630 std::vector<BITMAPS> modelPinIcons;
631 wxArrayString modelPinChoices;
633 for(
int jj = 0; jj < curModel().GetPinCount(); ++jj )
635 if( curModel().GetPin( jj ).symbolPinNumber !=
"" )
640 modelPinChoices.Add( getModelPinString( jj ) );
644 modelPinChoices.Add(
_(
"Not Connected" ) );
648 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
657 if( model->
GetType() == SIM_MODEL::TYPE::SUBCKT )
664 m_subcktLabel->Show(
false );
665 m_subckt->Show(
false );
670template <
typename T_symbol,
typename T_field>
673 for(
int i = 0; i < curModel().GetPinCount(); ++i )
675 if( !m_symbol.GetPin( curModel().GetPin( i ).symbolPinNumber ) )
676 curModel().SetPinSymbolPinNumber( i,
"" );
681template <
typename T_symbol,
typename T_field>
688 m_libraryModelsMgr.SetReporter( &reporter );
689 m_libraryModelsMgr.SetLibrary( aLibraryPath );
697 std::vector<LIB_PIN*> sourcePins = m_symbol.GetAllLibPins();
699 std::sort( sourcePins.begin(), sourcePins.end(),
702 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
707 for(
auto& [baseModelName, baseModel] :
library()->GetModels() )
709 if( baseModelName == modelName )
710 m_libraryModelsMgr.CreateModel( &baseModel, sourcePins, m_fields );
712 m_libraryModelsMgr.CreateModel( &baseModel, sourcePins );
718 m_useLibraryModelRadioButton->SetValue(
true );
719 m_libraryPathText->ChangeValue( aLibraryPath );
721 wxArrayString modelNames;
723 for(
auto& [
name, model] :
library()->GetModels() )
724 modelNames.Add(
name );
726 m_modelNameChoice->Clear();
727 m_modelNameChoice->Append( modelNames );
731 wxArrayString emptyArray;
732 m_ibisModelCombobox->Set( emptyArray );
733 m_ibisPinCombobox->Set( emptyArray );
734 m_ibisModelCombobox->SetSelection( -1 );
735 m_ibisPinCombobox->SetSelection( -1 );
742template <
typename T_symbol,
typename T_field>
748 switch( curModel().GetParam( aParamIndex ).
info.category )
751 m_paramGrid->HideProperty(
"AC",
false );
752 m_paramGrid->AppendIn(
"AC", newParamProperty( aParamIndex ) );
756 m_paramGrid->HideProperty(
"DC",
false );
757 m_paramGrid->AppendIn(
"DC", newParamProperty( aParamIndex ) );
761 m_paramGrid->HideProperty(
"Capacitance",
false );
762 m_paramGrid->AppendIn(
"Capacitance", newParamProperty( aParamIndex ) );
766 m_paramGrid->HideProperty(
"Temperature",
false );
767 m_paramGrid->AppendIn(
"Temperature", newParamProperty( aParamIndex ) );
771 m_paramGrid->HideProperty(
"Noise",
false );
772 m_paramGrid->AppendIn(
"Noise", newParamProperty( aParamIndex ) );
776 m_paramGrid->HideProperty(
"Distributed Quantities",
false );
777 m_paramGrid->AppendIn(
"Distributed Quantities", newParamProperty( aParamIndex ) );
781 m_paramGrid->HideProperty(
"Waveform",
false );
782 m_paramGrid->AppendIn(
"Waveform", newParamProperty( aParamIndex ) );
786 m_paramGrid->HideProperty(
"Geometry",
false );
787 m_paramGrid->AppendIn(
"Geometry", newParamProperty( aParamIndex ) );
791 m_paramGrid->HideProperty(
"Limiting Values",
false );
792 m_paramGrid->AppendIn(
"Limiting Values", newParamProperty( aParamIndex ) );
796 m_paramGrid->HideProperty(
"Advanced",
false );
797 m_paramGrid->AppendIn(
"Advanced", newParamProperty( aParamIndex ) );
801 m_paramGrid->HideProperty(
"Flags",
false );
802 m_paramGrid->AppendIn(
"Flags", newParamProperty( aParamIndex ) );
806 m_paramGrid->Insert( m_firstCategory, newParamProperty( aParamIndex ) );
816template <
typename T_symbol,
typename T_field>
820 wxString paramDescription;
827 wxPGProperty* prop =
nullptr;
834 prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX,
true );
864 prop =
new wxStringProperty( paramDescription, param.
info.
name );
868 prop->SetAttribute( wxPG_ATTR_UNITS, wxString::FromUTF8( param.
info.
unit.c_str() ) );
871 #if wxCHECK_VERSION( 3, 1, 0 )
904template <
typename T_symbol,
typename T_field>
907 for(
int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
911 if(
pin->GetNumber() == aSymbolPinNumber )
919template <
typename T_symbol,
typename T_field>
922 if( m_useLibraryModelRadioButton->GetValue()
923 && m_modelNameChoice->GetSelection() != wxNOT_FOUND )
925 return m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get();
929 return m_builtinModelsMgr.GetModels().at(
static_cast<int>( m_curModelType ) );
934template <
typename T_symbol,
typename T_field>
937 if( m_libraryModelsMgr.GetLibraries().size() == 1 )
938 return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
944template <
typename T_symbol,
typename T_field>
947 LIB_PIN*
pin = m_sortedPartPins.at( symbolPinIndex );
953 pinNumber =
pin->GetShownNumber();
954 pinName =
pin->GetShownName();
957 if( !pinName.IsEmpty() && pinName != pinNumber )
964template <
typename T_symbol,
typename T_field>
967 const wxString& pinName = curModel().GetPin( aModelPinIndex ).name;
973 if( !pinName.IsEmpty() && pinName != pinNumber )
980template <
typename T_symbol,
typename T_field>
983 if( aModelPinString ==
"Not Connected" )
986 int length = aModelPinString.Find(
" " );
988 if( length == wxNOT_FOUND )
989 length =
static_cast<int>( aModelPinString.Length() );
992 aModelPinString.Mid( 0, length ).ToCLong( &result );
994 return static_cast<int>( result - 1 );
998template <
typename T_symbol,
typename T_field>
1001 bool fromLibrary = m_useLibraryModelRadioButton->GetValue();
1003 m_pathLabel->Enable( fromLibrary );
1004 m_libraryPathText->Enable( fromLibrary );
1005 m_browseButton->Enable( fromLibrary );
1006 m_modelNameLabel->Enable( fromLibrary );
1007 m_modelNameChoice->Enable( fromLibrary );
1008 m_ibisPinLabel->Enable( fromLibrary );
1009 m_ibisPinCombobox->Enable( fromLibrary );
1010 m_differentialCheckbox->Enable( fromLibrary );
1011 m_ibisModelLabel->Enable( fromLibrary );
1012 m_ibisModelCombobox->Enable( fromLibrary );
1014 m_staticTextDevType->Enable( !fromLibrary );
1015 m_deviceTypeChoice->Enable( !fromLibrary );
1016 m_staticTextSpiceType->Enable( !fromLibrary );
1022template <
typename T_symbol,
typename T_field>
1025 if( m_useLibraryModelRadioButton->GetValue() )
1027 wxString
path = m_libraryPathText->GetValue();
1029 if( !
path.IsEmpty() )
1033 loadLibrary(
path );
1045template <
typename T_symbol,
typename T_field>
1048 if( !m_inKillFocus )
1050 m_inKillFocus =
true;
1052 wxCommandEvent
dummy;
1053 onLibraryPathTextEnter(
dummy );
1055 m_inKillFocus =
false;
1060template <
typename T_symbol,
typename T_field>
1063 static wxString s_mruPath;
1066 wxFileDialog dlg(
this,
_(
"Browse Models" ),
path );
1068 if( dlg.ShowModal() == wxID_CANCEL )
1071 path = dlg.GetPath();
1072 wxFileName fn(
path );
1074 s_mruPath = fn.GetPath();
1076 if( fn.MakeRelativeTo(
Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS(
".." ) ) )
1077 path = fn.GetFullPath();
1079 loadLibrary(
path,
true );
1084template <
typename T_symbol,
typename T_field>
1087 if( isIbisLoaded() )
1089 wxArrayString pinLabels;
1092 wxCHECK2( modelkibis,
return );
1094 for( std::pair<wxString, wxString> strs : modelkibis->
GetIbisPins() )
1095 pinLabels.Add( strs.first + wxT(
" - " ) + strs.second );
1097 m_ibisPinCombobox->Set( pinLabels );
1099 wxArrayString emptyArray;
1100 m_ibisModelCombobox->Set( emptyArray );
1107template <
typename T_symbol,
typename T_field>
1110 if( isIbisLoaded() )
1112 wxArrayString modelLabels;
1116 std::vector<std::pair<std::string, std::string>> strs = ibisModel.
GetIbisPins();
1117 std::string pinNumber = strs.at( m_ibisPinCombobox->GetSelection() ).first;
1121 ibisModel.
ChangePin( *ibisLibrary, pinNumber );
1126 modelLabels.Add( modelName );
1128 m_ibisModelCombobox->Set( modelLabels );
1135template <
typename T_symbol,
typename T_field>
1138 m_ibisPinCombobox->SetSelection(
1139 m_ibisPinCombobox->FindString( m_ibisPinCombobox->GetValue() ) );
1141 onIbisPinCombobox( aEvent );
1145template <
typename T_symbol,
typename T_field>
1152template <
typename T_symbol,
typename T_field>
1155 m_ibisModelCombobox->SetSelection(
1156 m_ibisModelCombobox->FindString( m_ibisModelCombobox->GetValue() ) );
1158 onIbisPinCombobox( aEvent );
1161template <
typename T_symbol,
typename T_field>
1164 if( isIbisLoaded() )
1167 bool diff = m_differentialCheckbox->GetValue() && modelkibis->
CanDifferential();
1175template <
typename T_symbol,
typename T_field>
1178 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
1182 m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
1191template <
typename T_symbol,
typename T_field>
1194 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1195 wxString typeDescription = m_typeChoice->GetString( m_typeChoice->GetSelection() );
1196 std::vector<LIB_PIN*> sourcePins = m_symbol.GetAllLibPins();
1198 std::sort( sourcePins.begin(), sourcePins.end(),
1201 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
1210 && ( type == SIM_MODEL::TYPE::KIBIS_DEVICE
1211 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
1212 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
1213 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS ) )
1215 int idx = m_modelNameChoice->GetSelection();
1217 auto& kibisModel =
static_cast<SIM_MODEL_KIBIS&
>( m_libraryModelsMgr.GetModels().at( idx ).get() );
1219 m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_KIBIS>( type, kibisModel,
1220 m_fields, sourcePins ) );
1223 m_curModelType = type;
1228 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1233template <
typename T_symbol,
typename T_field>
1238 m_paramGrid->GetGrid()->EditorsValueWasModified();
1239 m_paramGrid->GetGrid()->CommitChangesFromEditor();
1241 updateModelCodeTab();
1245template <
typename T_symbol,
typename T_field>
1248 int symbolPinIndex = aEvent.GetRow();
1249 wxString oldModelPinName = aEvent.GetString();
1250 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
1252 int oldModelPinIndex = getModelPinIndex( oldModelPinName );
1253 int modelPinIndex = getModelPinIndex( modelPinName );
1256 curModel().SetPinSymbolPinNumber( oldModelPinIndex,
"" );
1260 curModel().SetPinSymbolPinNumber( modelPinIndex,
1261 std::string( m_sortedPartPins.at( symbolPinIndex )->GetShownNumber().ToUTF8() ) );
1264 updatePinAssignments();
1270template <
typename T_symbol,
typename T_field>
1273 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
1276 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::MODEL, gridWidth / 2 );
1277 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::SYMBOL, gridWidth / 2 );
1283template <
typename T_symbol,
typename T_field>
1289 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1291 grid->CommitChangesFromEditor();
1293 wxPGProperty* selected =
grid->GetSelection();
1296 selected =
grid->wxPropertyGridInterface::GetFirst();
1299 grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
1305template <
typename T_symbol,
typename T_field>
1308 wxPropertyGrid*
grid = m_paramGrid->GetGrid();
1310 grid->CommitChangesFromEditor();
1313 if(
grid->GetSelection() &&
grid->GetSelection()->IsCategory() )
1315 wxPGProperty* selection =
grid->GetSelection();
1320 wxPropertyGridIterator it =
grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
1323 wxKeyEvent* keyEvent =
new wxKeyEvent( wxEVT_KEY_DOWN );
1325 if( *it == m_prevParamGridSelection )
1327 if( !selection->IsExpanded() )
1329 grid->Expand( selection );
1330 keyEvent->m_keyCode = WXK_DOWN;
1331 wxQueueEvent(
grid, keyEvent );
1339 keyEvent->m_keyCode = WXK_UP;
1340 wxQueueEvent(
grid, keyEvent );
1345 if( !selection->IsExpanded() )
1346 grid->Expand( selection );
1348 keyEvent->m_keyCode = WXK_DOWN;
1349 wxQueueEvent(
grid, keyEvent );
1352 m_prevParamGridSelection =
grid->GetSelection();
1356 wxWindow* editorControl =
grid->GetEditorControl();
1357 if( !editorControl )
1359 m_prevParamGridSelection =
grid->GetSelection();
1364 editorControl->SetFocus();
1365 m_prevParamGridSelection =
grid->GetSelection();
1369template <
typename T_symbol,
typename T_field>
1372 wxPropertyGrid*
grid = m_paramGridMgr->GetGrid();
1376 if( aWidth != m_lastParamGridWidth || aForce )
1378 m_lastParamGridWidth = aWidth;
1382 std::vector<int> colWidths;
1384 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1387 colWidths.push_back(
grid->GetState()->GetColumnWidth( ii ) + margin + indent );
1389 colWidths.push_back(
grid->GetState()->GetColumnWidth( ii ) + margin );
1391 colWidths.push_back( 50 );
1393 aWidth -= colWidths[ ii ];
1397 aWidth -= (
grid->GetSize().x -
grid->GetClientSize().x );
1400 colWidths[ PARAM_COLUMN::VALUE ] += aWidth;
1402 for(
size_t ii = 0; ii <
grid->GetColumnCount(); ii++ )
1403 grid->SetColumnProportion( ii, colWidths[ ii ] );
1405 grid->ResetColumnSizes();
1406 grid->RefreshEditor();
1411template <
typename T_symbol,
typename T_field>
1414 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
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)
void addParamPropertyIfRelevant(int aParamIndex)
void removeOrphanedPinAssignments()
void onPinAssignmentsGridCellChange(wxGridEvent &aEvent) override
void onPageChanging(wxNotebookEvent &event) override
void onParamGridSelectionChange(wxPropertyGridEvent &aEvent)
int findSymbolPinRow(const wxString &aSymbolPinNumber) const
void adjustParamGridColumns(int aWidth, bool aForce)
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
wxString getModelPinString(int aModelPinIndex) const
bool TransferDataToWindow() override
void onLibraryPathTextEnter(wxCommandEvent &aEvent) override
void onBrowseButtonClick(wxCommandEvent &aEvent) override
wxString getSymbolPinString(int aSymbolPinNumber) const
void onIbisModelCombobox(wxCommandEvent &event) override
void updateModelParamsTab()
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 updateInstanceWidgets()
void onParamGridSetFocus(wxFocusEvent &aEvent)
void onIbisPinCombobox(wxCommandEvent &event) override
void updatePinAssignments()
void updateModelCodeTab()
void onPinAssignmentsGridSize(wxSizeEvent &aEvent) override
wxPGProperty * newParamProperty(int aParamIndex) const
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.
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)
static void SetFieldValue(std::vector< T > &aFields, const wxString &aFieldName, const std::string &aValue)
static TYPE ReadTypeFromFields(const std::vector< T > &aFields)
static std::string GetFieldValue(const std::vector< T > *aFields, const wxString &aFieldName, bool aResolve=true)
static DEVICE_INFO DeviceInfo(DEVICE_T aDeviceType)
const SIM_MODEL::PARAM & GetParam() 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.
wxFont GetInfoFont(wxWindow *aWindow)
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
#define SIM_DEVICE_TYPE_FIELD
#define SIM_REFERENCE_FIELD
std::vector< FAB_LAYER_COLOR > dummy
std::vector< std::string > enumValues
std::string defaultValueOfOtherVariant
std::unique_ptr< SIM_VALUE > value
static constexpr auto NOT_CONNECTED
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".