KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_sim_model.h
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 The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef DIALOG_SIM_MODEL_H
22#define DIALOG_SIM_MODEL_H
23#include <sim/kibis/kibis.h>
24
27#include <scintilla_tricks.h>
28
29#include <sim/sim_model.h>
30#include <sim/sim_library.h>
32#include <sch_symbol.h>
33
34class EMBEDDED_FILES;
35
36// Some probable wxWidgets bugs encountered when writing this class:
37// 1. There are rendering problems with wxPropertyGrid on Linux, GTK, Xorg when
38// wxPG_NATIVE_DOUBLE_BUFFERING flag is not set.
39// 2. wxPropertyGridManager->ShowHeader() segfaults when called from this dialog's constructor.
40
41template <typename T>
43{
44public:
54
56 {
57 SYMBOL = 0,
59 };
60
61 DIALOG_SIM_MODEL( wxWindow* aParent, EDA_BASE_FRAME* aFrame, T& aSymbol,
62 std::vector<SCH_FIELD>& aFields );
63
65
73 static void RestoreInferredValue( std::vector<SCH_FIELD>& aFields, const wxString& aOriginalValue,
74 bool aOverwritten, bool aStoredInValue );
75
76private:
77 bool TransferDataToWindow() override;
78 bool TransferDataFromWindow() override;
79
80 void updateWidgets();
81 void updateIbisWidgets( SIM_MODEL* aModel );
83 void updateModelParamsTab( SIM_MODEL* aModel );
84 void updateModelCodeTab( SIM_MODEL* aModel );
85 void updatePinAssignments( SIM_MODEL* aModel, bool aForceUpdatePins );
86
88
89 bool loadLibrary( const wxString& aLibraryPath, REPORTER& aReporter,
90 bool aForceReload = false );
91
92 void addParamPropertyIfRelevant( SIM_MODEL* aModel, int aParamIndex );
93 wxPGProperty* newParamProperty( SIM_MODEL* aModel, int aParamIndex ) const;
94
95 int findSymbolPinRow( const wxString& aSymbolPinNumber ) const;
96
97 SIM_MODEL& curModel() const;
98 const SIM_LIBRARY* library() const;
99
100 wxString getSymbolPinString( int aSymbolPinNumber ) const;
101 wxString getModelPinString( SIM_MODEL* aModel, int aModelPinIndex ) const;
102 int getModelPinIndex( const wxString& aModelPinString ) const;
103
104 void onRadioButton( wxCommandEvent& aEvent ) override;
105 void onLibraryPathText( wxCommandEvent& aEvent ) override;
106 void onLibraryPathTextEnter( wxCommandEvent& aEvent ) override;
107 void onLibraryPathTextKillFocus( wxFocusEvent& aEvent ) override;
108 void onBrowseButtonClick( wxCommandEvent& aEvent ) override;
109 void onFilterCharHook( wxKeyEvent& aKeyStroke ) override;
110 void onModelFilter( wxCommandEvent& aEvent ) override;
111 void onModelNameChoice( wxCommandEvent& aEvent ) override;
112 void onPinCombobox( wxCommandEvent& event ) override;
113 void onPinComboboxTextEnter( wxCommandEvent& event ) override;
114 void onPinModelCombobox( wxCommandEvent& event ) override;
115 void onPinModelComboboxTextEnter( wxCommandEvent& event ) override;
116 void onDeviceTypeChoice( wxCommandEvent& aEvent ) override;
117 void onWaveformChoice( wxCommandEvent& aEvent ) override;
118 void onTypeChoice( wxCommandEvent& aEvent ) override;
119 void onPageChanging( wxNotebookEvent& event ) override;
120 void onPinAssignmentsGridCellChange( wxGridEvent& aEvent ) override;
121 void onPinAssignmentsGridSize( wxSizeEvent& aEvent ) override;
122 void onDecompositionModeChoice( wxCommandEvent& aEvent ) override;
123 void onDifferentialCheckbox( wxCommandEvent& event ) override;
124 void onSizeParamGrid( wxSizeEvent& event ) override;
125
126 void onParamGridSetFocus( wxFocusEvent& aEvent );
127 void onParamGridSelectionChange( wxPropertyGridEvent& aEvent );
128 void onUpdateUI( wxUpdateUIEvent& aEvent );
129
130 void adjustParamGridColumns( int aWidth, bool aForce );
131
134
135 bool isIbisLoaded() { return dynamic_cast<const SIM_LIBRARY_IBIS*>( library() ); }
136
137private:
140 std::vector<SCH_FIELD>& m_fields;
141
142 std::vector<EMBEDDED_FILES*> m_filesStack;
143
144 // Original Value text saved before parking the ${SIM.PARAMS} placeholder, restored verbatim if
145 // the user opts out of storing parameters in Value.
148
153
154 std::map<wxString, int> m_modelListBoxEntryToLibraryIdx;
155
156 std::vector<SCH_PIN*> m_sortedPartPins;
157 std::map<SIM_MODEL::DEVICE_T, SIM_MODEL::TYPE> m_curModelTypeOfDeviceType;
158 SIM_MODEL::TYPE m_curModelType;
159
162
163 wxPGProperty* m_firstCategory; // Used to add principal parameters to root.
165
167};
168
169#endif /* DIALOG_SIM_MODEL_H */
DIALOG_SIM_MODEL_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=_("Simulation Model Editor"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
const SIM_MODEL * m_prevModel
void onTypeChoice(wxCommandEvent &aEvent) override
void onLibraryPathTextKillFocus(wxFocusEvent &aEvent) override
wxString getSymbolPinString(int aSymbolPinNumber) const
void updateBuiltinModelWidgets(SIM_MODEL *aModel)
void onPinAssignmentsGridCellChange(wxGridEvent &aEvent) override
void onFilterCharHook(wxKeyEvent &aKeyStroke) override
int findSymbolPinRow(const wxString &aSymbolPinNumber) const
void onModelNameChoice(wxCommandEvent &aEvent) override
void onRadioButton(wxCommandEvent &aEvent) override
SCINTILLA_TRICKS * m_scintillaTricksSubckt
bool loadLibrary(const wxString &aLibraryPath, REPORTER &aReporter, bool aForceReload=false)
SIM_LIB_MGR m_builtinModelsMgr
int getModelPinIndex(const wxString &aModelPinString) const
void onModelFilter(wxCommandEvent &aEvent) override
void onLibraryPathText(wxCommandEvent &aEvent) override
void onDifferentialCheckbox(wxCommandEvent &event) override
void onParamGridSelectionChange(wxPropertyGridEvent &aEvent)
void removeOrphanedPinAssignments(SIM_MODEL *aModel)
void adjustParamGridColumns(int aWidth, bool aForce)
Show/populate the decomposition controls (multi-unit only) and sync their enabled state.
std::vector< SCH_FIELD > & m_fields
std::vector< SCH_PIN * > m_sortedPartPins
Pins of the current part.
wxPGProperty * newParamProperty(SIM_MODEL *aModel, int aParamIndex) const
void onDecompositionModeChoice(wxCommandEvent &aEvent) override
wxPGProperty * m_prevParamGridSelection
void onPinModelCombobox(wxCommandEvent &event) override
const SIM_LIBRARY * library() const
SIM_MODEL & curModel() const
SIM_LIB_MGR m_libraryModelsMgr
void onBrowseButtonClick(wxCommandEvent &aEvent) override
void onPinComboboxTextEnter(wxCommandEvent &event) override
void onPinCombobox(wxCommandEvent &event) override
wxPGProperty * m_firstCategory
SCINTILLA_TRICKS * m_scintillaTricksCode
wxString m_inferredValueRestore
std::map< wxString, int > m_modelListBoxEntryToLibraryIdx
void updatePinAssignments(SIM_MODEL *aModel, bool aForceUpdatePins)
void onUpdateUI(wxUpdateUIEvent &aEvent)
DIALOG_SIM_MODEL(wxWindow *aParent, EDA_BASE_FRAME *aFrame, T &aSymbol, std::vector< SCH_FIELD > &aFields)
wxString getModelPinString(SIM_MODEL *aModel, int aModelPinIndex) const
void onPinAssignmentsGridSize(wxSizeEvent &aEvent) override
void updateIbisWidgets(SIM_MODEL *aModel)
void onParamGridSetFocus(wxFocusEvent &aEvent)
void updateModelParamsTab(SIM_MODEL *aModel)
bool TransferDataFromWindow() override
SIM_MODEL::TYPE m_curModelType
void updateModelCodeTab(SIM_MODEL *aModel)
void onSizeParamGrid(wxSizeEvent &event) override
void onPageChanging(wxNotebookEvent &event) override
std::vector< EMBEDDED_FILES * > m_filesStack
void onWaveformChoice(wxCommandEvent &aEvent) override
std::map< SIM_MODEL::DEVICE_T, SIM_MODEL::TYPE > m_curModelTypeOfDeviceType
void onPinModelComboboxTextEnter(wxCommandEvent &event) override
EDA_BASE_FRAME * m_frame
void onLibraryPathTextEnter(wxCommandEvent &aEvent) override
static void RestoreInferredValue(std::vector< SCH_FIELD > &aFields, const wxString &aOriginalValue, bool aOverwritten, bool aStoredInValue)
Restore an inferred passive's Value field after WriteFields().
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.
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:71
Add cut/copy/paste, dark theme, autocomplete and brace highlighting to a wxStyleTextCtrl instance.