Browse Source
Sim Model Editor: Serialize models in fields
Sim Model Editor: Serialize models in fields
Implemented serialization and deserialization of models in symbol fields through the SIM_VALUE class. We don't carry the Spice legacy of case-insensitive suffixes, instead we conform to the SI standard (i.e. M is Mega, not milli, P is peta, p is pico). Parameter grid value validation is implemented by simply not allowing any characters that will make the value invalid (instead of highlighting the field in a red color). This will likely be changed at some point in the future.7.0
32 changed files with 1805 additions and 930 deletions
-
1eeschema/CMakeLists.txt
-
358eeschema/dialogs/dialog_spice_model.cpp
-
25eeschema/dialogs/dialog_spice_model.h
-
48eeschema/dialogs/dialog_spice_model_base.cpp
-
21eeschema/dialogs/dialog_spice_model_base.fbp
-
6eeschema/dialogs/dialog_spice_model_base.h
-
11eeschema/sch_symbol.cpp
-
8eeschema/sch_symbol.h
-
2eeschema/sim/ngspice.cpp
-
5eeschema/sim/ngspice.h
-
157eeschema/sim/ngspice_models.cpp
-
1019eeschema/sim/sim_model.cpp
-
54eeschema/sim/sim_model.h
-
15eeschema/sim/sim_model_behavioral.cpp
-
3eeschema/sim/sim_model_behavioral.h
-
13eeschema/sim/sim_model_codemodel.cpp
-
3eeschema/sim/sim_model_codemodel.h
-
20eeschema/sim/sim_model_ideal.cpp
-
5eeschema/sim/sim_model_ideal.h
-
22eeschema/sim/sim_model_ngspice.cpp
-
5eeschema/sim/sim_model_ngspice.h
-
13eeschema/sim/sim_model_rawspice.cpp
-
3eeschema/sim/sim_model_rawspice.h
-
35eeschema/sim/sim_model_source.cpp
-
3eeschema/sim/sim_model_source.h
-
14eeschema/sim/sim_model_subcircuit.cpp
-
3eeschema/sim/sim_model_subcircuit.h
-
185eeschema/sim/sim_property.cpp
-
80eeschema/sim/sim_property.h
-
457eeschema/sim/sim_value.cpp
-
137eeschema/sim/sim_value.h
-
4qa/unittests/eeschema/sim/test_ngspice.cpp
1019
eeschema/sim/sim_model.cpp
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,185 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2022 Mikolaj Wielgus |
|||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 3 |
|||
* 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: |
|||
* https://www.gnu.org/licenses/gpl-3.0.html
|
|||
* or you may search the http://www.gnu.org website for the version 3 license,
|
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#include <sim/sim_property.h>
|
|||
#include <sim/sim_value.h>
|
|||
#include <ki_exception.h>
|
|||
#include <confirm.h>
|
|||
#include <wx/combo.h>
|
|||
#include <wx/combobox.h>
|
|||
|
|||
|
|||
wxBEGIN_EVENT_TABLE( SIM_VALIDATOR, wxValidator ) |
|||
EVT_TEXT( wxID_ANY, SIM_VALIDATOR::onText ) |
|||
EVT_CHAR( SIM_VALIDATOR::onChar ) |
|||
EVT_MOUSE_EVENTS( SIM_VALIDATOR::onMouse ) |
|||
wxEND_EVENT_TABLE() |
|||
|
|||
|
|||
SIM_VALIDATOR::SIM_VALIDATOR( SIM_VALUE_BASE::TYPE aValueType, |
|||
SIM_VALUE_PARSER::NOTATION aNotation ) |
|||
: wxValidator(), |
|||
m_valueType( aValueType ), |
|||
m_notation( aNotation ) |
|||
{ |
|||
wxTextEntry* textEntry = getTextEntry(); |
|||
if( !textEntry ) |
|||
return; |
|||
|
|||
m_prevText = textEntry->GetValue(); |
|||
m_prevInsertionPoint = textEntry->GetInsertionPoint(); |
|||
} |
|||
|
|||
|
|||
wxObject* SIM_VALIDATOR::Clone() const |
|||
{ |
|||
return new SIM_VALIDATOR( *this ); |
|||
} |
|||
|
|||
|
|||
bool SIM_VALIDATOR::Validate( wxWindow* aParent ) |
|||
{ |
|||
if( !m_validatorWindow->IsEnabled() ) |
|||
return true; |
|||
|
|||
wxTextEntry* const textEntry = getTextEntry(); |
|||
if( !textEntry ) |
|||
return false; |
|||
|
|||
return isValid( textEntry->GetValue() ); |
|||
} |
|||
|
|||
|
|||
bool SIM_VALIDATOR::TransferToWindow() |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
|
|||
bool SIM_VALIDATOR::TransferFromWindow() |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
|
|||
bool SIM_VALIDATOR::isValid( const wxString& aString ) |
|||
{ |
|||
return SIM_VALUE_PARSER::IsValid( aString, m_valueType, m_notation ); |
|||
} |
|||
|
|||
|
|||
wxTextEntry* SIM_VALIDATOR::getTextEntry() |
|||
{ |
|||
// Taken from wxTextValidator.
|
|||
|
|||
if( wxDynamicCast( m_validatorWindow, wxTextCtrl ) ) |
|||
return ( wxTextCtrl* ) m_validatorWindow; |
|||
|
|||
if( wxDynamicCast( m_validatorWindow, wxComboBox ) ) |
|||
return ( wxComboBox* ) m_validatorWindow; |
|||
|
|||
if( wxDynamicCast( m_validatorWindow, wxComboCtrl ) ) |
|||
return ( wxComboCtrl* ) m_validatorWindow; |
|||
|
|||
wxFAIL_MSG( |
|||
"SIM_VALIDATOR can only be used with wxTextCtrl, wxComboBox, or wxComboCtrl" |
|||
); |
|||
|
|||
return nullptr; |
|||
} |
|||
|
|||
|
|||
void SIM_VALIDATOR::onText( wxCommandEvent& aEvent ) |
|||
{ |
|||
wxTextEntry* textEntry = getTextEntry(); |
|||
if( !textEntry ) |
|||
return; |
|||
|
|||
if( !isValid( textEntry->GetValue() ) ) |
|||
{ |
|||
textEntry->ChangeValue( m_prevText ); |
|||
textEntry->SetInsertionPoint( m_prevInsertionPoint ); |
|||
} |
|||
|
|||
m_prevText = textEntry->GetValue(); |
|||
m_prevInsertionPoint = textEntry->GetInsertionPoint(); |
|||
} |
|||
|
|||
|
|||
void SIM_VALIDATOR::onChar( wxKeyEvent& aEvent ) |
|||
{ |
|||
aEvent.Skip(); |
|||
|
|||
wxTextEntry* textEntry = getTextEntry(); |
|||
if( !textEntry ) |
|||
return; |
|||
|
|||
m_prevInsertionPoint = textEntry->GetInsertionPoint(); |
|||
} |
|||
|
|||
void SIM_VALIDATOR::onMouse( wxMouseEvent& aEvent ) |
|||
{ |
|||
aEvent.Skip(); |
|||
|
|||
wxTextEntry* textEntry = getTextEntry(); |
|||
if( !textEntry ) |
|||
return; |
|||
|
|||
m_prevInsertionPoint = textEntry->GetInsertionPoint(); |
|||
} |
|||
|
|||
|
|||
SIM_PROPERTY::SIM_PROPERTY( const wxString& aLabel, const wxString& aName, |
|||
SIM_VALUE_BASE& aValue, |
|||
SIM_VALUE_BASE::TYPE aValueType, |
|||
SIM_VALUE_PARSER::NOTATION aNotation ) |
|||
: wxStringProperty( aLabel, aName, aValue.ToString() ), |
|||
m_valueType( aValueType ), |
|||
m_notation( aNotation ), |
|||
m_value( aValue ) |
|||
{ |
|||
} |
|||
|
|||
|
|||
wxValidator* SIM_PROPERTY::DoGetValidator() const |
|||
{ |
|||
return new SIM_VALIDATOR( m_valueType, m_notation ); |
|||
} |
|||
|
|||
|
|||
bool SIM_PROPERTY::StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags ) const |
|||
{ |
|||
try |
|||
{ |
|||
m_value.FromString( aText ); |
|||
} |
|||
catch( KI_PARAM_ERROR& e ) |
|||
{ |
|||
aVariant = aText; |
|||
return false; |
|||
} |
|||
|
|||
aVariant = m_value.ToString(); |
|||
return true; |
|||
} |
@ -0,0 +1,80 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2022 Mikolaj Wielgus |
|||
* Copyright (C) 2022 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* This program is free software; you can redistribute it and/or |
|||
* modify it under the terms of the GNU General Public License |
|||
* as published by the Free Software Foundation; either version 3 |
|||
* 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: |
|||
* https://www.gnu.org/licenses/gpl-3.0.html |
|||
* or you may search the http://www.gnu.org website for the version 3 license, |
|||
* or you may write to the Free Software Foundation, Inc., |
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
|||
*/ |
|||
|
|||
#ifndef SIM_PROPERTY_H |
|||
#define SIM_PROPERTY_H |
|||
|
|||
#include <sim/sim_value.h> |
|||
#include <wx/propgrid/props.h> |
|||
|
|||
|
|||
class SIM_VALIDATOR : public wxValidator |
|||
{ |
|||
public: |
|||
SIM_VALIDATOR( SIM_VALUE_BASE::TYPE aValueType, SIM_VALUE_PARSER::NOTATION aNotation ); |
|||
SIM_VALIDATOR( const SIM_VALIDATOR& aValidator ) = default; |
|||
|
|||
wxObject* Clone() const override; |
|||
|
|||
bool Validate( wxWindow* aParent ) override; |
|||
bool TransferToWindow() override; |
|||
bool TransferFromWindow() override; |
|||
|
|||
private: |
|||
bool isValid( const wxString& aString ); |
|||
|
|||
wxTextEntry* getTextEntry(); |
|||
|
|||
void onText( wxCommandEvent& aEvent ); |
|||
void onChar( wxKeyEvent& aEvent ); |
|||
void onMouse( wxMouseEvent& aEvent ); |
|||
|
|||
SIM_VALUE_BASE::TYPE m_valueType; |
|||
SIM_VALUE_PARSER::NOTATION m_notation; |
|||
wxString m_prevText; |
|||
long m_prevInsertionPoint; |
|||
|
|||
wxDECLARE_EVENT_TABLE(); |
|||
}; |
|||
|
|||
|
|||
class SIM_PROPERTY : public wxStringProperty |
|||
{ |
|||
public: |
|||
SIM_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_VALUE_BASE& aValue, |
|||
SIM_VALUE_BASE::TYPE aValueType = SIM_VALUE_BASE::TYPE::FLOAT, |
|||
SIM_VALUE_PARSER::NOTATION aNotation = SIM_VALUE_PARSER::NOTATION::SI ); |
|||
|
|||
wxValidator* DoGetValidator() const override; |
|||
|
|||
bool StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags = 0 ) |
|||
const override; |
|||
|
|||
protected: |
|||
SIM_VALUE_BASE::TYPE m_valueType; |
|||
SIM_VALUE_PARSER::NOTATION m_notation; |
|||
SIM_VALUE_BASE& m_value; |
|||
}; |
|||
|
|||
#endif // SIM_PROPERTY_H |
Write
Preview
Loading…
Cancel
Save
Reference in new issue