2016-08-11 12:41:40 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2017-10-26 17:54:53 +00:00
|
|
|
* Copyright (C) 2016-2017 CERN
|
2021-01-26 15:23:37 +00:00
|
|
|
* Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
2016-08-11 12:41:40 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DIALOG_SPICE_MODEL_H
|
|
|
|
#define DIALOG_SPICE_MODEL_H
|
|
|
|
|
|
|
|
#include "dialog_spice_model_base.h"
|
2018-09-22 14:05:32 +00:00
|
|
|
#include "netlist_exporter_pspice.h"
|
2016-08-11 12:41:56 +00:00
|
|
|
|
|
|
|
#include <sim/spice_value.h>
|
2021-02-24 13:48:02 +00:00
|
|
|
#include <sch_symbol.h>
|
2019-01-10 05:42:14 +00:00
|
|
|
#include <sch_field.h>
|
|
|
|
#include <lib_field.h>
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2016-08-11 12:41:56 +00:00
|
|
|
#include <wx/valnum.h>
|
|
|
|
|
2016-08-11 12:41:40 +00:00
|
|
|
class DIALOG_SPICE_MODEL : public DIALOG_SPICE_MODEL_BASE
|
|
|
|
{
|
|
|
|
public:
|
2021-06-10 14:10:55 +00:00
|
|
|
DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
|
2020-12-15 15:06:19 +00:00
|
|
|
std::vector<SCH_FIELD>* aSchFields );
|
2021-06-10 14:10:55 +00:00
|
|
|
DIALOG_SPICE_MODEL( wxWindow* aParent, SCH_SYMBOL& aSymbol,
|
2020-12-15 15:06:19 +00:00
|
|
|
std::vector<LIB_FIELD>* aLibFields );
|
2016-08-11 12:41:40 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Parse a string describing a power source, so appropriate settings are checked in the dialog.
|
|
|
|
*
|
2016-08-11 12:41:40 +00:00
|
|
|
* @param aModel contains the string to be parse (e.g. sin(0 1 10k))
|
|
|
|
* @return True if the input string was parsed without errors.
|
|
|
|
*/
|
|
|
|
bool parsePowerSource( const wxString& aModel );
|
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Generate a string to describe power source parameters, basing on the current selection.
|
|
|
|
*
|
2016-08-11 12:41:40 +00:00
|
|
|
* If there are missing fields, it will not modify the target string.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2016-08-11 12:41:40 +00:00
|
|
|
* @param aTarget is the destination for the generated string.
|
|
|
|
* @return True if the string was saved successfully.
|
|
|
|
*/
|
2021-07-16 20:13:26 +00:00
|
|
|
bool generatePowerSource( wxString& aTarget );
|
2016-08-11 12:41:40 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Load a list of components (.model and .subckt) from a spice library file and add them to
|
|
|
|
* a combo box.
|
|
|
|
*
|
2016-08-11 12:41:40 +00:00
|
|
|
* @param aComboBox is the target combo box
|
2017-10-26 17:49:57 +00:00
|
|
|
* @param aFilePath is path to the library file
|
2016-08-11 12:41:40 +00:00
|
|
|
*/
|
2017-10-26 17:54:53 +00:00
|
|
|
void loadLibrary( const wxString& aFilePath );
|
2016-08-11 12:41:40 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Return or create a field in the edited schematic fields vector.
|
|
|
|
*
|
2016-08-11 12:41:40 +00:00
|
|
|
* @param aFieldType is an SPICE_FIELD enum value.
|
|
|
|
* @return Requested field.
|
|
|
|
*/
|
2019-01-10 05:42:14 +00:00
|
|
|
SCH_FIELD& getSchField( int aFieldType );
|
|
|
|
LIB_FIELD& getLibField( int aFieldType );
|
2016-08-11 12:41:40 +00:00
|
|
|
|
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Add a value to the PWL values list.
|
|
|
|
*
|
2016-08-11 12:41:40 +00:00
|
|
|
* @param aTime is the time value.
|
|
|
|
* @param aValue is the source value at the given time.
|
|
|
|
* @return True if request has completed successfully, false if the data is invalid.
|
|
|
|
*/
|
|
|
|
bool addPwlValue( const wxString& aTime, const wxString& aValue );
|
|
|
|
|
2016-09-17 12:38:34 +00:00
|
|
|
virtual bool TransferDataFromWindow() override;
|
|
|
|
virtual bool TransferDataToWindow() override;
|
|
|
|
|
|
|
|
// The default dialog Validate() calls the validators of all widgets.
|
|
|
|
// This is not what we want; We want only validators of the selected page
|
2021-01-26 15:23:37 +00:00
|
|
|
// of the notebooks. So disable the wxDialog::Validate(), and let our
|
2016-09-17 12:38:34 +00:00
|
|
|
// TransferDataFromWindow doing the job.
|
|
|
|
virtual bool Validate() override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2016-08-20 15:25:51 +00:00
|
|
|
virtual void onInitDlg( wxInitDialogEvent& event ) override
|
|
|
|
{
|
|
|
|
// Call the default wxDialog handler of a wxInitDialogEvent
|
|
|
|
TransferDataToWindow();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2016-08-20 15:25:51 +00:00
|
|
|
}
|
|
|
|
|
2019-01-10 05:42:14 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Initialize the internal settings.
|
2019-01-10 05:42:14 +00:00
|
|
|
*/
|
|
|
|
void Init();
|
|
|
|
|
2020-05-23 07:48:05 +00:00
|
|
|
/**
|
|
|
|
* Display a note info about pin order
|
|
|
|
*/
|
|
|
|
void showPinOrderNote( int aModelType );
|
|
|
|
|
2016-08-11 12:41:40 +00:00
|
|
|
// Event handlers
|
2017-10-26 17:54:53 +00:00
|
|
|
void onSelectLibrary( wxCommandEvent& event ) override;
|
|
|
|
void onModelSelected( wxCommandEvent& event ) override;
|
2016-08-11 12:41:40 +00:00
|
|
|
void onPwlAdd( wxCommandEvent& event ) override;
|
|
|
|
void onPwlRemove( wxCommandEvent& event ) override;
|
2020-03-23 16:49:21 +00:00
|
|
|
void onRandomSourceType( wxCommandEvent& event ) override;
|
2020-05-23 07:48:05 +00:00
|
|
|
void onTypeSelected( wxCommandEvent& event ) override;
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
///< Edited symbol
|
2021-06-10 14:10:55 +00:00
|
|
|
SCH_SYMBOL& m_symbol;
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2021-06-14 18:00:08 +00:00
|
|
|
///< Fields from the symbol properties dialog.
|
2020-12-15 15:06:19 +00:00
|
|
|
std::vector<SCH_FIELD>* m_schfields;
|
|
|
|
std::vector<LIB_FIELD>* m_libfields;
|
2019-01-10 05:42:14 +00:00
|
|
|
bool m_useSchFields;
|
2016-08-11 12:41:40 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Temporary field values
|
2016-08-11 12:41:40 +00:00
|
|
|
std::map<int, wxString> m_fieldsTmp;
|
|
|
|
|
2017-10-26 17:54:53 +00:00
|
|
|
struct MODEL
|
|
|
|
{
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Line number in the library file
|
2017-10-26 17:54:53 +00:00
|
|
|
int line;
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Type of the device
|
2018-09-22 14:05:32 +00:00
|
|
|
SPICE_PRIMITIVE model;
|
2017-10-26 17:54:53 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Convert string to model
|
2018-09-22 14:05:32 +00:00
|
|
|
static SPICE_PRIMITIVE parseModelType( const wxString& aValue );
|
2017-10-26 17:54:53 +00:00
|
|
|
|
2018-09-22 14:05:32 +00:00
|
|
|
MODEL( int aLine, enum SPICE_PRIMITIVE aModel )
|
2017-10-26 17:54:53 +00:00
|
|
|
: line( aLine ), model( aModel )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Models available in the selected library file
|
2017-10-26 17:54:53 +00:00
|
|
|
std::map<wxString, MODEL> m_models;
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Column identifiers for PWL power source value list
|
2016-08-11 12:41:40 +00:00
|
|
|
long m_pwlTimeCol, m_pwlValueCol;
|
2016-08-11 12:41:56 +00:00
|
|
|
|
|
|
|
SPICE_VALIDATOR m_spiceValidator;
|
|
|
|
SPICE_VALIDATOR m_spiceEmptyValidator;
|
|
|
|
wxTextValidator m_notEmptyValidator;
|
2016-08-11 12:41:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* DIALOG_SPICE_MODEL_H */
|