// Author: OCC team
// Copyright (C) CEA 2004
-/***************************************************************************
-** Class: GLViewer_Widget
-** Descr: OpenGL QWidget for GLViewer
-** Module: GLViewer
-** Created: UI team, 27.03.03
-****************************************************************************/
-
-//#include <GLViewerAfx.h>
+//================================================================
+// Class : GLViewer_Widget
+// Description : OpenGL QWidget for GLViewer
+//================================================================
+
#include "GLViewer_Widget.h"
#include "GLViewer_ViewPort2d.h"
#include "GLViewer_Viewer2d.h"
#include <cmath>
using namespace std;
-//#include <math.h>
-//#include <stdlib.h>
-//#include <iostream.h>
#include <qevent.h>
#include <qrect.h>
#include <qsize.h>
#include <qtooltip.h>
-//-----------
-#include <qfontdialog.h>
-#include <qfontmetrics.h>
-#include <qpainter.h>
-//-----------
-
-//static GLuint texFont;
-//static int fontW;
-//static int fontH;
-
-/*
-static void genFont()
-{
- bool ok;
- QFont aFont = QFontDialog::getFont( &ok );
- QFontMetrics aFM( aFont );
- QString aStr;
- for( int k = 32; k <= 127; k++ )
- {
- char aLetter = (char)k;
- aStr += aLetter;
- }
-
- int pixelsWidth = aFM.width( aStr );
- int pixelsHigh = aFM.height();
- int aFontX = 64;
- int aFontY = 64;
-
- while( aFontX < pixelsWidth )
- aFontX = aFontX * 2;
- while( aFontY < pixelsHigh )
- aFontY = aFontY * 2;
-
- QPixmap* aPixmap = new QPixmap( aFontX, aFontY );
- aPixmap->fill( QColor( 255, 255, 255) );
- QPainter aPainter( aPixmap );
- aPainter.setFont( aFont );
- aPainter.drawText ( 0, pixelsHigh, aStr );
- QImage aImage = aPixmap->convertToImage();
-
- aImage.save( "W:\\Temp\\pic.jpg", "JPEG" );
-
- char* pixels = new char[aFontX * aFontY * 2];
-
- for( int i = 0; i < aFontY; i++ )
- {
- for( int j = 0; j < aFontX; j++ )
- {
- if( qRed( aImage.pixel( j, aFontY - i - 1 ) ) == 0 )
- {
- pixels[i * aFontX * 2 + j * 2] = (char) 255;
- pixels[i * aFontX * 2 + j * 2 + 1]= (char) 255;
- }
- else
- {
- pixels[i * aFontX * 2 + j * 2] = (char) 0;
- pixels[i * aFontX * 2 + j * 2 + 1]= (char) 0;
- }
- }
- }
-
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glGenTextures(1, &texFont);
- glBindTexture(GL_TEXTURE_2D, texFont);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexImage2D(GL_TEXTURE_2D, 0, 2, aFontX,
- aFontY, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels);
-
- fontW = aFontX;
- fontH = aFontY;
-
- delete[] pixels;
-}
-
-static void showFont()
-{
- glEnable(GL_TEXTURE_2D);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glAlphaFunc(GL_GEQUAL, 0.005F);
- glEnable(GL_ALPHA_TEST);
- glColor3f( 1.0, 1.0, 1.0);
- glBindTexture(GL_TEXTURE_2D, texFont);
- glBegin(GL_QUADS);
-
- glTexCoord2f( 0.0, 0.0 ); glVertex3f( -fontW/2, -fontH/2, 1.0 );
- glTexCoord2f( 0.0, 1.0 ); glVertex3f( -fontW/2, fontH/2, 1.0 );
- glTexCoord2f( 1.0, 1.0 ); glVertex3f( fontW/2, fontH/2, 1.0 );
- glTexCoord2f( 1.0, 0.0 ); glVertex3f( fontW/2, -fontH/2, 1.0 );
-
- glEnd();
- glFlush();
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_TEXTURE_2D);
-}
-*/
-
+//=======================================================================
+// Function: GLViewer_Widget
+// Purpose :
+//=======================================================================
GLViewer_Widget::GLViewer_Widget( QWidget* parent, const char* name ):
QGLWidget( parent, 0/*, WRepaintNoErase | WResizeNoErase*/ )
{
setMouseTracking( true );
}
+//=======================================================================
+// Function: GLViewer_Widget
+// Purpose :
+//=======================================================================
GLViewer_Widget::~GLViewer_Widget()
{
}
+//=======================================================================
+// Function: ~GLViewer_Widget
+// Purpose :
+//=======================================================================
void GLViewer_Widget::getPan( GLfloat& xPan, GLfloat& yPan, GLfloat& zPan )
{
xPan = myXPan;
zPan = myZPan;
}
+//=======================================================================
+// Function: setPan
+// Purpose :
+//=======================================================================
void GLViewer_Widget::setPan( GLfloat xPan, GLfloat yPan, GLfloat zPan )
{
myXPan = xPan;
myZPan = zPan;
}
+//=======================================================================
+// Function: getScale
+// Purpose :
+//=======================================================================
void GLViewer_Widget::getScale( GLfloat& xScale, GLfloat& yScale, GLfloat& zScale )
{
xScale = myXScale;
zScale = myZScale;
}
+//=======================================================================
+// Function: setScale
+// Purpose :
+//=======================================================================
void GLViewer_Widget::setScale( GLfloat xScale, GLfloat yScale, GLfloat zScale )
{
if ( xScale > 0 && yScale > 0 && zScale > 0 )
}
}
-void GLViewer_Widget::getRotationStart( GLfloat& rotationStartX, GLfloat& rotationStartY,
- GLfloat& rotationStartZ )
+//=======================================================================
+// Function: getRotationStart
+// Purpose :
+//=======================================================================
+void GLViewer_Widget::getRotationStart( GLfloat& rotationStartX,
+ GLfloat& rotationStartY,
+ GLfloat& rotationStartZ )
{
rotationStartX = myRotationStartX;
rotationStartY = myRotationStartY;
rotationStartZ = myRotationStartZ;
}
-void GLViewer_Widget::setRotationStart( GLfloat rotationStartX, GLfloat rotationStartY,
- GLfloat rotationStartZ )
+//=======================================================================
+// Function: setRotationStart
+// Purpose :
+//=======================================================================
+void GLViewer_Widget::setRotationStart( GLfloat rotationStartX,
+ GLfloat rotationStartY,
+ GLfloat rotationStartZ )
{
myRotationStartX = rotationStartX;
myRotationStartY = rotationStartY;
myRotationStartZ = rotationStartZ;
}
-void GLViewer_Widget::getRotation( GLfloat& rotationAngle, GLfloat& rotationCenterX,
- GLfloat& rotationCenterY, GLfloat& rotationCenterZ )
+//=======================================================================
+// Function: getRotation
+// Purpose :
+//=======================================================================
+void GLViewer_Widget::getRotation( GLfloat& rotationAngle,
+ GLfloat& rotationCenterX,
+ GLfloat& rotationCenterY,
+ GLfloat& rotationCenterZ )
{
rotationAngle = myRotationAngle;
rotationCenterX = myRotationCenterX;
rotationCenterZ = myRotationCenterZ;
}
-void GLViewer_Widget::setRotation( GLfloat rotationAngle, GLfloat rotationCenterX,
- GLfloat rotationCenterY, GLfloat rotationCenterZ )
+//=======================================================================
+// Function: setRotation
+// Purpose :
+//=======================================================================
+void GLViewer_Widget::setRotation( GLfloat rotationAngle,
+ GLfloat rotationCenterX,
+ GLfloat rotationCenterY,
+ GLfloat rotationCenterZ )
{
myRotationAngle = rotationAngle;
myRotationCenterX = rotationCenterX;
myRotationCenterZ = rotationCenterZ;
}
+//=======================================================================
+// Function: setBackground
+// Purpose :
+//=======================================================================
void GLViewer_Widget::setBackground( QString filename )
{
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &texName);
glBindTexture(GL_TEXTURE_2D, texName);
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, myBackgroundSize , myBackgroundSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
delete[] pixels;
}
-
}
+//=======================================================================
+// Function: addToolTip
+// Purpose :
+//=======================================================================
void GLViewer_Widget::addToolTip( QString theString, QRect theRect )
{
myToolTipRect = theRect;
QToolTip::add( this, myToolTipRect, theString );
}
+//=======================================================================
+// Function: removeToolTip
+// Purpose :
+//=======================================================================
void GLViewer_Widget::removeToolTip()
{
QToolTip::remove( this, myToolTipRect );
}
+//=======================================================================
+// Function: initializeGL
+// Purpose :
+//=======================================================================
void GLViewer_Widget::initializeGL()
{
setAutoBufferSwap( true );
-// cout << "GLViewer_Widget::initializeGL" << endl;
-
- //glClearColor( 0.0, 0.0, 0.0, 0.0 );
- //-----------------
glShadeModel(GL_FLAT);
//get image
if ( !aPicturePath.isEmpty() && buf.load( aPicturePath ) )
{ // Load first image from file
isLoadBackground = true;
- setBackground( aPicturePath );
-
- // for test texture font
- //genFont();
-/*
- bool ok;
- QFont aFont = QFontDialog::getFont( &ok, this );
- QFontMetrics aFM( aFont );
- int pixelsWidth = aFM.width( "What's the width of this text?" );
- int pixelsHigh = aFM.height();
- int aFontX = 64;
- int aFontY = 64;
-
- while( aFontX < pixelsWidth )
- aFontX = aFontX * 2;
- while( aFontY < pixelsHigh )
- aFontY = aFontY * 2;
-
- myIW = aFontX;
- myIH = aFontY;
-
- QPixmap* aPixmap = new QPixmap( aFontX, aFontY );
- aPixmap->fill( QColor( 255, 255, 255) );
- QPainter aPainter( aPixmap );
- aPainter.setFont( aFont );
- //Painter.setPen( QColor( 0, 0, 0 ) );
- aPainter.drawText ( 0, pixelsHigh, "A" );
- QImage aImage = aPixmap->convertToImage();
-
- aImage.save( "W:\\Temp\\pic.jpg", "JPEG" );
-
- GLubyte* pixels = new GLubyte[aFontX * aFontY * 2];
-
- for( int i = 0; i < aFontY; i++ )
- {
- for( int j = 0; j < aFontX; j++ )
- {
- if( qRed( aImage.pixel( j, myIH - i - 1 ) ) == 0 )
- {
- pixels[i * aFontX * 2 + j * 2] = (GLubyte) 255;
- pixels[i * aFontX * 2 + j * 2 + 1]= (GLubyte) 255;
- }
- else
- {
- pixels[i * aFontX * 2 + j * 2] = (GLubyte) 0;
- pixels[i * aFontX * 2 + j * 2 + 1]= (GLubyte) 0;
- }
- }
- }
-
-
- glBindTexture(GL_TEXTURE_2D, texName);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glTexImage2D(GL_TEXTURE_2D, 0, 2, aFontX,
- aFontY, 0, GL_LUMINANCE_ALPHA, GL_UNSIGNED_BYTE, pixels);
-
- delete[] pixels;
-*/
-
- //tex2 = buf.convertDepth( 32, 0 );
-
- //tex1 = QGLWidget::convertToGLFormat( tex2 ); // flipped 32bit RGBA
-
- /*myIW = buf.width();
- myIH = buf.height();
-
- myBackgroundSize = 64;
- while( myBackgroundSize < myIW || myBackgroundSize < myIH)
- myBackgroundSize = myBackgroundSize * 2;
-
- GLubyte* pixels = new GLubyte[myBackgroundSize * myBackgroundSize * 4];
-
- //GLubyte pixels[512][512][3];
- for( int i = 0; i < myBackgroundSize; i++ )
- {
- for( int j = 0; j < myBackgroundSize; j++ )
- {
- if( j < myIW && i < myIH )
- {
- pixels[i * myBackgroundSize * 4 + j * 4] = (GLubyte)qRed( buf.pixel(j,myIH - i - 1) );
- pixels[i * myBackgroundSize * 4 + j * 4 + 1]= (GLubyte)qGreen( buf.pixel(j,myIH - i - 1) );
- pixels[i * myBackgroundSize * 4 + j * 4 + 2] = (GLubyte)qBlue( buf.pixel(j,myIH - i - 1) );
- }
- else
- {
- pixels[i * myBackgroundSize * 4 + j * 4] = (GLubyte)0;
- pixels[i * myBackgroundSize * 4 + j * 4 + 1] = (GLubyte)0;
- pixels[i * myBackgroundSize * 4 + j * 4 + 2] = (GLubyte)0;
- }
- pixels[i * myBackgroundSize* 4 + j * 4 + 3] = (GLubyte)255;
- //cout << "RED = " << qRed( buf.pixel(i,j) ) << " GREEN = " << qGreen( buf.pixel(i,j) ) <<
- // " BLUE = " << qBlue( buf.pixel(i,j) ) << endl;
- }
- }
-
- //initialize texture
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glGenTextures(1, &texName);
- glBindTexture(GL_TEXTURE_2D, texName);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, myBackgroundSize , myBackgroundSize, 0, GL_RGBA, GL_UNSIGNED_BYTE,
- pixels);
-
- delete[] pixels;
- */
+ setBackground( aPicturePath );
}
else
isLoadBackground = false;
-
- //GLViewer_TexFont aTexFont;
- //aTexFont.generateTexture();
- //aTexFont.drawString( "hello" );
- //-----------------
}
+//=======================================================================
+// Function: paintGL
+// Purpose :
+//=======================================================================
void GLViewer_Widget::paintGL()
{
-// cout << "GLViewer_Widget::paintGL" << endl;
-
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode( GL_MODELVIEW );
glRotatef( myRotationAngle, myRotationCenterX, myRotationCenterY, myRotationCenterZ );
glScalef( myXScale, myYScale, myZScale );
glTranslatef( myXPan, myYPan, myZPan );
- //glRotatef( myRotationAngle, myRotationCenterX, myRotationCenterY, myRotationCenterZ );
- if( isLoadBackground )
+ if( isLoadBackground )
{
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glFlush();
glDisable(GL_TEXTURE_2D);
- // for test texture font
- // showFont();
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
}
GLViewer_Grid* grid = myViewPort->getGrid();
if( grid )
grid->draw();
- //myViewPort->drawCompass();
-
- //glEnable( GL_POLYGON_OFFSET_FILL );
- //glPolygonOffset( 0, 1 );
GLViewer_Viewer2d* v = ( GLViewer_Viewer2d* )getViewPort()->getViewFrame()->getViewer();
if( !isExportMode )
v->updateDrawers( GL_FALSE, myXScale, myYScale );
else
v->repaintView( getViewPort()->getViewFrame() );
-
- //glDisable( GL_POLYGON_OFFSET_FILL );
-
-// GLViewer_TexFont aTexFont;
-// aTexFont.generateTexture();
-// aTexFont.drawString( "hello" );
}
+//=======================================================================
+// Function: resizeGL
+// Purpose :
+//=======================================================================
void GLViewer_Widget::resizeGL( int w, int h )
{
-// cout << "GLViewer_Widget::resizeGL " << w << " " << h << endl;
if( h < 1 ) h = 1;
if( w < 1 ) w = 1;
myViewPort->initResize( w, h );
- //GLViewer_Viewer2d* v = ( GLViewer_Viewer2d* )getViewPort()->getViewFrame()->getViewer();
- //v->updateDrawers( GL_FALSE, myXScale, myYScale );
-
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
GLfloat w_c = w / 2., h_c = h / 2.;
glLoadIdentity();
}
-void GLViewer_Widget::copyBuffers()
-{
-// cout << "GLViewer_Widget::copyBuffers" << endl;
-
- GLint val[4];
- glGetIntegerv( GL_VIEWPORT, val );
- glReadBuffer( GL_FRONT );
- glCopyPixels( val[0], val[1], val[2], val[3], GL_COLOR );
-}
-
+//=======================================================================
+// Function: exportRepaint
+// Purpose :
+//=======================================================================
void GLViewer_Widget::exportRepaint()
{
isExportMode = true;
isExportMode = false;
}
-
+//=======================================================================
+// Function: paintEvent
+// Purpose :
+//=======================================================================
void GLViewer_Widget::paintEvent( QPaintEvent* e )
{
-// cout << "GLViewer_Widget::paintEvent" << endl;
QApplication::sendEvent( myViewPort, e );
}
+//=======================================================================
+// Function: mouseMoveEvent
+// Purpose :
+//=======================================================================
void GLViewer_Widget::mouseMoveEvent( QMouseEvent* e )
{
-// cout << "GLViewer_Widget::mouseMoveEvent" << endl;
QApplication::sendEvent( myViewPort, e );
}
+//=======================================================================
+// Function: mousePressEvent
+// Purpose :
+//=======================================================================
void GLViewer_Widget::mousePressEvent( QMouseEvent* e )
{
-// cout << "GLViewer_Widget::mousePressEvent" << endl;
QApplication::sendEvent( myViewPort, e );
}
+//=======================================================================
+// Function: mouseReleaseEvent
+// Purpose :
+//=======================================================================
void GLViewer_Widget::mouseReleaseEvent( QMouseEvent* e )
{
-// cout << "GLViewer_Widget::mouseReleaseEvent" << endl;
QApplication::sendEvent( myViewPort, e );
}
+//=======================================================================
+// Function: enterEvent
+// Purpose :
+//=======================================================================
void GLViewer_Widget::enterEvent( QEvent* e )
{
-// cout << "GLViewer_Widget::enterEvent" << endl;
updateGL();
}
+
+//=======================================================================
+// Function: leaveEvent
+// Purpose :
+//=======================================================================
void GLViewer_Widget::leaveEvent( QEvent* e )
{
-// cout << "GLViewer_Widget::leaveEvent" << endl;
updateGL();
}
return 'a' + c - 10;
}
+//=======================================================================
+// Function: AddImagePart
+// Purpose :
+//=======================================================================
void AddImagePart( QFile& hFile, QImage& image, int w1, int w2, int h1, int h2,
GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS,
double a, double b, double c, double d, double dw, double dh )
}
}
+//=======================================================================
+// Function: getBackgroundRectInViewerCS
+// Purpose :
+//=======================================================================
void GLViewer_Widget::getBackgroundRectInViewerCS( double& left, double& top, double& right, double& bottom )
{
left = -myIW/2; right = myIW/2;
top = myIH/2; bottom = -myIH/2;
}
+//=======================================================================
+// Function: translateBackgroundToPS
+// Purpose :
+//=======================================================================
void GLViewer_Widget::translateBackgroundToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS )
{
QImage buf;
}
}
+//=======================================================================
+// Function: DecodeScanLine
+// Purpose :
+//=======================================================================
void DecodeScanLine( int width, uchar* dest, int dest_depth, uchar* source, int source_depth )
{
#ifndef WIN32
}
}
+//=======================================================================
+// Function: translateBackgroundToEMF
+// Purpose :
+//=======================================================================
#ifdef WIN32
void GLViewer_Widget::translateBackgroundToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS )
{
** Module: GLViewer
** Created: UI team, 27.03.03
****************************************************************************/
+
+/*! Class GLViewer_Widget
+ * Class for visualization OpenGL scene (widget) for GLViewer
+ *
+ */
#ifndef GLVIEWER_WIDGET_H
#define GLVIEWER_WIDGET_H
Q_OBJECT
public:
- GLViewer_Widget( QWidget*, const char* = 0 );
- ~GLViewer_Widget();
-
- GLViewer_ViewPort2d* getViewPort() const { return myViewPort; }
- GLint getWidth() const { return myWidth; }
- GLint getHeight() const { return myHeight; }
-
- void getScale( GLfloat&, GLfloat&, GLfloat& );
- void setScale( GLfloat, GLfloat, GLfloat );
-
- void getPan( GLfloat&, GLfloat&, GLfloat& );
- void setPan( GLfloat, GLfloat, GLfloat );
-
- GLfloat getRotationAngle() const { return myRotationAnglePrev; }
- void setRotationAngle( GLfloat a ) { myRotationAnglePrev = a; }
- void getRotationStart( GLfloat&, GLfloat&, GLfloat& );
- void setRotationStart( GLfloat, GLfloat, GLfloat );
- void getRotation( GLfloat&, GLfloat&, GLfloat&, GLfloat& );
- void setRotation( GLfloat, GLfloat, GLfloat, GLfloat );
- void setBackground( QString );
-
- void addToolTip( QString, QRect );
- void removeToolTip();
-
- void copyBuffers();
- virtual void translateBackgroundToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
-
- void exportRepaint();
+ //! A constructor
+ /*! Parameters using for QOGLWidget as is
+ */
+ GLViewer_Widget( QWidget* theParent, const char* theName = 0 );
+
+ //! A destructor
+ ~GLViewer_Widget();
+
+ //! Returns parent GLViewer_ViewPort2d
+ /*! ViewPort2d because this class is not use for 3D Viewer */
+ GLViewer_ViewPort2d* getViewPort() const { return myViewPort; }
+ //! Returns width of OpenGl Window
+ GLint getWidth() const { return myWidth; }
+ //! Returns height of OpenGl Window
+ GLint getHeight() const { return myHeight; }
+
+ //! Returns scales on OpenGL scene along 3 directions
+ /*! in 2d scene zScale = 1.0 */
+ void getScale( GLfloat& xScale,
+ GLfloat& yScale,
+ GLfloat& zScale );
+ //! A function for installing the scales of OpenGL scene
+ void setScale( GLfloat xScale,
+ GLfloat yScale,
+ GLfloat zScaleGLfloat );
+
+ //! Returns offset parameters of Window in OpenGL global scene
+ void getPan( GLfloat& xPan, GLfloat& yPan, GLfloat& zPan );
+ //! A function for installing the offset parameters of Window in OpenGL global scene
+ void setPan( GLfloat xPan, GLfloat yPan, GLfloat zPan );
+
+ //! Returns rotation angle of Window in OpenGL global scene in degree
+ /*! Only in 2D */
+ GLfloat getRotationAngle() const { return myRotationAnglePrev; }
+ //! A function for installing the rotation angle of Window in OpenGL global scene in degree
+ /*! Only in 2D */
+ void setRotationAngle( GLfloat a ) { myRotationAnglePrev = a; }
+
+ //! Returns start point of curren rotation of Window in OpenGL global scene
+ void getRotationStart( GLfloat& rotationStartX,
+ GLfloat& rotationStartY,
+ GLfloat& rotationStartZ );
+ //! A function for installing the start point of curren rotation of Window in OpenGL global scene
+ void setRotationStart( GLfloat rotationStartX,
+ GLfloat rotationStartY,
+ GLfloat rotationStartZ );
+ //! Returns parameters of current rotation
+ void getRotation( GLfloat& rotationAngle,
+ GLfloat& rotationCenterX,
+ GLfloat& rotationCenterY,
+ GLfloat& rotationCenterZ );
+ //! A function for installing the parameters of current rotation
+ void setRotation( GLfloat, GLfloat, GLfloat, GLfloat );
+
+ //! A function load picture from file with name theFileName and post it in center of global OpenGL scene
+ void setBackground( QString theFileName );
+
+ //! A function add the tool tip with text theTTText on theTTRect rect to the widget window
+ void addToolTip( QString theTTText, QRect theTTRect );
+ //! A function remove tool tip form widget window
+ void removeToolTip();
+
+ //! A function translate background of window in to PostScript file on disk
+ /*!
+ *\param hFile the name of PostScript file chosen by user
+ *\param aViewerCS the GLViewer_CoordSystem of window
+ *\param aPSCS the GLViewer_CoordSystem of PostScript page
+ */
+ virtual void translateBackgroundToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS );
+
+ //! A function repaints OpenGL scene in export mode
+ /* Repaints all objects in only current view */
+ void exportRepaint();
#ifdef WIN32
- virtual void translateBackgroundToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
+ //! A function translate background of window in to EMF file on disk
+ //!
+ /*!
+ *\warning WIN32 only
+ *
+ *\param dc the name of HDC associated with file chosen by user
+ *\param aViewerCS the GLViewer_CoordSystem of window
+ *\param aEMFCS the GLViewer_CoordSystem of EMF page
+ */
+ virtual void translateBackgroundToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS );
#endif
private:
- void getBackgroundRectInViewerCS( double& left, double& top, double& right, double& bottom );
-
+ //! Auxiliary function. Returns rect of window background in viewer coordinate system
+ void getBackgroundRectInViewerCS( double& left, double& top, double& right, double& bottom );
+
protected:
- virtual void initializeGL();
- virtual void paintGL();
- virtual void resizeGL( int, int );
-
- virtual void paintEvent( QPaintEvent* );
- virtual void mouseMoveEvent( QMouseEvent* );
- virtual void mousePressEvent( QMouseEvent* );
- virtual void mouseReleaseEvent( QMouseEvent* );
- virtual void enterEvent( QEvent* );
- virtual void leaveEvent( QEvent* );
-
+ /* Redefined QT methods */
+ //! A function is called before first display of window (create OpenGL scene)
+ virtual void initializeGL();
+ //! A function is called in earch paint event of window
+ /* Calling by public method repaint() */
+ virtual void paintGL();
+ //! A function is called in earch resize event of window
+ virtual void resizeGL( int, int );
+
+
+ virtual void paintEvent( QPaintEvent* );
+ virtual void mouseMoveEvent( QMouseEvent* );
+ virtual void mousePressEvent( QMouseEvent* );
+ virtual void mouseReleaseEvent( QMouseEvent* );
+
+ /* Needs to redefine because Window must be updated highlight presentation when mouse enter window */
+ virtual void enterEvent( QEvent* );
+ /* Needs to redefine because Window must be updated highlight presentation when mouse leave window */
+ virtual void leaveEvent( QEvent* );
+
private:
- GLint myWidth;
- GLint myHeight;
-
- GLfloat myXScale;
- GLfloat myYScale;
- GLfloat myZScale;
-
- GLfloat myXPan;
- GLfloat myYPan;
- GLfloat myZPan;
-
- GLfloat myRotationStartX;
- GLfloat myRotationStartY;
- GLfloat myRotationStartZ;
- GLfloat myRotationAngle;
- GLfloat myRotationCenterX;
- GLfloat myRotationCenterY;
- GLfloat myRotationCenterZ;
- GLfloat myRotationAnglePrev;
-
- GLboolean myStart;
- GLViewer_ViewPort2d* myViewPort;
-
- //new code
- bool isLoadBackground;
- QString myBackgroundFile;
- GLuint texName;
- int myIW;
- int myIH;
- int myBackgroundSize;
-
- //GLubyte*** pixels;
- QRect myToolTipRect;
-
- //for export repaint
- bool isExportMode;
+ //! width of window
+ GLint myWidth;
+ //! height of window
+ GLint myHeight;
+
+ //! Scale along X direction
+ GLfloat myXScale;
+ //! Scale along Y direction
+ GLfloat myYScale;
+ //! Scale along Z direction
+ /* equals 1 in 2D */
+ GLfloat myZScale;
+
+ //! Window offset along X direction
+ GLfloat myXPan;
+ //! Window offset along Y direction
+ GLfloat myYPan;
+ //! Window offset along Z direction
+ /* equals 0 in 2D */
+ GLfloat myZPan;
+
+ GLfloat myRotationStartX;
+ GLfloat myRotationStartY;
+ GLfloat myRotationStartZ;
+ GLfloat myRotationAngle;
+ GLfloat myRotationCenterX;
+ GLfloat myRotationCenterY;
+ GLfloat myRotationCenterZ;
+ GLfloat myRotationAnglePrev;
+
+ GLboolean myStart;
+ GLViewer_ViewPort2d* myViewPort;
+
+ //! True if background is loaded
+ bool isLoadBackground;
+ //! File name of background image
+ QString myBackgroundFile;
+ //! Texture id of loaded background image
+ GLuint texName;
+ //! Width of background image
+ int myIW;
+ //! Height of background image
+ int myIH;
+ //! Size of background image
+ int myBackgroundSize;
+
+ QRect myToolTipRect;
+
+ //! Needs for export repaint
+ bool isExportMode;
};
#endif // GLVIEWER_WIDGET_H