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  

polargraph.cpp

00001 /***************************************************************************
00002                           polargraph.cpp  -  description
00003                              -------------------
00004     begin                : Thu May 30 2002
00005     copyright            : (C) 2002 by Fungmeista
00006     email                : confederacy2@excite.com
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 #include "polargraph.h"
00019 
00020 #include <qpainter.h>
00021 
00022 #include "polarcoord.h"
00023 #include "rectcoord.h"
00024 #include "fungparser.h"
00025 #include "expression.h"
00026 
00027 PolarGraph::PolarGraph(QWidget *parent, const char *name ) : ExpressionGraph(parent,name)
00028 {
00029     setCoordinateStyle(POLAR);
00030 
00031     tMin = -15;
00032     tMax = 15;
00033     tStep = 0.1;
00034 }
00035 
00036 void PolarGraph::load_key( const char *key, const char *value )
00037 {
00038     ExpressionGraph::load_key(key,value);
00039 
00040     if (strcmp(key,"rScale=") == 0)
00041     {
00042         setRScale(QString(value).toDouble());
00043     }
00044     else if (strcmp(key,"aScale=") == 0)
00045     {
00046         setAScale(QString(value).toDouble());
00047     }
00048     else if (strcmp(key,"tMin=") == 0)
00049     {
00050         setTMin(QString(value).toDouble());
00051     }
00052     else if (strcmp(key,"tMax=") == 0)
00053     {
00054         setTMax(QString(value).toDouble());
00055     }
00056     else if (strcmp(key,"tStep=") == 0)
00057     {
00058         setTStep(QString(value).toDouble());
00059     }
00060 }
00061 int PolarGraph::setXYForTrace(const double mousex, const double, double *x, double *y, Expression &expression)
00062 {
00063     FungParser *fp = expression.getParsedExpression(dependent_var());
00064 
00065     double d[] = {mousex,animatorValue()};
00066     double r = fp->Eval(d);
00067 
00068     PolarCoord p(r, mousex, getAngle());
00069     *x = p.toRectangular().getX();
00070     *y = p.toRectangular().getY();
00071 
00072     t_trace = mousex;
00073 
00074     return fp->EvalError();
00075 }
00076 
00077 void PolarGraph::updateCoords()
00078 {
00079     if (isTracing())
00080         emit activeCoordinateChanged( QString("x = %1").arg(getMouseX()), QString("y = %1").arg(getMouseY()), QString("t = %1").arg(t_trace) );
00081     else
00082         BasicGraph::updateCoords();
00083 }
00084 
00085 void PolarGraph::drawExpression(QPainter *painter, Expression & expression)
00086 {
00087     for (double theta = tMin; theta < tMax; theta+=tStep)
00088     {
00089         FungParser *fp = expression.getParsedExpression(dependent_var());
00090 
00091         double d[] = {theta,animatorValue()};
00092 
00093         double r = fp->Eval(d);
00094         if (fp->EvalError()){continue;}
00095 
00096         PolarCoord p(r, theta, getAngle());
00097 
00098         if (isDrawConnected())
00099         {
00100             double temp = theta + tStep;
00101 
00102             double dnext[] = {temp,animatorValue()};
00103 
00104             r = fp->Eval(dnext);
00105             if (fp->EvalError()){continue;}
00106 
00107         PolarCoord nextP(r, theta + tStep, getAngle());
00108         painter->drawLine(
00109             toPixelXCoord(p.toRectangular().getX()),
00110             toPixelYCoord(p.toRectangular().getY()),
00111             toPixelXCoord(nextP.toRectangular().getX()),
00112             toPixelYCoord(nextP.toRectangular().getY()));
00113         }
00114         else
00115         {
00116             painter->drawPoint(
00117                 toPixelXCoord(p.toRectangular().getX()),
00118                 toPixelYCoord(p.toRectangular().getY()));
00119         }
00120     }
00121 }
00122 
00123 int PolarGraph::setTMin(double _tMin)
00124 {
00125     if (_tMin < tMax)
00126     {
00127         tMin = _tMin;
00128         repaint(false);
00129         return 0;
00130     }
00131     else
00132         return 1;
00133 }
00134 
00135 int PolarGraph::setTMax(double _tMax)
00136 {
00137     if (_tMax > tMin)
00138     {
00139         tMax = _tMax;
00140         repaint(false);
00141         return 0;
00142     }
00143     else
00144         return 1;
00145 }
00146 
00147 int PolarGraph::setTStep(double _tStep)
00148 {
00149     if (_tStep > 0)
00150     {
00151         tStep = _tStep;
00152         repaint(false);
00153         return 0;
00154     }
00155     else
00156         return 1;
00157 }
00158