Qucs-GUI
0.0.19
|
00001 /*************************************************************************** 00002 graph.h 00003 --------- 00004 begin : Thu Oct 2 2003 00005 copyright : (C) 2003 by Michael Margraf 00006 email : michael.margraf@alumni.tu-berlin.de 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef GRAPH_H 00019 #define GRAPH_H 00020 00021 00022 #include "marker.h" 00023 #include "element.h" 00024 00025 #include <cmath> 00026 #include <QColor> 00027 #include <Q3PtrList> 00028 #include <QDateTime> 00029 00030 #include <assert.h> 00031 00032 typedef enum{ 00033 GRAPHSTYLE_INVALID = -1, 00034 GRAPHSTYLE_SOLID = 0, 00035 GRAPHSTYLE_DASH, 00036 GRAPHSTYLE_DOT, 00037 GRAPHSTYLE_LONGDASH, 00038 GRAPHSTYLE_STAR, 00039 GRAPHSTYLE_CIRCLE, 00040 GRAPHSTYLE_ARROW, 00041 GRAPHSTYLE_COUNT, 00042 } graphstyle_t; 00043 00044 inline graphstyle_t toGraphStyle(int x){ 00045 if (x<0){ 00046 return GRAPHSTYLE_INVALID; 00047 }else if(x<GRAPHSTYLE_COUNT){ 00048 return graphstyle_t(x); 00049 }else{ 00050 return GRAPHSTYLE_INVALID; 00051 } 00052 } 00053 00054 class Diagram; 00055 class ViewPainter; 00056 00057 00058 struct DataX { 00059 DataX(const QString& Var_, double *Points_=0, int count_=0) 00060 : Var(Var_), Points(Points_), count(count_), Min(INFINITY), Max(-INFINITY) {}; 00061 ~DataX() { if(Points) delete[] Points; }; 00062 QString Var; 00063 double *Points; 00064 int count; 00065 00066 public: 00067 const double& min()const {return Min;} 00068 const double& max()const {return Max;} 00069 public: // only called from Graph. cleanup later. 00070 const double& min(const double& x){if (Min<x) Min=x; return Min;} 00071 const double& max(const double& x){if (Max>x) Max=x; return Max;} 00072 private: 00073 double Min; 00074 double Max; 00075 }; 00076 00077 struct Axis; 00078 00086 class Graph : public Element { 00087 public: 00088 Graph(const Diagram*, const QString& _Line=""); 00089 ~Graph(); 00090 00091 class ScrPt{ 00092 float ScrX; 00093 float ScrY; 00094 00095 double indep; // top level indep value (sweep) 00096 double dep; // top level dep value // FIXME: type?! 00097 public: 00098 ScrPt() : ScrX(0){} 00099 ~ScrPt(){} 00100 00101 void setStrokeEnd(); 00102 void setBranchEnd(); 00103 void setGraphEnd(); 00104 void setScrX(float); // screen horizontal coordinate 00105 void setScrY(float); // screen vertical coordinate 00106 void setScr(float,float); // both @ once. 00107 void setIndep(double); 00108 void setDep(double); 00109 // void attachCoords(double*); 00110 00111 bool isPt() const; // indicate if this is a point on the screen 00112 bool isStrokeEnd() const; 00113 bool isBranchEnd() const; 00114 bool isGraphEnd() const; 00115 00116 float getScrX() const; 00117 float getScrY() const; 00118 double getIndep() const; 00119 double getDep() const; 00120 }; 00121 typedef std::vector<ScrPt> container; 00122 typedef container::iterator iterator; 00123 typedef container::const_iterator const_iterator; 00124 00125 int loadDatFile(const QString& filename); 00126 int loadIndepVarData(const QString&, char* datfilecontent, DataX* where); 00127 00128 void paint(ViewPainter*, int, int); 00129 void paintLines(ViewPainter*, int, int); 00130 QString save(); 00131 bool load(const QString&); 00132 int getSelected(int, int); 00133 Graph* sameNewOne(); 00134 00135 private: // tmp hack 00136 DataX* mutable_axis(uint i) { if(i<(uint)cPointsX.size()) return cPointsX.at(i); return NULL;} 00137 public: 00138 unsigned numAxes() const { return cPointsX.size(); } 00139 DataX const* axis(uint i) const { if(i<(uint)cPointsX.size()) return cPointsX.at(i); return NULL;} 00140 size_t count(uint i) const { if(axis(i)) return axis(i)->count; return 0; } 00141 QString axisName(unsigned i) const {if(axis(i))return axis(i)->Var; return "";} 00142 bool isEmpty() const { return !cPointsX.size(); } 00143 QVector<DataX*>& mutable_axes(){return cPointsX;} // HACK 00144 00145 void clear(){ScrPoints.resize(0);} 00146 void resizeScrPoints(size_t s){assert(s>=ScrPoints.size()); ScrPoints.resize(s);} 00147 iterator begin(){return ScrPoints.begin();} 00148 iterator end(){return ScrPoints.end();} 00149 const_iterator begin() const{return ScrPoints.begin();} 00150 const_iterator end() const{return ScrPoints.end();} 00151 00152 QDateTime lastLoaded; // when it was loaded into memory 00153 int yAxisNo; // which y axis is used 00154 double *cPointsY; 00155 int countY; // number of curves 00156 QString Var; 00157 QColor Color; 00158 int Thick; 00159 graphstyle_t Style; 00160 QList<Marker *> Markers; 00161 00162 // for tabular diagram 00163 int Precision; // number of digits to show 00164 int numMode; // real/imag or polar (deg/rad) 00165 00166 private: // painting 00167 void drawLines(int, int, ViewPainter*) const; 00168 void drawStarSymbols(int, int, ViewPainter*) const; 00169 void drawCircleSymbols(int, int, ViewPainter*) const; 00170 void drawArrowSymbols(int, int, ViewPainter*) const; 00171 public: // marker related 00172 void createMarkerText() const; 00173 std::pair<double,double> findSample(std::vector<double>&) const; 00174 Diagram const* parentDiagram() const{return diagram;} 00175 private: 00176 QVector<DataX*> cPointsX; 00177 std::vector<ScrPt> ScrPoints; // data in screen coordinates 00178 Diagram const* diagram; 00179 }; 00180 00181 #endif 00182 00183 // vim:ts=8:sw=2:noet