KiCad PCB EDA Suite
mpWindow Class Reference

Canvas for plotting mpLayer implementations. More...

#include <mathplot.h>

Inheritance diagram for mpWindow:

Public Member Functions

 mpWindow ()
 
 mpWindow (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long flags=0)
 
 ~mpWindow ()
 
wxMenu * GetPopupMenu ()
 Get reference to context menu of the plot canvas. More...
 
bool AddLayer (mpLayer *layer, bool refreshDisplay=true)
 Add a plot layer to the canvas. More...
 
bool DelLayer (mpLayer *layer, bool alsoDeleteObject=false, bool refreshDisplay=true)
 Remove a plot layer from the canvas. More...
 
void DelAllLayers (bool alsoDeleteObject, bool refreshDisplay=true)
 Remove all layers from the plot. More...
 
mpLayerGetLayer (int position) const
 
const mpLayerGetLayerByName (const wxString &name) const
 
mpLayerGetLayerByName (const wxString &name)
 
double GetXscl () const
 Get current view's X scale. More...
 
double GetScaleX (void) const
 
double GetYscl () const
 Get current view's Y scale. More...
 
double GetScaleY (void) const
 
double GetXpos () const
 Get current view's X position. More...
 
double GetPosX (void) const
 
double GetYpos () const
 Get current view's Y position. More...
 
double GetPosY (void) const
 
int GetScrX (void) const
 Get current view's X dimension in device context units. More...
 
int GetXScreen (void) const
 
int GetScrY (void) const
 Get current view's Y dimension in device context units. More...
 
int GetYScreen (void) const
 
void SetScaleX (double scaleX)
 Set current view's X scale and refresh display. More...
 
void SetScaleY (double scaleY)
 Set current view's Y scale and refresh display. More...
 
void SetPosX (double posX)
 Set current view's X position and refresh display. More...
 
void SetPosY (double posY)
 Set current view's Y position and refresh display. More...
 
void SetPos (double posX, double posY)
 Set current view's X and Y position and refresh display. More...
 
void SetScr (int scrX, int scrY)
 Set current view's dimensions in device context units. More...
 
double p2x (wxCoord pixelCoordX)
 Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale. More...
 
double p2y (wxCoord pixelCoordY)
 Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale. More...
 
wxCoord x2p (double x)
 Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale. More...
 
wxCoord y2p (double y)
 Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale. More...
 
void EnableDoubleBuffer (bool enabled)
 Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled). More...
 
void EnableMousePanZoom (bool enabled)
 Enable/disable the feature of pan/zoom with the mouse (default=enabled) More...
 
void EnableMouseWheelPan (bool enabled)
 Enable/disable trackpad friendly panning (2-axis scroll wheel) More...
 
void LockAspect (bool enable=true)
 Enable or disable X/Y scale aspect locking for the view. More...
 
bool IsAspectLocked () const
 Checks whether the X/Y scale aspect is locked. More...
 
void Fit () override
 Set view to fit global bounding box of all plot layers and refresh display. More...
 
void Fit (double xMin, double xMax, double yMin, double yMax, wxCoord *printSizeX=NULL, wxCoord *printSizeY=NULL)
 Set view to fit a given bounding box and refresh display. More...
 
void ZoomIn (const wxPoint &centerPoint=wxDefaultPosition)
 Zoom into current view and refresh display. More...
 
void ZoomIn (const wxPoint &centerPoint, double zoomFactor)
 
void ZoomOut (const wxPoint &centerPoint=wxDefaultPosition)
 Zoom out current view and refresh display. More...
 
void ZoomOut (const wxPoint &centerPoint, double zoomFactor)
 
void ZoomInX ()
 Zoom in current view along X and refresh display. More...
 
void ZoomOutX ()
 Zoom out current view along X and refresh display. More...
 
void ZoomInY ()
 Zoom in current view along Y and refresh display. More...
 
void ZoomOutY ()
 Zoom out current view along Y and refresh display. More...
 
void ZoomRect (wxPoint p0, wxPoint p1)
 Zoom view fitting given coordinates to the window (p0 and p1 do not need to be in any specific order) More...
 
void UpdateAll ()
 Refresh display. More...
 
unsigned int CountLayers () const
 Counts the number of plot layers, excluding axes or text: this is to count only the layers which have a bounding box. More...
 
unsigned int CountAllLayers () const
 Counts the number of plot layers, whether or not they have a bounding box. More...
 
double GetDesiredXmin () const
 Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio). More...
 
double GetDesiredXmax () const
 Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio). More...
 
double GetDesiredYmin () const
 Returns the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio). More...
 
double GetDesiredYmax () const
 Returns the top layer-border coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio). More...
 
void GetBoundingBox (double *bbox) const
 Returns the bounding box coordinates. More...
 
void SetMPScrollbars (bool status)
 Enable/disable scrollbars. More...
 
bool GetMPScrollbars () const
 Get scrollbars status. More...
 
bool SaveScreenshot (const wxString &filename, wxBitmapType type=wxBITMAP_TYPE_BMP, wxSize imageSize=wxDefaultSize, bool fit=false)
 Draw the window on a wxBitmap, then save it to a file. More...
 
void SetMargins (int top, int right, int bottom, int left)
 Set window margins, creating a blank area where some kinds of layers cannot draw. More...
 
void SetMarginTop (int top)
 Set the top margin. More...
 
void SetMarginRight (int right)
 Set the right margin. More...
 
void SetMarginBottom (int bottom)
 Set the bottom margin. More...
 
void SetMarginLeft (int left)
 Set the left margin. More...
 
int GetMarginTop () const
 
int GetMarginRight () const
 
int GetMarginBottom () const
 
int GetMarginLeft () const
 
mpInfoLayerIsInsideInfoLayer (wxPoint &point)
 Check if a given point is inside the area of a mpInfoLayer and eventually returns its pointer. More...
 
void SetLayerVisible (const wxString &name, bool viewable)
 Sets the visibility of a layer by its name. More...
 
bool IsLayerVisible (const wxString &name) const
 Check whether a layer with given name is visible. More...
 
void SetLayerVisible (const unsigned int position, bool viewable)
 Sets the visibility of a layer by its position in layer list. More...
 
bool IsLayerVisible (unsigned int position) const
 Check whether the layer at given position is visible. More...
 
void SetColourTheme (const wxColour &bgColour, const wxColour &drawColour, const wxColour &axesColour)
 Set Color theme. More...
 
const wxColour & GetAxesColour ()
 Get axes draw colour. More...
 
void LimitView (bool aEnable)
 Limit zooming & panning to the area used by the plots. More...
 

Static Public Attributes

static double zoomIncrementalFactor = 1.1
 This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse wheel. More...
 

Protected Member Functions

void OnPaint (wxPaintEvent &event)
 
void OnSize (wxSizeEvent &event)
 
void OnShowPopupMenu (wxMouseEvent &event)
 
void OnMouseMiddleDown (wxMouseEvent &event)
 
void OnCenter (wxCommandEvent &event)
 
void OnFit (wxCommandEvent &event)
 
void OnZoomIn (wxCommandEvent &event)
 
void OnZoomOut (wxCommandEvent &event)
 
void OnLockAspect (wxCommandEvent &event)
 
void OnMouseWheel (wxMouseEvent &event)
 
void OnMagnify (wxMouseEvent &event)
 
void OnMouseMove (wxMouseEvent &event)
 
void OnMouseLeftDown (wxMouseEvent &event)
 
void OnMouseLeftRelease (wxMouseEvent &event)
 
void OnScrollThumbTrack (wxScrollWinEvent &event)
 
void OnScrollPageUp (wxScrollWinEvent &event)
 
void OnScrollPageDown (wxScrollWinEvent &event)
 
void OnScrollLineUp (wxScrollWinEvent &event)
 
void OnScrollLineDown (wxScrollWinEvent &event)
 
void OnScrollTop (wxScrollWinEvent &event)
 
void OnScrollBottom (wxScrollWinEvent &event)
 
void DoScrollCalc (const int position, const int orientation)
 
void DoZoomInXCalc (const int staticXpixel)
 
void DoZoomInYCalc (const int staticYpixel)
 
void DoZoomOutXCalc (const int staticXpixel)
 
void DoZoomOutYCalc (const int staticYpixel)
 
bool CheckXLimits (double &desiredMax, double &desiredMin) const
 
bool CheckYLimits (double &desiredMax, double &desiredMin) const
 
void AdjustLimitedView ()
 
virtual bool UpdateBBox ()
 Recalculate global layer bounding box, and save it in m_minX,... More...
 
virtual bool SetXView (double pos, double desiredMax, double desiredMin)
 Applies new X view coordinates depending on the settings. More...
 
virtual bool SetYView (double pos, double desiredMax, double desiredMin)
 Applies new Y view coordinates depending on the settings. More...
 

Protected Attributes

wxLayerList m_layers
 
wxMenu m_popmenu
 
bool m_lockaspect
 
wxColour m_bgColour
 
wxColour m_fgColour
 
wxColour m_axColour
 
double m_minX
 
double m_maxX
 
double m_minY
 
double m_maxY
 
double m_scaleX
 
double m_scaleY
 
double m_posX
 
double m_posY
 
int m_scrX
 
int m_scrY
 
int m_clickedX
 
int m_clickedY
 
double m_desiredXmin
 These are updated in Fit() only, and may be different from the real borders (layer coordinates) only if lock aspect ratio is true. More...
 
double m_desiredXmax
 
double m_desiredYmin
 
double m_desiredYmax
 
int m_marginTop
 
int m_marginRight
 
int m_marginBottom
 
int m_marginLeft
 
int m_last_lx
 
int m_last_ly
 
wxMemoryDC m_buff_dc
 
wxBitmap * m_buff_bmp
 
bool m_enableDoubleBuffer
 
bool m_enableMouseNavigation
 
bool m_enableMouseWheelPan
 
bool m_enableLimitedView
 
wxPoint m_mouseMClick
 
wxPoint m_mouseLClick
 
bool m_enableScrollBars
 
wxPoint m_scroll
 
mpInfoLayerm_movingInfoLayer
 
bool m_zooming
 
wxRect m_zoomRect
 

Detailed Description

Canvas for plotting mpLayer implementations.

This class defines a zoomable and moveable 2D plot canvas. Any number of mpLayer implementations (scale rulers, function plots, ...) can be attached using mpWindow::AddLayer.

The canvas window provides a context menu with actions for navigating the view. The context menu can be retrieved with mpWindow::GetPopupMenu, e.g. for extending it externally.

Since wxMathPlot version 0.03, the mpWindow incorporates the following features:

  • DoubleBuffering (Default=disabled): Can be set with EnableDoubleBuffer
  • Mouse based pan/zoom (Default=enabled): Can be set with EnableMousePanZoom.

The mouse commands can be visualized by the user through the popup menu, and are:

  • Mouse Move+CTRL: Pan (Move)
  • Mouse Wheel: Vertical scroll
  • Mouse Wheel+SHIFT: Horizontal scroll
  • Mouse Wheel UP+CTRL: Zoom in
  • Mouse Wheel DOWN+CTRL: Zoom out

Definition at line 1046 of file mathplot.h.

Constructor & Destructor Documentation

◆ mpWindow() [1/2]

mpWindow::mpWindow ( )

◆ mpWindow() [2/2]

mpWindow::mpWindow ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  flags = 0 
)

Definition at line 1638 of file mathplot.cpp.

1643  : wxWindow( parent, id, pos, size, flag, wxT( "mathplot" ) )
1644 {
1645  m_zooming = false;
1646  m_scaleX = m_scaleY = 1.0;
1647  m_posX = m_posY = 0;
1650  m_scrX = m_scrY = 64; // Fixed from m_scrX = m_scrX = 64;
1651  m_minX = m_minY = 0;
1652  m_maxX = m_maxY = 0;
1653  m_last_lx = m_last_ly = 0;
1654  m_buff_bmp = NULL;
1655  m_enableDoubleBuffer = false;
1656  m_enableMouseNavigation = true;
1657  m_enableLimitedView = false;
1658  m_movingInfoLayer = NULL;
1659  // Set margins to 0
1661 
1662 
1663  m_lockaspect = false;
1664 
1665  m_popmenu.Append( mpID_CENTER, _( "Center" ), _( "Center plot view to this position" ) );
1666  m_popmenu.Append( mpID_FIT, _( "Fit on Screen" ), _( "Set plot view to show all items" ) );
1667  m_popmenu.Append( mpID_ZOOM_IN, _( "Zoom In" ), _( "Zoom in plot view." ) );
1668  m_popmenu.Append( mpID_ZOOM_OUT, _( "Zoom Out" ), _( "Zoom out plot view." ) );
1669  // m_popmenu.AppendCheckItem( mpID_LOCKASPECT, _("Lock aspect"), _("Lock horizontal and vertical zoom aspect."));
1670  // m_popmenu.Append( mpID_HELP_MOUSE, _("Show mouse commands..."), _("Show help about the mouse commands."));
1671 
1672  m_layers.clear();
1673  SetBackgroundColour( *wxWHITE );
1674  m_bgColour = *wxWHITE;
1675  m_fgColour = *wxBLACK;
1676 
1677  m_enableScrollBars = false;
1678  SetSizeHints( 128, 128 );
1679 
1680  // J.L.Blanco: Eliminates the "flick" with the double buffer.
1681  SetBackgroundStyle( wxBG_STYLE_CUSTOM );
1682 
1683  UpdateAll();
1684 }
int m_marginRight
Definition: mathplot.h:1526
bool m_enableScrollBars
Definition: mathplot.h:1537
bool m_zooming
Definition: mathplot.h:1540
int m_marginLeft
Definition: mathplot.h:1526
double m_desiredXmax
Definition: mathplot.h:1524
double m_scaleY
Definition: mathplot.h:1513
bool m_enableMouseNavigation
Definition: mathplot.h:1532
double m_posX
Definition: mathplot.h:1514
double m_minY
Definition: mathplot.h:1510
double m_scaleX
Definition: mathplot.h:1512
wxLayerList m_layers
Definition: mathplot.h:1500
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
double m_desiredYmax
Definition: mathplot.h:1524
bool m_lockaspect
Definition: mathplot.h:1502
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
#define _(s)
mpInfoLayer * m_movingInfoLayer
Definition: mathplot.h:1539
wxColour m_fgColour
Definition: mathplot.h:1505
int m_last_ly
Definition: mathplot.h:1528
double m_posY
Definition: mathplot.h:1515
int m_marginTop
Definition: mathplot.h:1526
double m_minX
Definition: mathplot.h:1508
double m_desiredYmin
Definition: mathplot.h:1524
int m_marginBottom
Definition: mathplot.h:1526
int m_last_lx
Definition: mathplot.h:1528
int m_scrY
Definition: mathplot.h:1517
bool m_enableLimitedView
Definition: mathplot.h:1534
wxMenu m_popmenu
Definition: mathplot.h:1501
double m_maxX
Definition: mathplot.h:1509
wxColour m_bgColour
Definition: mathplot.h:1504
bool m_enableDoubleBuffer
Definition: mathplot.h:1531
int m_scrX
Definition: mathplot.h:1516
wxBitmap * m_buff_bmp
Definition: mathplot.h:1530
double m_maxY
Definition: mathplot.h:1511

