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  

glbasicgraph.cpp

00001 /***************************************************************************
00002                           glbasicgraph.cpp  -  description
00003                              -------------------
00004     begin                : Mon Sep 30 2002
00005     copyright            : (C) 2002-03 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 #include "glbasicgraph.h"
00018  
00019 #include <cmath>
00020 
00021 #include "config.h"
00022 
00023 #include <sstream>
00024 
00025 #if HAVE_GLUT
00026 #include <GL/glut.h>
00027 #endif //HAVE_GLUT
00028 
00029 #include <qcursor.h>
00030 #include <qimage.h>
00031 #include <qpainter.h>
00032 #include <qtimer.h> //auto-rotate
00033 
00034 #ifdef KDE_APP
00035 #include <kprinter.h>
00036 #else
00037 #include <qprinter.h>
00038 #endif //KDE_APP
00039 
00040 #include "glgraphevent.h"
00041 
00042 GLBasicGraph::GLBasicGraph( QWidget* parent, const char* name ) : QGLWidget( parent, name )
00043 {
00044     lastClick = new QPoint(0,0); 
00045 
00046     xMin = -15.0f;
00047     xMax = 15.0f;
00048     yMin = -15.0f;
00049     yMax = 15.0f;
00050     zMin = -10.0f;
00051     zMax = 10.0f;
00052 
00053     xMinView = -480.0f;
00054     xMaxView = 480.0f;
00055     yMinView = -480.0f;
00056     yMaxView = 480.0f;
00057     zMinView = -480.0f;
00058     zMaxView = 480.0f;
00059 
00060     xRot = 300.0f;
00061     yRot = 0.0f;
00062     zRot = 330.0f;
00063 
00064     mouseDown = false;
00065     snapToGrid = false;
00066 
00067     showAxis = true;
00068     showScale = true;
00069 
00070     xZoom = yZoom = zZoom = 2;
00071 
00072     //colors
00073     _axisColor = QColor(255,0,0);
00074     _backgroundColor = QColor(0,0,0);
00075     _scaleColor = QColor(85,170,0);
00076 
00077     setMouseTracking(true);
00078 
00079     xScale = 1;
00080     yScale = 1;
00081 
00082     origin = new QPoint();
00083     
00084     rotating_x = rotating_y = rotating_z = false;
00085     rotate_speed = 50;
00086     rotate_timer = new QTimer( this ); //auto-deleted
00087     connect( rotate_timer, SIGNAL(timeout()), this, SLOT(autoRotateStep()) );
00088 }
00089 
00090 GLBasicGraph::~GLBasicGraph()
00091 {
00092     delete lastClick;
00093     delete origin;
00094     delete rotate_timer;
00095 }
00096 
00097 void GLBasicGraph::load_key( const char *key, const char *value )
00098 {
00099     if (strcmp(key,"angle=") == 0)
00100     {
00101         setAngle(QString(value).toInt());
00102     }
00103     else if (strcmp(key,"BackgroundColor=") == 0)
00104     {
00105         QColor c(value);
00106         setBackgroundColor(c);
00107     }
00108     else if (strcmp(key,"AxisColor=") == 0)
00109     {
00110         QColor c(value);
00111         setAxisColor(c);
00112     }
00113     else if (strcmp(key,"GridColor=") == 0)
00114     {
00115         QColor c(value);
00116         setGridColor(c);
00117     }
00118     else if (strcmp(key,"showGrid=") == 0)
00119     {
00120         bool show;
00121         if ( strcmp( value,"0" ) == 0 )
00122             show = false;
00123         else
00124             show = true;
00125         setGrid(show);
00126     }
00127     else if (strcmp(key,"showAxis=") == 0)
00128     {
00129         bool show;
00130         if ( strcmp( value,"0" ) == 0 )
00131             show = false;
00132         else
00133             show = true;
00134         setAxis(show);
00135     }
00136     else if (strcmp(key,"xMinView=") == 0)
00137     {
00138         setXMinView(QString(value).toDouble());
00139     }
00140     else if (strcmp(key,"xMaxView=") == 0)
00141     {
00142         setXMaxView(QString(value).toDouble());
00143     }
00144     else if (strcmp(key,"yMinView=") == 0)
00145     {
00146         setYMinView(QString(value).toDouble());
00147     }
00148     else if (strcmp(key,"yMaxView=") == 0)
00149     {
00150         setYMaxView(QString(value).toDouble());
00151     }
00152     else if (strcmp(key,"zMinView=") == 0)
00153     {
00154         setZMinView(QString(value).toDouble());
00155     }
00156     else if (strcmp(key,"zMaxView=") == 0)
00157     {
00158         setZMaxView(QString(value).toDouble());
00159     }
00160     else if (strcmp(key,"dimensions=") == 0)
00161     {
00162         char xMin[256], xMax[256], yMin[256], yMax[256], zMin[256], zMax[256];
00163 
00164         std::stringstream valueStream(value);
00165         valueStream>>xMin;
00166         valueStream>>xMax;
00167         valueStream>>yMin;
00168         valueStream>>yMax;
00169         valueStream>>zMin;
00170         valueStream>>zMax;
00171         setRange(QString(xMin).toDouble(),QString(xMax).toDouble(),QString(yMin).toDouble(),
00172              QString(yMax).toDouble(),QString(zMin).toDouble(),QString(zMax).toDouble());
00173     }
00174     #ifndef NO_SUPPORT_OLD
00175     else if (strcmp(key,"xMin=") == 0)
00176     {
00177         setXMin(QString(value).toDouble());
00178     }
00179     else if (strcmp(key,"xMax=") == 0)
00180     {
00181         setXMax(QString(value).toDouble());
00182     }
00183     else if (strcmp(key,"yMin=") == 0)
00184     {
00185         setYMin(QString(value).toDouble());
00186     }
00187     else if (strcmp(key,"yMax=") == 0)
00188     {
00189         setYMax(QString(value).toDouble());
00190     }
00191     else if (strcmp(key,"zMin=") == 0)
00192     {
00193         setZMin(QString(value).toDouble());
00194     }
00195     else if (strcmp(key,"zMax=") == 0)
00196     {
00197         setZMin(QString(value).toDouble());
00198     }
00199     #endif
00200     else if (strcmp(key,"zEye=") == 0)
00201     {
00202         setAzimuthalEye(QString(value).toDouble());
00203     }
00204     else if (strcmp(key,"xEye=") == 0)
00205     {
00206         setPolarEye(QString(value).toDouble());
00207     }
00208 }
00209 
00210 void GLBasicGraph::initializeGL()
00211 {
00212     updateView();
00213 }
00214 
00215 void GLBasicGraph::resizeGL( int w, int h )
00216 {
00217     /*
00218     if ( w < h )
00219     {
00220         glViewport( 0, (h-w)/2, w, w );
00221         _width = _height = w;
00222     }
00223     else
00224     {
00225         glViewport( (w-h)/2, 0, h, h );
00226         _width = _height = h;
00227     }
00228     */
00229     
00230     _width = w;
00231     _height = h;
00232 
00233     glViewport( 0, 0, w, h );
00234 
00235     glMatrixMode( GL_PROJECTION );
00236     glLoadIdentity();
00237 
00238     updateOrtho();
00239 
00240     //gluPerspective( yRot, h/w, abs(zMinView), zMaxView );
00241     glMatrixMode( GL_MODELVIEW );
00242     glLoadIdentity();
00243 
00244     glDrawBuffer( GL_BACK );
00245     glEnable( GL_DEPTH_TEST );
00246     
00247     glShadeModel( GL_SMOOTH );
00248     glClearDepth( 1.0f );
00249     
00250     glEnable( GL_LINE_SMOOTH );
00251     glEnable( GL_BLEND );
00252     
00253     glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
00254     glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );
00255     
00256     updateView();
00257 }
00258 
00259 void GLBasicGraph::paintGL()
00260 {
00261     qglClearColor( _backgroundColor );
00262     
00263     glClear( GL_COLOR_BUFFER_BIT  | GL_DEPTH_BUFFER_BIT);
00264     
00265     glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
00266     glPushMatrix();
00267 
00268     //glTranslated( -(xMax+xMin)/2, -(yMax+yMin)/2, -(zMax+zMin)/2 );
00269     //glTranslated( 0.0, 0.0, 0.0 );
00270     glRotatef( xRot, 1.0f, 0.0f, 0.0f );
00271     glRotatef( yRot, 0.0f, 1.0f, 0.0f );
00272     glRotatef( zRot, 0.0f, 0.0f, 1.0f );
00273     glScalef( xScale, yScale, xScale );
00274 
00275     if (showAxis)
00276         drawAxis();
00277 
00278     //drawCage();
00279 }
00280 
00281 void GLBasicGraph::drawAxis()
00282 {
00283     double letter_width, letter_height;
00284     letter_width = letter_height = fabs( xMaxView / xScale ) / 30.0;
00285 
00286 //  qglColor( _axisColor );
00287 //  glLineWidth(6.0f);
00288     glBegin(GL_LINES);
00289 
00290         //x-axis and labels
00291         glColor3f(1.0f, 0.0f, 0.0f); //red
00292         glVertex3f(xMinView/xScale, 0.0, 0.0);
00293         glVertex3f(xMaxView/xScale, 0.0, 0.0);
00294         drawLetterMinus(xMinView/xScale,0.0,0.0,letter_width);
00295         drawLetterX(xMinView/xScale,0.0,0.0,letter_height,letter_width);
00296         drawLetterPlus(xMaxView/xScale,0.0,0.0,letter_height,letter_width);
00297         drawLetterX(xMaxView/xScale,0.0,0.0,letter_height,letter_width);
00298 
00299         //y-axis and labels
00300         glColor3f(0.0f, 1.0f, 0.0f); //green
00301         glVertex3f(0.0, yMinView/yScale, 0.0);
00302         glVertex3f(0.0, yMaxView/yScale, 0.0);
00303         drawLetterMinus(0.0,yMinView/yScale,0.0,letter_width);
00304         drawLetterY(0.0,yMinView/yScale,0.0,letter_height,letter_width);
00305         drawLetterPlus(0.0,yMaxView/yScale,0.0,letter_height,letter_width);
00306         drawLetterY(0.0,yMaxView/yScale,0.0,letter_height,letter_width);
00307 
00308         //z-axis and labels
00309         glColor3f(0.0f, 0.0f, 1.0f); //blue
00310         glVertex3f(0.0, 0.0, zMinView/xScale);
00311         glVertex3f(0.0, 0.0, zMaxView/xScale);
00312         drawLetterMinus(0.0,0.0,zMinView/xScale,letter_width);
00313         drawLetterZ(0.0,0.0,zMinView/xScale,letter_height,letter_width);
00314         drawLetterPlus(0.0,0.0,zMaxView/xScale,letter_height,letter_width);
00315         drawLetterZ(0.0,0.0,zMaxView/xScale,letter_height,letter_width);
00316 
00317     glEnd();
00318 //  glLineWidth(1.0f);
00319 /*
00320     glColor3f(1.0f, 0.0f, 0.0f);
00321     drawText(xMax, 0.0f, 0.0f, "+x");
00322     glColor3f(0.0f, 1.0f, 0.0f);
00323     drawText(0.0f, yMax, 0.0f, "+y");
00324     glColor3f(0.0f, 0.0f, 1.0f);
00325     drawText(0.0f, 0.0f, zMax, "+z");
00326 
00327     glColor3f(1.0f, 0.0f, 0.0f);
00328     drawText(xMin, 0.0f, 0.0f, "-x");
00329     glColor3f(0.0f, 1.0f, 0.0f);
00330     drawText(0.0f, yMin, 0.0f, "-y");
00331     glColor3f(0.0f, 0.0f, 1.0f);
00332     drawText(0.0f, 0.0f, zMin, "-z");
00333 */
00334 }
00335 #if 0
00336 void GLBasicGraph::drawCage()
00337 {
00338     const GLfloat x_view = (xMinView-xMaxView)*0.5f;
00339     const GLfloat y_view = (yMinView-yMaxView)*0.5f;
00340     const GLfloat z_view = (zMinView-zMaxView)*0.5f;
00341 
00342     glBegin(GL_LINES);
00343         glVertex3f(xMinView+x_view,yMaxView-y_view,zMaxView-z_view);
00344         glVertex3f(xMaxView-x_view,yMaxView-x_view,zMaxView-z_view);
00345 
00346         glVertex3f(xMinView,yMaxView,zMaxView);
00347         glVertex3f(xMinView,yMinView,zMaxView);
00348         
00349         glVertex3f(xMinView,yMaxView,zMaxView);
00350         glVertex3f(xMinView,yMaxView,zMinView);
00351         
00352         glVertex3f(xMinView,yMaxView,zMaxView);
00353         glVertex3f(xMaxView,yMaxView,zMaxView);
00354         
00355         glVertex3f(xMaxView,yMaxView,zMaxView);
00356         glVertex3f(xMaxView,yMaxView,zMinView);
00357         
00358         glVertex3f(xMinView,yMaxView,zMinView);
00359         glVertex3f(xMinView,yMinView,zMinView);
00360         
00361         glVertex3f(xMinView,yMinView,zMinView);
00362         glVertex3f(xMinView,yMinView,zMaxView);
00363         
00364         glVertex3f(xMinView,yMinView,zMinView);
00365         glVertex3f(xMaxView,yMinView,zMinView);
00366         
00367         glVertex3f(xMaxView,yMinView,zMinView);
00368         glVertex3f(xMaxView,yMinView,zMaxView);
00369         
00370         glVertex3f(xMaxView,yMinView,zMinView);
00371         glVertex3f(xMaxView,yMaxView,zMinView);
00372         
00373         glVertex3f(xMaxView,yMaxView,zMinView);
00374         glVertex3f(xMaxView,yMaxView,zMaxView);
00375         
00376         glVertex3f(xMaxView,yMinView,zMaxView);
00377         glVertex3f(xMinView,yMinView,zMaxView);
00378     
00379         glVertex3f(xMaxView,yMaxView,zMaxView);
00380         glVertex3f(xMaxView,yMinView,zMaxView);
00381     glEnd();
00382 }
00383 #endif
00384 double GLBasicGraph::toGraphXCoord(double x)
00385 {
00386     //if ( _width < _height )
00387         return ((x - origin->x()) / xScale);
00388     //else
00389     //  return toGraphYCoord(x);
00390 }
00391 
00392 double GLBasicGraph::toGraphYCoord(double y)
00393 {
00394     //if ( _height < _width )
00395         return ((y - origin->y()) / yScale);
00396     //else
00397     //  return toGraphXCoord(y);
00398 }
00399 
00400 void GLBasicGraph::mousePressEvent(QMouseEvent *e)
00401 {
00402     if (!mouseDown)
00403     {
00404         lastClick->setX(e->x());
00405         lastClick->setY(e->y());
00406         mouseDown = true;
00407     }
00408 
00409     updateGL();
00410 }
00411 
00412 void GLBasicGraph::mouseMoveEvent(QMouseEvent *e)
00413 {
00414     if (mouseDown)
00415     {
00416         xRot += (e->y() - lastClick->y());
00417         zRot += (e->x() - lastClick->x());
00418 
00419         lastClick->setX(e->x());
00420         lastClick->setY(e->y());
00421 
00422         //keep between 0 and 360
00423         if ( xRot >= 360 )
00424             xRot -= 360;
00425         if ( xRot < 0 )
00426             xRot += 360;
00427 
00428         if ( zRot >= 360 )
00429             zRot -= 360;
00430         if ( zRot < 0 )
00431             zRot += 360;
00432 
00433         if ( rotate_timer->isActive() )
00434         {
00435             rotating_x = rotating_y = rotating_z = false;
00436             rotate_timer->stop();
00437             rotateCanceled();
00438         }
00439 
00440         emitGraphRotated();
00441 
00442         updateGL();
00443     }
00444 }
00445 
00446 void GLBasicGraph::mouseReleaseEvent(QMouseEvent *)
00447 {
00448     mouseDown = false;
00449 }
00450 
00451 int GLBasicGraph::setXMin(double d)
00452 {
00453     if (d < xMax)
00454     {
00455         xMin = static_cast<GLfloat>(d);
00456         updateOrtho();
00457         updateGL();
00458         return 0;
00459     }
00460     else
00461         return 1;
00462 }
00463 
00464 int GLBasicGraph::setXMax(double d)
00465 {
00466     if (d > xMin)
00467     {
00468         xMax = static_cast<GLfloat>(d);
00469         updateOrtho();
00470         updateGL();
00471         return 0;
00472     }
00473     else
00474         return 1;
00475 }
00476 
00477 int GLBasicGraph::setYMin(double d)
00478 {
00479     if (d < yMax)
00480     {
00481         yMin = static_cast<GLfloat>(d);
00482         updateOrtho();
00483         updateGL();
00484         return 0;
00485     }
00486     else
00487         return 1;
00488 }
00489 
00490 int GLBasicGraph::setYMax(double d)
00491 {
00492     if (d > yMin)
00493     {
00494         yMax = static_cast<GLfloat>(d);
00495         updateOrtho();
00496         updateGL();
00497         return 0;
00498     }
00499     else
00500         return 1;
00501 }
00502 
00503 int GLBasicGraph::setZMin(double d)
00504 {
00505     if (d < zMax)
00506     {
00507         zMin = static_cast<GLfloat>(d);
00508         updateOrtho();
00509         updateGL();
00510         return 0;
00511     }
00512     else
00513         return 1;
00514 }
00515 
00516 int GLBasicGraph::setZMax(double d)
00517 {
00518     if (d > zMin)
00519     {
00520         zMax = static_cast<GLfloat>(d);
00521         updateOrtho();
00522         updateGL();
00523         return 0;
00524     }
00525     else
00526         return 1;
00527 }
00528 
00529 int GLBasicGraph::setXMinView(double d)
00530 {
00531     if (d < xMaxView)
00532     {
00533         xMinView = static_cast<GLfloat>(d);
00534         updateView();
00535         updateGL();
00536         return 0;
00537     }
00538     else
00539         return 1;
00540 }
00541 
00542 int GLBasicGraph::setXMaxView(double d)
00543 {
00544     if (d > xMinView)
00545     {
00546         xMaxView = static_cast<GLfloat>(d);
00547         updateView();
00548         updateGL();
00549         return 0;
00550     }
00551     else
00552         return 1;
00553 }
00554 
00555 int GLBasicGraph::setYMinView(double d)
00556 {
00557     if (d < yMaxView)
00558     {
00559         yMinView = static_cast<GLfloat>(d);
00560         updateView();
00561         updateGL();
00562         return 0;
00563     }
00564     else
00565         return 1;
00566 }
00567 
00568 int GLBasicGraph::setYMaxView(double d)
00569 {
00570     if (d > yMinView)
00571     {
00572         yMaxView = static_cast<GLfloat>(d);
00573         updateView();
00574         updateGL();
00575         return 0;
00576     }
00577     else
00578         return 1;
00579 }
00580 
00581 int GLBasicGraph::setZMinView(double d)
00582 {
00583     if (d < zMaxView)
00584     {
00585         zMinView = static_cast<GLfloat>(d);
00586         updateView();
00587         updateGL();
00588         return 0;
00589     }
00590     else
00591         return 1;
00592 }
00593 
00594 int GLBasicGraph::setZMaxView(double d)
00595 {
00596     if (d > zMinView)
00597     {
00598         zMaxView = static_cast<GLfloat>(d);
00599         updateView();
00600         updateGL();
00601         return 0;
00602     }
00603     else
00604         return 1;
00605 }
00606 
00607 void GLBasicGraph::setPolarEye(double d)
00608 {
00609     xRot = static_cast<GLfloat>(static_cast<int>(d) % 360);
00610     updateGL();
00611 }
00612 
00613 void GLBasicGraph::setAzimuthalEye(double d)
00614 {
00615     zRot = static_cast<GLfloat>(static_cast<int>(d) % 360);
00616     updateGL();
00617 }
00618 
00619 void GLBasicGraph::zoomStd()
00620 {
00621     xRot = 300.0f;
00622     yRot = 0.0f;
00623     zRot = 330.0f;
00624 
00625     emitGraphRotated();
00626 
00627     xMinView = -480.0f;
00628     xMaxView = 480.0f;
00629     yMinView = -480.0f;
00630     yMaxView = 480.0f;
00631     zMinView = -480.0f;
00632     zMaxView = 480.0f;
00633     
00634     updateView();
00635     updateGL();
00636 }
00637 
00638 void GLBasicGraph::zoomIn()
00639 {
00640     xMinView /= xZoom;//xMinView+(xMaxView-xMinView)/(2*xZoom);
00641     xMaxView /= xZoom;//xMaxView-(xMaxView-xMinView)/(2*xZoom);
00642     yMinView /= yZoom;//yMinView+(yMaxView-yMinView)/(2*yZoom);
00643     yMaxView /= yZoom;//yMaxView-(yMaxView-yMinView)/(2*yZoom);
00644     zMinView /= xZoom;//zMinView+(zMaxView-zMinView)/(2*zZoom);
00645     zMaxView /= xZoom;//zMaxView-(zMaxView-zMinView)/(2*zZoom);
00646     
00647     updateView();
00648     updateGL();
00649     //emitDimensionsChanged();
00650 }
00651 
00652 void GLBasicGraph::zoomOut()
00653 {
00654     xMinView *= xZoom;//xMinView-(xMaxView-xMinView)/(2*xZoom);
00655     xMaxView *= xZoom;//xMaxView+(xMaxView-xMinView)/(2*xZoom);
00656     yMinView *= yZoom;//yMinView-(yMaxView-yMinView)/(2*yZoom);
00657     yMaxView *= yZoom;//yMaxView+(yMaxView-yMinView)/(2*yZoom);
00658     zMinView *= zZoom;//zMinView-(zMaxView-zMinView)/(2*zZoom);
00659     zMaxView *= zZoom;//zMaxView+(zMaxView-zMinView)/(2*zZoom);
00660 
00661     updateView();
00662     updateGL();
00663     //emitDimensionsChanged();
00664 }
00665 
00666 int GLBasicGraph::setRange(GLfloat _xMin, GLfloat _xMax, GLfloat _yMin, GLfloat _yMax, GLfloat _zMin, GLfloat _zMax)
00667 {
00668     if (_xMin < _xMax && _yMin < _yMax && _zMin < _zMax)
00669     {
00670         xMin = _xMin;
00671         xMax = _xMax;
00672         yMin = _yMin;
00673         yMax = _yMax;
00674         zMin = _zMin;
00675         zMax = _zMax;
00676 
00677         updateOrtho();
00678         updateGL();
00679         return 0;
00680     }
00681     else
00682         return 1;
00683 }
00684 
00685 void GLBasicGraph::emitDimensionsChanged()
00686 {
00687     GLGraphEvent event(xMin,xMax,yMin,yMax,zMin,zMax);
00688     emit dimensionsChanged(event);
00689 }
00690 
00691 void GLBasicGraph::drawText(GLfloat x, GLfloat y, GLfloat z, const char *s)
00692 {
00693     #if HAVE_GLUT
00694     glRasterPos3f(x, y, z);
00695     for (const char *c = s; *c != '\0'; c++)
00696         glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, *c);
00697     glRasterPos3f(-x, -y, -z);
00698     #endif //HAVE_GLUT
00699 }
00700 
00701 void GLBasicGraph::emitGraphRotated()
00702 {
00703     emit graphRotated(GLGraphEvent(xRot,zRot));
00704 }
00705 
00706 void GLBasicGraph::exportAsImage(const QString &file, const QString &fileType)
00707 {
00708     QImage image = grabFrameBuffer();
00709     image.save(file,fileType);
00710 }
00711 
00712 void GLBasicGraph::getPixmap(QPixmap &pm)
00713 {
00714     pm = renderPixmap();
00715 }
00716 
00717 void GLBasicGraph::print(
00718     #ifdef KDE_APP
00719     KPrinter *printer
00720     #else
00721     QPrinter *printer
00722     #endif //KDE_APP
00723     )
00724 {
00725     if ( printer->setup(this) ) // printer dialog
00726     {               
00727         qDebug( "Printing...");
00728         QPainter p;
00729         if ( !p.begin( printer ) )
00730             return;
00731         p.drawImage ( 0, 0, grabFrameBuffer());
00732         p.end();
00733         qDebug( "Printing completed");
00734     }
00735     else
00736         qDebug( "Printing aborted" );
00737 }
00738 
00739 void GLBasicGraph::updateOrtho()
00740 {
00741     origin->setX( static_cast<int>(-xMin * _width / (xMax - xMin)) );
00742     origin->setY( static_cast<int>(-yMin * _height / (yMax - yMin)) );
00743     xScale = _width  / (xMax - xMin);
00744     yScale = _height / (yMax - yMin);
00745 
00746     orthoChanged();
00747 }
00748 
00749 void GLBasicGraph::updateView()
00750 {
00751     glMatrixMode( GL_PROJECTION );
00752     glLoadIdentity();
00753 
00754     glOrtho(xMinView,xMaxView,yMinView,yMaxView,zMinView,zMaxView);
00755 }
00756 
00757 void GLBasicGraph::autoRotateX(bool on)
00758 {
00759     rotating_x = on;
00760 
00761     if (on)
00762         rotate_timer->start( rotate_speed, FALSE );
00763     else if ( !rotating_y && !rotating_z )
00764         rotate_timer->stop();
00765 }
00766 
00767 void GLBasicGraph::autoRotateY(bool on)
00768 {
00769     rotating_y = on;
00770 
00771     if (on)
00772         rotate_timer->start( rotate_speed, FALSE );
00773     else if ( !rotating_x && !rotating_z )
00774         rotate_timer->stop();
00775     
00776 }
00777 
00778 void GLBasicGraph::autoRotateZ(bool on)
00779 {
00780     rotating_z = on;
00781 
00782     if (on)
00783         rotate_timer->start( rotate_speed, FALSE );
00784     else if ( !rotating_x && !rotating_y )
00785         rotate_timer->stop();
00786 }
00787 
00788 void GLBasicGraph::autoRotateStep()
00789 {
00790     if (rotating_x)
00791         xRot += 1;
00792     if (rotating_y)
00793         yRot += 1;
00794     if (rotating_z)
00795         zRot += 1;
00796 
00797     emitGraphRotated();
00798     updateGL();
00799 }
00800 
00801 void GLBasicGraph::drawLetterPlus(double pos_x, double pos_y, double pos_z,
00802                                         double plus_height, double plus_width)
00803 {
00804     glVertex3d( pos_x-(0.5*plus_width), pos_y , pos_z+(-0.5*plus_height));
00805     glVertex3d( pos_x-(0.5*plus_width), pos_y , pos_z+(0.5*plus_height));
00806     glVertex3d( pos_x                 , pos_y , pos_z);
00807     glVertex3d( pos_x-plus_width      , pos_y , pos_z);
00808 }
00809 
00810 void GLBasicGraph::drawLetterMinus(double pos_x, double pos_y, double pos_z,
00811                                          double minus_width)
00812 {
00813     glVertex3d( pos_x             , pos_y , pos_z);
00814     glVertex3d( pos_x-minus_width , pos_y , pos_z);
00815 }
00816 
00817 void GLBasicGraph::drawLetterX(double pos_x, double pos_y, double pos_z,
00818                                  double x_height, double x_width)
00819 {
00820     glVertex3d( pos_x + x_width, pos_y , pos_z+(-1*x_height));
00821     glVertex3d( pos_x          , pos_y , pos_z+x_height);
00822     glVertex3d( pos_x          , pos_y , pos_z+(-1*x_height));
00823     glVertex3d( pos_x + x_width, pos_y , pos_z+x_height);
00824 }
00825 
00826 void GLBasicGraph::drawLetterY(double pos_x, double pos_y, double pos_z,
00827                                  double y_height, double y_width)
00828 {
00829     glVertex3d( pos_x+(0.5*y_width), pos_y, pos_z-(0.4*y_height));
00830     glVertex3d( pos_x+(0.5*y_width), pos_y, pos_z);
00831     glVertex3d( pos_x              , pos_y, pos_z+(0.6*y_height));
00832     glVertex3d( pos_x+(0.5*y_width), pos_y, pos_z);
00833     glVertex3d( pos_x+y_width      , pos_y, pos_z+(0.6*y_height));
00834     glVertex3d( pos_x+(0.5*y_width), pos_y, pos_z);
00835 }
00836 
00837 void GLBasicGraph::drawLetterZ(double pos_x, double pos_y, double pos_z,
00838                                  double z_height, double z_width)
00839 {
00840     glVertex3d( pos_x + z_width, pos_y , pos_z+(-1*z_height));
00841     glVertex3d( pos_x          , pos_y , pos_z+(-1*z_height));
00842     glVertex3d( pos_x          , pos_y , pos_z+(-1*z_height));
00843     glVertex3d( pos_x + z_width, pos_y , pos_z+z_height);
00844     glVertex3d( pos_x + z_width, pos_y , pos_z+z_height);
00845     glVertex3d( pos_x          , pos_y , pos_z+z_height);
00846 }
00847 
00848 void GLBasicGraph::setMouseX(double x, bool snap)
00849 {
00850     if (snapToGrid && snap)
00851     {
00852         double interval = snapIntervalX();
00853         double remainder = fmod(x - startSnap(), interval);
00854         if (remainder < 0)
00855         {
00856             if ( fabs(remainder) < (interval/2) )
00857                 mouseX = x - remainder; //round up
00858             else
00859                 mouseX = x - (interval + remainder); //round down
00860         }
00861         else
00862         {
00863             if ( fabs(remainder) < (interval/2) )
00864                 mouseX = x - remainder; //round down
00865             else
00866                 mouseX = x + (interval - remainder); //round up
00867         }
00868     }
00869     else
00870         mouseX = x;
00871 }
00872 
00873 void GLBasicGraph::setMouseY(double y, bool snap)
00874 {
00875     if (snapToGrid && snap)
00876     {
00877         double interval = snapIntervalY();
00878         double remainder = fmod(y, interval);
00879         if (remainder < 0)
00880         {
00881             if ( fabs(remainder) < (interval/2) )
00882                 mouseY = y - remainder;
00883             else
00884                 mouseY = y - (interval + remainder);
00885         }
00886         else
00887         {
00888             if ( fabs(remainder) < (interval/2) )
00889                 mouseY = y - remainder;
00890             else
00891                 mouseY = y + (interval - remainder);
00892         }
00893     }
00894     else
00895         mouseY = y;
00896 }
00897 
00898 
00899 
00900