KiCad PCB EDA Suite
mpProfile Class Referenceabstract

Abstract base class providing plot and labeling functionality for functions F:Y->X. More...

#include <mathplot.h>

Inheritance diagram for mpProfile:
mpLayer

Public Member Functions

 mpProfile (wxString name=wxEmptyString, int flags=mpALIGN_TOP)
 
virtual double GetY (double x)=0
 Get function value for argument. More...
 
virtual void Plot (wxDC &dc, mpWindow &w) override
 Layer plot handler. More...
 
virtual bool HasBBox ()
 Check whether this layer has a bounding box. More...
 
virtual bool IsInfo ()
 Check whether the layer is an info box. More...
 
virtual double GetMinX ()
 Get inclusive left border of bounding box. More...
 
virtual double GetMaxX ()
 Get inclusive right border of bounding box. More...
 
virtual double GetMinY ()
 Get inclusive bottom border of bounding box. More...
 
virtual double GetMaxY ()
 Get inclusive top border of bounding box. More...
 
const wxString & GetName () const
 Get layer name. More...
 
const wxFont & GetFont () const
 Get font set for this layer. More...
 
const wxPen & GetPen () const
 Get pen set for this layer. More...
 
void SetContinuity (bool continuity)
 Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points). More...
 
bool GetContinuity () const
 Gets the 'continuity' property of the layer. More...
 
void ShowName (bool show)
 Shows or hides the text label with the name of the layer (default is visible). More...
 
void SetName (wxString name)
 Set layer name. More...
 
void SetFont (wxFont &font)
 Set layer font. More...
 
void SetPen (wxPen pen)
 Set layer pen. More...
 
void SetDrawOutsideMargins (bool drawModeOutside)
 Set Draw mode: inside or outside margins. More...
 
bool GetDrawOutsideMargins ()
 Get Draw mode: inside or outside margins. More...
 
wxBitmap GetColourSquare (int side=16)
 Get a small square bitmap filled with the colour of the pen used in the layer. More...
 
mpLayerType GetLayerType ()
 Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value. More...
 
bool IsVisible ()
 Checks whether the layer is visible or not. More...
 
void SetVisible (bool show)
 Sets layer visibility. More...
 
const wxBrush & GetBrush () const
 Get brush set for this layer. More...
 
void SetBrush (wxBrush brush)
 Set layer brush. More...
 

Protected Attributes

int m_flags
 
wxFont m_font
 
wxPen m_pen
 
wxBrush m_brush
 
wxString m_name
 
bool m_continuous
 
bool m_showName
 
bool m_drawOutsideMargins
 
mpLayerType m_type
 
bool m_visible
 

Detailed Description

Abstract base class providing plot and labeling functionality for functions F:Y->X.

Override mpProfile::GetX to implement a function. This class is similar to mpFY, but the Plot method is different. The plot is in fact represented by lines instead of points, which gives best rendering of rapidly-varying functions, and in general, data which are not so close one to another. Optionally implement a constructor and pass a name (label) and a label alignment to the constructor mpProfile::mpProfile. If the layer name is empty, no label will be plotted.

Definition at line 647 of file mathplot.h.

Constructor & Destructor Documentation

mpProfile::mpProfile ( wxString  name = wxEmptyString,
int  flags = mpALIGN_TOP 
)
Parameters
nameLabel
flagsLabel alignment, pass one of mpALIGN_BOTTOM, mpALIGN_CENTER, mpALIGN_TOP.

Definition at line 793 of file mathplot.cpp.

References mpLAYER_PLOT.

794 {
795  SetName( name );
796  m_flags = flags;
798 }
void SetName(wxString name)
Set layer name.
Definition: mathplot.h:266
int m_flags
Definition: mathplot.h:669
mpLayerType m_type
Definition: mathplot.h:320
const char * name

Member Function Documentation

const wxBrush& mpLayer::GetBrush ( ) const
inlineinherited

Get brush set for this layer.

Returns
brush.

Definition at line 305 of file mathplot.h.

305 { return m_brush; };
wxBrush m_brush
Definition: mathplot.h:315
wxBitmap mpLayer::GetColourSquare ( int  side = 16)
inherited

Get a small square bitmap filled with the colour of the pen used in the layer.

Useful to create legends or similar reference to the layers.

Parameters
sideside length in pixels
Returns
a wxBitmap filled with layer's colour

Definition at line 82 of file mathplot.cpp.

