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 *p);
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) { 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         virtual void draw(QPainter *p, int w, int h) = 0;
00096         void sortPoints(QPointArray pa, int s, int e);
00097         void drawStyle(QPainter *p, Style *s, Symbol *symbol, QPointArray pa, int xmin, int xmax, int ymin, int ymax);
00098         void drawErrorBar(QPainter *p, QPointArray pa, QPointArray hpa, QPointArray vpa);
00099         bool inside(double x, double y) {
00100                 if(x>position.X() && x<position.X()+size.X() && y>position.Y() && y<position.Y()+size.Y())
00101                         return true;
00102                 else
00103                         return false;
00104         }
00105         bool insideLegend(int x,int y) { if (legend.inside(x,y)) return true; return false;}
00106         bool insidePlottingArea(double x,double y) {
00107                 if (x>p1.X() && x<p2.X() && y>p1.Y() && y<p2.Y()) return true; return false;
00108         }
00109         bool insideF1Corner(double x, double y) {
00110                 if(fabs(x-position.X()) < 0.01 && fabs(y-position.Y())<0.01)
00111                         return true;
00112                 return false;
00113         }
00114         bool insideF2Corner(double x, double y) {
00115                 if(fabs(x-position.X()-size.X()) < 0.01 && fabs(y-position.Y()-size.Y())<0.01)
00116                         return true;
00117                 return false;
00118         }
00119         bool insideB1Corner(double x, double y) {
00120                 if(fabs(x-position.X()) < 0.01 && fabs(y-position.Y()-size.Y())<0.01)
00121                         return true;
00122                 return false;
00123         }
00124         bool insideB2Corner(double x, double y) {
00125                 if(fabs(x-position.X()-size.X()) < 0.01 && fabs(y-position.Y())<0.01)
00126                         return true;
00127                 return false;
00128         }
00129         bool insideX1Border(double x, double y) {
00130                 if(x >position.X() && x<position.X()+size.X() && fabs(y-position.Y()-size.Y())<0.01)
00131                         return true;
00132                 return false;
00133         }
00134         bool insideX2Border(double x, double y) {
00135                 if(x >position.X() && x<position.X()+size.X() && fabs(y-position.Y())<0.01)
00136                         return true;
00137                 return false;
00138         }
00139         bool insideY1Border(double x, double y) {
00140                 if(y >position.Y() && y<position.Y()+size.Y() && fabs(x-position.X())<0.01)
00141                         return true;
00142                 return false;
00143         }
00144         bool insideY2Border(double x, double y) {
00145                 if(y >position.Y() && y<position.Y()+size.Y() && fabs(x-position.X()-size.X())<0.01)
00146                         return true;
00147                 return false;
00148         }
00149         bool insideCenter(double x, double y) {
00150                 if(fabs(x-position.X()-size.X()/2.0)<0.01 && fabs(y-position.Y()-size.Y()/2.0)<0.01)
00151                         return true;
00152                 return false;
00153         }
00154         void setPosition(Point p) { position = p; }
00155         void setPosition(double x, double y) { position = Point(x,y); }
00156         Point Position() { return position; }
00157         void setSize(Point s) { size = s; }
00158         void setSize(double x, double y) { size = Point(x,y); }
00159         Point Size() { return size; }
00160         void enableAspectRatio(bool a=true) { aspect_enabled=a; }
00161         bool AspectRatioEnabled() { return aspect_enabled; }
00162         QColor Background() { return bgcolor; }
00163         void setBackground(QColor c) { bgcolor = c; }
00164         void setBackground(QString c) { bgcolor = QColor(c); }
00165         QColor graphBackground() { return gbgcolor; }
00166         void setGraphBackground(QColor c) { gbgcolor = c;}
00167         void setGraphBackground(QString c) { gbgcolor = QColor(c);}
00168         void autoScaleX();
00169         void autoScaleY();
00170         void autoScaleZ();
00171         void autoScaleAll() { autoScaleX(); autoScaleY(); autoScaleZ(); }
00172         void setXRange(double x1, double x2) {actrange[0].setMin(x1); actrange[0].setMax(x2); }
00173         void setYRange(double y1, double y2) {actrange[1].setMin(y1); actrange[1].setMax(y2); }
00174         void setZRange(double z1, double z2) {actrange[2].setMin(z1); actrange[2].setMax(z2); }
00175 
00176         Point P1() { return p1;}
00177         Point P2() { return p2;}
00178         void setP1(Point p) { p1=p;}
00179         void setP2(Point p) { p2=p;}
00180         void setLeftPanel() { p1.setX(0.0); }
00181         void setRightPanel() { p2.setX(1.0); }
00182         void setTopPanel() { p1.setY(0.0); }
00183         void setBottomPanel() { p2.setY(1.0); }
00184         
00185         void setXMin(int xmin,int X) { p1.setPoint((xmin/(double)X-position.X())/size.X(),p1.Y()); }
00186         void setXMax(int xmax,int X) { p2.setPoint((xmax/(double)X-position.X())/size.X(),p2.Y()); }
00187         void setYMin(int ymin,int Y) { p1.setPoint(p1.X(),(ymin/(double)Y-position.Y())/size.Y()); }
00188         void setYMax(int ymax,int Y) { p2.setPoint(p2.X(),(ymax/(double)Y-position.Y())/size.Y()); }
00189 
00190         void shiftRight();
00191         void shiftLeft();
00192         void shiftUp();
00193         void shiftDown();
00194         void scaleXUp();
00195         void scaleXDown();
00196         void scaleYUp();
00197         void scaleYDown();
00198         void scaleZUp();
00199         void scaleZDown();
00200         void zoomIn();
00201         void zoomOut();
00202 
00203         Point dataValue(double x);
00204 protected:
00205         int autoTicks(double min, double max);  // calcuate tick number for auto ticks
00206         void readAxisSettings(Axis *a, int type, int item=0);   // read default settings for axis
00207 #ifdef HAVE_GL
00208         Qwt3D::ColorVector convertOldColormap(int index);
00209 #endif
00210         Worksheet *worksheet;                   // parent worksheet
00211         PType type;                             // type of the plot
00212         GraphList *graphlist;                   // list of graphs
00213         Point position, size;                           // position and size (0..1)
00214         bool aspect_enabled;                    // plot in aspect ratio
00215         Label *title;                                   // Title
00216         Legend legend;                          // Legend
00217         QColor bgcolor, gbgcolor;               // background & graph background color
00218         Point p1, p2;                                   // plotting area        (0..1)
00219         LRange range[3];                                // graph ranges (x,y,z)
00220         LRange actrange[3];                     // actual plotting range (x,y,z)
00221         double baseline;                                // baseline
00222         bool baseline_enabled;                  // draw it ?
00223         double xbaseline;                               // x baseline
00224         bool xbaseline_enabled;                 // draw it ?
00225         LRange *region;                         // region
00226         bool region_enabled;                    // draw it ?
00227         bool transparent;                               // draw bgcolor & gbgcolor ?
00228         int clipoffset;                                 // offset for clipping area drawing (Symbols->full drawn, line section->limited)
00229         bool marks_enabled;
00230         LRange *markx, *marky;                  // marker
00231         bool fill_enabled;                              // fill between curve fillg1 and fillg2 ?
00232         int filltype;                                   // 0-all, 1-higher, 2-lower, 3-region
00233         int fillg1, fillg2;
00234         QBrush fillbrush;                               // use brush for fill
00235 };
00236 
00237 #ifndef HAVE_LOG2
00238 inline double log2(double x) {return log(x)/log(2.0);}
00239 #endif
00240 
00241 #endif // PLOT_H

Generated on Sun Apr 2 02:05:09 2006 for LabPlot by  doxygen 1.4.4