2016-08-11 12:41:40 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-02-09 00:45:04 +00:00
|
|
|
* Copyright (C) 2022 Mikolaj Wielgus
|
|
|
|
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-08-11 12:41:40 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2016-08-11 12:41:43 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2016-08-11 12:41:40 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
2016-08-11 12:41:43 +00:00
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
2016-08-11 12:41:40 +00:00
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <dialog_sim_model.h>
|
2022-03-09 01:40:59 +00:00
|
|
|
#include <sim/sim_property.h>
|
2022-09-27 20:47:00 +00:00
|
|
|
#include <sim/sim_library_kibis.h>
|
2022-04-01 04:30:50 +00:00
|
|
|
#include <sim/sim_library_spice.h>
|
2022-09-27 20:47:00 +00:00
|
|
|
#include <sim/sim_model_kibis.h>
|
2022-09-18 05:25:56 +00:00
|
|
|
#include <sim/sim_model_raw_spice.h>
|
2022-03-09 01:40:59 +00:00
|
|
|
#include <widgets/wx_grid.h>
|
|
|
|
#include <kiplatform/ui.h>
|
2016-08-11 12:41:56 +00:00
|
|
|
#include <confirm.h>
|
2022-08-26 01:26:54 +00:00
|
|
|
#include <string_utils.h>
|
2022-03-09 01:40:59 +00:00
|
|
|
#include <locale_io.h>
|
2022-04-01 04:30:50 +00:00
|
|
|
#include <wx/filedlg.h>
|
2022-09-03 12:55:47 +00:00
|
|
|
#include <wx/textfile.h>
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
using CATEGORY = SIM_MODEL::PARAM::CATEGORY;
|
|
|
|
|
2018-09-22 14:05:32 +00:00
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
DIALOG_SIM_MODEL<T>::DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
|
2022-08-28 12:51:03 +00:00
|
|
|
std::vector<T>& aFields )
|
2022-04-12 14:37:06 +00:00
|
|
|
: DIALOG_SIM_MODEL_BASE( aParent ),
|
2022-02-09 00:45:04 +00:00
|
|
|
m_symbol( aSymbol ),
|
2022-02-21 03:58:31 +00:00
|
|
|
m_fields( aFields ),
|
2022-10-04 12:37:24 +00:00
|
|
|
m_library( std::make_shared<SIM_LIBRARY_SPICE>() ),
|
2022-04-01 04:30:50 +00:00
|
|
|
m_prevModel( nullptr ),
|
2022-06-12 03:39:13 +00:00
|
|
|
m_firstCategory( nullptr ),
|
2022-06-21 02:22:52 +00:00
|
|
|
m_prevParamGridSelection( nullptr ),
|
|
|
|
m_wasCodePreviewUpdated( true )
|
2018-09-22 14:05:32 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
m_modelNameCombobox->SetValidator( m_modelNameValidator );
|
2022-06-12 03:39:13 +00:00
|
|
|
m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
|
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
m_sortedSymbolPins = m_symbol.GetLibPins();
|
|
|
|
std::sort( m_sortedSymbolPins.begin(), m_sortedSymbolPins.end(),
|
2022-08-26 01:26:54 +00:00
|
|
|
[]( const LIB_PIN* lhs, const LIB_PIN* rhs )
|
|
|
|
{
|
|
|
|
// We sort by StrNumCmp because SIM_MODEL_BASE sorts with it too.
|
|
|
|
return StrNumCmp( lhs->GetNumber(), rhs->GetNumber(), true ) < 0;
|
|
|
|
} );
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
|
2016-08-11 12:41:40 +00:00
|
|
|
{
|
2022-08-28 12:51:03 +00:00
|
|
|
m_models.push_back( SIM_MODEL::Create( type, m_sortedSymbolPins.size() ) );
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
SIM_MODEL::DEVICE_TYPE_ deviceType = SIM_MODEL::TypeInfo( type ).deviceType;
|
2022-07-30 12:06:51 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
if( !m_curModelTypeOfDeviceType.count( deviceType ) )
|
|
|
|
m_curModelTypeOfDeviceType[deviceType] = type;
|
2022-01-23 17:23:22 +00:00
|
|
|
}
|
2016-08-11 12:41:40 +00:00
|
|
|
|
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
m_typeChoice->Clear();
|
2020-03-23 16:49:21 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
for( SIM_MODEL::DEVICE_TYPE_ deviceType : SIM_MODEL::DEVICE_TYPE__ITERATOR() )
|
2022-02-21 03:58:31 +00:00
|
|
|
m_deviceTypeChoice->Append( SIM_MODEL::DeviceTypeInfo( deviceType ).description );
|
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
m_scintillaTricks = std::make_unique<SCINTILLA_TRICKS>( m_codePreview, wxT( "{}" ), false );
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
m_paramGridMgr->Bind( wxEVT_PG_SELECTED, &DIALOG_SIM_MODEL::onParamGridSelectionChange, this );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
m_paramGrid->SetValidationFailureBehavior( wxPG_VFB_STAY_IN_PROPERTY
|
|
|
|
| wxPG_VFB_BEEP
|
|
|
|
| wxPG_VFB_MARK_CELL );
|
|
|
|
|
|
|
|
m_paramGrid->SetColumnProportion( static_cast<int>( PARAM_COLUMN::DESCRIPTION ), 50 );
|
|
|
|
m_paramGrid->SetColumnProportion( static_cast<int>( PARAM_COLUMN::VALUE ), 18 );
|
|
|
|
m_paramGrid->SetColumnProportion( static_cast<int>( PARAM_COLUMN::UNIT ), 10 );
|
|
|
|
m_paramGrid->SetColumnProportion( static_cast<int>( PARAM_COLUMN::DEFAULT ), 12 );
|
|
|
|
m_paramGrid->SetColumnProportion( static_cast<int>( PARAM_COLUMN::TYPE ), 10 );
|
|
|
|
|
|
|
|
if( wxPropertyGrid* grid = m_paramGrid->GetGrid() )
|
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
//grid->SetCellBackgroundColour( grid->GetPropertyDefaultCell().GetBgCol() );
|
|
|
|
//grid->SetCellTextColour( grid->GetPropertyDefaultCell().GetFgCol();
|
|
|
|
|
|
|
|
// In wx 3.0 the color will be wrong sometimes.
|
|
|
|
grid->SetCellDisabledTextColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
|
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
grid->Bind( wxEVT_SET_FOCUS, &DIALOG_SIM_MODEL::onParamGridSetFocus, this );
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
grid->AddActionTrigger( wxPG_ACTION_EDIT, WXK_RETURN );
|
|
|
|
grid->DedicateKey( WXK_RETURN );
|
|
|
|
grid->AddActionTrigger( wxPG_ACTION_NEXT_PROPERTY, WXK_RETURN );
|
|
|
|
|
|
|
|
grid->DedicateKey( WXK_UP );
|
|
|
|
grid->DedicateKey( WXK_DOWN );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wxFAIL;
|
|
|
|
|
2022-08-02 10:52:22 +00:00
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
|
|
|
finishDialogSettings();
|
2016-08-11 12:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
|
2022-01-23 17:23:22 +00:00
|
|
|
{
|
2022-09-27 20:47:00 +00:00
|
|
|
wxString libraryFilename = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::LIBRARY_FIELD );
|
2022-01-23 17:23:22 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
if( libraryFilename != "" )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
// The model is sourced from a library, optionally with instance overrides.
|
|
|
|
loadLibrary( libraryFilename );
|
2022-01-23 17:23:22 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
// Must be set before curModel() is used since the latter checks the combobox value.
|
2022-04-12 14:37:06 +00:00
|
|
|
m_modelNameCombobox->SetStringSelection(
|
2022-09-27 20:47:00 +00:00
|
|
|
SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD ) );
|
|
|
|
|
2022-10-04 21:47:52 +00:00
|
|
|
if( isIbisLoaded() && ( m_modelNameCombobox->GetSelection() >= 0 ) )
|
2022-09-27 20:47:00 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<SIM_MODEL_KIBIS> kibismodel =
|
|
|
|
std::dynamic_pointer_cast<SIM_MODEL_KIBIS>(
|
|
|
|
m_libraryModels.at( m_modelNameCombobox->GetSelection() ) );
|
|
|
|
|
|
|
|
if( kibismodel )
|
|
|
|
{
|
|
|
|
wxCommandEvent dummyEvent;
|
|
|
|
onModelNameCombobox( dummyEvent ); // refresh list of pins
|
|
|
|
|
2022-10-04 21:47:52 +00:00
|
|
|
int i = 0;
|
2022-09-27 20:47:00 +00:00
|
|
|
|
|
|
|
for( std::pair<std::string, std::string> strs : kibismodel->GetIbisPins() )
|
|
|
|
{
|
|
|
|
if( strs.first
|
|
|
|
== SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY_KIBIS::PIN_FIELD ) )
|
|
|
|
{
|
|
|
|
kibismodel->ChangePin(
|
|
|
|
*( std::dynamic_pointer_cast<SIM_LIBRARY_KIBIS>( m_library ) ),
|
|
|
|
strs.first );
|
2022-10-04 21:47:52 +00:00
|
|
|
m_ibisPinCombobox->SetSelection( static_cast<int>( i ) );
|
2022-09-27 20:47:00 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2022-10-04 21:47:52 +00:00
|
|
|
if( i < static_cast<int>( kibismodel->GetIbisPins().size() ) )
|
2022-09-27 20:47:00 +00:00
|
|
|
{
|
|
|
|
onIbisPinCombobox( dummyEvent ); // refresh list of models
|
|
|
|
|
|
|
|
m_ibisModelCombobox->SetStringSelection(
|
|
|
|
SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY_KIBIS::MODEL_FIELD ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 12:42:09 +00:00
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
else
|
2016-08-11 12:41:40 +00:00
|
|
|
{
|
2022-04-01 04:30:50 +00:00
|
|
|
// The model is sourced from the instance.
|
|
|
|
SIM_MODEL::TYPE type = SIM_MODEL::ReadTypeFromFields( m_fields );
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2022-08-26 01:26:54 +00:00
|
|
|
m_models.at( static_cast<int>( SIM_MODEL::ReadTypeFromFields( m_fields ) ) ) =
|
2022-08-28 12:51:03 +00:00
|
|
|
SIM_MODEL::Create( m_sortedSymbolPins.size(), m_fields );
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
2022-06-21 02:22:52 +00:00
|
|
|
catch( const IO_ERROR& e )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, e.What() );
|
2022-04-12 14:37:06 +00:00
|
|
|
return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_curModelType = type;
|
2016-08-11 12:41:40 +00:00
|
|
|
}
|
2016-08-11 12:41:56 +00:00
|
|
|
|
2022-09-11 13:22:45 +00:00
|
|
|
m_overrideCheckbox->SetValue( curModel().HasNonInstanceOverrides() );
|
2022-10-05 09:24:04 +00:00
|
|
|
m_excludeSymbolCheckbox->SetValue( !curModel().IsEnabled() );
|
2022-09-11 13:22:45 +00:00
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
updateWidgets();
|
2016-08-11 12:41:56 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
|
2016-08-11 12:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
bool DIALOG_SIM_MODEL<T>::TransferDataFromWindow()
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
m_pinAssignmentsGrid->CommitPendingChanges();
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
|
2022-04-01 04:30:50 +00:00
|
|
|
return false;
|
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string modelName;
|
2022-05-31 02:55:48 +00:00
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
modelName = m_modelNameCombobox->GetValue();
|
2022-05-31 02:55:48 +00:00
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY::NAME_FIELD, modelName );
|
2022-05-31 02:55:48 +00:00
|
|
|
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string path;
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-10-04 21:47:52 +00:00
|
|
|
if( m_useLibraryModelRadioButton->GetValue() || isIbisLoaded() )
|
2022-05-31 02:55:48 +00:00
|
|
|
{
|
|
|
|
path = m_library->GetFilePath();
|
2022-04-12 14:37:06 +00:00
|
|
|
wxFileName fn( path );
|
|
|
|
|
|
|
|
if( fn.MakeRelativeTo( Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( ".." ) )
|
|
|
|
path = fn.GetFullPath();
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY::LIBRARY_FIELD, path );
|
|
|
|
|
2022-10-04 21:47:52 +00:00
|
|
|
if( isIbisLoaded() )
|
2022-09-27 20:47:00 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<SIM_MODEL_KIBIS> kibismodel = std::dynamic_pointer_cast<SIM_MODEL_KIBIS>(
|
|
|
|
m_libraryModels.at( m_modelNameCombobox->GetSelection() ) );
|
|
|
|
|
|
|
|
if( kibismodel )
|
|
|
|
|
|
|
|
{
|
|
|
|
SIM_MODEL::SetFieldValue(
|
|
|
|
m_fields, SIM_LIBRARY_KIBIS::PIN_FIELD,
|
|
|
|
kibismodel->GetIbisPins().at( m_ibisPinCombobox->GetSelection() ).first );
|
|
|
|
SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY_KIBIS::MODEL_FIELD,
|
|
|
|
std::string( m_ibisModelCombobox->GetValue().c_str() ) );
|
|
|
|
}
|
|
|
|
}
|
2022-05-31 02:55:48 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
curModel().WriteFields( m_fields );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::updateWidgets()
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-10-04 21:47:52 +00:00
|
|
|
updateIbisWidgets();
|
2022-03-09 01:40:59 +00:00
|
|
|
updateModelParamsTab();
|
|
|
|
updateModelCodeTab();
|
2022-08-28 12:51:03 +00:00
|
|
|
updatePinAssignments();
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-10-04 21:47:52 +00:00
|
|
|
m_modelPanel->Layout();
|
|
|
|
m_pinAssignmentsPanel->Layout();
|
|
|
|
m_parametersPanel->Layout();
|
|
|
|
m_codePanel->Layout();
|
|
|
|
|
|
|
|
SendSizeEvent( wxSEND_EVENT_POST );
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_prevModel = &curModel();
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
|
|
|
|
2022-10-04 21:47:52 +00:00
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::updateIbisWidgets()
|
|
|
|
{
|
|
|
|
m_ibisModelCombobox->Show( isIbisLoaded() );
|
|
|
|
m_ibisPinCombobox->Show( isIbisLoaded() );
|
|
|
|
m_ibisModelLabel->Show( isIbisLoaded() );
|
|
|
|
m_ibisPinLabel->Show( isIbisLoaded() );
|
|
|
|
m_overrideCheckbox->Show( !isIbisLoaded() );
|
|
|
|
|
|
|
|
m_modelNameLabel->SetLabel( isIbisLoaded() ? "Component:" : "Model:" );
|
|
|
|
}
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::updateModelParamsTab()
|
2016-08-11 12:41:40 +00:00
|
|
|
{
|
2022-09-30 12:29:44 +00:00
|
|
|
if( &curModel() != m_prevModel )
|
2016-08-11 12:41:40 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
SIM_MODEL::DEVICE_TYPE_ deviceType = SIM_MODEL::TypeInfo( curModel().GetType() ).deviceType;
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
// Change the Type choice to match the current device type.
|
2022-09-30 12:29:44 +00:00
|
|
|
if( !m_prevModel || deviceType != m_prevModel->GetDeviceType() )
|
2016-08-11 12:41:40 +00:00
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
m_deviceTypeChoice->SetSelection( static_cast<int>( deviceType ) );
|
|
|
|
|
|
|
|
m_typeChoice->Clear();
|
|
|
|
|
|
|
|
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
if( SIM_MODEL::TypeInfo( type ).deviceType == deviceType )
|
|
|
|
{
|
|
|
|
wxString description = SIM_MODEL::TypeInfo( type ).description;
|
2017-10-26 17:54:53 +00:00
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
if( !description.IsEmpty() )
|
|
|
|
m_typeChoice->Append( description );
|
2017-10-26 17:54:53 +00:00
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
if( type == curModel().GetType() )
|
|
|
|
m_typeChoice->SetSelection( m_typeChoice->GetCount() - 1 );
|
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
2016-08-11 12:41:40 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
// This wxPropertyGridManager column and header stuff has to be here because it segfaults in
|
|
|
|
// the constructor.
|
|
|
|
|
|
|
|
m_paramGridMgr->SetColumnCount( static_cast<int>( PARAM_COLUMN::END_ ) );
|
2018-05-03 09:58:13 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGridMgr->SetColumnTitle( static_cast<int>( PARAM_COLUMN::UNIT ), "Unit" );
|
|
|
|
m_paramGridMgr->SetColumnTitle( static_cast<int>( PARAM_COLUMN::DEFAULT ), "Default" );
|
|
|
|
m_paramGridMgr->SetColumnTitle( static_cast<int>( PARAM_COLUMN::TYPE ), "Type" );
|
2017-10-26 17:54:53 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGridMgr->ShowHeader();
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->Clear();
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
m_firstCategory = m_paramGrid->Append( new wxPropertyCategory( "Geometry" ) );
|
|
|
|
m_paramGrid->HideProperty( "Geometry" );
|
|
|
|
|
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "AC" ) );
|
2022-06-12 03:39:13 +00:00
|
|
|
m_paramGrid->HideProperty( "AC" );
|
|
|
|
|
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "DC" ) );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->HideProperty( "DC" );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-05-08 09:54:35 +00:00
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "Capacitance" ) );
|
|
|
|
m_paramGrid->HideProperty( "Capacitance" );
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "Temperature" ) );
|
|
|
|
m_paramGrid->HideProperty( "Temperature" );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "Noise" ) );
|
|
|
|
m_paramGrid->HideProperty( "Noise" );
|
2019-01-10 05:42:14 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "Distributed Quantities" ) );
|
|
|
|
m_paramGrid->HideProperty( "Distributed Quantities" );
|
2019-01-10 05:42:14 +00:00
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "Waveform" ) );
|
|
|
|
m_paramGrid->HideProperty( "Waveform" );
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "Limiting Values" ) );
|
|
|
|
m_paramGrid->HideProperty( "Limiting Values" );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "Advanced" ) );
|
|
|
|
m_paramGrid->HideProperty( "Advanced" );
|
|
|
|
|
|
|
|
m_paramGrid->Append( new wxPropertyCategory( "Flags" ) );
|
|
|
|
m_paramGrid->HideProperty( "Flags" );
|
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
m_paramGrid->CollapseAll();
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
for( int i = 0; i < curModel().GetParamCount(); ++i )
|
2022-04-01 04:30:50 +00:00
|
|
|
addParamPropertyIfRelevant( i );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
|
|
|
m_paramGrid->CollapseAll();
|
|
|
|
m_paramGrid->Expand( "AC" );
|
2022-09-27 20:47:00 +00:00
|
|
|
m_paramGrid->Expand( "Waveform" );
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
// Either enable all properties or disable all except the principal ones.
|
2022-06-21 02:22:52 +00:00
|
|
|
// Set all properties to default colors.
|
2022-04-01 04:30:50 +00:00
|
|
|
for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
|
|
|
|
{
|
2022-09-11 13:22:45 +00:00
|
|
|
SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it );
|
|
|
|
|
|
|
|
if( !prop )
|
2022-04-01 04:30:50 +00:00
|
|
|
continue;
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
|
|
|
|
wxColour fgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetFgCol();
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
for( int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2022-09-11 13:22:45 +00:00
|
|
|
( *it )->GetCell( col ).SetBgCol( bgCol );
|
|
|
|
( *it )->GetCell( col ).SetFgCol( fgCol );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
// Model values other than the currently edited value may have changed. Update them.
|
|
|
|
// This feature is called "autofill" and present only in certain models. Don't do it for
|
|
|
|
// models that don't have it for performance reasons.
|
|
|
|
if( curModel().HasAutofill() )
|
2022-09-11 13:22:45 +00:00
|
|
|
( *it )->SetValueFromString( prop->GetParam().value->ToString() );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
// Most of the values are disabled when the override checkbox is unchecked.
|
2022-09-27 20:47:00 +00:00
|
|
|
( *it )->Enable(
|
2022-10-04 21:47:52 +00:00
|
|
|
( isIbisLoaded() ) || m_useInstanceModelRadioButton->GetValue()
|
2022-09-27 20:47:00 +00:00
|
|
|
|| ( prop->GetParam().info.isInstanceParam
|
|
|
|
&& prop->GetParam().info.category == SIM_MODEL::PARAM::CATEGORY::PRINCIPAL )
|
|
|
|
|| m_overrideCheckbox->GetValue() );
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
2016-08-11 12:41:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::updateModelCodeTab()
|
2016-08-11 12:41:40 +00:00
|
|
|
{
|
2022-10-10 23:23:00 +00:00
|
|
|
SPICE_ITEM item;
|
|
|
|
item.modelName = m_modelNameCombobox->GetStringSelection();
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-10-10 23:23:00 +00:00
|
|
|
if( m_useInstanceModelRadioButton->GetValue() || item.modelName == "" )
|
|
|
|
item.modelName = m_fields.at( REFERENCE_FIELD ).GetText();
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2022-09-03 12:55:47 +00:00
|
|
|
m_codePreview->SetEditable( true ); // ???
|
|
|
|
|
2022-09-18 05:25:56 +00:00
|
|
|
if( dynamic_cast<SIM_MODEL_RAW_SPICE*>( &curModel() ) )
|
2022-09-03 12:55:47 +00:00
|
|
|
{
|
|
|
|
// For raw Spice models display the whole file instead.
|
|
|
|
|
|
|
|
wxString path = curModel().FindParam( "lib" )->value->ToString();
|
|
|
|
wxString absolutePath = Prj().AbsolutePath( path );
|
|
|
|
wxTextFile file;
|
|
|
|
wxString text;
|
|
|
|
|
2022-10-10 23:23:00 +00:00
|
|
|
text << curModel().SpiceGenerator().Preview( item );
|
2022-09-03 12:55:47 +00:00
|
|
|
text << "\n";
|
|
|
|
text << "--- FILE SOURCE (" << path << ") ---\n";
|
|
|
|
text << "\n";
|
|
|
|
|
|
|
|
if( wxFileExists( absolutePath ) && file.Open( absolutePath ) )
|
|
|
|
{
|
|
|
|
for( text << file.GetFirstLine() << "\n";
|
|
|
|
!file.Eof();
|
|
|
|
text << file.GetNextLine() << "\n" )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
file.Close();
|
|
|
|
m_codePreview->SetText( text );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2022-10-10 23:23:00 +00:00
|
|
|
m_codePreview->SetText( curModel().SpiceGenerator().Preview( item ) );
|
2022-09-03 12:55:47 +00:00
|
|
|
|
|
|
|
m_codePreview->SetEditable( false ); // ???
|
2022-06-21 02:22:52 +00:00
|
|
|
m_wasCodePreviewUpdated = true;
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
2016-08-19 15:33:26 +00:00
|
|
|
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
template <typename T>
|
2022-08-28 12:51:03 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::updatePinAssignments()
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-08-28 12:51:03 +00:00
|
|
|
removeOrphanedPinAssignments();
|
|
|
|
|
|
|
|
// Reset the grid.
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
m_pinAssignmentsGrid->ClearRows();
|
2022-08-28 12:51:03 +00:00
|
|
|
m_pinAssignmentsGrid->AppendRows( static_cast<int>( m_sortedSymbolPins.size() ) );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
for( int row = 0; row < m_pinAssignmentsGrid->GetNumberRows(); ++row )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
m_pinAssignmentsGrid->SetCellValue( row, static_cast<int>( PIN_COLUMN::MODEL ),
|
2022-03-09 01:40:59 +00:00
|
|
|
"Not Connected" );
|
|
|
|
}
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
// Now set up the grid values in the Model column.
|
|
|
|
for( int modelPinIndex = 0; modelPinIndex < curModel().GetPinCount(); ++modelPinIndex )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
wxString symbolPinNumber = curModel().GetPin( modelPinIndex ).symbolPinNumber;
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
if( symbolPinNumber == "" )
|
2022-03-09 01:40:59 +00:00
|
|
|
continue;
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
wxString modelPinString = getModelPinString( modelPinIndex );
|
|
|
|
m_pinAssignmentsGrid->SetCellValue( findSymbolPinRow( symbolPinNumber ),
|
2022-03-09 01:40:59 +00:00
|
|
|
static_cast<int>( PIN_COLUMN::MODEL ),
|
|
|
|
modelPinString );
|
|
|
|
}
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
wxArrayString modelPinChoices = getModelPinChoices();
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
// Set up the Symbol column grid values and Model column cell editors with dropdown options.
|
2022-03-09 01:40:59 +00:00
|
|
|
for( int i = 0; i < m_pinAssignmentsGrid->GetNumberRows(); ++i )
|
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
wxString symbolPinString = getSymbolPinString( i );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
m_pinAssignmentsGrid->SetReadOnly( i, static_cast<int>( PIN_COLUMN::SYMBOL ) );
|
|
|
|
m_pinAssignmentsGrid->SetCellValue( i, static_cast<int>( PIN_COLUMN::SYMBOL ),
|
|
|
|
symbolPinString );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
wxString curModelPinString = m_pinAssignmentsGrid->GetCellValue(
|
|
|
|
i, static_cast<int>( PIN_COLUMN::MODEL ) );
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
wxArrayString actualModelPinChoices( modelPinChoices );
|
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
if( curModelPinString != _( "Not Connected" ) )
|
2022-06-21 02:22:52 +00:00
|
|
|
actualModelPinChoices.Insert( curModelPinString, 0 );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
// Using `new` here shouldn't cause a memory leak because `SetCellEditor()` calls
|
|
|
|
// `DecRef()` on its last editor.
|
|
|
|
m_pinAssignmentsGrid->SetCellEditor( i, static_cast<int>( PIN_COLUMN::MODEL ),
|
|
|
|
new wxGridCellChoiceEditor( actualModelPinChoices ) );
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
2022-06-21 02:22:52 +00:00
|
|
|
|
|
|
|
// TODO: Show a preview of the symbol with the pin numbers shown.
|
|
|
|
// TODO: Maybe show a preview of the code for subcircuits and code models.
|
2020-03-23 16:49:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::removeOrphanedPinAssignments()
|
|
|
|
{
|
|
|
|
for( int i = 0; i < curModel().GetPinCount(); ++i )
|
|
|
|
{
|
|
|
|
const SIM_MODEL::PIN& modelPin = curModel().GetPin( i );
|
|
|
|
bool isOrphaned = true;
|
|
|
|
|
|
|
|
for( const LIB_PIN* symbolPin : m_sortedSymbolPins )
|
|
|
|
{
|
|
|
|
if( modelPin.symbolPinNumber == symbolPin->GetNumber() )
|
|
|
|
{
|
|
|
|
isOrphaned = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isOrphaned )
|
|
|
|
curModel().SetPinSymbolPinNumber( i, "" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::loadLibrary( const wxString& aFilePath )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-05-08 09:54:35 +00:00
|
|
|
const wxString absolutePath = Prj().AbsolutePath( aFilePath );
|
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
if( absolutePath.EndsWith( ".ibs" ) )
|
|
|
|
m_library = std::make_shared<SIM_LIBRARY_KIBIS>();
|
|
|
|
else
|
|
|
|
m_library = std::make_shared<SIM_LIBRARY_SPICE>();
|
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
try
|
|
|
|
{
|
2022-10-04 21:47:52 +00:00
|
|
|
if( isIbisLoaded() )
|
2022-09-29 08:35:01 +00:00
|
|
|
{
|
|
|
|
wxString ibisTypeString = SIM_MODEL::GetFieldValue( &m_fields, SIM_MODEL::TYPE_FIELD );
|
|
|
|
|
|
|
|
SIM_MODEL::TYPE ibisType = SIM_MODEL::TYPE::KIBIS_DEVICE;
|
|
|
|
|
2022-09-30 12:29:44 +00:00
|
|
|
if( ibisTypeString == "IBISDRIVERDC" )
|
|
|
|
ibisType = SIM_MODEL::TYPE::KIBIS_DRIVER_DC;
|
|
|
|
else if( ibisTypeString == "IBISDRIVERRECT" )
|
|
|
|
ibisType = SIM_MODEL::TYPE::KIBIS_DRIVER_RECT;
|
|
|
|
else if( ibisTypeString == "IBISDRIVRPRBS" )
|
|
|
|
ibisType = SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS;
|
2022-09-29 08:35:01 +00:00
|
|
|
else if( ibisTypeString == "IBISDIFFDEVICE" )
|
|
|
|
ibisType = SIM_MODEL::TYPE::KIBIS_DIFFDEVICE;
|
2022-09-30 12:29:44 +00:00
|
|
|
else if( ibisTypeString == "IBISDIFFDRIVER" )
|
|
|
|
ibisType = SIM_MODEL::TYPE::KIBIS_DIFFDRIVER;
|
2022-09-29 08:35:01 +00:00
|
|
|
|
|
|
|
std::dynamic_pointer_cast<SIM_LIBRARY_KIBIS>( m_library )
|
|
|
|
->ReadFile( std::string( absolutePath.ToUTF8() ), ibisType );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_library->ReadFile( std::string( absolutePath.ToUTF8() ) );
|
|
|
|
}
|
2022-06-12 03:39:13 +00:00
|
|
|
}
|
|
|
|
catch( const IO_ERROR& e )
|
2022-05-08 09:54:35 +00:00
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
DisplayErrorMessage( this, wxString::Format( _( "Failed reading model library '%s'." ),
|
|
|
|
absolutePath ),
|
|
|
|
e.What() );
|
2022-06-21 02:22:52 +00:00
|
|
|
return;
|
2022-05-08 09:54:35 +00:00
|
|
|
}
|
|
|
|
|
2022-08-02 10:52:22 +00:00
|
|
|
m_tclibraryPathName->ChangeValue( aFilePath );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
|
|
|
m_libraryModels.clear();
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
try
|
|
|
|
{
|
2022-10-06 12:08:01 +00:00
|
|
|
for( auto& [baseModelName, baseModel] : m_library->GetModels() )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
2022-09-27 20:47:00 +00:00
|
|
|
wxString expectedModelName;
|
|
|
|
expectedModelName =
|
|
|
|
SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY_KIBIS::NAME_FIELD );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
|
|
|
// Only the current model is initialized from fields. Others have default
|
|
|
|
// initialization.
|
2022-09-27 20:47:00 +00:00
|
|
|
if( baseModelName == expectedModelName )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
|
|
|
//TODO: it's not cur model.
|
|
|
|
|
|
|
|
m_libraryModels.push_back(
|
2022-08-28 12:51:03 +00:00
|
|
|
SIM_MODEL::Create( baseModel, m_sortedSymbolPins.size(), m_fields ) );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-28 12:51:03 +00:00
|
|
|
m_libraryModels.push_back( SIM_MODEL::Create( baseModel, m_sortedSymbolPins.size() ) );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( const IO_ERROR& e )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, e.What() );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayString modelNames;
|
2022-10-06 12:08:01 +00:00
|
|
|
for( auto& [modelName, model] : m_library->GetModels() )
|
|
|
|
modelNames.Add( modelName );
|
2022-06-21 02:22:52 +00:00
|
|
|
|
|
|
|
auto validator = dynamic_cast<MODEL_NAME_VALIDATOR*>( m_modelNameCombobox->GetValidator() );
|
2022-09-27 20:47:00 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
if( validator )
|
|
|
|
validator->SetIncludes( modelNames );
|
|
|
|
|
|
|
|
m_modelNameCombobox->Set( modelNames );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_useLibraryModelRadioButton->SetValue( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::addParamPropertyIfRelevant( int aParamIndex )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
if( curModel().GetParam( aParamIndex ).info.dir == SIM_MODEL::PARAM::DIR_OUT )
|
2022-02-21 03:58:31 +00:00
|
|
|
return;
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
switch( curModel().GetParam( aParamIndex ).info.category )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
case CATEGORY::AC:
|
|
|
|
m_paramGrid->HideProperty( "AC", false );
|
|
|
|
m_paramGrid->AppendIn( "AC", newParamProperty( aParamIndex ) );
|
|
|
|
break;
|
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
case CATEGORY::DC:
|
|
|
|
m_paramGrid->HideProperty( "DC", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "DC", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CATEGORY::CAPACITANCE:
|
|
|
|
m_paramGrid->HideProperty( "Capacitance", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "Capacitance", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CATEGORY::TEMPERATURE:
|
|
|
|
m_paramGrid->HideProperty( "Temperature", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "Temperature", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CATEGORY::NOISE:
|
|
|
|
m_paramGrid->HideProperty( "Noise", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "Noise", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CATEGORY::DISTRIBUTED_QUANTITIES:
|
|
|
|
m_paramGrid->HideProperty( "Distributed Quantities", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "Distributed Quantities", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
case CATEGORY::WAVEFORM:
|
|
|
|
m_paramGrid->HideProperty( "Waveform", false );
|
|
|
|
m_paramGrid->AppendIn( "Waveform", newParamProperty( aParamIndex ) );
|
|
|
|
break;
|
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
case CATEGORY::GEOMETRY:
|
|
|
|
m_paramGrid->HideProperty( "Geometry", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "Geometry", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CATEGORY::LIMITING_VALUES:
|
|
|
|
m_paramGrid->HideProperty( "Limiting Values", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "Limiting Values", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CATEGORY::ADVANCED:
|
|
|
|
m_paramGrid->HideProperty( "Advanced", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "Advanced", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CATEGORY::FLAGS:
|
|
|
|
m_paramGrid->HideProperty( "Flags", false );
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->AppendIn( "Flags", newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-04-01 04:30:50 +00:00
|
|
|
m_paramGrid->Insert( m_firstCategory, newParamProperty( aParamIndex ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CATEGORY::INITIAL_CONDITIONS:
|
|
|
|
case CATEGORY::SUPERFLUOUS:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
wxPGProperty* DIALOG_SIM_MODEL<T>::newParamProperty( int aParamIndex ) const
|
2017-10-26 17:54:53 +00:00
|
|
|
{
|
2022-04-01 04:30:50 +00:00
|
|
|
const SIM_MODEL::PARAM& param = curModel().GetParam( aParamIndex );
|
2022-04-12 14:37:06 +00:00
|
|
|
wxString paramDescription;
|
|
|
|
|
2022-08-02 12:43:03 +00:00
|
|
|
if( param.info.description == "" )
|
2022-04-12 14:37:06 +00:00
|
|
|
paramDescription = wxString::Format( "%s", param.info.name );
|
2022-08-30 07:00:52 +00:00
|
|
|
else
|
|
|
|
paramDescription = wxString::Format( "%s (%s)", param.info.description, param.info.name );
|
2022-04-12 14:37:06 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
wxPGProperty* prop = nullptr;
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
switch( param.info.type )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
case SIM_VALUE::TYPE_BOOL:
|
2022-05-08 09:54:35 +00:00
|
|
|
// TODO.
|
2022-06-21 02:22:52 +00:00
|
|
|
prop = new SIM_BOOL_PROPERTY( paramDescription, param.info.name, m_library,
|
|
|
|
curModelSharedPtr(), aParamIndex );
|
2022-05-08 09:54:35 +00:00
|
|
|
prop->SetAttribute( wxPG_BOOL_USE_CHECKBOX, true );
|
|
|
|
break;
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case SIM_VALUE::TYPE_INT:
|
|
|
|
prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, m_library,
|
|
|
|
curModelSharedPtr(), aParamIndex, SIM_VALUE::TYPE_INT );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case SIM_VALUE::TYPE_FLOAT:
|
|
|
|
prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, m_library,
|
|
|
|
curModelSharedPtr(), aParamIndex, SIM_VALUE::TYPE_FLOAT );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
//case TYPE_COMPLEX:
|
2022-05-08 09:54:35 +00:00
|
|
|
// break;
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
case SIM_VALUE::TYPE_STRING:
|
2022-08-30 07:00:52 +00:00
|
|
|
if( param.info.enumValues.empty() )
|
|
|
|
{
|
|
|
|
prop = new SIM_STRING_PROPERTY( paramDescription, param.info.name, m_library,
|
|
|
|
curModelSharedPtr(), aParamIndex, SIM_VALUE::TYPE_STRING );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prop = new SIM_ENUM_PROPERTY( paramDescription, param.info.name, m_library,
|
|
|
|
curModelSharedPtr(), aParamIndex, SIM_VALUE::TYPE_STRING );
|
|
|
|
}
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-04-01 04:30:50 +00:00
|
|
|
prop = new wxStringProperty( paramDescription, param.info.name );
|
2022-02-21 03:58:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
prop->SetAttribute( wxPG_ATTR_UNITS, param.info.unit );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
// Legacy due to the way we extracted the parameters from Ngspice.
|
2022-04-01 04:30:50 +00:00
|
|
|
if( param.isOtherVariant )
|
2022-09-22 05:38:45 +00:00
|
|
|
prop->SetCell( 3, wxString( param.info.defaultValueOfOtherVariant ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
else
|
2022-09-22 05:38:45 +00:00
|
|
|
prop->SetCell( 3, wxString( param.info.defaultValue ) );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
|
|
|
wxString typeStr;
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
switch( param.info.type )
|
2022-02-21 03:58:31 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
case SIM_VALUE::TYPE_BOOL: typeStr = wxString( "Bool" ); break;
|
|
|
|
case SIM_VALUE::TYPE_INT: typeStr = wxString( "Int" ); break;
|
|
|
|
case SIM_VALUE::TYPE_FLOAT: typeStr = wxString( "Float" ); break;
|
|
|
|
case SIM_VALUE::TYPE_COMPLEX: typeStr = wxString( "Complex" ); break;
|
|
|
|
case SIM_VALUE::TYPE_STRING: typeStr = wxString( "String" ); break;
|
|
|
|
case SIM_VALUE::TYPE_BOOL_VECTOR: typeStr = wxString( "Bool Vector" ); break;
|
|
|
|
case SIM_VALUE::TYPE_INT_VECTOR: typeStr = wxString( "Int Vector" ); break;
|
|
|
|
case SIM_VALUE::TYPE_FLOAT_VECTOR: typeStr = wxString( "Float Vector" ); break;
|
|
|
|
case SIM_VALUE::TYPE_COMPLEX_VECTOR: typeStr = wxString( "Complex Vector" ); break;
|
2022-02-21 03:58:31 +00:00
|
|
|
}
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
prop->SetCell( static_cast<int>( PARAM_COLUMN::TYPE ), typeStr );
|
2022-02-21 03:58:31 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
if( m_useLibraryModelRadioButton->GetValue()
|
|
|
|
&& !m_overrideCheckbox->GetValue()
|
2022-05-31 02:55:48 +00:00
|
|
|
&& !param.info.isInstanceParam )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
prop->Enable( false );
|
|
|
|
}
|
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
return prop;
|
2017-10-26 17:54:53 +00:00
|
|
|
}
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
template <typename T>
|
|
|
|
int DIALOG_SIM_MODEL<T>::findSymbolPinRow( const wxString& aSymbolPinNumber ) const
|
|
|
|
{
|
2022-08-28 12:51:03 +00:00
|
|
|
for( int row = 0; row < static_cast<int>( m_sortedSymbolPins.size() ); ++row )
|
2022-08-22 05:40:23 +00:00
|
|
|
{
|
2022-08-28 12:51:03 +00:00
|
|
|
LIB_PIN* pin = m_sortedSymbolPins[row];
|
2022-08-22 05:40:23 +00:00
|
|
|
|
|
|
|
if( pin->GetNumber() == aSymbolPinNumber )
|
|
|
|
return row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
SIM_MODEL& DIALOG_SIM_MODEL<T>::curModel() const
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-04-01 04:30:50 +00:00
|
|
|
return *curModelSharedPtr();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
std::shared_ptr<SIM_MODEL> DIALOG_SIM_MODEL<T>::curModelSharedPtr() const
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
if( m_useLibraryModelRadioButton->GetValue()
|
|
|
|
&& m_modelNameCombobox->GetSelection() != wxNOT_FOUND )
|
|
|
|
return m_libraryModels.at( m_modelNameCombobox->GetSelection() );
|
|
|
|
else
|
|
|
|
return m_models.at( static_cast<int>( m_curModelType ) );
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-08-22 05:40:23 +00:00
|
|
|
wxString DIALOG_SIM_MODEL<T>::getSymbolPinString( int symbolPinIndex ) const
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-08-28 12:51:03 +00:00
|
|
|
LIB_PIN* pin = m_sortedSymbolPins.at( symbolPinIndex );
|
2022-08-22 05:40:23 +00:00
|
|
|
wxString number;
|
|
|
|
wxString name;
|
|
|
|
|
|
|
|
if( pin )
|
|
|
|
{
|
|
|
|
number = pin->GetShownNumber();
|
|
|
|
name = pin->GetShownName();
|
|
|
|
}
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
LOCALE_IO toggle;
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
if( name == "" )
|
|
|
|
return wxString::Format( "%s", number );
|
2022-03-09 01:40:59 +00:00
|
|
|
else
|
2022-08-22 05:40:23 +00:00
|
|
|
return wxString::Format( "%s (%s)", number, name );
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-08-22 05:40:23 +00:00
|
|
|
wxString DIALOG_SIM_MODEL<T>::getModelPinString( int aModelPinIndex ) const
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
const wxString& pinName = curModel().GetPin( aModelPinIndex ).name;
|
|
|
|
|
|
|
|
LOCALE_IO toggle;
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
if( pinName == "" )
|
|
|
|
return wxString::Format( "%d", aModelPinIndex + 1, pinName );
|
2022-03-09 01:40:59 +00:00
|
|
|
else
|
2022-08-22 05:40:23 +00:00
|
|
|
return wxString::Format( "%d (%s)", aModelPinIndex + 1, pinName );
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-08-22 05:40:23 +00:00
|
|
|
int DIALOG_SIM_MODEL<T>::getModelPinIndex( const wxString& aModelPinString ) const
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
|
|
|
if( aModelPinString == "Not Connected" )
|
|
|
|
return SIM_MODEL::PIN::NOT_CONNECTED;
|
|
|
|
|
|
|
|
int length = aModelPinString.Find( " " );
|
|
|
|
|
|
|
|
if( length == wxNOT_FOUND )
|
|
|
|
length = static_cast<int>( aModelPinString.Length() );
|
|
|
|
|
|
|
|
long result = 0;
|
|
|
|
aModelPinString.Mid( 0, length ).ToCLong( &result );
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
return static_cast<int>( result - 1 );
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
template <typename T>
|
|
|
|
wxArrayString DIALOG_SIM_MODEL<T>::getModelPinChoices() const
|
|
|
|
{
|
|
|
|
wxArrayString modelPinChoices;
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
for( int i = 0; i < curModel().GetPinCount(); ++i )
|
2022-06-21 02:22:52 +00:00
|
|
|
{
|
|
|
|
const SIM_MODEL::PIN& modelPin = curModel().GetPin( i );
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
if( modelPin.symbolPinNumber != "" )
|
2022-06-21 02:22:52 +00:00
|
|
|
continue;
|
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
modelPinChoices.Add( getModelPinString( i ) );
|
2022-06-21 02:22:52 +00:00
|
|
|
}
|
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
modelPinChoices.Add( _( "Not Connected" ) );
|
2022-06-21 02:22:52 +00:00
|
|
|
return modelPinChoices;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onRadioButton( wxCommandEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onBrowseButtonClick( wxCommandEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
wxFileDialog dlg( this, _( "Browse Models" ), Prj().GetProjectPath() );
|
2022-04-01 04:30:50 +00:00
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
wxString path = dlg.GetPath();
|
|
|
|
wxFileName fn( path );
|
|
|
|
|
|
|
|
if( fn.MakeRelativeTo( Prj().GetProjectPath() ) && !fn.GetFullPath().StartsWith( ".." ) )
|
|
|
|
path = fn.GetFullPath();
|
|
|
|
|
|
|
|
loadLibrary( path );
|
2022-10-04 21:47:52 +00:00
|
|
|
updateWidgets();
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onModelNameCombobox( wxCommandEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-10-04 21:47:52 +00:00
|
|
|
if( isIbisLoaded() )
|
2022-09-27 20:47:00 +00:00
|
|
|
{
|
|
|
|
wxArrayString pinLabels;
|
|
|
|
SIM_MODEL_KIBIS* modelkibis = dynamic_cast<SIM_MODEL_KIBIS*>( &curModel() );
|
|
|
|
|
|
|
|
if( !modelkibis )
|
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for( std::pair<wxString, wxString> strs : modelkibis->GetIbisPins() )
|
|
|
|
{
|
|
|
|
pinLabels.Add( strs.first + " - " + strs.second );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_ibisPinCombobox->Set( pinLabels );
|
|
|
|
|
|
|
|
wxArrayString emptyArray;
|
|
|
|
m_ibisModelCombobox->Set( emptyArray );
|
|
|
|
}
|
2022-04-01 04:30:50 +00:00
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onModelNameComboboxKillFocus( wxFocusEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_modelNameCombobox->SetSelection(
|
|
|
|
m_modelNameCombobox->FindString( m_modelNameCombobox->GetValue() ) );
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onModelNameComboboxTextEnter( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_modelNameCombobox->SetSelection(
|
|
|
|
m_modelNameCombobox->FindString( m_modelNameCombobox->GetValue() ) );
|
2022-09-27 20:47:00 +00:00
|
|
|
onModelNameCombobox( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onIbisPinCombobox( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-10-04 21:47:52 +00:00
|
|
|
if( isIbisLoaded() )
|
2022-09-27 20:47:00 +00:00
|
|
|
{
|
|
|
|
wxArrayString modelLabels;
|
|
|
|
|
|
|
|
SIM_MODEL_KIBIS* modelkibis = dynamic_cast<SIM_MODEL_KIBIS*>( &curModel() );
|
|
|
|
|
|
|
|
if( !modelkibis )
|
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::pair<std::string, std::string>> strs = modelkibis->GetIbisPins();
|
|
|
|
modelkibis->ChangePin( *std::dynamic_pointer_cast<SIM_LIBRARY_KIBIS>( m_library ),
|
|
|
|
strs.at( m_ibisPinCombobox->GetSelection() ).first );
|
|
|
|
|
|
|
|
for( wxString modelName : modelkibis->GetIbisModels() )
|
|
|
|
modelLabels.Add( modelName );
|
|
|
|
|
|
|
|
m_ibisModelCombobox->Set( modelLabels );
|
|
|
|
}
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onIbisPinComboboxTextEnter( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_ibisPinCombobox->SetSelection(
|
|
|
|
m_ibisPinCombobox->FindString( m_ibisPinCombobox->GetValue() ) );
|
|
|
|
|
|
|
|
onIbisPinCombobox( aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onIbisModelCombobox( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-09-27 20:47:00 +00:00
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onIbisModelComboboxTextEnter( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_ibisModelCombobox->SetSelection(
|
|
|
|
m_ibisModelCombobox->FindString( m_ibisModelCombobox->GetValue() ) );
|
|
|
|
|
|
|
|
onIbisPinCombobox( aEvent );
|
|
|
|
}
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onOverrideCheckbox( wxCommandEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onDeviceTypeChoice( wxCommandEvent& aEvent )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
SIM_MODEL::DEVICE_TYPE_ deviceType =
|
|
|
|
static_cast<SIM_MODEL::DEVICE_TYPE_>( m_deviceTypeChoice->GetSelection() );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
m_curModelType = m_curModelTypeOfDeviceType.at( deviceType );
|
|
|
|
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onTypeChoice( wxCommandEvent& aEvent )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
SIM_MODEL::DEVICE_TYPE_ deviceType =
|
|
|
|
static_cast<SIM_MODEL::DEVICE_TYPE_>( m_deviceTypeChoice->GetSelection() );
|
2022-03-09 01:40:59 +00:00
|
|
|
wxString typeDescription = m_typeChoice->GetString( m_typeChoice->GetSelection() );
|
|
|
|
|
|
|
|
for( SIM_MODEL::TYPE type : SIM_MODEL::TYPE_ITERATOR() )
|
|
|
|
{
|
|
|
|
if( deviceType == SIM_MODEL::TypeInfo( type ).deviceType
|
|
|
|
&& typeDescription == SIM_MODEL::TypeInfo( type ).description )
|
|
|
|
{
|
2022-10-04 21:47:52 +00:00
|
|
|
if( isIbisLoaded()
|
2022-09-30 12:29:44 +00:00
|
|
|
&& ( type == SIM_MODEL::TYPE::KIBIS_DEVICE
|
|
|
|
|| type == SIM_MODEL::TYPE::KIBIS_DRIVER_DC
|
|
|
|
|| type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
|
|
|
|
|| type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS
|
|
|
|
|| type == SIM_MODEL::TYPE::KIBIS_DIFFDEVICE
|
|
|
|
|| type == SIM_MODEL::TYPE::KIBIS_DIFFDRIVER ) )
|
2022-09-27 20:47:00 +00:00
|
|
|
{
|
|
|
|
std::shared_ptr<SIM_MODEL_KIBIS> kibismodel =
|
|
|
|
std::dynamic_pointer_cast<SIM_MODEL_KIBIS>(
|
|
|
|
m_libraryModels.at( m_modelNameCombobox->GetSelection() ) );
|
|
|
|
|
|
|
|
m_libraryModels.at( m_modelNameCombobox->GetSelection() ) =
|
|
|
|
std::shared_ptr<SIM_MODEL>( dynamic_cast<SIM_MODEL*>(
|
|
|
|
new SIM_MODEL_KIBIS( type, *kibismodel, m_fields ) ) );
|
|
|
|
|
|
|
|
wxCommandEvent dummyEvent;
|
|
|
|
onIbisPinCombobox( dummyEvent );
|
|
|
|
|
|
|
|
kibismodel = std::dynamic_pointer_cast<SIM_MODEL_KIBIS>(
|
|
|
|
m_libraryModels.at( m_modelNameCombobox->GetSelection() ) );
|
|
|
|
}
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
m_curModelType = type;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_curModelTypeOfDeviceType.at( deviceType ) = m_curModelType;
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onParamGridChanged( wxPropertyGridEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
updateWidgets();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onCodePreviewSetFocus( wxFocusEvent& aEvent )
|
|
|
|
{
|
|
|
|
// For some reason all text gets selected for me -Mikolaj
|
|
|
|
if( m_wasCodePreviewUpdated )
|
|
|
|
m_codePreview->SelectNone();
|
|
|
|
|
|
|
|
m_wasCodePreviewUpdated = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onPinAssignmentsGridCellChange( wxGridEvent& aEvent )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-08-22 05:40:23 +00:00
|
|
|
int symbolPinIndex = aEvent.GetRow();
|
|
|
|
int oldModelPinIndex = getModelPinIndex( aEvent.GetString() );
|
|
|
|
int modelPinIndex = getModelPinIndex(
|
2022-03-09 01:40:59 +00:00
|
|
|
m_pinAssignmentsGrid->GetCellValue( aEvent.GetRow(), aEvent.GetCol() ) );
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
if( oldModelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
|
|
|
|
curModel().SetPinSymbolPinNumber( oldModelPinIndex, "" );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
if( modelPinIndex != SIM_MODEL::PIN::NOT_CONNECTED )
|
|
|
|
{
|
|
|
|
curModel().SetPinSymbolPinNumber( modelPinIndex,
|
2022-09-22 05:38:45 +00:00
|
|
|
std::string( m_sortedSymbolPins.at( symbolPinIndex )->GetShownNumber().ToUTF8() ) );
|
2022-08-22 05:40:23 +00:00
|
|
|
}
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-08-28 12:51:03 +00:00
|
|
|
updatePinAssignments();
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onPinAssignmentsGridSize( wxSizeEvent& aEvent )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
|
|
|
wxGridUpdateLocker deferRepaintsTillLeavingScope( m_pinAssignmentsGrid );
|
|
|
|
|
|
|
|
int gridWidth = KIPLATFORM::UI::GetUnobscuredSize( m_pinAssignmentsGrid ).x;
|
|
|
|
m_pinAssignmentsGrid->SetColSize( static_cast<int>( PIN_COLUMN::MODEL ), gridWidth / 2 );
|
|
|
|
m_pinAssignmentsGrid->SetColSize( static_cast<int>( PIN_COLUMN::SYMBOL ), gridWidth / 2 );
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
template <typename T>
|
2022-06-21 02:22:52 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onExcludeSymbolCheckbox( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
curModel().SetIsEnabled( !m_excludeSymbolCheckbox->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onLibraryPathUpdate( wxUpdateUIEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
aEvent.Enable( m_useLibraryModelRadioButton->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onBrowseButtonUpdate( wxUpdateUIEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
aEvent.Enable( m_useLibraryModelRadioButton->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onModelNameComboboxUpdate( wxUpdateUIEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
aEvent.Enable( m_useLibraryModelRadioButton->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onOverrideCheckboxUpdate( wxUpdateUIEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
aEvent.Enable( m_useLibraryModelRadioButton->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onDeviceTypeChoiceUpdate( wxUpdateUIEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
|
|
|
aEvent.Enable( m_useInstanceModelRadioButton->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onTypeChoiceUpdate( wxUpdateUIEvent& aEvent )
|
2022-04-01 04:30:50 +00:00
|
|
|
{
|
2022-10-04 21:47:52 +00:00
|
|
|
aEvent.Enable( m_useInstanceModelRadioButton->GetValue() || ( isIbisLoaded() ) );
|
2022-04-01 04:30:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
template <typename T>
|
2022-06-12 03:39:13 +00:00
|
|
|
void DIALOG_SIM_MODEL<T>::onParamGridSetFocus( wxFocusEvent& aEvent )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-06-21 02:22:52 +00:00
|
|
|
// By default, when a property grid is focused, the textbox is not immediately focused until
|
2022-06-12 03:39:13 +00:00
|
|
|
// Tab key is pressed. This is inconvenient, so we fix that here.
|
2022-03-09 01:40:59 +00:00
|
|
|
|
|
|
|
wxPropertyGrid* grid = m_paramGrid->GetGrid();
|
|
|
|
if( !grid )
|
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
wxPGProperty* selected = grid->GetSelection();
|
|
|
|
|
|
|
|
if( !selected )
|
|
|
|
selected = grid->wxPropertyGridInterface::GetFirst();
|
|
|
|
|
|
|
|
if( selected )
|
|
|
|
grid->DoSelectProperty( selected, wxPG_SEL_FOCUS );
|
|
|
|
|
|
|
|
aEvent.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void DIALOG_SIM_MODEL<T>::onParamGridSelectionChange( wxPropertyGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxPropertyGrid* grid = m_paramGrid->GetGrid();
|
|
|
|
if( !grid )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
|
|
|
wxFAIL;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
// Jump over categories.
|
|
|
|
if( grid->GetSelection() && grid->GetSelection()->IsCategory() )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
wxPGProperty* selection = grid->GetSelection();
|
|
|
|
|
|
|
|
// If the new selection is immediately above the previous selection, we jump up. Otherwise
|
|
|
|
// we jump down. We do this by simulating up or down arrow keys.
|
|
|
|
|
|
|
|
wxPropertyGridIterator it = grid->GetIterator( wxPG_ITERATE_VISIBLE, selection );
|
|
|
|
it.Next();
|
|
|
|
|
|
|
|
wxKeyEvent* keyEvent = new wxKeyEvent( wxEVT_KEY_DOWN );
|
|
|
|
|
|
|
|
if( *it == m_prevParamGridSelection )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
if( !selection->IsExpanded() )
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
grid->Expand( selection );
|
|
|
|
keyEvent->m_keyCode = WXK_DOWN;
|
|
|
|
wxQueueEvent( grid, keyEvent );
|
|
|
|
|
|
|
|
// Does not work for some reason.
|
|
|
|
/*m_paramGrid->DoSelectProperty( selection->Item( selection->GetChildCount() - 1 ),
|
|
|
|
wxPG_SEL_FOCUS );*/
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
2022-06-12 03:39:13 +00:00
|
|
|
else
|
2022-03-09 01:40:59 +00:00
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
keyEvent->m_keyCode = WXK_UP;
|
|
|
|
wxQueueEvent( grid, keyEvent );
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
|
|
|
}
|
2022-06-12 03:39:13 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if( !selection->IsExpanded() )
|
|
|
|
grid->Expand( selection );
|
|
|
|
|
|
|
|
keyEvent->m_keyCode = WXK_DOWN;
|
|
|
|
wxQueueEvent( grid, keyEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_prevParamGridSelection = grid->GetSelection();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxWindow* editorControl = grid->GetEditorControl();
|
|
|
|
if( !editorControl )
|
|
|
|
{
|
|
|
|
m_prevParamGridSelection = grid->GetSelection();
|
|
|
|
return;
|
2022-03-09 01:40:59 +00:00
|
|
|
}
|
2022-07-30 12:06:51 +00:00
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
// Without this the user had to press tab before they could edit the field.
|
|
|
|
editorControl->SetFocus();
|
|
|
|
m_prevParamGridSelection = grid->GetSelection();
|
|
|
|
}
|
2022-08-01 02:49:28 +00:00
|
|
|
|
|
|
|
template class DIALOG_SIM_MODEL<SCH_FIELD>;
|
|
|
|
template class DIALOG_SIM_MODEL<LIB_FIELD>;
|