41 fmt.Printf(
"%%.0%df", nDigits );
51static void getSISuffix(
double x,
const wxString& unit,
int& power, wxString& suffix )
53 const int n_powers = 11;
81 for(
int i = 0; i < n_powers - 1; i++ )
83 double r_cur = pow( 10, powers[i].exponent );
85 if( fabs( x ) >= r_cur && fabs( x ) < r_cur * 1000.0 )
87 power = powers[i].exponent;
89 if( powers[i].suffix )
90 suffix = wxString( powers[i].suffix ) + unit;
102 if( std::isnan( x ) )
108 int64_t k = (int)( ( x - floor( x ) ) * pow( 10.0, (
double) maxDigits ) );
111 while( k && ( ( k % 10LL ) == 0LL || ( k % 10LL ) == 9LL ) )
128template <
typename parent>
133 parent(
name, flags ),
139 double maxVis = parent::AbsVisibleMaxValue();
144 int constexpr DIGITS = 3;
148 double sf = pow( 10.0, power );
154 digits = std::max( digits, k );
159 l.label =
formatFloat( l.pos / sf, digits ) + suffix;
169template <
typename parent>
174 parent(
name, flags ),
186 double sf = pow( 10.0, power );
210 if( dataX.size() <= 1 )
218 auto maxXIt = std::upper_bound( dataX.begin(), dataX.end(),
m_coords.x );
219 int maxIdx = maxXIt - dataX.begin();
220 int minIdx = maxIdx - 1;
229 else if( maxIdx >= (
int) dataX.size() )
231 maxIdx = dataX.size() - 1;
236 const double leftX = dataX[minIdx];
237 const double rightX = dataX[maxIdx];
238 const double leftY = dataY[minIdx];
239 const double rightY = dataY[maxIdx];
242 m_coords.y = leftY + ( rightY - leftY ) / ( rightX - leftX ) * (
m_coords.x - leftX );
246 wxQueueEvent( aWindow.GetParent(),
new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
271 pen.SetStyle(
m_continuous ? wxPENSTYLE_SOLID : wxPENSTYLE_LONG_DASH );
274 if( topPx < cursorPos.y && cursorPos.y < bottomPx )
275 aDC.DrawLine( leftPx, cursorPos.y, rightPx, cursorPos.y );
277 if( leftPx < cursorPos.x && cursorPos.x < rightPx )
278 aDC.DrawLine( cursorPos.x, topPx, cursorPos.x, bottomPx );
287 return (
std::abs( (
double) aPoint.x -
306 const wxSize& size,
long style,
const wxString&
name )
309 m_axis_y1( nullptr ),
310 m_axis_y2( nullptr ),
311 m_dotted_cp( false ),
312 m_masterFrame( aMainFrame )
314 m_sizer =
new wxBoxSizer( wxVERTICAL );
406 if( sim_cmd.StartsWith(
".dc", &rem ) )
414 ch = rem.GetChar( 0 );
478 TRACE* trace =
nullptr;
483 auto prev =
m_traces.find( aTitle );
484 bool addedNewEntry = ( prev ==
m_traces.end() );
490 bool hasVoltageTraces =
false;
496 hasVoltageTraces =
true;
501 if( !hasVoltageTraces )
508 trace =
new TRACE( aName, aType );
524 trace = prev->second;
527 std::vector<double> tmp( aY, aY + aPoints );
533 for(
int i = 0; i < aPoints; i++ )
534 tmp[i] = tmp[i] * 180.0 / M_PI;
538 for(
int i = 0; i < aPoints; i++ )
542 tmp[i] = 20 * log( tmp[i] ) / log( 10.0 );
547 trace->
SetData( std::vector<double>( aX, aX + aPoints ), tmp );
556 return addedNewEntry;
566 TRACE* trace = it->second;
586 if( t ==
nullptr || t->
HasCursor() == aEnable )
596 c->
SetX( plotCenter );
609 wxQueueEvent( GetParent(),
new wxCommandEvent( EVT_SIM_CURSOR_UPDATE ) );
625 trace->UpdateScales();
Cursor attached to a trace to follow its values:
static constexpr int DRAG_MARGIN
void UpdateReference() override
Updates the rectangle reference point.
bool Inside(wxPoint &aPoint) override
Checks whether a point is inside the info box rectangle.
void Plot(wxDC &aDC, mpWindow &aWindow) override
Plot method.
LIN_SCALE(const wxString &name, const wxString &unit, int flags)
void formatLabels() override
LOG_SCALE(const wxString &name, const wxString &unit, int flags)
void formatLabels() override
const wxString & getSimCommand() const
wxColour GenerateColor(std::map< wxString, TRACE * > aTraces)
wxColour GetPlotColor(enum COLOR_SET aColorId)
Implementing SIM_PLOT_FRAME_BASE.
bool addTrace(const wxString &aTitle, const wxString &aName, int aPoints, const double *aX, const double *aY, SIM_PLOT_TYPE aType)
void UpdatePlotColors()
Update plot colors
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)
TRACE * GetTrace(const wxString &aName) const
void EnableCursor(const wxString &aName, bool aEnable)
Reset scale ranges to fit the current traces.
void updateAxes()
Create/Ensure axes are available for plotting
void UpdateTraceStyle(TRACE *trace)
void ResetScales()
Update trace line style.
virtual ~SIM_PLOT_PANEL()
set the pointer to the sim plot frame
std::map< wxString, TRACE * > m_traces
bool deleteTrace(const wxString &aName)
mpWindow * GetPlotWin() const
std::vector< mpLayer * > m_topLevel
void SetCursor(CURSOR *aCursor)
wxColour GetTraceColour()
void SetTraceColour(wxColour aColour)
void SetData(const std::vector< double > &aX, const std::vector< double > &aY) override
Assigns new data set for the trace.
SIM_PLOT_TYPE GetType() const
const std::vector< double > & GetDataY() const
const std::vector< double > & GetDataX() const
CURSOR * GetCursor() const
virtual void SetScale(mpScaleBase *scaleX, mpScaleBase *scaleY)
double y2s(double y) const
double x2s(double x) const
double s2x(double plotCoordX) const
Implements the legend to be added to the plot This layer allows you to add a legend to describe the p...
bool m_drawOutsideMargins
void SetPen(wxPen pen)
Set layer pen.
const wxPen & GetPen() const
Get pen set for this layer.
void SetVisible(bool show)
Sets layer visibility.
void SetNameAlign(int align)
void SetTicks(bool enable)
Set X axis ticks or grid.
void SetTicks(bool ticks)
Set Y axis ticks or grid.
void SetMasterScale(mpScaleY *masterScale)
Canvas for plotting mpLayer implementations.
void SetColourTheme(const wxColour &bgColour, const wxColour &drawColour, const wxColour &axesColour)
Set Color theme.
int GetMarginLeft() const
int GetScrX(void) const
Get current view's X dimension in device context units.
void SetMargins(int top, int right, int bottom, int left)
Set window margins, creating a blank area where some kinds of layers cannot draw.
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
int GetXScreen(void) const
void LimitView(bool aEnable)
Limit zooming & panning to the area used by the plots.
wxCoord x2p(double x)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
bool DelLayer(mpLayer *layer, bool alsoDeleteObject=false, bool refreshDisplay=true)
Remove a plot layer from the canvas.
void UpdateAll()
Refresh display.
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates,...
int GetMarginRight() const
int GetMarginBottom() const
void EnableDoubleBuffer(bool enabled)
Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
int GetScrY(void) const
Get current view's Y dimension in device context units.
bool AddLayer(mpLayer *layer, bool refreshDisplay=true)
Add a plot layer to the canvas.
class WXDLLIMPEXP_MATHPLOT mpWindow
#define mpALIGN_RIGHT
Aligns label to the right.
#define mpALIGN_LEFT
Aligns label to the left.
class WXDLLIMPEXP_MATHPLOT mpScaleY
#define mpALIGN_BOTTOM
Aligns label to the bottom.
EDA_ANGLE abs(const EDA_ANGLE &aAngle)
Class is responsible for providing colors for traces on simulation plot.
wxDEFINE_EVENT(EVT_SIM_CURSOR_UPDATE, wxCommandEvent)
static void getSISuffix(double x, const wxString &unit, int &power, wxString &suffix)
static int countDecimalDigits(double x, int maxDigits)
static wxString formatFloat(double x, int nDigits)