Tuners are common for all plots

This commit is contained in:
Maciej Suminski 2016-08-11 14:42:07 +02:00
parent 5772938a71
commit bf758dce3e
2 changed files with 29 additions and 69 deletions

View File

@ -167,6 +167,7 @@ void SIM_PLOT_FRAME::StartSimulation()
m_simulator->SetReporter( new SIM_THREAD_REPORTER( this ) ); m_simulator->SetReporter( new SIM_THREAD_REPORTER( this ) );
m_simulator->Init(); m_simulator->Init();
m_simulator->LoadNetlist( formatter.GetString() ); m_simulator->LoadNetlist( formatter.GetString() );
applyTuners();
m_simulator->Run(); m_simulator->Run();
Layout(); Layout();
@ -229,23 +230,22 @@ void SIM_PLOT_FRAME::AddTuner( SCH_COMPONENT* aComponent )
return; return;
const wxString& componentName = aComponent->GetField( REFERENCE )->GetText(); const wxString& componentName = aComponent->GetField( REFERENCE )->GetText();
auto& tunerList = m_plots[plotPanel].m_tuners;
// Do not add multiple instances for the same component // Do not add multiple instances for the same component
auto tunerIt = std::find_if( tunerList.begin(), tunerList.end(), [&]( const TUNER_SLIDER* t ) auto tunerIt = std::find_if( m_tuners.begin(), m_tuners.end(), [&]( const TUNER_SLIDER* t )
{ {
return t->GetComponentName() == componentName; return t->GetComponentName() == componentName;
} }
); );
if( tunerIt != tunerList.end() ) if( tunerIt != m_tuners.end() )
return; // We already have it return; // We already have it
try try
{ {
TUNER_SLIDER* tuner = new TUNER_SLIDER( this, m_sidePanel, aComponent ); TUNER_SLIDER* tuner = new TUNER_SLIDER( this, m_sidePanel, aComponent );
m_tuneSizer->Add( tuner ); m_tuneSizer->Add( tuner );
tunerList.push_back( tuner ); m_tuners.push_back( tuner );
m_sidePanel->Layout(); m_sidePanel->Layout();
} }
catch( ... ) catch( ... )
@ -257,12 +257,7 @@ void SIM_PLOT_FRAME::AddTuner( SCH_COMPONENT* aComponent )
void SIM_PLOT_FRAME::RemoveTuner( TUNER_SLIDER* aTuner ) void SIM_PLOT_FRAME::RemoveTuner( TUNER_SLIDER* aTuner )
{ {
SIM_PLOT_PANEL* plotPanel = CurrentPlot(); m_tuners.remove( aTuner );
if( !plotPanel )
return;
m_plots[plotPanel].m_tuners.remove( aTuner );
aTuner->Destroy(); aTuner->Destroy();
m_sidePanel->Layout(); m_sidePanel->Layout();
} }
@ -427,34 +422,24 @@ void SIM_PLOT_FRAME::updateSignalList()
} }
void SIM_PLOT_FRAME::updateTuners()
{
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
if( !plotPanel )
return;
for( unsigned int i = 0; i < m_tuneSizer->GetItemCount(); ++i )
m_tuneSizer->Hide( i );
m_tuneSizer->Clear();
for( auto& tuner : m_plots[plotPanel].m_tuners )
{
m_tuneSizer->Add( tuner );
tuner->Show();
}
Layout();
}
void SIM_PLOT_FRAME::updateCursors() void SIM_PLOT_FRAME::updateCursors()
{ {
wxQueueEvent( this, new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) ); wxQueueEvent( this, new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
} }
void SIM_PLOT_FRAME::applyTuners()
{
for( auto& tuner : m_tuners )
{
/// @todo no ngspice hardcoding
std::string command( "alter @" + tuner->GetSpiceName()
+ "=" + tuner->GetValue().ToSpiceString() );
m_simulator->Command( command );
}
}
SIM_PLOT_TYPE SIM_PLOT_FRAME::GetXAxisType( SIM_TYPE aType ) const SIM_PLOT_TYPE SIM_PLOT_FRAME::GetXAxisType( SIM_TYPE aType ) const
{ {
switch( aType ) switch( aType )
@ -612,7 +597,6 @@ void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
m_plots.erase( plotPanel ); m_plots.erase( plotPanel );
updateSignalList(); updateSignalList();
updateTuners();
updateCursors(); updateCursors();
} }
@ -620,7 +604,6 @@ void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event ) void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event )
{ {
updateSignalList(); updateSignalList();
updateTuners();
updateCursors(); updateCursors();
} }
@ -803,21 +786,8 @@ void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent )
StopSimulation(); StopSimulation();
m_simConsole->Clear(); m_simConsole->Clear();
// Do not export netlist, it is already stored in the simulator
// Apply tuned values applyTuners();
if( SIM_PLOT_PANEL* plotPanel = CurrentPlot() )
{
for( auto& tuner : m_plots[plotPanel].m_tuners )
{
/// @todo no ngspice hardcoding
std::string command( "alter @" + tuner->GetSpiceName()
+ "=" + tuner->GetValue().ToSpiceString() );
m_simulator->Command( command );
// printf("CMD: %s\n", command.c_str() );
}
}
m_simulator->Run(); m_simulator->Run();
} }
@ -830,13 +800,6 @@ void SIM_PLOT_FRAME::onSimReport( wxCommandEvent& aEvent )
} }
SIM_PLOT_FRAME::PLOT_INFO::~PLOT_INFO()
{
for( auto& t : m_tuners )
t->Destroy();
}
SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU( const wxString& aSignal,
SIM_PLOT_FRAME* aPlotFrame ) SIM_PLOT_FRAME* aPlotFrame )
: m_signal( aSignal ), m_plotFrame( aPlotFrame ) : m_signal( aSignal ), m_plotFrame( aPlotFrame )

View File

@ -167,16 +167,16 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
*/ */
void updateSignalList(); void updateSignalList();
/**
* @brief Fills the tuners area with the ones related to the current plot.
*/
void updateTuners();
/** /**
* @brief Updates the cursor values list. * @brief Updates the cursor values list.
*/ */
void updateCursors(); void updateCursors();
/**
* @brief Applies component values specified using tunder sliders to the current netlist.
*/
void applyTuners();
SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const; SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const;
// Menu handlers // Menu handlers
@ -231,22 +231,19 @@ class SIM_PLOT_FRAME : public SIM_PLOT_FRAME_BASE
std::unique_ptr<SPICE_SIMULATOR> m_simulator; std::unique_ptr<SPICE_SIMULATOR> m_simulator;
typedef std::map<wxString, TRACE_DESC> TRACE_MAP; typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
typedef std::list<TUNER_SLIDER*> TUNER_LIST;
class PLOT_INFO struct PLOT_INFO
{ {
public:
~PLOT_INFO();
///> List of component value tuners
TUNER_LIST m_tuners;
///> Map of the traces displayed on the plot ///> Map of the traces displayed on the plot
TRACE_MAP m_traces; TRACE_MAP m_traces;
}; };
///> Map of plot panels and associated data
std::map<SIM_PLOT_PANEL*, PLOT_INFO> m_plots; std::map<SIM_PLOT_PANEL*, PLOT_INFO> m_plots;
///> List of currently displayed tuners
std::list<TUNER_SLIDER*> m_tuners;
// Trick to preserve settings between runs // Trick to preserve settings between runs
DIALOG_SIM_SETTINGS m_settingsDlg; DIALOG_SIM_SETTINGS m_settingsDlg;