00001
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 class Plot {
00013 public:
00014 Plot(class Worksheet *p);
00015 virtual ~Plot() {}
00016 GraphList *getGraphList() { return graphlist; }
00017 void clear() {graphlist->clear();}
00018 void save(QTextStream *t);
00019 virtual void saveAxes(QTextStream *t) = 0;
00020 void saveAxis(QTextStream *t,Axis *axis,int gridenabled, int borderenabled, int minorgridenabled);
00021 void open(QTextStream *t, int version);
00022 void openAxis(QTextStream *t,int version, Axis *axis,bool *gridenabled,bool *borderenabled, bool *minorgridenabled);
00023 virtual void openAxes(QTextStream *t, int version) = 0;
00024
00025 QString TicLabel(int axisnr, int atlf, int prec, QString dtf, double value);
00026
00027 virtual Axis *getAxis(int i) = 0;
00028 class Legend* getLegend() { return &legend; }
00029 void setType(PType i) { type = i; }
00030 PType Type() { return type; }
00031 Label* Title() { return title; }
00032 virtual void setRanges(LRange *) = 0;
00033 LRange* Ranges() { return range;}
00034 virtual void setActRanges(LRange *) = 0;
00035 LRange* ActRanges() { return actrange;}
00036 void setRegionMin(double min) {region.setMin(min);}
00037 void setRegionMax(double max) {region.setMax(max);}
00038 double RegionMin() {return region.rMin();}
00039 double RegionMax() {return region.rMax();}
00040 bool regionEnabled() { return region_enabled; }
00041 void setRegionEnabled(bool e) { region_enabled = e; }
00042 void setTransparent(bool t) { transparent = t; }
00043 bool Transparent() { return transparent; }
00044 void setClipOffset(int c) { clipoffset=c;}
00045 int ClipOffset() { return clipoffset;}
00046
00047 virtual void enableGrid(int index,bool b) = 0;
00048 virtual bool gridEnabled(int index) = 0;
00049 virtual void enableBorder(int index,bool b) = 0;
00050 virtual bool borderEnabled(int index) = 0;
00051 bool baselineEnabled() { return baseline_enabled; }
00052 double Baseline() { return baseline; }
00053 void setBaselineEnabled(bool e) { baseline_enabled = e; }
00054 void setBaseline(double b) { baseline = b; }
00055
00056 virtual void draw(QPainter *p, int w, int h) = 0;
00057 void drawStyle(QPainter *p, Style s, int oldx, int oldy,int x,int y, int xmin, int xmax, int ymin, int ymax);
00058 void drawErrorBar(QPainter *p, int x, int y, int xleft, int xright, int ytop, int ybottom);
00059 virtual void setBorder(int,bool) = 0;
00060 bool inside(double x, double y) {
00061 if(x>position.X() && x<position.X()+size.X() && y>position.Y() && y<position.Y()+size.Y())
00062 return true;
00063 else
00064 return false;
00065 }
00066 bool insideLegend(int x,int y) { if (legend.inside(x,y)) return true; return false;}
00067 bool insidePlottingArea(double x,double y) {
00068 if (x>p1.X() && x<p2.X() && y>p1.Y() && y<p2.Y()) return true; return false;
00069 }
00070 bool insideF1Corner(double x, double y) {
00071 if(fabs(x-position.X()) < 0.01 && fabs(y-position.Y())<0.01)
00072 return true;
00073 return false;
00074 }
00075 bool insideF2Corner(double x, double y) {
00076 if(fabs(x-position.X()-size.X()) < 0.01 && fabs(y-position.Y()-size.Y())<0.01)
00077 return true;
00078 return false;
00079 }
00080 bool insideB1Corner(double x, double y) {
00081 if(fabs(x-position.X()) < 0.01 && fabs(y-position.Y()-size.Y())<0.01)
00082 return true;
00083 return false;
00084 }
00085 bool insideB2Corner(double x, double y) {
00086 if(fabs(x-position.X()-size.X()) < 0.01 && fabs(y-position.Y())<0.01)
00087 return true;
00088 return false;
00089 }
00090 bool insideX1Border(double x, double y) {
00091 if(x >position.X() && x<position.X()+size.X() && fabs(y-position.Y()-size.Y())<0.01)
00092 return true;
00093 return false;
00094 }
00095 bool insideX2Border(double x, double y) {
00096 if(x >position.X() && x<position.X()+size.X() && fabs(y-position.Y())<0.01)
00097 return true;
00098 return false;
00099 }
00100 bool insideY1Border(double x, double y) {
00101 if(y >position.Y() && y<position.Y()+size.Y() && fabs(x-position.X())<0.01)
00102 return true;
00103 return false;
00104 }
00105 bool insideY2Border(double x, double y) {
00106 if(y >position.Y() && y<position.Y()+size.Y() && fabs(x-position.X()-size.X())<0.01)
00107 return true;
00108 return false;
00109 }
00110 bool insideCenter(double x, double y) {
00111 if(fabs(x-position.X()-size.X()/2.0)<0.01 && fabs(y-position.Y()-size.Y()/2.0)<0.01)
00112 return true;
00113 return false;
00114 }
00115 void setPosition(Point p) { position = p; }
00116 void setPosition(double x, double y) { position = Point(x,y); }
00117 Point Position() { return position; }
00118 void setSize(Point s) { size = s; }
00119 void setSize(double x, double y) { size = Point(x,y); }
00120 Point Size() { return size; }
00121 void setBackground(QColor c) { bgcolor = c; }
00122 QColor Background() { return bgcolor; }
00123 void setGraphBackground(QColor c) { gbgcolor = c;}
00124 QColor graphBackground() { return gbgcolor; }
00125 void autoScaleX() {actrange[0].setMin(range[0].rMin());actrange[0].setMax(range[0].rMax());}
00126 void autoScaleY() {actrange[1].setMin(range[1].rMin());actrange[1].setMax(range[1].rMax());}
00127 void autoScaleZ() {actrange[2].setMin(range[2].rMin());actrange[2].setMax(range[2].rMax());}
00128 void setXRange(double x1, double x2) {actrange[0].setMin(x1); actrange[0].setMax(x2); }
00129 void setYRange(double y1, double y2) {actrange[1].setMin(y1); actrange[1].setMax(y2); }
00130 void setZRange(double z1, double z2) {actrange[2].setMin(z1); actrange[2].setMax(z2); }
00131
00132 Point P1() { return p1;}
00133 Point P2() { return p2;}
00134 void setP1(Point p) { p1=p;}
00135 void setP2(Point p) { p2=p;}
00136
00137 void setXMin(int xmin,int X) { p1.setPoint((xmin/(double)X-position.X())/size.X(),p1.Y()); }
00138 void setXMax(int xmax,int X) { p2.setPoint((xmax/(double)X-position.X())/size.X(),p2.Y()); }
00139 void setYMin(int ymin,int Y) { p1.setPoint(p1.X(),(ymin/(double)Y-position.Y())/size.Y()); }
00140 void setYMax(int ymax,int Y) { p2.setPoint(p2.X(),(ymax/(double)Y-position.Y())/size.Y()); }
00141
00142 void shiftRight() {double x1=actrange[0].rMin(), x2=actrange[0].rMax();
00143 actrange[0].setMin(x1-fabs(x2-x1)/3.0);actrange[0].setMax(x2-fabs(x2-x1)/3.0);}
00144 void shiftLeft() {double x1=actrange[0].rMin(), x2=actrange[0].rMax();
00145 actrange[0].setMin(x1+fabs(x2-x1)/3.0);actrange[0].setMax(x2+fabs(x2-x1)/3.0);}
00146 void shiftUp() {double y1=actrange[1].rMin(), y2=actrange[1].rMax();
00147 actrange[1].setMin(y1-fabs(y2-y1)/3.0);actrange[1].setMax(y2-fabs(y2-y1)/3.0);}
00148 void shiftDown() {double y1=actrange[1].rMin(), y2=actrange[1].rMax();
00149 actrange[1].setMin(y1+fabs(y2-y1)/3.0);actrange[1].setMax(y2+fabs(y2-y1)/3.0);}
00150 void scaleXUp() {double x1=actrange[0].rMin(), x2=actrange[0].rMax();
00151 actrange[0].setMin(x1+fabs(x2-x1)/4.0);actrange[0].setMax(x2-fabs(x2-x1)/4.0);}
00152 void scaleXDown() {double x1=actrange[0].rMin(), x2=actrange[0].rMax();
00153 actrange[0].setMin(x1-fabs(x2-x1)/4.0);actrange[0].setMax(x2+fabs(x2-x1)/4.0);}
00154 void scaleYUp() {double y1=actrange[1].rMin(), y2=actrange[1].rMax();
00155 actrange[1].setMin(y1+fabs(y2-y1)/4.0);actrange[1].setMax(y2-fabs(y2-y1)/4.0);}
00156 void scaleYDown() {double y1=actrange[1].rMin(), y2=actrange[1].rMax();
00157 actrange[1].setMin(y1-fabs(y2-y1)/4.0);actrange[1].setMax(y2+fabs(y2-y1)/4.0);}
00158 void scaleZUp() {double z1=actrange[2].rMin(), z2=actrange[2].rMax();
00159 actrange[2].setMin(z1+fabs(z2-z1)/4.0);actrange[2].setMax(z2-fabs(z2-z1)/4.0);}
00160 void scaleZDown() {double z1=actrange[2].rMin(), z2=actrange[2].rMax();
00161 actrange[2].setMin(z1-fabs(z2-z1)/4.0);actrange[2].setMax(z2+fabs(z2-z1)/4.0);}
00162 protected:
00163 Worksheet *worksheet;
00164 PType type;
00165 GraphList *graphlist;
00166 Point position, size;
00167 Label *title;
00168 Legend legend;
00169 QColor bgcolor, gbgcolor;
00170 Point p1, p2;
00171 LRange range[3];
00172 LRange actrange[3];
00173 double baseline;
00174 bool baseline_enabled;
00175 LRange region;
00176 bool region_enabled;
00177 bool transparent;
00178 int clipoffset;
00179 };
00180
00181 #ifndef HAVE_LOG2
00182 inline double log2(double x) {return log(x)/log(2.0);}
00183 #endif
00184
00185 #endif // PLOT_H