kicad/eeschema/sim/sim_plot_panel.cpp

69 lines
1.3 KiB
C++
Raw Normal View History

2016-08-11 12:41:01 +00:00
#include "sim_plot_panel.h"
static SIM_PLOT_PANEL *panel = NULL;
static int drawPlotFunc( mglGraph *graph )
{
printf("DrawPlot [%d traces]!\n", panel->m_traces.size());
2016-08-11 12:41:01 +00:00
graph->Clf();
//graph->SetRanges(-10e-3,10e-3,-2,2);
graph->Axis("x");
graph->Label('x',"Time",0);
graph->SetRange('x', 0, 10e-3);
2016-08-11 12:41:01 +00:00
graph->Axis("y");
graph->Label('y',"Voltage",0);
graph->SetRange('y', -1.5, 1.5);
2016-08-11 12:41:01 +00:00
for( auto t : panel->m_traces )
{
graph->AddLegend( (const char*) t.name.c_str(), "" );
graph->Plot( t.y );
}
2016-08-11 12:41:01 +00:00
graph->Box();
graph->Grid();
if ( panel->m_traces.size() )
graph->Legend(1,"-#");
2016-08-11 12:41:01 +00:00
return 0;
2016-08-11 12:41:01 +00:00
}
SIM_PLOT_PANEL::SIM_PLOT_PANEL( wxWindow* parent, wxWindowID id, const wxPoint& pos,
const wxSize& size, long style, const wxString& name )
: wxMathGL( parent, id, pos, size, style, name )
2016-08-11 12:41:01 +00:00
{
panel = this;
2016-08-11 12:41:01 +00:00
AutoResize = true;
SetDraw( drawPlotFunc );
// Update();
2016-08-11 12:41:01 +00:00
}
SIM_PLOT_PANEL::~SIM_PLOT_PANEL()
{
}
2016-08-11 12:41:01 +00:00
void SIM_PLOT_PANEL::AddTrace(const wxString& name, int n_points, double *t, double *x, int flags )
{
Trace trace;
2016-08-11 12:41:01 +00:00
trace.name = name;
trace.x.Set(t, n_points);
trace.y.Set(x, n_points);
2016-08-11 12:41:01 +00:00
m_traces.push_back(trace);
Update();
2016-08-11 12:41:01 +00:00
}
void SIM_PLOT_PANEL::DeleteTraces()
{
m_traces.clear();
Update();
2016-08-11 12:41:01 +00:00
}