X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FGLViewer%2FGLViewer_Widget.cxx;h=a12208c73354396fb641b2e98623f518e626505c;hb=refs%2Fheads%2Fngr%2Fpython3_dev_pv5.4;hp=b430332e19a9d6320c634b95d39c288324a5ad41;hpb=db4f3a2c934f44335bca0e70fec9aed00c8c29fd;p=modules%2Fgui.git diff --git a/src/GLViewer/GLViewer_Widget.cxx b/src/GLViewer/GLViewer_Widget.cxx index b430332e1..a12208c73 100644 --- a/src/GLViewer/GLViewer_Widget.cxx +++ b/src/GLViewer/GLViewer_Widget.cxx @@ -1,39 +1,46 @@ -// File: GLViewer_Widget.cxx -// Created: November, 2004 -// Author: OCC team -// Copyright (C) CEA 2004 - -//================================================================ -// Class : GLViewer_Widget -// Description : OpenGL QWidget for GLViewer -//================================================================ +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// #include "GLViewer_Widget.h" #include "GLViewer_ViewPort2d.h" #include "GLViewer_Viewer2d.h" -#include "GLViewer_Compass.h" #include "GLViewer_Grid.h" -#include "GLViewer_Object.h" #include "GLViewer_CoordSystem.h" +#include "GLViewer_ViewFrame.h" #include -using namespace std; - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -//======================================================================= -// Function: GLViewer_Widget -// Purpose : -//======================================================================= + +#include +#include +#include +#include +#include +#include +#include + +/*! + A constructor + Parameters using for QOGLWidget as is +*/ GLViewer_Widget::GLViewer_Widget( QWidget* parent, const char* name ): QGLWidget( parent, 0/*, WRepaintNoErase | WResizeNoErase*/ ) { @@ -59,18 +66,16 @@ QGLWidget( parent, 0/*, WRepaintNoErase | WResizeNoErase*/ ) setMouseTracking( true ); } -//======================================================================= -// Function: GLViewer_Widget -// Purpose : -//======================================================================= +/*! + Destructor +*/ GLViewer_Widget::~GLViewer_Widget() { } -//======================================================================= -// Function: ~GLViewer_Widget -// Purpose : -//======================================================================= +/*! + \return offset parameters of Window in OpenGL global scene +*/ void GLViewer_Widget::getPan( GLfloat& xPan, GLfloat& yPan, GLfloat& zPan ) { xPan = myXPan; @@ -78,10 +83,9 @@ void GLViewer_Widget::getPan( GLfloat& xPan, GLfloat& yPan, GLfloat& zPan ) zPan = myZPan; } -//======================================================================= -// Function: setPan -// Purpose : -//======================================================================= +/*! + A function for installing the offset parameters of Window in OpenGL global scene +*/ void GLViewer_Widget::setPan( GLfloat xPan, GLfloat yPan, GLfloat zPan ) { myXPan = xPan; @@ -89,10 +93,9 @@ void GLViewer_Widget::setPan( GLfloat xPan, GLfloat yPan, GLfloat zPan ) myZPan = zPan; } -//======================================================================= -// Function: getScale -// Purpose : -//======================================================================= +/*! + \return scales on OpenGL scene along 3 directions in 2d scene zScale = 1.0 +*/ void GLViewer_Widget::getScale( GLfloat& xScale, GLfloat& yScale, GLfloat& zScale ) { xScale = myXScale; @@ -100,10 +103,9 @@ void GLViewer_Widget::getScale( GLfloat& xScale, GLfloat& yScale, GLfloat& zScal zScale = myZScale; } -//======================================================================= -// Function: setScale -// Purpose : -//======================================================================= +/*! + A function for installing the scales of OpenGL scene +*/ void GLViewer_Widget::setScale( GLfloat xScale, GLfloat yScale, GLfloat zScale ) { if ( xScale > 0 && yScale > 0 && zScale > 0 ) @@ -114,12 +116,11 @@ void GLViewer_Widget::setScale( GLfloat xScale, GLfloat yScale, GLfloat zScale ) } } -//======================================================================= -// Function: getRotationStart -// Purpose : -//======================================================================= +/*! + \return start point of curren rotation of Window in OpenGL global scene +*/ void GLViewer_Widget::getRotationStart( GLfloat& rotationStartX, - GLfloat& rotationStartY, + GLfloat& rotationStartY, GLfloat& rotationStartZ ) { rotationStartX = myRotationStartX; @@ -127,12 +128,11 @@ void GLViewer_Widget::getRotationStart( GLfloat& rotationStartX, rotationStartZ = myRotationStartZ; } -//======================================================================= -// Function: setRotationStart -// Purpose : -//======================================================================= +/*! + A function for installing the rotation angle of Window in OpenGL global scene in degree (Only in 2D) +*/ void GLViewer_Widget::setRotationStart( GLfloat rotationStartX, - GLfloat rotationStartY, + GLfloat rotationStartY, GLfloat rotationStartZ ) { myRotationStartX = rotationStartX; @@ -140,14 +140,17 @@ void GLViewer_Widget::setRotationStart( GLfloat rotationStartX, myRotationStartZ = rotationStartZ; } -//======================================================================= -// Function: getRotation -// Purpose : -//======================================================================= +/*! + \return parameters of rotation + \param rotationAngle - angle + \param rotationCenterX - center x + \param rotationCenterY - center y + \param rotationCenterZ - center z +*/ void GLViewer_Widget::getRotation( GLfloat& rotationAngle, - GLfloat& rotationCenterX, - GLfloat& rotationCenterY, - GLfloat& rotationCenterZ ) + GLfloat& rotationCenterX, + GLfloat& rotationCenterY, + GLfloat& rotationCenterZ ) { rotationAngle = myRotationAngle; rotationCenterX = myRotationCenterX; @@ -155,14 +158,17 @@ void GLViewer_Widget::getRotation( GLfloat& rotationAngle, rotationCenterZ = myRotationCenterZ; } -//======================================================================= -// Function: setRotation -// Purpose : -//======================================================================= +/*! + Sets parameters of rotation + \param rotationAngle - angle + \param rotationCenterX - center x + \param rotationCenterY - center y + \param rotationCenterZ - center z +*/ void GLViewer_Widget::setRotation( GLfloat rotationAngle, - GLfloat rotationCenterX, - GLfloat rotationCenterY, - GLfloat rotationCenterZ ) + GLfloat rotationCenterX, + GLfloat rotationCenterY, + GLfloat rotationCenterZ ) { myRotationAngle = rotationAngle; myRotationCenterX = rotationCenterX; @@ -170,10 +176,11 @@ void GLViewer_Widget::setRotation( GLfloat rotationAngle, myRotationCenterZ = rotationCenterZ; } -//======================================================================= -// Function: setBackground -// Purpose : -//======================================================================= + +/*! + Sets image as background + \param filename - name of file +*/ void GLViewer_Widget::setBackground( QString filename ) { @@ -226,29 +233,30 @@ void GLViewer_Widget::setBackground( QString filename ) } } -//======================================================================= -// Function: addToolTip -// Purpose : -//======================================================================= +/*! + Adds tooltip + \param theString - tooltip text + \param theRect - tooltip rectangle +*/ void GLViewer_Widget::addToolTip( QString theString, QRect theRect ) { myToolTipRect = theRect; - QToolTip::add( this, myToolTipRect, theString ); + setToolTip(theString); + //QToolTip::add( this, myToolTipRect, theString ); } -//======================================================================= -// Function: removeToolTip -// Purpose : -//======================================================================= +/*! + Removes tooltip +*/ void GLViewer_Widget::removeToolTip() { - QToolTip::remove( this, myToolTipRect ); + setToolTip(""); + //QToolTip::remove( this, myToolTipRect ); } -//======================================================================= -// Function: initializeGL -// Purpose : -//======================================================================= +/*! + Initialization (redefined virtual from QGLWidget) +*/ void GLViewer_Widget::initializeGL() { setAutoBufferSwap( true ); @@ -270,10 +278,9 @@ void GLViewer_Widget::initializeGL() isLoadBackground = false; } -//======================================================================= -// Function: paintGL -// Purpose : -//======================================================================= +/*! + Paints content +*/ void GLViewer_Widget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); @@ -316,10 +323,11 @@ void GLViewer_Widget::paintGL() v->repaintView( getViewPort()->getViewFrame() ); } -//======================================================================= -// Function: resizeGL -// Purpose : -//======================================================================= +/*! + Resets OpenGl parameters after resize + \param w - new width + \param h - new height +*/ void GLViewer_Widget::resizeGL( int w, int h ) { @@ -346,10 +354,9 @@ void GLViewer_Widget::resizeGL( int w, int h ) glLoadIdentity(); } -//======================================================================= -// Function: exportRepaint -// Purpose : -//======================================================================= +/*! + Provides repaint in export mode +*/ void GLViewer_Widget::exportRepaint() { isExportMode = true; @@ -359,127 +366,154 @@ void GLViewer_Widget::exportRepaint() isExportMode = false; } -//======================================================================= -// Function: paintEvent -// Purpose : -//======================================================================= +/*! + Custom paint event handler +*/ void GLViewer_Widget::paintEvent( QPaintEvent* e ) { QApplication::sendEvent( myViewPort, e ); } -//======================================================================= -// Function: mouseMoveEvent -// Purpose : -//======================================================================= +/*! + Custom mouse move event handler +*/ void GLViewer_Widget::mouseMoveEvent( QMouseEvent* e ) { QApplication::sendEvent( myViewPort, e ); } -//======================================================================= -// Function: mousePressEvent -// Purpose : -//======================================================================= +/*! + Custom mouse press event handler +*/ void GLViewer_Widget::mousePressEvent( QMouseEvent* e ) { QApplication::sendEvent( myViewPort, e ); } -//======================================================================= -// Function: mouseReleaseEvent -// Purpose : -//======================================================================= +/*! + Custom mouse release event handler +*/ void GLViewer_Widget::mouseReleaseEvent( QMouseEvent* e ) { QApplication::sendEvent( myViewPort, e ); } -//======================================================================= -// Function: enterEvent -// Purpose : -//======================================================================= +/*! + Custom enter event handler +*/ void GLViewer_Widget::enterEvent( QEvent* e ) { updateGL(); } -//======================================================================= -// Function: leaveEvent -// Purpose : -//======================================================================= +/*! + Custom leave event handler +*/ void GLViewer_Widget::leaveEvent( QEvent* e ) { updateGL(); } +/*! + Custom leave event handler +*/ +bool GLViewer_Widget::event ( QEvent* e ) +{ + if (e->type() == QEvent::ToolTip) { + QHelpEvent *helpEvent = static_cast(e); + if ( myToolTipRect.contains(helpEvent->pos()) ) + QToolTip::showText(helpEvent->globalPos(), toolTip()); + } + return QGLWidget::event(e); +} + +/*! + \return the hex code of digit < 16 + \param c - digit +*/ inline char hex( uchar c ) { if( c<=9 ) return '0'+c; - else + else if( c < 16 ) return 'a' + c - 10; + + return ' '; } -//======================================================================= -// Function: AddImagePart -// Purpose : -//======================================================================= +/*! + Translates part of image inside rectangle from w1 to w2 and from h2 to h1 to PS format + \param hFile - PostScript file + \param image - image to be tarnslated + \param w1 - x start position + \param w2 - x end position + \param h1 - y start position + \param h2 - y end position + \param aViewerCS - viewer co-ordinate system + \param aPSCS - paper co-ordinate system + \param a + \param b + \param c + \param d + \param dw + \param dh +*/ 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 ) { - if( aViewerCS && aPSCS ) - { - double width = w2-w1+1, height = h2-h1+1; - QString aBuffer = "", temp = "%1 %2 8 [ %3 %4 %5 %6 %7 %8 ]\n"; - aBuffer += temp.arg( width ).arg( height ). + if( aViewerCS && aPSCS ) + { + double width = w2-w1+1, height = h2-h1+1; + QString aBuffer = "", temp = "%1 %2 8 [ %3 %4 %5 %6 %7 %8 ]\n"; + aBuffer += temp.arg( width ).arg( height ). arg( a ).arg( b ).arg( c ).arg( d ). arg( dw ).arg( dh ); - aBuffer += "<\n"; - - char line[81]; line[80] = '\0'; int cur_index = 0; - int full = 0; - for( int i=h2; i>=h1; i-- ) - { - uchar* theCurLine = image.scanLine( i ), cur; - for( int j=w1; j<=w2; j++ ) - for( int k=0; k<3; k++ ) - { - cur = *(theCurLine+4*j+2-k); - *(line+cur_index) = hex( cur/16 ); //HI - *(line+cur_index+1) = hex( cur%16 ); //LO - full++; - cur_index+=2; - if( cur_index>=80 ) - { - aBuffer += line; - aBuffer += "\n"; - cur_index = 0; - } - } - } - - aBuffer += "> false 3 colorimage\n\n"; - - hFile.writeBlock( aBuffer.ascii(), aBuffer.length() ); + aBuffer += "<\n"; + + char line[81]; line[80] = '\0'; int cur_index = 0; + int full = 0; + for( int i=h2; i>=h1; i-- ) + { + uchar* theCurLine = image.scanLine( i ), cur; + for( int j=w1; j<=w2; j++ ) + for( int k=0; k<3; k++ ) + { + cur = *(theCurLine+4*j+2-k); + *(line+cur_index) = hex( cur/16 ); //HI + *(line+cur_index+1) = hex( cur%16 ); //LO + full++; + cur_index+=2; + if( cur_index>=80 ) + { + aBuffer += line; + aBuffer += "\n"; + cur_index = 0; + } + } } + + aBuffer += "> false 3 colorimage\n\n"; + + hFile.write( aBuffer.toLatin1() ); + } } -//======================================================================= -// Function: getBackgroundRectInViewerCS -// Purpose : -//======================================================================= +/*! + \return background rectangle in viewer CS +*/ void GLViewer_Widget::getBackgroundRectInViewerCS( double& left, double& top, double& right, double& bottom ) { - left = -myIW/2; right = myIW/2; - top = myIH/2; bottom = -myIH/2; + left = -myIW/2; right = myIW/2; + top = myIH/2; bottom = -myIH/2; } -//======================================================================= -// Function: translateBackgroundToPS -// Purpose : -//======================================================================= +/*! + Translates background to PostScript + \param hFile - PostScript file + \param aViewerCS - viewer co-ordinate system + \param aPSCS - paper co-ordinate system +*/ void GLViewer_Widget::translateBackgroundToPS( QFile& hFile, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aPSCS ) { QImage buf; @@ -521,15 +555,14 @@ void GLViewer_Widget::translateBackgroundToPS( QFile& hFile, GLViewer_CoordSyste const int max = 133000; //The maximum length of string in PS int dh = int( floor( double( max ) / ( 3.0*2.0*width ) ) ); for( int k=buf.height()-1; k>=0; k-=dh ) - AddImagePart( hFile, buf, 0, buf.width()-1, QMAX( k-dh+1, 0 ), k, + AddImagePart( hFile, buf, 0, buf.width()-1, qMax( k-dh+1, 0 ), k, aViewerCS, aPSCS, a, b, c, d, dx, dy-(buf.height()-1-k) ); } } -//======================================================================= -// Function: DecodeScanLine -// Purpose : -//======================================================================= +/*! + Translates image line with one color depth to line with other depth +*/ void DecodeScanLine( int width, uchar* dest, int dest_depth, uchar* source, int source_depth ) { #ifndef WIN32 @@ -593,11 +626,13 @@ typedef unsigned int WORD; } } -//======================================================================= -// Function: translateBackgroundToEMF -// Purpose : -//======================================================================= #ifdef WIN32 +/*! + Translates background to EMF + \param dc - descriptor of EMF + \param aViewerCS - viewer co-ordinate system + \param aPSCS - paper co-ordinate system +*/ void GLViewer_Widget::translateBackgroundToEMF( HDC dc, GLViewer_CoordSystem* aViewerCS, GLViewer_CoordSystem* aEMFCS ) { QImage buf;