References _, flag, m_bgColour, m_buff_bmp, m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_enableDoubleBuffer, m_enableLimitedView, m_enableMouseNavigation, m_enableScrollBars, m_fgColour, m_last_lx, m_last_ly, m_layers, m_lockaspect, m_marginBottom, m_marginLeft, m_marginRight, m_marginTop, m_maxX, m_maxY, m_minX, m_minY, m_movingInfoLayer, m_popmenu, m_posX, m_posY, m_scaleX, m_scaleY, m_scrX, m_scrY, m_zooming, mpID_CENTER, mpID_FIT, mpID_ZOOM_IN, mpID_ZOOM_OUT, and UpdateAll().

◆ ~mpWindow()

mpWindow::~mpWindow ( )

Definition at line 1687 of file mathplot.cpp.

1688 {
1689  // Free all the layers:
1690  DelAllLayers( true, false );
1691 
1692  if( m_buff_bmp )
1693  {
1694  delete m_buff_bmp;
1695  m_buff_bmp = NULL;
1696  }
1697 }
void DelAllLayers(bool alsoDeleteObject, bool refreshDisplay=true)
Remove all layers from the plot.
Definition: mathplot.cpp:2300
wxBitmap * m_buff_bmp
Definition: mathplot.h:1530

References DelAllLayers(), and m_buff_bmp.

Member Function Documentation

◆ AddLayer()

bool mpWindow::AddLayer ( mpLayer layer,
bool  refreshDisplay = true 
)

Add a plot layer to the canvas.

Parameters
layerPointer to layer. The mpLayer object will get under control of mpWindow, i.e. it will be delete'd on mpWindow destruction
refreshDisplayStates whether to refresh the display (UpdateAll) after adding the layer.
Return values
trueSuccess
falseFailure due to out of memory.

Definition at line 2256 of file mathplot.cpp.

2257 {
2258  if( layer != NULL )
2259  {
2260  m_layers.push_back( layer );
2261 
2262  if( refreshDisplay )
2263  UpdateAll();
2264 
2265  return true;
2266  }
2267 
2268  ;
2269  return false;
2270 }
wxLayerList m_layers
Definition: mathplot.h:1500
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403

References m_layers, and UpdateAll().

Referenced by SIM_PLOT_PANEL::addTrace(), SIM_PLOT_PANEL::EnableCursor(), SIM_PLOT_PANEL::SIM_PLOT_PANEL(), and SIM_PLOT_PANEL::updateAxes().

◆ AdjustLimitedView()

void mpWindow::AdjustLimitedView ( )
protected

Definition at line 1996 of file mathplot.cpp.

1997 {
1998  if( !m_enableLimitedView )
1999  return;
2000 
2001  // m_min and m_max are plot limits for curves
2002  // xMin, xMax, yMin, yMax are the full limits (plot limit + margin)
2003  const double xMin = m_minX - m_marginLeft / m_scaleX;
2004  const double xMax = m_maxX + m_marginRight / m_scaleX;
2005  const double yMin = m_minY - m_marginTop / m_scaleY;
2006  const double yMax = m_maxY + m_marginBottom / m_scaleY;
2007 
2008  if( m_desiredXmin < xMin )
2009  {
2010  double diff = xMin - m_desiredXmin;
2011  m_posX += diff;
2012  m_desiredXmax += diff;
2013  m_desiredXmin = xMin;
2014  }
2015 
2016  if( m_desiredXmax > xMax )
2017  {
2018  double diff = m_desiredXmax - xMax;
2019  m_posX -= diff;
2020  m_desiredXmin -= diff;
2021  m_desiredXmax = xMax;
2022  }
2023 
2024  if( m_desiredYmin < yMin )
2025  {
2026  double diff = yMin - m_desiredYmin;
2027  m_posY += diff;
2028  m_desiredYmax += diff;
2029  m_desiredYmin = yMin;
2030  }
2031 
2032  if( m_desiredYmax > yMax )
2033  {
2034  double diff = m_desiredYmax - yMax;
2035  m_posY -= diff;
2036  m_desiredYmin -= diff;
2037  m_desiredYmax = yMax;
2038  }
2039 }
int m_marginRight
Definition: mathplot.h:1526
int m_marginLeft
Definition: mathplot.h:1526
double m_desiredXmax
Definition: mathplot.h:1524
double m_scaleY
Definition: mathplot.h:1513
double m_posX
Definition: mathplot.h:1514
double m_minY
Definition: mathplot.h:1510
double m_scaleX
Definition: mathplot.h:1512
double m_desiredYmax
Definition: mathplot.h:1524
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
double m_posY
Definition: mathplot.h:1515
int m_marginTop
Definition: mathplot.h:1526
double m_minX
Definition: mathplot.h:1508
double m_desiredYmin
Definition: mathplot.h:1524
int m_marginBottom
Definition: mathplot.h:1526
bool m_enableLimitedView
Definition: mathplot.h:1534
double m_maxX
Definition: mathplot.h:1509
double m_maxY
Definition: mathplot.h:1511

References m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_enableLimitedView, m_marginBottom, m_marginLeft, m_marginRight, m_marginTop, m_maxX, m_maxY, m_minX, m_minY, m_posX, m_posY, m_scaleX, and m_scaleY.

Referenced by SetXView(), SetYView(), ZoomIn(), and ZoomRect().

◆ CheckXLimits()

bool mpWindow::CheckXLimits ( double &  desiredMax,
double &  desiredMin 
) const
inlineprotected

Definition at line 1468 of file mathplot.h.

1469  {
1470  return !( m_enableLimitedView
1471  && (desiredMax > m_maxX - m_marginRight / m_scaleX
1472  || desiredMin < m_minX - m_marginLeft / m_scaleX) );
1473  }
int m_marginRight
Definition: mathplot.h:1526
int m_marginLeft
Definition: mathplot.h:1526
double m_scaleX
Definition: mathplot.h:1512
double m_minX
Definition: mathplot.h:1508
bool m_enableLimitedView
Definition: mathplot.h:1534
double m_maxX
Definition: mathplot.h:1509

Referenced by ZoomOut().

◆ CheckYLimits()

bool mpWindow::CheckYLimits ( double &  desiredMax,
double &  desiredMin 
) const
inlineprotected

Definition at line 1475 of file mathplot.h.

1476  {
1477  return !( m_enableLimitedView
1478  && (desiredMax > m_maxY + m_marginBottom / m_scaleY
1479  || desiredMin < m_minY + m_marginTop / m_scaleY) );
1480  }
double m_scaleY
Definition: mathplot.h:1513
double m_minY
Definition: mathplot.h:1510
int m_marginTop
Definition: mathplot.h:1526
int m_marginBottom
Definition: mathplot.h:1526
bool m_enableLimitedView
Definition: mathplot.h:1534
double m_maxY
Definition: mathplot.h:1511

Referenced by ZoomOut().

◆ CountAllLayers()

unsigned int mpWindow::CountAllLayers ( ) const
inline

Counts the number of plot layers, whether or not they have a bounding box.

Returns
The number of layers in the mpWindow.

Definition at line 1293 of file mathplot.h.

1293 { return m_layers.size(); };
wxLayerList m_layers
Definition: mathplot.h:1500

Referenced by mpPrintout::OnPrintPage(), and mpInfoLegend::Plot().

◆ CountLayers()

unsigned int mpWindow::CountLayers ( ) const

Counts the number of plot layers, excluding axes or text: this is to count only the layers which have a bounding box.

Returns
The number of profiles plotted.

Definition at line 2586 of file mathplot.cpp.

2587 {
2588  unsigned int layerNo = 0;
2589 
2590  for( const mpLayer* layer : m_layers )
2591  {
2592  if( layer->HasBBox() )
2593  layerNo++;
2594  }
2595 
2596  return layerNo;
2597 }
wxLayerList m_layers
Definition: mathplot.h:1500

References m_layers.

◆ DelAllLayers()

void mpWindow::DelAllLayers ( bool  alsoDeleteObject,
bool  refreshDisplay = true 
)

Remove all layers from the plot.

Parameters
alsoDeleteObjectIf set to true, the mpLayer objects will be also "deleted", not just removed from the internal list.
refreshDisplayStates whether to refresh the display (UpdateAll) after removing the layers.

Definition at line 2300 of file mathplot.cpp.

2301 {
2302  while( m_layers.size()>0 )
2303  {
2304  // Also delete the object?
2305  if( alsoDeleteObject )
2306  delete m_layers[0];
2307 
2308  m_layers.erase( m_layers.begin() ); // this deleted the reference only
2309  }
2310 
2311  if( refreshDisplay )
2312  UpdateAll();
2313 }
wxLayerList m_layers
Definition: mathplot.h:1500
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403

References m_layers, and UpdateAll().

Referenced by ~mpWindow().

◆ DelLayer()

bool mpWindow::DelLayer ( mpLayer layer,
bool  alsoDeleteObject = false,
bool  refreshDisplay = true 
)

Remove a plot layer from the canvas.

Parameters
layerPointer to layer. The mpLayer object will be destructed using delete.
alsoDeleteObjectIf set to true, the mpLayer object will be also "deleted", not just removed from the internal list.
refreshDisplayStates whether to refresh the display (UpdateAll) after removing the layer.
Returns
true if layer is deleted correctly

N.B. Only the layer reference in the mpWindow is deleted, the layer object still exists!

Definition at line 2273 of file mathplot.cpp.

2276 {
2277  wxLayerList::iterator layIt;
2278 
2279  for( layIt = m_layers.begin(); layIt != m_layers.end(); layIt++ )
2280  {
2281  if( *layIt == layer )
2282  {
2283  // Also delete the object?
2284  if( alsoDeleteObject )
2285  delete *layIt;
2286 
2287  m_layers.erase( layIt ); // this deleted the reference only
2288 
2289  if( refreshDisplay )
2290  UpdateAll();
2291 
2292  return true;
2293  }
2294  }
2295 
2296  return false;
2297 }
wxLayerList m_layers
Definition: mathplot.h:1500
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403

References m_layers, and UpdateAll().

Referenced by SIM_PLOT_PANEL::addTrace(), SIM_PLOT_PANEL::deleteTrace(), and SIM_PLOT_PANEL::EnableCursor().

◆ DoScrollCalc()

void mpWindow::DoScrollCalc ( const int  position,
const int  orientation 
)
protected

Definition at line 2450 of file mathplot.cpp.

2451 {
2452  if( orientation == wxVERTICAL )
2453  {
2454  // Y axis
2455  // Get top margin in coord units
2456  double topMargin = m_marginTop / m_scaleY;
2457  // Calculate maximum Y coord to be shown in the graph
2458  double maxY = m_desiredYmax > m_maxY ? m_desiredYmax : m_maxY;
2459  // Set new position
2460  SetPosY( ( maxY - (position / m_scaleY) ) + topMargin );
2461  }
2462  else
2463  {
2464  // X Axis
2465  // Get left margin in coord units
2466  double leftMargin = m_marginLeft / m_scaleX;
2467  // Calculate minimum X coord to be shown in the graph
2468  double minX = (m_desiredXmin < m_minX) ? m_desiredXmin : m_minX;
2469  // Set new position
2470  SetPosX( ( minX + (position / m_scaleX) ) - leftMargin );
2471  }
2472 }
int m_marginLeft
Definition: mathplot.h:1526
double m_scaleY
Definition: mathplot.h:1513
double m_scaleX
Definition: mathplot.h:1512
void SetPosX(double posX)
Set current view's X position and refresh display.
Definition: mathplot.h:1169
void SetPosY(double posY)
Set current view's Y position and refresh display.
Definition: mathplot.h:1174
double m_desiredYmax
Definition: mathplot.h:1524
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
int m_marginTop
Definition: mathplot.h:1526
double m_minX
Definition: mathplot.h:1508
double m_maxY
Definition: mathplot.h:1511

References m_desiredXmin, m_desiredYmax, m_marginLeft, m_marginTop, m_maxY, m_minX, m_scaleX, m_scaleY, SetPosX(), and SetPosY().

Referenced by OnScrollBottom(), OnScrollLineDown(), OnScrollLineUp(), OnScrollPageDown(), OnScrollPageUp(), OnScrollThumbTrack(), and OnScrollTop().

◆ DoZoomInXCalc()

void mpWindow::DoZoomInXCalc ( const int  staticXpixel)
protected

Definition at line 1981 of file mathplot.cpp.

1982 {
1983  // Preserve the position of the clicked point:
1984  double staticX = p2x( staticXpixel );
1985 
1986  // Zoom in:
1988  // Adjust the new m_posx
1989  m_posX = staticX - (staticXpixel / m_scaleX);
1990  // Adjust desired
1993 }
int m_marginRight
Definition: mathplot.h:1526
int m_marginLeft
Definition: mathplot.h:1526
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1192
double m_desiredXmax
Definition: mathplot.h:1524
double m_posX
Definition: mathplot.h:1514
double m_scaleX
Definition: mathplot.h:1512
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
Definition: mathplot.h:1351
int m_scrX
Definition: mathplot.h:1516

