1 ///////////////////////////////////////////////////////////////////////////// 2 // Name: plotcurv.h 3 // Purpose: wxPlotCurve for wxPlotCtrl 4 // Author: John Labenski 5 // Modified by: 6 // Created: 12/1/2000 7 // Copyright: (c) John Labenski 8 // Licence: wxWindows licence 9 ///////////////////////////////////////////////////////////////////////////// 10 11 #ifndef _WX_PLOTCURVE_H_ 12 #define _WX_PLOTCURVE_H_ 13 14 #include "wx/defs.h" 15 #include "wx/object.h" 16 #include "wx/clntdata.h" 17 #include "wx/geometry.h" 18 #include "wx/wxthings/genergdi.h" 19 #include "wx/plotctrl/plotdefs.h" 20 21 #ifdef GetYValue // Visual Studio 7 defines this 22 #undef GetYValue 23 #endif 24 25 //----------------------------------------------------------------------------- 26 // Utility functions 27 //----------------------------------------------------------------------------- 28 // Find y at point x along the line from (x0,y0)-(x1,y1), x0 must != x1 29 extern double LinearInterpolateY( double x0, double y0, 30 double x1, double y1, 31 double x ); 32 // Find x at point y along the line from (x0,y0)-(x1,y1), y0 must != y1 33 extern double LinearInterpolateX( double x0, double y0, 34 double x1, double y1, 35 double y ); 36 37 //---------------------------------------------------------------------------- 38 // Constants 39 //---------------------------------------------------------------------------- 40 41 // defines wxArrayDouble for use as necessary 42 #if !wxCHECK_VERSION(2,7,0) 43 WX_DEFINE_USER_EXPORTED_ARRAY_DOUBLE(double, wxArrayDouble, class WXDLLIMPEXP_PLOTCTRL); 44 #endif 45 46 // wxNullPlotBounds = wxRect2DDouble(0,0,0,0) 47 WXDLLIMPEXP_DATA_PLOTCTRL(extern const wxRect2DDouble) wxNullPlotBounds; 48 49 extern wxBitmap wxPlotSymbolNormal; 50 extern wxBitmap wxPlotSymbolActive; 51 extern wxBitmap wxPlotSymbolSelected; 52 53 enum wxPlotSymbol_Type 54 { 55 wxPLOTSYMBOL_ELLIPSE, 56 wxPLOTSYMBOL_RECTANGLE, 57 wxPLOTSYMBOL_CROSS, 58 wxPLOTSYMBOL_PLUS, 59 wxPLOTSYMBOL_MAXTYPE 60 }; 61 62 enum wxPlotPen_Type 63 { 64 wxPLOTPEN_NORMAL, 65 wxPLOTPEN_ACTIVE, 66 wxPLOTPEN_SELECTED, 67 wxPLOTPEN_MAXTYPE 68 }; 69 70 #define wxPLOTCURVE_OPTION_FILENAME wxT("File.Name") 71 #define wxPLOTCURVE_OPTION_EOLMODE wxT("EOL.Mode") 72 #define wxPLOTCURVE_OPTION_MODIFIED wxT("Modified") 73 #define wxPLOTCURVE_OPTION_HEADER wxT("Header") 74 #define wxPLOTCURVE_OPTION_DATASEPARATOR wxT("Data.Separator") 75 76 #define wxPLOTCURVE_DATASEPARATOR_SPACE wxT(" ") 77 #define wxPLOTCURVE_DATASEPARATOR_COMMA wxT(",") 78 #define wxPLOTCURVE_DATASEPARATOR_TAB wxT("\t") 79 80 //---------------------------------------------------------------------------- 81 // wxPlotCurveRefData - the wxObject::m_refData used for wxPlotCurves 82 // this should be the base class for ref data for your subclassed curves 83 // 84 // The ref data is also of class wxClientDataContainer so that you can 85 // attach arbitrary data to it 86 //---------------------------------------------------------------------------- 87 88 class WXDLLIMPEXP_PLOTCTRL wxPlotCurveRefData : public wxObjectRefData, public wxClientDataContainer 89 { 90 public: 91 wxPlotCurveRefData(); 92 wxPlotCurveRefData(const wxPlotCurveRefData& data); ~wxPlotCurveRefData()93 virtual ~wxPlotCurveRefData() {} 94 95 void Copy(const wxPlotCurveRefData &source); 96 97 wxRect2DDouble m_boundingRect; // bounds the curve or part to draw 98 // if width or height <= 0 then no bounds 99 100 wxArrayGenericPen m_pens; 101 static wxArrayGenericPen sm_defaultPens; 102 103 wxSortedArrayString m_optionNames; 104 wxArrayString m_optionValues; 105 }; 106 107 //----------------------------------------------------------------------------- 108 // wxPlotCurve - generic base plot curve class that must be subclassed for use 109 // 110 // GetY must be overridden as it "is" the curve 111 //----------------------------------------------------------------------------- 112 class WXDLLIMPEXP_PLOTCTRL wxPlotCurve: public wxObject 113 { 114 public: 115 // see the remmed out code in this function if you subclass it 116 wxPlotCurve(); ~wxPlotCurve()117 virtual ~wxPlotCurve() {} 118 119 // override as necessary so that Ok means that GetY works 120 virtual bool Ok() const; 121 122 // This *is* the output of the curve y = f(x) GetY(double WXUNUSED (x))123 virtual double GetY( double WXUNUSED(x) ) { return 0.0; } 124 125 // Bounding rect used for drawing the curve and... 126 // if the width or height <= 0 then there's no bounds (or unknown) 127 // wxPlotCurve/Function : may be unknown and should probably be (0,0,0,0) 128 // you can limit the extent by setting to a smaller rect 129 // wxPlotData : calculated from CalcBoundingRect and is well defined 130 // DON'T call SetBoundingRect unless you know what you're doing 131 virtual wxRect2DDouble GetBoundingRect() const; 132 virtual void SetBoundingRect( const wxRect2DDouble &rect ); 133 134 // Get/Set Pens for Normal, Active, Selected drawing 135 // if these are not set it resorts to the defaults 136 wxGenericPen GetPen(wxPlotPen_Type colour_type) const; 137 void SetPen(wxPlotPen_Type colour_type, const wxGenericPen &pen); 138 139 // Get/Set Default Pens for Normal, Active, Selected drawing for all curves 140 // these are the pens that are used when a wxPlotCurve/Function/Data is created 141 // default: Normal(0,0,0,1,wxSOLID), Active(0,0,255,1,wxSOLID), Selected(255,0,0,1,wxSOLID) 142 static wxGenericPen GetDefaultPen(wxPlotPen_Type colour_type); 143 static void SetDefaultPen(wxPlotPen_Type colour_type, const wxGenericPen &pen); 144 145 //------------------------------------------------------------------------- 146 // Get/Set Option names/values 147 //------------------------------------------------------------------------- 148 149 // Get the number of options set 150 size_t GetOptionCount() const; 151 // return the index of the option or wxNOT_FOUND (-1) 152 int HasOption(const wxString& name) const; 153 // Get the name/value at the index position 154 wxString GetOptionName( size_t index ) const; 155 wxString GetOptionValue( size_t index ) const; 156 // Set an option, if update=true then force it, else only set it if not found 157 // returns the index of the option 158 int SetOption(const wxString& name, const wxString& value, bool update=true); 159 int SetOption(const wxString& name, int option, bool update=true); 160 // Get an option returns the index if found 161 // returns wxNOT_FOUND (-1) if it doesn't exist and value isn't changed 162 int GetOption(const wxString& name, wxString& value) const; 163 // returns wxEmptyString if not found 164 wxString GetOption(const wxString& name) const; 165 // returns 0 if not found 166 int GetOptionInt(const wxString& name) const; 167 // get the arrays of option values 168 wxArrayString GetOptionNames() const; 169 wxArrayString GetOptionValues() const; 170 171 //------------------------------------------------------------------------- 172 // Get/Set the ClientData in the ref data - see wxClientDataContainer 173 // You can store any extra info here. 174 //------------------------------------------------------------------------- 175 176 void SetClientObject( wxClientData *data ); 177 wxClientData *GetClientObject() const; 178 179 void SetClientData( void *data ); 180 void *GetClientData() const; 181 182 //------------------------------------------------------------------------- 183 // operators 184 bool operator == (const wxPlotCurve& plotCurve) const 185 { return m_refData == plotCurve.m_refData; } 186 bool operator != (const wxPlotCurve& plotCurve) const 187 { return m_refData != plotCurve.m_refData; } 188 189 wxPlotCurve& operator = (const wxPlotCurve& plotCurve) 190 { 191 if ( (*this) != plotCurve ) 192 Ref(plotCurve); 193 return *this; 194 } 195 196 private : 197 // ref counting code 198 virtual wxObjectRefData *CreateRefData() const; 199 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const; 200 201 DECLARE_DYNAMIC_CLASS(wxPlotCurve); 202 }; 203 204 #endif // _WX_PLOTCURVE_H_ 205