kicad-source/eeschema/sim/sim_plot_panel.cpp

93 lines
2.4 KiB
C++
Raw Normal View History

2016-08-11 14:41:07 +02:00
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 CERN
* @author Tomasz Wlostowski <tomasz.wlostowski@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
*/
2016-08-11 14:41:01 +02:00
#include "sim_plot_panel.h"
2016-08-11 14:41:07 +02:00
static SIM_PLOT_PANEL* panel = NULL;
2016-08-11 14:41:01 +02:00
2016-08-11 14:41:07 +02:00
static int drawPlotFunc( mglGraph* aGraph )
2016-08-11 14:41:01 +02:00
{
2016-08-11 14:41:07 +02:00
aGraph->Clf();
//aGraph->SetRanges(-10e-3,10e-3,-2,2);
aGraph->Axis( "x" );
aGraph->Label( 'x', "Time", 0 );
aGraph->SetRange( 'x', 0, 10e-3 );
2016-08-11 14:41:01 +02:00
2016-08-11 14:41:07 +02:00
aGraph->Axis( "y" );
aGraph->Label( 'y', "Voltage", 0 );
aGraph->SetRange( 'y', -1.5, 1.5 );
2016-08-11 14:41:01 +02:00
for( auto t : panel->m_traces )
{
2016-08-11 14:41:07 +02:00
aGraph->AddLegend( (const char*) t.name.c_str(), "" );
aGraph->Plot( t.y );
}
2016-08-11 14:41:01 +02:00
2016-08-11 14:41:07 +02:00
aGraph->Box();
aGraph->Grid();
2016-08-11 14:41:01 +02:00
2016-08-11 14:41:07 +02:00
if( panel->m_traces.size() )
aGraph->Legend( 1, "-#" );
2016-08-11 14:41:01 +02:00
return 0;
2016-08-11 14:41:01 +02: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 14:41:01 +02:00
{
panel = this;
2016-08-11 14:41:01 +02:00
AutoResize = true;
SetDraw( drawPlotFunc );
// Update();
2016-08-11 14:41:01 +02:00
}
SIM_PLOT_PANEL::~SIM_PLOT_PANEL()
{
}
2016-08-11 14:41:07 +02:00
void SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints,
double* aT, double* aX, int aFlags )
2016-08-11 14:41:01 +02:00
{
2016-08-11 14:41:07 +02:00
TRACE trace;
2016-08-11 14:41:01 +02:00
2016-08-11 14:41:07 +02:00
trace.name = aName;
trace.x.Set( aT, aPoints );
trace.y.Set( aX, aPoints );
2016-08-11 14:41:01 +02:00
2016-08-11 14:41:07 +02:00
m_traces.push_back( trace );
Update();
2016-08-11 14:41:01 +02:00
}
2016-08-11 14:41:07 +02:00
2016-08-11 14:41:01 +02:00
void SIM_PLOT_PANEL::DeleteTraces()
{
m_traces.clear();
Update();
2016-08-11 14:41:01 +02:00
}