1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
|
/*
* This program source code file is part of KiCad, a free EDA CAD application.
*
* Copyright (C) 2016 CERN
* Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
* @author Maciej Suminski <maciej.suminski@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 3
* 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:
* https://www.gnu.org/licenses/gpl-3.0.html
* or you may search the http://www.gnu.org website for the version 3 license,
* or you may write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
#ifndef __SIM_PLOT_PANEL_H
#define __SIM_PLOT_PANEL_H
#include <widgets/mathplot.h>
#include <map>
#include "sim_types.h"
class TRACE;
///> Cursor attached to a trace to follow its values:
class CURSOR : public mpInfoLayer
{
public:
CURSOR( const TRACE* aTrace )
: mpInfoLayer( wxRect( 0, 0, DRAG_MARGIN, DRAG_MARGIN ), wxTRANSPARENT_BRUSH ),
m_trace( aTrace ), m_updateRequired( true ), m_updateRef( false ),
m_coords( 0.0, 0.0 ), m_window( nullptr )
{
SetDrawOutsideMargins( false );
}
void Plot( wxDC& aDC, mpWindow& aWindow ) override;
void SetX( int aX )
{
m_reference.x = 0;
m_updateRef = true;
Move( wxPoint( aX, 0 ) );
}
void Update()
{
m_updateRequired = true;
}
bool Inside( wxPoint& aPoint ) override;
void Move( wxPoint aDelta ) override
{
Update();
mpInfoLayer::Move( aDelta );
}
void UpdateReference() override;
const wxRealPoint& GetCoords() const
{
return m_coords;
}
private:
const TRACE* m_trace;
bool m_updateRequired, m_updateRef;
wxRealPoint m_coords;
mpWindow* m_window;
static constexpr int DRAG_MARGIN = 10;
};
class TRACE : public mpFXYVector
{
public:
TRACE( const wxString& aName ) :
mpFXYVector( aName ), m_cursor( nullptr ), m_flags( 0 )
{
SetContinuity( true );
SetDrawOutsideMargins( false );
ShowName( false );
}
/**
* @brief Assigns new data set for the trace. aX and aY need to have the same length.
* @param aX are the X axis values.
* @param aY are the Y axis values.
*/
void SetData( const std::vector<double>& aX, const std::vector<double>& aY ) override
{
if( m_cursor )
m_cursor->Update();
mpFXYVector::SetData( aX, aY );
}
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;
}
void SetFlags( int aFlags )
{
m_flags = aFlags;
}
int GetFlags() const
{
return m_flags;
}
void SetTraceColour( wxColour aColour )
{
m_traceColour = aColour;
}
wxColour GetTraceColour()
{
return m_traceColour;
}
protected:
CURSOR* m_cursor;
int m_flags;
wxColour m_traceColour;
};
class SIM_PLOT_PANEL : public mpWindow
{
public:
SIM_PLOT_PANEL( SIM_TYPE aType, wxWindow* parent, wxWindowID id, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize, long style = 0, const wxString& name = wxPanelNameStr );
~SIM_PLOT_PANEL();
SIM_TYPE GetType() const
{
return m_type;
}
static bool IsPlottable( SIM_TYPE aSimType );
wxString GetLabelX() const
{
return m_axis_x ? m_axis_x->GetName() : "";
}
wxString GetLabelY1() const
{
return m_axis_y1 ? m_axis_y1->GetName() : "";
}
wxString GetLabelY2() const
{
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 DeleteTrace( const wxString& aName );
void DeleteAllTraces();
bool TraceShown( const wxString& aName ) const
{
return m_traces.count( aName ) > 0;
}
const std::map<wxString, TRACE*>& GetTraces() const
{
return m_traces;
}
TRACE* GetTrace( const wxString& aName ) const
{
auto trace = m_traces.find( aName );
return trace == m_traces.end() ? NULL : trace->second;
}
void ShowGrid( bool aEnable )
{
m_axis_x->SetTicks( !aEnable );
m_axis_y1->SetTicks( !aEnable );
m_axis_y2->SetTicks( !aEnable );
UpdateAll();
}
bool IsGridShown() const
{
if( !m_axis_x || !m_axis_y1 )
return false;
assert( m_axis_x->GetTicks() == m_axis_y1->GetTicks() );
return !m_axis_x->GetTicks();
}
void ShowLegend( bool aEnable )
{
m_legend->SetVisible( aEnable );
UpdateAll();
}
bool IsLegendShown() const
{
return m_legend->IsVisible();
}
///> Returns true if the trace has cursor shown.
bool HasCursorEnabled( const wxString& aName ) const;
///> Toggles cursor for a particular trace.
void EnableCursor( const wxString& aName, bool aEnable );
///> Resets scale ranges to fit the current traces
void ResetScales();
private:
///> Returns a new color from the palette
wxColour generateColor();
// Color index to get a new color from the palette
unsigned int m_colorIdx;
// Traces to be plotted
std::map<wxString, TRACE*> m_traces;
mpScaleXBase* m_axis_x;
mpScaleY* m_axis_y1;
mpScaleY* m_axis_y2;
mpInfoLegend* m_legend;
std::vector<mpLayer*> m_topLevel;
const SIM_TYPE m_type;
};
wxDECLARE_EVENT( EVT_SIM_CURSOR_UPDATE, wxCommandEvent );
#endif
|