Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members Related Pages Search
functiongraph.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "functiongraph.h"
00018
00019 #include <qpainter.h>
00020
00021 #include "expression.h"
00022 #include "fungparser.h"
00023 #include "definiteintegralfunction.h"
00024 #include "arclengthfunction.h"
00025 #include "maximumfunction.h"
00026 #include "minimumfunction.h"
00027 #include "meanvaluefunction.h"
00028
00029 FunctionGraph::FunctionGraph ( QWidget *parent, const char *name ) : ExpressionGraph( parent, name )
00030 {
00031 }
00032
00033 FunctionGraph::~FunctionGraph()
00034 {
00035 }
00036
00037 void FunctionGraph::installMathFunctions()
00038 {
00039 BasicGraph::installMathFunctions();
00040
00041 addMathFunction(new DefiniteIntegralFunction(this,1),"Definite Integral");
00042 addMathFunction(new ArcLengthFunction(this,1),"Arc Length");
00043 addMathFunction(new MaximumFunction(this,1),"Maximum");
00044 addMathFunction(new MinimumFunction(this,1),"Minimum");
00045 addMathFunction(new MeanValueFunction(this,1),"Mean Value");
00046 }
00047
00048 void FunctionGraph::drawExpression(QPainter *painter, Expression & expression)
00049 {
00050 for (double x = 0; x < width(); x++)
00051 {
00052 FungParser *fp = expression.getParsedExpression(dependent_var());
00053
00054 double xval[] = {toGraphXCoord(x),animatorValue()};
00055
00056 double evaluated = fp->Eval(xval);
00057
00058 if (fp->EvalError()){continue;}
00059
00060 if (isDrawConnected())
00061 {
00062 double nextxval[] = {toGraphXCoord(x+1),animatorValue()};
00063 double nextevaluated = fp->Eval(nextxval);
00064
00065 if (!fp->EvalError())
00066 painter->drawLine((int)x,toPixelYCoord(evaluated),(int)x+1,toPixelYCoord(nextevaluated));
00067 }
00068 else
00069 painter->drawPoint((int)x,toPixelYCoord(evaluated));
00070 }
00071 }
00072
00073 int FunctionGraph::setXYForTrace(const double mousex, const double, double *x, double *y, Expression &expression)
00074 {
00075 FungParser *fp = expression.getParsedExpression(dependent_var());
00076
00077 double d[] = {mousex,animatorValue()};
00078
00079 *x = mousex;
00080 *y = fp->Eval(d);
00081
00082 return fp->EvalError();
00083 }
00084
00085 int FunctionGraph::execMathFunction( const char * id )
00086 {
00087 MathFunction *mf = getMathFunction(id);
00088 if ( mf )
00089 {
00090 switch ( mf->expressionsRequired() )
00091 {
00092 case 0: return BasicGraph::execMathFunction(id); break;
00093 case 1:
00094 {
00095 FungParser *fp = getParsedCurrentExpression();
00096 if (fp)
00097 {
00098 mf->exec(fp);
00099 return 1;
00100 }
00101 return -1;
00102 break;
00103 }
00104 default: break;
00105 }
00106 }
00107
00108 return -1;
00109 }
00110
00111
|