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>
45#include <widgets/wx_infobar.h>
49#include <wx/filedlg.h>
50#include <wx/log.h>
51
53
54#define FORCE_REFRESH_FROM_MODEL true
55
56
57bool equivalent( SIM_MODEL::DEVICE_T a, SIM_MODEL::DEVICE_T b )
58{
59 // A helper to handle SPICE's use of 'E' and 'H' for voltage sources and 'F' and 'G' for
60 // current sources
61 return a == b
62 || SIM_MODEL::DeviceInfo( a ).description == SIM_MODEL::DeviceInfo( b ).description;
63};
64
65
66template <typename T>
67DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, T& aSymbol,
68 std::vector<SCH_FIELD>& aFields ) :
69 DIALOG_SIM_MODEL_BASE( aParent ),
70 m_frame( aFrame ),
71 m_symbol( aSymbol ),
72 m_fields( aFields ),
75 m_prevModel( nullptr ),
77 m_scintillaTricksCode( nullptr ),
78 m_scintillaTricksSubckt( nullptr ),
79 m_firstCategory( nullptr ),
80 m_prevParamGridSelection( nullptr ),
82{
84 m_infoBar->AddCloseButton();
85
86 if constexpr (std::is_same_v<T, SCH_SYMBOL>)
87 {
88 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( &aSymbol );
89 m_filesStack.push_back( symbol->Schematic()->GetEmbeddedFiles() );
90 }
91
92 if( EMBEDDED_FILES* symbolEmbeddedFiles = aSymbol.GetEmbeddedFiles() )
93 {
94 m_filesStack.push_back( symbolEmbeddedFiles );
95
96 if constexpr (std::is_same_v<T, SCH_SYMBOL>)
97 {
98 SCH_SYMBOL* symbol = static_cast<SCH_SYMBOL*>( &aSymbol );
99 symbol->GetLibSymbolRef()->AppendParentEmbeddedFiles( m_filesStack );
100 }
101 else if constexpr (std::is_same_v<T, LIB_SYMBOL>)
102 {
103 LIB_SYMBOL* symbol = static_cast<LIB_SYMBOL*>( &aSymbol );
105 }
106 }
107
108 m_libraryModelsMgr.SetFilesStack( m_filesStack );
109 m_builtinModelsMgr.SetFilesStack( m_filesStack );
110
111 for( SCH_PIN* pin : aSymbol.GetPins() )
112 {
113 // Body styles (including De Morgan variants) are equivalences, not additional items to simulate
114 if( !pin->GetParentSymbol()->IsMultiBodyStyle() || pin->GetBodyStyle() < 2 )
115 m_sortedPartPins.push_back( pin );
116 }
117
118 std::sort( m_sortedPartPins.begin(), m_sortedPartPins.end(),
119 []( const SCH_PIN* lhs, const SCH_PIN* rhs )
120 {
121 // We sort by StrNumCmp because SIM_MODEL_BASE sorts with it too.
122 return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
123 } );
124
125 m_waveformChoice->Clear();
126 m_deviceChoice->Clear();
127 m_deviceSubtypeChoice->Clear();
128
129 m_scintillaTricksCode = new SCINTILLA_TRICKS( m_codePreview, wxT( "{}" ), false );
130 m_scintillaTricksSubckt = new SCINTILLA_TRICKS( m_subckt, wxT( "()" ), false );
131
132 m_paramGridMgr->Bind( wxEVT_PG_SELECTED, &DIALOG_SIM_MODEL::onParamGridSelectionChange, this );
133
134 wxPropertyGrid* grid = m_paramGrid->GetGrid();
135 grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
136 grid->Bind( wxEVT_SET_FOCUS, &DIALOG_SIM_MODEL::onParamGridSetFocus, this );
137 grid->Bind( wxEVT_UPDATE_UI, &DIALOG_SIM_MODEL::onUpdateUI, this );
138
139 grid->DedicateKey( WXK_RETURN );
140 grid->DedicateKey( WXK_NUMPAD_ENTER );
141 grid->DedicateKey( WXK_UP );
142 grid->DedicateKey( WXK_DOWN );
143
144#if wxCHECK_VERSION( 3, 3, 0 )
145 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_RETURN );
146 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_RETURN );
147 grid->AddActionTrigger( wxPGKeyboardAction::Edit, WXK_NUMPAD_ENTER );
148 grid->AddActionTrigger( wxPGKeyboardAction::NextProperty, WXK_NUMPAD_ENTER );
149#else
150 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
151 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
152 grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_NUMPAD_ENTER );
153 grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_NUMPAD_ENTER );
154#endif
155
156 m_pinAssignmentsGrid->ClearRows();
157 m_pinAssignmentsGrid->PushEventHandler( new GRID_TRICKS( m_pinAssignmentsGrid ) );
158
159 m_subcktLabel->SetFont( KIUI::GetStatusFont( m_subcktLabel ) );
160 finishDialogSettings();
161}
162
163
164template <typename T>
166{
167 // Disable all properties. This is necessary because some of their methods are called after
168 // destruction of DIALOG_SIM_MODEL, oddly. When disabled, they never access their models.
169 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
170 {
171 if( SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it ) )
172 prop->Disable();
173 }
174
175 // Delete the GRID_TRICKS.
176 m_pinAssignmentsGrid->PopEventHandler( true );
177
180}
181
182
183template <typename T>
185{
186 wxCommandEvent dummyEvent;
187 wxString deviceType;
188 wxString modelType;
189 wxString modelParams;
190 wxString pinMap;
191 bool storeInValue = false;
192
193 WX_STRING_REPORTER reporter;
194
195 // Infer RLC and VI models if they aren't specified
197 &deviceType, &modelType, &modelParams, &pinMap ) )
198 {
199 SetFieldValue( m_fields, SIM_DEVICE_FIELD, deviceType.ToStdString() );
200
201 if( !modelType.IsEmpty() )
202 SetFieldValue( m_fields, SIM_DEVICE_SUBTYPE_FIELD, modelType.ToStdString() );
203
204 SetFieldValue( m_fields, SIM_PARAMS_FIELD, modelParams.ToStdString() );
205
206 SetFieldValue( m_fields, SIM_PINS_FIELD, pinMap.ToStdString() );
207
208 storeInValue = true;
209
210 // In case the storeInValue checkbox is turned off (if it's left on then we'll overwrite
211 // this field with the actual value):
212 FindField( m_fields, FIELD_T::VALUE )->SetText( wxT( "${SIM.PARAMS}" ) );
213 }
214
215 wxString libraryFilename = GetFieldValue( &m_fields, SIM_LIBRARY::LIBRARY_FIELD, true, 0 );
216 wxFileName tmp( libraryFilename );
217
218 if( !tmp.GetFullName().IsEmpty() )
219 {
220 // The model is sourced from a library, optionally with instance overrides.
221 m_rbLibraryModel->SetValue( true );
222
223 if( !loadLibrary( libraryFilename, reporter ) )
224 {
225 if( reporter.HasMessage() )
226 m_infoBar->ShowMessage( reporter.GetMessages() );
227
228 m_libraryPathText->ChangeValue( libraryFilename );
230
231 m_libraryModelsMgr.CreateModel( nullptr, m_sortedPartPins, m_fields, true, 0, reporter );
232
233 m_modelListBox->Clear();
234 m_modelListBox->Append( _( "<unknown>" ) );
235 m_modelListBox->SetSelection( 0 );
236 }
237 else
238 {
239 std::string modelName = GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD, true, 0 );
240 int modelIdx = m_modelListBox->FindString( modelName );
241
242 if( modelIdx == wxNOT_FOUND )
243 {
244 m_infoBar->ShowMessage( wxString::Format( _( "No model named '%s' in library." ),
245 modelName ) );
246
247 // Default to first item in library if any exist
248 if( m_modelListBox->GetCount() > 0 )
249 m_modelListBox->SetSelection( 0 );
250 }
251 else
252 {
253 m_infoBar->Hide();
254 m_modelListBox->SetSelection( modelIdx );
255 }
256
257 m_curModelType = curModel().GetType();
258 }
259
260 if( isIbisLoaded() && ( m_modelListBox->GetSelection() >= 0 ) )
261 {
262 int idx = 0;
263 wxString sel = m_modelListBox->GetStringSelection();
264
265 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
266 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
267
268 SIM_MODEL_IBIS* ibismodel = dynamic_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels()[idx].get() );
269
270 if( ibismodel )
271 {
272 onModelNameChoice( dummyEvent ); // refresh list of pins
273
274 int i = 0;
275
276 for( const std::pair<std::string, std::string>& strs : ibismodel->GetIbisPins() )
277 {
278 if( strs.first == GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::PIN_FIELD, true, 0 ) )
279 {
280 auto ibisLibrary = static_cast<const SIM_LIBRARY_IBIS*>( library() );
281
282 ibismodel->ChangePin( *ibisLibrary, strs.first );
283 m_pinCombobox->SetSelection( static_cast<int>( i ) );
284 break;
285 }
286 i++;
287 }
288
289 if( i < static_cast<int>( ibismodel->GetIbisPins().size() ) )
290 {
291 onPinCombobox( dummyEvent ); // refresh list of models
292
293 wxString ibisModel = GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::MODEL_FIELD, true, 0 );
294 m_pinModelCombobox->SetStringSelection( ibisModel );
295 }
296
297 if( GetFieldValue( &m_fields, SIM_LIBRARY_IBIS::DIFF_FIELD, true, 0 ) == "1" )
298 {
299 ibismodel->SwitchSingleEndedDiff( true );
300 m_differentialCheckbox->SetValue( true );
301 }
302 else
303 {
304 ibismodel->SwitchSingleEndedDiff( false );
305 m_differentialCheckbox->SetValue( false );
306 }
307 }
308 }
309 }
310 else if( !GetFieldValue( &m_fields, SIM_DEVICE_FIELD, false, 0 ).empty()
312 {
313 // The model is sourced from the instance.
314 m_rbBuiltinModel->SetValue( true );
315
316 reporter.Clear();
318
319 if( reporter.HasMessage() )
320 DisplayErrorMessage( this, reporter.GetMessages() );
321 }
322
323 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
324 {
325 if( m_rbBuiltinModel->GetValue() && type == m_curModelType )
326 {
327 reporter.Clear();
328 m_builtinModelsMgr.CreateModel( m_fields, true, 0, m_sortedPartPins, reporter );
329
330 if( reporter.HasMessage() )
331 {
332 DisplayErrorMessage( this, _( "Failed to read simulation model from fields." )
333 + wxT( "\n\n" ) + reporter.GetMessages() );
334 }
335 }
336 else
337 {
338 m_builtinModelsMgr.CreateModel( type, m_sortedPartPins, reporter );
339 }
340
341 SIM_MODEL::DEVICE_T deviceTypeT = SIM_MODEL::TypeInfo( type ).deviceType;
342
343 if( !m_curModelTypeOfDeviceType.count( deviceTypeT ) )
344 m_curModelTypeOfDeviceType[deviceTypeT] = type;
345 }
346
347 if( storeInValue )
348 curModel().SetIsStoredInValue( true );
349
350 m_saveInValueCheckbox->SetValue( curModel().IsStoredInValue() );
351
352 onRadioButton( dummyEvent );
353 return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
354}
355
356
357template <typename T>
359{
360 if( !m_pinAssignmentsGrid->CommitPendingChanges() )
361 return false;
362
363 if( !m_paramGrid->GetGrid()->CommitChangesFromEditor() )
364 return false;
365
366 if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
367 return false;
368
370 std::string path;
371 std::string name;
372
373 if( m_rbLibraryModel->GetValue() )
374 {
375 path = m_libraryPathText->GetValue();
376 wxFileName fn( path );
377
378 if( !path.starts_with( FILEEXT::KiCadUriPrefix ) && fn.MakeRelativeTo( Prj().GetProjectPath() )
379 && !fn.GetFullPath().StartsWith( ".." ) )
380 {
381 path = fn.GetFullPath();
382 }
383
384 if( m_modelListBox->GetSelection() >= 0 )
385 name = m_modelListBox->GetStringSelection().ToStdString();
386 else if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( &model ) )
388 }
389
392
393 if( isIbisLoaded() && !m_libraryModelsMgr.GetModels().empty() )
394 {
395 int idx = 0;
396 wxString sel = m_modelListBox->GetStringSelection();
397
398 if( m_modelListBoxEntryToLibraryIdx.contains( sel ) )
399 idx = m_modelListBoxEntryToLibraryIdx.at( sel );
400
401 auto* ibismodel =
402 static_cast<SIM_MODEL_IBIS*>( &m_libraryModelsMgr.GetModels().at( idx ).get() );
403
404 if( ibismodel )
405 {
406 std::string pins;
407 std::string modelName = std::string( m_pinModelCombobox->GetValue().c_str() );
408 std::string differential;
409
410 if( m_pinCombobox->GetSelection() >= 0 )
411 pins = ibismodel->GetIbisPins().at( m_pinCombobox->GetSelection() ).first;
412
413 if( ibismodel->CanDifferential() && m_differentialCheckbox->GetValue() )
414 differential = "1";
415
419 }
420 }
421
422 if( model.GetType() == SIM_MODEL::TYPE::RAWSPICE )
423 {
424 if( m_modelNotebook->GetSelection() == 0 )
426
427 wxString code = m_codePreview->GetText().Trim( true ).Trim( false );
428 model.SetParamValue( "model", std::string( code.ToUTF8() ) );
429 }
430
431 model.SetIsStoredInValue( m_saveInValueCheckbox->GetValue() );
432
433 for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
434 {
435 wxString modelPinName = m_pinAssignmentsGrid->GetCellValue( row, PIN_COLUMN::MODEL );
436 wxString symbolPinName = m_sortedPartPins.at( row )->GetShownNumber();
437
438 model.AssignSymbolPinNumberToModelPin( getModelPinIndex( modelPinName ),
439 std::string( symbolPinName.ToUTF8() ) );
440 }
441
443
444 curModel().WriteFields( m_fields );
445
446 return true;
447}
448
449
450template <typename T>
452{
453 // always enable the library browser button -- it makes for fewer clicks if the user has a
454 // whole bunch of inferred passives that they want to specify library models for
455 m_browseButton->Enable();
456
457 // if we're in an undetermined state then enable everything for faster access
458 bool undetermined = !m_rbLibraryModel->GetValue() && !m_rbBuiltinModel->GetValue();
459 bool enableLibCtrls = m_rbLibraryModel->GetValue() || undetermined;
460 bool enableBuiltinCtrls = m_rbBuiltinModel->GetValue() || undetermined;
461
462 m_pathLabel->Enable( enableLibCtrls );
463 m_libraryPathText->Enable( enableLibCtrls );
464 m_modelNameLabel->Enable( enableLibCtrls );
465 m_modelFilter->Enable( enableLibCtrls && !isIbisLoaded() );
466 m_modelListBox->Enable( enableLibCtrls );
467 m_pinLabel->Enable( enableLibCtrls );
468 m_pinCombobox->Enable( enableLibCtrls );
469 m_differentialCheckbox->Enable( enableLibCtrls );
470 m_pinModelLabel->Enable( enableLibCtrls );
471 m_pinModelCombobox->Enable( enableLibCtrls );
472 m_waveformLabel->Enable( enableLibCtrls );
473 m_waveformChoice->Enable( enableLibCtrls );
474
475 m_deviceLabel->Enable( enableBuiltinCtrls );
476 m_deviceChoice->Enable( enableBuiltinCtrls );
477 m_deviceSubtypeLabel->Enable( enableBuiltinCtrls );
478 m_deviceSubtypeChoice->Enable( enableBuiltinCtrls );
479
481
486 updatePinAssignments( model, false );
487
488 std::string ref = GetFieldValue( &m_fields, SIM_REFERENCE_FIELD, false, 0 );
489
490 m_modelPanel->Layout();
491 m_pinAssignmentsPanel->Layout();
492 m_parametersPanel->Layout();
493 m_codePanel->Layout();
494
495 SendSizeEvent( wxSEND_EVENT_POST );
496
498}
499
500
501template <typename T>
503{
504 SIM_MODEL_IBIS* modelibis = isIbisLoaded() ? dynamic_cast<SIM_MODEL_IBIS*>( aModel ) : nullptr;
505
506 m_pinLabel->Show( isIbisLoaded() );
507 m_pinCombobox->Show( isIbisLoaded() );
508 m_pinModelLabel->Show( isIbisLoaded() );
510 m_waveformLabel->Show( isIbisLoaded() );
512
513 if( aModel != m_prevModel )
514 {
515 m_waveformChoice->Clear();
516
517 if( isIbisLoaded() )
518 {
519 for( SIM_MODEL::TYPE type : { SIM_MODEL::TYPE::KIBIS_DEVICE,
520 SIM_MODEL::TYPE::KIBIS_DRIVER_DC,
521 SIM_MODEL::TYPE::KIBIS_DRIVER_RECT,
522 SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS } )
523 {
524 SIM_MODEL::DEVICE_T deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
525 const std::string& deviceTypeDesc = SIM_MODEL::DeviceInfo( deviceType ).description;
526
527 if( deviceType == aModel->GetDeviceType()
528 || deviceTypeDesc == aModel->GetDeviceInfo().description )
529 {
530 m_waveformChoice->Append( SIM_MODEL::TypeInfo( type ).description );
531
532 if( type == aModel->GetType() )
533 m_waveformChoice->SetSelection( m_waveformChoice->GetCount() - 1 );
534 }
535 }
536 }
537 }
538
539 m_differentialCheckbox->Show( isIbisLoaded() && modelibis && modelibis->CanDifferential() );
540 m_modelNameLabel->SetLabel( isIbisLoaded() ? _( "Component:" ) : _( "Model:" ) );
541}
542
543
544template <typename T>
546{
547 // Change the Type choice to match the current device type.
548 if( aModel != m_prevModel )
549 {
550 m_deviceChoice->Clear();
551 m_deviceSubtypeChoice->Clear();
552
553 if( !m_rbLibraryModel->GetValue() )
554 {
555 for( SIM_MODEL::DEVICE_T deviceType : SIM_MODEL::DEVICE_T_ITERATOR() )
556 {
557 if( !SIM_MODEL::DeviceInfo( deviceType ).showInMenu )
558 continue;
559
560 m_deviceChoice->Append( SIM_MODEL::DeviceInfo( deviceType ).description );
561
562 if( equivalent( deviceType, aModel->GetDeviceType() ) )
563 m_deviceChoice->SetSelection( m_deviceChoice->GetCount() - 1 );
564 }
565
566 for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
567 {
568 if( type == SIM_MODEL::TYPE::KIBIS_DEVICE
569 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
570 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
571 || type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS )
572 {
573 continue;
574 }
575
576 SIM_MODEL::DEVICE_T deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
577 const std::string& deviceTypeDesc = SIM_MODEL::DeviceInfo( deviceType ).description;
578
579 if( deviceType == aModel->GetDeviceType()
580 || deviceTypeDesc == aModel->GetDeviceInfo().description )
581 {
582 m_deviceSubtypeChoice->Append( SIM_MODEL::TypeInfo( type ).description );
583
584 if( type == aModel->GetType() )
585 m_deviceSubtypeChoice->SetSelection( m_deviceSubtypeChoice->GetCount() - 1 );
586 }
587 }
588 }
589
590 m_deviceSubtypeLabel->Show( m_deviceSubtypeChoice->GetCount() > 1 );
591 m_deviceSubtypeChoice->Show( m_deviceSubtypeChoice->GetCount() > 1 );
592 }
593
594 if( dynamic_cast<SIM_MODEL_RAW_SPICE*>( aModel ) )
595 m_modelNotebook->SetSelection( 1 );
596 else
597 m_modelNotebook->SetSelection( 0 );
598
599 if( aModel->HasPrimaryValue() )
600 {
601 const SIM_MODEL::PARAM& primary = aModel->GetParam( 0 );
602
603 m_saveInValueCheckbox->SetLabel( wxString::Format( _( "Save parameter '%s (%s)' in Value "
604 "field" ),
605 primary.info.description,
606 primary.info.name ) );
607 m_saveInValueCheckbox->Enable( true );
608 }
609 else
610 {
611 m_saveInValueCheckbox->SetLabel( _( "Save primary parameter in Value field" ) );
612 m_saveInValueCheckbox->SetValue( false );
613 m_saveInValueCheckbox->Enable( false );
614 }
615}
616
617
618template <typename T>
620{
621 if( aModel != m_prevModel )
622 {
623 // This wxPropertyGridManager column and header stuff has to be here because it segfaults in
624 // the constructor.
625
626 m_paramGridMgr->SetColumnCount( PARAM_COLUMN::END_ );
627
628 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DESCRIPTION, _( "Parameter" ) );
629 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::UNIT, _( "Unit" ) );
630 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::DEFAULT, _( "Default" ) );
631 m_paramGridMgr->SetColumnTitle( PARAM_COLUMN::TYPE, _( "Type" ) );
632
633 m_paramGridMgr->ShowHeader();
634
635
636 m_paramGrid->Clear();
637
638 m_firstCategory = m_paramGrid->Append( new wxPropertyCategory( "Geometry" ) );
639 m_paramGrid->HideProperty( "Geometry" );
640
641 m_paramGrid->Append( new wxPropertyCategory( "AC" ) );
642 m_paramGrid->HideProperty( "AC" );
643
644 m_paramGrid->Append( new wxPropertyCategory( "DC" ) );
645 m_paramGrid->HideProperty( "DC" );
646
647 m_paramGrid->Append( new wxPropertyCategory( "S-Parameters" ) );
648 m_paramGrid->HideProperty( "S-Parameters" );
649
650 m_paramGrid->Append( new wxPropertyCategory( "Capacitance" ) );
651 m_paramGrid->HideProperty( "Capacitance" );
652
653 m_paramGrid->Append( new wxPropertyCategory( "Temperature" ) );
654 m_paramGrid->HideProperty( "Temperature" );
655
656 m_paramGrid->Append( new wxPropertyCategory( "Noise" ) );
657 m_paramGrid->HideProperty( "Noise" );
658
659 m_paramGrid->Append( new wxPropertyCategory( "Distributed Quantities" ) );
660 m_paramGrid->HideProperty( "Distributed Quantities" );
661
662 m_paramGrid->Append( new wxPropertyCategory( "Waveform" ) );
663 m_paramGrid->HideProperty( "Waveform" );
664
665 m_paramGrid->Append( new wxPropertyCategory( "Limiting Values" ) );
666 m_paramGrid->HideProperty( "Limiting Values" );
667
668 m_paramGrid->Append( new wxPropertyCategory( "Advanced" ) );
669 m_paramGrid->HideProperty( "Advanced" );
670
671 m_paramGrid->Append( new wxPropertyCategory( "Flags" ) );
672 m_paramGrid->HideProperty( "Flags" );
673
674 m_paramGrid->CollapseAll();
675
676 for( int i = 0; i < aModel->GetParamCount(); ++i )
677 addParamPropertyIfRelevant( aModel, i );
678
679 m_paramGrid->CollapseAll();
680 m_paramGrid->Expand( "AC" );
681 m_paramGrid->Expand( "Waveform" );
682 }
683
684 adjustParamGridColumns( m_paramGrid->GetGrid()->GetSize().GetX(), true );
685
686 // Set all properties to default colors.
687 // Update properties in models that have autofill.
688 for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
689 {
690 wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
691 wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
692
693 for( int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
694 {
695 ( *it )->GetCell( col ).SetBgCol( bgCol );
696 ( *it )->GetCell( col ).SetFgCol( fgCol );
697 }
698
699 SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it );
700
701 if( !prop )
702 continue;
703
704 const SIM_MODEL::PARAM& param = prop->GetParam();
705
706 // Model values other than the currently edited value may have changed. Update them.
707 // This feature is called "autofill" and present only in certain models. Don't do it for
708 // models that don't have it for performance reasons.
709 if( aModel->HasAutofill() )
710 ( *it )->SetValueFromString( param.value );
711 }
712}
713
714
715template <typename T>
717{
718 if( dynamic_cast<SIM_MODEL_SPICE_FALLBACK*>( aModel ) )
719 return;
720
721 wxString text;
722 SPICE_ITEM item;
723
724 item.modelName = m_modelListBox->GetStringSelection();
725
726 if( m_rbBuiltinModel->GetValue() || item.modelName == "" )
728
729 text << aModel->SpiceGenerator().Preview( item );
730
731 m_codePreview->SetText( text );
732 m_codePreview->SelectNone();
733}
734
735
736template <typename T>
737void DIALOG_SIM_MODEL<T>::updatePinAssignments( SIM_MODEL* aModel, bool aForceRefreshFromModel )
738{
739 if( m_pinAssignmentsGrid->GetNumberRows() == 0 )
740 {
741 m_pinAssignmentsGrid->AppendRows( (int) m_sortedPartPins.size() );
742
743 for( int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
744 {
745 wxString symbolPinString = getSymbolPinString( ii );
746
747 m_pinAssignmentsGrid->SetReadOnly( ii, PIN_COLUMN::SYMBOL );
748 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::SYMBOL, symbolPinString );
749 }
750
751 aForceRefreshFromModel = true;
752 }
753
754 if( aForceRefreshFromModel )
755 {
756 // Reset the grid.
757 for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
758 m_pinAssignmentsGrid->SetCellValue( row, PIN_COLUMN::MODEL, _( "Not Connected" ) );
759
760 // Now set up the grid values in the Model column.
761 for( int modelPinIndex = 0; modelPinIndex < aModel->GetPinCount(); ++modelPinIndex )
762 {
763 wxString symbolPinNumber = aModel->GetPin( modelPinIndex ).symbolPinNumber;
764
765 if( symbolPinNumber == "" )
766 continue;
767
768 int symbolPinRow = findSymbolPinRow( symbolPinNumber );
769
770 if( symbolPinRow == -1 )
771 continue;
772
773 wxString modelPinString = getModelPinString( aModel, modelPinIndex );
774 m_pinAssignmentsGrid->SetCellValue( symbolPinRow, PIN_COLUMN::MODEL, modelPinString );
775 }
776 }
777
778 for( int ii = 0; ii < m_pinAssignmentsGrid->GetNumberRows(); ++ii )
779 {
780 // Set up the Model column cell editors with dropdown options.
781 std::vector<BITMAPS> modelPinIcons;
782 wxArrayString modelPinChoices;
783
784 for( int jj = 0; jj < aModel->GetPinCount(); ++jj )
785 {
786 if( aModel->GetPin( jj ).symbolPinNumber != "" )
787 modelPinIcons.push_back( PinShapeGetBitmap( GRAPHIC_PINSHAPE::LINE ) );
788 else
789 modelPinIcons.push_back( BITMAPS::INVALID_BITMAP );
790
791 modelPinChoices.Add( getModelPinString( aModel, jj ) );
792 }
793
794 modelPinIcons.push_back( BITMAPS::INVALID_BITMAP );
795 modelPinChoices.Add( _( "Not Connected" ) );
796
797 // This is not a memory leak; `SetCellEditor()` calls `DecRef()` on its previous editor.
798 m_pinAssignmentsGrid->SetCellEditor( ii, PIN_COLUMN::MODEL,
799 new GRID_CELL_ICON_TEXT_POPUP( modelPinIcons, modelPinChoices ) );
800
801 // Assignment stays the same, but model pin names need to be updated
802 int modelPinIndex = getModelPinIndex( m_pinAssignmentsGrid->GetCellValue( ii, PIN_COLUMN::MODEL ) );
803
804 if( modelPinIndex >= 0 )
805 m_pinAssignmentsGrid->SetCellValue( ii, PIN_COLUMN::MODEL, getModelPinString( aModel, modelPinIndex ) );
806 }
807
808 // TODO: Show a preview of the symbol with the pin numbers shown.
809
810 if( aModel->GetType() == SIM_MODEL::TYPE::SUBCKT )
811 {
812 SIM_MODEL_SUBCKT* subckt = static_cast<SIM_MODEL_SUBCKT*>( aModel );
813 m_subckt->SetText( subckt->GetSpiceCode() );
814 m_subckt->SetEditable( false );
815 }
816 else
817 {
818 m_subcktLabel->Show( false );
819 m_subckt->Show( false );
820 }
821}
822
823
824template <typename T>
826{
827 for( int i = 0; i < aModel->GetPinCount(); ++i )
828 {
829 if( !m_symbol.GetPin( aModel->GetPin( i ).symbolPinNumber ) )
830 aModel->AssignSymbolPinNumberToModelPin( i, "" );
831 }
832}
833
834
835template <typename T>
836bool DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aLibraryPath, REPORTER& aReporter, bool aForceReload )
837{
838 if( m_prevLibrary == aLibraryPath && !aForceReload )
839 return true;
840
841 m_libraryModelsMgr.SetForceFullParse();
842 m_libraryModelsMgr.SetLibrary( aLibraryPath, aReporter );
843 m_libraryPathText->ChangeValue( aLibraryPath );
845
847 {
848 m_libraryModelsMgr.Clear();
849
850 if( m_modelListBox->GetSelection() != wxNOT_FOUND )
851 m_modelListBox->SetSelection( wxNOT_FOUND );
852
853 if( m_modelListBox->GetCount() )
854 m_modelListBox->Clear();
855
856 wxArrayString emptyArray;
857 m_pinModelCombobox->Set( emptyArray );
858 m_pinCombobox->Set( emptyArray );
859 m_pinModelCombobox->SetSelection( -1 );
860 m_pinCombobox->SetSelection( -1 );
861 m_waveformChoice->Clear();
862 m_prevLibrary.Clear();
863
864 return false;
865 }
866
867 std::string modelName = GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD, true, 0 );
868
869 for( const auto& [baseModelName, baseModel] : library()->GetModels() )
870 {
871 if( baseModelName == modelName )
872 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, m_fields, true, 0, aReporter );
873 else
874 m_libraryModelsMgr.CreateModel( &baseModel, m_sortedPartPins, aReporter );
875 }
876
877 m_rbLibraryModel->SetValue( true );
878
879 wxArrayString modelNames;
880
881 bool modelNameExists = false;
882 for( const auto& [name, model] : library()->GetModels() )
883 {
884 modelNames.Add( name );
886
887 if( name == modelName )
888 modelNameExists = true;
889 }
890
891 modelNames.Sort();
892
893 m_modelListBox->Clear();
894 m_modelListBox->Append( modelNames );
895
896 if( !modelNameExists )
897 {
898 m_infoBar->ShowMessage( wxString::Format( _( "No model named '%s' in '%s'." ),
899 modelName,
900 aLibraryPath ) );
901 return false;
902 }
903
904 if( isIbisLoaded() )
905 {
906 wxArrayString emptyArray;
907 m_pinModelCombobox->Set( emptyArray );
908 m_pinCombobox->Set( emptyArray );
909 m_pinModelCombobox->SetSelection( -1 );
910 m_pinCombobox->SetSelection( -1 );
911 }
912
913 m_modelListBox->SetStringSelection( modelName );
914
915 if( m_modelListBox->GetSelection() < 0 && m_modelListBox->GetCount() > 0 )
916 m_modelListBox->SetSelection( 0 );
917
918 m_curModelType = curModel().GetType();
919
920 m_prevLibrary = aLibraryPath;
921 return true;
922}
923
924
925template <typename T>
927{
928 if( aModel->GetParam( aParamIndex ).info.dir == SIM_MODEL::PARAM::DIR_OUT )
929 return;
930
931 switch( aModel->GetParam( aParamIndex ).info.category )
932 {
933 case CATEGORY::AC:
934 m_paramGrid->HideProperty( "AC", false );
935 m_paramGrid->AppendIn( "AC", newParamProperty( aModel, aParamIndex ) );
936 break;
937
938 case CATEGORY::DC:
939 m_paramGrid->HideProperty( "DC", false );
940 m_paramGrid->AppendIn( "DC", newParamProperty( aModel, aParamIndex ) );
941 break;
942
943 case CATEGORY::S_PARAM:
944 m_paramGrid->HideProperty( "S-Parameters", false );
945 m_paramGrid->AppendIn( "S-Parameters", newParamProperty( aModel, aParamIndex ) );
946 break;
947
948 case CATEGORY::CAPACITANCE:
949 m_paramGrid->HideProperty( "Capacitance", false );
950 m_paramGrid->AppendIn( "Capacitance", newParamProperty( aModel, aParamIndex ) );
951 break;
952
953 case CATEGORY::TEMPERATURE:
954 m_paramGrid->HideProperty( "Temperature", false );
955 m_paramGrid->AppendIn( "Temperature", newParamProperty( aModel, aParamIndex ) );
956 break;
957
958 case CATEGORY::NOISE:
959 m_paramGrid->HideProperty( "Noise", false );
960 m_paramGrid->AppendIn( "Noise", newParamProperty( aModel, aParamIndex ) );
961 break;
962
963 case CATEGORY::DISTRIBUTED_QUANTITIES:
964 m_paramGrid->HideProperty( "Distributed Quantities", false );
965 m_paramGrid->AppendIn( "Distributed Quantities", newParamProperty( aModel, aParamIndex ) );
966 break;
967
968 case CATEGORY::WAVEFORM:
969 m_paramGrid->HideProperty( "Waveform", false );
970 m_paramGrid->AppendIn( "Waveform", newParamProperty( aModel, aParamIndex ) );
971 break;
972
973 case CATEGORY::GEOMETRY:
974 m_paramGrid->HideProperty( "Geometry", false );
975 m_paramGrid->AppendIn( "Geometry", newParamProperty( aModel, aParamIndex ) );
976 break;
977
978 case CATEGORY::LIMITING_VALUES:
979 m_paramGrid->HideProperty( "Limiting Values", false );
980 m_paramGrid->AppendIn( "Limiting Values", newParamProperty( aModel, aParamIndex ) );
981 break;
982
983 case CATEGORY::ADVANCED:
984 m_paramGrid->HideProperty( "Advanced", false );
985 m_paramGrid->AppendIn( "Advanced", newParamProperty( aModel, aParamIndex ) );
986 break;
987
988 case CATEGORY::FLAGS:
989 m_paramGrid->HideProperty( "Flags", false );
990 m_paramGrid->AppendIn( "Flags", newParamProperty( aModel, aParamIndex ) );
991 break;
992
993 default:
994 m_paramGrid->Insert( m_firstCategory, newParamProperty( aModel, aParamIndex ) );
995 break;
996
997 case CATEGORY::INITIAL_CONDITIONS:
998 case CATEGORY::SUPERFLUOUS:
999 return;
1000 }
1001}
1002
1003
1004template <typename T>
1005wxPGProperty* DIALOG_SIM_MODEL<T>::newParamProperty( SIM_MODEL* aModel, int aParamIndex ) const
1006{
1007 const SIM_MODEL::PARAM& param = aModel->GetParam( aParamIndex );
1008 wxString paramDescription;
1009
1010 if( param.info.description == "" )
1011 paramDescription = wxString::Format( "%s", param.info.name );
1012 else
1013 paramDescription = wxString::Format( "%s (%s)", param.info.description, param.info.name );
1014
1015 wxPGProperty* prop = nullptr;
1016
1017 switch( param.info.type )
1018 {
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:177
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:254
const wxString & GetShownNumber() const
Definition sch_pin.cpp:592
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:61
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:642
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:435
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.