You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1485 lines
57 KiB

Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
Horizontal/vertical zoom for Simulator plots ADDED: Horizontal/vertical zoom for simulator plots, via mouse wheel, toolbar buttons, menu commands, and hotkeys. ADDED: Simulator preferences panel, populated with mouse wheel and trackpad settings that control pan and zoom of simulator plots. ADDED: Zoom In/Out Horizontally/Vertically commands that can be bound to hotkeys. CHANGED: Simulator plot scroll wheel gestures are no longer hard-coded and can now be configured via the new Simulator preferences panel. Fixes https://gitlab.com/kicad/code/kicad/-/issues/16597 Other unreported bugs that were fixed: - Fixed wierd, jumpy simulator plot view limiting behavior. - Fixed Zoom In Center and Zoom Out Center commands not preserving the simulator plot center point. - Fixed simulator plot nudging when exported as PNGs. - Fixed rectangular selection zoom being able to exceed simulator plot view limits. Notes: - Provided new SIM_PREFERENCES struct to be used for future simulator preferences set via the simulator preferences dialog. - Bundled pre-existing EESCHEMA_SETTINGS::SIMULATOR settings into EESCHEMA_SETTINGS::SIMULATOR::VIEW. - Replaced mpWindow::EnableMouseWheelPan with more general SetMouseWheelActions. - Refactored and tidied up wxMathPlot's mpWindow code involved with fitting, zooming, and panning. - Consolidated long lists of duplicated member variable initializers to a new mpWindow private delegated constructor. - Provided provisional Zoom In/Out Horizontally/Vertically toolbar icons that need improvement by a graphics designer. - Provided gitignore entries for the Qt Creator IDE
2 years ago
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: mathplot.cpp
  3. // Purpose: Framework for plotting in wxWindows
  4. // Original Author: David Schalig
  5. // Maintainer: Davide Rondini
  6. // Contributors: Jose Luis Blanco, Val Greene, Maciej Suminski, Tomasz Wlostowski
  7. // Created: 21/07/2003
  8. // Last edit: 05/08/2016
  9. // Copyright: (c) David Schalig, Davide Rondini
  10. // Copyright (c) 2021-2024 KiCad Developers, see AUTHORS.txt for contributors.
  11. // Licence: wxWindows licence
  12. /////////////////////////////////////////////////////////////////////////////
  13. #ifndef _MP_MATHPLOT_H_
  14. #define _MP_MATHPLOT_H_
  15. /**
  16. * wxMathPlot is a framework for mathematical graph plotting in wxWindows.
  17. *
  18. * The framework is designed for convenience and ease of use.
  19. *
  20. * @section screenshots Screenshots
  21. * <a href="http://wxmathplot.sourceforge.net/screenshot.shtml">Go to the screenshots page.</a>
  22. *
  23. * @section overview Overview
  24. * The heart of wxMathPlot is mpWindow, which is a 2D canvas for plot layers.
  25. * mpWindow can be embedded as subwindow in a wxPane, a wxFrame, or any other wxWindow.
  26. * mpWindow provides a zoomable and moveable view of the layers. The current view can
  27. * be controlled with the mouse, the scrollbars, and a context menu.
  28. *
  29. * Plot layers are implementations of the abstract base class mpLayer. Those can
  30. * be function plots, scale rulers, or any other vector data visualisation.
  31. * wxMathPlot provides two mpLayer implementations for plotting horizontal and vertical rulers: mpScaleX and mpScaleY.
  32. * For convenient function plotting a series of classes derived from mpLayer are provided,
  33. * like mpFX, mpProfile, mpLegend and so on.
  34. * These base classes already come with plot code, user's own functions can be implemented by overriding just one member for retrieving a function value.
  35. *
  36. * mpWindow has built-in support for mouse-based pan and zoom through intuitive combinations of buttons and the mouse wheel. It also incorporates an optional double buffering mechanism to avoid flicker. Plots can be easily sent to printer evices or exported in bitmap formats like PNG, BMP or JPEG.
  37. *
  38. * @section coding Coding conventions
  39. * wxMathPlot sticks to wxWindow's coding conventions.
  40. * All entities defined by wxMathPlot have the prefix <i>mp</i>.
  41. *
  42. * @section author Author and license
  43. * wxMathPlot is published under the terms of the wxWindow license.<br>
  44. * The original author is David Schalig <mrhill@users.sourceforge.net>.<br>
  45. * From June 2007 the project is maintained by Davide Rondini <cdron77@users.sourceforge.net>.<br>
  46. * Authors can be contacted via the wxMathPlot's homepage at
  47. * https://sourceforge.net/projects/wxmathplot<br>
  48. * Contributors:<br>
  49. * Jose Luis Blanco, Val Greene.<br>
  50. */
  51. // this definition uses windows dll to export function.
  52. // WXDLLIMPEXP_MATHPLOT definition definition changed to WXDLLIMPEXP_MATHPLOT
  53. // mathplot_EXPORTS will be defined by cmake
  54. #ifdef mathplot_EXPORTS
  55. #define WXDLLIMPEXP_MATHPLOT WXEXPORT
  56. #define WXDLLIMPEXP_DATA_MATHPLOT( type ) WXEXPORT type
  57. #else // not making DLL
  58. #define WXDLLIMPEXP_MATHPLOT
  59. #define WXDLLIMPEXP_DATA_MATHPLOT( type ) type
  60. #endif
  61. #include <wx/defs.h>
  62. #include <wx/menu.h>
  63. #include <wx/scrolwin.h>
  64. #include <wx/event.h>
  65. #include <wx/dynarray.h>
  66. #include <wx/pen.h>
  67. #include <wx/dcmemory.h>
  68. #include <wx/string.h>
  69. #include <wx/print.h>
  70. #include <wx/image.h>
  71. #include <vector>
  72. #include <deque>
  73. #include <stack>
  74. #include <array>
  75. #include <algorithm>
  76. // For memory leak debug
  77. #ifdef _WINDOWS
  78. #ifdef _DEBUG
  79. #include <crtdbg.h>
  80. #define DEBUG_NEW new (_NORMAL_BLOCK, __FILE__, __LINE__)
  81. #else
  82. #define DEBUG_NEW new
  83. #endif // _DEBUG
  84. #endif // _WINDOWS
  85. // Separation for axes when set close to border
  86. #define X_BORDER_SEPARATION 40
  87. #define Y_BORDER_SEPARATION 60
  88. // -----------------------------------------------------------------------------
  89. // classes
  90. // -----------------------------------------------------------------------------
  91. class WXDLLIMPEXP_MATHPLOT mpLayer;
  92. class WXDLLIMPEXP_MATHPLOT mpFX;
  93. class WXDLLIMPEXP_MATHPLOT mpFY;
  94. class WXDLLIMPEXP_MATHPLOT mpFXY;
  95. class WXDLLIMPEXP_MATHPLOT mpFXYVector;
  96. class WXDLLIMPEXP_MATHPLOT mpScaleX;
  97. class WXDLLIMPEXP_MATHPLOT mpScaleY;
  98. class WXDLLIMPEXP_MATHPLOT mpWindow;
  99. class WXDLLIMPEXP_MATHPLOT mpPrintout;
  100. /** Command IDs used by mpWindow */
  101. enum
  102. {
  103. mpID_FIT = 2000, // !< Fit view to match bounding box of all layers
  104. mpID_ZOOM_UNDO,
  105. mpID_ZOOM_REDO,
  106. mpID_ZOOM_IN, // !< Zoom into view at clickposition / window center
  107. mpID_ZOOM_OUT, // !< Zoom out
  108. mpID_CENTER, // !< Center view on click position
  109. };
  110. // -----------------------------------------------------------------------------
  111. // mpLayer
  112. // -----------------------------------------------------------------------------
  113. typedef enum __mp_Layer_Type
  114. {
  115. mpLAYER_UNDEF, // !< Layer type undefined
  116. mpLAYER_AXIS, // !< Axis type layer
  117. mpLAYER_PLOT, // !< Plot type layer
  118. mpLAYER_INFO, // !< Info box type layer
  119. mpLAYER_BITMAP // !< Bitmap type layer
  120. } mpLayerType;
  121. /** Plot layer, abstract base class.
  122. * Any number of mpLayer implementations can be attached to mpWindow.
  123. * Examples for mpLayer implementations are function graphs, or scale rulers.
  124. *
  125. * For convenience mpLayer defines a name, a font (wxFont), a pen (wxPen),
  126. * and a continuity property (bool) as class members.
  127. * The default values at constructor are the default font, a black pen, and
  128. * continuity set to false (draw separate points).
  129. * These may or may not be used by implementations.
  130. */
  131. class mpScaleBase;
  132. class WXDLLIMPEXP_MATHPLOT mpLayer : public wxObject
  133. {
  134. public:
  135. mpLayer();
  136. virtual ~mpLayer() {};
  137. /** Check whether this layer has a bounding box.
  138. * The default implementation returns \a true. Override and return
  139. * false if your mpLayer implementation should be ignored by the calculation
  140. * of the global bounding box for all layers in a mpWindow.
  141. * @retval true Has bounding box
  142. * @retval false Has not bounding box
  143. */
  144. virtual bool HasBBox() const { return true; }
  145. /** Check whether the layer is an info box.
  146. * The default implementation returns \a false. It is overridden to \a true for mpInfoLayer
  147. * class and its derivative. It is necessary to define mouse actions behaviour over
  148. * info boxes.
  149. * @return whether the layer is an info boxes
  150. * @sa mpInfoLayer::IsInfo
  151. */
  152. virtual bool IsInfo() const { return false; };
  153. /** Get inclusive left border of bounding box.
  154. * @return Value
  155. */
  156. virtual double GetMinX() const { return -1.0; }
  157. /** Get inclusive right border of bounding box.
  158. * @return Value
  159. */
  160. virtual double GetMaxX() const { return 1.0; }
  161. /** Get inclusive bottom border of bounding box.
  162. * @return Value
  163. */
  164. virtual double GetMinY() const { return -1.0; }
  165. /** Get inclusive top border of bounding box.
  166. * @return Value
  167. */
  168. virtual double GetMaxY() const { return 1.0; }
  169. /** Plot given view of layer to the given device context.
  170. * An implementation of this function has to transform layer coordinates to
  171. * wxDC coordinates based on the view parameters retrievable from the mpWindow
  172. * passed in \a w.
  173. * Note that the public methods of mpWindow: x2p,y2p and p2x,p2y are already provided
  174. * which transform layer coordinates to DC pixel coordinates, and <b>user code should rely
  175. * on them</b> for portability and future changes to be applied transparently, instead of
  176. * implementing the following formulas manually.
  177. *
  178. * The passed device context \a dc has its coordinate origin set to the top-left corner
  179. * of the visible area (the default). The coordinate orientation is as shown in the
  180. * following picture:
  181. * <pre>
  182. * (wxDC origin 0,0)
  183. * x-------------> ascending X ----------------+
  184. * | |
  185. * | |
  186. * | V ascending Y |
  187. * | |
  188. * | |
  189. * | |
  190. * |+------------------------------------------+ <-- right-bottom corner of the mpWindow visible area.
  191. * </pre>
  192. * Note that Y ascends in downward direction, whereas the usual vertical orientation
  193. * for mathematical plots is vice versa. Thus Y-orientation will be swapped usually,
  194. * when transforming between wxDC and mpLayer coordinates. This change of coordinates
  195. * is taken into account in the methods p2x,p2y,x2p,y2p.
  196. *
  197. * <b> Rules for transformation between mpLayer and wxDC coordinates </b>
  198. * @code
  199. * dc_X = (layer_X - mpWindow::GetPosX()) * mpWindow::GetScaleX()
  200. * dc_Y = (mpWindow::GetPosY() - layer_Y) * mpWindow::GetScaleY() // swapping Y-orientation
  201. *
  202. * layer_X = (dc_X / mpWindow::GetScaleX()) + mpWindow::GetPosX() // scale guaranteed to be not 0
  203. * layer_Y = mpWindow::GetPosY() - (dc_Y / mpWindow::GetScaleY()) // swapping Y-orientation
  204. * @endcode
  205. *
  206. * @param dc Device context to plot to.
  207. * @param w View to plot. The visible area can be retrieved from this object.
  208. * @sa mpWindow::p2x,mpWindow::p2y,mpWindow::x2p,mpWindow::y2p
  209. */
  210. virtual void Plot( wxDC& dc, mpWindow& w ) = 0;
  211. /** Get layer name.
  212. * @return Name
  213. */
  214. const wxString& GetName() const { return m_name; }
  215. const wxString& GetDisplayName() const
  216. {
  217. return m_displayName.IsEmpty() ? m_name : m_displayName;
  218. }
  219. /** Get font set for this layer.
  220. * @return Font
  221. */
  222. const wxFont& GetFont() const { return m_font; }
  223. /** Get pen set for this layer.
  224. * @return Pen
  225. */
  226. const wxPen& GetPen() const { return m_pen; }
  227. /** Set the 'continuity' property of the layer (true:draws a continuous line, false:draws separate points).
  228. * @sa GetContinuity
  229. */
  230. void SetContinuity( bool continuity ) { m_continuous = continuity; }
  231. /** Gets the 'continuity' property of the layer.
  232. * @sa SetContinuity
  233. */
  234. bool GetContinuity() const { return m_continuous; }
  235. /** Shows or hides the text label with the name of the layer (default is visible).
  236. */
  237. void ShowName( bool show ) { m_showName = show; };
  238. /** Set layer name
  239. * @param name Name, will be copied to internal class member
  240. */
  241. virtual void SetName( const wxString& name ) { m_name = name; }
  242. /** Set layer font
  243. * @param font Font, will be copied to internal class member
  244. */
  245. void SetFont( const wxFont& font ) { m_font = font; }
  246. /** Set layer pen
  247. * @param pen Pen, will be copied to internal class member
  248. */
  249. void SetPen( const wxPen& pen ) { m_pen = pen; }
  250. /** Get layer type: a Layer can be of different types: plot lines, axis, info boxes, etc, this method returns the right value.
  251. * @return An integer indicating layer type */
  252. mpLayerType GetLayerType() const { return m_type; };
  253. /** Checks whether the layer is visible or not.
  254. * @return \a true if visible */
  255. bool IsVisible() const { return m_visible; };
  256. /** Sets layer visibility.
  257. * @param show visibility bool. */
  258. void SetVisible( bool show ) { m_visible = show; };
  259. /** Get brush set for this layer.
  260. * @return brush. */
  261. const wxBrush& GetBrush() const { return m_brush; };
  262. /** Set layer brush
  263. * @param brush brush, will be copied to internal class member */
  264. void SetBrush( const wxBrush& brush ) { m_brush = brush; };
  265. protected:
  266. wxFont m_font; // !< Layer's font
  267. wxPen m_pen; // !< Layer's pen
  268. wxBrush m_brush; // !< Layer's brush
  269. wxString m_name; // !< Layer's name
  270. wxString m_displayName;
  271. bool m_continuous; // !< Specify if the layer will be plotted as a continuous line or a set of points.
  272. bool m_showName; // !< States whether the name of the layer must be shown (default is true).
  273. mpLayerType m_type; // !< Define layer type, which is assigned by constructor
  274. bool m_visible; // !< Toggles layer visibility
  275. DECLARE_DYNAMIC_CLASS( mpLayer )
  276. };
  277. // -----------------------------------------------------------------------------
  278. // mpInfoLayer
  279. // -----------------------------------------------------------------------------
  280. /** @class mpInfoLayer
  281. * @brief Base class to create small rectangular info boxes
  282. * mpInfoLayer is the base class to create a small rectangular info box in transparent overlay over plot layers. It is used to implement objects like legends.
  283. */
  284. class WXDLLIMPEXP_MATHPLOT mpInfoLayer : public mpLayer
  285. {
  286. public:
  287. /** Default constructor. */
  288. mpInfoLayer();
  289. /** Complete constructor.
  290. * @param rect Sets the initial size rectangle of the layer.
  291. * @param brush pointer to a fill brush. Default is transparent */
  292. mpInfoLayer( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
  293. /** Destructor */
  294. virtual ~mpInfoLayer();
  295. /** mpInfoLayer has not bounding box. @sa mpLayer::HasBBox
  296. * @return always \a false */
  297. virtual bool HasBBox() const override { return false; }
  298. /** Plot method. Can be overridden by derived classes.
  299. * @param dc the device content where to plot
  300. * @param w the window to plot
  301. * @sa mpLayer::Plot */
  302. virtual void Plot( wxDC& dc, mpWindow& w ) override;
  303. /** Specifies that this is an Info box layer.
  304. * @return always \a true
  305. * @sa mpLayer::IsInfo */
  306. virtual bool IsInfo() const override { return true; }
  307. /** Checks whether a point is inside the info box rectangle.
  308. * @param point The point to be checked
  309. * @return \a true if the point is inside the bounding box */
  310. virtual bool Inside( const wxPoint& point ) const;
  311. /** Moves the layer rectangle of given pixel deltas.
  312. * @param delta The wxPoint container for delta coordinates along x and y. Units are in pixels. */
  313. virtual void Move( wxPoint delta );
  314. /** Updates the rectangle reference point. Used by internal methods of mpWindow to correctly move mpInfoLayers. */
  315. virtual void UpdateReference();
  316. /** Returns the position of the upper left corner of the box (in pixels)
  317. * @return The rectangle position */
  318. wxPoint GetPosition() const;
  319. /** Returns the size of the box (in pixels)
  320. * @return The rectangle size */
  321. wxSize GetSize() const;
  322. protected:
  323. wxRect m_dim; // !< The bounding rectangle of the box. It may be resized dynamically
  324. // by the Plot method.
  325. wxPoint m_reference; // !< Holds the reference point for movements
  326. wxBrush m_brush; // !< The brush to be used for the background
  327. int m_winX; // !< Holds the mpWindow size. Used to rescale position when window is
  328. int m_winY; // resized.
  329. DECLARE_DYNAMIC_CLASS( mpInfoLayer )
  330. };
  331. /** @class mpInfoLegend
  332. * @brief Implements the legend to be added to the plot
  333. * This layer allows you to add a legend to describe the plots in the window. The legend uses the layer name as a label, and displays only layers of type mpLAYER_PLOT. */
  334. class WXDLLIMPEXP_MATHPLOT mpInfoLegend : public mpInfoLayer
  335. {
  336. public:
  337. /** Default constructor */
  338. mpInfoLegend();
  339. /** Complete constructor, setting initial rectangle and background brush.
  340. * @param rect The initial bounding rectangle.
  341. * @param brush The wxBrush to be used for box background: default is transparent
  342. * @sa mpInfoLayer::mpInfoLayer */
  343. mpInfoLegend( wxRect rect, const wxBrush* brush = wxTRANSPARENT_BRUSH );
  344. /** Default destructor */
  345. ~mpInfoLegend();
  346. /** Plot method.
  347. * @param dc the device content where to plot
  348. * @param w the window to plot
  349. */
  350. virtual void Plot( wxDC& dc, mpWindow& w ) override;
  351. protected:
  352. };
  353. // -----------------------------------------------------------------------------
  354. // mpLayer implementations - functions
  355. // -----------------------------------------------------------------------------
  356. /** @name Label alignment constants
  357. * @{*/
  358. /** @internal */
  359. #define mpALIGNMASK 0x03
  360. /** Aligns label to the right. For use with mpFX. */
  361. #define mpALIGN_RIGHT 0x00
  362. /** Aligns label to the center. For use with mpFX and mpFY. */
  363. #define mpALIGN_CENTER 0x01
  364. /** Aligns label to the left. For use with mpFX. */
  365. #define mpALIGN_LEFT 0x02
  366. /** Aligns label to the top. For use with mpFY. */
  367. #define mpALIGN_TOP mpALIGN_RIGHT
  368. /** Aligns label to the bottom. For use with mpFY. */
  369. #define mpALIGN_BOTTOM mpALIGN_LEFT
  370. /** Aligns X axis to bottom border. For mpScaleX */
  371. #define mpALIGN_BORDER_BOTTOM 0x04
  372. /** Aligns X axis to top border. For mpScaleX */
  373. #define mpALIGN_BORDER_TOP 0x05
  374. /** Aligns label to the right of mpALIGN_RIGHT */
  375. #define mpALIGN_FAR_RIGHT 0x06
  376. /** Set label for X axis in normal mode */
  377. #define mpX_NORMAL 0x00
  378. /** Set label for X axis in time mode: the value is represented as minutes:seconds.milliseconds if time is less than 2 minutes, hours:minutes:seconds otherwise. */
  379. #define mpX_TIME 0x01
  380. /** Set label for X axis in hours mode: the value is always represented as hours:minutes:seconds. */
  381. #define mpX_HOURS 0x02
  382. /** Set label for X axis in date mode: the value is always represented as yyyy-mm-dd. */
  383. #define mpX_DATE 0x03
  384. /** Set label for X axis in datetime mode: the value is always represented as yyyy-mm-ddThh:mm:ss. */
  385. #define mpX_DATETIME 0x04
  386. /** Aligns Y axis to left border. For mpScaleY */
  387. #define mpALIGN_BORDER_LEFT mpALIGN_BORDER_BOTTOM
  388. /** Aligns Y axis to right border. For mpScaleY */
  389. #define mpALIGN_BORDER_RIGHT mpALIGN_BORDER_TOP
  390. /** Aligns label to north-east. For use with mpFXY. */
  391. #define mpALIGN_NE 0x00
  392. /** Aligns label to north-west. For use with mpFXY. */
  393. #define mpALIGN_NW 0x01
  394. /** Aligns label to south-west. For use with mpFXY. */
  395. #define mpALIGN_SW 0x02
  396. /** Aligns label to south-east. For use with mpFXY. */
  397. #define mpALIGN_SE 0x03
  398. /*@}*/
  399. /** @name mpLayer implementations - functions
  400. * @{*/
  401. /** Abstract base class providing plot and labeling functionality for functions F:X->Y.
  402. * Override mpFX::GetY to implement a function.
  403. * Optionally implement a constructor and pass a name (label) and a label alignment
  404. * to the constructor mpFX::mpFX. If the layer name is empty, no label will be plotted.
  405. */
  406. class WXDLLIMPEXP_MATHPLOT mpFX : public mpLayer
  407. {
  408. public:
  409. /** @param name Label
  410. * @param flags Label alignment, pass one of #mpALIGN_RIGHT, #mpALIGN_CENTER, #mpALIGN_LEFT.
  411. */
  412. mpFX( const wxString& name = wxEmptyString, int flags = mpALIGN_RIGHT );
  413. /** Get function value for argument.
  414. * Override this function in your implementation.
  415. * @param x Argument
  416. * @return Function value
  417. */
  418. virtual double GetY( double x ) const = 0;
  419. /** Layer plot handler.
  420. * This implementation will plot the function in the visible area and put a label according
  421. * to the alignment specified.
  422. */
  423. virtual void Plot( wxDC& dc, mpWindow& w ) override;
  424. protected:
  425. int m_flags; // !< Holds label alignment
  426. DECLARE_DYNAMIC_CLASS( mpFX )
  427. };
  428. /** Abstract base class providing plot and labeling functionality for functions F:Y->X.
  429. * Override mpFY::GetX to implement a function.
  430. * Optionally implement a constructor and pass a name (label) and a label alignment to the
  431. * constructor mpFY::mpFY. If the layer name is empty, no label will be plotted.
  432. */
  433. class WXDLLIMPEXP_MATHPLOT mpFY : public mpLayer
  434. {
  435. public:
  436. /** @param name Label
  437. * @param flags Label alignment, pass one of #mpALIGN_BOTTOM, #mpALIGN_CENTER, #mpALIGN_TOP.
  438. */
  439. mpFY( const wxString& name = wxEmptyString, int flags = mpALIGN_TOP );
  440. /** Get function value for argument.
  441. * Override this function in your implementation.
  442. * @param y Argument
  443. * @return Function value
  444. */
  445. virtual double GetX( double y ) const = 0;
  446. /** Layer plot handler.
  447. * This implementation will plot the function in the visible area and put a label according
  448. * to the alignment specified.
  449. */
  450. virtual void Plot( wxDC& dc, mpWindow& w ) override;
  451. protected:
  452. int m_flags; // !< Holds label alignment
  453. DECLARE_DYNAMIC_CLASS( mpFY )
  454. };
  455. /** Abstract base class providing plot and labeling functionality for a locus plot F:N->X,Y.
  456. * Locus argument N is assumed to be in range 0 .. MAX_N, and implicitly derived by enumerating
  457. * all locus values. Override mpFXY::Rewind and mpFXY::GetNextXY to implement a locus.
  458. * Optionally implement a constructor and pass a name (label) and a label alignment
  459. * to the constructor mpFXY::mpFXY. If the layer name is empty, no label will be plotted.
  460. */
  461. class WXDLLIMPEXP_MATHPLOT mpFXY : public mpLayer
  462. {
  463. public:
  464. /** @param name Label
  465. * @param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE.
  466. */
  467. mpFXY( const wxString& name = wxEmptyString, int flags = mpALIGN_NE );
  468. /** Rewind value enumeration with mpFXY::GetNextXY.
  469. * Override this function in your implementation.
  470. */
  471. virtual void Rewind() = 0;
  472. virtual void SetSweepWindow( int aSweepIdx ) { Rewind(); }
  473. /** Get locus value for next N.
  474. * Override this function in your implementation.
  475. * @param x Returns X value
  476. * @param y Returns Y value
  477. */
  478. virtual bool GetNextXY( double& x, double& y ) = 0;
  479. virtual size_t GetCount() const = 0;
  480. virtual int GetSweepCount() const { return 1; }
  481. /** Layer plot handler.
  482. * This implementation will plot the locus in the visible area and put a label according to
  483. * the alignment specified.
  484. */
  485. virtual void Plot( wxDC& dc, mpWindow& w ) override;
  486. virtual void SetScale( mpScaleBase* scaleX, mpScaleBase* scaleY );
  487. void UpdateScales();
  488. double s2x( double plotCoordX ) const;
  489. double s2y( double plotCoordY ) const;
  490. double x2s( double x ) const;
  491. double y2s( double y ) const;
  492. protected:
  493. int m_flags; // !< Holds label alignment
  494. // Data to calculate label positioning
  495. wxCoord maxDrawX, minDrawX, maxDrawY, minDrawY;
  496. // int drawnPoints;
  497. mpScaleBase* m_scaleX, * m_scaleY;
  498. /** Update label positioning data
  499. * @param xnew New x coordinate
  500. * @param ynew New y coordinate
  501. */
  502. void UpdateViewBoundary( wxCoord xnew, wxCoord ynew );
  503. DECLARE_DYNAMIC_CLASS( mpFXY )
  504. };
  505. /*@}*/
  506. // -----------------------------------------------------------------------------
  507. // mpLayer implementations - furniture (scales, ...)
  508. // -----------------------------------------------------------------------------
  509. /** @name mpLayer implementations - furniture (scales, ...)
  510. * @{*/
  511. /** Plot layer implementing a x-scale ruler.
  512. * The ruler is fixed at Y=0 in the coordinate system. A label is plotted at the bottom-right
  513. * hand of the ruler. The scale numbering automatically adjusts to view and zoom factor.
  514. */
  515. class WXDLLIMPEXP_MATHPLOT mpScaleBase : public mpLayer
  516. {
  517. public:
  518. mpScaleBase();
  519. virtual ~mpScaleBase() {};
  520. virtual bool IsHorizontal() const = 0;
  521. bool HasBBox() const override { return false; }
  522. /** Set X axis alignment.
  523. * @param align alignment (choose between mpALIGN_BORDER_BOTTOM, mpALIGN_BOTTOM, mpALIGN_CENTER,
  524. * mpALIGN_TOP, mpALIGN_BORDER_TOP
  525. */
  526. void SetAlign( int align ) { m_flags = align; };
  527. void SetNameAlign( int align ) { m_nameFlags = align; }
  528. /** Set X axis ticks or grid
  529. * @param enable = true to plot axis ticks, false to plot grid.
  530. */
  531. void SetTicks( bool enable ) { m_ticks = enable; };
  532. /** Get X axis ticks or grid
  533. * @return true if plot is drawing axis ticks, false if the grid is active.
  534. */
  535. bool GetTicks() const { return m_ticks; };
  536. void GetDataRange( double& minV, double& maxV ) const
  537. {
  538. minV = m_minV;
  539. maxV = m_maxV;
  540. }
  541. virtual void ExtendDataRange( double minV, double maxV )
  542. {
  543. if( !m_rangeSet )
  544. {
  545. m_minV = minV;
  546. m_maxV = maxV;
  547. m_rangeSet = true;
  548. }
  549. else
  550. {
  551. m_minV = std::min( minV, m_minV );
  552. m_maxV = std::max( maxV, m_maxV );
  553. }
  554. if( m_minV == m_maxV )
  555. {
  556. m_minV = m_minV - 1.0;
  557. m_maxV = m_maxV + 1.0;
  558. }
  559. }
  560. virtual void ResetDataRange()
  561. {
  562. m_rangeSet = false;
  563. }
  564. double AbsMaxValue() const
  565. {
  566. return std::max( std::abs( m_maxV ), std::abs( m_minV ) );
  567. }
  568. double AbsVisibleMaxValue() const
  569. {
  570. return m_absVisibleMaxV;
  571. }
  572. void SetAxisMinMax( bool lock, double minV, double maxV )
  573. {
  574. m_axisLocked = lock;
  575. m_axisMin = minV;
  576. m_axisMax = maxV;
  577. }
  578. bool GetAxisMinMax( double* minV, double* maxV )
  579. {
  580. if( m_axisLocked )
  581. {
  582. *minV = m_axisMin;
  583. *maxV = m_axisMax;
  584. }
  585. else if( !m_tickValues.empty() )
  586. {
  587. *minV = m_tickValues.front();
  588. *maxV = m_tickValues.back();
  589. }
  590. return m_axisLocked;
  591. }
  592. virtual double TransformToPlot( double x ) const { return 0.0; };
  593. virtual double TransformFromPlot( double xplot ) const { return 0.0; };
  594. struct TICK_LABEL
  595. {
  596. TICK_LABEL( double pos_ = 0.0, const wxString& label_ = wxT( "" ) ) :
  597. pos( pos_ ),
  598. label( label_ ),
  599. visible( true )
  600. {}
  601. double pos;
  602. wxString label;
  603. bool visible;
  604. };
  605. protected:
  606. void updateTickLabels( wxDC& dc, mpWindow& w );
  607. void computeLabelExtents( wxDC& dc, mpWindow& w );
  608. // virtual int getLabelDecimalDigits(int maxDigits) const;
  609. virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) {};
  610. virtual void recalculateTicks( wxDC& dc, mpWindow& w ) {};
  611. virtual void formatLabels() {};
  612. protected:
  613. std::vector<double> m_tickValues;
  614. std::vector<TICK_LABEL> m_tickLabels;
  615. double m_offset, m_scale;
  616. double m_absVisibleMaxV;
  617. int m_flags; // !< Flag for axis alignment
  618. int m_nameFlags;
  619. bool m_ticks; // !< Flag to toggle between ticks or grid
  620. double m_minV, m_maxV;
  621. bool m_rangeSet;
  622. bool m_axisLocked;
  623. double m_axisMin;
  624. double m_axisMax;
  625. int m_maxLabelHeight;
  626. int m_maxLabelWidth;
  627. };
  628. class WXDLLIMPEXP_MATHPLOT mpScaleXBase : public mpScaleBase
  629. {
  630. public:
  631. /** Full constructor.
  632. * @param name Label to plot by the ruler
  633. * @param flags Set the position of the scale with respect to the window.
  634. * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for
  635. * drawing the grid.
  636. * @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds.
  637. */
  638. mpScaleXBase( const wxString& name = wxT( "X" ), int flags = mpALIGN_CENTER, bool ticks = true,
  639. unsigned int type = mpX_NORMAL );
  640. virtual ~mpScaleXBase() {};
  641. virtual bool IsHorizontal() const override { return true; }
  642. virtual void Plot( wxDC& dc, mpWindow& w ) override;
  643. virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override;
  644. DECLARE_DYNAMIC_CLASS( mpScaleXBase )
  645. };
  646. class WXDLLIMPEXP_MATHPLOT mpScaleX : public mpScaleXBase
  647. {
  648. public:
  649. /** Full constructor.
  650. * @param name Label to plot by the ruler
  651. * @param flags Set the position of the scale with respect to the window.
  652. * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for
  653. * drawing the grid.
  654. * @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds.
  655. */
  656. mpScaleX( const wxString& name = wxT( "X" ), int flags = mpALIGN_CENTER, bool ticks = true,
  657. unsigned int type = mpX_NORMAL );
  658. virtual double TransformToPlot( double x ) const override;
  659. virtual double TransformFromPlot( double xplot ) const override;
  660. protected:
  661. virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override;
  662. DECLARE_DYNAMIC_CLASS( mpScaleX )
  663. };
  664. class WXDLLIMPEXP_MATHPLOT mpScaleXLog : public mpScaleXBase
  665. {
  666. public:
  667. /** Full constructor.
  668. * @param name Label to plot by the ruler
  669. * @param flags Set the position of the scale with respect to the window.
  670. * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for
  671. * drawing the grid.
  672. * @param type mpX_NORMAL for normal labels, mpX_TIME for time axis in hours, minutes, seconds.
  673. */
  674. mpScaleXLog( const wxString& name = wxT( "log(X)" ), int flags = mpALIGN_CENTER,
  675. bool ticks = true, unsigned int type = mpX_NORMAL );
  676. virtual double TransformToPlot( double x ) const override;
  677. virtual double TransformFromPlot( double xplot ) const override;
  678. protected:
  679. void recalculateTicks( wxDC& dc, mpWindow& w ) override;
  680. DECLARE_DYNAMIC_CLASS( mpScaleXLog )
  681. };
  682. /** Plot layer implementing a y-scale ruler.
  683. * If align is set to mpALIGN_CENTER, the ruler is fixed at X=0 in the coordinate system.
  684. * If the align is set to mpALIGN_TOP or mpALIGN_BOTTOM, the axis is always
  685. * drawn respectively at top or bottom of the window. A label is plotted at
  686. * the top-right hand of the ruler.
  687. * The scale numbering automatically adjusts to view and zoom factor.
  688. */
  689. class WXDLLIMPEXP_MATHPLOT mpScaleY : public mpScaleBase
  690. {
  691. public:
  692. /** @param name Label to plot by the ruler
  693. * @param flags Set position of the scale respect to the window.
  694. * @param ticks Select ticks or grid. Give true (default) for drawing axis ticks, false for
  695. * drawing the grid
  696. */
  697. mpScaleY( const wxString& name = wxT( "Y" ), int flags = mpALIGN_CENTER, bool ticks = true );
  698. virtual bool IsHorizontal() const override { return false; }
  699. /** Layer plot handler.
  700. * This implementation will plot the ruler adjusted to the visible area.
  701. */
  702. virtual void Plot( wxDC& dc, mpWindow& w ) override;
  703. /** Check whether this layer has a bounding box.
  704. * This implementation returns \a false thus making the ruler invisible
  705. * to the plot layer bounding box calculation by mpWindow.
  706. */
  707. virtual bool HasBBox() const override { return false; }
  708. virtual double TransformToPlot( double x ) const override;
  709. virtual double TransformFromPlot( double xplot ) const override;
  710. void SetMasterScale( mpScaleY* masterScale ) { m_masterScale = masterScale; }
  711. protected:
  712. virtual void getVisibleDataRange( mpWindow& w, double& minV, double& maxV ) override;
  713. virtual void recalculateTicks( wxDC& dc, mpWindow& w ) override;
  714. void computeSlaveTicks( mpWindow& w );
  715. mpScaleY* m_masterScale;
  716. int m_flags; // !< Flag for axis alignment
  717. bool m_ticks; // !< Flag to toggle between ticks or grid
  718. DECLARE_DYNAMIC_CLASS( mpScaleY )
  719. };
  720. // -----------------------------------------------------------------------------
  721. // mpWindow
  722. // -----------------------------------------------------------------------------
  723. /** @name Constants defining mouse modes for mpWindow
  724. * @{*/
  725. /** Mouse panning drags the view. Mouse mode for mpWindow. */
  726. #define mpMOUSEMODE_DRAG 0
  727. /** Mouse panning creates a zoom box. Mouse mode for mpWindow. */
  728. #define mpMOUSEMODE_ZOOMBOX 1
  729. /*@}*/
  730. /** Define the type for the list of layers inside mpWindow */
  731. // WX_DECLARE_HASH_MAP( int, mpLayer*, wxIntegerHash, wxIntegerEqual, wxLayerList );
  732. typedef std::deque<mpLayer*> wxLayerList;
  733. /** Canvas for plotting mpLayer implementations.
  734. *
  735. * This class defines a zoomable and moveable 2D plot canvas. Any number
  736. * of mpLayer implementations (scale rulers, function plots, ...) can be
  737. * attached using mpWindow::AddLayer.
  738. *
  739. * The canvas window provides a context menu with actions for navigating the view.
  740. * The context menu can be retrieved with mpWindow::GetPopupMenu, e.g. for extending it
  741. * externally.
  742. *
  743. * Since wxMathPlot version 0.03, the mpWindow incorporates the following features:
  744. * - DoubleBuffering (Default=disabled): Can be set with EnableDoubleBuffer
  745. * - Mouse based pan/zoom (Default=enabled): Can be set with EnableMousePanZoom.
  746. *
  747. * The mouse commands can be visualized by the user through the popup menu, and are:
  748. * - Mouse Move+CTRL: Pan (Move)
  749. * - Mouse Wheel: Vertical scroll
  750. * - Mouse Wheel+SHIFT: Horizontal scroll
  751. * - Mouse Wheel UP+CTRL: Zoom in
  752. * - Mouse Wheel DOWN+CTRL: Zoom out
  753. *
  754. */
  755. class WXDLLIMPEXP_MATHPLOT mpWindow : public wxWindow
  756. {
  757. public:
  758. /**
  759. * Enumerates the possible mouse wheel actions that can be performed on the plot.
  760. */
  761. enum class MouseWheelAction
  762. {
  763. NONE,
  764. PAN_LEFT_RIGHT,
  765. PAN_RIGHT_LEFT,
  766. PAN_UP_DOWN,
  767. ZOOM,
  768. ZOOM_HORIZONTALLY,
  769. ZOOM_VERTICALLY,
  770. COUNT // Internal use only
  771. };
  772. /**
  773. * Contains the set of modified mouse wheel actions that can be performed on the plot.
  774. */
  775. struct MouseWheelActionSet
  776. {
  777. /* If this bundled wxMathPlot implementation is to remain single-header and not dependent
  778. * on any part of KiCad, then the SIM_MOUSE_WHEEL_ACTION_SET struct must be duplicated
  779. * here. SIM_PLOT_TAB::convertMouseWheelActions is used to convert from
  780. * SIM_MOUSE_WHEEL_ACTION_SET to mpWindow::MouseWheelActionSet. */
  781. MouseWheelAction verticalUnmodified;
  782. MouseWheelAction verticalWithCtrl;
  783. MouseWheelAction verticalWithShift;
  784. MouseWheelAction verticalWithAlt;
  785. MouseWheelAction horizontal;
  786. };
  787. mpWindow();
  788. mpWindow( wxWindow* parent, wxWindowID id );
  789. ~mpWindow();
  790. /** Get reference to context menu of the plot canvas.
  791. * @return Pointer to menu. The menu can be modified.
  792. */
  793. wxMenu* GetPopupMenu() { return &m_popmenu; }
  794. /** Add a plot layer to the canvas.
  795. * @param layer Pointer to layer. The mpLayer object will get under control of mpWindow,
  796. * i.e. it will be delete'd on mpWindow destruction
  797. * @param refreshDisplay States whether to refresh the display (UpdateAll) after adding the
  798. * layer.
  799. * @retval true Success
  800. * @retval false Failure due to out of memory.
  801. */
  802. bool AddLayer( mpLayer* layer, bool refreshDisplay = true );
  803. /** Remove a plot layer from the canvas.
  804. * @param layer Pointer to layer. The mpLayer object will be destructed using delete.
  805. * @param alsoDeleteObject If set to true, the mpLayer object will be also "deleted", not just
  806. * removed from the internal list.
  807. * @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the
  808. * layer.
  809. * @return true if layer is deleted correctly
  810. *
  811. * N.B. Only the layer reference in the mpWindow is deleted, the layer object still exists!
  812. */
  813. bool DelLayer( mpLayer* layer, bool alsoDeleteObject = false, bool refreshDisplay = true );
  814. /** Remove all layers from the plot.
  815. * @param alsoDeleteObject If set to true, the mpLayer objects will be also "deleted", not
  816. * just removed from the internal list.
  817. * @param refreshDisplay States whether to refresh the display (UpdateAll) after removing the
  818. * layers.
  819. */
  820. void DelAllLayers( bool alsoDeleteObject, bool refreshDisplay = true );
  821. /*! Get the layer in list position indicated.
  822. * N.B. You <i>must</i> know the index of the layer inside the list!
  823. * @param position position of the layer in the layers list
  824. * @return pointer to mpLayer
  825. */
  826. mpLayer* GetLayer( int position ) const;
  827. /*! Get the layer by its name (case sensitive).
  828. * @param name The name of the layer to retrieve
  829. * @return A pointer to the mpLayer object, or NULL if not found.
  830. */
  831. const mpLayer* GetLayerByName( const wxString& name ) const;
  832. mpLayer* GetLayerByName( const wxString& name )
  833. {
  834. return const_cast<mpLayer*>( static_cast<const mpWindow*>( this )->GetLayerByName( name ) );
  835. }
  836. /** Get current view's X scale.
  837. * See @ref mpLayer::Plot "rules for coordinate transformation"
  838. * @return Scale
  839. */
  840. double GetScaleX() const { return m_scaleX; };
  841. /** Get current view's Y scale.
  842. * See @ref mpLayer::Plot "rules for coordinate transformation"
  843. * @return Scale
  844. */
  845. double GetScaleY() const { return m_scaleY; }
  846. /** Get current view's X position.
  847. * See @ref mpLayer::Plot "rules for coordinate transformation"
  848. * @return X Position in layer coordinate system, that corresponds to the center point of the view.
  849. */
  850. double GetPosX() const { return m_posX; }
  851. /** Get current view's Y position.
  852. * See @ref mpLayer::Plot "rules for coordinate transformation"
  853. * @return Y Position in layer coordinate system, that corresponds to the center point of the view.
  854. */
  855. double GetPosY() const { return m_posY; }
  856. /** Get current view's X dimension in device context units.
  857. * Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer
  858. * implementations should rely on the value returned by the function.
  859. * See @ref mpLayer::Plot "rules for coordinate transformation"
  860. * @return X dimension.
  861. */
  862. int GetScrX() const { return m_scrX; }
  863. int GetXScreen() const { return m_scrX; }
  864. /** Get current view's Y dimension in device context units.
  865. * Usually this is equal to wxDC::GetSize, but it might differ thus mpLayer
  866. * implementations should rely on the value returned by the function.
  867. * See @ref mpLayer::Plot "rules for coordinate transformation"
  868. * @return Y dimension.
  869. */
  870. int GetScrY() const { return m_scrY; }
  871. int GetYScreen() const { return m_scrY; }
  872. /** Set current view's X scale and refresh display.
  873. * @param scaleX New scale, must not be 0.
  874. */
  875. void SetScaleX( double scaleX );
  876. /** Set current view's Y scale and refresh display.
  877. * @param scaleY New scale, must not be 0.
  878. */
  879. void SetScaleY( double scaleY )
  880. {
  881. if( scaleY != 0 )
  882. m_scaleY = scaleY;
  883. UpdateAll();
  884. }
  885. /** Set current view's X position and refresh display.
  886. * @param posX New position that corresponds to the center point of the view.
  887. */
  888. void SetPosX( double posX ) { m_posX = posX; UpdateAll(); }
  889. /** Set current view's Y position and refresh display.
  890. * @param posY New position that corresponds to the center point of the view.
  891. */
  892. void SetPosY( double posY ) { m_posY = posY; UpdateAll(); }
  893. /** Set current view's X and Y position and refresh display.
  894. * @param posX New position that corresponds to the center point of the view.
  895. * @param posY New position that corresponds to the center point of the view.
  896. */
  897. void SetPos( double posX, double posY ) { m_posX = posX; m_posY = posY; UpdateAll(); }
  898. /** Set current view's dimensions in device context units.
  899. * Needed by plotting functions. It doesn't refresh display.
  900. * @param scrX New position that corresponds to the center point of the view.
  901. * @param scrY New position that corresponds to the center point of the view.
  902. */
  903. void SetScr( int scrX, int scrY ) { m_scrX = scrX; m_scrY = scrY; }
  904. /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
  905. * @sa p2y,x2p,y2p */
  906. inline double p2x( wxCoord pixelCoordX ) { return m_posX + pixelCoordX / m_scaleX; }
  907. /** Converts mpWindow (screen) pixel coordinates into graph (floating point) coordinates, using current mpWindow position and scale.
  908. * @sa p2x,x2p,y2p */
  909. inline double p2y( wxCoord pixelCoordY ) { return m_posY - pixelCoordY / m_scaleY; }
  910. /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
  911. * @sa p2x,p2y,y2p */
  912. inline wxCoord x2p( double x ) { return (wxCoord) ( (x - m_posX) * m_scaleX ); }
  913. /** Converts graph (floating point) coordinates into mpWindow (screen) pixel coordinates, using current mpWindow position and scale.
  914. * @sa p2x,p2y,x2p */
  915. inline wxCoord y2p( double y ) { return (wxCoord) ( (m_posY - y) * m_scaleY ); }
  916. /** Enable/disable the double-buffering of the window, eliminating the flicker (default=disabled).
  917. */
  918. void EnableDoubleBuffer( bool enabled ) { m_enableDoubleBuffer = enabled; }
  919. /** Enable/disable the feature of pan/zoom with the mouse (default=enabled)
  920. */
  921. void EnableMousePanZoom( bool enabled ) { m_enableMouseNavigation = enabled; }
  922. /** Set the pan/zoom actions corresponding to mousewheel/trackpad events. */
  923. void SetMouseWheelActions( const MouseWheelActionSet& s ) { m_mouseWheelActions = s; }
  924. /** Set view to fit global bounding box of all plot layers and refresh display.
  925. * Scale and position will be set to show all attached mpLayers.
  926. * The X/Y scale aspect lock is taken into account.
  927. */
  928. void Fit() override;
  929. /** Set view to fit a given bounding box and refresh display.
  930. * The X/Y scale aspect lock is taken into account.
  931. * If provided, the parameters printSizeX and printSizeY are taken as the DC size, and the
  932. * pixel scales are computed accordingly. Also, in this case the passed borders are not saved
  933. * as the "desired borders", since this use will be invoked only when printing.
  934. */
  935. void Fit( double xMin, double xMax, double yMin, double yMax,
  936. const wxCoord* printSizeX = nullptr, const wxCoord* printSizeY = nullptr,
  937. wxOrientation directions = wxBOTH );
  938. /** Zoom into current view and refresh display
  939. * @param centerPoint The point (pixel coordinates) that will stay in the same
  940. * position on the screen after the zoom (by default, the center of the mpWindow).
  941. */
  942. void ZoomIn( const wxPoint& centerPoint = wxDefaultPosition );
  943. void ZoomIn( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions = wxBOTH );
  944. /** Zoom out current view and refresh display
  945. * @param centerPoint The point (pixel coordinates) that will stay in the same
  946. * position on the screen after the zoom (by default, the center of the mpWindow).
  947. */
  948. void ZoomOut( const wxPoint& centerPoint = wxDefaultPosition );
  949. void ZoomOut( const wxPoint& centerPoint, double zoomFactor,
  950. wxOrientation directions = wxBOTH );
  951. /** Zoom view fitting given coordinates to the window (p0 and p1 do not need to be in any specific order)
  952. */
  953. void ZoomRect( wxPoint p0, wxPoint p1 );
  954. /** Refresh display */
  955. void UpdateAll();
  956. // Added methods by Davide Rondini
  957. /** Counts the number of plot layers, whether or not they have a bounding box.
  958. * \return The number of layers in the mpWindow. */
  959. unsigned int CountAllLayers() const { return m_layers.size(); };
  960. /** Returns the left-border layer coordinate that the user wants the mpWindow to show
  961. * (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).
  962. * @sa Fit
  963. */
  964. double GetDesiredXmin() const { return m_desiredXmin; }
  965. /** Returns the right-border layer coordinate that the user wants the mpWindow to show
  966. * (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).
  967. * @sa Fit
  968. */
  969. double GetDesiredXmax() const { return m_desiredXmax; }
  970. /** Returns the bottom-border layer coordinate that the user wants the mpWindow to show
  971. * (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).
  972. * @sa Fit
  973. */
  974. double GetDesiredYmin() const { return m_desiredYmin; }
  975. /** Returns the top layer-border coordinate that the user wants the mpWindow to show
  976. * (it may be not exactly the actual shown coordinate in the case of locked aspect ratio).
  977. * @sa Fit
  978. */
  979. double GetDesiredYmax() const { return m_desiredYmax; }
  980. /** Returns the bounding box coordinates
  981. * @param bbox Pointer to a 6-element double array where to store bounding box coordinates.
  982. */
  983. void GetBoundingBox( double* bbox ) const;
  984. /** Draw the window on a wxBitmap, then save it to a file.
  985. * @param aImage a wxImage where to save the screenshot
  986. * @param aImageSize Set a size for the output image. Default is the same as the screen size
  987. * @param aFit Decide whether to fit the plot into the size
  988. */
  989. bool SaveScreenshot( wxImage& aImage,
  990. wxSize aImageSize = wxDefaultSize, bool aFit = false );
  991. /** This value sets the zoom steps whenever the user clicks "Zoom in/out" or performs zoom with the mouse wheel.
  992. * It must be a number above unity. This number is used for zoom in, and its inverse for zoom out.
  993. * Set to 1.5 by default.
  994. */
  995. static double zoomIncrementalFactor;
  996. /** Set window margins, creating a blank area where some kinds of layers cannot draw.
  997. * This is useful for example to draw axes outside the area where the plots are drawn.
  998. * @param top Top border
  999. * @param right Right border
  1000. * @param bottom Bottom border
  1001. * @param left Left border */
  1002. void SetMargins( int top, int right, int bottom, int left );
  1003. /** Set the top margin. @param top Top Margin */
  1004. void SetMarginTop( int top ) { m_marginTop = top; };
  1005. /** Set the right margin. @param right Right Margin */
  1006. void SetMarginRight( int right ) { m_marginRight = right; };
  1007. /** Set the bottom margin. @param bottom Bottom Margin */
  1008. void SetMarginBottom( int bottom ) { m_marginBottom = bottom; };
  1009. /** Set the left margin. @param left Left Margin */
  1010. void SetMarginLeft( int left ) { m_marginLeft = left; };
  1011. /** @return the top margin. */
  1012. int GetMarginTop() const { return m_marginTop; };
  1013. /** @return the right margin. */
  1014. int GetMarginRight() const { return m_marginRight; };
  1015. /** @return the bottom margin. */
  1016. int GetMarginBottom() const { return m_marginBottom; };
  1017. /** @return the left margin. */
  1018. int GetMarginLeft() const { return m_marginLeft; };
  1019. /** Check if a given point is inside the area of a mpInfoLayer and eventually returns its pointer.
  1020. * @param point The position to be checked
  1021. * @return If an info layer is found, returns its pointer, NULL otherwise */
  1022. mpInfoLayer* IsInsideInfoLayer( wxPoint& point );
  1023. /** Sets the visibility of a layer by its name.
  1024. * @param name The layer name to set visibility
  1025. * @param viewable the view status to be set */
  1026. void SetLayerVisible( const wxString& name, bool viewable );
  1027. /** Check whether a layer with given name is visible
  1028. * @param name The layer name
  1029. * @return layer visibility status */
  1030. bool IsLayerVisible( const wxString& name ) const;
  1031. /** Sets the visibility of a layer by its position in layer list.
  1032. * @param position The layer position in layer list
  1033. * @param viewable the view status to be set */
  1034. void SetLayerVisible( const unsigned int position, bool viewable );
  1035. /** Check whether the layer at given position is visible
  1036. * @param position The layer position in layer list
  1037. * @return layer visibility status */
  1038. bool IsLayerVisible( unsigned int position ) const;
  1039. /** Set Color theme. Provide colours to set a new colour theme.
  1040. * @param bgColour Background colour
  1041. * @param drawColour The colour used to draw all elements in foreground, axes excluded
  1042. * @param axesColour The colour used to draw axes (but not their labels) */
  1043. void SetColourTheme( const wxColour& bgColour, const wxColour& drawColour,
  1044. const wxColour& axesColour );
  1045. /** Get axes draw colour
  1046. * @return reference to axis colour used in theme */
  1047. const wxColour& GetAxesColour() { return m_axColour; };
  1048. /** Enable limiting of zooming & panning to the area used by the plots */
  1049. void LimitView( bool aEnable )
  1050. {
  1051. m_enableLimitedView = aEnable;
  1052. }
  1053. void LockY( bool aLock ) { m_yLocked = aLock; }
  1054. bool GetYLocked() const { return m_yLocked; }
  1055. void ZoomUndo();
  1056. void ZoomRedo();
  1057. int UndoZoomStackSize() const { return m_undoZoomStack.size(); }
  1058. int RedoZoomStackSize() const { return m_redoZoomStack.size(); }
  1059. /** Limits the zoomed or panned view to the area used by the plots. */
  1060. void AdjustLimitedView( wxOrientation directions = wxBOTH );
  1061. void OnFit( wxCommandEvent& event );
  1062. void OnCenter( wxCommandEvent& event );
  1063. protected:
  1064. static MouseWheelActionSet defaultMouseWheelActions();
  1065. void pushZoomUndo( const std::array<double, 4>& aZoom );
  1066. void OnPaint( wxPaintEvent& event ); // !< Paint handler, will plot all attached layers
  1067. void OnSize( wxSizeEvent& event ); // !< Size handler, will update scroll bar sizes
  1068. void OnShowPopupMenu( wxMouseEvent& event ); // !< Mouse handler, will show context menu
  1069. void OnMouseMiddleDown( wxMouseEvent& event ); // !< Mouse handler, for detecting when the user
  1070. // !< drags with the middle button or just "clicks" for the menu
  1071. void onZoomIn( wxCommandEvent& event ); // !< Context menu handler
  1072. void onZoomOut( wxCommandEvent& event ); // !< Context menu handler
  1073. void onZoomUndo( wxCommandEvent& event ); // !< Context menu handler
  1074. void onZoomRedo( wxCommandEvent& event ); // !< Context menu handler
  1075. void onMouseWheel( wxMouseEvent& event ); // !< Mouse handler for the wheel
  1076. void onMagnify( wxMouseEvent& event ); // !< Pinch zoom handler
  1077. void onMouseMove( wxMouseEvent& event ); // !< Mouse handler for mouse motion (for pan)
  1078. void onMouseLeftDown( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
  1079. void onMouseLeftRelease( wxMouseEvent& event ); // !< Mouse left click (for rect zoom)
  1080. void DoZoom( const wxPoint& centerPoint, double zoomFactor, wxOrientation directions );
  1081. void RecomputeDesiredX( double& min, double& max );
  1082. void RecomputeDesiredY( double& min, double& max );
  1083. wxOrientation ViewNeedsRefitting( wxOrientation directions ) const;
  1084. void PerformMouseWheelAction( wxMouseEvent& event, MouseWheelAction action );
  1085. /** Recalculate global layer bounding box, and save it in m_minX,...
  1086. * \return true if there is any valid BBox information.
  1087. */
  1088. virtual bool UpdateBBox();
  1089. /** Applies new X view coordinates depending on the settings
  1090. * \return true if the changes were applied
  1091. */
  1092. virtual bool SetXView( double pos, double desiredMax, double desiredMin );
  1093. /** Applies new Y view coordinates depending on the settings
  1094. * \return true if the changes were applied
  1095. */
  1096. virtual bool SetYView( double pos, double desiredMax, double desiredMin );
  1097. // wxList m_layers; //!< List of attached plot layers
  1098. wxLayerList m_layers; // !< List of attached plot layers
  1099. wxMenu m_popmenu; // !< Canvas' context menu
  1100. wxColour m_bgColour; // !< Background Colour
  1101. wxColour m_fgColour; // !< Foreground Colour
  1102. wxColour m_axColour; // !< Axes Colour
  1103. double m_minX; // !< Global layer bounding box, left border incl.
  1104. double m_maxX; // !< Global layer bounding box, right border incl.
  1105. double m_minY; // !< Global layer bounding box, bottom border incl.
  1106. double m_maxY; // !< Global layer bounding box, top border incl.
  1107. double m_scaleX; // !< Current view's X scale
  1108. double m_scaleY; // !< Current view's Y scale
  1109. double m_posX; // !< Current view's X position
  1110. double m_posY; // !< Current view's Y position
  1111. int m_scrX; // !< Current view's X dimension
  1112. int m_scrY; // !< Current view's Y dimension
  1113. int m_clickedX; // !< Last mouse click X position, for centering and zooming the view
  1114. int m_clickedY; // !< Last mouse click Y position, for centering and zooming the view
  1115. bool m_yLocked;
  1116. /** These are updated in Fit, ZoomIn, ZoomOut, ZoomRect, SetXView, SetYView and may be different
  1117. * from the real borders (layer coordinates) only if lock aspect ratio is true.
  1118. *
  1119. * @note They use the plot area as their coordinate system, and not the layer coordinate
  1120. * system used by m_posX/Y.
  1121. */
  1122. double m_desiredXmin, m_desiredXmax, m_desiredYmin, m_desiredYmax;
  1123. // These are gaps between the curve extrema and the edges of the plot area, expressed as
  1124. // a factor of global layer bounding box width/height.
  1125. double m_topBottomPlotGapFactor;
  1126. double m_leftRightPlotGapFactor;
  1127. int m_marginTop, m_marginRight, m_marginBottom, m_marginLeft;
  1128. int m_last_lx, m_last_ly; // !< For double buffering
  1129. wxMemoryDC m_buff_dc; // !< For double buffering
  1130. wxBitmap* m_buff_bmp; // !< For double buffering
  1131. bool m_enableDoubleBuffer; // !< For double buffering
  1132. bool m_enableMouseNavigation; // !< For pan/zoom with the mouse.
  1133. bool m_enableLimitedView;
  1134. MouseWheelActionSet m_mouseWheelActions;
  1135. wxPoint m_mouseMClick; // !< For the middle button "drag" feature
  1136. wxPoint m_mouseLClick; // !< Starting coords for rectangular zoom selection
  1137. mpInfoLayer* m_movingInfoLayer; // !< For moving info layers over the window area
  1138. bool m_zooming;
  1139. wxRect m_zoomRect;
  1140. std::stack<std::array<double, 4>> m_undoZoomStack;
  1141. std::stack<std::array<double, 4>> m_redoZoomStack;
  1142. DECLARE_DYNAMIC_CLASS( mpWindow )
  1143. DECLARE_EVENT_TABLE()
  1144. private:
  1145. struct DelegatingContructorTag {};
  1146. template <typename... Ts>
  1147. mpWindow( DelegatingContructorTag, Ts&&... windowArgs );
  1148. void initializeGraphicsContext();
  1149. };
  1150. // -----------------------------------------------------------------------------
  1151. // mpFXYVector - provided by Jose Luis Blanco
  1152. // -----------------------------------------------------------------------------
  1153. /** A class providing graphs functionality for a 2D plot (either continuous or a set of points), from vectors of data.
  1154. * This class can be used directly, the user does not need to derive any new class. Simply pass the data as two vectors
  1155. * with the same length containing the X and Y coordinates to the method SetData.
  1156. *
  1157. * To generate a graph with a set of points, call
  1158. * \code
  1159. * layerVar->SetContinuity(false)
  1160. * \endcode
  1161. *
  1162. * or
  1163. *
  1164. * \code
  1165. * layerVar->SetContinuity(true)
  1166. * \endcode
  1167. *
  1168. * to render the sequence of coordinates as a continuous line.
  1169. *
  1170. * (Added: Jose Luis Blanco, AGO-2007)
  1171. */
  1172. class WXDLLIMPEXP_MATHPLOT mpFXYVector : public mpFXY
  1173. {
  1174. public:
  1175. /** @param name Label
  1176. * @param flags Label alignment, pass one of #mpALIGN_NE, #mpALIGN_NW, #mpALIGN_SW, #mpALIGN_SE.
  1177. */
  1178. mpFXYVector( const wxString& name = wxEmptyString, int flags = mpALIGN_NE );
  1179. virtual ~mpFXYVector() {}
  1180. /** Changes the internal data: the set of points to draw.
  1181. * Both vectors MUST be of the same length. This method DOES NOT refresh the mpWindow; do it manually.
  1182. * @sa Clear
  1183. */
  1184. virtual void SetData( const std::vector<double>& xs, const std::vector<double>& ys );
  1185. void SetSweepCount( int aSweepCount ) { m_sweepCount = aSweepCount; }
  1186. void SetSweepSize( size_t aSweepSize ) { m_sweepSize = aSweepSize; }
  1187. /** Clears all the data, leaving the layer empty.
  1188. * @sa SetData
  1189. */
  1190. void Clear();
  1191. protected:
  1192. /** The internal copy of the set of data to draw.
  1193. */
  1194. std::vector<double> m_xs, m_ys;
  1195. size_t m_index; // internal counter for the "GetNextXY" interface
  1196. size_t m_sweepWindow; // last m_index of the current sweep
  1197. /** Loaded at SetData
  1198. */
  1199. double m_minX, m_maxX, m_minY, m_maxY;
  1200. int m_sweepCount = 1; // sweeps to split data into
  1201. size_t m_sweepSize = std::numeric_limits<size_t>::max(); // data-points in each sweep
  1202. /** Rewind value enumeration with mpFXY::GetNextXY.
  1203. * Overridden in this implementation.
  1204. */
  1205. void Rewind() override;
  1206. void SetSweepWindow( int aSweepIdx ) override;
  1207. /** Get locus value for next N.
  1208. * Overridden in this implementation.
  1209. * @param x Returns X value
  1210. * @param y Returns Y value
  1211. */
  1212. bool GetNextXY( double& x, double& y ) override;
  1213. size_t GetCount() const override { return m_xs.size(); }
  1214. int GetSweepCount() const override { return m_sweepCount; }
  1215. public:
  1216. /** Returns the actual minimum X data (loaded in SetData).
  1217. */
  1218. double GetMinX() const override { return m_minX; }
  1219. /** Returns the actual minimum Y data (loaded in SetData).
  1220. */
  1221. double GetMinY() const override { return m_minY; }
  1222. /** Returns the actual maximum X data (loaded in SetData).
  1223. */
  1224. double GetMaxX() const override { return m_maxX; }
  1225. /** Returns the actual maximum Y data (loaded in SetData).
  1226. */
  1227. double GetMaxY() const override { return m_maxY; }
  1228. protected:
  1229. DECLARE_DYNAMIC_CLASS( mpFXYVector )
  1230. };
  1231. #endif // _MP_MATHPLOT_H_