Simulation settings combo boxes are filled with net/power source choices
This commit is contained in:
parent
95ca3914ce
commit
2b1784cfc6
|
@ -183,6 +183,7 @@ set( EESCHEMA_SRCS
|
|||
sim/sim_plot_panel.cpp
|
||||
sim/spice_simulator.cpp
|
||||
sim/ngspice.cpp
|
||||
sim/netlist_exporter_pspice_sim.cpp
|
||||
dialogs/dialog_sim_settings.cpp
|
||||
dialogs/dialog_sim_settings_base.cpp
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
*/
|
||||
|
||||
#include "dialog_sim_settings.h"
|
||||
#include <wx/log.h>
|
||||
#include <sim/netlist_exporter_pspice_sim.h>
|
||||
|
||||
/// @todo ngspice offers more types of analysis,
|
||||
//so there are a few tabs missing (e.g. pole-zero, distortion, sensitivity)
|
||||
|
@ -167,6 +167,68 @@ bool DIALOG_SIM_SETTINGS::TransferDataToWindow()
|
|||
}
|
||||
|
||||
|
||||
int DIALOG_SIM_SETTINGS::ShowModal()
|
||||
{
|
||||
// Fill out comboboxes that allow to select nets
|
||||
// Map comoboxes to their current values
|
||||
std::map<wxComboBox*, wxString> cmbNet = {
|
||||
{ m_noiseMeas, m_noiseMeas->GetStringSelection() },
|
||||
{ m_noiseRef, m_noiseRef->GetStringSelection() }
|
||||
};
|
||||
|
||||
for( auto c : cmbNet )
|
||||
c.first->Clear();
|
||||
|
||||
for( auto net : m_exporter->GetNetIndexMap() )
|
||||
{
|
||||
for( auto c : cmbNet )
|
||||
c.first->Append( net.first );
|
||||
}
|
||||
|
||||
// Try to restore the previous selection, if possible
|
||||
for( auto c : cmbNet )
|
||||
{
|
||||
int idx = c.first->FindString( c.second );
|
||||
|
||||
if( idx != wxNOT_FOUND )
|
||||
c.first->SetSelection( idx );
|
||||
}
|
||||
|
||||
|
||||
// Fill out comboboxes that allow to select power sources
|
||||
std::map<wxComboBox*, wxString> cmbSrc = {
|
||||
{ m_dcSource1, m_dcSource1->GetStringSelection() },
|
||||
{ m_dcSource2, m_dcSource2->GetStringSelection() },
|
||||
{ m_noiseSrc, m_noiseSrc->GetStringSelection() },
|
||||
};
|
||||
|
||||
for( auto c : cmbSrc )
|
||||
c.first->Clear();
|
||||
|
||||
for( auto item : m_exporter->GetSpiceItems() )
|
||||
{
|
||||
if( item.m_primitive == 'V' )
|
||||
{
|
||||
for( auto c : cmbSrc )
|
||||
c.first->Append( item.m_refName );
|
||||
}
|
||||
}
|
||||
|
||||
// Try to restore the previous selection, if possible
|
||||
for( auto c : cmbSrc )
|
||||
{
|
||||
int idx = c.first->FindString( c.second );
|
||||
|
||||
if( idx != wxNOT_FOUND )
|
||||
c.first->SetSelection( idx );
|
||||
}
|
||||
|
||||
return DIALOG_SIM_SETTINGS_BASE::ShowModal();
|
||||
}
|
||||
|
||||
|
||||
void DIALOG_SIM_SETTINGS::onLoadDirectives( wxCommandEvent& event )
|
||||
{
|
||||
if( m_exporter )
|
||||
m_customTxt->SetValue( m_exporter->GetSheetSimCommand() );
|
||||
}
|
||||
|
|
|
@ -48,6 +48,8 @@ public:
|
|||
bool TransferDataFromWindow() override;
|
||||
bool TransferDataToWindow() override;
|
||||
|
||||
int ShowModal() override;
|
||||
|
||||
private:
|
||||
enum SCALE_TYPE
|
||||
{
|
||||
|
|
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 CERN
|
||||
* @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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* 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:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include "netlist_exporter_pspice_sim.h"
|
||||
|
||||
wxString NETLIST_EXPORTER_PSPICE_SIM::GetSheetSimCommand()
|
||||
{
|
||||
wxString simCmd;
|
||||
|
||||
UpdateDirectives( NET_ALL_FLAGS );
|
||||
|
||||
for( const auto& dir : GetDirectives() )
|
||||
{
|
||||
if( isSimCommand( dir ) )
|
||||
simCmd += wxString::Format( "%s\r\n", dir );
|
||||
}
|
||||
|
||||
return simCmd;
|
||||
}
|
||||
|
||||
|
||||
void NETLIST_EXPORTER_PSPICE_SIM::writeDirectives( OUTPUTFORMATTER* aFormatter, unsigned aCtl ) const
|
||||
{
|
||||
if( m_simCommand.IsEmpty() )
|
||||
{
|
||||
// Fallback to the default behavior and just write all directives
|
||||
NETLIST_EXPORTER_PSPICE::writeDirectives( aFormatter, aCtl );
|
||||
}
|
||||
|
||||
// Dump all directives, but simulation commands
|
||||
for( const auto& dir : GetDirectives() )
|
||||
{
|
||||
if( !isSimCommand( dir ) )
|
||||
aFormatter->Print( 0, "%s\n", (const char*) dir.c_str() );
|
||||
}
|
||||
|
||||
// Finish with our custom simulation command
|
||||
aFormatter->Print( 0, "%s\n", (const char*) m_simCommand.c_str() );
|
||||
}
|
||||
|
||||
|
||||
bool NETLIST_EXPORTER_PSPICE_SIM::isSimCommand( const wxString& aCmd )
|
||||
{
|
||||
const std::vector<wxString> simCmds = {
|
||||
".ac", ".dc", ".disto", ".noise", ".op", ".pz", ".sens", ".tf", ".tran", ".pss"
|
||||
};
|
||||
|
||||
wxString lcaseCmd = aCmd.Lower();
|
||||
|
||||
for( const auto& c : simCmds )
|
||||
{
|
||||
if( lcaseCmd.StartsWith( c ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2016 CERN
|
||||
* @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
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* 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:
|
||||
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
* or you may search the http://www.gnu.org website for the version 2 license,
|
||||
* or you may write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#ifndef NETLIST_EXPORTER_PSPICE_SIM_H
|
||||
#define NETLIST_EXPORTER_PSPICE_SIM_H
|
||||
|
||||
#include <netlist_exporters/netlist_exporter_pspice.h>
|
||||
|
||||
/// Special netlist exporter flavor that allows to override simulation commands
|
||||
class NETLIST_EXPORTER_PSPICE_SIM : public NETLIST_EXPORTER_PSPICE
|
||||
{
|
||||
public:
|
||||
NETLIST_EXPORTER_PSPICE_SIM( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs,
|
||||
SEARCH_STACK* aPaths = NULL ) :
|
||||
NETLIST_EXPORTER_PSPICE( aMasterList, aLibs, aPaths )
|
||||
{
|
||||
}
|
||||
|
||||
void SetSimCommand( const wxString& aCmd )
|
||||
{
|
||||
m_simCommand = aCmd;
|
||||
}
|
||||
|
||||
const wxString& GetSimCommand() const
|
||||
{
|
||||
return m_simCommand;
|
||||
}
|
||||
|
||||
void ClearSimCommand()
|
||||
{
|
||||
m_simCommand.Clear();
|
||||
}
|
||||
|
||||
wxString GetSheetSimCommand();
|
||||
|
||||
protected:
|
||||
void writeDirectives( OUTPUTFORMATTER* aFormatter, unsigned aCtl ) const override;
|
||||
|
||||
private:
|
||||
static bool isSimCommand( const wxString& aCmd );
|
||||
|
||||
///> Overridden simulation command
|
||||
wxString m_simCommand;
|
||||
};
|
||||
|
||||
#endif /* NETLIST_EXPORTER_PSPICE_SIM_H */
|
|
@ -27,8 +27,7 @@
|
|||
#include <eeschema_id.h>
|
||||
#include <kiway.h>
|
||||
|
||||
#include <netlist_exporter_kicad.h>
|
||||
#include <netlist_exporters/netlist_exporter_pspice.h>
|
||||
#include "netlist_exporter_pspice_sim.h"
|
||||
|
||||
#include "sim_plot_frame.h"
|
||||
#include "sim_plot_panel.h"
|
||||
|
@ -74,73 +73,6 @@ private:
|
|||
};
|
||||
|
||||
|
||||
/// Special netlist exporter flavor that allows to override simulation commands
|
||||
class NETLIST_EXPORTER_PSPICE_SIM : public NETLIST_EXPORTER_PSPICE
|
||||
{
|
||||
public:
|
||||
NETLIST_EXPORTER_PSPICE_SIM( NETLIST_OBJECT_LIST* aMasterList, PART_LIBS* aLibs,
|
||||
SEARCH_STACK* aPaths = NULL ) :
|
||||
NETLIST_EXPORTER_PSPICE( aMasterList, aLibs, aPaths )
|
||||
{
|
||||
}
|
||||
|
||||
void SetSimCommand( const wxString& aCmd )
|
||||
{
|
||||
m_simCommand = aCmd;
|
||||
}
|
||||
|
||||
const wxString& GetSimCommand() const
|
||||
{
|
||||
return m_simCommand;
|
||||
}
|
||||
|
||||
void ClearSimCommand()
|
||||
{
|
||||
m_simCommand.Clear();
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void writeDirectives( OUTPUTFORMATTER* aFormatter, int aCtl ) const
|
||||
{
|
||||
if( m_simCommand.IsEmpty() )
|
||||
{
|
||||
// Fallback to the default behavior
|
||||
NETLIST_EXPORTER_PSPICE::writeDirectives( aFormatter, aCtl );
|
||||
}
|
||||
|
||||
// Dump all directives, but simulation commands
|
||||
for( const auto& dir : GetDirectives() )
|
||||
{
|
||||
if( !isSimCommand( dir ) )
|
||||
aFormatter->Print( 0, "%s\n", (const char*) dir.c_str() );
|
||||
}
|
||||
|
||||
// Finish with our custom simulation command
|
||||
aFormatter->Print( 0, "%s\n", (const char*) m_simCommand.c_str() );
|
||||
}
|
||||
|
||||
private:
|
||||
bool isSimCommand( const wxString& aCmd ) const
|
||||
{
|
||||
const std::vector<wxString> simCmds = {
|
||||
".ac", ".dc", ".disto", ".noise", ".op", ".pz", ".sens", ".tf", ".tran", ".pss"
|
||||
};
|
||||
|
||||
wxString lcaseCmd = aCmd.Lower();
|
||||
|
||||
for( const auto& c : simCmds )
|
||||
{
|
||||
if( lcaseCmd.StartsWith( c ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
wxString m_simCommand;
|
||||
};
|
||||
|
||||
|
||||
SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
|
||||
: SIM_PLOT_FRAME_BASE( aParent ), m_settingsDlg( this )
|
||||
{
|
||||
|
@ -163,6 +95,8 @@ SIM_PLOT_FRAME::~SIM_PLOT_FRAME()
|
|||
|
||||
void SIM_PLOT_FRAME::StartSimulation()
|
||||
{
|
||||
STRING_FORMATTER formatter;
|
||||
|
||||
m_simConsole->Clear();
|
||||
|
||||
// TODO check if there is a valid simulation command
|
||||
|
@ -172,13 +106,9 @@ void SIM_PLOT_FRAME::StartSimulation()
|
|||
m_simulator->SetReporter( new SIM_THREAD_REPORTER( this ) );
|
||||
m_simulator->Init();
|
||||
|
||||
NETLIST_OBJECT_LIST* net_atoms = m_schematicFrame->BuildNetListBase();
|
||||
STRING_FORMATTER formatter;
|
||||
|
||||
m_exporter.reset( new NETLIST_EXPORTER_PSPICE_SIM( net_atoms,
|
||||
Prj().SchLibs(), Prj().SchSearchS() ) );
|
||||
updateNetlistExporter();
|
||||
m_exporter->SetSimCommand( m_simCommand );
|
||||
m_exporter->Format( &formatter, GNL_ALL );
|
||||
m_exporter->Format( &formatter, NET_ALL_FLAGS );
|
||||
|
||||
m_simulator->LoadNetlist( formatter.GetString() );
|
||||
m_simulator->Run();
|
||||
|
@ -222,6 +152,13 @@ bool SIM_PLOT_FRAME::isSimulationRunning()
|
|||
}
|
||||
|
||||
|
||||
void SIM_PLOT_FRAME::updateNetlistExporter()
|
||||
{
|
||||
m_exporter.reset( new NETLIST_EXPORTER_PSPICE_SIM( m_schematicFrame->BuildNetListBase(),
|
||||
Prj().SchLibs(), Prj().SchSearchS() ) );
|
||||
}
|
||||
|
||||
|
||||
void SIM_PLOT_FRAME::updatePlot( const wxString& aSpiceName, const wxString& aName, SIM_PLOT_PANEL* aPanel )
|
||||
{
|
||||
auto data_y = m_simulator->GetPlot( (const char*) aSpiceName.c_str() );
|
||||
|
@ -415,12 +352,13 @@ void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event )
|
|||
|
||||
void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event )
|
||||
{
|
||||
// TODO set exporter
|
||||
updateNetlistExporter();
|
||||
m_exporter->ProcessNetlist( NET_ALL_FLAGS );
|
||||
|
||||
m_settingsDlg.SetNetlistExporter( m_exporter.get() );
|
||||
|
||||
if( m_settingsDlg.ShowModal() == wxID_OK )
|
||||
m_simCommand = m_settingsDlg.GetSimCommand();
|
||||
|
||||
wxLogDebug( "sim command = %s", m_simCommand ); // TODO remove
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -64,6 +64,8 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
|
|||
private:
|
||||
bool isSimulationRunning();
|
||||
|
||||
void updateNetlistExporter();
|
||||
|
||||
/**
|
||||
* @brief Updates plot in a particular SIM_PLOT_PANEL. If the panel does not contain
|
||||
* the plot, it will be added.
|
||||
|
|
Loading…
Reference in New Issue