00001 #ifndef _PlotControl_h
00002 #define _PlotControl_h
00003
00004 #include "../CountedPtr.h"
00005 #include "../Region.h"
00006 #include "PlotAxis.h"
00007 #include "PlotLayer.h"
00008 #include "PlotStatus.h"
00009
00010 DECLARE_EVENT_TYPE(PLOT_FITVIEW_REQUEST_EVENT, -1);
00011
00012 class PlotControl
00013 : public wxWindow
00014 {
00015 public:
00016 enum ToolType
00017 {
00018 PAN,
00019 ZOOM_IN,
00020 ZOOM_OUT
00021 };
00022
00023 PlotControl(
00024 wxWindow* pParent,
00025 wxWindowID id,
00026 const FunctionBase& function,
00027 PlotStatus* pPlotStatus = NULL,
00028 const wxPoint& position = wxDefaultPosition,
00029 const wxSize& size = wxDefaultSize);
00030
00031 virtual ~PlotControl();
00032
00035 void SetTool(ToolType tool);
00036
00039 void OnEraseEvent(wxEraseEvent& event);
00040
00043 void OnPaint(wxPaintEvent& event);
00044
00047 void OnResize(wxSizeEvent& event);
00048
00051 void OnFitViewRequest(wxCommandEvent& event);
00052
00053
00054 void OnMouseLeftDown(wxMouseEvent& event);
00055 void OnMouseLeftUp(wxMouseEvent& event);
00056 void OnMouseRightUp(wxMouseEvent& event);
00057 void OnMouseMove(wxMouseEvent& event);
00058 void OnMouseWheel(wxMouseEvent& event);
00059
00060 void OnMouseEnter(wxMouseEvent& event);
00061 void OnMouseLeave(wxMouseEvent& event);
00062
00063
00066 void ExportBitmap();
00067
00075 virtual void OnAspectChange(bool redraw = false) = 0;
00076
00079 bool AdjustView(const Region& region);
00080
00084 void SetView(const Region& region);
00085
00090 bool FitView();
00091
00094 void RefreshPlot();
00095
00096
00097
00098 inline double X1() const;
00099 inline double X2() const;
00100 inline double Y1() const;
00101 inline double Y2() const;
00102 inline double ScaleX() const;
00103 inline double ScaleY() const;
00104
00105 inline double DcToPlotX(wxCoord x) const;
00106 inline double DcToPlotY(wxCoord y) const;
00107
00108 inline wxCoord PlotToDcX(double x) const;
00109 inline wxCoord PlotToDcY(double y) const;
00110
00111 void SetFunctionValueExtent(double min, double max) const;
00112
00113 void AppendLayer(CountedPtr<PlotLayer> cpLayer);
00114
00115 protected:
00118 void InitPlotDc();
00119
00122 void RedrawAxes(wxDC& dc);
00123
00126 void Redraw();
00127
00128 void StartDragRectangle(wxCoord x, wxCoord y);
00129 void UpdateDragRectangle(wxCoord x, wxCoord y);
00130 void StopDragRectangle();
00131
00132 wxSize ComputePlotSize() const;
00133
00134 wxCoord WindowToPlotAreaX(wxCoord x) const;
00135 wxCoord WindowToPlotAreaY(wxCoord y) const;
00136
00137
00138
00140 void LimitZoom(double& rA, double& rB, double min, double max) const;
00141
00142
00143
00144
00149 virtual void DrawDisplaced(long x, long y) = 0;
00150
00153 virtual void Pan(wxCoord x, wxCoord y) = 0;
00154
00157
00158
00161 virtual void ZoomIn(wxCoord x, wxCoord y) = 0;
00162
00165 virtual void ZoomRegionIn(wxCoord x,
00166 wxCoord y,
00167 wxCoord width,
00168 wxCoord height) = 0;
00169
00172 virtual void ZoomOut(wxCoord x, wxCoord y) = 0;
00173
00177 virtual void UpdateStatusOnMove(long x, long y) = 0;
00178
00181 virtual void UpdateScale() = 0;
00182
00183
00184
00185 const FunctionBase& mFunction;
00186
00187 wxMemoryDC mPlotDc;
00188 wxBitmap mPlotBitmap;
00189 bool mDirty;
00190
00191 PlotStatus* mpPlotStatus;
00192
00193 PlotAxis mXAxis;
00194 PlotAxis mYAxis;
00195
00196 ToolType mTool;
00197
00198
00199 double mPlotX1;
00200 double mPlotX2;
00201 double mPlotY1;
00202 double mPlotY2;
00203 mutable double mPlotMin;
00204 mutable double mPlotMax;
00205 double mScaleX;
00206 double mScaleY;
00207 double mScaleValues;
00208
00209 wxCoord mPlotAreaX;
00210 wxCoord mPlotAreaY;
00211
00212
00213 wxCoord mDragStartX;
00214 wxCoord mDragStartY;
00215 wxCoord mDragWidth;
00216 wxCoord mDragHeight;
00217
00218 wxCursor mOldCursor;
00219
00220 vector<CountedPtr<PlotLayer> > mLayers;
00221
00222 int mWheelRotation;
00223
00224 double mMinZoomX;
00225 double mMaxZoomX;
00226 double mMinZoomY;
00227 double mMaxZoomY;
00228
00230 const static double ZOOM_RATIO;
00232 const static double MIN_ZOOMED_WIDTH;
00234 const static double MAX_ZOOMED_WIDTH;
00236 const static wxCoord MARGIN_SIZE;
00237
00238 const wxCursor mCursorPan;
00239 const wxCursor mCursorZoomIn;
00240 const wxCursor mCursorZoomOut;
00241
00242 DECLARE_EVENT_TABLE()
00243 };
00244
00245
00246 inline double
00247 PlotControl::X1() const
00248 {
00249 return mPlotX1;
00250 }
00251
00252 inline double
00253 PlotControl::X2() const
00254 {
00255 return mPlotX2;
00256 }
00257
00258 inline double
00259 PlotControl::Y1() const
00260 {
00261 return mPlotY1;
00262 }
00263
00264 inline double
00265 PlotControl::Y2() const
00266 {
00267 return mPlotY2;
00268 }
00269
00270 inline double
00271 PlotControl::ScaleX() const
00272 {
00273 return mScaleX;
00274 }
00275
00276 inline double
00277 PlotControl::ScaleY() const
00278 {
00279 return mScaleY;
00280 }
00281
00282 inline double
00283 PlotControl::DcToPlotX(wxCoord x) const
00284 {
00285 return mPlotX1 + x * mScaleX;
00286 }
00287
00288 inline double
00289 PlotControl::DcToPlotY(wxCoord y) const
00290 {
00291 return mPlotY2 - y * mScaleY;
00292 }
00293
00294 inline wxCoord
00295 PlotControl::PlotToDcX(double x) const
00296 {
00297 return lround((x - mPlotX1) / mScaleX);
00298 }
00299
00300
00301 inline wxCoord
00302 PlotControl::PlotToDcY(double y) const
00303 {
00304 return lround((mPlotY2 - y) / mScaleY);
00305 }
00306
00307 #endif