References mpLayer::m_pen, and square().

83 {
84  wxBitmap square( side, side, -1 );
85  wxColour filler = m_pen.GetColour();
86  wxBrush brush( filler, wxBRUSHSTYLE_SOLID );
87  wxMemoryDC dc;
88 
89  dc.SelectObject( square );
90  dc.SetBackground( brush );
91  dc.Clear();
92  dc.SelectObject( wxNullBitmap );
93  return square;
94 }
static double square(int x)
Definition: trigo.cpp:138
wxPen m_pen
Definition: mathplot.h:314
bool mpLayer::GetContinuity ( ) const
inlineinherited

Gets the 'continuity' property of the layer.

See also
SetContinuity

Definition at line 257 of file mathplot.h.

257 { return m_continuous; }
bool m_continuous
Definition: mathplot.h:317
bool mpLayer::GetDrawOutsideMargins ( )
inlineinherited

Get Draw mode: inside or outside margins.

Returns
The draw mode

Definition at line 284 of file mathplot.h.

284 { return m_drawOutsideMargins; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
const wxFont& mpLayer::GetFont ( ) const
inlineinherited

Get font set for this layer.

Returns
Font

Definition at line 242 of file mathplot.h.

242 { return m_font; }
wxFont m_font
Definition: mathplot.h:309
mpLayerType mpLayer::GetLayerType ( )
inlineinherited

Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.

Returns
An integer indicating layer type

Definition at line 293 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

293 { return m_type; };
mpLayerType m_type
Definition: mathplot.h:320
virtual double mpLayer::GetMaxX ( )
inlinevirtualinherited

Get inclusive right border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 179 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

179 { return 1.0; }
virtual double mpLayer::GetMaxY ( )
inlinevirtualinherited

Get inclusive top border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 189 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

189 { return 1.0; }
virtual double mpLayer::GetMinX ( )
inlinevirtualinherited

Get inclusive left border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 174 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

174 { return -1.0; }
virtual double mpLayer::GetMinY ( )
inlinevirtualinherited

Get inclusive bottom border of bounding box.

Returns
Value

Reimplemented in mpBitmapLayer, mpMovableObject, and mpFXYVector.

Definition at line 184 of file mathplot.h.

Referenced by mpWindow::UpdateBBox(), and mpFXY::UpdateScales().

184 { return -1.0; }
const wxString& mpLayer::GetName ( void  ) const
inlineinherited

Get layer name.

Returns
Name

Definition at line 237 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::GetLabelX(), SIM_PLOT_PANEL::GetLabelY1(), SIM_PLOT_PANEL::GetLabelY2(), mpInfoLegend::Plot(), and mpText::Plot().

237 { return m_name; }
wxString m_name
Definition: mathplot.h:316
const wxPen& mpLayer::GetPen ( ) const
inlineinherited

Get pen set for this layer.

Returns
Pen

Definition at line 247 of file mathplot.h.

Referenced by mpInfoLegend::Plot().

247 { return m_pen; }
wxPen m_pen
Definition: mathplot.h:314
virtual double mpProfile::GetY ( double  x)
pure virtual

Get function value for argument.

Override this function in your implementation.

Parameters
xArgument
Returns
Function value

Referenced by Plot().

virtual bool mpLayer::HasBBox ( )
inlinevirtualinherited

Check whether this layer has a bounding box.

The default implementation returns TRUE. Override and return FALSE if your mpLayer implementation should be ignored by the calculation of the global bounding box for all layers in a mpWindow.

Return values
TRUEHas bounding box
FALSEHas not bounding box

Reimplemented in mpBitmapLayer, mpMovableObject, mpText, mpScaleY, mpScaleBase, and mpInfoLayer.

Definition at line 160 of file mathplot.h.

Referenced by mpWindow::UpdateBBox().

160 { return TRUE; }
virtual bool mpLayer::IsInfo ( )
inlinevirtualinherited

Check whether the layer is an info box.

The default implementation returns FALSE. It is overrided to TRUE for mpInfoLayer class and its derivative. It is necessary to define mouse actions behaviour over info boxes.

Returns
whether the layer is an info boxes
See also
mpInfoLayer::IsInfo

Reimplemented in mpInfoLayer.

Definition at line 169 of file mathplot.h.

169 { return false; };
bool mpLayer::IsVisible ( )
inlineinherited

Checks whether the layer is visible or not.

Returns
true if visible

Definition at line 297 of file mathplot.h.

Referenced by mpWindow::IsLayerVisible(), SIM_PLOT_PANEL::IsLegendShown(), and mpInfoLegend::Plot().

297 { return m_visible; };
bool m_visible
Definition: mathplot.h:321
void mpProfile::Plot ( wxDC &  dc,
mpWindow w 
)
overridevirtual

Layer plot handler.

This implementation will plot the function in the visible area and put a label according to the aligment specified.

Implements mpLayer.

Definition at line 801 of file mathplot.cpp.

References mpWindow::GetMarginBottom(), mpWindow::GetMarginLeft(), mpWindow::GetMarginRight(), mpWindow::GetMarginTop(), mpWindow::GetScrX(), mpWindow::GetScrY(), GetY(), mpLayer::m_drawOutsideMargins, m_flags, mpLayer::m_font, mpLayer::m_name, mpLayer::m_pen, mpLayer::m_visible, mpALIGN_CENTER, mpALIGN_RIGHT, mpALIGNMASK, mpWindow::p2x(), and mpWindow::y2p().

802 {
803  if( m_visible )
804  {
805  dc.SetPen( m_pen );
806 
807  wxCoord startPx = m_drawOutsideMargins ? 0 : w.GetMarginLeft();
808  wxCoord endPx = m_drawOutsideMargins ? w.GetScrX() : w.GetScrX() - w.GetMarginRight();
809  wxCoord minYpx = m_drawOutsideMargins ? 0 : w.GetMarginTop();
810  wxCoord maxYpx = m_drawOutsideMargins ? w.GetScrY() : w.GetScrY() - w.GetMarginBottom();
811 
812  // Plot profile linking subsequent point of the profile, instead of mpFY, which plots simple points.
813  for( wxCoord i = startPx; i < endPx; ++i )
814  {
815  wxCoord c0 = w.y2p( GetY( w.p2x( i ) ) ); // (wxCoord) ((w.GetYpos() - GetY( (double)i / w.GetXscl() + w.GetXpos()) ) * w.GetYscl());
816  wxCoord c1 = w.y2p( GetY( w.p2x( i + 1 ) ) ); // (wxCoord) ((w.GetYpos() - GetY( (double)(i+1) / w.GetXscl() + (w.GetXpos() ) ) ) * w.GetYscl());
817 
818  // c0 = (c0 <= maxYpx) ? ((c0 >= minYpx) ? c0 : minYpx) : maxYpx;
819  // c1 = (c1 <= maxYpx) ? ((c1 >= minYpx) ? c1 : minYpx) : maxYpx;
820  if( !m_drawOutsideMargins )
821  {
822  c0 = (c0 <= maxYpx) ? ( (c0 >= minYpx) ? c0 : minYpx ) : maxYpx;
823  c1 = (c1 <= maxYpx) ? ( (c1 >= minYpx) ? c1 : minYpx ) : maxYpx;
824  }
825 
826  dc.DrawLine( i, c0, i + 1, c1 );
827  }
828 
829  ;
830 
831  if( !m_name.IsEmpty() )
832  {
833  dc.SetFont( m_font );
834 
835  wxCoord tx, ty;
836  dc.GetTextExtent( m_name, &tx, &ty );
837 
838  if( (m_flags & mpALIGNMASK) == mpALIGN_RIGHT )
839  tx = (w.GetScrX() - tx) - w.GetMarginRight() - 8;
840  else if( (m_flags & mpALIGNMASK) == mpALIGN_CENTER )
841  tx = ( (w.GetScrX() - w.GetMarginRight() - w.GetMarginLeft() - tx) / 2 ) +
842  w.GetMarginLeft();
843  else
844  tx = w.GetMarginLeft() + 8;
845 
846  dc.DrawText( m_name, tx, w.y2p( GetY( w.p2x( tx ) ) ) ); // (wxCoord) ((w.GetPosY() - GetY( (double)tx / w.GetScaleX() + w.GetPosX())) * w.GetScaleY()) );
847  }
848  }
849 }
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1181
int GetMarginBottom()
Get the bottom margin.
Definition: mathplot.h:1344
int GetScrY(void) const
Get current view's Y dimension in device context units.
Definition: mathplot.h:1136
#define mpALIGN_RIGHT
Aligns label to the right.
Definition: mathplot.h:476
bool m_visible
Definition: mathplot.h:321
wxCoord y2p(double y)
Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
Definition: mathplot.h:1196
int GetMarginTop()
Get the top margin.
Definition: mathplot.h:1340
virtual double GetY(double x)=0
Get function value for argument.
wxFont m_font
Definition: mathplot.h:309
int GetScrX(void) const
Get current view's X dimension in device context units.
Definition: mathplot.h:1127
#define mpALIGNMASK
Definition: mathplot.h:474
bool m_drawOutsideMargins
Definition: mathplot.h:319
int GetMarginRight()
Get the right margin.
Definition: mathplot.h:1342
int GetMarginLeft()
Get the left margin.
Definition: mathplot.h:1346
wxPen m_pen
Definition: mathplot.h:314
int m_flags
Definition: mathplot.h:669
#define mpALIGN_CENTER
Aligns label to the center.
Definition: mathplot.h:478
wxString m_name
Definition: mathplot.h:316
void mpLayer::SetBrush ( wxBrush  brush)
inlineinherited

Set layer brush.

Parameters
brushbrush, will be copied to internal class member

Definition at line 309 of file mathplot.h.

309 { m_brush = brush; };
wxBrush m_brush
Definition: mathplot.h:315
void mpLayer::SetContinuity ( bool  continuity)
inlineinherited

Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).

