From 8a6e6f2d3606b6d855c2a5c48a08172daeeae7c3 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:41:16 +0200 Subject: [PATCH] Do not add a trace if it is already plotted --- eeschema/sim/sim_plot_panel.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index 3f197b5125..707d0c679f 100644 --- a/eeschema/sim/sim_plot_panel.cpp +++ b/eeschema/sim/sim_plot_panel.cpp @@ -24,6 +24,7 @@ #include "sim_plot_panel.h" +#include #include SIM_PLOT_PANEL::SIM_PLOT_PANEL( wxWindow* parent, wxWindowID id, const wxPoint& pos, @@ -65,13 +66,27 @@ static std::pair find_minmax( const T* aArray, unsigned int aSize ) void SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints, double* aT, double* aY, int aFlags ) { - TRACE trace; + // Find previous entry, if there is one + auto it = std::find_if( m_traces.begin(), m_traces.end(), + [&](const TRACE& t) { return t.name == aName; }); - trace.name = aName; - trace.style = wxString( '-' ) + m_painter.GenerateColor( SIM_PLOT_PAINTER::DARK ); - trace.x.Set( aT, aPoints ); - trace.y.Set( aY, aPoints ); - m_traces.push_back( trace ); + if( it == m_traces.end() ) + { + // New entry + TRACE trace; + trace.name = aName; + trace.style = wxString( '-' ) + m_painter.GenerateColor( SIM_PLOT_PAINTER::DARK ); + trace.x.Set( aT, aPoints ); + trace.y.Set( aY, aPoints ); + m_traces.push_back( trace ); + } + else + { + // Update + TRACE& trace = *it; + trace.x.Set( aT, aPoints ); + trace.y.Set( aY, aPoints ); + } // Update axis ranges std::pair traceRangeT = find_minmax( aT, aPoints );