2016-08-11 12:41:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
2021-01-26 15:23:37 +00:00
|
|
|
* Copyright (C) 2016-2021 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
*
|
2016-08-11 12:41:07 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2016-08-11 12:41:21 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2016-08-11 12:41:07 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2016-08-11 12:41:43 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2016-08-11 12:41:07 +00:00
|
|
|
* 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:
|
2016-08-11 12:41:43 +00:00
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
2016-08-11 12:41:07 +00:00
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
#ifndef __SIM_PLOT_PANEL_H
|
|
|
|
#define __SIM_PLOT_PANEL_H
|
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
#include "sim_types.h"
|
2020-04-15 01:51:58 +00:00
|
|
|
#include <map>
|
|
|
|
#include <widgets/mathplot.h>
|
2021-01-21 21:17:13 +00:00
|
|
|
#include <wx/colour.h>
|
2020-04-15 01:51:58 +00:00
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include "sim_panel_base.h"
|
2021-01-21 21:17:13 +00:00
|
|
|
#include "sim_plot_colors.h"
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2020-02-01 12:05:44 +00:00
|
|
|
class SIM_PLOT_FRAME;
|
|
|
|
class SIM_PLOT_PANEL;
|
2016-08-11 12:41:25 +00:00
|
|
|
class TRACE;
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Cursor attached to a trace to follow its values:
|
2016-08-11 12:41:22 +00:00
|
|
|
class CURSOR : public mpInfoLayer
|
|
|
|
{
|
|
|
|
public:
|
2021-01-21 21:17:13 +00:00
|
|
|
CURSOR( const TRACE* aTrace, SIM_PLOT_PANEL* aPlotPanel ) :
|
|
|
|
mpInfoLayer( wxRect( 0, 0, DRAG_MARGIN, DRAG_MARGIN ), wxTRANSPARENT_BRUSH ),
|
2023-01-14 00:17:33 +00:00
|
|
|
m_trace( aTrace ),
|
|
|
|
m_updateRequired( true ),
|
|
|
|
m_updateRef( false ),
|
|
|
|
m_coords( 0.0, 0.0 ),
|
2021-01-21 21:17:13 +00:00
|
|
|
m_window( nullptr )
|
2016-08-11 12:41:22 +00:00
|
|
|
{
|
2016-08-11 12:41:55 +00:00
|
|
|
SetDrawOutsideMargins( false );
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Plot( wxDC& aDC, mpWindow& aWindow ) override;
|
|
|
|
|
2016-08-11 12:42:14 +00:00
|
|
|
void SetX( int aX )
|
|
|
|
{
|
|
|
|
m_reference.x = 0;
|
|
|
|
m_updateRef = true;
|
|
|
|
Move( wxPoint( aX, 0 ) );
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:25 +00:00
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
m_updateRequired = true;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:55 +00:00
|
|
|
bool Inside( wxPoint& aPoint ) override;
|
2016-08-11 12:41:22 +00:00
|
|
|
|
|
|
|
void Move( wxPoint aDelta ) override
|
|
|
|
{
|
2016-08-11 12:41:25 +00:00
|
|
|
Update();
|
2016-08-11 12:41:22 +00:00
|
|
|
mpInfoLayer::Move( aDelta );
|
|
|
|
}
|
|
|
|
|
2016-09-27 08:58:05 +00:00
|
|
|
void UpdateReference() override;
|
2016-08-11 12:41:22 +00:00
|
|
|
|
|
|
|
const wxRealPoint& GetCoords() const
|
|
|
|
{
|
|
|
|
return m_coords;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
const TRACE* m_trace;
|
2016-08-11 12:42:14 +00:00
|
|
|
bool m_updateRequired, m_updateRef;
|
2016-08-11 12:41:22 +00:00
|
|
|
wxRealPoint m_coords;
|
|
|
|
mpWindow* m_window;
|
|
|
|
|
2017-03-19 13:13:44 +00:00
|
|
|
static constexpr int DRAG_MARGIN = 10;
|
2016-08-11 12:41:22 +00:00
|
|
|
};
|
|
|
|
|
2016-08-11 12:41:25 +00:00
|
|
|
|
|
|
|
class TRACE : public mpFXYVector
|
|
|
|
{
|
|
|
|
public:
|
2022-04-12 14:37:06 +00:00
|
|
|
TRACE( const wxString& aName, SIM_PLOT_TYPE aType ) :
|
2023-01-14 00:17:33 +00:00
|
|
|
mpFXYVector( aName ),
|
|
|
|
m_cursor( nullptr ),
|
|
|
|
m_type( aType )
|
2016-08-11 12:42:17 +00:00
|
|
|
{
|
|
|
|
SetContinuity( true );
|
|
|
|
SetDrawOutsideMargins( false );
|
|
|
|
ShowName( false );
|
|
|
|
}
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
/**
|
2021-01-26 15:23:37 +00:00
|
|
|
* Assigns new data set for the trace. aX and aY need to have the same length.
|
|
|
|
*
|
2016-08-11 12:42:17 +00:00
|
|
|
* @param aX are the X axis values.
|
|
|
|
* @param aY are the Y axis values.
|
|
|
|
*/
|
2016-08-11 12:41:55 +00:00
|
|
|
void SetData( const std::vector<double>& aX, const std::vector<double>& aY ) override
|
|
|
|
{
|
|
|
|
if( m_cursor )
|
|
|
|
m_cursor->Update();
|
|
|
|
|
|
|
|
mpFXYVector::SetData( aX, aY );
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:25 +00:00
|
|
|
const std::vector<double>& GetDataX() const
|
|
|
|
{
|
|
|
|
return m_xs;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<double>& GetDataY() const
|
|
|
|
{
|
|
|
|
return m_ys;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasCursor() const
|
|
|
|
{
|
|
|
|
return m_cursor != nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetCursor( CURSOR* aCursor )
|
|
|
|
{
|
|
|
|
m_cursor = aCursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
CURSOR* GetCursor() const
|
|
|
|
{
|
|
|
|
return m_cursor;
|
|
|
|
}
|
|
|
|
|
2021-05-24 20:17:29 +00:00
|
|
|
SIM_PLOT_TYPE GetType() const
|
2016-08-11 12:42:14 +00:00
|
|
|
{
|
2021-05-24 20:17:29 +00:00
|
|
|
return m_type;
|
2016-08-11 12:42:14 +00:00
|
|
|
}
|
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
void SetTraceColour( wxColour aColour )
|
|
|
|
{
|
|
|
|
m_traceColour = aColour;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxColour GetTraceColour()
|
|
|
|
{
|
|
|
|
return m_traceColour;
|
|
|
|
}
|
|
|
|
|
2021-05-24 20:17:29 +00:00
|
|
|
const wxString& GetParam() const
|
|
|
|
{
|
|
|
|
return m_param;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:49 +00:00
|
|
|
protected:
|
2016-08-11 12:41:25 +00:00
|
|
|
CURSOR* m_cursor;
|
2021-05-24 20:17:29 +00:00
|
|
|
SIM_PLOT_TYPE m_type;
|
2016-08-29 09:39:54 +00:00
|
|
|
wxColour m_traceColour;
|
2021-05-24 20:17:29 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
///< Name of the signal parameter
|
|
|
|
wxString m_param;
|
2016-08-11 12:41:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
class SIM_PLOT_PANEL : public SIM_PANEL_BASE
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2021-06-30 00:13:10 +00:00
|
|
|
friend class SIM_WORKBOOK;
|
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
public:
|
2023-01-14 00:17:33 +00:00
|
|
|
SIM_PLOT_PANEL( const wxString& aCommand, int aOptions, wxWindow* parent,
|
|
|
|
SIM_PLOT_FRAME* aMainFrame, wxWindowID id,
|
|
|
|
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
|
|
|
long style = 0, const wxString& name = wxPanelNameStr );
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
virtual ~SIM_PLOT_PANEL();
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< set the pointer to the sim plot frame
|
2020-02-01 12:05:44 +00:00
|
|
|
void SetMasterFrame( SIM_PLOT_FRAME* aFrame )
|
|
|
|
{
|
|
|
|
m_masterFrame = aFrame;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
wxString GetLabelX() const
|
|
|
|
{
|
|
|
|
return m_axis_x ? m_axis_x->GetName() : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetLabelY1() const
|
2016-08-11 12:41:26 +00:00
|
|
|
{
|
2016-08-11 12:41:35 +00:00
|
|
|
return m_axis_y1 ? m_axis_y1->GetName() : "";
|
|
|
|
}
|
|
|
|
|
|
|
|
wxString GetLabelY2() const
|
|
|
|
{
|
|
|
|
return m_axis_y2 ? m_axis_y2->GetName() : "";
|
2016-08-11 12:41:26 +00:00
|
|
|
}
|
|
|
|
|
2017-03-19 13:17:33 +00:00
|
|
|
bool TraceShown( const wxString& aName ) const
|
2016-08-11 12:41:24 +00:00
|
|
|
{
|
2016-08-11 12:41:52 +00:00
|
|
|
return m_traces.count( aName ) > 0;
|
2016-08-11 12:41:24 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
const std::map<wxString, TRACE*>& GetTraces() const
|
2016-08-11 12:41:18 +00:00
|
|
|
{
|
|
|
|
return m_traces;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:25 +00:00
|
|
|
TRACE* GetTrace( const wxString& aName ) const
|
|
|
|
{
|
2016-08-11 12:41:52 +00:00
|
|
|
auto trace = m_traces.find( aName );
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
return trace == m_traces.end() ? nullptr : trace->second;
|
2016-08-11 12:41:25 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
void ShowGrid( bool aEnable )
|
|
|
|
{
|
|
|
|
m_axis_x->SetTicks( !aEnable );
|
2016-08-11 12:41:35 +00:00
|
|
|
m_axis_y1->SetTicks( !aEnable );
|
|
|
|
m_axis_y2->SetTicks( !aEnable );
|
2020-04-15 01:51:58 +00:00
|
|
|
m_plotWin->UpdateAll();
|
2016-08-11 12:41:27 +00:00
|
|
|
}
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
bool IsGridShown() const
|
|
|
|
{
|
2017-12-18 08:33:05 +00:00
|
|
|
if( !m_axis_x || !m_axis_y1 )
|
|
|
|
return false;
|
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
assert( m_axis_x->GetTicks() == m_axis_y1->GetTicks() );
|
2016-08-11 12:41:27 +00:00
|
|
|
return !m_axis_x->GetTicks();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShowLegend( bool aEnable )
|
|
|
|
{
|
|
|
|
m_legend->SetVisible( aEnable );
|
2020-04-15 01:51:58 +00:00
|
|
|
m_plotWin->UpdateAll();
|
2016-08-11 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsLegendShown() const
|
|
|
|
{
|
|
|
|
return m_legend->IsVisible();
|
|
|
|
}
|
|
|
|
|
2019-11-19 16:17:37 +00:00
|
|
|
void SetDottedCurrentPhase( bool aEnable )
|
|
|
|
{
|
|
|
|
m_dotted_cp = aEnable;
|
|
|
|
|
|
|
|
for( const auto& tr : m_traces )
|
|
|
|
{
|
|
|
|
UpdateTraceStyle( tr.second );
|
|
|
|
}
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
m_plotWin->UpdateAll();
|
2019-11-19 16:17:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GetDottedCurrentPhase() const
|
|
|
|
{
|
|
|
|
return m_dotted_cp;
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
///< Toggle cursor for a particular trace.
|
2016-08-11 12:41:25 +00:00
|
|
|
void EnableCursor( const wxString& aName, bool aEnable );
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
///< Reset scale ranges to fit the current traces.
|
2016-08-11 12:42:04 +00:00
|
|
|
void ResetScales();
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Update trace line style
|
2019-11-19 16:17:37 +00:00
|
|
|
void UpdateTraceStyle( TRACE* trace );
|
|
|
|
|
2021-01-21 21:17:13 +00:00
|
|
|
///> Update plot colors
|
2020-02-01 12:05:44 +00:00
|
|
|
void UpdatePlotColors();
|
|
|
|
|
2021-01-26 15:23:37 +00:00
|
|
|
///< Getter for math plot window
|
2020-04-15 01:51:58 +00:00
|
|
|
mpWindow* GetPlotWin() const
|
|
|
|
{
|
|
|
|
return m_plotWin;
|
|
|
|
}
|
|
|
|
|
2021-06-30 00:13:10 +00:00
|
|
|
protected:
|
2021-09-07 21:18:22 +00:00
|
|
|
bool addTrace( const wxString& aTitle, const wxString& aName, int aPoints, const double* aX,
|
2022-04-12 14:37:06 +00:00
|
|
|
const double* aY, SIM_PLOT_TYPE aType );
|
2021-06-30 00:13:10 +00:00
|
|
|
|
|
|
|
bool deleteTrace( const wxString& aName );
|
|
|
|
|
2016-08-11 12:41:12 +00:00
|
|
|
private:
|
2021-01-27 22:15:38 +00:00
|
|
|
///< @brief Construct the plot axes for DC simulation plot.
|
2021-01-25 21:29:13 +00:00
|
|
|
void prepareDCAxes();
|
|
|
|
|
2021-10-18 17:01:08 +00:00
|
|
|
///> Create/Ensure axes are available for plotting
|
|
|
|
void updateAxes();
|
|
|
|
|
2021-01-21 21:17:13 +00:00
|
|
|
SIM_PLOT_COLORS m_colors;
|
2016-08-11 12:41:14 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
// Top-level plot window
|
|
|
|
mpWindow* m_plotWin;
|
|
|
|
wxBoxSizer* m_sizer;
|
|
|
|
|
2016-08-11 12:41:21 +00:00
|
|
|
// Traces to be plotted
|
2016-08-11 12:41:52 +00:00
|
|
|
std::map<wxString, TRACE*> m_traces;
|
2016-08-11 12:41:14 +00:00
|
|
|
|
2016-08-11 12:41:49 +00:00
|
|
|
mpScaleXBase* m_axis_x;
|
2016-08-11 12:41:35 +00:00
|
|
|
mpScaleY* m_axis_y1;
|
|
|
|
mpScaleY* m_axis_y2;
|
2016-08-11 12:41:21 +00:00
|
|
|
mpInfoLegend* m_legend;
|
2016-08-11 12:41:27 +00:00
|
|
|
|
2019-11-19 16:17:37 +00:00
|
|
|
bool m_dotted_cp;
|
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
std::vector<mpLayer*> m_topLevel;
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2020-02-01 12:05:44 +00:00
|
|
|
SIM_PLOT_FRAME* m_masterFrame;
|
2016-08-11 12:41:01 +00:00
|
|
|
};
|
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
wxDECLARE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent );
|
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
#endif
|