See also
GetContinuity

Definition at line 252 of file mathplot.h.

Referenced by TRACE::TRACE().

252 { m_continuous = continuity; }
bool m_continuous
Definition: mathplot.h:317
void mpLayer::SetDrawOutsideMargins ( bool  drawModeOutside)
inlineinherited

Set Draw mode: inside or outside margins.

Default is outside, which allows the layer to draw up to the mpWindow border.

Parameters
drawModeOutsideThe draw mode to be set

Definition at line 280 of file mathplot.h.

Referenced by CURSOR::CURSOR(), and TRACE::TRACE().

280 { m_drawOutsideMargins = drawModeOutside; };
bool m_drawOutsideMargins
Definition: mathplot.h:319
void mpLayer::SetFont ( wxFont &  font)
inlineinherited

Set layer font.

Parameters
fontFont, will be copied to internal class member

Definition at line 271 of file mathplot.h.

271 { m_font = font; }
wxFont m_font
Definition: mathplot.h:309
void mpLayer::SetName ( wxString  name)
inlineinherited

Set layer name.

Parameters
nameName, will be copied to internal class member

Definition at line 266 of file mathplot.h.

References name.

266 { m_name = name; }
const char * name
wxString m_name
Definition: mathplot.h:316
void mpLayer::SetPen ( wxPen  pen)
inlineinherited