References m_desiredXmax, m_desiredXmin, m_marginLeft, m_marginRight, m_posX, m_scaleX, m_scrX, p2x(), and zoomIncrementalFactor.

◆ DoZoomInYCalc()

void mpWindow::DoZoomInYCalc ( const int  staticYpixel)
protected

◆ DoZoomOutXCalc()

void mpWindow::DoZoomOutXCalc ( const int  staticXpixel)
protected

◆ DoZoomOutYCalc()

void mpWindow::DoZoomOutYCalc ( const int  staticYpixel)
protected

◆ EnableDoubleBuffer()

void mpWindow::EnableDoubleBuffer ( bool  enabled)
inline

Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).

Definition at line 1212 of file mathplot.h.

1212 { m_enableDoubleBuffer = enabled; }
bool m_enableDoubleBuffer
Definition: mathplot.h:1531

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

◆ EnableMousePanZoom()

void mpWindow::EnableMousePanZoom ( bool  enabled)
inline

Enable/disable the feature of pan/zoom with the mouse (default=enabled)

Definition at line 1216 of file mathplot.h.

1216 { m_enableMouseNavigation = enabled; }
bool m_enableMouseNavigation
Definition: mathplot.h:1532

◆ EnableMouseWheelPan()

void mpWindow::EnableMouseWheelPan ( bool  enabled)
inline

Enable/disable trackpad friendly panning (2-axis scroll wheel)

Definition at line 1220 of file mathplot.h.

1220 { m_enableMouseWheelPan = enabled; }
bool m_enableMouseWheelPan
Definition: mathplot.h:1533

Referenced by SIM_PLOT_FRAME::NewPlotPanel().

◆ Fit() [1/2]

void mpWindow::Fit ( )
override

Set view to fit global bounding box of all plot layers and refresh display.

Scale and position will be set to show all attached mpLayers. The X/Y scale aspect lock is taken into account.

Definition at line 1910 of file mathplot.cpp.

1911 {
1912  if( UpdateBBox() )
1913  Fit( m_minX, m_maxX, m_minY, m_maxY );
1914 }
double m_minY
Definition: mathplot.h:1510
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
Definition: mathplot.cpp:1910
double m_minX
Definition: mathplot.h:1508
virtual bool UpdateBBox()
Recalculate global layer bounding box, and save it in m_minX,...
Definition: mathplot.cpp:2392
double m_maxX
Definition: mathplot.h:1509
double m_maxY
Definition: mathplot.h:1511

References m_maxX, m_maxY, m_minX, m_minY, and UpdateBBox().

Referenced by LockAspect(), SIM_PLOT_FRAME::menuZoomFit(), OnFit(), mpPrintout::OnPrintPage(), OnSize(), SIM_PLOT_FRAME::removePlot(), SaveScreenshot(), ZoomOut(), and ZoomRect().

◆ Fit() [2/2]

void mpWindow::Fit ( double  xMin,
double  xMax,
double  yMin,
double  yMax,
wxCoord *  printSizeX = NULL,
wxCoord *  printSizeY = NULL 
)

Set view to fit a given bounding box and refresh display.

The X/Y scale aspect lock is taken into account. If provided, the parameters printSizeX and printSizeY are taken as the DC size, and the pixel scales are computed accordingly. Also, in this case the passed borders are not saved as the "desired borders", since this use will be invoked only when printing.

Definition at line 1918 of file mathplot.cpp.

1920 {
1921  // Save desired borders:
1922  m_desiredXmin = xMin; m_desiredXmax = xMax;
1923  m_desiredYmin = yMin; m_desiredYmax = yMax;
1924 
1925  // Give a small margin to plot area
1926  double xExtra = fabs( xMax - xMin ) * 0.00;
1927  double yExtra = fabs( yMax - yMin ) * 0.03;
1928 
1929  xMin -= xExtra;
1930  xMax += xExtra;
1931  yMin -= yExtra;
1932  yMax += yExtra;
1933 
1934  if( printSizeX != NULL && printSizeY != NULL )
1935  {
1936  // Printer:
1937  m_scrX = *printSizeX;
1938  m_scrY = *printSizeY;
1939  }
1940  else
1941  {
1942  // Normal case (screen):
1943  GetClientSize( &m_scrX, &m_scrY );
1944  }
1945 
1946  double Ax, Ay;
1947 
1948  Ax = xMax - xMin;
1949  Ay = yMax - yMin;
1950 
1951  m_scaleX = (Ax != 0) ? (m_scrX - m_marginLeft - m_marginRight) / Ax : 1; // m_scaleX = (Ax != 0) ? m_scrX / Ax : 1;
1952  m_scaleY = (Ay != 0) ? (m_scrY - m_marginTop - m_marginBottom) / Ay : 1; // m_scaleY = (Ay != 0) ? m_scrY / Ay : 1;
1953 
1954  if( m_lockaspect )
1955  {
1956  // Keep the lowest "scale" to fit the whole range required by that axis (to actually
1957  // "fit"!):
1958  double s = m_scaleX < m_scaleY ? m_scaleX : m_scaleY;
1959  m_scaleX = s;
1960  m_scaleY = s;
1961  }
1962 
1963  // Adjusts corner coordinates: This should be simply:
1964  // m_posX = m_minX;
1965  // m_posY = m_maxY;
1966  // But account for centering if we have lock aspect:
1967  m_posX = (xMin + xMax) / 2 - ( (m_scrX - m_marginLeft - m_marginRight) / 2 + m_marginLeft ) /
1968  m_scaleX; // m_posX = (xMin+xMax)/2 - (m_scrX/2)/m_scaleX;
1969  // m_posY = (yMin+yMax)/2 + ((m_scrY - m_marginTop - m_marginBottom)/2 - m_marginTop)/m_scaleY; // m_posY = (yMin+yMax)/2 + (m_scrY/2)/m_scaleY;
1970  m_posY = (yMin + yMax) / 2 + ( (m_scrY - m_marginTop - m_marginBottom) / 2 + m_marginTop ) /
1971  m_scaleY; // m_posY = (yMin+yMax)/2 + (m_scrY/2)/m_scaleY;
1972 
1973  // It is VERY IMPORTANT to DO NOT call Refresh if we are drawing to the printer!!
1974  // Otherwise, the DC dimensions will be those of the window instead of the printer device
1975  if( printSizeX == NULL || printSizeY == NULL )
1976  UpdateAll();
1977 }
int m_marginRight
Definition: mathplot.h:1526
int m_marginLeft
Definition: mathplot.h:1526
double m_desiredXmax
Definition: mathplot.h:1524
double m_scaleY
Definition: mathplot.h:1513
double m_posX
Definition: mathplot.h:1514
double m_scaleX
Definition: mathplot.h:1512
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
double m_desiredYmax
Definition: mathplot.h:1524
bool m_lockaspect
Definition: mathplot.h:1502
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
double m_posY
Definition: mathplot.h:1515
int m_marginTop
Definition: mathplot.h:1526
double m_desiredYmin
Definition: mathplot.h:1524
int m_marginBottom
Definition: mathplot.h:1526
int m_scrY
Definition: mathplot.h:1517
int m_scrX
Definition: mathplot.h:1516

References m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_lockaspect, m_marginBottom, m_marginLeft, m_marginRight, m_marginTop, m_posX, m_posY, m_scaleX, m_scaleY, m_scrX, m_scrY, and UpdateAll().

◆ GetAxesColour()

const wxColour& mpWindow::GetAxesColour ( )
inline

Get axes draw colour.

Returns
reference to axis colour used in theme

Definition at line 1426 of file mathplot.h.

1426 { return m_axColour; };
wxColour m_axColour
Definition: mathplot.h:1506

Referenced by mpPrintout::OnPrintPage().

◆ GetBoundingBox()

void mpWindow::GetBoundingBox ( double *  bbox) const

Returns the bounding box coordinates.

Parameters
bboxPointer to a 6-element double array where to store bounding box coordinates.

Definition at line 2621 of file mathplot.cpp.

2622 {
2623  bbox[0] = m_minX;
2624  bbox[1] = m_maxX;
2625  bbox[2] = m_minY;
2626  bbox[3] = m_maxY;
2627 }
double m_minY
Definition: mathplot.h:1510
double m_minX
Definition: mathplot.h:1508
double m_maxX
Definition: mathplot.h:1509
double m_maxY
Definition: mathplot.h:1511

References m_maxX, m_maxY, m_minX, and m_minY.

◆ GetDesiredXmax()

double mpWindow::GetDesiredXmax ( ) const
inline

Returns the right-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).

See also
Fit

Definition at line 1312 of file mathplot.h.

1312 { return m_desiredXmax; }
double m_desiredXmax
Definition: mathplot.h:1524

Referenced by mpPrintout::OnPrintPage().

◆ GetDesiredXmin()

double mpWindow::GetDesiredXmin ( ) const
inline

Returns the left-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).

See also
Fit

Definition at line 1306 of file mathplot.h.

1306 { return m_desiredXmin; }
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524

Referenced by mpPrintout::OnPrintPage().

◆ GetDesiredYmax()

double mpWindow::GetDesiredYmax ( ) const
inline

Returns the top layer-border coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).

See also
Fit

Definition at line 1324 of file mathplot.h.

1324 { return m_desiredYmax; }
double m_desiredYmax
Definition: mathplot.h:1524

Referenced by mpPrintout::OnPrintPage().

◆ GetDesiredYmin()

double mpWindow::GetDesiredYmin ( ) const
inline

Returns the bottom-border layer coordinate that the user wants the mpWindow to show (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).

See also
Fit

Definition at line 1318 of file mathplot.h.

1318 { return m_desiredYmin; }
double m_desiredYmin
Definition: mathplot.h:1524

Referenced by mpPrintout::OnPrintPage().

◆ GetLayer()

mpLayer * mpWindow::GetLayer ( int  position) const

Get the layer in list position indicated. N.B. You must know the index of the layer inside the list!

Parameters
positionposition of the layer in the layers list
Returns
pointer to mpLayer

Definition at line 2600 of file mathplot.cpp.

2601 {
2602  if( ( position >= (int) m_layers.size() ) || position < 0 )
2603  return NULL;
2604 
2605  return m_layers[position];
2606 }
wxLayerList m_layers
Definition: mathplot.h:1500

References m_layers.

Referenced by IsLayerVisible(), mpPrintout::OnPrintPage(), mpInfoLegend::Plot(), and SetLayerVisible().

◆ GetLayerByName() [1/2]

const mpLayer * mpWindow::GetLayerByName ( const wxString &  name) const

Get the layer by its name (case sensitive).

Parameters
nameThe name of the layer to retrieve
Returns
A pointer to the mpLayer object, or NULL if not found.

Definition at line 2609 of file mathplot.cpp.

2610 {
2611  for( const mpLayer* layer : m_layers )
2612  {
2613  if( !layer->GetName().Cmp( name ) )
2614  return layer;
2615  }
2616 
2617  return NULL; // Not found
2618 }
wxLayerList m_layers
Definition: mathplot.h:1500
const char * name
Definition: DXF_plotter.cpp:56

References m_layers, and name.

Referenced by IsLayerVisible(), and SetLayerVisible().

◆ GetLayerByName() [2/2]

mpLayer* mpWindow::GetLayerByName ( const wxString &  name)
inline

Definition at line 1099 of file mathplot.h.

1100  {
1101  return const_cast<mpLayer*>( static_cast<const mpWindow*>( this )->GetLayerByName( name ) );
1102  }
const mpLayer * GetLayerByName(const wxString &name) const
Definition: mathplot.cpp:2609
const char * name
Definition: DXF_plotter.cpp:56

References name.

◆ GetMarginBottom()

int mpWindow::GetMarginBottom ( ) const
inline

◆ GetMarginLeft()

int mpWindow::GetMarginLeft ( ) const
inline

◆ GetMarginRight()

int mpWindow::GetMarginRight ( ) const
inline

◆ GetMarginTop()

int mpWindow::GetMarginTop ( ) const
inline

◆ GetMPScrollbars()

bool mpWindow::GetMPScrollbars ( ) const
inline

Get scrollbars status.

Returns
true if scrollbars are visible

Definition at line 1337 of file mathplot.h.

1337 { return m_enableScrollBars; };
bool m_enableScrollBars
Definition: mathplot.h:1537

◆ GetPopupMenu()

wxMenu* mpWindow::GetPopupMenu ( )
inline

Get reference to context menu of the plot canvas.

Returns
Pointer to menu. The menu can be modified.

Definition at line 1059 of file mathplot.h.

1059 { return &m_popmenu; }
wxMenu m_popmenu
Definition: mathplot.h:1501

◆ GetPosX()

double mpWindow::GetPosX ( void  ) const
inline

Definition at line 1123 of file mathplot.h.

1123 { return m_posX; }
double m_posX
Definition: mathplot.h:1514

Referenced by mpScaleXBase::Plot(), mpMovableObject::Plot(), and mpBitmapLayer::Plot().

◆ GetPosY()

double mpWindow::GetPosY ( void  ) const
inline

Definition at line 1130 of file mathplot.h.

1130 { return m_posY; }
double m_posY
Definition: mathplot.h:1515

Referenced by mpScaleY::Plot(), mpMovableObject::Plot(), and mpBitmapLayer::Plot().

◆ GetScaleX()

double mpWindow::GetScaleX ( void  ) const
inline

Definition at line 1109 of file mathplot.h.

1109 { return m_scaleX; }; // Schaling's method: maybe another method exists with the same name
double m_scaleX
Definition: mathplot.h:1512

Referenced by mpScaleXBase::Plot(), mpMovableObject::Plot(), and mpBitmapLayer::Plot().

◆ GetScaleY()

double mpWindow::GetScaleY ( void  ) const
inline

Definition at line 1116 of file mathplot.h.

1116 { return m_scaleY; } // Schaling's method: maybe another method exists with the same name
double m_scaleY
Definition: mathplot.h:1513

Referenced by mpScaleY::Plot(), mpMovableObject::Plot(), and mpBitmapLayer::Plot().

◆ GetScrX()

int mpWindow::GetScrX ( void  ) const
inline

Get current view's X dimension in device context units.

Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer implementations should rely on the value returned by the function. See rules for coordinate transformation

Returns
X dimension.

