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