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-06-21 02:22:52 +00:00
|
|
|
#ifndef DIALOG_SIM_MODEL_H
|
|
|
|
#define DIALOG_SIM_MODEL_H
|
2022-09-28 09:09:35 +00:00
|
|
|
#include <../../pcbnew/ibis/kibis.h>
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
#include <dialog_sim_model_base.h>
|
|
|
|
#include <netlist_exporter_spice.h>
|
2021-12-03 02:41:02 +00:00
|
|
|
#include <scintilla_tricks.h>
|
2016-08-11 12:41:56 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
#include <sim/sim_model.h>
|
2022-04-01 04:30:50 +00:00
|
|
|
#include <sim/sim_library.h>
|
2022-10-10 11:49:43 +00:00
|
|
|
#include <sim/sim_library_kibis.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2016-08-11 12:41:56 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
|
2022-02-21 03:58:31 +00:00
|
|
|
// Some probable wxWidgets bugs encountered when writing this class:
|
|
|
|
// 1. There are rendering problems with wxPropertyGrid on Linux, GTK, Xorg when
|
|
|
|
// wxPG_NATIVE_DOUBLE_BUFFERING flag is not set.
|
|
|
|
// 2. wxPropertyGridManager->ShowHeader() segfaults when called from this dialog's constructor.
|
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
template <typename T>
|
2022-04-12 14:37:06 +00:00
|
|
|
class DIALOG_SIM_MODEL : public DIALOG_SIM_MODEL_BASE
|
2016-08-11 12:41:40 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-06-21 02:22:52 +00:00
|
|
|
class MODEL_NAME_VALIDATOR : public wxTextValidator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MODEL_NAME_VALIDATOR() : wxTextValidator( wxFILTER_INCLUDE_LIST )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
wxObject* Clone() const override
|
|
|
|
{
|
|
|
|
return new MODEL_NAME_VALIDATOR( *this );
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString IsValid( const wxString& aStr ) const override
|
|
|
|
{
|
|
|
|
if( m_includes.Index( aStr ) == wxNOT_FOUND )
|
|
|
|
return wxString::Format( _( "No model named '%s' in library." ), aStr );
|
|
|
|
|
|
|
|
return wxString();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
enum class PARAM_COLUMN : int { DESCRIPTION, VALUE, UNIT, DEFAULT, TYPE, END_ };
|
|
|
|
enum class PIN_COLUMN : int { SYMBOL, MODEL };
|
2022-02-09 00:45:04 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
DIALOG_SIM_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol, std::vector<T>& aSchFields );
|
2016-08-11 12:41:40 +00:00
|
|
|
|
|
|
|
private:
|
2022-02-09 00:45:04 +00:00
|
|
|
bool TransferDataToWindow() override;
|
2022-04-01 04:30:50 +00:00
|
|
|
bool TransferDataFromWindow() override;
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2022-02-09 00:45:04 +00:00
|
|
|
void updateWidgets();
|
2022-10-04 21:47:52 +00:00
|
|
|
void updateIbisWidgets();
|
2022-03-09 01:40:59 +00:00
|
|
|
void updateModelParamsTab();
|
|
|
|
void updateModelCodeTab();
|
2022-08-28 12:51:03 +00:00
|
|
|
void updatePinAssignments();
|
|
|
|
|
|
|
|
void removeOrphanedPinAssignments();
|
2022-04-01 04:30:50 +00:00
|
|
|
|
|
|
|
void loadLibrary( const wxString& aFilePath );
|
2022-09-28 09:09:35 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
void addParamPropertyIfRelevant( int aParamIndex );
|
|
|
|
wxPGProperty* newParamProperty( int aParamIndex ) const;
|
|
|
|
|
2022-08-22 05:40:23 +00:00
|
|
|
int findSymbolPinRow( const wxString& aSymbolPinNumber ) const;
|
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
SIM_MODEL& curModel() const;
|
|
|
|
std::shared_ptr<SIM_MODEL> curModelSharedPtr() const;
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2022-03-09 01:40:59 +00:00
|
|
|
wxString getSymbolPinString( int aSymbolPinNumber ) const;
|
2022-08-22 05:40:23 +00:00
|
|
|
wxString getModelPinString( int aModelPinIndex ) const;
|
|
|
|
int getModelPinIndex( const wxString& aModelPinString ) const;
|
2022-06-21 02:22:52 +00:00
|
|
|
wxArrayString getModelPinChoices() const;
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
void onRadioButton( wxCommandEvent& aEvent ) override;
|
|
|
|
void onBrowseButtonClick( wxCommandEvent& aEvent ) override;
|
|
|
|
void onModelNameCombobox( wxCommandEvent& aEvent ) override;
|
2022-06-21 02:22:52 +00:00
|
|
|
void onModelNameComboboxKillFocus( wxFocusEvent& event ) override;
|
|
|
|
void onModelNameComboboxTextEnter( wxCommandEvent& event ) override;
|
2022-09-27 20:47:00 +00:00
|
|
|
void onIbisPinCombobox( wxCommandEvent& event ) override;
|
|
|
|
void onIbisPinComboboxTextEnter( wxCommandEvent& event ) override;
|
|
|
|
void onIbisModelCombobox( wxCommandEvent& event ) override;
|
|
|
|
void onIbisModelComboboxTextEnter( wxCommandEvent& event ) override;
|
2022-04-01 04:30:50 +00:00
|
|
|
void onOverrideCheckbox( wxCommandEvent& aEvent ) override;
|
2022-03-09 01:40:59 +00:00
|
|
|
void onDeviceTypeChoice( wxCommandEvent& aEvent ) override;
|
|
|
|
void onTypeChoice( wxCommandEvent& aEvent ) override;
|
2022-04-01 04:30:50 +00:00
|
|
|
void onParamGridChanged( wxPropertyGridEvent& aEvent ) override;
|
2022-06-21 02:22:52 +00:00
|
|
|
void onCodePreviewSetFocus( wxFocusEvent& aEvent ) override;
|
2022-03-09 01:40:59 +00:00
|
|
|
void onPinAssignmentsGridCellChange( wxGridEvent& aEvent ) override;
|
|
|
|
void onPinAssignmentsGridSize( wxSizeEvent& aEvent ) override;
|
2022-06-21 02:22:52 +00:00
|
|
|
void onExcludeSymbolCheckbox( wxCommandEvent& aEvent ) override;
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
void onLibraryPathUpdate( wxUpdateUIEvent& aEvent ) override;
|
2022-04-01 04:30:50 +00:00
|
|
|
void onBrowseButtonUpdate( wxUpdateUIEvent& aEvent ) override;
|
|
|
|
void onModelNameComboboxUpdate( wxUpdateUIEvent& aEvent ) override;
|
|
|
|
void onOverrideCheckboxUpdate( wxUpdateUIEvent& aEvent ) override;
|
|
|
|
void onDeviceTypeChoiceUpdate( wxUpdateUIEvent& aEvent ) override;
|
|
|
|
void onTypeChoiceUpdate( wxUpdateUIEvent& aEvent ) override;
|
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
void onParamGridSetFocus( wxFocusEvent& aEvent );
|
|
|
|
void onParamGridSelectionChange( wxPropertyGridEvent& aEvent );
|
2022-03-09 01:40:59 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL& m_symbol;
|
2022-02-21 03:58:31 +00:00
|
|
|
std::vector<T>& m_fields;
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2022-08-26 01:26:54 +00:00
|
|
|
std::vector<std::shared_ptr<SIM_MODEL>> m_models;
|
2022-08-28 12:51:03 +00:00
|
|
|
std::vector<LIB_PIN*> m_sortedSymbolPins;
|
2022-06-21 02:22:52 +00:00
|
|
|
std::map<SIM_MODEL::DEVICE_TYPE_, SIM_MODEL::TYPE> m_curModelTypeOfDeviceType;
|
2022-08-26 01:26:54 +00:00
|
|
|
SIM_MODEL::TYPE m_curModelType = SIM_MODEL::TYPE::NONE;
|
2021-12-03 02:41:02 +00:00
|
|
|
|
2022-04-01 04:30:50 +00:00
|
|
|
std::shared_ptr<SIM_LIBRARY> m_library;
|
|
|
|
std::vector<std::shared_ptr<SIM_MODEL>> m_libraryModels;
|
|
|
|
const SIM_MODEL* m_prevModel;
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
MODEL_NAME_VALIDATOR m_modelNameValidator;
|
2022-06-12 03:39:13 +00:00
|
|
|
wxPGProperty* m_firstCategory; // Used to add principal parameters to root.
|
2021-12-03 02:41:02 +00:00
|
|
|
std::unique_ptr<SCINTILLA_TRICKS> m_scintillaTricks;
|
2022-06-12 03:39:13 +00:00
|
|
|
|
|
|
|
wxPGProperty* m_prevParamGridSelection;
|
2022-06-21 02:22:52 +00:00
|
|
|
bool m_wasCodePreviewUpdated;
|
2022-09-27 20:47:00 +00:00
|
|
|
|
2022-10-10 11:49:43 +00:00
|
|
|
bool isIbisLoaded() { return dynamic_cast<SIM_LIBRARY_KIBIS*>( m_library.get() ); }
|
2016-08-11 12:41:40 +00:00
|
|
|
};
|
|
|
|
|
2022-06-21 02:22:52 +00:00
|
|
|
#endif /* DIALOG_SIM_MODEL_H */
|