Definition at line 1138 of file mathplot.h.

1138 { return m_scrX; }
int m_scrX
Definition: mathplot.h:1516

Referenced by mpScaleXBase::getVisibleDataRange(), CURSOR::Plot(), mpInfoLayer::Plot(), mpInfoCoords::Plot(), mpInfoLegend::Plot(), mpFX::Plot(), mpFY::Plot(), mpFXY::Plot(), mpProfile::Plot(), mpScaleXBase::Plot(), mpScaleY::Plot(), mpText::Plot(), mpMovableObject::Plot(), and mpBitmapLayer::Plot().

◆ GetScrY()

int mpWindow::GetScrY ( void  ) const
inline

Get current view's Y dimension in device context units.

Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer implementations should rely on the value returned by the function. See rules for coordinate transformation

Returns
Y dimension.

Definition at line 1147 of file mathplot.h.

1147 { return m_scrY; }
int m_scrY
Definition: mathplot.h:1517

Referenced by mpScaleY::getVisibleDataRange(), CURSOR::Plot(), mpInfoLayer::Plot(), mpInfoCoords::Plot(), mpInfoLegend::Plot(), mpFX::Plot(), mpFY::Plot(), mpFXY::Plot(), mpProfile::Plot(), mpScaleXBase::Plot(), mpScaleY::Plot(), mpText::Plot(), mpMovableObject::Plot(), and mpBitmapLayer::Plot().

◆ GetXpos()

double mpWindow::GetXpos ( ) const
inline

Get current view's X position.

See rules for coordinate transformation

Returns
X Position in layer coordinate system, that corresponds to the center point of the view.

Definition at line 1122 of file mathplot.h.

1122 { return m_posX; }
double m_posX
Definition: mathplot.h:1514

◆ GetXscl()

double mpWindow::GetXscl ( ) const
inline

Get current view's X scale.

See rules for coordinate transformation

Returns
Scale

Definition at line 1108 of file mathplot.h.

1108 { return m_scaleX; }
double m_scaleX
Definition: mathplot.h:1512

◆ GetXScreen()

int mpWindow::GetXScreen ( void  ) const
inline

Definition at line 1139 of file mathplot.h.

1139 { return m_scrX; }
int m_scrX
Definition: mathplot.h:1516

Referenced by SIM_PLOT_PANEL::EnableCursor().

◆ GetYpos()

double mpWindow::GetYpos ( ) const
inline

Get current view's Y position.

See rules for coordinate transformation

Returns
Y Position in layer coordinate system, that corresponds to the center point of the view.

Definition at line 1129 of file mathplot.h.

1129 { return m_posY; }
double m_posY
Definition: mathplot.h:1515

◆ GetYscl()

double mpWindow::GetYscl ( ) const
inline

Get current view's Y scale.

See rules for coordinate transformation

Returns
Scale

Definition at line 1115 of file mathplot.h.

1115 { return m_scaleY; }
double m_scaleY
Definition: mathplot.h:1513

◆ GetYScreen()

int mpWindow::GetYScreen ( void  ) const
inline

Definition at line 1148 of file mathplot.h.

1148 { return m_scrY; }
int m_scrY
Definition: mathplot.h:1517

◆ IsAspectLocked()

bool mpWindow::IsAspectLocked ( ) const
inline

Checks whether the X/Y scale aspect is locked.

Return values
trueLocked
falseUnlocked

Definition at line 1233 of file mathplot.h.

1233 { return m_lockaspect; }
bool m_lockaspect
Definition: mathplot.h:1502

◆ IsInsideInfoLayer()

mpInfoLayer * mpWindow::IsInsideInfoLayer ( wxPoint &  point)

Check if a given point is inside the area of a mpInfoLayer and eventually returns its pointer.

Parameters
pointThe position to be checked
Returns
If an info layer is found, returns its pointer, NULL otherwise

Definition at line 2691 of file mathplot.cpp.

2692 {
2693  for( mpLayer* layer : m_layers )
2694  {
2695  if( layer->IsInfo() )
2696  {
2697  mpInfoLayer* tmpLyr = static_cast<mpInfoLayer*>( layer );
2698 
2699  if( tmpLyr->Inside( point ) )
2700  return tmpLyr;
2701  }
2702  }
2703 
2704  return NULL;
2705 }
virtual bool Inside(wxPoint &point)
Checks whether a point is inside the info box rectangle.
Definition: mathplot.cpp:126
wxLayerList m_layers
Definition: mathplot.h:1500
Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rec...
Definition: mathplot.h:335

References mpInfoLayer::Inside(), and m_layers.

Referenced by OnMouseLeftDown().

◆ IsLayerVisible() [1/2]

bool mpWindow::IsLayerVisible ( const wxString &  name) const

Check whether a layer with given name is visible.

Parameters
nameThe layer name
Returns
layer visibility status

Definition at line 2720 of file mathplot.cpp.

2721 {
2722  const mpLayer* lx = GetLayerByName( name );
2723 
2724  return lx ? lx->IsVisible() : false;
2725 }
const mpLayer * GetLayerByName(const wxString &name) const
Definition: mathplot.cpp:2609
bool IsVisible() const
Checks whether the layer is visible or not.
Definition: mathplot.h:298
const char * name
Definition: DXF_plotter.cpp:56

References GetLayerByName(), mpLayer::IsVisible(), and name.

◆ IsLayerVisible() [2/2]

bool mpWindow::IsLayerVisible ( unsigned int  position) const

Check whether the layer at given position is visible.

Parameters
positionThe layer position in layer list
Returns
layer visibility status

Definition at line 2740 of file mathplot.cpp.

2741 {
2742  mpLayer* lx = GetLayer( position );
2743 
2744  return (lx) ? lx->IsVisible() : false;
2745 }
bool IsVisible() const
Checks whether the layer is visible or not.
Definition: mathplot.h:298
mpLayer * GetLayer(int position) const
Definition: mathplot.cpp:2600

References GetLayer(), and mpLayer::IsVisible().

◆ LimitView()

void mpWindow::LimitView ( bool  aEnable)
inline

Limit zooming & panning to the area used by the plots.

Definition at line 1429 of file mathplot.h.

1430  {
1431  m_enableLimitedView = aEnable;
1432  }
bool m_enableLimitedView
Definition: mathplot.h:1534

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

◆ LockAspect()

void mpWindow::LockAspect ( bool  enable = true)

Enable or disable X/Y scale aspect locking for the view.

Note
Explicit calls to mpWindow::SetScaleX and mpWindow::SetScaleY will set an unlocked aspect, but any other action changing the view scale will lock the aspect again.

Definition at line 2197 of file mathplot.cpp.

2198 {
2199  m_lockaspect = enable;
2200  m_popmenu.Check( mpID_LOCKASPECT, enable );
2201 
2202  // Try to fit again with the new config:
2204 }
double m_desiredXmax
Definition: mathplot.h:1524
double m_desiredYmax
Definition: mathplot.h:1524
bool m_lockaspect
Definition: mathplot.h:1502
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
Definition: mathplot.cpp:1910
double m_desiredYmin
Definition: mathplot.h:1524
wxMenu m_popmenu
Definition: mathplot.h:1501

References Fit(), m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_lockaspect, m_popmenu, and mpID_LOCKASPECT.

Referenced by OnLockAspect().

◆ OnCenter()

void mpWindow::OnCenter ( wxCommandEvent &  event)
protected

Definition at line 2227 of file mathplot.cpp.

2228 {
2229  GetClientSize( &m_scrX, &m_scrY );
2230  int centerX = (m_scrX - m_marginLeft - m_marginRight) / 2; // + m_marginLeft; // c.x = m_scrX/2;
2231  int centerY = (m_scrY - m_marginTop - m_marginBottom) / 2; // - m_marginTop; // c.y = m_scrY/2;
2232  SetPos( p2x( m_clickedX - centerX ), p2y( m_clickedY - centerY ) );
2233  // SetPos( p2x(m_clickedX-m_scrX/2), p2y(m_clickedY-m_scrY/2) ); //SetPos( (double)(m_clickedX-m_scrX/2) / m_scaleX + m_posX, (double)(m_scrY/2-m_clickedY) / m_scaleY + m_posY);
2234 }
int m_marginRight
Definition: mathplot.h:1526
int m_marginLeft
Definition: mathplot.h:1526
int m_clickedX
Definition: mathplot.h:1518
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1192
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1197
int m_marginTop
Definition: mathplot.h:1526
void SetPos(double posX, double posY)
Set current view's X and Y position and refresh display.
Definition: mathplot.h:1180
int m_clickedY
Definition: mathplot.h:1519
int m_marginBottom
Definition: mathplot.h:1526
int m_scrY
Definition: mathplot.h:1517
int m_scrX
Definition: mathplot.h:1516

References m_clickedX, m_clickedY, m_marginBottom, m_marginLeft, m_marginRight, m_marginTop, m_scrX, m_scrY, p2x(), p2y(), and SetPos().

◆ OnFit()

void mpWindow::OnFit ( wxCommandEvent &  event)
protected

Definition at line 2221 of file mathplot.cpp.

2222 {
2223  Fit();
2224 }
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
Definition: mathplot.cpp:1910

References Fit().

◆ OnLockAspect()

void mpWindow::OnLockAspect ( wxCommandEvent &  event)
protected

Definition at line 2215 of file mathplot.cpp.

2216 {
2218 }
void LockAspect(bool enable=true)
Enable or disable X/Y scale aspect locking for the view.
Definition: mathplot.cpp:2197
bool m_lockaspect
Definition: mathplot.h:1502

References LockAspect(), and m_lockaspect.

◆ OnMagnify()

void mpWindow::OnMagnify ( wxMouseEvent &  event)
protected

◆ OnMouseLeftDown()

void mpWindow::OnMouseLeftDown ( wxMouseEvent &  event)
protected

Definition at line 1876 of file mathplot.cpp.

1877 {
1878  m_mouseLClick.x = event.GetX();
1879  m_mouseLClick.y = event.GetY();
1880  m_zooming = true;
1881  wxPoint pointClicked = event.GetPosition();
1882  m_movingInfoLayer = IsInsideInfoLayer( pointClicked );
1883 
1884  event.Skip();
1885 }
bool m_zooming
Definition: mathplot.h:1540
mpInfoLayer * IsInsideInfoLayer(wxPoint &point)
Check if a given point is inside the area of a mpInfoLayer and eventually returns its pointer.
Definition: mathplot.cpp:2691
wxPoint m_mouseLClick
Definition: mathplot.h:1536
mpInfoLayer * m_movingInfoLayer
Definition: mathplot.h:1539

References IsInsideInfoLayer(), m_mouseLClick, m_movingInfoLayer, and m_zooming.

◆ OnMouseLeftRelease()

void mpWindow::OnMouseLeftRelease ( wxMouseEvent &  event)
protected

Definition at line 1888 of file mathplot.cpp.

1889 {
1890  wxPoint release( event.GetX(), event.GetY() );
1891  wxPoint press( m_mouseLClick.x, m_mouseLClick.y );
1892 
1893  m_zooming = false;
1894 
1895  if( m_movingInfoLayer != NULL )
1896  {
1898  m_movingInfoLayer = NULL;
1899  }
1900  else
1901  {
1902  if( release != press )
1903  ZoomRect( press, release );
1904  }
1905 
1906  event.Skip();
1907 }
bool m_zooming
Definition: mathplot.h:1540
wxPoint m_mouseLClick
Definition: mathplot.h:1536
void ZoomRect(wxPoint p0, wxPoint p1)
Zoom view fitting given coordinates to the window (p0 and p1 do not need to be in any specific order)
Definition: mathplot.cpp:2178
mpInfoLayer * m_movingInfoLayer
Definition: mathplot.h:1539
virtual void UpdateReference()
Updates the rectangle reference point.
Definition: mathplot.cpp:139

References m_mouseLClick, m_movingInfoLayer, m_zooming, mpInfoLayer::UpdateReference(), and ZoomRect().

◆ OnMouseMiddleDown()

void mpWindow::OnMouseMiddleDown ( wxMouseEvent &  event)
protected

Definition at line 1702 of file mathplot.cpp.

1703 {
1704  m_mouseMClick.x = event.GetX();
1705  m_mouseMClick.y = event.GetY();
1706 }
wxPoint m_mouseMClick
Definition: mathplot.h:1535

References m_mouseMClick.

◆ OnMouseMove()

void mpWindow::OnMouseMove ( wxMouseEvent &  event)
protected

Definition at line 1785 of file mathplot.cpp.

