KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_sim_model.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2022 Mikolaj Wielgus
5 * Copyright (C) 2022 CERN
6 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 3
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
23#include <dialog_sim_model.h>
24#include <sim/sim_property.h>
26#include <sim/sim_model.h>
28#include <sim/sim_model_ibis.h>
32#include <grid_tricks.h>
35#include <kiplatform/ui.h>
36#include <confirm.h>
37#include <string_utils.h>
38
39#include <wx/filedlg.h>
40#include <fmt/format.h>
41#include <sch_edit_frame.h>
42#include <widgets/wx_infobar.h>
46#include <wx/filedlg.h>
47#include <wx/log.h>
48
50
51#define FORCE_REFRESH_FROM_MODEL true
52
53
54bool equivalent( SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b )
55{
56 // A helper to handle SPICE's use of 'E' and 'H' for voltage sources and 'F' and 'G' for
57 // current sources
58 return a == b
59 || SIM_MODEL::DeviceInfo( a ).description == SIM_MODEL::DeviceInfo( b ).description;
60};
61
62
63template <typename T>
64DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, T& aSymbol,
65 std::vector<SCH_FIELD>& aFields ) :
66 DIALOG_SIM_MODEL_BASE( aParent ),
67 m_frame( aFrame ),
68 m_symbol( aSymbol ),
69 m_fields( aFields ),
73 m_prevModel( nullptr ),
75 m_scintillaTricksCode( nullptr ),
76 m_scintillaTricksSubckt( nullptr ),
77 m_firstCategory( nullptr ),
78 m_prevParamGridSelection( nullptr ),
80{
82 m_infoBar->AddCloseButton();
83
84 if constexpr (std::is_same_v<T, SCH_SYMBOL>)
85 {
86 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( &aSymbol );
87 m_filesStack.push_back( symbol->Schematic()->GetEmbeddedFiles() );
88 }
89
90 if( EMBEDDED_FILES* symbolEmbeddedFiles = aSymbol.GetEmbeddedFiles() )
91 {
92 m_filesStack.push_back( symbolEmbeddedFiles );
93
94 if constexpr (std::is_same_v<T, SCH_SYMBOL>)
95 {
96 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( &aSymbol );
97 symbol->GetLibSymbolRef()->AppendParentEmbeddedFiles( m_filesStack );
98 }
99 else if constexpr (std::is_same_v<T, LIB_SYMBOL>)
100 {
101 LIB_SYMBOL* symbol = static_cast<LIB_SYMBOL*>( &aSymbol );
103 }
104 }
105
106 m_libraryModelsMgr.SetFilesStack( m_filesStack );
107 m_builtinModelsMgr.SetFilesStack( m_filesStack );
108
109 for( SCH_PIN* pin : aSymbol.GetPins() )
110 {
111 // Body styles (including De Morgan variants) are equivalences, not additional items to simulate
112 if( !pin->GetParentSymbol()->IsMultiBodyStyle() || pin->GetBodyStyle() < 2 )
113 m_sortedPartPins.push_back( pin );
114 }
115
116 std::sort( m_sortedPartPins.begin(), m_sortedPartPins.end(),
117 []( const SCH_PIN* lhs, const SCH_PIN* rhs )
118 {
119 // We sort by StrNumCmp because SIM_MODEL_BASE sorts with it too.
120 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
121 } );
122
123 m_waveformChoice->Clear();
124 m_deviceChoice->Clear();
125 m_deviceSubtypeChoice->Clear();
126
127 m_scintillaTricksCode = new SCINTILLA_TRICKS( m_codePreview, wxT( "{}" ), false );
128 m_scintillaTricksSubckt = new SCINTILLA_TRICKS( m_subckt, wxT( "()" ), false );
129
130 m_paramGridMgr->Bind( wxEVT_PG_SELECTED, &DIALOG_SIM_MODEL::onParamGridSelectionChange, this );
131
132 wxPropertyGrid* grid = m_paramGrid->GetGrid();
133 grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
134 grid->Bind( wxEVT_SET_FOCUS, &DIALOG_SIM_MODEL::onParamGridSetFocus, this );
135 grid->Bind( wxEVT_UPDATE_UI, &DIALOG_SIM_MODEL::onUpdateUI, this );
136
137 grid->DedicateKey( WXK_RETURN );
138 grid->DedicateKey( WXK_NUMPAD_ENTER );
139 grid->DedicateKey( WXK_UP );
140 grid->DedicateKey( WXK_DOWN );
141
142#if wxCHECK_VERSION( 3, 3, 0 )
143 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_RETURN );
144 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
145 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_NUMPAD_ENTER );
146 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
147#else
148 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
149 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
150 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_NUMPAD_ENTER );
151 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
152#endif
153
154 m_pinAssignmentsGrid->ClearRows();
155 m_pinAssignmentsGrid->PushEventHandler( new GRID_TRICKS( m_pinAssignmentsGrid ) );
156
157 m_subcktLabel->SetFont( KIUI::GetStatusFont( m_subcktLabel ) );
158 finishDialogSettings();
159}
160
161
162template <typename T>
164{
165 // Disable all properties. This is necessary because some of their methods are called after
166 // destruction of DIALOG_SIM_MODEL, oddly. When disabled, they never access their models.
167 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
168 {
169 if( SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it ) )
170 prop->Disable();
171 }
172
173 // Delete the GRID_TRICKS.
174 m_pinAssignmentsGrid->PopEventHandler( true );
175
178}
179
180
181template <typename T>
183{
184 wxCommandEvent dummyEvent;
185 wxString deviceType;
186 wxString modelType;
187 wxString modelParams;
188 wxString pinMap;
189 bool storeInValue = false;
190
192
193 // Infer RLC and VI models if they aren't specified
195 &deviceType, &modelType, &modelParams, &pinMap ) )
196 {
197 SetFieldValue( m_fields, SIM_DEVICE_FIELD, deviceType.ToStdString() );
198
199 if( !modelType.IsEmpty() )
200 SetFieldValue( m_fields, SIM_DEVICE_SUBTYPE_FIELD, modelType.ToStdString() );
201
202 SetFieldValue( m_fields, SIM_PARAMS_FIELD, modelParams.ToStdString() );
203
204 SetFieldValue( m_fields, SIM_PINS_FIELD, pinMap.ToStdString() );
205
206 storeInValue = true;
207
208 // WriteFields() only rewrites Value when storeInValue stays on, so remember the original
209 // text first to restore it verbatim if the user turns storeInValue off.
210 SCH_FIELD* valueField = FindField( m_fields, FIELD_T::VALUE );
211
212 m_inferredValueRestore = valueField->GetText();
214 valueField->SetText( wxT( "${SIM.PARAMS}" ) );
215 }
216
217 wxString libraryFilename = GetFieldValue( &m_fields, SIM_LIBRARY::LIBRARY_FIELD, true, 0 );
218 wxFileName tmp( libraryFilename );
219
220 if( !tmp.GetFullName().IsEmpty() )
221 {
222 // The model is sourced from a library, optionally with instance overrides.
223 m_rbLibraryModel->SetValue( true );
224
225 if( !loadLibrary( libraryFilename, reporter ) )
226 {
227 if( reporter.HasMessage() )
228 m_infoBar->ShowMessage( reporter.GetMessages() );
229
230 m_libraryPathText->ChangeValue( libraryFilename );
232
234 m_fields, true, 0, reporter );
235
236 m_modelListBox->Clear();
237 m_modelListBox->Append( _( "<unknown>" ) );
238 m_modelListBox->SetSelection( 0 );
239 }
240 else
241 {
242 std::string modelName = GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD, true, 0 );
243 int modelIdx = m_modelListBox->FindString( modelName );
244
245 if( modelIdx == wxNOT_FOUND )
246 {
247 m_infoBar->ShowMessage( wxString::Format( _( "No model named '%s' in library." ),
248 modelName ) );
249
250 // Default to first item in library if any exist
251 if( m_modelListBox->GetCount() > 0 )
252 m_modelListBox->SetSelection( 0 );
253 }
254 else
255 {
256 m_infoBar->Hide();
257 m_modelListBox->SetSelection( modelIdx );
258 }
259
260 m_curModelType = curModel().GetType();
261 }
262
263 if( isIbisLoaded() && ( m_modelListBox->GetSelection() >= 0 ) )
264 {
265 int idx = 0;
266 wxString sel = m_modelListBox->GetStringSelection();
267
268 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
269 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
270
271 SIM_MODEL_IBIS* ibismodel = dynamic_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels()[idx].get() );
272
273 if( ibismodel )
274 {
275 onModelNameChoice( dummyEvent ); // refresh list of pins
276
277 int i = 0;
278
279 for( const std::pair<std::string, std::string>& strs : ibismodel->GetIbisPins() )
280 {
281 if( strs.first == GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::PIN_FIELD, true, 0 ) )
282 {
283 auto ibisLibrary = static_cast<const SIM_LIBRARY_IBIS*>( library() );
284
285 ibismodel->ChangePin( *ibisLibrary, strs.first );
286 m_pinCombobox->SetSelection( static_cast<int>( i ) );
287 break;
288 }
289 i++;
290 }
291
292 if( i < static_cast<int>( ibismodel->GetIbisPins().size() ) )
293 {
294 onPinCombobox( dummyEvent ); // refresh list of models
295
296 wxString ibisModel = GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::MODEL_FIELD, true, 0 );
297 m_pinModelCombobox->SetStringSelection( ibisModel );
298 }
299
300 if( GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::DIFF_FIELD, true, 0 ) == "1" )
301 {
302 ibismodel->SwitchSingleEndedDiff( true );
303 m_differentialCheckbox->SetValue( true );
304 }
305 else
306 {
307 ibismodel->SwitchSingleEndedDiff( false );
308 m_differentialCheckbox->SetValue( false );
309 }
310
311 // SetIbisModel derives the IO mode from KIBIS_MODEL::m_type
312 // (Series / Series_switch override the differential layout).
313 auto ibisLibrary = static_cast<const SIM_LIBRARY_IBIS*>( library() );
314 std::string pinNum = GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::PIN_FIELD,
315 true, 0 );
317 true, 0 );
318
319 if( ibisLibrary && !pinNum.empty() && !modelNm.empty() )
320 ibismodel->SetIbisModel( *ibisLibrary, pinNum, modelNm );
321 }
322 }
323 }
324 else if( !GetFieldValue( &m_fields, SIM_DEVICE_FIELD, false, 0 ).empty()
326 {
327 // The model is sourced from the instance.
328 m_rbBuiltinModel->SetValue( true );
329
330 reporter.Clear();
332
333 if( reporter.HasMessage() )
334 DisplayErrorMessage( this, reporter.GetMessages() );
335 }
336
337 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
338 {
339 if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
340 {
341 reporter.Clear();
343
344 if( reporter.HasMessage() )
345 {
346 DisplayErrorMessage( this, _( "Failed to read simulation model from fields." )
347 + wxT( "\n\n" ) + reporter.GetMessages() );
348 }
349 }
350 else
351 {
353 }
354
355 SIM_MODEL::DEVICE_T deviceTypeT = SIM_MODEL::TypeInfo( type ).deviceType;
356
357 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
358 m_curModelTypeOfDeviceType[deviceTypeT] = type;
359 }
360
361 if( storeInValue )
362 curModel().SetIsStoredInValue( true );
363
364 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
365
367
368 onRadioButton( dummyEvent );
369 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
370}
371
372
373template <typename T>
375{
376 if( !m_pinAssignmentsGrid->CommitPendingChanges() )
377 return false;
378
379 if( !m_paramGrid->GetGrid()->CommitChangesFromEditor() )
380 return false;
381
382 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
383 return false;
384
386 std::string path;
387 std::string name;
388
389 if( m_rbLibraryModel->GetValue() )
390 {
391 path = m_libraryPathText->GetValue();
392 wxFileName fn( path );
393
394 if( !path.starts_with( FILEEXT::KiCadUriPrefix ) && fn.MakeRelativeTo( Prj().GetProjectPath() )
395 && !fn.GetFullPath().StartsWith( ".." ) )
396 {
397 path = fn.GetFullPath();
398 }
399
400 if( m_modelListBox->GetSelection() >= 0 )
401 name = m_modelListBox->GetStringSelection().ToStdString();
402 else if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( &model ) )
404 }
405
408
409 if( isIbisLoaded() && !m_libraryModelsMgr.GetModels().empty() )
410 {
411 int idx = 0;
412 wxString sel = m_modelListBox->GetStringSelection();
413
414 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
415 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
416
417 auto* ibismodel =
418 static_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels().at( idx ).get() );
419
420 if( ibismodel )
421 {
422 std::string pins;
423 std::string modelName = std::string( m_pinModelCombobox->GetValue().c_str() );
424 std::string differential;
425
426 if( m_pinCombobox->GetSelection() >= 0 )
427 pins = ibismodel->GetIbisPins().at( m_pinCombobox->GetSelection() ).first;
428
429 if( ibismodel->CanDifferential() && m_differentialCheckbox->GetValue() )
430 differential = "1";
431
435 }
436 }
437
438 if( model.GetType() == SIM_MODEL::TYPE::RAWSPICE )
439 {
440 if( m_modelNotebook->GetSelection() == 0 )
442
443 wxString code = m_codePreview->GetText().Trim( true ).Trim( false );
444 model.SetParamValue( "model", std::string( code.ToUTF8() ) );
445 }
446
447 model.SetIsStoredInValue( m_saveInValueCheckbox->GetValue() );
448
449 for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
450 {
451 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( row, PIN_COLUMN::MODEL );
452 wxString symbolPinName = m_sortedPartPins.at( row )->GetShownNumber();
453
454 model.AssignSymbolPinNumberToModelPin( getModelPinIndex( modelPinName ),
455 std::string( symbolPinName.ToUTF8() ) );
456 }
457
459
460 curModel().WriteFields( m_fields );
461
463 model.IsStoredInValue() );
464
465 // Decomposition is a component-level choice and is independent of the model fields written
466 // above. Only multi-unit symbols expose it; write it after WriteFields() so it is preserved.
467 if( m_symbol.GetUnitCount() > 1 )
468 {
469 SIM_DECOMPOSITION decomposition;
470
471 if( m_decompositionChoice->GetSelection() == 1 )
472 {
474
475 wxStringTokenizer sharedTokens( m_sharedPinsText->GetValue(), wxS( ", \t" ),
476 wxTOKEN_STRTOK );
477
478 while( sharedTokens.HasMoreTokens() )
479 decomposition.sharedModelPins.push_back( sharedTokens.GetNextToken() );
480 }
481
482 // Whole-device formats to an empty string, which clears any previous repeat selection.
483 SetFieldValue( m_fields, SIM_DECOMPOSITION_FIELD, decomposition.Format().ToStdString(),
484 false );
485 }
486
487 return true;
488}
489
490
491template <typename T>
492void DIALOG_SIM_MODEL<T>::RestoreInferredValue( std::vector<SCH_FIELD>& aFields,
493 const wxString& aOriginalValue, bool aOverwritten,
494 bool aStoredInValue )
495{
496 if( !aOverwritten || aStoredInValue )
497 return;
498
499 if( SCH_FIELD* valueField = FindField( aFields, FIELD_T::VALUE ) )
500 valueField->SetText( aOriginalValue );
501}
502
503
504template <typename T>
506{
507 bool multiUnit = m_symbol.GetUnitCount() > 1;
508
509 m_decompositionLabel->Show( multiUnit );
510 m_decompositionChoice->Show( multiUnit );
511 m_sharedPinsLabel->Show( multiUnit );
512 m_sharedPinsText->Show( multiUnit );
513
514 if( multiUnit )
515 {
518
519 bool repeat = decomposition.mode == SIM_DECOMPOSITION::MODE::REPEAT_PER_UNIT;
520
521 m_decompositionChoice->SetSelection( repeat ? 1 : 0 );
522
523 wxString shared;
524
525 for( const wxString& pin : decomposition.sharedModelPins )
526 {
527 if( !shared.IsEmpty() )
528 shared += wxS( ", " );
529
530 shared += pin;
531 }
532
533 m_sharedPinsText->SetValue( shared );
534 m_sharedPinsLabel->Enable( repeat );
535 m_sharedPinsText->Enable( repeat );
536 }
537
538 m_pinAssignmentsPanel->Layout();
539}
540
541
542template <typename T>
544{
545 bool repeat = m_decompositionChoice->GetSelection() == 1;
546
547 m_sharedPinsLabel->Enable( repeat );
548 m_sharedPinsText->Enable( repeat );
549
550 aEvent.Skip();
551}
552
553
554template <typename T>
556{
557 // always enable the library browser button -- it makes for fewer clicks if the user has a
558 // whole bunch of inferred passives that they want to specify library models for
559 m_browseButton->Enable();
560
561 // if we're in an undetermined state then enable everything for faster access
562 bool undetermined = !m_rbLibraryModel->GetValue() && !m_rbBuiltinModel->GetValue();
563 bool enableLibCtrls = m_rbLibraryModel->GetValue() || undetermined;
564 bool enableBuiltinCtrls = m_rbBuiltinModel->GetValue() || undetermined;
565
566 m_pathLabel->Enable( enableLibCtrls );
567 m_libraryPathText->Enable( enableLibCtrls );
568 m_modelNameLabel->Enable( enableLibCtrls );
569 m_modelFilter->Enable( enableLibCtrls && !isIbisLoaded() );
570 m_modelListBox->Enable( enableLibCtrls );
571 m_pinLabel->Enable( enableLibCtrls );
572 m_pinCombobox->Enable( enableLibCtrls );
573 m_differentialCheckbox->Enable( enableLibCtrls );
574 m_pinModelLabel->Enable( enableLibCtrls );
575 m_pinModelCombobox->Enable( enableLibCtrls );
576 m_waveformLabel->Enable( enableLibCtrls );
577 m_waveformChoice->Enable( enableLibCtrls );
578
579 m_deviceLabel->Enable( enableBuiltinCtrls );
580 m_deviceChoice->Enable( enableBuiltinCtrls );
581 m_deviceSubtypeLabel->Enable( enableBuiltinCtrls );
582 m_deviceSubtypeChoice->Enable( enableBuiltinCtrls );
583
585
590 updatePinAssignments( model, false );
591
592 std::string ref = GetFieldValue( &m_fields, SIM_REFERENCE_FIELD, false, 0 );
593
594 m_modelPanel->Layout();
595 m_pinAssignmentsPanel->Layout();
596 m_parametersPanel->Layout();
597 m_codePanel->Layout();
598
599 SendSizeEvent( wxSEND_EVENT_POST );
600
602}
603
604
605template <typename T>
607{
608 SIM_MODEL_IBIS* modelibis = isIbisLoaded() ? dynamic_cast<SIM_MODEL_IBIS*>( aModel ) : nullptr;
609
610 m_pinLabel->Show( isIbisLoaded() );
611 m_pinCombobox->Show( isIbisLoaded() );
612 m_pinModelLabel->Show( isIbisLoaded() );
614 m_waveformLabel->Show( isIbisLoaded() );
616
617 if( aModel != m_prevModel )
618 {
619 m_waveformChoice->Clear();
620
621 if( isIbisLoaded() )
622 {
623 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
624 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
625 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
626 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
627 {
628 SIM_MODEL::DEVICE_T deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
629 const std::string& deviceTypeDesc = SIM_MODEL::DeviceInfo( deviceType ).description;
630
631 if( deviceType == aModel->GetDeviceType()
632 || deviceTypeDesc == aModel->GetDeviceInfo().description )
633 {
634 m_waveformChoice->Append( SIM_MODEL::TypeInfo( type ).description );
635
636 if( type == aModel->GetType() )
637 m_waveformChoice->SetSelection( m_waveformChoice->GetCount() - 1 );
638 }
639 }
640 }
641 }
642
643 m_differentialCheckbox->Show( isIbisLoaded() && modelibis && modelibis->CanDifferential() );
644 m_modelNameLabel->SetLabel( isIbisLoaded() ? _( "Component:" ) : _( "Model:" ) );
645}
646
647
648template <typename T>
650{
651 // Change the Type choice to match the current device type.
652 if( aModel != m_prevModel )
653 {
654 m_deviceChoice->Clear();
655 m_deviceSubtypeChoice->Clear();
656
657 if( !m_rbLibraryModel->GetValue() )
658 {
659 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
660 {
661 if( !SIM_MODEL::DeviceInfo( deviceType ).showInMenu )
662 continue;
663
664 m_deviceChoice->Append( SIM_MODEL::DeviceInfo( deviceType ).description );
665
666 if( equivalent( deviceType, aModel->GetDeviceType() ) )
667 m_deviceChoice->SetSelection( m_deviceChoice->GetCount() - 1 );
668 }
669
670 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
671 {
672 if( type == SIM_MODEL::TYPE::KIBIS_DEVICE
673 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
674 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
675 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS )
676 {
677 continue;
678 }
679
680 SIM_MODEL::DEVICE_T deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
681 const std::string& deviceTypeDesc = SIM_MODEL::DeviceInfo( deviceType ).description;
682
683 if( deviceType == aModel->GetDeviceType()
684 || deviceTypeDesc == aModel->GetDeviceInfo().description )
685 {
686 m_deviceSubtypeChoice->Append( SIM_MODEL::TypeInfo( type ).description );
687
688 if( type == aModel->GetType() )
689 m_deviceSubtypeChoice->SetSelection( m_deviceSubtypeChoice->GetCount() - 1 );
690 }
691 }
692 }
693
694 m_deviceSubtypeLabel->Show( m_deviceSubtypeChoice->GetCount() > 1 );
695 m_deviceSubtypeChoice->Show( m_deviceSubtypeChoice->GetCount() > 1 );
696 }
697
698 if( dynamic_cast<SIM_MODEL_RAW_SPICE*>( aModel ) )
699 m_modelNotebook->SetSelection( 1 );
700 else
701 m_modelNotebook->SetSelection( 0 );
702
703 if( aModel->HasPrimaryValue() )
704 {
705 const SIM_MODEL::PARAM& primary = aModel->GetParam( 0 );
706
707 m_saveInValueCheckbox->SetLabel( wxString::Format( _( "Save parameter '%s (%s)' in Value "
708 "field" ),
709 primary.info.description,
710 primary.info.name ) );
711 m_saveInValueCheckbox->Enable( true );
712 }
713 else
714 {
715 m_saveInValueCheckbox->SetLabel( _( "Save primary parameter in Value field" ) );
716 m_saveInValueCheckbox->SetValue( false );
717 m_saveInValueCheckbox->Enable( false );
718 }
719}
720
721
722template <typename T>
724{
725 if( aModel != m_prevModel )
726 {
727 // This wxPropertyGridManager column and header stuff has to be here because it segfaults in
728 // the constructor.
729
730 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
731
732 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION, _( "Parameter" ) );
733 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT, _( "Unit" ) );
734 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT, _( "Default" ) );
735 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE, _( "Type" ) );
736
737 m_paramGridMgr->ShowHeader();
738
739
740 m_paramGrid->Clear();
741
742 m_firstCategory = m_paramGrid->Append( new wxPropertyCategory( "Geometry" ) );
743 m_paramGrid->HideProperty( "Geometry" );
744
745 m_paramGrid->Append( new wxPropertyCategory( "AC" ) );
746 m_paramGrid->HideProperty( "AC" );
747
748 m_paramGrid->Append( new wxPropertyCategory( "DC" ) );
749 m_paramGrid->HideProperty( "DC" );
750
751 m_paramGrid->Append( new wxPropertyCategory( "S-Parameters" ) );
752 m_paramGrid->HideProperty( "S-Parameters" );
753
754 m_paramGrid->Append( new wxPropertyCategory( "Capacitance" ) );
755 m_paramGrid->HideProperty( "Capacitance" );
756
757 m_paramGrid->Append( new wxPropertyCategory( "Temperature" ) );
758 m_paramGrid->HideProperty( "Temperature" );
759
760 m_paramGrid->Append( new wxPropertyCategory( "Noise" ) );
761 m_paramGrid->HideProperty( "Noise" );
762
763 m_paramGrid->Append( new wxPropertyCategory( "Distributed Quantities" ) );
764 m_paramGrid->HideProperty( "Distributed Quantities" );
765
766 m_paramGrid->Append( new wxPropertyCategory( "Waveform" ) );
767 m_paramGrid->HideProperty( "Waveform" );
768
769 m_paramGrid->Append( new wxPropertyCategory( "Limiting Values" ) );
770 m_paramGrid->HideProperty( "Limiting Values" );
771
772 m_paramGrid->Append( new wxPropertyCategory( "Advanced" ) );
773 m_paramGrid->HideProperty( "Advanced" );
774
775 m_paramGrid->Append( new wxPropertyCategory( "Flags" ) );
776 m_paramGrid->HideProperty( "Flags" );
777
778 m_paramGrid->CollapseAll();
779
780 for( int i = 0; i < aModel->GetParamCount(); ++i )
781 addParamPropertyIfRelevant( aModel, i );
782
783 m_paramGrid->CollapseAll();
784 m_paramGrid->Expand( "AC" );
785 m_paramGrid->Expand( "Waveform" );
786 }
787
788 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(), true );
789
790 // Set all properties to default colors.
791 // Update properties in models that have autofill.
792 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
793 {
794 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
795 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
796
797 for( int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
798 {
799 ( *it )->GetCell( col ).SetBgCol( bgCol );
800 ( *it )->GetCell( col ).SetFgCol( fgCol );
801 }
802
803 SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it );
804
805 if( !prop )
806 continue;
807
808 const SIM_MODEL::PARAM& param = prop->GetParam();
809
810 // Model values other than the currently edited value may have changed. Update them.
811 // This feature is called "autofill" and present only in certain models. Don't do it for
812 // models that don't have it for performance reasons.
813 if( aModel->HasAutofill() )
814 ( *it )->SetValueFromString( param.value );
815 }
816}
817
818
819template <typename T>
821{
822 if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( aModel ) )
823 return;
824
825 wxString text;
826 SPICE_ITEM item;
827
828 item.modelName = m_modelListBox->GetStringSelection();
829
830 if( m_rbBuiltinModel->GetValue() || item.modelName == "" )
832
833 text << aModel->SpiceGenerator().Preview( item );
834
835 m_codePreview->SetText( text );
836 m_codePreview->SelectNone();
837}
838
839
840template <typename T>
841void DIALOG_SIM_MODEL<T>::updatePinAssignments( SIM_MODEL* aModel, bool aForceRefreshFromModel )
842{
843 m_pinAssignmentsGrid->CommitPendingChanges( true );
844
845 if( m_pinAssignmentsGrid->GetNumberRows() == 0 )
846 {
847 m_pinAssignmentsGrid->AppendRows( (int) m_sortedPartPins.size() );
848
849 for( int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
850 {
851 wxString symbolPinString = getSymbolPinString( ii );
852
853 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
854 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
855 }
856
857 aForceRefreshFromModel = true;
858 }
859
860 if( aForceRefreshFromModel )
861 {
862 // Reset the grid.
863 for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
864 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL, _( "Not Connected" ) );
865
866 // Now set up the grid values in the Model column.
867 for( int modelPinIndex = 0; modelPinIndex < aModel->GetPinCount(); ++modelPinIndex )
868 {
869 wxString symbolPinNumber = aModel->GetPin( modelPinIndex ).symbolPinNumber;
870
871 if( symbolPinNumber == "" )
872 continue;
873
874 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
875
876 if( symbolPinRow == -1 )
877 continue;
878
879 wxString modelPinString = getModelPinString( aModel, modelPinIndex );
880 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
881 }
882 }
883
884 for( int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
885 {
886 // Set up the Model column cell editors with dropdown options.
887 std::vector<BITMAPS> modelPinIcons;
888 wxArrayString modelPinChoices;
889
890 for( int jj = 0; jj < aModel->GetPinCount(); ++jj )
891 {
892 if( aModel->GetPin( jj ).symbolPinNumber != "" )
893 modelPinIcons.push_back( PinShapeGetBitmap( GRAPHIC_PINSHAPE::LINE ) );
894 else
895 modelPinIcons.push_back( BITMAPS::INVALID_BITMAP );
896
897 modelPinChoices.Add( getModelPinString( aModel, jj ) );
898 }
899
900 modelPinIcons.push_back( BITMAPS::INVALID_BITMAP );
901 modelPinChoices.Add( _( "Not Connected" ) );
902
903 // This is not a memory leak; `SetCellEditor()` calls `DecRef()` on its previous editor.
904 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
905 new GRID_CELL_ICON_TEXT_POPUP( modelPinIcons, modelPinChoices ) );
906
907 // Assignment stays the same, but model pin names need to be updated
908 int modelPinIndex = getModelPinIndex( m_pinAssignmentsGrid->GetCellValue( ii, PIN_COLUMN::MODEL ) );
909
910 if( modelPinIndex >= 0 )
911 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::MODEL, getModelPinString( aModel, modelPinIndex ) );
912 }
913
914 // TODO: Show a preview of the symbol with the pin numbers shown.
915
916 if( aModel->GetType() == SIM_MODEL::TYPE::SUBCKT )
917 {
918 SIM_MODEL_SUBCKT* subckt = static_cast<SIM_MODEL_SUBCKT*>( aModel );
919 m_subckt->SetText( subckt->GetSpiceCode() );
920 m_subckt->SetEditable( false );
921 }
922 else
923 {
924 m_subcktLabel->Show( false );
925 m_subckt->Show( false );
926 }
927}
928
929
930template <typename T>
932{
933 for( int i = 0; i < aModel->GetPinCount(); ++i )
934 {
935 if( !m_symbol.GetPin( aModel->GetPin( i ).symbolPinNumber ) )
936 aModel->AssignSymbolPinNumberToModelPin( i, "" );
937 }
938}
939
940
941template <typename T>
942bool DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aLibraryPath, REPORTER& aReporter, bool aForceReload )
943{
944 if( m_prevLibrary == aLibraryPath && !aForceReload )
945 return true;
946
947 m_libraryModelsMgr.SetForceFullParse();
948 m_libraryModelsMgr.SetLibrary( aLibraryPath, aReporter );
949 m_libraryPathText->ChangeValue( aLibraryPath );
951
953 {
954 m_libraryModelsMgr.Clear();
955
956 if( m_modelListBox->GetSelection() != wxNOT_FOUND )
957 m_modelListBox->SetSelection( wxNOT_FOUND );
958
959 if( m_modelListBox->GetCount() )
960 m_modelListBox->Clear();
961
962 wxArrayString emptyArray;
963 m_pinModelCombobox->Set( emptyArray );
964 m_pinCombobox->Set( emptyArray );
965 m_pinModelCombobox->SetSelection( -1 );
966 m_pinCombobox->SetSelection( -1 );
967 m_waveformChoice->Clear();
968 m_prevLibrary.Clear();
969
970 return false;
971 }
972
973 std::string modelName = GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD, true, 0 );
974
975 const auto partPinNumbers = SIM_MODEL::PinNumbers( m_sortedPartPins );
976
977 for( const auto& [baseModelName, baseModel] : library()->GetModels() )
978 {
979 if( baseModelName == modelName )
980 m_libraryModelsMgr.CreateModel( &baseModel, partPinNumbers,
981 m_fields, true, 0, aReporter );
982 else
983 m_libraryModelsMgr.CreateModel( &baseModel, partPinNumbers, aReporter );
984 }
985
986 m_rbLibraryModel->SetValue( true );
987
988 wxArrayString modelNames;
989
990 bool modelNameExists = false;
991 for( const auto& [name, model] : library()->GetModels() )
992 {
993 modelNames.Add( name );
995
996 if( name == modelName )
997 modelNameExists = true;
998 }
999
1000 modelNames.Sort();
1001
1002 m_modelListBox->Clear();
1003 m_modelListBox->Append( modelNames );
1004
1005 if( !modelNameExists )
1006 {
1007 m_infoBar->ShowMessage( wxString::Format( _( "No model named '%s' in '%s'." ),
1008 modelName,
1009 aLibraryPath ) );
1010 return false;
1011 }
1012
1013 if( isIbisLoaded() )
1014 {
1015 wxArrayString emptyArray;
1016 m_pinModelCombobox->Set( emptyArray );
1017 m_pinCombobox->Set( emptyArray );
1018 m_pinModelCombobox->SetSelection( -1 );
1019 m_pinCombobox->SetSelection( -1 );
1020 }
1021
1022 m_modelListBox->SetStringSelection( modelName );
1023
1024 if( m_modelListBox->GetSelection() < 0 && m_modelListBox->GetCount() > 0 )
1025 m_modelListBox->SetSelection( 0 );
1026
1027 m_curModelType = curModel().GetType();
1028
1029 m_prevLibrary = aLibraryPath;
1030 return true;
1031}
1032
1033
1034template <typename T>
1036{
1037 if( aModel->GetParam( aParamIndex ).info.dir == SIM_MODEL::PARAM::DIR_OUT )
1038 return;
1039
1040 switch( aModel->GetParam( aParamIndex ).info.category )
1041 {
1042 case CATEGORY::AC:
1043 m_paramGrid->HideProperty( "AC", false );
1044 m_paramGrid->AppendIn( "AC", newParamProperty( aModel, aParamIndex ) );
1045 break;
1046
1047 case CATEGORY::DC:
1048 m_paramGrid->HideProperty( "DC", false );
1049 m_paramGrid->AppendIn( "DC", newParamProperty( aModel, aParamIndex ) );
1050 break;
1051
1052 case CATEGORY::S_PARAM:
1053 m_paramGrid->HideProperty( "S-Parameters", false );
1054 m_paramGrid->AppendIn( "S-Parameters", newParamProperty( aModel, aParamIndex ) );
1055 break;
1056
1057 case CATEGORY::CAPACITANCE:
1058 m_paramGrid->HideProperty( "Capacitance", false );
1059 m_paramGrid->AppendIn( "Capacitance", newParamProperty( aModel, aParamIndex ) );
1060 break;
1061
1062 case CATEGORY::TEMPERATURE:
1063 m_paramGrid->HideProperty( "Temperature", false );
1064 m_paramGrid->AppendIn( "Temperature", newParamProperty( aModel, aParamIndex ) );
1065 break;
1066
1067 case CATEGORY::NOISE:
1068 m_paramGrid->HideProperty( "Noise", false );
1069 m_paramGrid->AppendIn( "Noise", newParamProperty( aModel, aParamIndex ) );
1070 break;
1071
1072 case CATEGORY::DISTRIBUTED_QUANTITIES:
1073 m_paramGrid->HideProperty( "Distributed Quantities", false );
1074 m_paramGrid->AppendIn( "Distributed Quantities", newParamProperty( aModel, aParamIndex ) );
1075 break;
1076
1077 case CATEGORY::WAVEFORM:
1078 m_paramGrid->HideProperty( "Waveform", false );
1079 m_paramGrid->AppendIn( "Waveform", newParamProperty( aModel, aParamIndex ) );
1080 break;
1081
1082 case CATEGORY::GEOMETRY:
1083 m_paramGrid->HideProperty( "Geometry", false );
1084 m_paramGrid->AppendIn( "Geometry", newParamProperty( aModel, aParamIndex ) );
1085 break;
1086
1087 case CATEGORY::LIMITING_VALUES:
1088 m_paramGrid->HideProperty( "Limiting Values", false );
1089 m_paramGrid->AppendIn( "Limiting Values", newParamProperty( aModel, aParamIndex ) );
1090 break;
1091
1092 case CATEGORY::ADVANCED:
1093 m_paramGrid->HideProperty( "Advanced", false );
1094 m_paramGrid->AppendIn( "Advanced", newParamProperty( aModel, aParamIndex ) );
1095 break;
1096
1097 case CATEGORY::FLAGS:
1098 m_paramGrid->HideProperty( "Flags", false );
1099 m_paramGrid->AppendIn( "Flags", newParamProperty( aModel, aParamIndex ) );
1100 break;
1101
1102 default:
1103 m_paramGrid->Insert( m_firstCategory, newParamProperty( aModel, aParamIndex ) );
1104 break;
1105
1106 case CATEGORY::INITIAL_CONDITIONS:
1107 case CATEGORY::SUPERFLUOUS:
1108 return;
1109 }
1110}
1111
1112
1113template <typename T>
1114wxPGProperty* DIALOG_SIM_MODEL<T>::newParamProperty( SIM_MODEL* aModel, int aParamIndex ) const
1115{
1116 const SIM_MODEL::PARAM& param = aModel->GetParam( aParamIndex );
1117 wxString paramDescription;
1118
1119 if( param.info.description == "" )
1120 paramDescription = wxString::Format( "%s", param.info.name );
1121 else
1122 paramDescription = wxString::Format( "%s (%s)", param.info.description, param.info.name );
1123
1124 wxPGProperty* prop = nullptr;
1125
1126 switch( param.info.type )
1127 {
1129 prop = new SIM_BOOL_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex );
1130 prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX, true );
1131 break;
1132
1134 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1136 break;
1137
1139 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1141 break;
1142
1143 //case TYPE_COMPLEX:
1144 // break;
1145
1147 // Special case: K-line mutual inductance statement parameters l1 and l2 are references
1148 // to other inductors in the circuit.
1149 if( dynamic_cast<SIM_MODEL_L_MUTUAL*>( aModel ) != nullptr
1150 && ( param.info.name == "l1" || param.info.name == "l2" ) )
1151 {
1152 wxArrayString inductors;
1153
1154 if( SCH_EDIT_FRAME* schEditFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
1155 {
1156 SPICE_CIRCUIT_MODEL circuit( &schEditFrame->Schematic() );
1157 NULL_REPORTER devNul;
1158
1160
1161 for( const SPICE_ITEM& item : circuit.GetItems() )
1162 {
1163 if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::L )
1164 inductors.push_back( item.refName );
1165 }
1166
1167 inductors.Sort(
1168 []( const wxString& a, const wxString& b ) -> int
1169 {
1170 return StrNumCmp( a, b, true );
1171 } );
1172 }
1173
1174 if( inductors.empty() )
1175 {
1176 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1178 }
1179 else
1180 {
1181 prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1182 inductors );
1183 }
1184 }
1185 else if( param.info.enumValues.empty() )
1186 {
1187 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1189 }
1190 else
1191 {
1192 wxArrayString values;
1193
1194 for( const std::string& string : aModel->GetParam( aParamIndex ).info.enumValues )
1195 values.Add( string );
1196
1197 prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1198 values );
1199 }
1200 break;
1201
1202 default:
1203 prop = new wxStringProperty( paramDescription, param.info.name );
1204 break;
1205 }
1206
1207 prop->SetAttribute( wxPG_ATTR_UNITS, wxString::FromUTF8( param.info.unit.c_str() ) );
1208
1209 // Legacy due to the way we extracted the parameters from Ngspice.
1210 prop->SetCell( 3, wxString::FromUTF8( param.info.defaultValue ) );
1211
1212 wxString typeStr;
1213
1214 switch( param.info.type )
1215 {
1216 case SIM_VALUE::TYPE_BOOL: typeStr = wxT( "Bool" ); break;
1217 case SIM_VALUE::TYPE_INT: typeStr = wxT( "Int" ); break;
1218 case SIM_VALUE::TYPE_FLOAT: typeStr = wxT( "Float" ); break;
1219 case SIM_VALUE::TYPE_COMPLEX: typeStr = wxT( "Complex" ); break;
1220 case SIM_VALUE::TYPE_STRING: typeStr = wxT( "String" ); break;
1221 case SIM_VALUE::TYPE_BOOL_VECTOR: typeStr = wxT( "Bool Vector" ); break;
1222 case SIM_VALUE::TYPE_INT_VECTOR: typeStr = wxT( "Int Vector" ); break;
1223 case SIM_VALUE::TYPE_FLOAT_VECTOR: typeStr = wxT( "Float Vector" ); break;
1224 case SIM_VALUE::TYPE_COMPLEX_VECTOR: typeStr = wxT( "Complex Vector" ); break;
1225 }
1226
1227 prop->SetCell( PARAM_COLUMN::TYPE, typeStr );
1228
1229 return prop;
1230}
1231
1232
1233template <typename T>
1234int DIALOG_SIM_MODEL<T>::findSymbolPinRow( const wxString& aSymbolPinNumber ) const
1235{
1236 for( int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
1237 {
1239
1240 if( pin->GetNumber() == aSymbolPinNumber )
1241 return row;
1242 }
1243
1244 return -1;
1245}
1246
1247
1248template <typename T>
1250{
1251 if( m_rbLibraryModel->GetValue() )
1252 {
1253 wxString sel = m_modelListBox->GetStringSelection();
1254
1255 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
1256 {
1257 int idx = m_modelListBoxEntryToLibraryIdx.at( sel );
1258
1259 if( idx >= 0 && idx < (int) m_libraryModelsMgr.GetModels().size() )
1260 return m_libraryModelsMgr.GetModels().at( idx ).get();
1261 }
1262 }
1263 else
1264 {
1265 if( (int) m_curModelType < (int) m_builtinModelsMgr.GetModels().size() )
1266 return m_builtinModelsMgr.GetModels().at( static_cast<int>( m_curModelType ) );
1267 }
1268
1269 return m_builtinModelsMgr.GetModels().at( (int) SIM_MODEL::TYPE::NONE );
1270}
1271
1272
1273template <typename T>
1275{
1276 if( m_libraryModelsMgr.GetLibraries().size() == 1 )
1277 return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
1278
1279 return nullptr;
1280}
1281
1282
1283template <typename T>
1284wxString DIALOG_SIM_MODEL<T>::getSymbolPinString( int symbolPinIndex ) const
1285{
1286 SCH_PIN* pin = m_sortedPartPins.at( symbolPinIndex );
1287 wxString pinNumber;
1288 wxString pinName;
1289
1290 if( pin )
1291 {
1292 pinNumber = pin->GetShownNumber();
1293 pinName = pin->GetShownName();
1294 }
1295
1296 if( !pinName.IsEmpty() && pinName != pinNumber )
1297 pinNumber += wxString::Format( wxT( " (\"%s\")" ), pinName );
1298
1299 return pinNumber;
1300}
1301
1302
1303template <typename T>
1304wxString DIALOG_SIM_MODEL<T>::getModelPinString( SIM_MODEL* aModel, int aModelPinIndex ) const
1305{
1306 wxString modelPinName;
1307
1308 if( aModelPinIndex >= 0 && aModelPinIndex < aModel->GetPinCount() )
1309 modelPinName = aModel->GetPin( aModelPinIndex ).modelPinName;
1310
1311 wxString modelPinNumber = wxString::Format( "%d", aModelPinIndex + 1 );
1312
1313 if( !modelPinName.IsEmpty() && modelPinName != modelPinNumber )
1314 modelPinNumber += wxString::Format( wxT( " (\"%s\")" ), modelPinName );
1315
1316 return modelPinNumber;
1317}
1318
1319
1320template <typename T>
1321int DIALOG_SIM_MODEL<T>::getModelPinIndex( const wxString& aModelPinString ) const
1322{
1323 if( aModelPinString == "Not Connected" )
1325
1326 int length = aModelPinString.Find( " " );
1327
1328 if( length == wxNOT_FOUND )
1329 length = static_cast<int>( aModelPinString.Length() );
1330
1331 long result = 0;
1332 aModelPinString.Mid( 0, length ).ToCLong( &result );
1333
1334 return static_cast<int>( result - 1 );
1335}
1336
1337
1338template <typename T>
1339void DIALOG_SIM_MODEL<T>::onRadioButton( wxCommandEvent& aEvent )
1340{
1341 m_prevModel = nullptr; // Ensure the Model panel will be rebuild after updating other params.
1342 updateWidgets();
1343}
1344
1345
1346template <typename T>
1347void DIALOG_SIM_MODEL<T>::onLibraryPathText( wxCommandEvent& aEvent )
1348{
1349 m_rbLibraryModel->SetValue( true );
1350}
1351
1352
1353template <typename T>
1355{
1356 m_rbLibraryModel->SetValue( true );
1357
1359 wxString path = m_libraryPathText->GetValue();
1360
1361 if( loadLibrary( path, reporter, true ) || path.IsEmpty() )
1362 m_infoBar->Hide();
1363 else if( reporter.HasMessage() )
1364 m_infoBar->ShowMessage( reporter.GetMessages() );
1365
1366 updateWidgets();
1367}
1368
1369
1370template <typename T>
1372{
1373 CallAfter(
1374 [this]()
1375 {
1376 // Disable logging -- otherwise we'll end up in an endless loop of show-log,
1377 // kill-focus, show-log, kill-focus, etc.
1378 wxLogNull doNotLog;
1379
1380 wxCommandEvent dummy;
1382 } );
1383
1384 aEvent.Skip(); // mandatory in wxFocusEvent events
1385}
1386
1387
1388template <typename T>
1389void DIALOG_SIM_MODEL<T>::onBrowseButtonClick( wxCommandEvent& aEvent )
1390{
1391 static wxString s_mruPath;
1392
1393 wxString path = s_mruPath.IsEmpty() ? Prj().GetProjectPath() : s_mruPath;
1394 wxFileDialog dlg( this, _( "Browse Models" ), path );
1396
1397 dlg.SetCustomizeHook( customize );
1398
1400
1401 if( dlg.ShowModal() == wxID_CANCEL )
1402 return;
1403
1404 m_rbLibraryModel->SetValue( true );
1405
1406 path = dlg.GetPath();
1407 wxFileName fn( path );
1408 s_mruPath = fn.GetPath();
1409
1410 if( customize.GetEmbed() )
1411 {
1412 EMBEDDED_FILES::EMBEDDED_FILE* result = m_filesStack[0]->AddFile( fn, false );
1413 path = result->GetLink();
1414 }
1415 else if( fn.MakeRelativeTo( Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS( ".." ) ) )
1416 {
1417 path = fn.GetFullPath();
1418 }
1419
1421
1422 if( loadLibrary( path, reporter, true ) )
1423 m_infoBar->Hide();
1424 else
1425 m_infoBar->ShowMessage( reporter.GetMessages() );
1426
1427 updateWidgets();
1428}
1429
1430
1431template <typename T>
1432void DIALOG_SIM_MODEL<T>::onFilterCharHook( wxKeyEvent& aKeyStroke )
1433{
1434 int count = m_modelListBox->GetCount();
1435
1436 if( count == 0 )
1437 {
1438 aKeyStroke.Skip();
1439 return;
1440 }
1441
1442 int sel = m_modelListBox->GetSelection();
1443
1444 switch( aKeyStroke.GetKeyCode() )
1445 {
1446 case WXK_UP:
1447 if( sel == wxNOT_FOUND )
1448 sel = count - 1;
1449 else
1450 sel = std::max( sel - 1, 0 );
1451
1452 break;
1453
1454 case WXK_DOWN:
1455 if( sel == wxNOT_FOUND )
1456 sel = 0;
1457 else
1458 sel = std::min( sel + 1, count - 1 );
1459
1460 break;
1461
1462 case WXK_RETURN:
1463 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
1464 return;
1465
1466 default:
1467 aKeyStroke.Skip();
1468 return;
1469 }
1470
1471 m_modelListBox->SetSelection( sel );
1472}
1473
1474
1475template <typename T>
1476void DIALOG_SIM_MODEL<T>::onModelFilter( wxCommandEvent& aEvent )
1477{
1478 if( library() == nullptr ) // No library loaded
1479 return;
1480
1481 wxArrayString modelNames;
1482 wxString current = m_modelListBox->GetStringSelection();
1483 wxString filter = wxT( "*" ) + m_modelFilter->GetValue() + wxT( "*" );
1484
1485 for( const auto& [name, model] : library()->GetModels() )
1486 {
1487 wxString wx_name( name );
1488
1489 if( wx_name.Matches( filter ) )
1490 modelNames.Add( wx_name );
1491 }
1492
1493 modelNames.Sort();
1494
1495 m_modelListBox->Clear();
1496 m_modelListBox->Append( modelNames );
1497
1498 if( m_modelListBox->GetCount() > 0 )
1499 {
1500 if( !m_modelListBox->SetStringSelection( current ) )
1501 m_modelListBox->SetSelection( 0 );
1502 }
1503}
1504
1505
1506template <typename T>
1507void DIALOG_SIM_MODEL<T>::onModelNameChoice( wxCommandEvent& aEvent )
1508{
1509 if( isIbisLoaded() )
1510 {
1511 wxArrayString pinLabels;
1512 SIM_MODEL_IBIS* modelkibis = dynamic_cast<SIM_MODEL_IBIS*>( &curModel() );
1513
1514 wxCHECK2( modelkibis, return );
1515
1516 for( std::pair<wxString, wxString> strs : modelkibis->GetIbisPins() )
1517 pinLabels.Add( strs.first + wxT( " - " ) + strs.second );
1518
1519 m_pinCombobox->Set( pinLabels );
1520
1521 wxArrayString emptyArray;
1522 m_pinModelCombobox->Set( emptyArray );
1523 }
1524
1525 m_rbLibraryModel->SetValue( true );
1526
1527 if( SIM_MODEL_SPICE_FALLBACK* fallback =
1528 dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( &curModel() ) )
1529 {
1530 wxArrayString lines = wxSplit( fallback->GetSpiceCode(), '\n' );
1531 wxString code;
1532
1533 for( const wxString& line : lines )
1534 {
1535 if( !line.StartsWith( '*' ) )
1536 {
1537 if( !code.IsEmpty() )
1538 code += "\n";
1539
1540 code += line;
1541 }
1542 }
1543
1544 m_infoBar->ShowMessage( wxString::Format( _( "Failed to parse:\n\n"
1545 "%s\n"
1546 "Using generic SPICE model." ),
1547 code ) );
1548 }
1549 else
1550 {
1551 m_infoBar->Hide();
1552 }
1553
1554 updateWidgets();
1555}
1556
1557
1558template <typename T>
1559void DIALOG_SIM_MODEL<T>::onPinCombobox( wxCommandEvent& aEvent )
1560{
1561 wxArrayString modelLabels;
1562
1563 SIM_MODEL_IBIS& ibisModel = static_cast<SIM_MODEL_IBIS&>( curModel() );
1564
1565 std::vector<std::pair<std::string, std::string>> strs = ibisModel.GetIbisPins();
1566 std::string pinNumber = strs.at( m_pinCombobox->GetSelection() ).first;
1567
1568 const SIM_LIBRARY_IBIS* ibisLibrary = dynamic_cast<const SIM_LIBRARY_IBIS*>( library() );
1569
1570 ibisModel.ChangePin( *ibisLibrary, pinNumber );
1571
1572 ibisModel.m_enableDiff = ibisLibrary->isPinDiff( ibisModel.GetComponentName(), pinNumber );
1573
1574 for( wxString modelName : ibisModel.GetIbisModels() )
1575 modelLabels.Add( modelName );
1576
1577 m_pinModelCombobox->Set( modelLabels );
1578
1579 if( m_pinModelCombobox->GetCount() == 1 )
1580 m_pinModelCombobox->SetSelection( 0 );
1581 else
1582 m_pinModelCombobox->SetSelection( -1 );
1583
1584 updateWidgets();
1585}
1586
1587
1588template <typename T>
1590{
1591 m_pinCombobox->SetSelection( m_pinCombobox->FindString( m_pinCombobox->GetValue() ) );
1592
1593 onPinModelCombobox( aEvent );
1594}
1595
1596
1597template <typename T>
1598void DIALOG_SIM_MODEL<T>::onPinModelCombobox( wxCommandEvent& aEvent )
1599{
1600 if( SIM_MODEL_IBIS* ibismodel = dynamic_cast<SIM_MODEL_IBIS*>( &curModel() ) )
1601 {
1602 const SIM_LIBRARY_IBIS* ibisLibrary = dynamic_cast<const SIM_LIBRARY_IBIS*>( library() );
1603
1604 // Skip uncommitted combobox text so SetIbisModel doesn't silently fail.
1605 if( ibisLibrary
1606 && m_pinCombobox->GetSelection() >= 0
1607 && m_pinModelCombobox->GetSelection() >= 0 )
1608 {
1609 std::string pinNumber = ibismodel->GetIbisPins()
1610 .at( m_pinCombobox->GetSelection() )
1611 .first;
1612 std::string modelName = m_pinModelCombobox->GetStringSelection().ToStdString();
1613
1614 ibismodel->SetIbisModel( *ibisLibrary, pinNumber, modelName );
1615 }
1616 }
1617
1618 updateWidgets();
1619}
1620
1621
1622template <typename T>
1624{
1625 m_pinModelCombobox->SetSelection( m_pinModelCombobox->FindString( m_pinModelCombobox->GetValue() ) );
1626}
1627
1628
1629template <typename T>
1631{
1632 if( SIM_MODEL_IBIS* modelibis = dynamic_cast<SIM_MODEL_IBIS*>( &curModel() ) )
1633 {
1634 bool diff = m_differentialCheckbox->GetValue() && modelibis->CanDifferential();
1635 modelibis->SwitchSingleEndedDiff( diff );
1636
1637 updateWidgets();
1638 }
1639}
1640
1641
1642template <typename T>
1643void DIALOG_SIM_MODEL<T>::onDeviceTypeChoice( wxCommandEvent& aEvent )
1644{
1645 m_rbBuiltinModel->SetValue( true );
1646
1647 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
1648 {
1649 if( SIM_MODEL::DeviceInfo( deviceType ).description == m_deviceChoice->GetStringSelection() )
1650 {
1651 m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
1652 break;
1653 }
1654 }
1655
1656 updateWidgets();
1657}
1658
1659
1660template <typename T>
1661void DIALOG_SIM_MODEL<T>::onWaveformChoice( wxCommandEvent& aEvent )
1662{
1663 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1664 wxString typeDescription = m_waveformChoice->GetStringSelection();
1665
1666 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
1667 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
1668 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
1669 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
1670 {
1671 if( equivalent( deviceType, SIM_MODEL::TypeInfo( type ).deviceType )
1672 && typeDescription == SIM_MODEL::TypeInfo( type ).description )
1673 {
1674 int idx = 0;
1675 wxString sel = m_modelListBox->GetStringSelection();
1676
1677 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
1678 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
1679
1680 SIM_MODEL_IBIS& baseModel = static_cast<SIM_MODEL_IBIS&>( m_libraryModelsMgr.GetModels()[idx].get() );
1681
1682 m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_IBIS>( type, baseModel ) );
1683
1684 try
1685 {
1686 m_libraryModelsMgr.GetModels()[idx].get().ReadDataFields(
1688 }
1689 catch( IO_ERROR& err )
1690 {
1691 DisplayErrorMessage( this, err.What() );
1692 }
1693
1694 m_curModelType = type;
1695 break;
1696 }
1697 }
1698
1699 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1700 updateWidgets();
1701}
1702
1703
1704template <typename T>
1705void DIALOG_SIM_MODEL<T>::onTypeChoice( wxCommandEvent& aEvent )
1706{
1707 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1708 wxString typeDescription = m_deviceSubtypeChoice->GetStringSelection();
1709
1710 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1711 {
1712 if( equivalent( deviceType, SIM_MODEL::TypeInfo( type ).deviceType )
1713 && typeDescription == SIM_MODEL::TypeInfo( type ).description )
1714 {
1715 m_curModelType = type;
1716 break;
1717 }
1718 }
1719
1720 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1721 updateWidgets();
1722}
1723
1724
1725template <typename T>
1726void DIALOG_SIM_MODEL<T>::onPageChanging( wxBookCtrlEvent& event )
1727{
1729}
1730
1731
1732template <typename T>
1734{
1735 int symbolPinIndex = aEvent.GetRow();
1736 wxString oldModelPinName = aEvent.GetString();
1737 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
1738
1739 int oldModelPinIndex = getModelPinIndex( oldModelPinName );
1740 int modelPinIndex = getModelPinIndex( modelPinName );
1741
1742 if( oldModelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED )
1743 curModel().AssignSymbolPinNumberToModelPin( oldModelPinIndex, "" );
1744
1745 if( modelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED )
1746 {
1747 SCH_PIN* symbolPin = m_sortedPartPins.at( symbolPinIndex );
1748
1749 curModel().AssignSymbolPinNumberToModelPin( modelPinIndex, symbolPin->GetShownNumber() );
1750 }
1751
1753
1754 aEvent.Skip();
1755}
1756
1757
1758template <typename T>
1760{
1761 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
1762
1764 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::MODEL, gridWidth / 2 );
1765 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::SYMBOL, gridWidth / 2 );
1766
1767 aEvent.Skip();
1768}
1769
1770
1771template <typename T>
1773{
1774 // By default, when a property grid is focused, the textbox is not immediately focused until
1775 // Tab key is pressed. This is inconvenient, so we fix that here.
1776
1777 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1778 wxPGProperty* selected = grid->GetSelection();
1779
1780 if( !selected )
1781 selected = grid->wxPropertyGridInterface::GetFirst();
1782
1783#if wxCHECK_VERSION( 3, 3, 0 )
1784 if( selected )
1785 grid->DoSelectProperty( selected, wxPGSelectPropertyFlags::Focus );
1786#else
1787 if( selected )
1788 grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
1789#endif
1790
1791 aEvent.Skip();
1792}
1793
1794
1795template <typename T>
1796void DIALOG_SIM_MODEL<T>::onParamGridSelectionChange( wxPropertyGridEvent& aEvent )
1797{
1798 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1799
1800 // Jump over categories.
1801 if( grid->GetSelection() && grid->GetSelection()->IsCategory() )
1802 {
1803 wxPGProperty* selection = grid->GetSelection();
1804
1805 // If the new selection is immediately above the previous selection, we jump up. Otherwise
1806 // we jump down. We do this by simulating up or down arrow keys.
1807
1808 wxPropertyGridIterator it = grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
1809 it.Next();
1810
1811 wxKeyEvent* keyEvent = new wxKeyEvent( wxEVT_KEY_DOWN );
1812
1813 if( *it == m_prevParamGridSelection )
1814 {
1815 if( !selection->IsExpanded() )
1816 {
1817 grid->Expand( selection );
1818 keyEvent->m_keyCode = WXK_DOWN;
1819 wxQueueEvent( grid, keyEvent );
1820
1821 // Does not work for some reason.
1822 /*m_paramGrid->DoSelectProperty( selection->Item( selection->GetChildCount() - 1 ),
1823 wxPG_SEL_FOCUS );*/
1824 }
1825 else
1826 {
1827 keyEvent->m_keyCode = WXK_UP;
1828 wxQueueEvent( grid, keyEvent );
1829 }
1830 }
1831 else
1832 {
1833 if( !selection->IsExpanded() )
1834 grid->Expand( selection );
1835
1836 keyEvent->m_keyCode = WXK_DOWN;
1837 wxQueueEvent( grid, keyEvent );
1838 }
1839
1840 m_prevParamGridSelection = grid->GetSelection();
1841 return;
1842 }
1843
1844 wxWindow* editorControl = grid->GetEditorControl();
1845
1846 if( !editorControl )
1847 {
1848 m_prevParamGridSelection = grid->GetSelection();
1849 return;
1850 }
1851
1852 // Without this the user had to press tab before they could edit the field.
1853 editorControl->SetFocus();
1854 m_prevParamGridSelection = grid->GetSelection();
1855}
1856
1857
1858template <typename T>
1859void DIALOG_SIM_MODEL<T>::onUpdateUI( wxUpdateUIEvent& aEvent )
1860{
1861 // This is currently patched in wxPropertyGrid::ScrollWindow() in the Mac wxWidgets fork.
1862 // However, we may need this version if it turns out to be an issue on other platforms and
1863 // we can't get it upstreamed.
1864#if 0
1865 // It's a shame to do this on the UpdateUI event, but neither the wxPropertyGridManager,
1866 // wxPropertyGridPage, wxPropertyGrid, nor the wxPropertyGrid's GetCanvas() window appear
1867 // to get scroll events.
1868
1869 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1870 wxTextCtrl* ctrl = grid->GetEditorTextCtrl();
1871
1872 if( ctrl )
1873 {
1874 wxRect ctrlRect = ctrl->GetScreenRect();
1875 wxRect gridRect = grid->GetScreenRect();
1876
1877 if( ctrlRect.GetTop() < gridRect.GetTop() || ctrlRect.GetBottom() > gridRect.GetBottom() )
1878 grid->ClearSelection();
1879 }
1880#endif
1881}
1882
1883
1884template <typename T>
1885void DIALOG_SIM_MODEL<T>::adjustParamGridColumns( int aWidth, bool aForce )
1886{
1887 wxPropertyGrid* grid = m_paramGridMgr->GetGrid();
1888 int margin = 15;
1889 int indent = 20;
1890
1891 if( aWidth != m_lastParamGridWidth || aForce )
1892 {
1893 m_lastParamGridWidth = aWidth;
1894
1895 grid->FitColumns();
1896
1897 std::vector<int> colWidths;
1898
1899 for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ )
1900 {
1901 if( ii == PARAM_COLUMN::DESCRIPTION )
1902 colWidths.push_back( grid->GetState()->GetColumnWidth( ii ) + margin + indent );
1903 else if( ii == PARAM_COLUMN::VALUE )
1904 colWidths.push_back( std::max( 72, grid->GetState()->GetColumnWidth( ii ) ) + margin );
1905 else
1906 colWidths.push_back( 60 + margin );
1907
1908 aWidth -= colWidths[ ii ];
1909 }
1910
1911 for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ )
1912 grid->SetColumnProportion( ii, colWidths[ ii ] );
1913
1914 grid->ResetColumnSizes();
1915 grid->RefreshEditor();
1916 }
1917}
1918
1919
1920template <typename T>
1922{
1923 adjustParamGridColumns( event.GetSize().GetX(), false );
1924
1925 event.Skip();
1926}
1927
1928
1929template class DIALOG_SIM_MODEL<SCH_SYMBOL>;
1930template class DIALOG_SIM_MODEL<LIB_SYMBOL>;
const char * name
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap, int aMinHeight)
Definition bitmap.cpp:106
@ INVALID_BITMAP
wxPropertyGridManager * m_paramGridMgr
DIALOG_SIM_MODEL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Simulation Model Editor"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
wxStaticText * m_decompositionLabel
wxStaticText * m_deviceSubtypeLabel
STD_BITMAP_BUTTON * m_browseButton
wxStyledTextCtrl * m_subckt
wxPropertyGridPage * m_paramGrid
wxStyledTextCtrl * m_codePreview
const SIM_MODEL * m_prevModel
void onTypeChoice(wxCommandEvent &aEvent) override
void onLibraryPathTextKillFocus(wxFocusEvent &aEvent) override
wxString getSymbolPinString(int aSymbolPinNumber) const
void updateBuiltinModelWidgets(SIM_MODEL *aModel)
void onPinAssignmentsGridCellChange(wxGridEvent &aEvent) override
void onFilterCharHook(wxKeyEvent &aKeyStroke) override
int findSymbolPinRow(const wxString &aSymbolPinNumber) const
void onModelNameChoice(wxCommandEvent &aEvent) override
void onRadioButton(wxCommandEvent &aEvent) override
SCINTILLA_TRICKS * m_scintillaTricksSubckt
bool loadLibrary(const wxString &aLibraryPath, REPORTER &aReporter, bool aForceReload=false)
SIM_LIB_MGR m_builtinModelsMgr
int getModelPinIndex(const wxString &aModelPinString) const
void onModelFilter(wxCommandEvent &aEvent) override
void onLibraryPathText(wxCommandEvent &aEvent) override
void onDifferentialCheckbox(wxCommandEvent &event) override
void onParamGridSelectionChange(wxPropertyGridEvent &aEvent)
void removeOrphanedPinAssignments(SIM_MODEL *aModel)
void adjustParamGridColumns(int aWidth, bool aForce)
Show/populate the decomposition controls (multi-unit only) and sync their enabled state.
std::vector< SCH_FIELD > & m_fields
std::vector< SCH_PIN * > m_sortedPartPins
Pins of the current part.
wxPGProperty * newParamProperty(SIM_MODEL *aModel, int aParamIndex) const
void onDecompositionModeChoice(wxCommandEvent &aEvent) override
wxPGProperty * m_prevParamGridSelection
void onPinModelCombobox(wxCommandEvent &event) override
const SIM_LIBRARY * library() const
SIM_MODEL & curModel() const
SIM_LIB_MGR m_libraryModelsMgr
void onBrowseButtonClick(wxCommandEvent &aEvent) override
void onPinComboboxTextEnter(wxCommandEvent &event) override
void onPinCombobox(wxCommandEvent &event) override
wxPGProperty * m_firstCategory
SCINTILLA_TRICKS * m_scintillaTricksCode
wxString m_inferredValueRestore
std::map< wxString, int > m_modelListBoxEntryToLibraryIdx
void updatePinAssignments(SIM_MODEL *aModel, bool aForceUpdatePins)
void onUpdateUI(wxUpdateUIEvent &aEvent)
DIALOG_SIM_MODEL(wxWindow *aParent, EDA_BASE_FRAME *aFrame, T &aSymbol, std::vector< SCH_FIELD > &aFields)
wxString getModelPinString(SIM_MODEL *aModel, int aModelPinIndex) const
void onPinAssignmentsGridSize(wxSizeEvent &aEvent) override
void updateIbisWidgets(SIM_MODEL *aModel)
void onParamGridSetFocus(wxFocusEvent &aEvent)
void updateModelParamsTab(SIM_MODEL *aModel)
bool TransferDataFromWindow() override
SIM_MODEL::TYPE m_curModelType
void updateModelCodeTab(SIM_MODEL *aModel)
void onSizeParamGrid(wxSizeEvent &event) override
void onPageChanging(wxNotebookEvent &event) override
std::vector< EMBEDDED_FILES * > m_filesStack
void onWaveformChoice(wxCommandEvent &aEvent) override
std::map< SIM_MODEL::DEVICE_T, SIM_MODEL::TYPE > m_curModelTypeOfDeviceType
void onPinModelComboboxTextEnter(wxCommandEvent &event) override
EDA_BASE_FRAME * m_frame
void onLibraryPathTextEnter(wxCommandEvent &aEvent) override
static void RestoreInferredValue(std::vector< SCH_FIELD > &aFields, const wxString &aOriginalValue, bool aOverwritten, bool aStoredInValue)
Restore an inferred passive's Value field after WriteFields().
void onDeviceTypeChoice(wxCommandEvent &aEvent) override
bool TransferDataToWindow() override
void addParamPropertyIfRelevant(SIM_MODEL *aModel, int aParamIndex)
The base frame for deriving all KiCad main window classes.
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:57
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()
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
Define a library symbol object.
Definition lib_symbol.h:119
void AppendParentEmbeddedFiles(std::vector< EMBEDDED_FILES * > &aStack) const
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.
Definition reporter.h:267
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition project.cpp:183
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
Definition reporter.h:152
EMBEDDED_FILES * GetEmbeddedFiles() override
Schematic editor (Eeschema) main window.
virtual const wxString & GetText() const override
Return the string associated with the text object.
Definition sch_field.h:138
void SetText(const wxString &aText) override
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:281
const wxString & GetShownNumber() const
Definition sch_pin.cpp:691
Schematic symbol object.
Definition sch_symbol.h:75
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.
static constexpr auto MODEL_FIELD
static constexpr auto PIN_FIELD
static constexpr auto DIFF_FIELD
bool isPinDiff(const std::string &aComp, const std::string &aPinNumber) const
static constexpr auto LIBRARY_FIELD
Definition sim_library.h:31
static constexpr auto NAME_FIELD
Definition sim_library.h:32
bool SetIbisModel(const SIM_LIBRARY_IBIS &aLib, const std::string &aPinNumber, const std::string &aModelName)
Bind to a KIBIS model, set IO mode from its type, manage sw_state.
std::vector< std::pair< std::string, std::string > > GetIbisPins() const
void SwitchSingleEndedDiff(bool aDiff) override
bool CanDifferential() const
std::vector< std::string > GetIbisModels() const
bool ChangePin(const SIM_LIBRARY_IBIS &aLib, const std::string &aPinNumber)
update the list of available models based on the pin number.
std::string GetComponentName() const
static INFO TypeInfo(TYPE aType)
int GetPinCount() const
Definition sim_model.h:478
static bool InferSimModel(const wxString &aPrefix, std::span< const wxString > aPins, std::vector< SCH_FIELD > *aFields, bool aResolve, int aDepth, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
aPins follows lexical symbol-pin number order, including duplicate numbers.
const SPICE_GENERATOR & SpiceGenerator() const
Definition sim_model.h:429
virtual const PARAM & GetParam(unsigned aParamIndex) const
static TYPE ReadTypeFromFields(const std::vector< SCH_FIELD > &aFields, bool aResolve, int aDepth, REPORTER &aReporter)
int GetParamCount() const
Definition sim_model.h:488
void AssignSymbolPinNumberToModelPin(int aPinIndex, const wxString &aSymbolPinNumber)
DEVICE_INFO GetDeviceInfo() const
Definition sim_model.h:467
DEVICE_T GetDeviceType() const
Definition sim_model.h:470
static DEVICE_INFO DeviceInfo(DEVICE_T aDeviceType)
Definition sim_model.cpp:57
virtual bool HasAutofill() const
Definition sim_model.h:505
const SIM_MODEL_PIN & GetPin(unsigned aIndex) const
Definition sim_model.h:479
virtual bool HasPrimaryValue() const
Definition sim_model.h:506
TYPE GetType() const
Definition sim_model.h:471
static std::vector< wxString > PinNumbers(std::span< const SCH_PIN *const > aPins)
const SIM_MODEL::PARAM & GetParam() const
@ TYPE_FLOAT_VECTOR
Definition sim_value.h:71
@ TYPE_BOOL_VECTOR
Definition sim_value.h:69
@ TYPE_INT_VECTOR
Definition sim_value.h:70
@ TYPE_COMPLEX_VECTOR
Definition sim_value.h:72
@ TYPE_STRING
Definition sim_value.h:67
@ TYPE_COMPLEX
Definition sim_value.h:66
Special netlist exporter flavor that allows one to override simulation commands.
virtual std::string Preview(const SPICE_ITEM &aItem) const
A wrapper for reporting to a wxString object.
Definition reporter.h:242
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition confirm.cpp:217
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_REFRESH_FROM_MODEL
SIM_MODEL::PARAM::CATEGORY CATEGORY
#define _(s)
@ NONE
Definition eda_fill.h:42
static const std::string KiCadUriPrefix
PROJECT & Prj()
Definition kicad.cpp:727
static bool loadLibrary(SYMBOL_LIBRARY_ADAPTER &aAdapter, const wxString &aNickname, std::vector< KI_ERROR > &aErrors)
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition wxgtk/ui.cpp:367
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:521
KICOMMON_API wxFont GetStatusFont(wxWindow *aWindow)
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE shape)
Definition pin_type.cpp:245
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
void SetFieldValue(std::vector< SCH_FIELD > &aFields, const wxString &aFieldName, const std::string &aValue, bool aIsVisible=true, const SCH_SHEET_PATH *aSheetPath=nullptr, const wxString &aVariantName=wxEmptyString)
Definition sch_field.h:456
wxString GetFieldValue(const std::vector< SCH_FIELD > *aFields, FIELD_T aFieldType)
Definition sch_field.h:431
const SCH_FIELD * FindField(const std::vector< SCH_FIELD > &aFields, FIELD_T aFieldId)
Definition sch_field.h:393
#define SIM_PINS_FIELD
Definition sim_model.h:51
#define SIM_DEVICE_FIELD
Definition sim_model.h:49
#define SIM_REFERENCE_FIELD
Definition sim_model.h:46
#define SIM_PARAMS_FIELD
Definition sim_model.h:53
#define SIM_DECOMPOSITION_FIELD
Definition sim_model.h:52
#define SIM_DEVICE_SUBTYPE_FIELD
Definition sim_model.h:50
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Per-component decomposition descriptor stored in the Sim.Decomposition field.
static SIM_DECOMPOSITION Parse(const wxString &aField)
std::vector< wxString > sharedModelPins
wxString Format() const
std::vector< std::string > enumValues
Definition sim_model.h:386
SIM_VALUE::TYPE type
Definition sim_model.h:377
std::string defaultValue
Definition sim_model.h:380
std::string description
Definition sim_model.h:381
std::string value
Definition sim_model.h:398
const INFO & info
Definition sim_model.h:399
static constexpr auto NOT_CONNECTED
Definition sim_model.h:71
const std::string modelPinName
Definition sim_model.h:68
wxString symbolPinNumber
Definition sim_model.h:69
std::string modelName
@ REFERENCE
Field Reference of part, i.e. "IC21".
@ VALUE
Field Value of part, i.e. "3.3K".
std::string subckt
std::string path
IbisParser parser & reporter
KIBIS_MODEL * model
KIBIS_PIN * pin
wxString result
Test unit parsing edge cases and error handling.