KiCad PCB EDA Suite
dialog_spice_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) 2016-2017 CERN
5  * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Maciej Suminski <maciej.suminski@cern.ch>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 3
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, you may find one here:
21  * https://www.gnu.org/licenses/gpl-3.0.html
22  * or you may search the http://www.gnu.org website for the version 3 license,
23  * or you may write to the Free Software Foundation, Inc.,
24  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25  */
26 
27 #ifndef DIALOG_SPICE_MODEL_H
28 #define DIALOG_SPICE_MODEL_H
29 
32 
33 #include <sim/spice_value.h>
34 #include <sch_component.h>
35 #include <sch_field.h>
36 #include <lib_field.h>
37 
38 #include <wx/valnum.h>
39 
41 {
42 public:
43  DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent,
44  std::vector<SCH_FIELD>* aSchFields );
45  DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent,
46  std::vector<LIB_FIELD>* aLibFields );
47 
48 private:
55  bool parsePowerSource( const wxString& aModel );
56 
65  bool generatePowerSource( wxString& aTarget ) const;
66 
74  void loadLibrary( const wxString& aFilePath );
75 
82  SCH_FIELD& getSchField( int aFieldType );
83  LIB_FIELD& getLibField( int aFieldType );
84 
92  bool addPwlValue( const wxString& aTime, const wxString& aValue );
93 
94  virtual bool TransferDataFromWindow() override;
95  virtual bool TransferDataToWindow() override;
96 
97  // The default dialog Validate() calls the validators of all widgets.
98  // This is not what we want; We want only validators of the selected page
99  // of the notebooks. So disable the wxDialog::Validate(), and let our
100  // TransferDataFromWindow doing the job.
101  virtual bool Validate() override
102  {
103  return true;
104  }
105 
106  virtual void onInitDlg( wxInitDialogEvent& event ) override
107  {
108  // Call the default wxDialog handler of a wxInitDialogEvent
110 
111  // Now all widgets have the size fixed, call FinishDialogSettings
113  }
114 
118  void Init();
119 
123  void showPinOrderNote( int aModelType );
124 
125  // Event handlers
126  void onSelectLibrary( wxCommandEvent& event ) override;
127  void onModelSelected( wxCommandEvent& event ) override;
128  void onPwlAdd( wxCommandEvent& event ) override;
129  void onPwlRemove( wxCommandEvent& event ) override;
130  void onRandomSourceType( wxCommandEvent& event ) override;
131  void onTypeSelected( wxCommandEvent& event ) override;
132 
135 
137  std::vector<SCH_FIELD>* m_schfields;
138  std::vector<LIB_FIELD>* m_libfields;
140 
142  std::map<int, wxString> m_fieldsTmp;
143 
144  struct MODEL
145  {
147  int line;
148 
151 
153  static SPICE_PRIMITIVE parseModelType( const wxString& aValue );
154 
155  MODEL( int aLine, enum SPICE_PRIMITIVE aModel )
156  : line( aLine ), model( aModel )
157  {
158  }
159  };
160 
162  std::map<wxString, MODEL> m_models;
163 
166 
169  wxTextValidator m_notEmptyValidator;
170 };
171 
172 #endif /* DIALOG_SPICE_MODEL_H */
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:51
void onSelectLibrary(wxCommandEvent &event) override
void Init()
Initialize the internal settings.
SCH_COMPONENT & m_component
Fields from the component properties dialog.
bool generatePowerSource(wxString &aTarget) const
Generate a string to describe power source parameters, basing on the current selection.
static SPICE_PRIMITIVE parseModelType(const wxString &aValue)
SPICE_VALIDATOR m_spiceValidator
void onTypeSelected(wxCommandEvent &event) override
Edited component.
std::vector< LIB_FIELD > * m_libfields
virtual bool TransferDataFromWindow() override
bool m_useSchFields
Temporary field values.
Field object used in symbol libraries.
Definition: lib_field.h:59
bool addPwlValue(const wxString &aTime, const wxString &aValue)
Add a value to the PWL values list.
LIB_FIELD & getLibField(int aFieldType)
bool parsePowerSource(const wxString &aModel)
Parse a string describing a power source, so appropriate settings are checked in the dialog.
virtual bool Validate() override
void showPinOrderNote(int aModelType)
Display a note info about pin order.
void onRandomSourceType(wxCommandEvent &event) override
SCH_FIELD & getSchField(int aFieldType)
Return or create a field in the edited schematic fields vector.
wxTextValidator m_notEmptyValidator
void onModelSelected(wxCommandEvent &event) override
std::map< int, wxString > m_fieldsTmp
Models available in the selected library file.
void onPwlRemove(wxCommandEvent &event) override
void onPwlAdd(wxCommandEvent &event) override
void loadLibrary(const wxString &aFilePath)
Load a list of components (.model and .subckt) from a spice library file and add them to a combo box.
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
SPICE_PRIMITIVE model
Convert string to model.
Class DIALOG_SPICE_MODEL_BASE.
MODEL(int aLine, enum SPICE_PRIMITIVE aModel)
std::map< wxString, MODEL > m_models
Column identifiers for PWL power source value list.
Schematic symbol object.
Definition: sch_component.h:79
int line
< Line number in the library file
DIALOG_SPICE_MODEL(wxWindow *aParent, SCH_COMPONENT &aComponent, std::vector< SCH_FIELD > *aSchFields)
virtual void onInitDlg(wxInitDialogEvent &event) override
std::vector< SCH_FIELD > * m_schfields
SPICE_VALIDATOR m_spiceEmptyValidator
virtual bool TransferDataToWindow() override