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

Plot.h

Go to the documentation of this file.
00001 //LabPlot : Plot.h
00002 
00003 #ifndef PLOT_H
00004 #define PLOT_H
00005 
00006 #include <math.h>
00007 #include "Worksheet.h"
00008 #include "Legend.h"
00009 #include "Label.h"
00010 #include "Axis.h"
00011 
00012 #ifdef HAVE_GL
00013 #include "qwt3d_surfaceplot.h"
00014 #endif
00015 
00016 class Legend;
00017 
00018 class Plot {
00019 public:
00020         Plot(class Worksheet *w);
00021         virtual ~Plot() {}
00022         GraphList *getGraphList() { return graphlist; }
00023         void clear() {graphlist->clear();}
00024         void save(QTextStream *t);
00025         void open(QTextStream *t, int version);
00026         QDomElement savePlotXML(QDomDocument doc);
00027         void openPlotXML(QDomNode node);
00028         virtual void saveXML(QDomDocument doc, QDomElement plottag) = 0;
00029         virtual void openXML(QDomElement e) = 0;
00030         virtual void saveAxes(QTextStream *t) = 0;
00031         virtual void openAxes(QTextStream *t, int version) = 0;
00032         void saveAxis(QTextStream *t,Axis *axis);
00033         void openAxis(QTextStream *t,int version, Axis *axis);
00034 
00035         QString TicLabel(int atlf, int prec, QString dtf, double value);
00036         double TicLabelValue(int atlf, QString string);
00037 
00038         virtual Axis *getAxis(int i) = 0;
00039         Legend* getLegend() { return &legend; }
00040         void setType(PType i) { type = i; }
00041         PType Type() { return type; }
00042         Label* Title() { return title; }
00043         virtual void setRange(LRange *,int i) = 0;
00044         LRange* Range(int i) { return &range[i];}
00045         virtual void setActRange(LRange *,int i) = 0;
00046         LRange* ActRange(int i) { return &actrange[i];}
00047         virtual void setRanges(LRange *) = 0;
00048         LRange* Ranges() { return range;}
00049         virtual void setActRanges(LRange *) = 0;
00050         LRange* ActRanges() { return actrange;}
00051         void setRegionMin(double min) {region->setMin(min);}
00052         void setRegionMax(double max) {region->setMax(max);}
00053         void setRegion(double min, double max) {region->setMin(min); region->setMax(max);}
00054         void setRegion(LRange *r) {region->setMin(r->rMin()); region->setMax(r->rMax());}
00055         double RegionMin() {return region->rMin();}
00056         double RegionMax() {return region->rMax();}
00057         LRange *Region() { return region; }
00058         bool regionEnabled() { return region_enabled; }
00059         void enableRegion(bool e=true) { region_enabled = e; }
00060         void setRegionEnabled(bool e=true) { enableRegion(e); }
00061         void setTransparent(bool t=true) { transparent = t; }
00062         bool Transparent() { return transparent; }
00063         void setClipOffset(int c) { clipoffset=c;}
00064         int ClipOffset() { return clipoffset;}
00065 
00066         bool BaselineEnabled() { return baseline_enabled; }
00067         void enableBaseline(bool e=true) { baseline_enabled = e; }
00068         void setBaselineEnabled(bool e=true) { enableBaseline(e); }
00069         double Baseline() { return baseline; }
00070         void setBaseline(double b) { baseline = b; }
00071         double XBaseline() { return xbaseline; }
00072         void setXBaseline(double b) { xbaseline = b; }
00073         bool XBaselineEnabled() { return xbaseline_enabled; }
00074         void enableXBaseline(bool e=true) { baseline_enabled = e; }
00075         void setXBaselineEnabled(bool e=true) { enableXBaseline(e); }
00076 
00077         bool marksEnabled() { return marks_enabled; }                   // marker
00078         void enableMarks(bool m=true) { marks_enabled=m; }
00079         void setMarksEnabled(bool m=true) { enableMarks(m); }
00080         LRange *markX() { return markx; }
00081         void setMarkX(LRange *l) { markx=l; }
00082         LRange *markY() { return marky; }
00083         void setMarkY(LRange *l) { marky=l; }
00084         void setFill(bool f=true) { fill_enabled=f; }                           // fill
00085         bool Fill() { return fill_enabled; }            
00086         void setFillType(int t) { filltype=t; }
00087         int  FillType() { return filltype; }
00088         void setFillG1(int f) { fillg1=f; }
00089         int FillG1() { return fillg1; }
00090         void setFillG2(int f) { fillg2=f; }
00091         int FillG2() { return fillg2; }
00092         void setFillBrush(QBrush b) { fillbrush=b; }
00093         QBrush FillBrush() { return fillbrush; }
00094 
00095         void setDataModeGraph(int i) { datamodegraph=i; }
00096         int DataModeGraph() { return datamodegraph; }
00097 
00098         virtual void draw(QPainter *p, int w, int h) = 0;
00099         void sortPoints(QPointArray pa, int s, int e);
00100         void drawStyle(QPainter *p, Style *s, Symbol *symbol, QPointArray pa, int xmin, int xmax, int ymin, int ymax);
00101 //      void drawErrorBar(QPainter *p, QPointArray pa, QPointArray hpa, QPointArray vpa);       // TODO : Errorbar ebar
00102         bool inside(double x, double y) {
00103                 if(x>position.X() && x<position.X()+size.X() && y>position.Y() && y<position.Y()+size.Y())
00104                         return true;
00105                 else
00106                         return false;
00107         }
00108         bool insideLegend(int x,int y) { if (legend.inside(x,y)) return true; return false;}
00109         bool insidePlottingArea(double x,double y) {
00110                 if (x>p1.X() && x<p2.X() && y>p1.Y() && y<p2.Y()) return true; return false;
00111         }
00112         bool insideF1Corner(double x, double y) {
00113                 if(fabs(x-position.X()) < 0.01 && fabs(y-position.Y())<0.01)
00114                         return true;
00115                 return false;
00116         }
00117         bool insideF2Corner(double x, double y) {
00118                 if(fabs(x-position.X()-size.X()) < 0.01 && fabs(y-position.Y()-size.Y())<0.01)
00119                         return true;
00120                 return false;
00121         }
00122         bool insideB1Corner(double x, double y) {
00123                 if(fabs(x-position.X()) < 0.01 && fabs(y-position.Y()-size.Y())<0.01)
00124                         return true;
00125                 return false;
00126         }
00127         bool insideB2Corner(double x, double y) {
00128                 if(fabs(x-position.X()-size.X()) < 0.01 && fabs(y-position.Y())<0.01)
00129                         return true;
00130                 return false;
00131         }
00132         bool insideX1Border(double x, double y) {
00133                 if(x >position.X() && x<position.X()+size.X() && fabs(y-position.Y()-size.Y())<0.01)
00134                         return true;
00135                 return false;
00136         }
00137         bool insideX2Border(double x, double y) {
00138                 if(x >position.X() && x<position.X()+size.X() && fabs(y-position.Y())<0.01)
00139                         return true;
00140                 return false;
00141         }
00142         bool insideY1Border(double x, double y) {
00143                 if(y >position.Y() && y<position.Y()+size.Y() && fabs(x-position.X())<0.01)
00144                         return true;
00145                 return false;
00146         }
00147         bool insideY2Border(double x, double y) {
00148                 if(y >position.Y() && y<position.Y()+size.Y() && fabs(x-position.X()-size.X())<0.01)
00149                         return true;
00150                 return false;
00151         }
00152         bool insideCenter(double x, double y) {
00153                 if(fabs(x-position.X()-size.X()/2.0)<0.01 && fabs(y-position.Y()-size.Y()/2.0)<0.01)
00154                         return true;
00155                 return false;
00156         }
00157         void setPosition(Point p) { position = p; }
00158         void setPosition(double x, double y) { position = Point(x,y); }
00159         Point Position() { return position; }
00160         void setSize(Point s) { size = s; }
00161         void setSize(double x, double y) { size = Point(x,y); }
00162         Point Size() { return size; }
00163         void enableAspectRatio(bool a=true) { aspect_enabled=a; }
00164         bool AspectRatioEnabled() { return aspect_enabled; }
00165         QBrush Background() { return bgcolor; }
00166         void setBackground(QBrush c) { bgcolor = c; }
00167         void setBackground(QString c) { setBackground(QBrush(QColor(c))); }
00168         QBrush graphBackground() { return gbgcolor; }
00169         void setGraphBackground(QBrush c) { gbgcolor = c;}
00170         void setGraphBackground(QString c) { setGraphBackground(QBrush(QColor(c)));}
00171         void autoScaleX();
00172         void autoScaleY();
00173         void autoScaleZ();
00174         void autoScaleAll() { autoScaleX(); autoScaleY(); autoScaleZ(); }
00175         void setXRange(double x1, double x2) {actrange[0].setMin(x1); actrange[0].setMax(x2); }
00176         void setYRange(double y1, double y2) {actrange[1].setMin(y1); actrange[1].setMax(y2); }
00177         void setZRange(double z1, double z2) {actrange[2].setMin(z1); actrange[2].setMax(z2); }
00178 
00179         Point P1() { return p1;}
00180         Point P2() { return p2;}
00181         void setP1(Point p) { p1=p;}
00182         void setP2(Point p) { p2=p;}
00183         void setLeftPanel() { p1.setX(0.0); }
00184         void setRightPanel() { p2.setX(1.0); }
00185         void setTopPanel() { p1.setY(0.0); }
00186         void setBottomPanel() { p2.setY(1.0); }
00187         
00188         void setXMin(int xmin,int X) { p1.setPoint((xmin/(double)X-position.X())/size.X(),p1.Y()); }
00189         void setXMax(int xmax,int X) { p2.setPoint((xmax/(double)X-position.X())/size.X(),p2.Y()); }
00190         void setYMin(int ymin,int Y) { p1.setPoint(p1.X(),(ymin/(double)Y-position.Y())/size.Y()); }
00191         void setYMax(int ymax,int Y) { p2.setPoint(p2.X(),(ymax/(double)Y-position.Y())/size.Y()); }
00192 
00193         void shiftRight();
00194         void shiftLeft();
00195         void shiftUp();
00196         void shiftDown();
00197         void scaleXUp();
00198         void scaleXDown();
00199         void scaleYUp();
00200         void scaleYDown();
00201         void scaleZUp();
00202         void scaleZDown();
00203         void zoomIn();
00204         void zoomOut();
00205 
00206         Point dataValue(double x);
00207 protected:
00208         int autoTicks(double min, double max);  // calcuate tick number for auto ticks
00209         void readAxisSettings(Axis *a, int type, int item=0);   // read default settings for axis
00210 #ifdef HAVE_GL
00211         Qwt3D::ColorVector convertOldColormap(int index);
00212 #endif
00213         Worksheet *worksheet;                   // parent worksheet
00214         PType type;                             // type of the plot
00215         GraphList *graphlist;                   // list of graphs
00216         Point position, size;                           // position and size (0..1)
00217         bool aspect_enabled;                    // plot in aspect ratio
00218         Label *title;                                   // Title
00219         Legend legend;                          // Legend
00220         QBrush bgcolor, gbgcolor;               // background & graph background color/brush
00221         Point p1, p2;                                   // plotting area        (0..1)
00222         LRange range[3];                                // graph ranges (x,y,z)
00223         LRange actrange[3];                     // actual plotting range (x,y,z)
00224         double baseline;                                // baseline
00225         bool baseline_enabled;                  // draw it ?
00226         double xbaseline;                               // x baseline
00227         bool xbaseline_enabled;                 // draw it ?
00228         LRange *region;                         // region
00229         bool region_enabled;                    // draw it ?
00230         bool transparent;                               // draw bgcolor & gbgcolor ?
00231         int clipoffset;                                 // offset for clipping area drawing (Symbols->full drawn, line section->limited)
00232         bool marks_enabled;
00233         LRange *markx, *marky;                  // marker
00234         bool fill_enabled;                              // fill between curve fillg1 and fillg2 ?
00235         int filltype;                                   // 0-all, 1-higher, 2-lower, 3-region
00236         int fillg1, fillg2;
00237         QBrush fillbrush;                               // use brush for fill
00238         int datamodegraph;                      // graph number for data mode
00239 };
00240 
00241 #ifndef HAVE_LOG2
00242 inline double log2(double x) {return log(x)/log(2.0);}
00243 #endif
00244 
00245 #endif // PLOT_H

Generated on Sat Oct 13 21:55:01 2007 for LabPlot by  doxygen 1.4.4