1786 {
1788  {
1789  event.Skip();
1790  return;
1791  }
1792 
1793  if( event.m_middleDown )
1794  {
1795  // The change:
1796  int Ax = m_mouseMClick.x - event.GetX();
1797  int Ay = m_mouseMClick.y - event.GetY();
1798 
1799  // For the next event, use relative to this coordinates.
1800  m_mouseMClick.x = event.GetX();
1801  m_mouseMClick.y = event.GetY();
1802 
1803  double Ax_units = Ax / m_scaleX;
1804  double Ay_units = -Ay / m_scaleY;
1805 
1806  bool updateRequired = false;
1807  updateRequired |= SetXView( m_posX + Ax_units,
1808  m_desiredXmax + Ax_units,
1809  m_desiredXmin + Ax_units );
1810  updateRequired |= SetYView( m_posY + Ay_units,
1811  m_desiredYmax + Ay_units,
1812  m_desiredYmin + Ay_units );
1813 
1814  if( updateRequired )
1815  UpdateAll();
1816  }
1817  else
1818  {
1819  if( event.m_leftDown )
1820  {
1821  if( m_movingInfoLayer == NULL )
1822  {
1823  wxClientDC dc( this );
1824  wxPen pen( m_fgColour, 1, wxPENSTYLE_DOT );
1825  dc.SetPen( pen );
1826  dc.SetBrush( *wxTRANSPARENT_BRUSH );
1827  dc.DrawRectangle( m_mouseLClick.x, m_mouseLClick.y,
1828  event.GetX() - m_mouseLClick.x, event.GetY() - m_mouseLClick.y );
1829  m_zooming = true;
1830  m_zoomRect.x = m_mouseLClick.x;
1831  m_zoomRect.y = m_mouseLClick.y;
1832  m_zoomRect.width = event.GetX() - m_mouseLClick.x;
1833  m_zoomRect.height = event.GetY() - m_mouseLClick.y;
1834  }
1835  else
1836  {
1837  wxPoint moveVector( event.GetX() - m_mouseLClick.x, event.GetY() - m_mouseLClick.y );
1838  m_movingInfoLayer->Move( moveVector );
1839  m_zooming = false;
1840  }
1841 
1842  UpdateAll();
1843  }
1844  else
1845  {
1846 #if 0
1847  wxLayerList::iterator li;
1848 
1849  for( li = m_layers.begin(); li != m_layers.end(); li++ )
1850  {
1851  if( (*li)->IsInfo() && (*li)->IsVisible() )
1852  {
1853  mpInfoLayer* tmpLyr = (mpInfoLayer*) (*li);
1854  tmpLyr->UpdateInfo( *this, event );
1855  // UpdateAll();
1856  RefreshRect( tmpLyr->GetRectangle() );
1857  }
1858  }
1859 
1860 #endif
1861  /* if (m_coordTooltip) {
1862  * wxString toolTipContent;
1863  * toolTipContent.Printf( "X = %f\nY = %f", p2x(event.GetX()), p2y(event.GetY()));
1864  * wxTipWindow** ptr = NULL;
1865  * wxRect rectBounds(event.GetX(), event.GetY(), 5, 5);
1866  * wxTipWindow* tip = new wxTipWindow(this, toolTipContent, 100, ptr, &rectBounds);
1867  *
1868  * } */
1869  }
1870  }
1871 
1872  event.Skip();
1873 }
bool m_zooming
Definition: mathplot.h:1540
const wxRect & GetRectangle() const
Returns the current rectangle coordinates.
Definition: mathplot.h:392
virtual bool SetYView(double pos, double desiredMax, double desiredMin)
Applies new Y view coordinates depending on the settings.
Definition: mathplot.cpp:2056
double m_desiredXmax
Definition: mathplot.h:1524
double m_scaleY
Definition: mathplot.h:1513
bool m_enableMouseNavigation
Definition: mathplot.h:1532
double m_posX
Definition: mathplot.h:1514
wxPoint m_mouseMClick
Definition: mathplot.h:1535
double m_scaleX
Definition: mathplot.h:1512
wxLayerList m_layers
Definition: mathplot.h:1500
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
wxPoint m_mouseLClick
Definition: mathplot.h:1536
virtual void Move(wxPoint delta)
Moves the layer rectangle of given pixel deltas.
Definition: mathplot.cpp:132
double m_desiredYmax
Definition: mathplot.h:1524
virtual void UpdateInfo(mpWindow &w, wxEvent &event)
Updates the content of the info box.
Definition: mathplot.cpp:121
Base class to create small rectangular info boxes mpInfoLayer is the base class to create a small rec...
Definition: mathplot.h:335
wxRect m_zoomRect
Definition: mathplot.h:1541
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
mpInfoLayer * m_movingInfoLayer
Definition: mathplot.h:1539
wxColour m_fgColour
Definition: mathplot.h:1505
double m_posY
Definition: mathplot.h:1515
double m_desiredYmin
Definition: mathplot.h:1524
virtual bool SetXView(double pos, double desiredMax, double desiredMin)
Applies new X view coordinates depending on the settings.
Definition: mathplot.cpp:2042

References mpInfoLayer::GetRectangle(), m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_enableMouseNavigation, m_fgColour, m_layers, m_mouseLClick, m_mouseMClick, m_movingInfoLayer, m_posX, m_posY, m_scaleX, m_scaleY, m_zooming, m_zoomRect, mpInfoLayer::Move(), SetXView(), SetYView(), UpdateAll(), and mpInfoLayer::UpdateInfo().

◆ OnMouseWheel()

void mpWindow::OnMouseWheel ( wxMouseEvent &  event)
protected

Definition at line 1730 of file mathplot.cpp.

1731 {
1733  {
1734  event.Skip();
1735  return;
1736  }
1737 
1738  int change = event.GetWheelRotation();
1739  const int axis = event.GetWheelAxis();
1740  double changeUnitsX = change / m_scaleX;
1741  double changeUnitsY = change / m_scaleY;
1742 
1743  if( ( !m_enableMouseWheelPan && ( event.ControlDown() || event.ShiftDown() ) )
1744  || ( m_enableMouseWheelPan && !event.ControlDown() ) )
1745  {
1746  // Scrolling
1747  if( m_enableMouseWheelPan )
1748  {
1749  if( axis == wxMOUSE_WHEEL_HORIZONTAL || event.ShiftDown() )
1750  SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
1751  m_desiredXmin + changeUnitsX );
1752  else
1753  SetYView( m_posY + changeUnitsY, m_desiredYmax + changeUnitsY,
1754  m_desiredYmin + changeUnitsY );
1755  }
1756  else
1757  {
1758  if( event.ControlDown() )
1759  SetXView( m_posX + changeUnitsX, m_desiredXmax + changeUnitsX,
1760  m_desiredXmin + changeUnitsX );
1761  else
1762  SetYView( m_posY + changeUnitsY, m_desiredYmax + changeUnitsY,
1763  m_desiredYmin + changeUnitsY );
1764  }
1765 
1766  UpdateAll();
1767  }
1768  else
1769  {
1770  // zoom in/out
1771  wxPoint clickPt( event.GetX(), event.GetY() );
1772 
1773  if( event.GetWheelRotation() > 0 )
1774  ZoomIn( clickPt );
1775  else
1776  ZoomOut( clickPt );
1777 
1778  return;
1779  }
1780 }
void ZoomOut(const wxPoint &centerPoint=wxDefaultPosition)
Zoom out current view and refresh display.
Definition: mathplot.cpp:2127
virtual bool SetYView(double pos, double desiredMax, double desiredMin)
Applies new Y view coordinates depending on the settings.
Definition: mathplot.cpp:2056
double m_desiredXmax
Definition: mathplot.h:1524
double m_scaleY
Definition: mathplot.h:1513
bool m_enableMouseNavigation
Definition: mathplot.h:1532
double m_posX
Definition: mathplot.h:1514
bool m_enableMouseWheelPan
Definition: mathplot.h:1533
double m_scaleX
Definition: mathplot.h:1512
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
double m_desiredYmax
Definition: mathplot.h:1524
void ZoomIn(const wxPoint &centerPoint=wxDefaultPosition)
Zoom into current view and refresh display.
Definition: mathplot.cpp:2070
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
double m_posY
Definition: mathplot.h:1515
double m_desiredYmin
Definition: mathplot.h:1524
virtual bool SetXView(double pos, double desiredMax, double desiredMin)
Applies new X view coordinates depending on the settings.
Definition: mathplot.cpp:2042

References m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_enableMouseNavigation, m_enableMouseWheelPan, m_posX, m_posY, m_scaleX, m_scaleY, SetXView(), SetYView(), UpdateAll(), ZoomIn(), and ZoomOut().

◆ OnPaint()

void mpWindow::OnPaint ( wxPaintEvent &  event)
protected

Definition at line 2316 of file mathplot.cpp.

2317 {
2318  wxPaintDC dc( this );
2319 
2320  dc.GetSize( &m_scrX, &m_scrY ); // This is the size of the visible area only!
2321 
2322  // Selects direct or buffered draw:
2323  wxDC* trgDc;
2324 
2325  // J.L.Blanco @ Aug 2007: Added double buffer support
2326  if( m_enableDoubleBuffer )
2327  {
2328  if( m_last_lx != m_scrX || m_last_ly != m_scrY )
2329  {
2330  if( m_buff_bmp )
2331  delete m_buff_bmp;
2332 
2333  m_buff_bmp = new wxBitmap( m_scrX, m_scrY );
2334  m_buff_dc.SelectObject( *m_buff_bmp );
2335  m_last_lx = m_scrX;
2336  m_last_ly = m_scrY;
2337  }
2338 
2339  trgDc = &m_buff_dc;
2340  }
2341  else
2342  {
2343  trgDc = &dc;
2344  }
2345 
2346  // Draw background:
2347  // trgDc->SetDeviceOrigin(0,0);
2348  trgDc->SetPen( *wxTRANSPARENT_PEN );
2349  wxBrush brush( GetBackgroundColour() );
2350  trgDc->SetBrush( brush );
2351  trgDc->SetTextForeground( m_fgColour );
2352  trgDc->DrawRectangle( 0, 0, m_scrX, m_scrY );
2353 
2354  // Draw all the layers:
2355  // trgDc->SetDeviceOrigin( m_scrX>>1, m_scrY>>1); // Origin at the center
2356  wxLayerList::iterator li;
2357 
2358  for( li = m_layers.begin(); li != m_layers.end(); li++ )
2359  (*li)->Plot( *trgDc, *this );
2360 
2361  if( m_zooming )
2362  {
2363  wxPen pen( m_fgColour, 1, wxPENSTYLE_DOT );
2364  trgDc->SetPen( pen );
2365  trgDc->SetBrush( *wxTRANSPARENT_BRUSH );
2366  trgDc->DrawRectangle( m_zoomRect );
2367  }
2368 
2369  // If doublebuffer, draw now to the window:
2370  if( m_enableDoubleBuffer )
2371  {
2372  // trgDc->SetDeviceOrigin(0,0);
2373  // dc.SetDeviceOrigin(0,0); // Origin at the center
2374  dc.Blit( 0, 0, m_scrX, m_scrY, trgDc, 0, 0 );
2375  }
2376 
2377  // If scrollbars are enabled, refresh them
2378  if( m_enableScrollBars )
2379  {
2380  /* m_scroll.x = (int) floor((m_posX - m_minX)*m_scaleX);
2381  * m_scroll.y = (int) floor((m_maxY - m_posY )*m_scaleY);
2382  * Scroll(m_scroll.x, m_scroll.y);*/
2383  // Scroll(x2p(m_posX), y2p(m_posY));
2384  // SetVirtualSize((int) ((m_maxX - m_minX)*m_scaleX), (int) ((m_maxY - m_minY)*m_scaleY));
2385  // int centerX = (m_scrX - m_marginLeft - m_marginRight)/2; // + m_marginLeft; // c.x = m_scrX/2;
2386  // int centerY = (m_scrY - m_marginTop - m_marginBottom)/2; // - m_marginTop; // c.y = m_scrY/2;
2387  /*SetScrollbars(1, 1, (int) ((m_maxX - m_minX)*m_scaleX), (int) ((m_maxY - m_minY)*m_scaleY));*/ // , x2p(m_posX + centerX/m_scaleX), y2p(m_posY - centerY/m_scaleY), true);
2388  }
2389 }
wxMemoryDC m_buff_dc
Definition: mathplot.h:1529
bool m_enableScrollBars
Definition: mathplot.h:1537
bool m_zooming
Definition: mathplot.h:1540
wxLayerList m_layers
Definition: mathplot.h:1500
wxRect m_zoomRect
Definition: mathplot.h:1541
wxColour m_fgColour
Definition: mathplot.h:1505
int m_last_ly
Definition: mathplot.h:1528
int m_last_lx
Definition: mathplot.h:1528
int m_scrY
Definition: mathplot.h:1517
bool m_enableDoubleBuffer
Definition: mathplot.h:1531
int m_scrX
Definition: mathplot.h:1516
wxBitmap * m_buff_bmp
Definition: mathplot.h:1530

References m_buff_bmp, m_buff_dc, m_enableDoubleBuffer, m_enableScrollBars, m_fgColour, m_last_lx, m_last_ly, m_layers, m_scrX, m_scrY, m_zooming, and m_zoomRect.

◆ OnScrollBottom()

void mpWindow::OnScrollBottom ( wxScrollWinEvent &  event)
protected

Definition at line 2561 of file mathplot.cpp.

2562 {
2563  int scrollOrientation = event.GetOrientation();
2564  // Get thumb size
2565  int thumbSize = GetScrollThumb( scrollOrientation );
2566  // Get scroll range
2567  int scrollRange = GetScrollRange( scrollOrientation );
2568 
2569  DoScrollCalc( scrollRange - thumbSize, scrollOrientation );
2570 }
void DoScrollCalc(const int position, const int orientation)
Definition: mathplot.cpp:2450

References DoScrollCalc().

◆ OnScrollLineDown()

void mpWindow::OnScrollLineDown ( wxScrollWinEvent &  event)
protected

Definition at line 2535 of file mathplot.cpp.

2536 {
2537  int scrollOrientation = event.GetOrientation();
2538  // Get position before page up
2539  int position = GetScrollPos( scrollOrientation );
2540  // Get thumb size
2541  int thumbSize = GetScrollThumb( scrollOrientation );
2542  // Get scroll range
2543  int scrollRange = GetScrollRange( scrollOrientation );
2544 
2545  // Need to adjust position by a page
2546  position += mpSCROLL_NUM_PIXELS_PER_LINE;
2547 
2548  if( position > (scrollRange - thumbSize) )
2549  position = scrollRange - thumbSize;
2550 
2551  DoScrollCalc( position, scrollOrientation );
2552 }
#define mpSCROLL_NUM_PIXELS_PER_LINE
Definition: mathplot.cpp:52
void DoScrollCalc(const int position, const int orientation)
Definition: mathplot.cpp:2450

References DoScrollCalc(), and mpSCROLL_NUM_PIXELS_PER_LINE.

◆ OnScrollLineUp()

void mpWindow::OnScrollLineUp ( wxScrollWinEvent &  event)
protected

Definition at line 2519 of file mathplot.cpp.

2520 {
2521  int scrollOrientation = event.GetOrientation();
2522  // Get position before page up
2523  int position = GetScrollPos( scrollOrientation );
2524 
2525  // Need to adjust position by a line
2526  position -= mpSCROLL_NUM_PIXELS_PER_LINE;
2527 
2528  if( position < 0 )
2529  position = 0;
2530 
2531  DoScrollCalc( position, scrollOrientation );
2532 }
#define mpSCROLL_NUM_PIXELS_PER_LINE
Definition: mathplot.cpp:52
void DoScrollCalc(const int position, const int orientation)
Definition: mathplot.cpp:2450

