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