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 (C) 2022-2024 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, you may find one here:
20 * https://www.gnu.org/licenses/gpl-3.0.html
21 * or you may search the http://www.gnu.org website for the version 3 license,
22 * or you may write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 */
25
27#include <dialog_sim_model.h>
28#include <sim/sim_property.h>
30#include <sim/sim_model.h>
31#include <sim/sim_model_ibis.h>
35#include <grid_tricks.h>
38#include <kiplatform/ui.h>
39#include <confirm.h>
40#include <string_utils.h>
41#include <locale_io.h>
42#include <wx/filedlg.h>
43#include <fmt/format.h>
44#include <sch_edit_frame.h>
47#include <wx/log.h>
48
50
51#define FORCE_UPDATE_PINS 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 ),
70 m_libraryModelsMgr( &Prj() ),
71 m_builtinModelsMgr( &Prj() ),
72 m_prevModel( nullptr ),
73 m_curModelType( SIM_MODEL::TYPE::NONE ),
74 m_scintillaTricksCode( nullptr ),
75 m_scintillaTricksSubckt( nullptr ),
76 m_firstCategory( nullptr ),
77 m_prevParamGridSelection( nullptr ),
78 m_lastParamGridWidth( 0 )
79{
80 m_browseButton->SetBitmap( KiBitmapBundle( BITMAPS::small_folder ) );
82
83 for( SCH_PIN* pin : aSymbol.GetAllLibPins() )
84 {
85 // De Morgan conversions are equivalences, not additional items to simulate
86 if( !pin->GetParentSymbol()->HasAlternateBodyStyle() || pin->GetBodyStyle() < 2 )
87 m_sortedPartPins.push_back( pin );
88 }
89
90 std::sort( m_sortedPartPins.begin(), m_sortedPartPins.end(),
91 []( const SCH_PIN* lhs, const SCH_PIN* rhs )
92 {
93 // We sort by StrNumCmp because SIM_MODEL_BASE sorts with it too.
94 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
95 } );
96
97 m_waveformChoice->Clear();
98 m_deviceChoice->Clear();
99 m_deviceSubtypeChoice->Clear();
100
101 m_scintillaTricksCode = new SCINTILLA_TRICKS( m_codePreview, wxT( "{}" ), false );
102 m_scintillaTricksSubckt = new SCINTILLA_TRICKS( m_subckt, wxT( "()" ), false );
103
104 m_paramGridMgr->Bind( wxEVT_PG_SELECTED, &DIALOG_SIM_MODEL::onParamGridSelectionChange, this );
105
106 wxPropertyGrid* grid = m_paramGrid->GetGrid();
107
108 // In wx 3.0 the color will be wrong sometimes.
109 grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
110
111 grid->Bind( wxEVT_SET_FOCUS, &DIALOG_SIM_MODEL::onParamGridSetFocus, this );
112 grid->Bind( wxEVT_UPDATE_UI, &DIALOG_SIM_MODEL::onUpdateUI, this );
113
114 grid->DedicateKey( WXK_RETURN );
115 grid->DedicateKey( WXK_NUMPAD_ENTER );
116 grid->DedicateKey( WXK_UP );
117 grid->DedicateKey( WXK_DOWN );
118
119#if wxCHECK_VERSION( 3, 3, 0 )
120 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_RETURN );
121 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
122 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_NUMPAD_ENTER );
123 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
124#else
125 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
126 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
127 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_NUMPAD_ENTER );
128 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
129#endif
130
132 m_pinAssignmentsGrid->PushEventHandler( new GRID_TRICKS( m_pinAssignmentsGrid ) );
133
135
136 // Now all widgets have the size fixed, call FinishDialogSettings
138}
139
140
141template <typename T>
143{
144 // Disable all properties. This is necessary because some of their methods are called after
145 // destruction of DIALOG_SIM_MODEL, oddly. When disabled, they never access their models.
146 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
147 {
148 SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it );
149
150 if( !prop )
151 continue;
152
153 prop->Disable();
154 }
155
156 // Delete the GRID_TRICKS.
157 m_pinAssignmentsGrid->PopEventHandler( true );
158
159 delete m_scintillaTricksCode;
160 delete m_scintillaTricksSubckt;
161}
162
163
164template <typename T>
166{
167 wxCommandEvent dummyEvent;
168 wxString deviceType;
169 wxString modelType;
170 wxString modelParams;
171 wxString pinMap;
172 bool storeInValue = false;
173
174 WX_STRING_REPORTER reporter;
175
176 auto setFieldValue =
177 [&]( const wxString& aFieldName, const wxString& aValue )
178 {
179 for( SCH_FIELD& field : m_fields )
180 {
181 if( field.GetName() == aFieldName )
182 {
183 field.SetText( aValue );
184 return;
185 }
186 }
187
188 m_fields.emplace_back( &m_symbol, -1, aFieldName );
189 m_fields.back().SetText( aValue );
190 };
191
192 // Infer RLC and VI models if they aren't specified
193 if( SIM_MODEL::InferSimModel( m_symbol, &m_fields, false, SIM_VALUE_GRAMMAR::NOTATION::SI,
194 &deviceType, &modelType, &modelParams, &pinMap ) )
195 {
196 setFieldValue( SIM_DEVICE_FIELD, deviceType );
197
198 if( !modelType.IsEmpty() )
199 setFieldValue( SIM_DEVICE_SUBTYPE_FIELD, modelType );
200
201 setFieldValue( SIM_PARAMS_FIELD, modelParams );
202
203 setFieldValue( SIM_PINS_FIELD, pinMap );
204
205 storeInValue = true;
206
207 // In case the storeInValue checkbox is turned off (if it's left on then we'll overwrite
208 // this field with the actual value):
209 m_fields[ VALUE_FIELD ].SetText( wxT( "${SIM.PARAMS}" ) );
210 }
211
212 std::string libraryFilename = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::LIBRARY_FIELD );
213
214 if( libraryFilename != "" )
215 {
216 // The model is sourced from a library, optionally with instance overrides.
217 m_rbLibraryModel->SetValue( true );
218
219 if( !loadLibrary( libraryFilename, reporter ) )
220 {
221 if( reporter.HasMessage() )
222 m_infoBar->ShowMessage( reporter.GetMessages() );
223
224 m_libraryPathText->ChangeValue( libraryFilename );
225 m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields, reporter );
226
227 m_libraryModelsMgr.CreateModel( nullptr, m_sortedPartPins, m_fields, reporter );
228
229 m_modelListBox->Append( _( "<unknown>" ) );
230 m_modelListBox->SetSelection( 0 );
231 }
232 else
233 {
234 std::string modelName = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD );
235 int modelIdx = m_modelListBox->FindString( modelName );
236
237 if( modelIdx == wxNOT_FOUND )
238 {
239 m_infoBar->ShowMessage( wxString::Format( _( "No model named '%s' in library." ),
240 modelName ) );
241
242 // Default to first item in library
243 m_modelListBox->SetSelection( 0 );
244 }
245 else
246 {
247 m_infoBar->Hide();
248 m_modelListBox->SetSelection( modelIdx );
249 }
250
251 m_curModelType = curModel().GetType();
252 }
253
254 if( isIbisLoaded() && ( m_modelListBox->GetSelection() >= 0 ) )
255 {
256 int idx = 0;
257 wxString sel = m_modelListBox->GetStringSelection();
258
259 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
260 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
261
262 auto ibismodel = dynamic_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels()[idx].get() );
263
264 if( ibismodel )
265 {
266 onModelNameChoice( dummyEvent ); // refresh list of pins
267
268 int i = 0;
269
270 for( const std::pair<std::string, std::string>& strs : ibismodel->GetIbisPins() )
271 {
272 if( strs.first == SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::PIN_FIELD ) )
273 {
274 auto ibisLibrary = static_cast<const SIM_LIBRARY_IBIS*>( library() );
275
276 ibismodel->ChangePin( *ibisLibrary, strs.first );
277 m_pinCombobox->SetSelection( static_cast<int>( i ) );
278 break;
279 }
280 i++;
281 }
282
283 if( i < static_cast<int>( ibismodel->GetIbisPins().size() ) )
284 {
285 onPinCombobox( dummyEvent ); // refresh list of models
286
287 m_pinModelCombobox->SetStringSelection(
289 }
290
292 {
293 ibismodel->SwitchSingleEndedDiff( true );
294 m_differentialCheckbox->SetValue( true );
295 }
296 else
297 {
298 ibismodel->SwitchSingleEndedDiff( false );
299 m_differentialCheckbox->SetValue( false );
300 }
301 }
302 }
303 }
304 else if( !SIM_MODEL::GetFieldValue( &m_fields, SIM_DEVICE_FIELD ).empty()
306 {
307 // The model is sourced from the instance.
308 m_rbBuiltinModel->SetValue( true );
309
310 reporter.Clear();
311 m_curModelType = SIM_MODEL::ReadTypeFromFields( m_fields, reporter );
312
313 if( reporter.HasMessage() )
314 DisplayErrorMessage( this, reporter.GetMessages() );
315 }
316
317 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
318 {
319 if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
320 {
321 reporter.Clear();
322 m_builtinModelsMgr.CreateModel( m_fields, m_sortedPartPins, false, reporter );
323
324 if( reporter.HasMessage() )
325 {
326 DisplayErrorMessage( this, _( "Failed to read simulation model from fields." )
327 + wxT( "\n\n" ) + reporter.GetMessages() );
328 }
329 }
330 else
331 {
332 m_builtinModelsMgr.CreateModel( type, m_sortedPartPins, reporter );
333 }
334
335 SIM_MODEL::DEVICE_T deviceTypeT = SIM_MODEL::TypeInfo( type ).deviceType;
336
337 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
338 m_curModelTypeOfDeviceType[deviceTypeT] = type;
339 }
340
341 if( storeInValue )
342 curModel().SetIsStoredInValue( true );
343
344 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
345
346 onRadioButton( dummyEvent );
347 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
348}
349
350
351template <typename T>
353{
354 m_pinAssignmentsGrid->CommitPendingChanges();
355 m_paramGrid->GetGrid()->CommitChangesFromEditor();
356
357 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
358 return false;
359
360 SIM_MODEL& model = curModel();
361 std::string path;
362 std::string name;
363
364 if( m_rbLibraryModel->GetValue() )
365 {
366 path = m_libraryPathText->GetValue();
367 wxFileName fn( path );
368
369 if( fn.MakeRelativeTo( Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( ".." ) )
370 path = fn.GetFullPath();
371
372 if( m_modelListBox->GetSelection() >= 0 )
373 name = m_modelListBox->GetStringSelection().ToStdString();
374 else if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( &model ) )
376 }
377
380
381 if( isIbisLoaded() )
382 {
383 int idx = 0;
384 wxString sel = m_modelListBox->GetStringSelection();
385
386 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
387 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
388
389 auto* ibismodel = static_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels().at( idx ).get() );
390
391 if( ibismodel )
392 {
393 std::string pins;
394 std::string modelName = std::string( m_pinModelCombobox->GetValue().c_str() );
395 std::string differential;
396
397 if( m_pinCombobox->GetSelection() >= 0 )
398 pins = ibismodel->GetIbisPins().at( m_pinCombobox->GetSelection() ).first;
399
400 if( ibismodel->CanDifferential() && m_differentialCheckbox->GetValue() )
401 differential = "1";
402
406 }
407 }
408
409 if( model.GetType() == SIM_MODEL::TYPE::RAWSPICE )
410 {
411 if( m_modelNotebook->GetSelection() == 0 )
412 updateModelCodeTab( &model );
413
414 wxString code = m_codePreview->GetText().Trim( true ).Trim( false );
415 model.SetParamValue( "model", std::string( code.ToUTF8() ) );
416 }
417
418 model.SetIsStoredInValue( m_saveInValueCheckbox->GetValue() );
419
420 for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
421 {
422 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( row, PIN_COLUMN::MODEL );
423 wxString symbolPinName = m_sortedPartPins.at( row )->GetShownNumber();
424
425 model.AssignSymbolPinNumberToModelPin( getModelPinIndex( modelPinName ),
426 std::string( symbolPinName.ToUTF8() ) );
427 }
428
429 removeOrphanedPinAssignments( &model );
430
431 curModel().WriteFields( m_fields );
432
433 return true;
434}
435
436
437template <typename T>
439{
440 // always enable the library browser button -- it makes for fewer clicks if the user has a
441 // whole bunch of inferred passives that they want to specify library models for
442 m_browseButton->Enable();
443
444 // if we're in an undetermined state then enable everything for faster access
445 bool undetermined = !m_rbLibraryModel->GetValue() && !m_rbBuiltinModel->GetValue();
446 bool enableLibCtrls = m_rbLibraryModel->GetValue() || undetermined;
447 bool enableBuiltinCtrls = m_rbBuiltinModel->GetValue() || undetermined;
448
449 m_pathLabel->Enable( enableLibCtrls );
450 m_libraryPathText->Enable( enableLibCtrls );
451 m_modelNameLabel->Enable( enableLibCtrls );
452 m_modelFilter->Enable( enableLibCtrls && !isIbisLoaded() );
453 m_modelListBox->Enable( enableLibCtrls );
454 m_pinLabel->Enable( enableLibCtrls );
455 m_pinCombobox->Enable( enableLibCtrls );
456 m_differentialCheckbox->Enable( enableLibCtrls );
457 m_pinModelLabel->Enable( enableLibCtrls );
458 m_pinModelCombobox->Enable( enableLibCtrls );
459 m_waveformLabel->Enable( enableLibCtrls );
460 m_waveformChoice->Enable( enableLibCtrls );
461
462 m_deviceLabel->Enable( enableBuiltinCtrls );
463 m_deviceChoice->Enable( enableBuiltinCtrls );
464 m_deviceSubtypeLabel->Enable( enableBuiltinCtrls );
465 m_deviceSubtypeChoice->Enable( enableBuiltinCtrls );
466
467 SIM_MODEL* model = &curModel();
468
469 updateIbisWidgets( model );
470 updateBuiltinModelWidgets( model );
471 updateModelParamsTab( model );
472 updateModelCodeTab( model );
473 updatePinAssignments( model, false );
474
475 std::string ref = SIM_MODEL::GetFieldValue( &m_fields, SIM_REFERENCE_FIELD );
476
477 m_modelPanel->Layout();
478 m_pinAssignmentsPanel->Layout();
479 m_parametersPanel->Layout();
480 m_codePanel->Layout();
481
482 SendSizeEvent( wxSEND_EVENT_POST );
483
484 m_prevModel = &curModel();
485}
486
487
488template <typename T>
490{
491 SIM_MODEL_IBIS* modelibis = isIbisLoaded() ? dynamic_cast<SIM_MODEL_IBIS*>( aModel )
492 : nullptr;
493
494 m_pinLabel->Show( isIbisLoaded() );
495 m_pinCombobox->Show( isIbisLoaded() );
496 m_pinModelLabel->Show( isIbisLoaded() );
497 m_pinModelCombobox->Show( isIbisLoaded() );
498 m_waveformLabel->Show( isIbisLoaded() );
499 m_waveformChoice->Show( isIbisLoaded() );
500
501 if( aModel != m_prevModel )
502 {
503 m_waveformChoice->Clear();
504
505 if( isIbisLoaded() )
506 {
507 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
508 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
509 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
510 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
511 {
512 SIM_MODEL::DEVICE_T deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
513 const std::string& deviceTypeDesc = SIM_MODEL::DeviceInfo( deviceType ).description;
514
515 if( deviceType == aModel->GetDeviceType()
516 || deviceTypeDesc == aModel->GetDeviceInfo().description )
517 {
518 m_waveformChoice->Append( SIM_MODEL::TypeInfo( type ).description );
519
520 if( type == aModel->GetType() )
521 m_waveformChoice->SetSelection( m_waveformChoice->GetCount() - 1 );
522 }
523 }
524 }
525 }
526
527 m_differentialCheckbox->Show( isIbisLoaded() && modelibis && modelibis->CanDifferential() );
528 m_modelNameLabel->SetLabel( isIbisLoaded() ? _( "Component:" ) : _( "Model:" ) );
529}
530
531
532template <typename T>
534{
535 // Change the Type choice to match the current device type.
536 if( aModel != m_prevModel )
537 {
538 m_deviceChoice->Clear();
539 m_deviceSubtypeChoice->Clear();
540
541 if( !m_rbLibraryModel->GetValue() )
542 {
543 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
544 {
545 if( !SIM_MODEL::DeviceInfo( deviceType ).showInMenu )
546 continue;
547
548 m_deviceChoice->Append( SIM_MODEL::DeviceInfo( deviceType ).description );
549
550 if( equivalent( deviceType, aModel->GetDeviceType() ) )
551 m_deviceChoice->SetSelection( m_deviceChoice->GetCount() - 1 );
552 }
553
554 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
555 {
556 if( type == SIM_MODEL::TYPE::KIBIS_DEVICE
557 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
558 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
559 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS )
560 {
561 continue;
562 }
563
564 SIM_MODEL::DEVICE_T deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
565 const std::string& deviceTypeDesc = SIM_MODEL::DeviceInfo( deviceType ).description;
566
567 if( deviceType == aModel->GetDeviceType()
568 || deviceTypeDesc == aModel->GetDeviceInfo().description )
569 {
570 m_deviceSubtypeChoice->Append( SIM_MODEL::TypeInfo( type ).description );
571
572 if( type == aModel->GetType() )
573 m_deviceSubtypeChoice->SetSelection( m_deviceSubtypeChoice->GetCount() - 1 );
574 }
575 }
576 }
577
578 m_deviceSubtypeLabel->Show( m_deviceSubtypeChoice->GetCount() > 1 );
579 m_deviceSubtypeChoice->Show( m_deviceSubtypeChoice->GetCount() > 1 );
580 }
581
582 if( dynamic_cast<SIM_MODEL_RAW_SPICE*>( aModel ) )
583 m_modelNotebook->SetSelection( 1 );
584 else
585 m_modelNotebook->SetSelection( 0 );
586
587 if( aModel->HasPrimaryValue() )
588 {
589 const SIM_MODEL::PARAM& primary = aModel->GetParam( 0 );
590
591 m_saveInValueCheckbox->SetLabel( wxString::Format( _( "Save parameter '%s (%s)' in Value "
592 "field" ),
593 primary.info.description,
594 primary.info.name ) );
595 m_saveInValueCheckbox->Enable( true );
596 }
597 else
598 {
599 m_saveInValueCheckbox->SetLabel( _( "Save primary parameter in Value field" ) );
600 m_saveInValueCheckbox->SetValue( false );
601 m_saveInValueCheckbox->Enable( false );
602 }
603}
604
605
606template <typename T>
608{
609 if( aModel != m_prevModel )
610 {
611 // This wxPropertyGridManager column and header stuff has to be here because it segfaults in
612 // the constructor.
613
614 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
615
616 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION, _( "Parameter" ) );
617 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT, _( "Unit" ) );
618 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT, _( "Default" ) );
619 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE, _( "Type" ) );
620
621 m_paramGridMgr->ShowHeader();
622
623
624 m_paramGrid->Clear();
625
626 m_firstCategory = m_paramGrid->Append( new wxPropertyCategory( "Geometry" ) );
627 m_paramGrid->HideProperty( "Geometry" );
628
629 m_paramGrid->Append( new wxPropertyCategory( "AC" ) );
630 m_paramGrid->HideProperty( "AC" );
631
632 m_paramGrid->Append( new wxPropertyCategory( "DC" ) );
633 m_paramGrid->HideProperty( "DC" );
634
635 m_paramGrid->Append( new wxPropertyCategory( "S-Parameters" ) );
636 m_paramGrid->HideProperty( "S-Parameters" );
637
638 m_paramGrid->Append( new wxPropertyCategory( "Capacitance" ) );
639 m_paramGrid->HideProperty( "Capacitance" );
640
641 m_paramGrid->Append( new wxPropertyCategory( "Temperature" ) );
642 m_paramGrid->HideProperty( "Temperature" );
643
644 m_paramGrid->Append( new wxPropertyCategory( "Noise" ) );
645 m_paramGrid->HideProperty( "Noise" );
646
647 m_paramGrid->Append( new wxPropertyCategory( "Distributed Quantities" ) );
648 m_paramGrid->HideProperty( "Distributed Quantities" );
649
650 m_paramGrid->Append( new wxPropertyCategory( "Waveform" ) );
651 m_paramGrid->HideProperty( "Waveform" );
652
653 m_paramGrid->Append( new wxPropertyCategory( "Limiting Values" ) );
654 m_paramGrid->HideProperty( "Limiting Values" );
655
656 m_paramGrid->Append( new wxPropertyCategory( "Advanced" ) );
657 m_paramGrid->HideProperty( "Advanced" );
658
659 m_paramGrid->Append( new wxPropertyCategory( "Flags" ) );
660 m_paramGrid->HideProperty( "Flags" );
661
662 m_paramGrid->CollapseAll();
663
664 for( int i = 0; i < aModel->GetParamCount(); ++i )
665 addParamPropertyIfRelevant( aModel, i );
666
667 m_paramGrid->CollapseAll();
668 m_paramGrid->Expand( "AC" );
669 m_paramGrid->Expand( "Waveform" );
670 }
671
672 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(), true );
673
674 // Set all properties to default colors.
675 // Update properties in models that have autofill.
676 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
677 {
678 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
679 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
680
681 for( int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
682 {
683 ( *it )->GetCell( col ).SetBgCol( bgCol );
684 ( *it )->GetCell( col ).SetFgCol( fgCol );
685 }
686
687 SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it );
688
689 if( !prop )
690 continue;
691
692 const SIM_MODEL::PARAM& param = prop->GetParam();
693
694 // Model values other than the currently edited value may have changed. Update them.
695 // This feature is called "autofill" and present only in certain models. Don't do it for
696 // models that don't have it for performance reasons.
697 if( aModel->HasAutofill() )
698 ( *it )->SetValueFromString( param.value );
699 }
700}
701
702
703template <typename T>
705{
706 if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( aModel ) )
707 return;
708
709 wxString text;
710 SPICE_ITEM item;
711
712 item.modelName = m_modelListBox->GetStringSelection();
713
714 if( m_rbBuiltinModel->GetValue() || item.modelName == "" )
715 item.modelName = m_fields.at( REFERENCE_FIELD ).GetText();
716
717 text << aModel->SpiceGenerator().Preview( item );
718
719 m_codePreview->SetText( text );
720 m_codePreview->SelectNone();
721}
722
723
724template <typename T>
725void DIALOG_SIM_MODEL<T>::updatePinAssignments( SIM_MODEL* aModel, bool aForceUpdatePins )
726{
727 if( m_pinAssignmentsGrid->GetNumberRows() == 0 )
728 {
729 m_pinAssignmentsGrid->AppendRows( static_cast<int>( m_sortedPartPins.size() ) );
730
731 for( int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
732 {
733 wxString symbolPinString = getSymbolPinString( ii );
734
735 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
736 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
737 }
738
739 aForceUpdatePins = true;
740 }
741
742 if( aForceUpdatePins )
743 {
744 // Reset the grid.
745 for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
746 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL, _( "Not Connected" ) );
747
748 // Now set up the grid values in the Model column.
749 for( int modelPinIndex = 0; modelPinIndex < aModel->GetPinCount(); ++modelPinIndex )
750 {
751 wxString symbolPinNumber = aModel->GetPin( modelPinIndex ).symbolPinNumber;
752
753 if( symbolPinNumber == "" )
754 continue;
755
756 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
757
758 if( symbolPinRow == -1 )
759 continue;
760
761 wxString modelPinString = getModelPinString( aModel, modelPinIndex );
762 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
763 }
764 }
765
766 for( int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
767 {
768 // Set up the Model column cell editors with dropdown options.
769 std::vector<BITMAPS> modelPinIcons;
770 wxArrayString modelPinChoices;
771
772 for( int jj = 0; jj < aModel->GetPinCount(); ++jj )
773 {
774 if( aModel->GetPin( jj ).symbolPinNumber != "" )
775 modelPinIcons.push_back( PinShapeGetBitmap( GRAPHIC_PINSHAPE::LINE ) );
776 else
777 modelPinIcons.push_back( BITMAPS::INVALID_BITMAP );
778
779 modelPinChoices.Add( getModelPinString( aModel, jj ) );
780 }
781
782 modelPinIcons.push_back( BITMAPS::INVALID_BITMAP );
783 modelPinChoices.Add( _( "Not Connected" ) );
784
785 // Using `new` here shouldn't cause a memory leak because `SetCellEditor()` calls
786 // `DecRef()` on its last editor.
787 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
788 new GRID_CELL_ICON_TEXT_POPUP( modelPinIcons,
789 modelPinChoices ) );
790 }
791
792 // TODO: Show a preview of the symbol with the pin numbers shown.
793
794 if( aModel->GetType() == SIM_MODEL::TYPE::SUBCKT )
795 {
796 SIM_MODEL_SUBCKT* subckt = static_cast<SIM_MODEL_SUBCKT*>( aModel );
797 m_subckt->SetText( subckt->GetSpiceCode() );
798 m_subckt->SetEditable( false );
799 }
800 else
801 {
802 m_subcktLabel->Show( false );
803 m_subckt->Show( false );
804 }
805}
806
807
808template <typename T>
810{
811 for( int i = 0; i < aModel->GetPinCount(); ++i )
812 {
813 if( !m_symbol.GetPin( aModel->GetPin( i ).symbolPinNumber ) )
814 aModel->AssignSymbolPinNumberToModelPin( i, "" );
815 }
816}
817
818
819template <typename T>
820bool DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aLibraryPath, REPORTER& aReporter,
821 bool aForceReload )
822{
823 if( m_prevLibrary == aLibraryPath && !aForceReload )
824 return true;
825
826 m_libraryModelsMgr.SetForceFullParse();
827 m_libraryModelsMgr.SetLibrary( aLibraryPath, aReporter );
828
830 return false;
831
832 std::string modelName = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD );
833
834 for( const auto& [baseModelName, baseModel] : library()->GetModels() )
835 {
836 if( baseModelName == modelName )
837 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, aReporter );
838 else
839 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, aReporter );
840 }
841
842 m_rbLibraryModel->SetValue( true );
843 m_libraryPathText->ChangeValue( aLibraryPath );
844
845 m_modelListBoxEntryToLibraryIdx.clear();
846 wxArrayString modelNames;
847
848 for( const auto& [name, model] : library()->GetModels() )
849 {
850 modelNames.Add( name );
851 m_modelListBoxEntryToLibraryIdx[name] = m_modelListBoxEntryToLibraryIdx.size();
852 }
853
854 modelNames.Sort();
855
856 m_modelListBox->Clear();
857 m_modelListBox->Append( modelNames );
858
859 if( isIbisLoaded() )
860 {
861 wxArrayString emptyArray;
862 m_pinModelCombobox->Set( emptyArray );
863 m_pinCombobox->Set( emptyArray );
864 m_pinModelCombobox->SetSelection( -1 );
865 m_pinCombobox->SetSelection( -1 );
866 }
867
868 m_modelListBox->SetStringSelection( modelName );
869
870 if( m_modelListBox->GetSelection() < 0 && m_modelListBox->GetCount() > 0 )
871 m_modelListBox->SetSelection( 0 );
872
873 m_curModelType = curModel().GetType();
874
875 m_prevLibrary = aLibraryPath;
876 return true;
877}
878
879
880template <typename T>
882{
883 if( aModel->GetParam( aParamIndex ).info.dir == SIM_MODEL::PARAM::DIR_OUT )
884 return;
885
886 switch( aModel->GetParam( aParamIndex ).info.category )
887 {
888 case CATEGORY::AC:
889 m_paramGrid->HideProperty( "AC", false );
890 m_paramGrid->AppendIn( "AC", newParamProperty( aModel, aParamIndex ) );
891 break;
892
893 case CATEGORY::DC:
894 m_paramGrid->HideProperty( "DC", false );
895 m_paramGrid->AppendIn( "DC", newParamProperty( aModel, aParamIndex ) );
896 break;
897
898 case CATEGORY::S_PARAM:
899 m_paramGrid->HideProperty( "S-Parameters", false );
900 m_paramGrid->AppendIn( "S-Parameters", newParamProperty( aModel, aParamIndex ) );
901 break;
902
903 case CATEGORY::CAPACITANCE:
904 m_paramGrid->HideProperty( "Capacitance", false );
905 m_paramGrid->AppendIn( "Capacitance", newParamProperty( aModel, aParamIndex ) );
906 break;
907
908 case CATEGORY::TEMPERATURE:
909 m_paramGrid->HideProperty( "Temperature", false );
910 m_paramGrid->AppendIn( "Temperature", newParamProperty( aModel, aParamIndex ) );
911 break;
912
913 case CATEGORY::NOISE:
914 m_paramGrid->HideProperty( "Noise", false );
915 m_paramGrid->AppendIn( "Noise", newParamProperty( aModel, aParamIndex ) );
916 break;
917
918 case CATEGORY::DISTRIBUTED_QUANTITIES:
919 m_paramGrid->HideProperty( "Distributed Quantities", false );
920 m_paramGrid->AppendIn( "Distributed Quantities", newParamProperty( aModel, aParamIndex ) );
921 break;
922
923 case CATEGORY::WAVEFORM:
924 m_paramGrid->HideProperty( "Waveform", false );
925 m_paramGrid->AppendIn( "Waveform", newParamProperty( aModel, aParamIndex ) );
926 break;
927
928 case CATEGORY::GEOMETRY:
929 m_paramGrid->HideProperty( "Geometry", false );
930 m_paramGrid->AppendIn( "Geometry", newParamProperty( aModel, aParamIndex ) );
931 break;
932
933 case CATEGORY::LIMITING_VALUES:
934 m_paramGrid->HideProperty( "Limiting Values", false );
935 m_paramGrid->AppendIn( "Limiting Values", newParamProperty( aModel, aParamIndex ) );
936 break;
937
938 case CATEGORY::ADVANCED:
939 m_paramGrid->HideProperty( "Advanced", false );
940 m_paramGrid->AppendIn( "Advanced", newParamProperty( aModel, aParamIndex ) );
941 break;
942
943 case CATEGORY::FLAGS:
944 m_paramGrid->HideProperty( "Flags", false );
945 m_paramGrid->AppendIn( "Flags", newParamProperty( aModel, aParamIndex ) );
946 break;
947
948 default:
949 m_paramGrid->Insert( m_firstCategory, newParamProperty( aModel, aParamIndex ) );
950 break;
951
952 case CATEGORY::INITIAL_CONDITIONS:
953 case CATEGORY::SUPERFLUOUS:
954 return;
955 }
956}
957
958
959template <typename T>
960wxPGProperty* DIALOG_SIM_MODEL<T>::newParamProperty( SIM_MODEL* aModel, int aParamIndex ) const
961{
962 const SIM_MODEL::PARAM& param = aModel->GetParam( aParamIndex );
963 wxString paramDescription;
964
965 if( param.info.description == "" )
966 paramDescription = wxString::Format( "%s", param.info.name );
967 else
968 paramDescription = wxString::Format( "%s (%s)", param.info.description, param.info.name );
969
970 wxPGProperty* prop = nullptr;
971
972 switch( param.info.type )
973 {
975 // TODO.
976 prop = new SIM_BOOL_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex );
977 prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX, true );
978 break;
979
981 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
983 break;
984
986 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
988 break;
989
990 //case TYPE_COMPLEX:
991 // break;
992
994 // Special case: K-line mutual inductance statement parameters l1 and l2 are references
995 // to other inductors in the circuit.
996 if( dynamic_cast<SIM_MODEL_L_MUTUAL*>( aModel ) != nullptr
997 && ( param.info.name == "l1" || param.info.name == "l2" ) )
998 {
999 wxArrayString inductors;
1000
1001 if( SCH_EDIT_FRAME* schEditFrame = dynamic_cast<SCH_EDIT_FRAME*>( m_frame ) )
1002 {
1003 SPICE_CIRCUIT_MODEL circuit( &schEditFrame->Schematic() );
1004 NULL_REPORTER devNul;
1005
1007 devNul );
1008
1009 for( const SPICE_ITEM& item : circuit.GetItems() )
1010 {
1011 if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::L )
1012 inductors.push_back( item.refName );
1013 }
1014
1015 inductors.Sort(
1016 []( const wxString& a, const wxString& b ) -> int
1017 {
1018 return StrNumCmp( a, b, true );
1019 } );
1020 }
1021
1022 if( inductors.empty() )
1023 {
1024 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel,
1025 aParamIndex, SIM_VALUE::TYPE_STRING );
1026 }
1027 else
1028 {
1029 prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel,
1030 aParamIndex, inductors );
1031 }
1032 }
1033 else if( param.info.enumValues.empty() )
1034 {
1035 prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, *aModel,
1036 aParamIndex, SIM_VALUE::TYPE_STRING );
1037 }
1038 else
1039 {
1040 wxArrayString values;
1041
1042 for( const std::string& string : aModel->GetParam( aParamIndex ).info.enumValues )
1043 values.Add( string );
1044
1045 prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, *aModel, aParamIndex,
1046 values );
1047 }
1048 break;
1049
1050 default:
1051 prop = new wxStringProperty( paramDescription, param.info.name );
1052 break;
1053 }
1054
1055 prop->SetAttribute( wxPG_ATTR_UNITS, wxString::FromUTF8( param.info.unit.c_str() ) );
1056
1057 // Legacy due to the way we extracted the parameters from Ngspice.
1058 prop->SetCell( 3, wxString::FromUTF8( param.info.defaultValue ) );
1059
1060 wxString typeStr;
1061
1062 switch( param.info.type )
1063 {
1064 case SIM_VALUE::TYPE_BOOL: typeStr = wxT( "Bool" ); break;
1065 case SIM_VALUE::TYPE_INT: typeStr = wxT( "Int" ); break;
1066 case SIM_VALUE::TYPE_FLOAT: typeStr = wxT( "Float" ); break;
1067 case SIM_VALUE::TYPE_COMPLEX: typeStr = wxT( "Complex" ); break;
1068 case SIM_VALUE::TYPE_STRING: typeStr = wxT( "String" ); break;
1069 case SIM_VALUE::TYPE_BOOL_VECTOR: typeStr = wxT( "Bool Vector" ); break;
1070 case SIM_VALUE::TYPE_INT_VECTOR: typeStr = wxT( "Int Vector" ); break;
1071 case SIM_VALUE::TYPE_FLOAT_VECTOR: typeStr = wxT( "Float Vector" ); break;
1072 case SIM_VALUE::TYPE_COMPLEX_VECTOR: typeStr = wxT( "Complex Vector" ); break;
1073 }
1074
1075 prop->SetCell( PARAM_COLUMN::TYPE, typeStr );
1076
1077 return prop;
1078}
1079
1080
1081template <typename T>
1082int DIALOG_SIM_MODEL<T>::findSymbolPinRow( const wxString& aSymbolPinNumber ) const
1083{
1084 for( int row = 0; row < static_cast<int>( m_sortedPartPins.size() ); ++row )
1085 {
1086 SCH_PIN* pin = m_sortedPartPins[row];
1087
1088 if( pin->GetNumber() == aSymbolPinNumber )
1089 return row;
1090 }
1091
1092 return -1;
1093}
1094
1095
1096template <typename T>
1098{
1099 if( m_rbLibraryModel->GetValue() )
1100 {
1101 wxString sel = m_modelListBox->GetStringSelection();
1102
1103 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
1104 return m_libraryModelsMgr.GetModels().at( m_modelListBoxEntryToLibraryIdx.at( sel ) ).get();
1105 }
1106 else
1107 {
1108 if( static_cast<int>( m_curModelType ) < static_cast<int>( m_builtinModelsMgr.GetModels().size() ) )
1109 return m_builtinModelsMgr.GetModels().at( static_cast<int>( m_curModelType ) );
1110 }
1111
1112 return m_builtinModelsMgr.GetModels().at( static_cast<int>( SIM_MODEL::TYPE::NONE ) );
1113}
1114
1115
1116template <typename T>
1118{
1119 if( m_libraryModelsMgr.GetLibraries().size() == 1 )
1120 return &m_libraryModelsMgr.GetLibraries().begin()->second.get();
1121
1122 return nullptr;
1123}
1124
1125
1126template <typename T>
1127wxString DIALOG_SIM_MODEL<T>::getSymbolPinString( int symbolPinIndex ) const
1128{
1129 SCH_PIN* pin = m_sortedPartPins.at( symbolPinIndex );
1130 wxString pinNumber;
1131 wxString pinName;
1132
1133 if( pin )
1134 {
1135 pinNumber = pin->GetShownNumber();
1136 pinName = pin->GetShownName();
1137 }
1138
1139 if( !pinName.IsEmpty() && pinName != pinNumber )
1140 pinNumber += wxString::Format( wxT( " (%s)" ), pinName );
1141
1142 return pinNumber;
1143}
1144
1145
1146template <typename T>
1147wxString DIALOG_SIM_MODEL<T>::getModelPinString( SIM_MODEL* aModel, int aModelPinIndex ) const
1148{
1149 const wxString& modelPinName = aModel->GetPin( aModelPinIndex ).modelPinName;
1150
1151 LOCALE_IO toggle;
1152
1153 wxString modelPinNumber = wxString::Format( "%d", aModelPinIndex + 1 );
1154
1155 if( !modelPinName.IsEmpty() && modelPinName != modelPinNumber )
1156 modelPinNumber += wxString::Format( wxT( " (%s)" ), modelPinName );
1157
1158 return modelPinNumber;
1159}
1160
1161
1162template <typename T>
1163int DIALOG_SIM_MODEL<T>::getModelPinIndex( const wxString& aModelPinString ) const
1164{
1165 if( aModelPinString == "Not Connected" )
1167
1168 int length = aModelPinString.Find( " " );
1169
1170 if( length == wxNOT_FOUND )
1171 length = static_cast<int>( aModelPinString.Length() );
1172
1173 long result = 0;
1174 aModelPinString.Mid( 0, length ).ToCLong( &result );
1175
1176 return static_cast<int>( result - 1 );
1177}
1178
1179
1180template <typename T>
1181void DIALOG_SIM_MODEL<T>::onRadioButton( wxCommandEvent& aEvent )
1182{
1183 m_prevModel = nullptr; // Ensure the Model panel will be rebuild after updating other params.
1184 updateWidgets();
1185}
1186
1187
1188template <typename T>
1189void DIALOG_SIM_MODEL<T>::onLibraryPathText( wxCommandEvent& aEvent )
1190{
1191 m_rbLibraryModel->SetValue( true );
1192}
1193
1194
1195template <typename T>
1197{
1198 m_rbLibraryModel->SetValue( true );
1199
1200 WX_STRING_REPORTER reporter;
1201 wxString path = m_libraryPathText->GetValue();
1202
1203 if( loadLibrary( path, reporter, true ) || path.IsEmpty() )
1204 m_infoBar->Hide();
1205 else if( reporter.HasMessage() )
1206 m_infoBar->ShowMessage( reporter.GetMessages() );
1207
1208 updateWidgets();
1209}
1210
1211
1212template <typename T>
1214{
1215 CallAfter(
1216 [this]()
1217 {
1218 // Disable logging -- otherwise we'll end up in an endless loop of show-log,
1219 // kill-focus, show-log, kill-focus, etc.
1220 wxLogNull doNotLog;
1221
1222 wxCommandEvent dummy;
1223 onLibraryPathTextEnter( dummy );
1224 } );
1225
1226 aEvent.Skip(); // mandatory in wxFocusEvent events
1227}
1228
1229
1230template <typename T>
1231void DIALOG_SIM_MODEL<T>::onBrowseButtonClick( wxCommandEvent& aEvent )
1232{
1233 static wxString s_mruPath;
1234
1235 wxString path = s_mruPath.IsEmpty() ? Prj().GetProjectPath() : s_mruPath;
1236 wxFileDialog dlg( this, _( "Browse Models" ), path );
1237
1238 if( dlg.ShowModal() == wxID_CANCEL )
1239 return;
1240
1241 m_rbLibraryModel->SetValue( true );
1242
1243 path = dlg.GetPath();
1244 wxFileName fn( path );
1245
1246 s_mruPath = fn.GetPath();
1247
1248 if( fn.MakeRelativeTo( Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( wxS( ".." ) ) )
1249 path = fn.GetFullPath();
1250
1251 WX_STRING_REPORTER reporter;
1252
1253 if( loadLibrary( path, reporter, true ) )
1254 m_infoBar->Hide();
1255 else
1256 m_infoBar->ShowMessage( reporter.GetMessages() );
1257
1258 updateWidgets();
1259}
1260
1261
1262template <typename T>
1263void DIALOG_SIM_MODEL<T>::onFilterCharHook( wxKeyEvent& aKeyStroke )
1264{
1265 int sel = m_modelListBox->GetSelection();
1266
1267 switch( aKeyStroke.GetKeyCode() )
1268 {
1269 case WXK_UP:
1270 if( sel == wxNOT_FOUND )
1271 sel = m_modelListBox->GetCount() - 1;
1272 else
1273 sel--;
1274
1275 break;
1276
1277 case WXK_DOWN:
1278 if( sel == wxNOT_FOUND )
1279 sel = 0;
1280 else
1281 sel++;
1282
1283 break;
1284
1285 case WXK_RETURN:
1286 wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
1287 return;
1288
1289 default:
1290 aKeyStroke.Skip(); // Any other key: pass on to search box directly.
1291 return;
1292 }
1293
1294 if( sel >= 0 && sel < (int) m_modelListBox->GetCount() )
1295 m_modelListBox->SetSelection( sel );
1296}
1297
1298
1299template <typename T>
1300void DIALOG_SIM_MODEL<T>::onModelFilter( wxCommandEvent& aEvent )
1301{
1302 wxArrayString modelNames;
1303 wxString current = m_modelListBox->GetStringSelection();
1304 wxString filter = wxT( "*" ) + m_modelFilter->GetValue() + wxT( "*" );
1305
1306 for( const auto& [name, model] : library()->GetModels() )
1307 {
1308 wxString wx_name( name );
1309
1310 if( wx_name.Matches( filter ) )
1311 modelNames.Add( wx_name );
1312 }
1313
1314 modelNames.Sort();
1315
1316 m_modelListBox->Clear();
1317 m_modelListBox->Append( modelNames );
1318
1319 if( !m_modelListBox->SetStringSelection( current ) )
1320 m_modelListBox->SetSelection( 0 );
1321}
1322
1323
1324template <typename T>
1325void DIALOG_SIM_MODEL<T>::onModelNameChoice( wxCommandEvent& aEvent )
1326{
1327 if( isIbisLoaded() )
1328 {
1329 wxArrayString pinLabels;
1330 SIM_MODEL_IBIS* modelkibis = dynamic_cast<SIM_MODEL_IBIS*>( &curModel() );
1331
1332 wxCHECK2( modelkibis, return );
1333
1334 for( std::pair<wxString, wxString> strs : modelkibis->GetIbisPins() )
1335 pinLabels.Add( strs.first + wxT( " - " ) + strs.second );
1336
1337 m_pinCombobox->Set( pinLabels );
1338
1339 wxArrayString emptyArray;
1340 m_pinModelCombobox->Set( emptyArray );
1341 }
1342
1343 m_rbLibraryModel->SetValue( true );
1344
1345 if( SIM_MODEL_SPICE_FALLBACK* fallback = dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( &curModel() ) )
1346 {
1347 wxArrayString lines = wxSplit( fallback->GetSpiceCode(), '\n' );
1348 wxString code;
1349
1350 for( const wxString& line : lines )
1351 {
1352 if( !line.StartsWith( '*' ) )
1353 {
1354 if( !code.IsEmpty() )
1355 code += "\n";
1356
1357 code += line;
1358 }
1359 }
1360
1361 m_infoBar->ShowMessage( wxString::Format( _( "Failed to parse:\n\n"
1362 "%s\n"
1363 "Using generic SPICE model." ),
1364 code ) );
1365 }
1366 else
1367 {
1368 m_infoBar->Hide();
1369 }
1370
1371 updateWidgets();
1372}
1373
1374
1375template <typename T>
1376void DIALOG_SIM_MODEL<T>::onPinCombobox( wxCommandEvent& aEvent )
1377{
1378 wxArrayString modelLabels;
1379
1380 SIM_MODEL_IBIS& ibisModel = static_cast<SIM_MODEL_IBIS&>( curModel() );
1381
1382 std::vector<std::pair<std::string, std::string>> strs = ibisModel.GetIbisPins();
1383 std::string pinNumber = strs.at( m_pinCombobox->GetSelection() ).first;
1384
1385 const SIM_LIBRARY_IBIS* ibisLibrary = dynamic_cast<const SIM_LIBRARY_IBIS*>( library() );
1386
1387 ibisModel.ChangePin( *ibisLibrary, pinNumber );
1388
1389 ibisModel.m_enableDiff = ibisLibrary->isPinDiff( ibisModel.GetComponentName(), pinNumber );
1390
1391 for( wxString modelName : ibisModel.GetIbisModels() )
1392 modelLabels.Add( modelName );
1393
1394 m_pinModelCombobox->Set( modelLabels );
1395
1396 if( m_pinModelCombobox->GetCount() == 1 )
1397 m_pinModelCombobox->SetSelection( 0 );
1398 else
1399 m_pinModelCombobox->SetSelection( -1 );
1400
1401 updateWidgets();
1402}
1403
1404
1405template <typename T>
1407{
1408 m_pinCombobox->SetSelection( m_pinCombobox->FindString( m_pinCombobox->GetValue() ) );
1409
1410 onPinModelCombobox( aEvent );
1411}
1412
1413
1414template <typename T>
1415void DIALOG_SIM_MODEL<T>::onPinModelCombobox( wxCommandEvent& aEvent )
1416{
1417 updateWidgets();
1418}
1419
1420
1421template <typename T>
1423{
1424 m_pinModelCombobox->SetSelection( m_pinModelCombobox->FindString( m_pinModelCombobox->GetValue() ) );
1425}
1426
1427template <typename T>
1429{
1430 if( SIM_MODEL_IBIS* modelibis = dynamic_cast<SIM_MODEL_IBIS*>( &curModel() ) )
1431 {
1432 bool diff = m_differentialCheckbox->GetValue() && modelibis->CanDifferential();
1433 modelibis->SwitchSingleEndedDiff( diff );
1434
1435 updateWidgets();
1436 }
1437}
1438
1439
1440template <typename T>
1441void DIALOG_SIM_MODEL<T>::onDeviceTypeChoice( wxCommandEvent& aEvent )
1442{
1443 m_rbBuiltinModel->SetValue( true );
1444
1445 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
1446 {
1447 if( SIM_MODEL::DeviceInfo( deviceType ).description == m_deviceChoice->GetStringSelection() )
1448 {
1449 m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
1450 break;
1451 }
1452 }
1453
1454 updateWidgets();
1455}
1456
1457
1458template <typename T>
1459void DIALOG_SIM_MODEL<T>::onWaveformChoice( wxCommandEvent& aEvent )
1460{
1461 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1462 wxString typeDescription = m_waveformChoice->GetStringSelection();
1463
1464 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
1465 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
1466 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
1467 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
1468 {
1469 if( equivalent( deviceType, SIM_MODEL::TypeInfo( type ).deviceType )
1470 && typeDescription == SIM_MODEL::TypeInfo( type ).description )
1471 {
1472 int idx = 0;
1473 wxString sel = m_modelListBox->GetStringSelection();
1474
1475 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
1476 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
1477
1478 auto& baseModel = static_cast<SIM_MODEL_IBIS&>( m_libraryModelsMgr.GetModels()[idx].get() );
1479
1480 m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_IBIS>( type, baseModel ) );
1481
1482 try
1483 {
1484 m_libraryModelsMgr.GetModels()[idx].get().ReadDataFields( &m_fields, m_sortedPartPins );
1485 }
1486 catch( IO_ERROR& err )
1487 {
1488 DisplayErrorMessage( this, err.What() );
1489 }
1490
1491 m_curModelType = type;
1492 break;
1493 }
1494 }
1495
1496 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1497 updateWidgets();
1498}
1499
1500
1501template <typename T>
1502void DIALOG_SIM_MODEL<T>::onTypeChoice( wxCommandEvent& aEvent )
1503{
1504 SIM_MODEL::DEVICE_T deviceType = curModel().GetDeviceType();
1505 wxString typeDescription = m_deviceSubtypeChoice->GetStringSelection();
1506
1507 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
1508 {
1509 if( equivalent( deviceType, SIM_MODEL::TypeInfo( type ).deviceType )
1510 && typeDescription == SIM_MODEL::TypeInfo( type ).description )
1511 {
1512 m_curModelType = type;
1513 break;
1514 }
1515 }
1516
1517 m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
1518 updateWidgets();
1519}
1520
1521
1522template <typename T>
1523void DIALOG_SIM_MODEL<T>::onPageChanging( wxBookCtrlEvent& event )
1524{
1525 updateModelCodeTab( &curModel() );
1526}
1527
1528
1529template <typename T>
1531{
1532 int symbolPinIndex = aEvent.GetRow();
1533 wxString oldModelPinName = aEvent.GetString();
1534 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() );
1535
1536 int oldModelPinIndex = getModelPinIndex( oldModelPinName );
1537 int modelPinIndex = getModelPinIndex( modelPinName );
1538
1539 if( oldModelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED )
1540 curModel().AssignSymbolPinNumberToModelPin( oldModelPinIndex, "" );
1541
1542 if( modelPinIndex != SIM_MODEL_PIN::NOT_CONNECTED )
1543 {
1544 SCH_PIN* symbolPin = m_sortedPartPins.at( symbolPinIndex );
1545
1546 curModel().AssignSymbolPinNumberToModelPin( modelPinIndex, symbolPin->GetShownNumber() );
1547 }
1548
1549 updatePinAssignments( &curModel(), FORCE_UPDATE_PINS );
1550
1551 aEvent.Skip();
1552}
1553
1554
1555template <typename T>
1557{
1558 wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
1559
1560 int gridWidth = KIPLATFORM::UI::GetUnobscuredSize( m_pinAssignmentsGrid ).x;
1561 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::MODEL, gridWidth / 2 );
1562 m_pinAssignmentsGrid->SetColSize( PIN_COLUMN::SYMBOL, gridWidth / 2 );
1563
1564 aEvent.Skip();
1565}
1566
1567
1568template <typename T>
1570{
1571 // By default, when a property grid is focused, the textbox is not immediately focused until
1572 // Tab key is pressed. This is inconvenient, so we fix that here.
1573
1574 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1575 wxPGProperty* selected = grid->GetSelection();
1576
1577 if( !selected )
1578 selected = grid->wxPropertyGridInterface::GetFirst();
1579
1580#if wxCHECK_VERSION( 3, 3, 0 )
1581 if( selected )
1582 grid->DoSelectProperty( selected, wxPGSelectPropertyFlags::Focus );
1583#else
1584 if( selected )
1585 grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
1586#endif
1587
1588 aEvent.Skip();
1589}
1590
1591
1592template <typename T>
1593void DIALOG_SIM_MODEL<T>::onParamGridSelectionChange( wxPropertyGridEvent& aEvent )
1594{
1595 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1596
1597 // Jump over categories.
1598 if( grid->GetSelection() && grid->GetSelection()->IsCategory() )
1599 {
1600 wxPGProperty* selection = grid->GetSelection();
1601
1602 // If the new selection is immediately above the previous selection, we jump up. Otherwise
1603 // we jump down. We do this by simulating up or down arrow keys.
1604
1605 wxPropertyGridIterator it = grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
1606 it.Next();
1607
1608 wxKeyEvent* keyEvent = new wxKeyEvent( wxEVT_KEY_DOWN );
1609
1610 if( *it == m_prevParamGridSelection )
1611 {
1612 if( !selection->IsExpanded() )
1613 {
1614 grid->Expand( selection );
1615 keyEvent->m_keyCode = WXK_DOWN;
1616 wxQueueEvent( grid, keyEvent );
1617
1618 // Does not work for some reason.
1619 /*m_paramGrid->DoSelectProperty( selection->Item( selection->GetChildCount() - 1 ),
1620 wxPG_SEL_FOCUS );*/
1621 }
1622 else
1623 {
1624 keyEvent->m_keyCode = WXK_UP;
1625 wxQueueEvent( grid, keyEvent );
1626 }
1627 }
1628 else
1629 {
1630 if( !selection->IsExpanded() )
1631 grid->Expand( selection );
1632
1633 keyEvent->m_keyCode = WXK_DOWN;
1634 wxQueueEvent( grid, keyEvent );
1635 }
1636
1637 m_prevParamGridSelection = grid->GetSelection();
1638 return;
1639 }
1640
1641 wxWindow* editorControl = grid->GetEditorControl();
1642
1643 if( !editorControl )
1644 {
1645 m_prevParamGridSelection = grid->GetSelection();
1646 return;
1647 }
1648
1649 // Without this the user had to press tab before they could edit the field.
1650 editorControl->SetFocus();
1651 m_prevParamGridSelection = grid->GetSelection();
1652}
1653
1654
1655template <typename T>
1656void DIALOG_SIM_MODEL<T>::onUpdateUI( wxUpdateUIEvent& aEvent )
1657{
1658 // This is currently patched in wxPropertyGrid::ScrollWindow() in the Mac wxWidgets fork.
1659 // However, we may need this version if it turns out to be an issue on other platforms and
1660 // we can't get it upstreamed.
1661#if 0
1662 // It's a shame to do this on the UpdateUI event, but neither the wxPropertyGridManager,
1663 // wxPropertyGridPage, wxPropertyGrid, nor the wxPropertyGrid's GetCanvas() window appear
1664 // to get scroll events.
1665
1666 wxPropertyGrid* grid = m_paramGrid->GetGrid();
1667 wxTextCtrl* ctrl = grid->GetEditorTextCtrl();
1668
1669 if( ctrl )
1670 {
1671 wxRect ctrlRect = ctrl->GetScreenRect();
1672 wxRect gridRect = grid->GetScreenRect();
1673
1674 if( ctrlRect.GetTop() < gridRect.GetTop() || ctrlRect.GetBottom() > gridRect.GetBottom() )
1675 grid->ClearSelection();
1676 }
1677#endif
1678}
1679
1680
1681template <typename T>
1682void DIALOG_SIM_MODEL<T>::adjustParamGridColumns( int aWidth, bool aForce )
1683{
1684 wxPropertyGrid* grid = m_paramGridMgr->GetGrid();
1685 int margin = 15;
1686 int indent = 20;
1687
1688 if( aWidth != m_lastParamGridWidth || aForce )
1689 {
1690 m_lastParamGridWidth = aWidth;
1691
1692 grid->FitColumns();
1693
1694 std::vector<int> colWidths;
1695
1696 for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ )
1697 {
1698 if( ii == PARAM_COLUMN::DESCRIPTION )
1699 colWidths.push_back( grid->GetState()->GetColumnWidth( ii ) + margin + indent );
1700 else if( ii == PARAM_COLUMN::VALUE )
1701 colWidths.push_back( std::max( 72, grid->GetState()->GetColumnWidth( ii ) ) + margin );
1702 else
1703 colWidths.push_back( 60 + margin );
1704
1705 aWidth -= colWidths[ ii ];
1706 }
1707
1708 for( size_t ii = 0; ii < grid->GetColumnCount(); ii++ )
1709 grid->SetColumnProportion( ii, colWidths[ ii ] );
1710
1711 grid->ResetColumnSizes();
1712 grid->RefreshEditor();
1713 }
1714}
1715
1716
1717template <typename T>
1719{
1720 adjustParamGridColumns( event.GetSize().GetX(), false );
1721
1722 event.Skip();
1723}
1724
1725
1726
1727template class DIALOG_SIM_MODEL<SCH_SYMBOL>;
1728template class DIALOG_SIM_MODEL<LIB_SYMBOL>;
const char * name
Definition: DXF_plotter.cpp:57
wxBitmapBundle KiBitmapBundle(BITMAPS aBitmap)
Definition: bitmap.cpp:110
@ INVALID_BITMAP
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
Class DIALOG_SIM_MODEL_BASE.
wxPropertyGridManager * m_paramGridMgr
STD_BITMAP_BUTTON * m_browseButton
wxStyledTextCtrl * m_subckt
wxPropertyGridPage * m_paramGrid
wxStyledTextCtrl * m_codePreview
void onTypeChoice(wxCommandEvent &aEvent) override
void onLibraryPathTextKillFocus(wxFocusEvent &aEvent) override
wxString getSymbolPinString(int aSymbolPinNumber) const
void updateBuiltinModelWidgets(SIM_MODEL *aModel)
void onPinAssignmentsGridCellChange(wxGridEvent &aEvent) override
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)
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)
std::vector< SCH_PIN * > m_sortedPartPins
wxPGProperty * newParamProperty(SIM_MODEL *aModel, int aParamIndex) const
void onPinModelCombobox(wxCommandEvent &event) override
const SIM_LIBRARY * library() const
SIM_MODEL & curModel() const
void onBrowseButtonClick(wxCommandEvent &aEvent) override
void onPinComboboxTextEnter(wxCommandEvent &event) override
void onPinCombobox(wxCommandEvent &event) override
SCINTILLA_TRICKS * m_scintillaTricksCode
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
void updateModelCodeTab(SIM_MODEL *aModel)
void onSizeParamGrid(wxSizeEvent &event) override
void onPageChanging(wxNotebookEvent &event) override
void onWaveformChoice(wxCommandEvent &aEvent) override
void onPinModelComboboxTextEnter(wxCommandEvent &event) override
void onLibraryPathTextEnter(wxCommandEvent &aEvent) override
void onDeviceTypeChoice(wxCommandEvent &aEvent) override
bool TransferDataToWindow() override
void addParamPropertyIfRelevant(SIM_MODEL *aModel, int aParamIndex)
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:61
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:77
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
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:203
virtual const wxString GetProjectPath() const
Return the full path of the project.
Definition: project.cpp:135
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
Definition: reporter.cpp:53
Schematic editor (Eeschema) main window.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
wxString GetShownNumber() const
Definition: sch_pin.cpp:511
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:35
static constexpr auto NAME_FIELD
Definition: sim_library.h:36
std::vector< std::pair< std::string, std::string > > GetIbisPins() const
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
std::string GetSpiceCode() const
static TYPE ReadTypeFromFields(const std::vector< SCH_FIELD > &aFields, REPORTER &aReporter)
Definition: sim_model.cpp:390
static INFO TypeInfo(TYPE aType)
Definition: sim_model.cpp:105
static void SetFieldValue(std::vector< SCH_FIELD > &aFields, const wxString &aFieldName, const std::string &aValue)
Definition: sim_model.cpp:673
int GetPinCount() const
Definition: sim_model.h:471
void ReadDataFields(const std::vector< SCH_FIELD > *aFields, const std::vector< SCH_PIN * > &aPins)
Definition: sim_model.cpp:427
const SPICE_GENERATOR & SpiceGenerator() const
Definition: sim_model.h:435
virtual const PARAM & GetParam(unsigned aParamIndex) const
Definition: sim_model.cpp:789
static bool InferSimModel(T &aSymbol, std::vector< SCH_FIELD > *aFields, bool aResolve, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
Definition: sim_model.cpp:1082
static std::string GetFieldValue(const std::vector< SCH_FIELD > *aFields, const wxString &aFieldName, bool aResolve=true)
Definition: sim_model.cpp:654
int GetParamCount() const
Definition: sim_model.h:481
void AssignSymbolPinNumberToModelPin(int aPinIndex, const wxString &aSymbolPinNumber)
Definition: sim_model.cpp:758
DEVICE_INFO GetDeviceInfo() const
Definition: sim_model.h:460
DEVICE_T GetDeviceType() const
Definition: sim_model.h:463
static DEVICE_INFO DeviceInfo(DEVICE_T aDeviceType)
Definition: sim_model.cpp:60
virtual bool HasAutofill() const
Definition: sim_model.h:498
void SetParamValue(int aParamIndex, const std::string &aValue, SIM_VALUE::NOTATION aNotation=SIM_VALUE::NOTATION::SI)
Definition: sim_model.cpp:845
const SIM_MODEL_PIN & GetPin(unsigned aIndex) const
Definition: sim_model.h:472
void SetIsStoredInValue(bool aIsStoredInValue)
Definition: sim_model.h:504
virtual bool HasPrimaryValue() const
Definition: sim_model.h:499
TYPE GetType() const
Definition: sim_model.h:464
const SIM_MODEL::PARAM & GetParam() const
Definition: sim_property.h:60
@ TYPE_BOOL
Definition: sim_value.h:67
@ TYPE_FLOAT_VECTOR
Definition: sim_value.h:75
@ TYPE_BOOL_VECTOR
Definition: sim_value.h:73
@ TYPE_INT
Definition: sim_value.h:68
@ TYPE_FLOAT
Definition: sim_value.h:69
@ TYPE_INT_VECTOR
Definition: sim_value.h:74
@ TYPE_COMPLEX_VECTOR
Definition: sim_value.h:76
@ TYPE_STRING
Definition: sim_value.h:71
@ TYPE_COMPLEX
Definition: sim_value.h:70
Special netlist exporter flavor that allows one to override simulation commands.
virtual std::string Preview(const SPICE_ITEM &aItem) const
void SetBitmap(const wxBitmapBundle &aBmp)
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:184
void AddCloseButton(const wxString &aTooltip=_("Hide this message."))
Add the default close button to the infobar on the right side.
Definition: wx_infobar.cpp:294
A wrapper for reporting to a wxString object.
Definition: reporter.h:171
bool HasMessage() const override
Returns true if the reporter client is non-empty.
Definition: reporter.cpp:97
const wxString & GetMessages() const
Definition: reporter.cpp:84
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:195
This file is part of the common library.
static bool empty(const wxTextEntryBase *aCtrl)
bool equivalent(SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b)
#define FORCE_UPDATE_PINS
#define _(s)
PROJECT & Prj()
Definition: kicad.cpp:597
wxSize GetUnobscuredSize(const wxWindow *aWindow)
Tries to determine the size of the viewport of a scrollable widget (wxDataViewCtrl,...
Definition: wxgtk/ui.cpp:195
KICOMMON_API wxFont GetInfoFont(wxWindow *aWindow)
Definition: ui_common.cpp:154
BITMAPS PinShapeGetBitmap(GRAPHIC_PINSHAPE aShape)
Definition: pin_type.cpp:246
@ RPT_SEVERITY_ERROR
@ RPT_SEVERITY_UNDEFINED
@ NONE
No connection to this item.
SIM_MODEL::TYPE TYPE
Definition: sim_model.cpp:57
#define SIM_PINS_FIELD
Definition: sim_model.h:54
#define SIM_DEVICE_FIELD
Definition: sim_model.h:52
#define SIM_REFERENCE_FIELD
Definition: sim_model.h:49
#define SIM_PARAMS_FIELD
Definition: sim_model.h:55
#define SIM_DEVICE_SUBTYPE_FIELD
Definition: sim_model.h:53
std::vector< FAB_LAYER_COLOR > dummy
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
std::vector< std::string > enumValues
Definition: sim_model.h:388
SIM_VALUE::TYPE type
Definition: sim_model.h:379
std::string defaultValue
Definition: sim_model.h:382
std::string description
Definition: sim_model.h:383
std::string value
Definition: sim_model.h:400
const INFO & info
Definition: sim_model.h:401
static constexpr auto NOT_CONNECTED
Definition: sim_model.h:73
const std::string modelPinName
Definition: sim_model.h:70
wxString symbolPinNumber
Definition: sim_model.h:71
std::string modelName
@ VALUE_FIELD
Field Value of part, i.e. "3.3K".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".