References DoScrollCalc(), and mpSCROLL_NUM_PIXELS_PER_LINE.

◆ OnScrollPageDown()

void mpWindow::OnScrollPageDown ( wxScrollWinEvent &  event)
protected

Definition at line 2499 of file mathplot.cpp.

2500 {
2501  int scrollOrientation = event.GetOrientation();
2502  // Get position before page up
2503  int position = GetScrollPos( scrollOrientation );
2504  // Get thumb size
2505  int thumbSize = GetScrollThumb( scrollOrientation );
2506  // Get scroll range
2507  int scrollRange = GetScrollRange( scrollOrientation );
2508 
2509  // Need to adjust position by a page
2510  position += thumbSize;
2511 
2512  if( position > (scrollRange - thumbSize) )
2513  position = scrollRange - thumbSize;
2514 
2515  DoScrollCalc( position, scrollOrientation );
2516 }
void DoScrollCalc(const int position, const int orientation)
Definition: mathplot.cpp:2450

References DoScrollCalc().

◆ OnScrollPageUp()

void mpWindow::OnScrollPageUp ( wxScrollWinEvent &  event)
protected

Definition at line 2481 of file mathplot.cpp.

2482 {
2483  int scrollOrientation = event.GetOrientation();
2484  // Get position before page up
2485  int position = GetScrollPos( scrollOrientation );
2486  // Get thumb size
2487  int thumbSize = GetScrollThumb( scrollOrientation );
2488 
2489  // Need to adjust position by a page
2490  position -= thumbSize;
2491 
2492  if( position < 0 )
2493  position = 0;
2494 
2495  DoScrollCalc( position, scrollOrientation );
2496 }
void DoScrollCalc(const int position, const int orientation)
Definition: mathplot.cpp:2450

References DoScrollCalc().

◆ OnScrollThumbTrack()

void mpWindow::OnScrollThumbTrack ( wxScrollWinEvent &  event)
protected

Definition at line 2475 of file mathplot.cpp.

2476 {
2477  DoScrollCalc( event.GetPosition(), event.GetOrientation() );
2478 }
void DoScrollCalc(const int position, const int orientation)
Definition: mathplot.cpp:2450

References DoScrollCalc().

◆ OnScrollTop()

void mpWindow::OnScrollTop ( wxScrollWinEvent &  event)
protected

Definition at line 2555 of file mathplot.cpp.

2556 {
2557  DoScrollCalc( 0, event.GetOrientation() );
2558 }
void DoScrollCalc(const int position, const int orientation)
Definition: mathplot.cpp:2450

References DoScrollCalc().

◆ OnShowPopupMenu()

void mpWindow::OnShowPopupMenu ( wxMouseEvent &  event)
protected

Definition at line 2207 of file mathplot.cpp.

2208 {
2209  m_clickedX = event.GetX();
2210  m_clickedY = event.GetY();
2211  PopupMenu( &m_popmenu, event.GetX(), event.GetY() );
2212 }
int m_clickedX
Definition: mathplot.h:1518
int m_clickedY
Definition: mathplot.h:1519
wxMenu m_popmenu
Definition: mathplot.h:1501

References m_clickedX, m_clickedY, and m_popmenu.

◆ OnSize()

void mpWindow::OnSize ( wxSizeEvent &  event)
protected

Definition at line 2249 of file mathplot.cpp.

2250 {
2251  // Try to fit again with the new window size:
2253 }
double m_desiredXmax
Definition: mathplot.h:1524
double m_desiredYmax
Definition: mathplot.h:1524
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
Definition: mathplot.cpp:1910
double m_desiredYmin
Definition: mathplot.h:1524

References Fit(), m_desiredXmax, m_desiredXmin, m_desiredYmax, and m_desiredYmin.

◆ OnZoomIn()

void mpWindow::OnZoomIn ( wxCommandEvent &  event)
protected

Definition at line 2237 of file mathplot.cpp.

2238 {
2239  ZoomIn( wxPoint( m_mouseMClick.x, m_mouseMClick.y ) );
2240 }
wxPoint m_mouseMClick
Definition: mathplot.h:1535
void ZoomIn(const wxPoint &centerPoint=wxDefaultPosition)
Zoom into current view and refresh display.
Definition: mathplot.cpp:2070

References m_mouseMClick, and ZoomIn().

◆ OnZoomOut()

void mpWindow::OnZoomOut ( wxCommandEvent &  event)
protected

Definition at line 2243 of file mathplot.cpp.

2244 {
2245  ZoomOut();
2246 }
void ZoomOut(const wxPoint &centerPoint=wxDefaultPosition)
Zoom out current view and refresh display.
Definition: mathplot.cpp:2127

References ZoomOut().

◆ p2x()

double mpWindow::p2x ( wxCoord  pixelCoordX)
inline

Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.

See also
p2y,x2p,y2p

Definition at line 1192 of file mathplot.h.

1192 { return m_posX + pixelCoordX / m_scaleX; }
double m_posX
Definition: mathplot.h:1514
double m_scaleX
Definition: mathplot.h:1512

Referenced by DoZoomInXCalc(), mpScaleXBase::getVisibleDataRange(), OnCenter(), CURSOR::Plot(), mpFX::Plot(), mpProfile::Plot(), ZoomIn(), ZoomOut(), and ZoomRect().

◆ p2y()

double mpWindow::p2y ( wxCoord  pixelCoordY)
inline

Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.

See also
p2x,x2p,y2p

Definition at line 1197 of file mathplot.h.

1197 { return m_posY - pixelCoordY / m_scaleY; }
double m_scaleY
Definition: mathplot.h:1513
double m_posY
Definition: mathplot.h:1515

Referenced by mpScaleY::getVisibleDataRange(), OnCenter(), mpFY::Plot(), ZoomIn(), ZoomOut(), and ZoomRect().

◆ SaveScreenshot()

bool mpWindow::SaveScreenshot ( const wxString &  filename,
wxBitmapType  type = wxBITMAP_TYPE_BMP,
wxSize  imageSize = wxDefaultSize,
bool  fit = false 
)

Draw the window on a wxBitmap, then save it to a file.

Parameters
filenameFile name where to save the screenshot
typeimage type to be saved: see wxImage output file types for flags
imageSizeSet a size for the output image. Default is the same as the screen size
fitDecide whether to fit the plot into the size

Definition at line 2630 of file mathplot.cpp.

2632 {
2633  int sizeX, sizeY;
2634  int bk_scrX, bk_scrY;
2635 
2636  if( imageSize == wxDefaultSize )
2637  {
2638  sizeX = m_scrX;
2639  sizeY = m_scrY;
2640  }
2641  else
2642  {
2643  sizeX = imageSize.x;
2644  sizeY = imageSize.y;
2645  bk_scrX = m_scrX;
2646  bk_scrY = m_scrY;
2647  SetScr( sizeX, sizeY );
2648  }
2649 
2650  wxBitmap screenBuffer( sizeX, sizeY );
2651  wxMemoryDC screenDC;
2652  screenDC.SelectObject( screenBuffer );
2653  screenDC.SetPen( *wxWHITE_PEN );
2654  screenDC.SetTextForeground( m_fgColour );
2655  wxBrush brush( GetBackgroundColour() );
2656  screenDC.SetBrush( brush );
2657  screenDC.DrawRectangle( 0, 0, sizeX, sizeY );
2658 
2659  if( fit )
2660  Fit( m_minX, m_maxX, m_minY, m_maxY, &sizeX, &sizeY );
2661  else
2663 
2664  // Draw all the layers:
2665  for( mpLayer* layer : m_layers )
2666  layer->Plot( screenDC, *this );
2667 
2668  if( imageSize != wxDefaultSize )
2669  {
2670  // Restore dimensions
2671  SetScr( bk_scrX, bk_scrY );
2672  Fit( m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax, &bk_scrX, &bk_scrY );
2673  UpdateAll();
2674  }
2675 
2676  // Once drawing is complete, actually save screen shot
2677  wxImage screenImage = screenBuffer.ConvertToImage();
2678  return screenImage.SaveFile( filename, type );
2679 }
double m_desiredXmax
Definition: mathplot.h:1524
double m_minY
Definition: mathplot.h:1510
wxLayerList m_layers
Definition: mathplot.h:1500
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
double m_desiredYmax
Definition: mathplot.h:1524
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
wxColour m_fgColour
Definition: mathplot.h:1505
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
Definition: mathplot.cpp:1910
double m_minX
Definition: mathplot.h:1508
double m_desiredYmin
Definition: mathplot.h:1524
void SetScr(int scrX, int scrY)
Set current view's dimensions in device context units.
Definition: mathplot.h:1187
int m_scrY
Definition: mathplot.h:1517
double m_maxX
Definition: mathplot.h:1509
int m_scrX
Definition: mathplot.h:1516
double m_maxY
Definition: mathplot.h:1511

References Fit(), m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_fgColour, m_layers, m_maxX, m_maxY, m_minX, m_minY, m_scrX, m_scrY, SetScr(), and UpdateAll().

Referenced by SIM_PLOT_FRAME::menuSaveImage().

◆ SetColourTheme()

void mpWindow::SetColourTheme ( const wxColour &  bgColour,
const wxColour &  drawColour,
const wxColour &  axesColour 
)

Set Color theme.

Provide colours to set a new colour theme.

Parameters
bgColourBackground colour
drawColourThe colour used to draw all elements in foreground, axes excluded
axesColourThe colour used to draw axes (but not their labels)

Definition at line 2748 of file mathplot.cpp.

2750 {
2751  SetBackgroundColour( bgColour );
2752  SetForegroundColour( drawColour );
2753  m_bgColour = bgColour;
2754  m_fgColour = drawColour;
2755  m_axColour = axesColour;
2756 
2757  // Cycle between layers to set colours and properties to them
2758  for( mpLayer* layer : m_layers )
2759  {
2760  if( layer->GetLayerType() == mpLAYER_AXIS )
2761  {
2762  wxPen axisPen = layer->GetPen(); // Get the old pen to modify only colour, not style or width
2763  axisPen.SetColour( axesColour );
2764  layer->SetPen( axisPen );
2765  }
2766 
2767  if( layer->GetLayerType() == mpLAYER_INFO )
2768  {
2769  wxPen infoPen = layer->GetPen(); // Get the old pen to modify only colour, not style or width
2770  infoPen.SetColour( drawColour );
2771  layer->SetPen( infoPen );
2772  }
2773  }
2774 }
wxColour m_axColour
Definition: mathplot.h:1506
wxLayerList m_layers
Definition: mathplot.h:1500
wxColour m_fgColour
Definition: mathplot.h:1505
wxColour m_bgColour
Definition: mathplot.h:1504

References m_axColour, m_bgColour, m_fgColour, m_layers, mpLAYER_AXIS, and mpLAYER_INFO.

Referenced by mpPrintout::OnPrintPage(), and SIM_PLOT_PANEL::UpdatePlotColors().

◆ SetLayerVisible() [1/2]

void mpWindow::SetLayerVisible ( const wxString &  name,
bool  viewable 
)

Sets the visibility of a layer by its name.

Parameters
nameThe layer name to set visibility
viewablethe view status to be set

Definition at line 2708 of file mathplot.cpp.

2709 {
2710  mpLayer* lx = GetLayerByName( name );
2711 
2712  if( lx )
2713  {
2714  lx->SetVisible( viewable );
2715  UpdateAll();
2716  }
2717 }
const mpLayer * GetLayerByName(const wxString &name) const
Definition: mathplot.cpp:2609
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
void SetVisible(bool show)
Sets layer visibility.
Definition: mathplot.h:302
const char * name
Definition: DXF_plotter.cpp:56

References GetLayerByName(), name, mpLayer::SetVisible(), and UpdateAll().

◆ SetLayerVisible() [2/2]

void mpWindow::SetLayerVisible ( const unsigned int  position,
bool  viewable 
)

Sets the visibility of a layer by its position in layer list.

Parameters
positionThe layer position in layer list
viewablethe view status to be set

Definition at line 2728 of file mathplot.cpp.

2729 {
2730  mpLayer* lx = GetLayer( position );
2731 
2732  if( lx )
2733  {
2734  lx->SetVisible( viewable );
2735  UpdateAll();
2736  }
2737 }
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
void SetVisible(bool show)
Sets layer visibility.
Definition: mathplot.h:302
mpLayer * GetLayer(int position) const
Definition: mathplot.cpp:2600

References GetLayer(), mpLayer::SetVisible(), and UpdateAll().

◆ SetMarginBottom()

void mpWindow::SetMarginBottom ( int  bottom)
inline

Set the bottom margin.

Parameters
bottomBottom Margin

Definition at line 1366 of file mathplot.h.

1366 { m_marginBottom = bottom; };
int m_marginBottom
Definition: mathplot.h:1526

◆ SetMarginLeft()

void mpWindow::SetMarginLeft ( int  left)
inline

Set the left margin.

Parameters
leftLeft Margin

Definition at line 1368 of file mathplot.h.

1368 { m_marginLeft = left; };
int m_marginLeft
Definition: mathplot.h:1526

References left.

◆ SetMarginRight()

void mpWindow::SetMarginRight ( int  right)
inline

Set the right margin.

Parameters
rightRight Margin

Definition at line 1364 of file mathplot.h.

1364 { m_marginRight = right; };
int m_marginRight
Definition: mathplot.h:1526

References right.

◆ SetMargins()

void mpWindow::SetMargins ( int  top,
int  right,
int  bottom,
int  left 
)

Set window margins, creating a blank area where some kinds of layers cannot draw.

This is useful for example to draw axes outside the area where the plots are drawn.

Parameters
topTop border
rightRight border
bottomBottom border
leftLeft border

Definition at line 2682 of file mathplot.cpp.

2683 {
2684  m_marginTop = top;
2685  m_marginRight = right;
2686  m_marginBottom = bottom;
2687  m_marginLeft = left;
2688 }
int m_marginRight
Definition: mathplot.h:1526
int m_marginLeft
Definition: mathplot.h:1526
int m_marginTop
Definition: mathplot.h:1526
int m_marginBottom
Definition: mathplot.h:1526

References left, m_marginBottom, m_marginLeft, m_marginRight, m_marginTop, and right.

