eeschema: remove TRACE_DESC from SIM_WORKBOOK

This commit is contained in:
Sylwester Kocjan 2021-05-24 22:17:29 +02:00 committed by Wayne Stambaugh
parent 3ff670d2a4
commit 917e329bdf
7 changed files with 100 additions and 181 deletions

View File

@ -86,13 +86,8 @@ SIM_NOPLOT_PANEL::SIM_NOPLOT_PANEL( wxString aCommand, wxWindow* parent, wxWindo
m_textInfo->SetFont( wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_DEFAULT,
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_BOLD, false, wxEmptyString ) );
m_textInfo->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_GRAYTEXT ) );
//ST_UNKNOWN serves purpose of a welcome panel
m_textInfo->SetLabel(
( GetType() == ST_UNKNOWN )
? _( "Start the simulation by clicking the Run Simulation button" )
: _( "This simulation provide no plots. Please refer to console window for "
"results" ) );
_( "This simulation provide no plots. Please refer to console window for results" ) );
m_sizer->Add( m_textInfo, 1, wxALL | wxEXPAND, 5 );
m_sizer->Add( 0, 1, 1, wxEXPAND, 5 );

View File

@ -649,26 +649,22 @@ void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const
if( !plotPanel ) // Something is wrong
return;
TRACE_DESC descriptor( *m_exporter, aName, aType, aParam );
bool updated = false;
SIM_PLOT_TYPE xAxisType = GetXAxisType( simType );
if( xAxisType == SPT_LIN_FREQUENCY || xAxisType == SPT_LOG_FREQUENCY )
{
int baseType = descriptor.GetType() & ~( SPT_AC_MAG | SPT_AC_PHASE );
int baseType = aType & ~( SPT_AC_MAG | SPT_AC_PHASE );
// Add two plots: magnitude & phase
TRACE_DESC mag_desc( *m_exporter, descriptor, (SIM_PLOT_TYPE)( baseType | SPT_AC_MAG ) );
TRACE_DESC phase_desc( *m_exporter, descriptor,
(SIM_PLOT_TYPE)( baseType | SPT_AC_PHASE ) );
updated |= updatePlot( mag_desc, plotPanel );
updated |= updatePlot( phase_desc, plotPanel );
updated |=
updatePlot( aName, ( SIM_PLOT_TYPE )( baseType | SPT_AC_MAG ), aParam, plotPanel );
updated |= updatePlot( aName, ( SIM_PLOT_TYPE )( baseType | SPT_AC_PHASE ), aParam,
plotPanel );
}
else
{
updated = updatePlot( descriptor, plotPanel );
updated = updatePlot( aName, aType, aParam, plotPanel );
}
if( updated )
@ -708,11 +704,11 @@ void SIM_PLOT_FRAME::updateNetlistExporter()
}
bool SIM_PLOT_FRAME::updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel )
bool SIM_PLOT_FRAME::updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam,
SIM_PLOT_PANEL* aPanel )
{
SIM_TYPE simType = m_exporter->GetSimType();
wxString spiceVector = m_exporter->ComponentToVector(
aDescriptor.GetName(), aDescriptor.GetType(), aDescriptor.GetParam() );
wxString spiceVector = m_exporter->ComponentToVector( aName, aType, aParam );
if( !SIM_PANEL_BASE::IsPlottable( simType ) )
{
@ -734,19 +730,18 @@ bool SIM_PLOT_FRAME::updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL*
if( data_x.empty() )
return false;
SIM_PLOT_TYPE plotType = aDescriptor.GetType();
std::vector<double> data_y;
// Now, Y axis data
switch( m_exporter->GetSimType() )
{
case ST_AC:
wxASSERT_MSG( !( ( plotType & SPT_AC_MAG ) && ( plotType & SPT_AC_PHASE ) ),
wxASSERT_MSG( !( ( aType & SPT_AC_MAG ) && ( aType & SPT_AC_PHASE ) ),
"Cannot set both AC_PHASE and AC_MAG bits" );
if( plotType & SPT_AC_MAG )
if( aType & SPT_AC_MAG )
data_y = m_simulator->GetMagPlot( (const char*) spiceVector.c_str() );
else if( plotType & SPT_AC_PHASE )
else if( aType & SPT_AC_PHASE )
data_y = m_simulator->GetPhasePlot( (const char*) spiceVector.c_str() );
else
wxASSERT_MSG( false, "Plot type missing AC_PHASE or AC_MAG bit" );
@ -788,17 +783,15 @@ bool SIM_PLOT_FRAME::updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL*
for( size_t idx = 0; idx <= outer; idx++ )
{
name = wxString::Format( "%s (%s = %s V)", aDescriptor.GetTitle(),
source2.m_source, v.ToString() );
name = wxString::Format( "%s (%s = %s V)", aName, source2.m_source, v.ToString() );
std::vector<double> sub_x( data_x.begin() + offset,
data_x.begin() + offset + inner );
std::vector<double> sub_y( data_y.begin() + offset,
data_y.begin() + offset + inner );
if( aPanel->AddTrace( name, inner,
sub_x.data(), sub_y.data(), aDescriptor.GetType() ) )
m_workbook->AddTrace( aPanel, name, aDescriptor );
if( aPanel->AddTrace( name, inner, sub_x.data(), sub_y.data(), aType, aParam ) )
m_workbook->AddTrace( aPanel, name );
v = v + source2.m_vincrement;
offset += inner;
@ -809,9 +802,8 @@ bool SIM_PLOT_FRAME::updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL*
}
}
if( aPanel->AddTrace( aDescriptor.GetTitle(), size,
data_x.data(), data_y.data(), aDescriptor.GetType() ) )
m_workbook->AddTrace( aPanel, aDescriptor.GetTitle(), aDescriptor );
if( aPanel->AddTrace( aName, size, data_x.data(), data_y.data(), aType, aParam ) )
m_workbook->AddTrace( aPanel, aName );
updateFrame();
return true;
@ -876,7 +868,7 @@ void SIM_PLOT_FRAME::updateSignalList()
// calculated from the trace name index
int imgidx = 0;
for( const auto& trace : m_workbook->GetTraces( plotPanel ) )
for( const auto& trace : plotPanel->GetTraces() )
{
m_signals->InsertItem( imgidx, trace.first, imgidx );
imgidx++;
@ -1040,13 +1032,20 @@ bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath )
file.AddLine( wxString::Format( "%d", plotPanel->GetType() ) );
file.AddLine( plot.m_simCommand );
file.AddLine( wxString::Format( "%llu", plot.m_traces.size() ) );
for( const auto& trace : plot.m_traces )
const SIM_PLOT_PANEL* panel = dynamic_cast<const SIM_PLOT_PANEL*>( plotPanel );
if( !panel )
file.AddLine( wxString::Format( "%llu", 0ull ) );
else
{
file.AddLine( wxString::Format( "%d", trace.second.GetType() ) );
file.AddLine( trace.second.GetName() );
file.AddLine( trace.second.GetParam() );
file.AddLine( wxString::Format( "%llu", panel->GetTraces().size() ) );
for( const auto& trace : panel->GetTraces() )
{
file.AddLine( wxString::Format( "%d", trace.second->GetType() ) );
file.AddLine( trace.second->GetName() );
file.AddLine( trace.second->GetParam() );
}
}
}
@ -1653,18 +1652,37 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent )
SIM_PLOT_PANEL* plotPanel = dynamic_cast<SIM_PLOT_PANEL*>( plotPanelWindow );
wxCHECK_RET( plotPanel, "not a SIM_PLOT_PANEL" );
for( auto it = m_workbook->TracesBegin( plotPanel );
it != m_workbook->TracesEnd( plotPanel ); )
struct TRACE_DESC
{
if( !updatePlot( it->second, plotPanel ) )
///< Name of the measured net/device
wxString m_name;
///< Type of the signal
SIM_PLOT_TYPE m_type;
///< Name of the signal parameter
wxString m_param;
};
std::vector<struct TRACE_DESC> traceInfo;
// Get information about all the traces on the plot, remove and add again
for( auto& trace : plotPanel->GetTraces() )
{
struct TRACE_DESC placeholder;
placeholder.m_name = trace.second->GetName();
placeholder.m_type = trace.second->GetType();
placeholder.m_param = trace.second->GetParam();
traceInfo.push_back( placeholder );
}
for( auto& trace : traceInfo )
{
if( !updatePlot( trace.m_name, trace.m_type, trace.m_param, plotPanel ) )
{
removePlot( it->first, false );
it = m_workbook->RemoveTrace( plotPanel, it );
}
else
{
++it;
removePlot( trace.m_name, false );
m_workbook->RemoveTrace( plotPanel, trace.m_name );
}
}

View File

@ -203,7 +203,8 @@ private:
* @param aPanel is the panel that should receive the update.
* @return True if a plot was successfully added/updated.
*/
bool updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel );
bool updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam,
SIM_PLOT_PANEL* aPanel );
/**
* Update the list of currently plotted signals.

View File

@ -433,21 +433,27 @@ void SIM_PLOT_PANEL::UpdatePlotColors()
void SIM_PLOT_PANEL::UpdateTraceStyle( TRACE* trace )
{
int flags = trace->GetFlags();
wxPenStyle penStyle = ( ( flags & SPT_AC_PHASE || flags & SPT_CURRENT ) && m_dotted_cp ) ?
wxPENSTYLE_DOT :
wxPENSTYLE_SOLID;
int type = trace->GetType();
wxPenStyle penStyle = ( ( type & SPT_AC_PHASE || type & SPT_CURRENT ) && m_dotted_cp )
? wxPENSTYLE_DOT
: wxPENSTYLE_SOLID;
trace->SetPen( wxPen( trace->GetTraceColour(), 2, penStyle ) );
}
bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints,
const double* aX, const double* aY, SIM_PLOT_TYPE aFlags )
bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints, const double* aX,
const double* aY, SIM_PLOT_TYPE aType, const wxString& aParam )
{
TRACE* trace = NULL;
wxString name = aName;
if( aType & SPT_AC_MAG )
name += " (mag)";
else if( aType & SPT_AC_PHASE )
name += " (phase)";
// Find previous entry, if there is one
auto prev = m_traces.find( aName );
auto prev = m_traces.find( name );
bool addedNewEntry = ( prev == m_traces.end() );
if( addedNewEntry )
@ -458,7 +464,7 @@ bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints,
for( const auto& tr : m_traces )
{
if( !( tr.second->GetFlags() & SPT_CURRENT ) )
if( !( tr.second->GetType() & SPT_CURRENT ) )
{
hasVoltageTraces = true;
break;
@ -472,10 +478,10 @@ bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints,
}
// New entry
trace = new TRACE( aName );
trace = new TRACE( aName, aType, aParam );
trace->SetTraceColour( m_colors.GenerateColor( m_traces ) );
UpdateTraceStyle( trace );
m_traces[aName] = trace;
m_traces[name] = trace;
// It is a trick to keep legend & coords always on the top
for( mpLayer* l : m_topLevel )
@ -495,7 +501,7 @@ bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints,
if( GetType() == ST_AC )
{
if( aFlags & SPT_AC_PHASE )
if( aType & SPT_AC_PHASE )
{
for( int i = 0; i < aPoints; i++ )
tmp[i] = tmp[i] * 180.0 / M_PI; // convert to degrees
@ -509,13 +515,11 @@ bool SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints,
trace->SetData( std::vector<double>( aX, aX + aPoints ), tmp );
if( ( aFlags & SPT_AC_PHASE ) || ( aFlags & SPT_CURRENT ) )
if( ( aType & SPT_AC_PHASE ) || ( aType & SPT_CURRENT ) )
trace->SetScale( m_axis_x, m_axis_y2 );
else
trace->SetScale( m_axis_x, m_axis_y1 );
trace->SetFlags( aFlags );
m_plotWin->UpdateAll();
return addedNewEntry;

View File

@ -94,8 +94,8 @@ private:
class TRACE : public mpFXYVector
{
public:
TRACE( const wxString& aName ) :
mpFXYVector( aName ), m_cursor( nullptr ), m_flags( 0 )
TRACE( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam ) :
mpFXYVector( aName ), m_cursor( nullptr ), m_type( aType ), m_param( aParam )
{
SetContinuity( true );
SetDrawOutsideMargins( false );
@ -141,14 +141,9 @@ public:
return m_cursor;
}
void SetFlags( int aFlags )
SIM_PLOT_TYPE GetType() const
{
m_flags = aFlags;
}
int GetFlags() const
{
return m_flags;
return m_type;
}
void SetTraceColour( wxColour aColour )
@ -161,10 +156,20 @@ public:
return m_traceColour;
}
const wxString& GetParam() const
{
return m_param;
}
protected:
CURSOR* m_cursor;
int m_flags;
SIM_PLOT_TYPE m_type;
wxColour m_traceColour;
private:
///< Name of the signal parameter
wxString m_param;
};
@ -198,8 +203,8 @@ public:
return m_axis_y2 ? m_axis_y2->GetName() : "";
}
bool AddTrace( const wxString& aName, int aPoints, const double* aX,
const double* aY, SIM_PLOT_TYPE aFlags );
bool AddTrace( const wxString& aName, int aPoints, const double* aX, const double* aY,
SIM_PLOT_TYPE aType, const wxString& aParam );
bool DeleteTrace( const wxString& aName );

View File

@ -24,21 +24,6 @@
#include <sim/sim_workbook.h>
TRACE_DESC::TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
SIM_PLOT_TYPE aType, const wxString& aParam ) :
m_name( aName ),
m_type( aType ),
m_param( aParam )
{
// Title generation
m_title = wxString::Format( "%s(%s)", aParam, aName );
if( aType & SPT_AC_MAG )
m_title += " (mag)";
else if( aType & SPT_AC_PHASE )
m_title += " (phase)";
}
SIM_WORKBOOK::SIM_WORKBOOK() :
m_flagModified( false )
@ -87,30 +72,14 @@ std::vector<const SIM_PANEL_BASE*> SIM_WORKBOOK::GetSortedPlotPanels() const
}
void SIM_WORKBOOK::AddTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName,
const TRACE_DESC& aTrace )
void SIM_WORKBOOK::AddTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName )
{
m_plots.at( aPlotPanel ).m_traces.insert(
std::make_pair( aName, aTrace ) );
m_flagModified = true;
}
void SIM_WORKBOOK::RemoveTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName )
{
auto& traceMap = m_plots.at( aPlotPanel ).m_traces;
auto traceIt = traceMap.find( aName );
wxASSERT( traceIt != traceMap.end() );
traceMap.erase( traceIt );
m_flagModified = true;
}
SIM_WORKBOOK::TRACE_MAP::const_iterator SIM_WORKBOOK::RemoveTrace( const SIM_PANEL_BASE* aPlotPanel,
TRACE_MAP::const_iterator aIt )
{
m_flagModified = true;
return m_plots.at( aPlotPanel ).m_traces.erase( aIt );
}

View File

@ -27,76 +27,20 @@
#include <sim/sim_plot_panel.h>
///< Trace descriptor class
class TRACE_DESC
{
public:
TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
SIM_PLOT_TYPE aType, const wxString& aParam );
///< Modifies an existing TRACE_DESC simulation type
TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter,
const TRACE_DESC& aDescription, SIM_PLOT_TYPE aNewType )
: TRACE_DESC( aExporter, aDescription.GetName(), aNewType, aDescription.GetParam() )
{
}
const wxString& GetTitle() const
{
return m_title;
}
const wxString& GetName() const
{
return m_name;
}
const wxString& GetParam() const
{
return m_param;
}
SIM_PLOT_TYPE GetType() const
{
return m_type;
}
private:
// Three basic parameters
///< Name of the measured net/device
wxString m_name;
///< Type of the signal
SIM_PLOT_TYPE m_type;
///< Name of the signal parameter
wxString m_param;
// Generated data
///< Title displayed in the signal list/plot legend
wxString m_title;
};
class SIM_WORKBOOK
{
public:
typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
struct PLOT_INFO
{
///< Map of the traces displayed on the plot
TRACE_MAP m_traces;
///< Spice directive used to execute the simulation
///< TODO: use SIM_PANEL_BASE::m_simCommand instead
wxString m_simCommand;
///< The current position of the plot in the notebook
unsigned int pos;
};
typedef std::map<const SIM_PANEL_BASE*, PLOT_INFO> PLOT_MAP;
SIM_WORKBOOK();
void Clear();
@ -111,20 +55,8 @@ public:
return m_plots.count( aPlotPanel ) == 1;
}
void AddTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName,
const TRACE_DESC& aTrace );
void AddTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName );
void RemoveTrace( const SIM_PANEL_BASE* aPlotPanel, const wxString& aName );
TRACE_MAP::const_iterator RemoveTrace( const SIM_PANEL_BASE* aPlotPanel, TRACE_MAP::const_iterator aIt );
TRACE_MAP::const_iterator TracesBegin( const SIM_PANEL_BASE* aPlotPanel ) const
{
return m_plots.at( aPlotPanel ).m_traces.cbegin();
}
TRACE_MAP::const_iterator TracesEnd( const SIM_PANEL_BASE* aPlotPanel ) const
{
return m_plots.at( aPlotPanel ).m_traces.cend();
}
void SetPlotPanelPosition( const SIM_PANEL_BASE* aPlotPanel, unsigned int pos )
{
@ -152,11 +84,6 @@ public:
return m_plots.at( aPlotPanel );
}
const TRACE_MAP GetTraces( const SIM_PANEL_BASE* aPlotPanel ) const
{
return m_plots.at( aPlotPanel ).m_traces;
}
void ClrModified() { m_flagModified = false; }
bool IsModified() const { return m_flagModified; }