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  * @author Maciej Suminski <maciej.suminski@cern.ch>
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, you may find one here:
19  * https://www.gnu.org/licenses/gpl-3.0.html
20  * or you may search the http://www.gnu.org website for the version 3 license,
21  * or you may write to the Free Software Foundation, Inc.,
22  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23  */
24 
25 #ifndef DIALOG_SPICE_MODEL_H
26 #define DIALOG_SPICE_MODEL_H
27 
29 
30 #include <sim/spice_value.h>
31 #include <sch_component.h>
32 
33 #include <wx/valnum.h>
34 
36 {
37 public:
38  DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent, SCH_FIELDS& aSchFields );
39 
40 private:
46  bool parsePowerSource( const wxString& aModel );
47 
54  bool generatePowerSource( wxString& aTarget ) const;
55 
62  void loadLibrary( const wxString& aFilePath );
63 
69  SCH_FIELD& getField( int aFieldType );
70 
77  bool addPwlValue( const wxString& aTime, const wxString& aValue );
78 
79  virtual bool TransferDataFromWindow() override;
80  virtual bool TransferDataToWindow() override;
81 
82  // The default dialog Validate() calls the validators of all widgets.
83  // This is not what we want; We want only validators of the selected page
84  // of the notbooks. So disable the wxDialog::Validate(), and let our
85  // TransferDataFromWindow doing the job.
86  virtual bool Validate() override
87  {
88  return true;
89  }
90 
91  virtual void onInitDlg( wxInitDialogEvent& event ) override
92  {
93  // Call the default wxDialog handler of a wxInitDialogEvent
95 
96  // Now all widgets have the size fixed, call FinishDialogSettings
98  }
99 
100  // Event handlers
101  void onSelectLibrary( wxCommandEvent& event ) override;
102  void onModelSelected( wxCommandEvent& event ) override;
103  void onPwlAdd( wxCommandEvent& event ) override;
104  void onPwlRemove( wxCommandEvent& event ) override;
105 
108 
111 
113  std::map<int, wxString> m_fieldsTmp;
114 
115  struct MODEL
116  {
118  int line;
119 
121  enum TYPE { UNKNOWN = -1, SUBCKT, BJT, MOSFET, DIODE } model;
122 
124  static TYPE parseModelType( const wxString& aValue );
125 
126  MODEL( int aLine, enum TYPE aModel )
127  : line( aLine ), model( aModel )
128  {
129  }
130  };
131 
133  std::map<wxString, MODEL> m_models;
134 
137 
140  wxTextValidator m_notEmptyValidator;
141 };
142 
143 #endif /* DIALOG_SPICE_MODEL_H */
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
void onSelectLibrary(wxCommandEvent &event) override
SCH_COMPONENT & m_component
Edited component
SPICE_VALIDATOR m_spiceValidator
SCH_FIELD & getField(int aFieldType)
Returns or creates a field in the edited schematic fields vector.
virtual bool TransferDataFromWindow() override
bool addPwlValue(const wxString &aTime, const wxString &aValue)
Adds a value to the PWL values list.
void FinishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
MODEL(int aLine, enum TYPE aModel)
long m_pwlTimeCol
Column identifiers for PWL power source value list
bool generatePowerSource(wxString &aTarget) const
Generates a string to describe power source parameters, basing on the current selection.
bool parsePowerSource(const wxString &aModel)
Parse a string describing a power source, so appropriate settings are checked in the dialog...
virtual bool Validate() override
static TYPE parseModelType(const wxString &aValue)
Convert string to model
std::vector< SCH_FIELD > SCH_FIELDS
A container for several SCH_FIELD items.
Definition: sch_component.h:53
Helper class to recognize Spice formatted values
Definition: spice_value.h:146
DIALOG_SPICE_MODEL(wxWindow *aParent, SCH_COMPONENT &aComponent, SCH_FIELDS &aSchFields)
wxTextValidator m_notEmptyValidator
void onModelSelected(wxCommandEvent &event) override
std::map< int, wxString > m_fieldsTmp
Temporary field values
void onPwlRemove(wxCommandEvent &event) override
SCH_FIELDS & m_fields
Fields from the component properties dialog
void onPwlAdd(wxCommandEvent &event) override
enum DIALOG_SPICE_MODEL::MODEL::TYPE model
void loadLibrary(const wxString &aFilePath)
Loads a list of components (.model and .subckt) from a spice library file and adds them to a combo bo...
Definition the SCH_COMPONENT class for Eeschema.
Class DIALOG_SPICE_MODEL_BASE.
std::map< wxString, MODEL > m_models
Models available in the selected library file
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
int line
Line number in the library file
virtual void onInitDlg(wxInitDialogEvent &event) override
SPICE_VALIDATOR m_spiceEmptyValidator
virtual bool TransferDataToWindow() override