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 
30 
31 #include <sim/spice_value.h>
32 #include <sch_component.h>
33 #include <sch_field.h>
34 #include <lib_field.h>
35 
36 #include <wx/valnum.h>
37 
39 {
40 public:
41  DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent, SCH_FIELDS* aSchFields );
42  DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_COMPONENT& aComponent, LIB_FIELDS* aLibFields );
43 
44 private:
50  bool parsePowerSource( const wxString& aModel );
51 
58  bool generatePowerSource( wxString& aTarget ) const;
59 
66  void loadLibrary( const wxString& aFilePath );
67 
73  SCH_FIELD& getSchField( int aFieldType );
74  LIB_FIELD& getLibField( int aFieldType );
75 
82  bool addPwlValue( const wxString& aTime, const wxString& aValue );
83 
84  virtual bool TransferDataFromWindow() override;
85  virtual bool TransferDataToWindow() override;
86 
87  // The default dialog Validate() calls the validators of all widgets.
88  // This is not what we want; We want only validators of the selected page
89  // of the notbooks. So disable the wxDialog::Validate(), and let our
90  // TransferDataFromWindow doing the job.
91  virtual bool Validate() override
92  {
93  return true;
94  }
95 
96  virtual void onInitDlg( wxInitDialogEvent& event ) override
97  {
98  // Call the default wxDialog handler of a wxInitDialogEvent
100 
101  // Now all widgets have the size fixed, call FinishDialogSettings
103  }
104 
108  void Init();
109 
110  // Event handlers
111  void onSelectLibrary( wxCommandEvent& event ) override;
112  void onModelSelected( wxCommandEvent& event ) override;
113  void onPwlAdd( wxCommandEvent& event ) override;
114  void onPwlRemove( wxCommandEvent& event ) override;
115 
118 
123 
125  std::map<int, wxString> m_fieldsTmp;
126 
127  struct MODEL
128  {
130  int line;
131 
134 
136  static SPICE_PRIMITIVE parseModelType( const wxString& aValue );
137 
138  MODEL( int aLine, enum SPICE_PRIMITIVE aModel )
139  : line( aLine ), model( aModel )
140  {
141  }
142  };
143 
145  std::map<wxString, MODEL> m_models;
146 
149 
152  wxTextValidator m_notEmptyValidator;
153 };
154 
155 #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
void Init()
Initializes the internal settings.
SCH_COMPONENT & m_component
Edited component
bool generatePowerSource(wxString &aTarget) const
Generates a string to describe power source parameters, basing on the current selection.
static SPICE_PRIMITIVE parseModelType(const wxString &aValue)
Convert string to model
SPICE_VALIDATOR m_spiceValidator
virtual bool TransferDataFromWindow() override
Field object used in symbol libraries.
Definition: lib_field.h:59
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...
long m_pwlTimeCol
Column identifiers for PWL power source value 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
SCH_FIELDS * m_schfields
Fields from the component properties dialog
std::vector< SCH_FIELD > SCH_FIELDS
A container for several SCH_FIELD items.
Definition: sch_component.h:54
Helper class to recognize Spice formatted values
Definition: spice_value.h:146
SCH_FIELD & getSchField(int aFieldType)
Returns or creates a field in the edited schematic fields vector.
wxTextValidator m_notEmptyValidator
void onModelSelected(wxCommandEvent &event) override
std::map< int, wxString > m_fieldsTmp
Temporary field values
void onPwlRemove(wxCommandEvent &event) override
void onPwlAdd(wxCommandEvent &event) override
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...
SPICE_PRIMITIVE model
Type of the device
Definition the SCH_COMPONENT class for Eeschema.
Class DIALOG_SPICE_MODEL_BASE.
DIALOG_SPICE_MODEL(wxWindow *aParent, SCH_COMPONENT &aComponent, SCH_FIELDS *aSchFields)
SPICE_PRIMITIVE
Basic Spice component primitives
MODEL(int aLine, enum SPICE_PRIMITIVE aModel)
std::map< wxString, MODEL > m_models
Models available in the selected library file
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:259
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:70
int line
Line number in the library file
Definition of the SCH_FIELD class for Eeschema.
virtual void onInitDlg(wxInitDialogEvent &event) override
SPICE_VALIDATOR m_spiceEmptyValidator
virtual bool TransferDataToWindow() override