Referenced by SIM_PLOT_PANEL::SIM_PLOT_PANEL().

◆ SetMarginTop()

void mpWindow::SetMarginTop ( int  top)
inline

Set the top margin.

Parameters
topTop Margin

Definition at line 1362 of file mathplot.h.

1362 { m_marginTop = top; };
int m_marginTop
Definition: mathplot.h:1526

◆ SetMPScrollbars()

void mpWindow::SetMPScrollbars ( bool  status)

Enable/disable scrollbars.

Parameters
statusSet to true to show scrollbars

◆ SetPos()

void mpWindow::SetPos ( double  posX,
double  posY 
)
inline

Set current view's X and Y position and refresh display.

Parameters
posXNew position that corresponds to the center point of the view.
posYNew position that corresponds to the center point of the view.

Definition at line 1180 of file mathplot.h.

1180 { m_posX = posX; m_posY = posY; UpdateAll(); }
double m_posX
Definition: mathplot.h:1514
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
double m_posY
Definition: mathplot.h:1515

Referenced by OnCenter().

◆ SetPosX()

void mpWindow::SetPosX ( double  posX)
inline

Set current view's X position and refresh display.

Parameters
posXNew position that corresponds to the center point of the view.

Definition at line 1169 of file mathplot.h.

1169 { m_posX = posX; UpdateAll(); }
double m_posX
Definition: mathplot.h:1514
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403

Referenced by DoScrollCalc().

◆ SetPosY()

void mpWindow::SetPosY ( double  posY)
inline

Set current view's Y position and refresh display.

Parameters
posYNew position that corresponds to the center point of the view.

Definition at line 1174 of file mathplot.h.

1174 { m_posY = posY; UpdateAll(); }
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
double m_posY
Definition: mathplot.h:1515

Referenced by DoScrollCalc().

◆ SetScaleX()

void mpWindow::SetScaleX ( double  scaleX)

Set current view's X scale and refresh display.

Parameters
scaleXNew scale, must not be 0.

Definition at line 2575 of file mathplot.cpp.

2576 {
2577  if( scaleX != 0 )
2578  m_scaleX = scaleX;
2579 
2580  UpdateAll();
2581 }
double m_scaleX
Definition: mathplot.h:1512
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403

References m_scaleX, and UpdateAll().

◆ SetScaleY()

void mpWindow::SetScaleY ( double  scaleY)
inline

Set current view's Y scale and refresh display.

Parameters
scaleYNew scale, must not be 0.

Definition at line 1158 of file mathplot.h.

1159  {
1160  if( scaleY != 0 )
1161  m_scaleY = scaleY;
1162 
1163  UpdateAll();
1164  }
double m_scaleY
Definition: mathplot.h:1513
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403

◆ SetScr()

void mpWindow::SetScr ( int  scrX,
int  scrY 
)
inline

Set current view's dimensions in device context units.

Needed by plotting functions. It doesn't refresh display.

Parameters
scrXNew position that corresponds to the center point of the view.
scrYNew position that corresponds to the center point of the view.

Definition at line 1187 of file mathplot.h.

1187 { m_scrX = scrX; m_scrY = scrY; }
int m_scrY
Definition: mathplot.h:1517
int m_scrX
Definition: mathplot.h:1516

Referenced by SaveScreenshot().

◆ SetXView()

bool mpWindow::SetXView ( double  pos,
double  desiredMax,
double  desiredMin 
)
protectedvirtual

Applies new X view coordinates depending on the settings.

Returns
true if the changes were applied

Definition at line 2042 of file mathplot.cpp.

2043 {
2044  // if(!CheckXLimits(desiredMax, desiredMin))
2045  // return false;
2046 
2047  m_posX = pos;
2048  m_desiredXmax = desiredMax;
2049  m_desiredXmin = desiredMin;
2051 
2052  return true;
2053 }
double m_desiredXmax
Definition: mathplot.h:1524
double m_posX
Definition: mathplot.h:1514
void AdjustLimitedView()
Definition: mathplot.cpp:1996
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524

References AdjustLimitedView(), m_desiredXmax, m_desiredXmin, and m_posX.

Referenced by OnMouseMove(), and OnMouseWheel().

◆ SetYView()

bool mpWindow::SetYView ( double  pos,
double  desiredMax,
double  desiredMin 
)
protectedvirtual

Applies new Y view coordinates depending on the settings.

Returns
true if the changes were applied

Definition at line 2056 of file mathplot.cpp.

2057 {
2058  // if(!CheckYLimits(desiredMax, desiredMin))
2059  // return false;
2060 
2061  m_posY = pos;
2062  m_desiredYmax = desiredMax;
2063  m_desiredYmin = desiredMin;
2065 
2066  return true;
2067 }
double m_desiredYmax
Definition: mathplot.h:1524
void AdjustLimitedView()
Definition: mathplot.cpp:1996
double m_posY
Definition: mathplot.h:1515
double m_desiredYmin
Definition: mathplot.h:1524

References AdjustLimitedView(), m_desiredYmax, m_desiredYmin, and m_posY.

Referenced by OnMouseMove(), and OnMouseWheel().

◆ UpdateAll()

void mpWindow::UpdateAll ( )

Refresh display.

Definition at line 2403 of file mathplot.cpp.

