00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef GLBASICGRAPH_H
00018 #define GLBASICGRAPH_H
00019
00020 #include <qgl.h>
00021
00022 #include "commongraph.h"
00023
00024 class QTimer;
00025
00026 #ifdef KDE_APP
00027 class KPrinter;
00028 #else
00029 class QPrinter;
00030 #endif
00031
00032 class GLGraphEvent;
00033
00038 class GLBasicGraph : public QGLWidget, public CommonGraph
00039 {
00040 Q_OBJECT
00041
00042 public:
00043 GLBasicGraph( QWidget *parent=0, const char *name=0 );
00044 virtual ~GLBasicGraph();
00045
00046 virtual void load_key( const char *key, const char *value );
00047
00048 int setRange(GLfloat xMin, GLfloat xMax, GLfloat yMin, GLfloat yMax, GLfloat zMin, GLfloat zMax);
00049 int setXMin(double);
00050 int setXMax(double);
00051 int setYMin(double);
00052 int setYMax(double);
00053 int setZMin(double);
00054 int setZMax(double);
00055 int setXMinView(double);
00056 int setXMaxView(double);
00057 int setYMinView(double);
00058 int setYMaxView(double);
00059 int setZMinView(double);
00060 int setZMaxView(double);
00061
00062 void setPolarEye(double);
00063 void setAzimuthalEye(double);
00064 GLfloat getXMin() const{return xMin;}
00065 GLfloat getXMax() const{return xMax;}
00066 GLfloat getYMin() const{return yMin;}
00067 GLfloat getYMax() const{return yMax;}
00068 GLfloat getZMin() const{return zMin;}
00069 GLfloat getZMax() const{return zMax;}
00070 GLfloat getXMinView() const{return xMinView;}
00071 GLfloat getXMaxView() const{return xMaxView;}
00072 GLfloat getYMinView() const{return yMinView;}
00073 GLfloat getYMaxView() const{return yMaxView;}
00074 GLfloat getZMinView() const{return zMinView;}
00075 GLfloat getZMaxView() const{return zMaxView;}
00076 GLfloat getPolarEye() const{return xRot;}
00077 GLfloat getAzimuthalEye() const{return zRot;}
00078
00079 QColor axisColor() const{return _axisColor;}
00080 QColor backgroundColor() const{return _backgroundColor;}
00081 QColor scaleColor() const{return _scaleColor;}
00082
00083 void setAxisColor(const QColor &c){_axisColor = c; updateGL();}
00084 void setBackgroundColor(const QColor &c){_backgroundColor = c; qglClearColor(_backgroundColor); updateGL();}
00085 void setScaleColor(const QColor &c){_scaleColor = c; updateGL();}
00086
00087 void setAxis(bool b){showAxis = b; updateGL();}
00088 void setScale(bool b){showScale = b; updateGL();}
00089 bool getAxisState() const{return showAxis;}
00090 bool getScaleState() const{return showScale;}
00091
00092 int getXZoomFactor() const{return xZoom;}
00093 int getYZoomFactor() const{return yZoom;}
00094 void setXZoomFactor(int i){xZoom = i;}
00095 void setYZoomFactor(int i){yZoom = i;}
00096
00097 void exportAsImage(const QString &,const QString &);
00098 void getPixmap(QPixmap &pm);
00099
00100 #ifdef KDE_APP
00101 virtual void print(KPrinter *);
00102 #else
00103 virtual void print(QPrinter *);
00104 #endif //KDE_APP
00105
00106 void autoRotateX(bool);
00107 void autoRotateY(bool);
00108 void autoRotateZ(bool);
00109
00110 bool isAutoRotatingX() const{ return rotating_x;}
00111 bool isAutoRotatingY() const{ return rotating_y;}
00112 bool isAutoRotatingZ() const{ return rotating_z;}
00113
00117 inline double getMouseX() const{return mouseX;}
00118
00122 inline double getMouseY() const{return mouseY;}
00123
00124 inline virtual void setSnapToGrid(bool b){snapToGrid = b;}
00125 inline virtual bool isSnapToGrid() const{return snapToGrid;}
00126
00127
00128
00129 public slots:
00130 void zoomIn();
00131 void zoomOut();
00132 void zoomStd();
00133
00134 signals:
00135 void graphRotated( const GLGraphEvent & );
00136 void dimensionsChanged( const GLGraphEvent & );
00137 void activeCoordinateChanged( const QString &, const QString &, const QString & );
00138 void infoMessageReady( const QString & );
00139 void rotateCanceled();
00140
00141 protected:
00142 void initializeGL();
00143 void resizeGL( int w, int h );
00144 void paintGL();
00145
00146 void mousePressEvent(QMouseEvent *);
00147 void mouseMoveEvent(QMouseEvent *);
00148 void mouseReleaseEvent(QMouseEvent *);
00149
00150 void emitGraphRotated();
00151 void emitDimensionsChanged();
00152
00153 void drawText(GLfloat x, GLfloat y, GLfloat z, const char * s);
00154
00155 void updateOrtho();
00156 void updateView();
00157 virtual void orthoChanged(){}
00158
00159 double toGraphXCoord(double);
00160 double toGraphYCoord(double);
00161
00166 void setMouseX(double x_coordiniate,bool snapToGrid=true);
00167
00172 void setMouseY(double y_coordiniate,bool snapToGrid=true);
00173
00174 virtual double snapIntervalX() const = 0;
00175 virtual double snapIntervalY() const = 0;
00176 inline virtual double startSnap() const{return 0;}
00177
00178 GLfloat _height, _width;
00179
00180 private:
00181 void drawAxis();
00182
00183
00184 void drawLetterMinus(double pos_x, double pos_y, double pos_z, double width);
00185 void drawLetterPlus(double pos_x, double pos_y, double pos_z, double height, double width);
00186 void drawLetterX(double pos_x, double pos_y, double pos_z, double height, double width);
00187 void drawLetterY(double pos_x, double pos_y, double pos_z, double height, double width);
00188 void drawLetterZ(double pos_x, double pos_y, double pos_z, double height, double width);
00189
00190 bool showAxis,showScale;
00191 GLfloat xMin,xMax,yMin,yMax,zMin,zMax;
00192 GLfloat xMinView, xMaxView, yMinView, yMaxView, zMinView, zMaxView;
00193 GLfloat xRot,yRot,zRot;
00194 QPoint *lastClick,*origin;
00195 double xScale,yScale, mouseX, mouseY;
00196 bool mouseDown, snapToGrid;
00197 QColor _scaleColor,_axisColor,_backgroundColor;
00198 int xZoom,yZoom,zZoom;
00199
00200 QTimer *rotate_timer;
00201 bool rotating_z, rotating_y, rotating_x;
00202 int rotate_speed;
00203
00204 private slots:
00205 void autoRotateStep();
00206 };
00207
00208 #endif // GLBASICGRAPH_H