Home

Download

Features

Screenshots

Handbook

Browse Source

Authors

SourceForge.net Logo
Hosted by SourceForge.net

OSI Certified


Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   Related Pages   Search  

glexpressiongraph.h

00001 /***************************************************************************
00002                           glexpressiongraph.h  -  description
00003                              -------------------
00004     begin                : Fri Oct 18 2002
00005     copyright            : (C) 2002 by Fungmeista
00006     email                : mizunoami44@users.sourceforge.net
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 GLEXPRESSIONGRAPH_H
00019 #define GLEXPRESSIONGRAPH_H
00020 
00021 #include <vector>
00022 #include <fstream>
00023 
00024 #include "expression.h"
00025 #include "cartesian3dcoord.h"
00026 
00027 #include "glbasicgraph.h"
00028 #include "animator.h"
00029 
00030 class FungParser;
00031 
00037 class GLExpressionGraph : public GLBasicGraph, public Animator
00038 {
00039     Q_OBJECT
00040 
00041     public:
00042         GLExpressionGraph(QWidget *parent=0, const char *name=0);
00043         ~GLExpressionGraph();
00044 
00045         typedef std::vector< std::vector<Cartesian3DCoord> > Cartesian3DCoord2DVector;
00046 
00047         virtual void load_key( const char *key, const char *value );
00048 
00049         inline void setAngle(int m){angle = m; recompileLists(); updateGL();}
00050         inline int getAngle() const{return angle;}
00051 
00052         void addExpression(const Expression &);
00053 
00054         void removeExpression(unsigned int);
00055         inline Expression getExpression(unsigned int i) const{return (functions.size() >= i + 1 && functions[i]) ? *functions[i] : Expression("",true,QColor());}
00056 
00057         inline int getCurrentExpressionIndex() const{return expressionIndex;}
00058         inline void setCurrentExpressionIndex(int i){ expressionIndex = i;}
00059 
00060         inline void setDrawConnected(bool b){drawConnected = b; recompileLists(); updateGL();}
00061         inline bool isDrawConnected() const{return drawConnected;}
00062 
00063         inline void setGrid(bool b){showGrid = b; recompileLists(); updateGL();}
00064         inline bool getGridState() const{return showGrid;}
00065 
00066         inline void setGridColor(const QColor &c){_gridColor = c; recompileLists(); updateGL();}
00067         inline QColor gridColor() const{return _gridColor;}
00068 
00069         inline bool isTracing() const{return doTrace;}
00070 
00071         inline void setTrace(bool b){doTrace = b; updateGL();}
00072 
00074         inline int expressionCount() const{return functions.size();}
00075 
00079         inline void setXRes(GLfloat f){xRes = f; xScale = (getXMax()-getXMin())/f;}
00080 
00084         inline void setYRes(GLfloat f){yRes = f; yScale = (getYMax()-getYMin())/f;}
00085 
00086         inline GLfloat getXRes() const{return xScale;}
00087         inline GLfloat getYRes() const{return yScale;}
00088         
00089         void exportToDXF( const char * );
00090         
00091     public slots:
00096         void setResolution(int percent);
00097 
00098         int getResolution() const;
00099     
00101         void nextExpression();
00102 
00104         void prevExpression();
00105 
00106         void setShowCurrentExpression(bool state);
00107 
00108         void slotNextFrame(){nextFrame();}
00109         
00110     signals:
00111         void animationValueChanged(double);
00112 
00113     protected:
00114         void paintGL();
00115         void initializeGL();
00116 
00117         virtual double snapIntervalX() const{return xScale;}
00118         virtual double snapIntervalY() const{return yScale;}
00119 
00120         virtual void nextFrameReady();
00121 
00122         /* Implement this function to let the ExpressionGraph know the independent variables which the graph takes.
00123          * Multiple variables should be seperated by commas.
00124          */
00125         virtual const char * independent_vars() const = 0;
00126 
00127         /* Implement this function to let the ExpressionGraph know the dependent variables which the graph takes. */
00128         virtual const char * dependent_var() const = 0;
00129 
00130         /* Implement this function which the ExpressionGraph calls when tracing to let it know the x, y, and z
00131          * coordinates of the trace box.
00132          */
00133         virtual void trace(GLfloat mouseX, GLfloat mouseY, FungParser &parsed_expression, GLfloat *x, GLfloat *y, GLfloat *z) = 0;
00134 
00135         inline virtual GLfloat traceDepX(GLfloat x) const{return x;}
00136         inline virtual GLfloat traceDepY(GLfloat y) const{return y;}
00137 
00138         void recompileLists();
00139         void orthoChanged();
00140 
00144         void doColorBlend(GLfloat, const QColor &, GLfloat, GLfloat );
00145         
00150         virtual Cartesian3DCoord2DVector getValues( FungParser &, GLfloat * = 0, GLfloat * = 0 ) = 0;
00151 
00152         //events
00153         void mouseMoveEvent(QMouseEvent *);
00154         void resizeGL( int w, int h );
00155 
00156         GLfloat xScale, yScale;
00157         
00158         
00159 
00160     private:
00161         void compileList(GLuint, FungParser &, std::string &, const QColor &);
00162         void exportSingleExprDXF( const Cartesian3DCoord2DVector &, std::ofstream *output, int layer );
00163         void drawCube(GLfloat x, GLfloat y, GLfloat z, GLfloat percentx, GLfloat percenty);
00164         std::vector<Expression*> functions;
00165         unsigned int expressionIndex;
00166         int angle;
00167         QColor _gridColor;
00168         bool drawConnected, showGrid, doTrace;
00169         GLfloat lastX,lastY,lastZ;
00170         GLfloat xRes,yRes;
00171         int x_percent_res, y_percent_res;
00172 };
00173 
00174 #endif