2404 {
2405  if( UpdateBBox() )
2406  {
2407  if( m_enableScrollBars )
2408  {
2409  int cx, cy;
2410  GetClientSize( &cx, &cy );
2411  // Do x scroll bar
2412  {
2413  // Convert margin sizes from pixels to coordinates
2414  double leftMargin = m_marginLeft / m_scaleX;
2415  // Calculate the range in coords that we want to scroll over
2416  double maxX = (m_desiredXmax > m_maxX) ? m_desiredXmax : m_maxX;
2417  double minX = (m_desiredXmin < m_minX) ? m_desiredXmin : m_minX;
2418 
2419  if( (m_posX + leftMargin) < minX )
2420  minX = m_posX + leftMargin;
2421 
2422  // Calculate scroll bar size and thumb position
2423  int sizeX = (int) ( (maxX - minX) * m_scaleX );
2424  int thumbX = (int) ( ( (m_posX + leftMargin) - minX ) * m_scaleX );
2425  SetScrollbar( wxHORIZONTAL, thumbX, cx - (m_marginRight + m_marginLeft), sizeX );
2426  }
2427  // Do y scroll bar
2428  {
2429  // Convert margin sizes from pixels to coordinates
2430  double topMargin = m_marginTop / m_scaleY;
2431  // Calculate the range in coords that we want to scroll over
2432  double maxY = (m_desiredYmax > m_maxY) ? m_desiredYmax : m_maxY;
2433 
2434  if( (m_posY - topMargin) > maxY )
2435  maxY = m_posY - topMargin;
2436 
2437  double minY = (m_desiredYmin < m_minY) ? m_desiredYmin : m_minY;
2438  // Calculate scroll bar size and thumb position
2439  int sizeY = (int) ( (maxY - minY) * m_scaleY );
2440  int thumbY = (int) ( ( maxY - (m_posY - topMargin) ) * m_scaleY );
2441  SetScrollbar( wxVERTICAL, thumbY, cy - (m_marginTop + m_marginBottom), sizeY );
2442  }
2443  }
2444  }
2445 
2446  Refresh( false );
2447 }
int m_marginRight
Definition: mathplot.h:1526
bool m_enableScrollBars
Definition: mathplot.h:1537
int m_marginLeft
Definition: mathplot.h:1526
double m_desiredXmax
Definition: mathplot.h:1524
double m_scaleY
Definition: mathplot.h:1513
double m_posX
Definition: mathplot.h:1514
double m_minY
Definition: mathplot.h:1510
double m_scaleX
Definition: mathplot.h:1512
double m_desiredYmax
Definition: mathplot.h:1524
void Refresh()
Update the board display after modifying it by a python script (note: it is automatically called by a...
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
double m_posY
Definition: mathplot.h:1515
int m_marginTop
Definition: mathplot.h:1526
double m_minX
Definition: mathplot.h:1508
double m_desiredYmin
Definition: mathplot.h:1524
int m_marginBottom
Definition: mathplot.h:1526
virtual bool UpdateBBox()
Recalculate global layer bounding box, and save it in m_minX,...
Definition: mathplot.cpp:2392
double m_maxX
Definition: mathplot.h:1509
double m_maxY
Definition: mathplot.h:1511

References m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_enableScrollBars, m_marginBottom, m_marginLeft, m_marginRight, m_marginTop, m_maxX, m_maxY, m_minX, m_minY, m_posX, m_posY, m_scaleX, m_scaleY, Refresh(), and UpdateBBox().

Referenced by AddLayer(), SIM_PLOT_PANEL::addTrace(), DelAllLayers(), DelLayer(), Fit(), mpWindow(), OnMouseMove(), OnMouseWheel(), mpPrintout::OnPrintPage(), SIM_PLOT_FRAME::onSimFinished(), SaveScreenshot(), SIM_PLOT_PANEL::SetDottedCurrentPhase(), SetLayerVisible(), SetScaleX(), SIM_PLOT_PANEL::ShowGrid(), SIM_PLOT_PANEL::ShowLegend(), SIM_PLOT_PANEL::SIM_PLOT_PANEL(), SIM_PLOT_PANEL::UpdatePlotColors(), ZoomIn(), ZoomInX(), and ZoomOut().

◆ UpdateBBox()

bool mpWindow::UpdateBBox ( )
protectedvirtual

Recalculate global layer bounding box, and save it in m_minX,...

Returns
true if there is any valid BBox information.

Definition at line 2392 of file mathplot.cpp.

2393 {
2394  m_minX = 0.0;
2395  m_maxX = 1.0;
2396  m_minY = 0.0;
2397  m_maxY = 1.0;
2398 
2399  return true;
2400 }
double m_minY
Definition: mathplot.h:1510
double m_minX
Definition: mathplot.h:1508
double m_maxX
Definition: mathplot.h:1509
double m_maxY
Definition: mathplot.h:1511

References m_maxX, m_maxY, m_minX, and m_minY.

Referenced by Fit(), and UpdateAll().

◆ x2p()

wxCoord mpWindow::x2p ( double  x)
inline

Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.

See also
p2x,p2y,y2p

Definition at line 1202 of file mathplot.h.

1202 { return (wxCoord) ( (x - m_posX) * m_scaleX ); }
double m_posX
Definition: mathplot.h:1514
double m_scaleX
Definition: mathplot.h:1512

Referenced by CURSOR::Inside(), CURSOR::Plot(), mpFY::Plot(), mpFXY::Plot(), mpScaleY::Plot(), mpMovableObject::Plot(), mpBitmapLayer::Plot(), and CURSOR::UpdateReference().

◆ y2p()

wxCoord mpWindow::y2p ( double  y)
inline

Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.

See also
p2x,p2y,x2p

Definition at line 1207 of file mathplot.h.

1207 { return (wxCoord) ( (m_posY - y) * m_scaleY ); }
double m_scaleY
Definition: mathplot.h:1513
double m_posY
Definition: mathplot.h:1515

Referenced by CURSOR::Inside(), CURSOR::Plot(), mpFX::Plot(), mpFXY::Plot(), mpProfile::Plot(), mpScaleXBase::Plot(), mpMovableObject::Plot(), mpBitmapLayer::Plot(), and CURSOR::UpdateReference().

◆ ZoomIn() [1/2]

void mpWindow::ZoomIn ( const wxPoint &  centerPoint = wxDefaultPosition)

Zoom into current view and refresh display.

Parameters
centerPointThe point (pixel coordinates) that will stay in the same position on the screen after the zoom (by default, the center of the mpWindow).

Definition at line 2070 of file mathplot.cpp.

2071 {
2072  ZoomIn( centerPoint, zoomIncrementalFactor );
2073 }
void ZoomIn(const wxPoint &centerPoint=wxDefaultPosition)
Zoom into current view and refresh display.
Definition: mathplot.cpp:2070
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
Definition: mathplot.h:1351

References zoomIncrementalFactor.

Referenced by SIM_PLOT_FRAME::menuZoomIn(), OnMouseWheel(), and OnZoomIn().

◆ ZoomIn() [2/2]

void mpWindow::ZoomIn ( const wxPoint &  centerPoint,
double  zoomFactor 
)

Definition at line 2076 of file mathplot.cpp.

2077 {
2078  wxPoint c( centerPoint );
2079 
2080  if( c == wxDefaultPosition )
2081  {
2082  GetClientSize( &m_scrX, &m_scrY );
2083  c.x = (m_scrX - m_marginLeft - m_marginRight) / 2 + m_marginLeft; // c.x = m_scrX/2;
2084  c.y = (m_scrY - m_marginTop - m_marginBottom) / 2 - m_marginTop; // c.y = m_scrY/2;
2085  }
2086  else
2087  {
2088  c.x = std::max( c.x, m_marginLeft );
2089  c.x = std::min( c.x, m_scrX - m_marginRight );
2090  c.y = std::max( c.y, m_marginTop );
2091  c.y = std::min( c.y, m_scrY - m_marginBottom );
2092  }
2093 
2094  // Preserve the position of the clicked point:
2095  double prior_layer_x = p2x( c.x );
2096  double prior_layer_y = p2y( c.y );
2097 
2098  // Zoom in:
2099  const double MAX_SCALE = 1e6;
2100  double newScaleX = m_scaleX * zoomFactor;
2101  double newScaleY = m_scaleY * zoomFactor;
2102 
2103  // Baaaaad things happen when you zoom in too much..
2104  if( newScaleX <= MAX_SCALE && newScaleY <= MAX_SCALE )
2105  {
2106  m_scaleX = newScaleX;
2107  m_scaleY = newScaleY;
2108  }
2109  else
2110  {
2111  return;
2112  }
2113 
2114  // Adjust the new m_posx/y:
2115  m_posX = prior_layer_x - c.x / m_scaleX;
2116  m_posY = prior_layer_y + c.y / m_scaleY;
2117 
2119  m_desiredXmax = m_posX + (m_scrX - m_marginLeft - m_marginRight) / m_scaleX; // m_desiredXmax = m_posX + m_scrX / m_scaleX;
2121  m_desiredYmin = m_posY - (m_scrY - m_marginTop - m_marginBottom) / m_scaleY; // m_desiredYmin = m_posY - m_scrY / m_scaleY;
2123  UpdateAll();
2124 }
int m_marginRight
Definition: mathplot.h:1526
int m_marginLeft
Definition: mathplot.h:1526
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1192
double m_desiredXmax
Definition: mathplot.h:1524
double m_scaleY
Definition: mathplot.h:1513
double m_posX
Definition: mathplot.h:1514
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1197
double m_scaleX
Definition: mathplot.h:1512
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
double m_desiredYmax
Definition: mathplot.h:1524
void AdjustLimitedView()
Definition: mathplot.cpp:1996
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
#define MAX_SCALE
double m_posY
Definition: mathplot.h:1515
int m_marginTop
Definition: mathplot.h:1526
double m_desiredYmin
Definition: mathplot.h:1524
int m_marginBottom
Definition: mathplot.h:1526
int m_scrY
Definition: mathplot.h:1517
int m_scrX
Definition: mathplot.h:1516

References AdjustLimitedView(), m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_marginBottom, m_marginLeft, m_marginRight, m_marginTop, m_posX, m_posY, m_scaleX, m_scaleY, m_scrX, m_scrY, MAX_SCALE, p2x(), p2y(), and UpdateAll().

◆ ZoomInX()

void mpWindow::ZoomInX ( )

Zoom in current view along X and refresh display.

Definition at line 2171 of file mathplot.cpp.

2172 {
2174  UpdateAll();
2175 }
double m_scaleX
Definition: mathplot.h:1512
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
Definition: mathplot.h:1351

References m_scaleX, UpdateAll(), and zoomIncrementalFactor.

◆ ZoomInY()

void mpWindow::ZoomInY ( )

Zoom in current view along Y and refresh display.

◆ ZoomOut() [1/2]

void mpWindow::ZoomOut ( const wxPoint &  centerPoint = wxDefaultPosition)

Zoom out current view and refresh display.

Parameters
centerPointThe point (pixel coordinates) that will stay in the same position on the screen after the zoom (by default, the center of the mpWindow).

Definition at line 2127 of file mathplot.cpp.

2128 {
2129  ZoomOut( centerPoint, zoomIncrementalFactor );
2130 }
void ZoomOut(const wxPoint &centerPoint=wxDefaultPosition)
Zoom out current view and refresh display.
Definition: mathplot.cpp:2127
static double zoomIncrementalFactor
This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse...
Definition: mathplot.h:1351

References zoomIncrementalFactor.

Referenced by SIM_PLOT_FRAME::menuZoomOut(), OnMouseWheel(), and OnZoomOut().

◆ ZoomOut() [2/2]

void mpWindow::ZoomOut ( const wxPoint &  centerPoint,
double  zoomFactor 
)

Definition at line 2133 of file mathplot.cpp.

2134 {
2135  wxPoint c( centerPoint );
2136 
2137  if( c == wxDefaultPosition )
2138  {
2139  GetClientSize( &m_scrX, &m_scrY );
2140  c.x = (m_scrX - m_marginLeft - m_marginRight) / 2 + m_marginLeft; // c.x = m_scrX/2;
2141  c.y = (m_scrY - m_marginTop - m_marginBottom) / 2 - m_marginTop; // c.y = m_scrY/2;
2142  }
2143 
2144  // Preserve the position of the clicked point:
2145  double prior_layer_x = p2x( c.x );
2146  double prior_layer_y = p2y( c.y );
2147 
2148  // Zoom out:
2149  m_scaleX = m_scaleX / zoomFactor;
2150  m_scaleY = m_scaleY / zoomFactor;
2151 
2152  // Adjust the new m_posx/y:
2153  m_posX = prior_layer_x - c.x / m_scaleX;
2154  m_posY = prior_layer_y + c.y / m_scaleY;
2155 
2157  m_desiredXmax = m_posX + (m_scrX - m_marginLeft - m_marginRight) / m_scaleX; // m_desiredXmax = m_posX + m_scrX / m_scaleX;
2159  m_desiredYmin = m_posY - (m_scrY - m_marginTop - m_marginBottom) / m_scaleY; // m_desiredYmin = m_posY - m_scrY / m_scaleY;
2160 
2163  {
2164  Fit();
2165  }
2166 
2167  UpdateAll();
2168 }
int m_marginRight
Definition: mathplot.h:1526
int m_marginLeft
Definition: mathplot.h:1526
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1192
double m_desiredXmax
Definition: mathplot.h:1524
double m_scaleY
Definition: mathplot.h:1513
double m_posX
Definition: mathplot.h:1514
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1197
double m_scaleX
Definition: mathplot.h:1512
void UpdateAll()
Refresh display.
Definition: mathplot.cpp:2403
double m_desiredYmax
Definition: mathplot.h:1524
double m_desiredXmin
These are updated in Fit() only, and may be different from the real borders (layer coordinates) only ...
Definition: mathplot.h:1524
bool CheckYLimits(double &desiredMax, double &desiredMin) const
Definition: mathplot.h:1475
double m_posY
Definition: mathplot.h:1515
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
Definition: mathplot.cpp:1910
int m_marginTop
Definition: mathplot.h:1526
double m_desiredYmin
Definition: mathplot.h:1524
int m_marginBottom
Definition: mathplot.h:1526
int m_scrY
Definition: mathplot.h:1517
bool CheckXLimits(double &desiredMax, double &desiredMin) const
Definition: mathplot.h:1468
int m_scrX
Definition: mathplot.h:1516

References CheckXLimits(), CheckYLimits(), Fit(), m_desiredXmax, m_desiredXmin, m_desiredYmax, m_desiredYmin, m_marginBottom, m_marginLeft, m_marginRight, m_marginTop, m_posX, m_posY, m_scaleX, m_scaleY, m_scrX, m_scrY, p2x(), p2y(), and UpdateAll().

◆ ZoomOutX()

void mpWindow::ZoomOutX ( )

Zoom out current view along X and refresh display.

◆ ZoomOutY()

void mpWindow::ZoomOutY ( )

Zoom out current view along Y and refresh display.

◆ ZoomRect()

void mpWindow::ZoomRect ( wxPoint  p0,
wxPoint  p1 
)

Zoom view fitting given coordinates to the window (p0 and p1 do not need to be in any specific order)

Definition at line 2178 of file mathplot.cpp.

2179 {
2180  // Compute the 2 corners in graph coordinates:
2181  double p0x = p2x( p0.x );
2182  double p0y = p2y( p0.y );
2183  double p1x = p2x( p1.x );
2184  double p1y = p2y( p1.y );
2185 
2186  // Order them:
2187  double zoom_x_min = p0x<p1x ? p0x : p1x;
2188  double zoom_x_max = p0x>p1x ? p0x : p1x;
2189  double zoom_y_min = p0y<p1y ? p0y : p1y;
2190  double zoom_y_max = p0y>p1y ? p0y : p1y;
2191 
2192  Fit( zoom_x_min, zoom_x_max, zoom_y_min, zoom_y_max );
2194 }
double p2x(wxCoord pixelCoordX)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1192
double p2y(wxCoord pixelCoordY)
Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates,...
Definition: mathplot.h:1197
void AdjustLimitedView()
Definition: mathplot.cpp:1996
void Fit() override
Set view to fit global bounding box of all plot layers and refresh display.
Definition: mathplot.cpp:1910

References AdjustLimitedView(), Fit(), p2x(), and p2y().

Referenced by OnMouseLeftRelease().

Member Data Documentation

◆ m_axColour

wxColour mpWindow::m_axColour
protected

Definition at line 1506 of file mathplot.h.

Referenced by SetColourTheme().

◆ m_bgColour

wxColour mpWindow::m_bgColour
protected

Definition at line 1504 of file mathplot.h.

Referenced by mpWindow(), and SetColourTheme().

◆ m_buff_bmp

wxBitmap* mpWindow::m_buff_bmp
protected

Definition at line 1530 of file mathplot.h.

Referenced by mpWindow(), OnPaint(), and ~mpWindow().

◆ m_buff_dc

wxMemoryDC mpWindow::m_buff_dc
protected

Definition at line 1529 of file mathplot.h.

Referenced by OnPaint().

◆ m_clickedX

int mpWindow::m_clickedX
protected

Definition at line 1518 of file mathplot.h.

Referenced by OnCenter(), and OnShowPopupMenu().

◆ m_clickedY

int mpWindow::m_clickedY
protected

Definition at line 1519 of file mathplot.h.

Referenced by OnCenter(), and OnShowPopupMenu().

◆ m_desiredXmax

double mpWindow::m_desiredXmax
protected

◆ m_desiredXmin

double mpWindow::m_desiredXmin
protected

These are updated in Fit() only, and may be different from the real borders (layer coordinates) only if lock aspect ratio is true.

Definition at line 1524 of file mathplot.h.

Referenced by AdjustLimitedView(), DoScrollCalc(), DoZoomInXCalc(), Fit(), LockAspect(), mpWindow(), OnMouseMove(), OnMouseWheel(), OnSize(), SaveScreenshot(), SetXView(), UpdateAll(), ZoomIn(), and ZoomOut().

◆ m_desiredYmax

double mpWindow::m_desiredYmax
protected

◆ m_desiredYmin

double mpWindow::m_desiredYmin
protected

◆ m_enableDoubleBuffer

bool mpWindow::m_enableDoubleBuffer
protected

Definition at line 1531 of file mathplot.h.

Referenced by mpWindow(), and OnPaint().

◆ m_enableLimitedView

bool mpWindow::m_enableLimitedView
protected

Definition at line 1534 of file mathplot.h.

Referenced by AdjustLimitedView(), and mpWindow().

◆ m_enableMouseNavigation

bool mpWindow::m_enableMouseNavigation
protected

Definition at line 1532 of file mathplot.h.

Referenced by mpWindow(), OnMouseMove(), and OnMouseWheel().

◆ m_enableMouseWheelPan

bool mpWindow::m_enableMouseWheelPan
protected

Definition at line 1533 of file mathplot.h.

Referenced by OnMouseWheel().

◆ m_enableScrollBars

bool mpWindow::m_enableScrollBars
protected

Definition at line 1537 of file mathplot.h.

Referenced by mpWindow(), OnPaint(), and UpdateAll().

◆ m_fgColour

wxColour mpWindow::m_fgColour
protected

Definition at line 1505 of file mathplot.h.

Referenced by mpWindow(), OnMouseMove(), OnPaint(), SaveScreenshot(), and SetColourTheme().

◆ m_last_lx

int mpWindow::m_last_lx
protected

Definition at line 1528 of file mathplot.h.

Referenced by mpWindow(), and OnPaint().

◆ m_last_ly

int mpWindow::m_last_ly
protected

Definition at line 1528 of file mathplot.h.

Referenced by mpWindow(), and OnPaint().

◆ m_layers

◆ m_lockaspect

bool mpWindow::m_lockaspect
protected

Definition at line 1502 of file mathplot.h.

Referenced by Fit(), LockAspect(), mpWindow(), and OnLockAspect().

◆ m_marginBottom

int mpWindow::m_marginBottom
protected

◆ m_marginLeft

int mpWindow::m_marginLeft
protected

◆ m_marginRight

int mpWindow::m_marginRight
protected

◆ m_marginTop

int mpWindow::m_marginTop
protected

◆ m_maxX

double mpWindow::m_maxX
protected

◆ m_maxY

double mpWindow::m_maxY
protected

◆ m_minX

double mpWindow::m_minX
protected

◆ m_minY

double mpWindow::m_minY
protected

◆ m_mouseLClick

wxPoint mpWindow::m_mouseLClick
protected

Definition at line 1536 of file mathplot.h.

Referenced by OnMouseLeftDown(), OnMouseLeftRelease(), and OnMouseMove().

◆ m_mouseMClick

wxPoint mpWindow::m_mouseMClick
protected

Definition at line 1535 of file mathplot.h.

Referenced by OnMouseMiddleDown(), OnMouseMove(), and OnZoomIn().

◆ m_movingInfoLayer

mpInfoLayer* mpWindow::m_movingInfoLayer
protected

Definition at line 1539 of file mathplot.h.

Referenced by mpWindow(), OnMouseLeftDown(), OnMouseLeftRelease(), and OnMouseMove().

◆ m_popmenu

wxMenu mpWindow::m_popmenu
protected

Definition at line 1501 of file mathplot.h.

Referenced by LockAspect(), mpWindow(), and OnShowPopupMenu().

◆ m_posX

double mpWindow::m_posX
protected

◆ m_posY

double mpWindow::m_posY
protected

◆ m_scaleX

double mpWindow::m_scaleX
protected

◆ m_scaleY

double mpWindow::m_scaleY
protected

◆ m_scroll

wxPoint mpWindow::m_scroll
protected

Definition at line 1538 of file mathplot.h.

◆ m_scrX

int mpWindow::m_scrX
protected

Definition at line 1516 of file mathplot.h.

Referenced by DoZoomInXCalc(), Fit(), mpWindow(), OnCenter(), OnPaint(), SaveScreenshot(), ZoomIn(), and ZoomOut().

◆ m_scrY

int mpWindow::m_scrY
protected

Definition at line 1517 of file mathplot.h.

Referenced by Fit(), mpWindow(), OnCenter(), OnPaint(), SaveScreenshot(), ZoomIn(), and ZoomOut().

◆ m_zooming

bool mpWindow::m_zooming
protected

Definition at line 1540 of file mathplot.h.

Referenced by mpWindow(), OnMouseLeftDown(), OnMouseLeftRelease(), OnMouseMove(), and OnPaint().

◆ m_zoomRect

wxRect mpWindow::m_zoomRect
protected

Definition at line 1541 of file mathplot.h.

Referenced by OnMouseMove(), and OnPaint().

◆ zoomIncrementalFactor

double mpWindow::zoomIncrementalFactor = 1.1
static

This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse wheel.

It must be a number above unity. This number is used for zoom in, and its inverse for zoom out. Set to 1.5 by default.

Definition at line 1351 of file mathplot.h.

Referenced by DoZoomInXCalc(), ZoomIn(), ZoomInX(), and ZoomOut().


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