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
233 m_libraryModelsMgr.CreateModel( nullptr, m_sortedPartPins, m_fields, true, 0, reporter );
234
235 m_modelListBox->Clear();
236 m_modelListBox->Append( _( "<unknown>" ) );
237 m_modelListBox->SetSelection( 0 );
238 }
239 else
240 {
241 std::string modelName = GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD, true, 0 );
242 int modelIdx = m_modelListBox->FindString( modelName );
243
244 if( modelIdx == wxNOT_FOUND )
245 {
246 m_infoBar->ShowMessage( wxString::Format( _( "No model named '%s' in library." ),
247 modelName ) );
248
249 // Default to first item in library if any exist
250 if( m_modelListBox->GetCount() > 0 )
251 m_modelListBox->SetSelection( 0 );
252 }
253 else
254 {
255 m_infoBar->Hide();
256 m_modelListBox->SetSelection( modelIdx );
257 }
258
259 m_curModelType = curModel().GetType();
260 }
261
262 if( isIbisLoaded() && ( m_modelListBox->GetSelection() >= 0 ) )
263 {
264 int idx = 0;
265 wxString sel = m_modelListBox->GetStringSelection();
266
267 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
268 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
269
270 SIM_MODEL_IBIS* ibismodel = dynamic_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels()[idx].get() );
271
272 if( ibismodel )
273 {
274 onModelNameChoice( dummyEvent ); // refresh list of pins
275
276 int i = 0;
277
278 for( const std::pair<std::string, std::string>& strs : ibismodel->GetIbisPins() )
279 {
280 if( strs.first == GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::PIN_FIELD, true, 0 ) )
281 {
282 auto ibisLibrary = static_cast<const SIM_LIBRARY_IBIS*>( library() );
283
284 ibismodel->ChangePin( *ibisLibrary, strs.first );
285 m_pinCombobox->SetSelection( static_cast<int>( i ) );
286 break;
287 }
288 i++;
289 }
290
291 if( i < static_cast<int>( ibismodel->GetIbisPins().size() ) )
292 {
293 onPinCombobox( dummyEvent ); // refresh list of models
294
295 wxString ibisModel = GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::MODEL_FIELD, true, 0 );
296 m_pinModelCombobox->SetStringSelection( ibisModel );
297 }
298
299 if( GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::DIFF_FIELD, true, 0 ) == "1" )
300 {
301 ibismodel->SwitchSingleEndedDiff( true );
302 m_differentialCheckbox->SetValue( true );
303 }
304 else
305 {
306 ibismodel->SwitchSingleEndedDiff( false );
307 m_differentialCheckbox->SetValue( false );
308 }
309
310 // SetIbisModel derives the IO mode from KIBIS_MODEL::m_type
311 // (Series / Series_switch override the differential layout).
312 auto ibisLibrary = static_cast<const SIM_LIBRARY_IBIS*>( library() );
313 std::string pinNum = GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::PIN_FIELD,
314 true, 0 );
316 true, 0 );
317
318 if( ibisLibrary && !pinNum.empty() && !modelNm.empty() )
319 ibismodel->SetIbisModel( *ibisLibrary, pinNum, modelNm );
320 }
321 }
322 }
323 else if( !GetFieldValue( &m_fields, SIM_DEVICE_FIELD, false, 0 ).empty()
325 {
326 // The model is sourced from the instance.
327 m_rbBuiltinModel->SetValue( true );
328
329 reporter.Clear();
331
332 if( reporter.HasMessage() )
333 DisplayErrorMessage( this, reporter.GetMessages() );
334 }
335
336 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
337 {
338 if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
339 {
340 reporter.Clear();
341 m_builtinModelsMgr.CreateModel( m_fields, true, 0, m_sortedPartPins, reporter );
342
343 if( reporter.HasMessage() )
344 {
345 DisplayErrorMessage( this, _( "Failed to read simulation model from fields." )
346 + wxT( "\n\n" ) + reporter.GetMessages() );
347 }
348 }
349 else
350 {
351 m_builtinModelsMgr.CreateModel( type, m_sortedPartPins, reporter );
352 }
353
354 SIM_MODEL::DEVICE_T deviceTypeT = SIM_MODEL::TypeInfo( type ).deviceType;
355
356 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
357 m_curModelTypeOfDeviceType[deviceTypeT] = type;
358 }
359
360 if( storeInValue )
361 curModel().SetIsStoredInValue( true );
362
363 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
364
366
367 onRadioButton( dummyEvent );
368 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
369}
370
371
372template <typename T>
374{
375 if( !m_pinAssignmentsGrid->CommitPendingChanges() )
376 return false;
377
378 if( !m_paramGrid->GetGrid()->CommitChangesFromEditor() )
379 return false;
380
381 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
382 return false;
383
385 std::string path;
386 std::string name;
387
388 if( m_rbLibraryModel->GetValue() )
389 {
390 path = m_libraryPathText->GetValue();
391 wxFileName fn( path );
392
393 if( !path.starts_with( FILEEXT::KiCadUriPrefix ) && fn.MakeRelativeTo( Prj().GetProjectPath() )
394 && !fn.GetFullPath().StartsWith( ".." ) )
395 {
396 path = fn.GetFullPath();
397 }
398
399 if( m_modelListBox->GetSelection() >= 0 )
400 name = m_modelListBox->GetStringSelection().ToStdString();
401 else if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( &model ) )
403 }
404
407
408 if( isIbisLoaded() && !m_libraryModelsMgr.GetModels().empty() )
409 {
410 int idx = 0;
411 wxString sel = m_modelListBox->GetStringSelection();
412
413 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
414 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
415
416 auto* ibismodel =
417 static_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels().at( idx ).get() );
418
419 if( ibismodel )
420 {
421 std::string pins;
422 std::string modelName = std::string( m_pinModelCombobox->GetValue().c_str() );
423 std::string differential;
424
425 if( m_pinCombobox->GetSelection() >= 0 )
426 pins = ibismodel->GetIbisPins().at( m_pinCombobox->GetSelection() ).first;
427
428 if( ibismodel->CanDifferential() && m_differentialCheckbox->GetValue() )
429 differential = "1";
430
434 }
435 }
436
437 if( model.GetType() == SIM_MODEL::TYPE::RAWSPICE )
438 {
439 if( m_modelNotebook->GetSelection() == 0 )
441
442 wxString code = m_codePreview->GetText().Trim( true ).Trim( false );
443 model.SetParamValue( "model", std::string( code.ToUTF8() ) );
444 }
445
446 model.SetIsStoredInValue( m_saveInValueCheckbox->GetValue() );
447
448 for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
449 {
450 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( row, PIN_COLUMN::MODEL );
451 wxString symbolPinName = m_sortedPartPins.at( row )->GetShownNumber();
452
453 model.AssignSymbolPinNumberToModelPin( getModelPinIndex( modelPinName ),
454 std::string( symbolPinName.ToUTF8() ) );
455 }
456
458
459 curModel().WriteFields( m_fields );
460
462 model.IsStoredInValue() );
463
464 // Decomposition is a component-level choice and is independent of the model fields written
465 // above. Only multi-unit symbols expose it; write it after WriteFields() so it is preserved.
466 if( m_symbol.GetUnitCount() > 1 )
467 {
468 SIM_DECOMPOSITION decomposition;
469
470 if( m_decompositionChoice->GetSelection() == 1 )
471 {
473
474 wxStringTokenizer sharedTokens( m_sharedPinsText->GetValue(), wxS( ", \t" ),
475 wxTOKEN_STRTOK );
476
477 while( sharedTokens.HasMoreTokens() )
478 decomposition.sharedModelPins.push_back( sharedTokens.GetNextToken() );
479 }
480
481 // Whole-device formats to an empty string, which clears any previous repeat selection.
482 SetFieldValue( m_fields, SIM_DECOMPOSITION_FIELD, decomposition.Format().ToStdString(),
483 false );
484 }
485
486 return true;
487}
488
489
490template <typename T>
491void DIALOG_SIM_MODEL<T>::RestoreInferredValue( std::vector<SCH_FIELD>& aFields,
492 const wxString& aOriginalValue, bool aOverwritten,
493 bool aStoredInValue )
494{
495 if( !aOverwritten || aStoredInValue )
496 return;
497
498 if( SCH_FIELD* valueField = FindField( aFields, FIELD_T::VALUE ) )
499 valueField->SetText( aOriginalValue );
500}
501
502
503template <typename T>
505{
506 bool multiUnit = m_symbol.GetUnitCount() > 1;
507
508 m_decompositionLabel->Show( multiUnit );
509 m_decompositionChoice->Show( multiUnit );
510 m_sharedPinsLabel->Show( multiUnit );
511 m_sharedPinsText->Show( multiUnit );
512
513 if( multiUnit )
514 {
517
518 bool repeat = decomposition.mode == SIM_DECOMPOSITION::MODE::REPEAT_PER_UNIT;
519
520 m_decompositionChoice->SetSelection( repeat ? 1 : 0 );
521
522 wxString shared;
523
524 for( const wxString& pin : decomposition.sharedModelPins )
525 {
526 if( !shared.IsEmpty() )
527 shared += wxS( ", " );
528
529 shared += pin;
530 }
531
532 m_sharedPinsText->SetValue( shared );
533 m_sharedPinsLabel->Enable( repeat );
534 m_sharedPinsText->Enable( repeat );
535 }
536
537 m_pinAssignmentsPanel->Layout();
538}
539
540
541template <typename T>
543{
544 bool repeat = m_decompositionChoice->GetSelection() == 1;
545
546 m_sharedPinsLabel->Enable( repeat );
547 m_sharedPinsText->Enable( repeat );
548
549 aEvent.Skip();
550}
551
552
553template <typename T>
555{
556 // always enable the library browser button -- it makes for fewer clicks if the user has a
557 // whole bunch of inferred passives that they want to specify library models for
558 m_browseButton->Enable();
559
560 // if we're in an undetermined state then enable everything for faster access
561 bool undetermined = !m_rbLibraryModel->GetValue() && !m_rbBuiltinModel->GetValue();
562 bool enableLibCtrls = m_rbLibraryModel->GetValue() || undetermined;
563 bool enableBuiltinCtrls = m_rbBuiltinModel->GetValue() || undetermined;
564
565 m_pathLabel->Enable( enableLibCtrls );
566 m_libraryPathText->Enable( enableLibCtrls );
567 m_modelNameLabel->Enable( enableLibCtrls );
568 m_modelFilter->Enable( enableLibCtrls && !isIbisLoaded() );
569 m_modelListBox->Enable( enableLibCtrls );
570 m_pinLabel->Enable( enableLibCtrls );
571 m_pinCombobox->Enable( enableLibCtrls );
572 m_differentialCheckbox->Enable( enableLibCtrls );
573 m_pinModelLabel->Enable( enableLibCtrls );
574 m_pinModelCombobox->Enable( enableLibCtrls );
575 m_waveformLabel->Enable( enableLibCtrls );
576 m_waveformChoice->Enable( enableLibCtrls );
577
578 m_deviceLabel->Enable( enableBuiltinCtrls );
579 m_deviceChoice->Enable( enableBuiltinCtrls );
580 m_deviceSubtypeLabel->Enable( enableBuiltinCtrls );
581 m_deviceSubtypeChoice->Enable( enableBuiltinCtrls );
582
584
589 updatePinAssignments( model, false );
590
591 std::string ref = GetFieldValue( &m_fields, SIM_REFERENCE_FIELD, false, 0 );
592
593 m_modelPanel->Layout();
594 m_pinAssignmentsPanel->Layout();
595 m_parametersPanel->Layout();
596 m_codePanel->Layout();
597
598 SendSizeEvent( wxSEND_EVENT_POST );
599
601}
602
603
604template <typename T>
606{
607 SIM_MODEL_IBIS* modelibis = isIbisLoaded() ? dynamic_cast<SIM_MODEL_IBIS*>( aModel ) : nullptr;
608
609 m_pinLabel->Show( isIbisLoaded() );
610 m_pinCombobox->Show( isIbisLoaded() );
611 m_pinModelLabel->Show( isIbisLoaded() );
613 m_waveformLabel->Show( isIbisLoaded() );
615
616 if( aModel != m_prevModel )
617 {
618 m_waveformChoice->Clear();
619
620 if( isIbisLoaded() )
621 {
622 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
623 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
624 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
625 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
626 {
627 SIM_MODEL::DEVICE_T deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
628 const std::string& deviceTypeDesc = SIM_MODEL::DeviceInfo( deviceType ).description;
629
630 if( deviceType == aModel->GetDeviceType()
631 || deviceTypeDesc == aModel->GetDeviceInfo().description )
632 {
633 m_waveformChoice->Append( SIM_MODEL::TypeInfo( type ).description );
634
635 if( type == aModel->GetType() )
636 m_waveformChoice->SetSelection( m_waveformChoice->GetCount() - 1 );
637 }
638 }
639 }
640 }
641
642 m_differentialCheckbox->Show( isIbisLoaded() && modelibis && modelibis->CanDifferential() );
643 m_modelNameLabel->SetLabel( isIbisLoaded() ? _( "Component:" ) : _( "Model:" ) );
644}
645
646
647template <typename T>
649{
650 // Change the Type choice to match the current device type.
651 if( aModel != m_prevModel )
652 {
653 m_deviceChoice->Clear();
654 m_deviceSubtypeChoice->Clear();
655
656 if( !m_rbLibraryModel->GetValue() )
657 {
658 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
659 {
660 if( !SIM_MODEL::DeviceInfo( deviceType ).showInMenu )
661 continue;
662
663 m_deviceChoice->Append( SIM_MODEL::DeviceInfo( deviceType ).description );
664
665 if( equivalent( deviceType, aModel->GetDeviceType() ) )
666 m_deviceChoice->SetSelection( m_deviceChoice->GetCount() - 1 );
667 }
668
669 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
670 {
671 if( type == SIM_MODEL::TYPE::KIBIS_DEVICE
672 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
673 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
674 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS )
675 {
676 continue;
677 }
678
679 SIM_MODEL::DEVICE_T deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
680 const std::string& deviceTypeDesc = SIM_MODEL::DeviceInfo( deviceType ).description;
681
682 if( deviceType == aModel->GetDeviceType()
683 || deviceTypeDesc == aModel->GetDeviceInfo().description )
684 {
685 m_deviceSubtypeChoice->Append( SIM_MODEL::TypeInfo( type ).description );
686
687 if( type == aModel->GetType() )
688 m_deviceSubtypeChoice->SetSelection( m_deviceSubtypeChoice->GetCount() - 1 );
689 }
690 }
691 }
692
693 m_deviceSubtypeLabel->Show( m_deviceSubtypeChoice->GetCount() > 1 );
694 m_deviceSubtypeChoice->Show( m_deviceSubtypeChoice->GetCount() > 1 );
695 }
696
697 if( dynamic_cast<SIM_MODEL_RAW_SPICE*>( aModel ) )
698 m_modelNotebook->SetSelection( 1 );
699 else
700 m_modelNotebook->SetSelection( 0 );
701
702 if( aModel->HasPrimaryValue() )
703 {
704 const SIM_MODEL::PARAM& primary = aModel->GetParam( 0 );
705
706 m_saveInValueCheckbox->SetLabel( wxString::Format( _( "Save parameter '%s (%s)' in Value "
707 "field" ),
708 primary.info.description,
709 primary.info.name ) );
710 m_saveInValueCheckbox->Enable( true );
711 }
712 else
713 {
714 m_saveInValueCheckbox->SetLabel( _( "Save primary parameter in Value field" ) );
715 m_saveInValueCheckbox->SetValue( false );
716 m_saveInValueCheckbox->Enable( false );
717 }
718}
719
720
721template <typename T>
723{
724 if( aModel != m_prevModel )
725 {
726 // This wxPropertyGridManager column and header stuff has to be here because it segfaults in
727 // the constructor.
728
729 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
730
731 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION, _( "Parameter" ) );
732 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT, _( "Unit" ) );
733 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT, _( "Default" ) );
734 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE, _( "Type" ) );
735
736 m_paramGridMgr->ShowHeader();
737
738
739 m_paramGrid->Clear();
740
741 m_firstCategory = m_paramGrid->Append( new wxPropertyCategory( "Geometry" ) );
742 m_paramGrid->HideProperty( "Geometry" );
743
744 m_paramGrid->Append( new wxPropertyCategory( "AC" ) );
745 m_paramGrid->HideProperty( "AC" );
746
747 m_paramGrid->Append( new wxPropertyCategory( "DC" ) );
748 m_paramGrid->HideProperty( "DC" );
749
750 m_paramGrid->Append( new wxPropertyCategory( "S-Parameters" ) );
751 m_paramGrid->HideProperty( "S-Parameters" );
752
753 m_paramGrid->Append( new wxPropertyCategory( "Capacitance" ) );
754 m_paramGrid->HideProperty( "Capacitance" );
755
756 m_paramGrid->Append( new wxPropertyCategory( "Temperature" ) );
757 m_paramGrid->HideProperty( "Temperature" );
758
759 m_paramGrid->Append( new wxPropertyCategory( "Noise" ) );
760 m_paramGrid->HideProperty( "Noise" );
761
762 m_paramGrid->Append( new wxPropertyCategory( "Distributed Quantities" ) );
763 m_paramGrid->HideProperty( "Distributed Quantities" );
764
765 m_paramGrid->Append( new wxPropertyCategory( "Waveform" ) );
766 m_paramGrid->HideProperty( "Waveform" );
767
768 m_paramGrid->Append( new wxPropertyCategory( "Limiting Values" ) );
769 m_paramGrid->HideProperty( "Limiting Values" );
770
771 m_paramGrid->Append( new wxPropertyCategory( "Advanced" ) );
772 m_paramGrid->HideProperty( "Advanced" );
773
774 m_paramGrid->Append( new wxPropertyCategory( "Flags" ) );
775 m_paramGrid->HideProperty( "Flags" );
776
777 m_paramGrid->CollapseAll();
778
779 for( int i = 0; i < aModel->GetParamCount(); ++i )
780 addParamPropertyIfRelevant( aModel, i );
781
782 m_paramGrid->CollapseAll();
783 m_paramGrid->Expand( "AC" );
784 m_paramGrid->Expand( "Waveform" );
785 }
786
787 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(), true );
788
789 // Set all properties to default colors.
790 // Update properties in models that have autofill.
791 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
792 {
793 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
794 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
795
796 for( int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
797 {
798 ( *it )->GetCell( col ).SetBgCol( bgCol );
799 ( *it )->GetCell( col ).SetFgCol( fgCol );
800 }
801
802 SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it );
803
804 if( !prop )
805 continue;
806
807 const SIM_MODEL::PARAM& param = prop->GetParam();
808
809 // Model values other than the currently edited value may have changed. Update them.
810 // This feature is called "autofill" and present only in certain models. Don't do it for
811 // models that don't have it for performance reasons.
812 if( aModel->HasAutofill() )
813 ( *it )->SetValueFromString( param.value );
814 }
815}
816
817
818template <typename T>
820{
821 if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( aModel ) )
822 return;
823
824 wxString text;
825 SPICE_ITEM item;
826
827 item.modelName = m_modelListBox->GetStringSelection();
828
829 if( m_rbBuiltinModel->GetValue() || item.modelName == "" )
831
832 text << aModel->SpiceGenerator().Preview( item );
833
834 m_codePreview->SetText( text );
835 m_codePreview->SelectNone();
836}
837
838
839template <typename T>
840void DIALOG_SIM_MODEL<T>::updatePinAssignments( SIM_MODEL* aModel, bool aForceRefreshFromModel )
841{
842 if( m_pinAssignmentsGrid->GetNumberRows() == 0 )
843 {
844 m_pinAssignmentsGrid->AppendRows( (int) m_sortedPartPins.size() );
845
846 for( int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
847 {
848 wxString symbolPinString = getSymbolPinString( ii );
849
850 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
851 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
852 }
853
854 aForceRefreshFromModel = true;
855 }
856
857 if( aForceRefreshFromModel )
858 {
859 // Reset the grid.
860 for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
861 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL, _( "Not Connected" ) );
862
863 // Now set up the grid values in the Model column.
864 for( int modelPinIndex = 0; modelPinIndex < aModel->GetPinCount(); ++modelPinIndex )
865 {
866 wxString symbolPinNumber = aModel->GetPin( modelPinIndex ).symbolPinNumber;
867
868 if( symbolPinNumber == "" )
869 continue;
870
871 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
872
873 if( symbolPinRow == -1 )
874 continue;
875
876 wxString modelPinString = getModelPinString( aModel, modelPinIndex );
877 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
878 }
879 }
880
881 for( int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
882 {
883 // Set up the Model column cell editors with dropdown options.
884 std::vector<BITMAPS> modelPinIcons;
885 wxArrayString modelPinChoices;
886
887 for( int jj = 0; jj < aModel->GetPinCount(); ++jj )
888 {
889 if( aModel->GetPin( jj ).symbolPinNumber != "" )
890 modelPinIcons.push_back( PinShapeGetBitmap( GRAPHIC_PINSHAPE::LINE ) );
891 else
892 modelPinIcons.push_back( BITMAPS::INVALID_BITMAP );
893
894 modelPinChoices.Add( getModelPinString( aModel, jj ) );
895 }
896
897 modelPinIcons.push_back( BITMAPS::INVALID_BITMAP );
898 modelPinChoices.Add( _( "Not Connected" ) );
899
900 // This is not a memory leak; `SetCellEditor()` calls `DecRef()` on its previous editor.
901 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
902 new GRID_CELL_ICON_TEXT_POPUP( modelPinIcons, modelPinChoices ) );
903
904 // Assignment stays the same, but model pin names need to be updated
905 int modelPinIndex = getModelPinIndex( m_pinAssignmentsGrid->GetCellValue( ii, PIN_COLUMN::MODEL ) );
906
907 if( modelPinIndex >= 0 )
908 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::MODEL, getModelPinString( aModel, modelPinIndex ) );
909 }
910
911 // TODO: Show a preview of the symbol with the pin numbers shown.
912
913 if( aModel->GetType() == SIM_MODEL::TYPE::SUBCKT )
914 {
915 SIM_MODEL_SUBCKT* subckt = static_cast<SIM_MODEL_SUBCKT*>( aModel );
916 m_subckt->SetText( subckt->GetSpiceCode() );
917 m_subckt->SetEditable( false );
918 }
919 else
920 {
921 m_subcktLabel->Show( false );
922 m_subckt->Show( false );
923 }
924}
925
926
927template <typename T>
929{
930 for( int i = 0; i < aModel->GetPinCount(); ++i )
931 {
932 if( !m_symbol.GetPin( aModel->GetPin( i ).symbolPinNumber ) )
933 aModel->AssignSymbolPinNumberToModelPin( i, "" );
934 }
935}
936
937
938template <typename T>
939bool DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aLibraryPath, REPORTER& aReporter, bool aForceReload )
940{
941 if( m_prevLibrary == aLibraryPath && !aForceReload )
942 return true;
943
944 m_libraryModelsMgr.SetForceFullParse();
945 m_libraryModelsMgr.SetLibrary( aLibraryPath, aReporter );
946 m_libraryPathText->ChangeValue( aLibraryPath );
948
950 {
951 m_libraryModelsMgr.Clear();
952
953 if( m_modelListBox->GetSelection() != wxNOT_FOUND )
954 m_modelListBox->SetSelection( wxNOT_FOUND );
955
956 if( m_modelListBox->GetCount() )
957 m_modelListBox->Clear();
958
959 wxArrayString emptyArray;
960 m_pinModelCombobox->Set( emptyArray );
961 m_pinCombobox->Set( emptyArray );
962 m_pinModelCombobox->SetSelection( -1 );
963 m_pinCombobox->SetSelection( -1 );
964 m_waveformChoice->Clear();
965 m_prevLibrary.Clear();
966
967 return false;
968 }
969
970 std::string modelName = GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD, true, 0 );
971
972 for( const auto& [baseModelName, baseModel] : library()->GetModels() )
973 {
974 if( baseModelName == modelName )
975 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, true, 0, aReporter );
976 else
977 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, aReporter );
978 }
979
980 m_rbLibraryModel->SetValue( true );
981
982 wxArrayString modelNames;
983
984 bool modelNameExists = false;
985 for( const auto& [name, model] : library()->GetModels() )
986 {
987 modelNames.Add( name );
989
990 if( name == modelName )
991 modelNameExists = true;
992 }
993
994 modelNames.Sort();
995
996 m_modelListBox->Clear();
997 m_modelListBox->Append( modelNames );
998
999 if( !modelNameExists )
1000 {
1001 m_infoBar->ShowMessage( wxString::Format( _( "No model named '%s' in '%s'." ),
1002 modelName,
1003 aLibraryPath ) );
1004 return false;
1005 }
1006
1007 if( isIbisLoaded() )
1008 {
1009 wxArrayString emptyArray;
1010 m_pinModelCombobox->Set( emptyArray );
1011 m_pinCombobox->Set( emptyArray );
1012 m_pinModelCombobox->SetSelection( -1 );
1013 m_pinCombobox->SetSelection( -1 );
1014 }
1015
1016 m_modelListBox->SetStringSelection( modelName );
1017
1018 if( m_modelListBox->GetSelection() < 0 && m_modelListBox->GetCount() > 0 )
1019 m_modelListBox->SetSelection( 0 );
1020
1021 m_curModelType = curModel().GetType();
1022
1023 m_prevLibrary = aLibraryPath;
1024 return true;
1025}
1026
1027
1028template <typename T>
1030{
1031 if( aModel->GetParam( aParamIndex ).info.dir == SIM_MODEL::PARAM::DIR_OUT )
1032 return;
1033
1034 switch( aModel->GetParam( aParamIndex ).info.category )
1035 {
1036 case CATEGORY::AC:
1037 m_paramGrid->HideProperty( "AC", false );
1038 m_paramGrid->AppendIn( "AC", newParamProperty( aModel, aParamIndex ) );
1039 break;
1040
1041 case CATEGORY::DC:
1042 m_paramGrid->HideProperty( "DC", false );
1043 m_paramGrid->AppendIn( "DC", newParamProperty( aModel, aParamIndex ) );
1044 break;
1045
1046 case CATEGORY::S_PARAM:
1047 m_paramGrid->HideProperty( "S-Parameters", false );
1048 m_paramGrid->AppendIn( "S-Parameters", newParamProperty( aModel, aParamIndex ) );
1049 break;
1050
1051 case CATEGORY::CAPACITANCE:
1052 m_paramGrid->HideProperty( "Capacitance", false );
1053 m_paramGrid->AppendIn( "Capacitance", newParamProperty( aModel, aParamIndex ) );
1054 break;
1055
1056 case CATEGORY::TEMPERATURE:
1057 m_paramGrid->HideProperty( "Temperature", false );
1058 m_paramGrid->AppendIn( "Temperature", newParamProperty( aModel, aParamIndex ) );
1059 break;
1060
1061 case CATEGORY::NOISE:
1062 m_paramGrid->HideProperty( "Noise", false );
1063 m_paramGrid->AppendIn( "Noise", newParamProperty( aModel, aParamIndex ) );
1064 break;
1065
1066 case CATEGORY::DISTRIBUTED_QUANTITIES:
1067 m_paramGrid->HideProperty( "Distributed Quantities", false );
1068 m_paramGrid->AppendIn( "Distributed Quantities", newParamProperty( aModel, aParamIndex ) );
1069 break;
1070
1071 case CATEGORY::WAVEFORM:
1072 m_paramGrid->HideProperty( "Waveform", false );
1073 m_paramGrid->AppendIn( "Waveform", newParamProperty( aModel, aParamIndex ) );
1074 break;
1075
1076 case CATEGORY::GEOMETRY:
1077 m_paramGrid->HideProperty( "Geometry", false );
1078 m_paramGrid->AppendIn( "Geometry", newParamProperty( aModel, aParamIndex ) );
1079 break;
1080
1081 case CATEGORY::LIMITING_VALUES:
1082 m_paramGrid->HideProperty( "Limiting Values", false );
1083 m_paramGrid->AppendIn( "Limiting Values", newParamProperty( aModel, aParamIndex ) );
1084 break;
1085
1086 case CATEGORY::ADVANCED:
1087 m_paramGrid->HideProperty( "Advanced", false );
1088 m_paramGrid->AppendIn( "Advanced", newParamProperty( aModel, aParamIndex ) );
1089 break;
1090
1091 case CATEGORY::FLAGS:
1092 m_paramGrid->HideProperty( "Flags", false );
1093 m_paramGrid->AppendIn( "Flags", newParamProperty( aModel, aParamIndex ) );
1094 break;
1095
1096 default:
1097 m_paramGrid->Insert( m_firstCategory, newParamProperty( aModel, aParamIndex ) );
1098 break;
1099
1100 case CATEGORY::INITIAL_CONDITIONS:
1101 case CATEGORY::SUPERFLUOUS:
1102 return;
1103 }
1104}
1105
1106
1107template <typename T>
1108wxPGProperty* DIALOG_SIM_MODEL<T>::newParamProperty( SIM_MODEL* aModel, int aParamIndex ) const
1109{
1110 const SIM_MODEL::PARAM& param = aModel->GetParam( aParamIndex );
1111 wxString paramDescription;
1112
1113 if( param.info.description == "" )
1114 paramDescription = wxString::Format( "%s", param.info.name );
1115 else
1116 paramDescription = wxString::Format( "%s (%s)", param.info.description, param.info.name );
1117
1118 wxPGProperty* prop = nullptr;
1119
1120 switch( param.info.type )
1121 {
1123 prop = new SIM_BOOL_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex );
1124 prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX, true );
1125 break;
1126
1128 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1130 break;
1131
1133 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1135 break;
1136
1137 //case TYPE_COMPLEX:
1138 // break;
1139
1141 // Special case: K-line mutual inductance statement parameters l1 and l2 are references
1142 // to other inductors in the circuit.
1143 if( dynamic_cast<SIM_MODEL_L_MUTUAL*>( aModel ) != nullptr
1144 && ( param.info.name == "l1" || param.info.name == "l2" ) )
1145 {
1146 wxArrayString inductors;
1147
1148 if( SCH_EDIT_FRAME* schEditFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
1149 {
1150 SPICE_CIRCUIT_MODEL circuit( &schEditFrame->Schematic() );
1151 NULL_REPORTER devNul;
1152
1154
1155 for( const SPICE_ITEM& item : circuit.GetItems() )
1156 {
1157 if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::L )
1158 inductors.push_back( item.refName );
1159 }
1160
1161 inductors.Sort(
1162 []( const wxString& a, const wxString& b ) -> int
1163 {
1164 return StrNumCmp( a, b, true );
1165 } );
1166 }
1167
1168 if( inductors.empty() )
1169 {
1170 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1172 }
1173 else
1174 {
1175 prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1176 inductors );
1177 }
1178 }
1179 else if( param.info.enumValues.empty() )
1180 {
1181 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1183 }
1184 else
1185 {
1186 wxArrayString values;
1187
1188 for( const std::string& string : aModel->GetParam( aParamIndex ).info.enumValues )
1189 values.Add( string );
1190
1191 prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1192 values );
1193 }
1194 break;
1195
1196 default:
1197 prop = new wxStringProperty( paramDescription, param.info.name );
1198 break;
1199 }
1200
1201 prop->SetAttribute( wxPG_ATTR_UNITS, wxString::FromUTF8( param.info.unit.c_str() ) );
1202
1203 // Legacy due to the way we extracted the parameters from Ngspice.
1204 prop->SetCell( 3, wxString::FromUTF8( param.info.defaultValue ) );
1205
1206 wxString typeStr;
1207
1208 switch( param.info.type )
1209 {
1210 case SIM_VALUE::TYPE_BOOL: typeStr = wxT( "Bool" ); break;
1211 case SIM_VALUE::TYPE_INT: typeStr = wxT( "Int" ); break;
1212 case SIM_VALUE::TYPE_FLOAT: typeStr = wxT( "Float" ); break;
1213 case SIM_VALUE::TYPE_COMPLEX: typeStr = wxT( "Complex" ); break;
1214 case SIM_VALUE::TYPE_STRING: typeStr = wxT( "String" ); break;
1215 case SIM_VALUE::TYPE_BOOL_VECTOR: typeStr = wxT( "Bool Vector" ); break;
1216 case SIM_VALUE::TYPE_INT_VECTOR: typeStr = wxT( "Int Vector" ); break;
1217 case SIM_VALUE::TYPE_FLOAT_VECTOR: typeStr = wxT( "Float Vector" ); break;
1218 case SIM_VALUE::TYPE_COMPLEX_VECTOR: typeStr = wxT( "Complex Vector" ); break;
1219 }
1220
1221 prop->SetCell( PARAM_COLUMN::TYPE, typeStr );
1222
1223 return prop;
1224}
1225
1226
1227template <typename T>
1228int DIALOG_SIM_MODEL<T>::findSymbolPinRow( const wxString& aSymbolPinNumber ) const
1229{
1230 for( int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
1231 {
1233
1234 if( pin->GetNumber() == aSymbolPinNumber )
1235 return row;
1236 }
1237
1238 return -1;
1239}
1240
1241
1242template <typename T>
1244{
1245 if( m_rbLibraryModel->GetValue() )
1246 {
1247 wxString sel = m_modelListBox->GetStringSelection();
1248
1249 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
1250 {
1251 int idx = m_modelListBoxEntryToLibraryIdx.at( sel );
1252
1253 if( idx >= 0 && idx < (int) m_libraryModelsMgr.GetModels().size() )
1254 return m_libraryModelsMgr.GetModels().at( idx ).get();
1255 }
1256 }
1257 else
1258 {
1259 if( (int) m_curModelType < (int) m_builtinModelsMgr.GetModels().size() )
1260 return m_builtinModelsMgr.GetModels().at( static_cast<int>( m_curModelType ) );
1261 }
1262
1263 return m_builtinModelsMgr.GetModels().at( (int) SIM_MODEL::TYPE::NONE );
1264}
1265
1266
1267template <typename T>
1269{
1270 if( m_libraryModelsMgr.GetLibraries().size() == 1 )
1271 return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
1272
1273 return nullptr;
1274}
1275
1276
1277template <typename T>
1278wxString DIALOG_SIM_MODEL<T>::getSymbolPinString( int symbolPinIndex ) const
1279{
1280 SCH_PIN* pin = m_sortedPartPins.at( symbolPinIndex );
1281 wxString pinNumber;
1282 wxString pinName;
1283
1284 if( pin )
1285 {
1286 pinNumber = pin->GetShownNumber();
1287 pinName = pin->GetShownName();
1288 }
1289
1290 if( !pinName.IsEmpty() && pinName != pinNumber )
1291 pinNumber += wxString::Format( wxT( " (\"%s\")" ), pinName );
1292
1293 return pinNumber;
1294}
1295
1296
1297template <typename T>
1298wxString DIALOG_SIM_MODEL<T>::getModelPinString( SIM_MODEL* aModel, int aModelPinIndex ) const
1299{
1300 wxString modelPinName;
1301
1302 if( aModelPinIndex >= 0 && aModelPinIndex < aModel->GetPinCount() )
1303 modelPinName = aModel->GetPin( aModelPinIndex ).modelPinName;
1304
1305 wxString modelPinNumber = wxString::Format( "%d", aModelPinIndex + 1 );
1306
1307 if( !modelPinName.IsEmpty() && modelPinName != modelPinNumber )
1308 modelPinNumber += wxString::Format( wxT( " (\"%s\")" ), modelPinName );
1309
1310 return modelPinNumber;
1311}
1312
1313
1314template <typename T>
1315int DIALOG_SIM_MODEL<T>::getModelPinIndex( const wxString& aModelPinString ) const
1316{
1317 if( aModelPinString == "Not Connected" )
1319
1320 int length = aModelPinString.Find( " " );
1321
1322 if( length == wxNOT_FOUND )
1323 length = static_cast<int>( aModelPinString.Length() );
1324
1325 long result = 0;
1326 aModelPinString.Mid( 0, length ).ToCLong( &result );
1327
1328 return static_cast<int>( result - 1 );
1329}
1330
1331
1332template <typename T>
1333void DIALOG_SIM_MODEL<T>::onRadioButton( wxCommandEvent& aEvent )
1334{
1335 m_prevModel = nullptr; // Ensure the Model panel will be rebuild after updating other params.
1336 updateWidgets();
1337}
1338
1339
1340template <typename T>
1341void DIALOG_SIM_MODEL<T>::onLibraryPathText( wxCommandEvent& aEvent )
1342{
1343 m_rbLibraryModel->SetValue( true );
1344}
1345
1346
1347template <typename T>
1349{
1350 m_rbLibraryModel->SetValue( true );
1351
1353 wxString path = m_libraryPathText->GetValue();
1354
1355 if( loadLibrary( path, reporter, true ) || path.IsEmpty() )
1356 m_infoBar->Hide();
1357 else if( reporter.HasMessage() )
1358 m_infoBar->ShowMessage( reporter.GetMessages() );
1359
1360 updateWidgets();
1361}
1362
1363
1364template <typename T>
1366{
1367 CallAfter(
1368 [this]()
1369 {
1370 // Disable logging -- otherwise we'll end up in an endless loop of show-log,
1371 // kill-focus, show-log, kill-focus, etc.
1372 wxLogNull doNotLog;
1373
1374 wxCommandEvent dummy;
1376 } );
1377
1378 aEvent.Skip(); // mandatory in wxFocusEvent events
1379}
1380
1381
1382template <typename T>
1383void DIALOG_SIM_MODEL<T>::onBrowseButtonClick( wxCommandEvent& aEvent )
1384{
1385 static wxString s_mruPath;
1386
1387 wxString path = s_mruPath.IsEmpty() ? Prj().GetProjectPath() : s_mruPath;
1388 wxFileDialog dlg( this, _( "Browse Models" ), path );
1389 FILEDLG_HOOK_EMBED_FILE customize( false );
1390
1391 dlg.SetCustomizeHook( customize );
1392
1394
1395 if( dlg.ShowModal() == wxID_CANCEL )
1396 return;
1397
1398 m_rbLibraryModel->SetValue( true );
1399
1400 path = dlg.GetPath();
1401 wxFileName fn( path );
1402 s_mruPath = fn.GetPath();
1403
1404 if( customize.GetEmbed() )
1405 {
1406 EMBEDDED_FILES::EMBEDDED_FILE* result = m_filesStack[0]->AddFile( fn, false );
1407 path = result->GetLink();
1408 }
1409 else if( fn.MakeRelativeTo( Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS( ".." ) ) )
1410 {
1411 path = fn.GetFullPath();
1412 }
1413
1415
1416 if( loadLibrary( path, reporter, true ) )
1417 m_infoBar->Hide();
1418 else
1419 m_infoBar->ShowMessage( reporter.GetMessages() );
1420
1421 updateWidgets();
1422}
1423
1424
1425template <typename T>
1426void DIALOG_SIM_MODEL<T>::onFilterCharHook( wxKeyEvent& aKeyStroke )
1427{
1428 int count = m_modelListBox->GetCount();
1429
1430 if( count == 0 )
1431 {
1432 aKeyStroke.Skip();
1433 return;
1434 }
1435
1436 int sel = m_modelListBox->GetSelection();
1437
1438 switch( aKeyStroke.GetKeyCode() )
1439 {
1440 case WXK_UP:
1441 if( sel == wxNOT_FOUND )
1442 sel = count - 1;
1443 else
1444 sel = std::max( sel - 1, 0 );
1445
1446 break;
1447
1448 case WXK_DOWN:
1449 if( sel == wxNOT_FOUND )
1450 sel = 0;
1451 else
1452 sel = std::min( sel + 1, count - 1 );
1453
1454 break;
1455
1456 case WXK_RETURN:
1457 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
1458 return;
1459
1460 default:
1461 aKeyStroke.Skip();
1462 return;
1463 }
1464
1465 m_modelListBox->SetSelection( sel );
1466}
1467
1468
1469template <typename T>
1470void DIALOG_SIM_MODEL<T>::onModelFilter( wxCommandEvent& aEvent )
1471{
1472 if( library() == nullptr ) // No library loaded
1473 return;
1474
1475 wxArrayString modelNames;
1476 wxString current = m_modelListBox->GetStringSelection();
1477 wxString filter = wxT( "*" ) + m_modelFilter->GetValue() + wxT( "*" );
1478
1479 for( const auto& [name, model] : library()->GetModels() )
1480 {
1481 wxString wx_name( name );
1482
1483 if( wx_name.Matches( filter ) )
1484 modelNames.Add( wx_name );
1485 }
1486
1487 modelNames.Sort();
1488
1489 m_modelListBox->Clear();
1490 m_modelListBox->Append( modelNames );
1491
1492 if( m_modelListBox->GetCount() > 0 )
1493 {
1494 if( !m_modelListBox->SetStringSelection( current ) )
1495 m_modelListBox->SetSelection( 0 );
1496 }
1497}
1498
1499
1500template <typename T>
1501void DIALOG_SIM_MODEL<T>::onModelNameChoice( wxCommandEvent& aEvent )
1502{
1503 if( isIbisLoaded() )
1504 {
1505 wxArrayString pinLabels;
1506 SIM_MODEL_IBIS* modelkibis = dynamic_cast<SIM_MODEL_IBIS*>( &curModel() );
1507
1508 wxCHECK2( modelkibis, return );
1509
1510 for( std::pair<wxString, wxString> strs : modelkibis->GetIbisPins() )
1511 pinLabels.Add( strs.first + wxT( " - " ) + strs.second );
1512
1513 m_pinCombobox->Set( pinLabels );
1514
1515 wxArrayString emptyArray;
1516 m_pinModelCombobox->Set( emptyArray );
1517 }
1518
1519 m_rbLibraryModel->SetValue( true );
1520
1521 if( SIM_MODEL_SPICE_FALLBACK* fallback =
1522 dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( &curModel() ) )
1523 {
1524 wxArrayString lines = wxSplit( fallback->GetSpiceCode(), '\n' );
1525 wxString code;
1526
1527 for( const wxString& line : lines )
1528 {
1529 if( !line.StartsWith( '*' ) )
1530 {
1531 if( !code.IsEmpty() )
1532 code += "\n";
1533
1534 code += line;
1535 }
1536 }
1537
1538 m_infoBar->ShowMessage( wxString::Format( _( "Failed to parse:\n\n"
1539 "%s\n"
1540 "Using generic SPICE model." ),
1541 code ) );
1542 }
1543 else
1544 {
1545 m_infoBar->Hide();
1546 }
1547
1548 updateWidgets();
1549}
1550
1551
1552template <typename T>
1553void DIALOG_SIM_MODEL<T>::onPinCombobox( wxCommandEvent& aEvent )
1554{
1555 wxArrayString modelLabels;
1556
1557 SIM_MODEL_IBIS& ibisModel = static_cast<SIM_MODEL_IBIS&>( curModel() );
1558
1559 std::vector<std::pair<std::string, std::string>> strs = ibisModel.GetIbisPins();
1560 std::string pinNumber = strs.at( m_pinCombobox->GetSelection() ).first;
1561
1562 const SIM_LIBRARY_IBIS* ibisLibrary = dynamic_cast<const SIM_LIBRARY_IBIS*>( library() );
1563
1564 ibisModel.ChangePin( *ibisLibrary, pinNumber );
1565
1566 ibisModel.m_enableDiff = ibisLibrary->isPinDiff( ibisModel.GetComponentName(), pinNumber );
1567
1568 for( wxString modelName : ibisModel.GetIbisModels() )
1569 modelLabels.Add( modelName );
1570
1571 m_pinModelCombobox->Set( modelLabels );
1572
1573 if( m_pinModelCombobox->GetCount() == 1 )
1574 m_pinModelCombobox->SetSelection( 0 );
1575 else
1576 m_pinModelCombobox->SetSelection( -1 );
1577
1578 updateWidgets();
1579}
1580
1581
1582template <typename T>
1584{
1585 m_pinCombobox->SetSelection( m_pinCombobox->FindString( m_pinCombobox->GetValue() ) );
1586
1587 onPinModelCombobox( aEvent );
1588}
1589
1590
1591template <typename T>
1592void DIALOG_SIM_MODEL<T>::onPinModelCombobox( wxCommandEvent& aEvent )
1593{
1594 if( SIM_MODEL_IBIS* ibismodel = dynamic_cast<SIM_MODEL_IBIS*>( &curModel() ) )
1595 {
1596 const SIM_LIBRARY_IBIS* ibisLibrary = dynamic_cast<const SIM_LIBRARY_IBIS*>( library() );
1597
1598 // Skip uncommitted combobox text so SetIbisModel doesn't silently fail.
1599 if( ibisLibrary
1600 && m_pinCombobox->GetSelection() >= 0
1601 && m_pinModelCombobox->GetSelection() >= 0 )
1602 {
1603 std::string pinNumber = ibismodel->GetIbisPins()
1604 .at( m_pinCombobox->GetSelection() )
1605 .first;
1606 std::string modelName = m_pinModelCombobox->GetStringSelection().ToStdString();
1607
1608 ibismodel->SetIbisModel( *ibisLibrary, pinNumber, modelName );
1609 }
1610 }
1611
1612 updateWidgets();
1613}
1614
1615
1616template <typename T>
1618{
1619 m_pinModelCombobox->SetSelection( m_pinModelCombobox->FindString( m_pinModelCombobox->GetValue() ) );
1620}
1621
1622
1623template <typename T>
1625{
1626 if( SIM_MODEL_IBIS* modelibis = dynamic_cast<SIM_MODEL_IBIS*>( &curModel() ) )
1627 {
1628 bool diff = m_differentialCheckbox->GetValue() && modelibis->CanDifferential();
1629 modelibis->SwitchSingleEndedDiff( diff );
1630
1631 updateWidgets();
1632 }
1633}
1634
1635
1636template <typename T>
1637void DIALOG_SIM_MODEL<T>::onDeviceTypeChoice( wxCommandEvent& aEvent )
1638{
1639 m_rbBuiltinModel->SetValue( true );
1640
1641 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
1642 {
1643 if( SIM_MODEL::DeviceInfo( deviceType ).description == m_deviceChoice->GetStringSelection() )
1644 {
1645 m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
1646 break;
1647 }
1648 }
1649
1650 updateWidgets();
1651}
1652
1653
1654template <typename T>
1655void DIALOG_SIM_MODEL<T>::onWaveformChoice( wxCommandEvent& aEvent )
1656{
1657 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1658 wxString typeDescription = m_waveformChoice->GetStringSelection();
1659
1660 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
1661 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
1662 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
1663 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
1664 {
1665 if( equivalent( deviceType, SIM_MODEL::TypeInfo( type ).deviceType )
1666 && typeDescription == SIM_MODEL::TypeInfo( type ).description )
1667 {
1668 int idx = 0;
1669 wxString sel = m_modelListBox->GetStringSelection();
1670
1671 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
1672 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
1673
1674 SIM_MODEL_IBIS& baseModel = static_cast<SIM_MODEL_IBIS&>( m_libraryModelsMgr.GetModels()[idx].get() );
1675
1676 m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_IBIS>( type, baseModel ) );
1677
1678 try
1679 {
1680 m_libraryModelsMgr.GetModels()[idx].get().ReadDataFields( &m_fields, true, 0, m_sortedPartPins );
1681 }
1682 catch( IO_ERROR& err )
1683 {
1684 DisplayErrorMessage( this, err.What() );
1685 }
1686
1687 m_curModelType = type;
1688 break;
1689 }
1690 }
1691
1692 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1693 updateWidgets();
1694}
1695
1696
1697template <typename T>
1698void DIALOG_SIM_MODEL<T>::onTypeChoice( wxCommandEvent& aEvent )
1699{
1700 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1701 wxString typeDescription = m_deviceSubtypeChoice->GetStringSelection();
1702
1703 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1704 {
1705 if( equivalent( deviceType, SIM_MODEL::TypeInfo( type ).deviceType )
1706 && typeDescription == SIM_MODEL::TypeInfo( type ).description )
1707 {
1708 m_curModelType = type;
1709 break;
1710 }
1711 }
1712
1713 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1714 updateWidgets();
1715}
1716
1717
1718template <typename T>
1719void DIALOG_SIM_MODEL<T>::onPageChanging( wxBookCtrlEvent& event )
1720{
1722}
1723
1724
1725template <typename T>
1727{
1728 int symbolPinIndex = aEvent.GetRow();
1729 wxString oldModelPinName = aEvent.GetString();
1730 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
1731
1732 int oldModelPinIndex = getModelPinIndex( oldModelPinName );
1733 int modelPinIndex = getModelPinIndex( modelPinName );
1734
1735 if( oldModelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED )
1736 curModel().AssignSymbolPinNumberToModelPin( oldModelPinIndex, "" );
1737
1738 if( modelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED )
1739 {
1740 SCH_PIN* symbolPin = m_sortedPartPins.at( symbolPinIndex );
1741
1742 curModel().AssignSymbolPinNumberToModelPin( modelPinIndex, symbolPin->GetShownNumber() );
1743 }
1744
1746
1747 aEvent.Skip();
1748}
1749
1750
1751template <typename T>
1753{
1754 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
1755
1757 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::MODEL, gridWidth / 2 );
1758 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::SYMBOL, gridWidth / 2 );
1759
1760 aEvent.Skip();
1761}
1762
1763
1764template <typename T>
1766{
1767 // By default, when a property grid is focused, the textbox is not immediately focused until
1768 // Tab key is pressed. This is inconvenient, so we fix that here.
1769
1770 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1771 wxPGProperty* selected = grid->GetSelection();
1772
1773 if( !selected )
1774 selected = grid->wxPropertyGridInterface::GetFirst();
1775
1776#if wxCHECK_VERSION( 3, 3, 0 )
1777 if( selected )
1778 grid->DoSelectProperty( selected, wxPGSelectPropertyFlags::Focus );
1779#else
1780 if( selected )
1781 grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
1782#endif
1783
1784 aEvent.Skip();
1785}
1786
1787
1788template <typename T>
1789void DIALOG_SIM_MODEL<T>::onParamGridSelectionChange( wxPropertyGridEvent& aEvent )
1790{
1791 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1792
1793 // Jump over categories.
1794 if( grid->GetSelection() && grid->GetSelection()->IsCategory() )
1795 {
1796 wxPGProperty* selection = grid->GetSelection();
1797
1798 // If the new selection is immediately above the previous selection, we jump up. Otherwise
1799 // we jump down. We do this by simulating up or down arrow keys.
1800
1801 wxPropertyGridIterator it = grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
1802 it.Next();
1803
1804 wxKeyEvent* keyEvent = new wxKeyEvent( wxEVT_KEY_DOWN );
1805
1806 if( *it == m_prevParamGridSelection )
1807 {
1808 if( !selection->IsExpanded() )
1809 {
1810 grid->Expand( selection );
1811 keyEvent->m_keyCode = WXK_DOWN;
1812 wxQueueEvent( grid, keyEvent );
1813
1814 // Does not work for some reason.
1815 /*m_paramGrid->DoSelectProperty( selection->Item( selection->GetChildCount() - 1 ),
1816 wxPG_SEL_FOCUS );*/
1817 }
1818 else
1819 {
1820 keyEvent->m_keyCode = WXK_UP;
1821 wxQueueEvent( grid, keyEvent );
1822 }
1823 }
1824 else
1825 {
1826 if( !selection->IsExpanded() )
1827 grid->Expand( selection );
1828
1829 keyEvent->m_keyCode = WXK_DOWN;
1830 wxQueueEvent( grid, keyEvent );
1831 }
1832
1833 m_prevParamGridSelection = grid->GetSelection();
1834 return;
1835 }
1836
1837 wxWindow* editorControl = grid->GetEditorControl();
1838
1839 if( !editorControl )
1840 {
1841 m_prevParamGridSelection = grid->GetSelection();
1842 return;
1843 }
1844
1845 // Without this the user had to press tab before they could edit the field.
1846 editorControl->SetFocus();
1847 m_prevParamGridSelection = grid->GetSelection();
1848}
1849
1850
1851template <typename T>
1852void DIALOG_SIM_MODEL<T>::onUpdateUI( wxUpdateUIEvent& aEvent )
1853{
1854 // This is currently patched in wxPropertyGrid::ScrollWindow() in the Mac wxWidgets fork.
1855 // However, we may need this version if it turns out to be an issue on other platforms and
1856 // we can't get it upstreamed.
1857#if 0
1858 // It's a shame to do this on the UpdateUI event, but neither the wxPropertyGridManager,
1859 // wxPropertyGridPage, wxPropertyGrid, nor the wxPropertyGrid's GetCanvas() window appear
1860 // to get scroll events.
1861
1862 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1863 wxTextCtrl* ctrl = grid->GetEditorTextCtrl();
1864
1865 if( ctrl )
1866 {
1867 wxRect ctrlRect = ctrl->GetScreenRect();
1868 wxRect gridRect = grid->GetScreenRect();
1869
1870 if( ctrlRect.GetTop() < gridRect.GetTop() || ctrlRect.GetBottom() > gridRect.GetBottom() )
1871 grid->ClearSelection();
1872 }
1873#endif
1874}
1875
1876
1877template <typename T>
1878void DIALOG_SIM_MODEL<T>::adjustParamGridColumns( int aWidth, bool aForce )
1879{
1880 wxPropertyGrid* grid = m_paramGridMgr->GetGrid();
1881 int margin = 15;
1882 int indent = 20;
1883
1884 if( aWidth != m_lastParamGridWidth || aForce )
1885 {
1886 m_lastParamGridWidth = aWidth;
1887
1888 grid->FitColumns();
1889
1890 std::vector<int> colWidths;
1891
1892 for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ )
1893 {
1894 if( ii == PARAM_COLUMN::DESCRIPTION )
1895 colWidths.push_back( grid->GetState()->GetColumnWidth( ii ) + margin + indent );
1896 else if( ii == PARAM_COLUMN::VALUE )
1897 colWidths.push_back( std::max( 72, grid->GetState()->GetColumnWidth( ii ) ) + margin );
1898 else
1899 colWidths.push_back( 60 + margin );
1900
1901 aWidth -= colWidths[ ii ];
1902 }
1903
1904 for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ )
1905 grid->SetColumnProportion( ii, colWidths[ ii ] );
1906
1907 grid->ResetColumnSizes();
1908 grid->RefreshEditor();
1909 }
1910}
1911
1912
1913template <typename T>
1915{
1916 adjustParamGridColumns( event.GetSize().GetX(), false );
1917
1918 event.Skip();
1919}
1920
1921
1922template class DIALOG_SIM_MODEL<SCH_SYMBOL>;
1923template 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:79
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:214
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:71
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
Definition reporter.h:141
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:128
void SetText(const wxString &aText) override
SCHEMATIC * Schematic() const
Search the item hierarchy to find a SCHEMATIC.
Definition sch_item.cpp:268
const wxString & GetShownNumber() const
Definition sch_pin.cpp:682
Schematic symbol object.
Definition sch_symbol.h:69
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:465
static bool InferSimModel(T &aSymbol, std::vector< SCH_FIELD > *aFields, bool aResolve, int aDepth, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
const SPICE_GENERATOR & SpiceGenerator() const
Definition sim_model.h:428
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:475
void AssignSymbolPinNumberToModelPin(int aPinIndex, const wxString &aSymbolPinNumber)
DEVICE_INFO GetDeviceInfo() const
Definition sim_model.h:454
DEVICE_T GetDeviceType() const
Definition sim_model.h:457
static DEVICE_INFO DeviceInfo(DEVICE_T aDeviceType)
Definition sim_model.cpp:57
virtual bool HasAutofill() const
Definition sim_model.h:492
const SIM_MODEL_PIN & GetPin(unsigned aIndex) const
Definition sim_model.h:466
virtual bool HasPrimaryValue() const
Definition sim_model.h:493
TYPE GetType() const
Definition sim_model.h:458
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:189
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_shape.h:72
static const std::string KiCadUriPrefix
PROJECT & Prj()
Definition kicad.cpp:730
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition wxgtk/ui.cpp:294
void AllowNetworkFileSystems(wxDialog *aDialog)
Configure a file dialog to show network and virtual file systems.
Definition wxgtk/ui.cpp:448
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:446
wxString GetFieldValue(const std::vector< SCH_FIELD > *aFields, FIELD_T aFieldType)
Definition sch_field.h:421
const SCH_FIELD * FindField(const std::vector< SCH_FIELD > &aFields, FIELD_T aFieldId)
Definition sch_field.h:383
#define SIM_PINS_FIELD
Definition sim_model.h:50
#define SIM_DEVICE_FIELD
Definition sim_model.h:48
#define SIM_REFERENCE_FIELD
Definition sim_model.h:45
#define SIM_PARAMS_FIELD
Definition sim_model.h:52
#define SIM_DECOMPOSITION_FIELD
Definition sim_model.h:51
#define SIM_DEVICE_SUBTYPE_FIELD
Definition sim_model.h:49
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:385
SIM_VALUE::TYPE type
Definition sim_model.h:376
std::string defaultValue
Definition sim_model.h:379
std::string description
Definition sim_model.h:380
std::string value
Definition sim_model.h:397
const INFO & info
Definition sim_model.h:398
static constexpr auto NOT_CONNECTED
Definition sim_model.h:70
const std::string modelPinName
Definition sim_model.h:67
wxString symbolPinNumber
Definition sim_model.h:68
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.