Set layer pen.

Parameters
penPen, will be copied to internal class member

Definition at line 276 of file mathplot.h.

Referenced by SIM_PLOT_PANEL::AddTrace().

276 { m_pen = pen; }
wxPen m_pen
Definition: mathplot.h:314
void mpLayer::SetVisible ( bool  show)
inlineinherited

Sets layer visibility.

Parameters
showvisibility bool.

Definition at line 301 of file mathplot.h.

Referenced by mpWindow::SetLayerVisible(), SIM_PLOT_PANEL::ShowLegend(), and SIM_PLOT_PANEL::SIM_PLOT_PANEL().

301 { m_visible = show; };
bool m_visible
Definition: mathplot.h:321
void mpLayer::ShowName ( bool  show)
inlineinherited

Shows or hides the text label with the name of the layer (default is visible).

Definition at line 261 of file mathplot.h.

Referenced by TRACE::TRACE().

261 { m_showName = show; };
bool m_showName
Definition: mathplot.h:318

Member Data Documentation

wxBrush mpLayer::m_brush
protectedinherited

Definition at line 315 of file mathplot.h.

bool mpLayer::m_continuous
protectedinherited

Definition at line 317 of file mathplot.h.

Referenced by CURSOR::Plot(), mpFXY::Plot(), and mpMovableObject::Plot().

bool mpLayer::m_drawOutsideMargins
protectedinherited
int mpProfile::m_flags
protected

Definition at line 669 of file mathplot.h.

Referenced by Plot().

wxString mpLayer::m_name
protectedinherited
bool mpLayer::m_showName
protectedinherited
mpLayerType mpLayer::m_type
protectedinherited

Definition at line 320 of file mathplot.h.

Referenced by mpInfoLayer::mpInfoLayer().


The documentation for this class was generated from the following files: