Main Page | Class Hierarchy | Class List | Directories | File List | Class Members

FXCurve.h

00001 /*******************************************************************************
00002 * Copyright (C) 2003-2005 by Rafael de Pelegrini Soares.   All Rights Reserved.
00003 ********************************************************************************
00004 * This library is free software; you can redistribute it and/or
00005 * modify it under the terms of the GNU Lesser General Public
00006 * License as published by the Free Software Foundation; either
00007 * version 2.1 of the License, or (at your option) any later version.
00008 *
00009 * This library is distributed in the hope that it will be useful,
00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00012 * Lesser General Public License for more details.
00013 *
00014 * You should have received a copy of the GNU Lesser General Public
00015 * License along with this library; if not, write to the Free Software
00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
00017 ********************************************************************************
00018 * $Id: FXCurve.h,v 1.4 2006/01/17 22:06:18 rpseng Exp $
00019 ********************************************************************************/
00020 
00021 
00022 #ifndef __FXCURVE_H
00023 #define __FXCURVE_H
00024 
00025 
00026 #include <vector>
00027 
00028 // forward declaration of plot
00029 class FXPlot2D;
00030 class FXAxis;
00031 
00034 class FXCurveData {
00035 protected:
00037         double *data;
00038 
00040         FXbool del;
00041 
00043         FXint len;
00044 
00046         FXdouble max;
00048         FXdouble min;
00049         
00050 public:
00052         enum DataType{
00053                 SharedData = 0, 
00054                 SharedDelete, 
00055                 CopyData, 
00056         };
00057 
00064         FXCurveData(double *data, FXint len, DataType type = CopyData){
00065                 this->data = NULL;
00066                 this->len = 0;
00067                 this->del = false;
00068                 setData(data, len, type);
00069         }
00070 
00072         void clear(){
00073                 if(del)
00074                         delete []data;
00075                 data = NULL;
00076                 len = 0;
00077                 del = false;
00078         }
00079 
00081         void setData(double *data, FXint len, DataType type){
00082                 clear();
00083                 del = false;
00084                 this->len = len;
00085                 switch(type){
00086                         case SharedDelete:
00087                                 del = true;
00088                         case SharedData:
00089                                 this->data = data;
00090                                 break;
00091                         case CopyData:
00092                         default:
00093                                 del = true;
00094                                 this->data = new double[len];
00095                                 memcpy(this->data, data, sizeof(double)*len);
00096                 }
00097 
00099                 min = HUGE_VAL;
00100                 max = -min;
00101                 FXint i; double *di;
00102                 for(i=0, di = data; i<len; ++i, ++di){
00103                         if(*di < min) min = *di;
00104                         if(*di > max) max = *di;
00105                 }
00106         };
00108         virtual ~FXCurveData(){
00109                 clear();
00110         }
00111 
00113         const double& at(FXint i) const {
00114                 return data[i];
00115         }
00117         double& at(FXint i) {
00118                 return data[i];
00119         }
00120 
00122         FXint length() const {
00123                 return len;
00124         };
00125 
00127         double getMax() const {
00128                 return max;
00129         }
00130 
00132         double getMin() const {
00133                 return min;
00134         }
00135 };
00136 
00137 
00141 class FXCurve
00142 {
00143 public:
00147         enum CurveStyle {
00148                 Lines = 0,
00149                 Steps,
00150                 //Sticks,
00151                 //Spline,
00152                 NoCurve,
00153         };
00154 
00156         enum MarkStyle{
00157                 Square = 0,
00158                 Circle,
00159                 Triangle,
00160                 TriangleInv,
00161                 X,
00162                 NoMark,
00163         };
00164 protected:
00166         FXString label;
00167 
00169         FXPlot2D *plot;
00170 
00172         FXAxis *axisx;
00174         FXAxis *axisy;
00175 
00177         FXCurveData *datax;
00179         FXCurveData *datay;
00181         std::vector<FXPoint> points;
00182 
00184         MarkStyle mark;
00186         FXint marksize;
00188         FXColor markcolor;
00190         FXPlotPen pen;
00192         CurveStyle style;
00193 
00195         FXbool calculated;
00196 
00197 public:
00199         void loadDefault(FXuint width, FXuint counter);
00200 
00205         void setAxis(FXAxis *x, FXAxis *y);
00206 
00212         void drawSample(FXDC *p, FXint x, FXint y, FXbool line = false) const;
00213         
00215         void setLabel(FXString curveName);
00216         
00218         virtual void drawSelf(FXDC *dc, FXint rootx, FXint rooty);
00219 
00221         const FXCurveData* getDataX(void){
00222                 return datax;
00223         }
00225         const FXCurveData* getDataY(void){
00226                 return datay;
00227         }
00229         void setView(FXPlot2D *view);
00231         const FXPlotPen& getPen(void) const {
00232                 return pen;
00233         }
00234 
00236         CurveStyle getStyle() const {
00237                 return style;
00238         }
00240         void setStyle(CurveStyle style) {
00241                 this->style = style;
00242         }
00243 
00245         enum MarkStyle getMarkStyle(void) const{
00246                 return mark;
00247         }
00249         FXint getMarkSize(void) const{
00250                 return marksize;
00251         }
00253         FXColor getMarkColor(void) const {
00254                 return markcolor;
00255         }
00256 
00258         void setPen(const FXPlotPen &pen){
00259                 this->pen = pen;
00260         }
00262         void setMarkSize(FXint size){
00263                 marksize = size;
00264         }
00266         void setMarkStyle(MarkStyle m){
00267                 mark = m;
00268         }
00269 
00271         void setMarkColor(FXColor color){
00272                 markcolor = color;
00273         }
00274 
00278         void update(){
00279                 calculated = false;
00280         }
00281 
00287         FXCurve(const FXString &label, FXCurveData *x, FXCurveData *y,
00288                 CurveStyle style = Lines, FXPlot2D *view = NULL);
00289 
00291         virtual ~FXCurve();
00292 
00294         void calcule(FXint rootx, FXint rooty);
00295 
00297         FXString getLabel() const {
00298                 return label;
00299         }
00300 
00301 protected:
00302 
00307         virtual void drawSteps(FXDC *dc) const;
00308 
00315         virtual void drawMarks(FXDC *dc) const;
00316 
00318         virtual void drawMark(FXDC *dc, FXPoint p, MarkStyle style, FXint size,
00319                         FXColor color) const ;
00320 };
00321 
00322 #endif // __FXCURVE_H

Generated on Tue Jan 31 10:55:30 2006 for FXPlot by  doxygen 1.4.4