From: ouv Date: Thu, 19 Aug 2010 11:34:55 +0000 (+0000) Subject: Few minor improvements (grid, printing) X-Git-Tag: DIAGRAM_0_1~41 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=a4d9438c358825fb14dbee0ed895aaefe447845c;p=modules%2Fgui.git Few minor improvements (grid, printing) --- diff --git a/src/GLViewer/GLViewer_Drawer.cxx b/src/GLViewer/GLViewer_Drawer.cxx index ec365e067..fb45550e3 100644 --- a/src/GLViewer/GLViewer_Drawer.cxx +++ b/src/GLViewer/GLViewer_Drawer.cxx @@ -485,6 +485,7 @@ GLViewer_Drawer::GLViewer_Drawer() myObjectType = "GLViewer_Object"; myTextFormat = DTF_BITMAP; myTextScale = 0.125; + myIsPrintingModeEnabled = false; } /*! diff --git a/src/GLViewer/GLViewer_Drawer.h b/src/GLViewer/GLViewer_Drawer.h index 853ca8edc..446c90cac 100644 --- a/src/GLViewer/GLViewer_Drawer.h +++ b/src/GLViewer/GLViewer_Drawer.h @@ -395,6 +395,11 @@ public: //! Returns a rectangle of text (without viewer scale) GLViewer_Rect textRect( const QString& ) const; + //! Enables/disables printing mode (in particular, rendering without selection) + void setPrintingModeEnabled( bool theFlag ) { myIsPrintingModeEnabled = theFlag; } + + //! Returns printing mode state + bool isPrintingModeEnabled() const { return myIsPrintingModeEnabled; } //! Draw rectangle with predefined color static void drawRectangle( GLViewer_Rect* theRect, QColor = Qt::black ); @@ -437,6 +442,9 @@ protected: //! Scale factor for text string draw, by default 0.125 //! (used only with text format DTF_TEXTURE_SCALABLE) GLfloat myTextScale; + + //! Printing mode state + bool myIsPrintingModeEnabled; }; #ifdef WIN32 diff --git a/src/GLViewer/GLViewer_Grid.cxx b/src/GLViewer/GLViewer_Grid.cxx index 9420de128..da470d855 100644 --- a/src/GLViewer/GLViewer_Grid.cxx +++ b/src/GLViewer/GLViewer_Grid.cxx @@ -32,10 +32,10 @@ Default constructor */ GLViewer_Grid::GLViewer_Grid() : - myGridList( 0 ), myGridHeight( (GLfloat)0.0 ), myGridWidth( (GLfloat)0.0 ), + myIsEnabled( GL_TRUE ), myGridList( 0 ), myGridHeight( (GLfloat)0.0 ), myGridWidth( (GLfloat)0.0 ), myWinW( (GLfloat)0.0 ), myWinH( (GLfloat)0.0 ), myXSize( (GLfloat)0.0 ), myYSize( (GLfloat)0.0 ), myXPan( (GLfloat)0.0 ), myYPan( (GLfloat)0.0 ), myXScale( (GLfloat)1.0 ), myYScale( (GLfloat)1.0 ), - myLineWidth( (GLfloat)0.05 ), myCenterWidth( (GLfloat)1.5 ), myCenterRadius( (GLfloat)5.0 ), + myLineWidth( (GLfloat)0.05 ), myCenterWidth( (GLfloat)1.5 ), myCenterRadius( 5 ), myScaleFactor( 10 ), myIsUpdate( GL_FALSE ) { myGridColor[0] = 0.5; @@ -59,10 +59,10 @@ GLViewer_Grid::GLViewer_Grid( GLfloat width, GLfloat height, GLfloat xSize, GLfloat ySize, GLfloat xPan, GLfloat yPan, GLfloat xScale, GLfloat yScale ) : - myGridList( 0 ), myGridHeight( (GLfloat)0.0 ), myGridWidth( (GLfloat)0.0 ), + myIsEnabled( GL_TRUE ), myGridList( 0 ), myGridHeight( (GLfloat)0.0 ), myGridWidth( (GLfloat)0.0 ), myWinW( (GLfloat)0.0 ), myWinH( (GLfloat)0.0 ), myXSize( (GLfloat)0.0 ), myYSize( (GLfloat)0.0 ), myXPan( (GLfloat)0.0 ), myYPan( (GLfloat)0.0 ), myXScale( (GLfloat)1.0 ), myYScale( (GLfloat)1.0 ), - myLineWidth( (GLfloat)0.05 ), myCenterWidth( (GLfloat)1.5 ), myCenterRadius( (GLfloat)5.0 ), + myLineWidth( (GLfloat)0.05 ), myCenterWidth( (GLfloat)1.5 ), myCenterRadius( 5 ), myScaleFactor( 10 ), myIsUpdate( GL_FALSE ) { myGridColor[0] = 0.5; @@ -85,12 +85,24 @@ GLViewer_Grid::~GLViewer_Grid() */ void GLViewer_Grid::draw() { + if ( !isEnabled() ) + return; + if ( myGridList == 0 || myIsUpdate ) initList(); glCallList( myGridList ); } +/*! + Sets grid enabled + \param state - enable state +*/ +void GLViewer_Grid::setEnabled( GLboolean state ) +{ + myIsEnabled = state; +} + /*! Changes color of grid \param r, g, b - components of color @@ -122,7 +134,7 @@ void GLViewer_Grid::setAxisColor( GLfloat r, GLfloat g, GLfloat b ) } /*! - Changes grid width + Sets grid width \param w - new grid width */ void GLViewer_Grid::setGridWidth( float w ) @@ -134,6 +146,19 @@ void GLViewer_Grid::setGridWidth( float w ) myIsUpdate = GL_TRUE; } +/*! + Sets grid height + \param h - new grid height +*/ +void GLViewer_Grid::setGridHeight( float h ) +{ + if( myGridHeight == h ) + return; + + myGridHeight = h; + myIsUpdate = GL_TRUE; +} + /*! Sets Radius of center point( begin coords ) \param r - new radius @@ -258,6 +283,19 @@ void GLViewer_Grid::getScale( float& xScale, float& yScale ) const yScale = myYScale; } +/*! + Sets grid scale factor + \param scaleFactor - scale factor +*/ +void GLViewer_Grid::setScaleFactor( int scaleFactor ) +{ + if( myScaleFactor == scaleFactor ) + return; + + myScaleFactor = scaleFactor; + myIsUpdate = GL_TRUE; +} + /*! Initialize grid display list */ @@ -265,10 +303,10 @@ bool GLViewer_Grid::initList() { myIsUpdate = GL_FALSE; - if( myXSize == (GLfloat)0.0 ) - myXSize = (GLfloat)0.1; - if( myYSize == (GLfloat)0.0 ) - myYSize = (GLfloat)0.1; + if( myXSize == (GLfloat)0.0 ) + myXSize = (GLfloat)0.1; + if( myYSize == (GLfloat)0.0 ) + myYSize = (GLfloat)0.1; label: if( ( myXSize >= myGridWidth/5 ) && ( myYSize >= myGridHeight/5 ) ) @@ -295,7 +333,7 @@ label: { glDeleteLists( myGridList, 1 ); if ( glGetError() != GL_NO_ERROR ) - return FALSE; + return FALSE; } float xLoc = (int)(myXPan / myXSize) * myXSize; @@ -334,15 +372,18 @@ label: glVertex2d( 0, -myGridHeight / 2 - myYSize - yLoc ); glEnd(); - glBegin( GL_LINE_LOOP ); - double angle = 0.0; - for ( int k = 0; k < SEGMENTS; k++ ) - { - glVertex2f( cos(angle) * myCenterRadius * myXScale, - sin(angle) * myCenterRadius * myYScale ); - angle += STEP; - } - glEnd(); + if( myCenterRadius > 0 ) + { + glBegin( GL_LINE_LOOP ); + double angle = 0.0; + for ( int k = 0; k < SEGMENTS; k++ ) + { + glVertex2f( cos(angle) * myCenterRadius * myXScale, + sin(angle) * myCenterRadius * myYScale ); + angle += STEP; + } + glEnd(); + } glEndList(); } diff --git a/src/GLViewer/GLViewer_Grid.h b/src/GLViewer/GLViewer_Grid.h index 80f5b33bb..d6ae484e7 100644 --- a/src/GLViewer/GLViewer_Grid.h +++ b/src/GLViewer/GLViewer_Grid.h @@ -66,11 +66,20 @@ public: //! Draws grid void draw(); + //! Sets grid enabled + void setEnabled( GLboolean ); + + //! Returns grid enable state + GLboolean isEnabled() const { return myIsEnabled; } + //! Sets color of grid in RGB format void setGridColor( GLfloat r, GLfloat g, GLfloat b ); //! Sets color of grid axes in RGB format void setAxisColor( GLfloat r, GLfloat g, GLfloat b ); + //! Sets grid width void setGridWidth( float ); + //! Sets grid height + void setGridHeight( float ); //! Sets Radius of center point( begin coords ) void setCenterRadius( int ); @@ -89,12 +98,14 @@ public: //! Sets step of scale void setScaleFactor( int ); - int getScaleFactor(); + int getScaleFactor() const { return myScaleFactor; } protected: //! Initialize grid display list bool initList(); + GLboolean myIsEnabled; + GLuint myGridList; GLfloat myGridColor[3]; GLfloat myAxisColor[3]; diff --git a/src/GLViewer/GLViewer_ViewPort2d.cxx b/src/GLViewer/GLViewer_ViewPort2d.cxx index 669df64dc..855c3ccc7 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.cxx +++ b/src/GLViewer/GLViewer_ViewPort2d.cxx @@ -475,14 +475,19 @@ void GLViewer_ViewPort2d::turnGrid( GLboolean on ) { if( on ) { - myGrid = new GLViewer_Grid( 2*WIDTH, 2*HEIGHT, - 2*WIDTH, 2*HEIGHT, - GRID_XSIZE, GRID_YSIZE, - myXPan, myYPan, - myXScale, myYScale ); + if( !myGrid ) + myGrid = new GLViewer_Grid( 2*WIDTH, 2*HEIGHT, + 2*WIDTH, 2*HEIGHT, + GRID_XSIZE, GRID_YSIZE, + myXPan, myYPan, + myXScale, myYScale ); + myGrid->setEnabled( GL_TRUE ); + } + else + { + if( myGrid ) + myGrid->setEnabled( GL_FALSE ); } - else if( myGrid ) - delete myGrid; } /*! @@ -1441,14 +1446,20 @@ void GLViewer_ViewPort2d::onMaybeTip( QPoint thePoint, QString& theText, QFont& Dumps contents of the scene \param theWholeScene - flag, allowing to dump the whole scene, not only its visible regeion + \param theScale - parameter, allowing to get a scaled image \return image with the scene contents */ -QImage GLViewer_ViewPort2d::dumpContents( bool theWholeScene ) +QImage GLViewer_ViewPort2d::dumpContents( bool theWholeScene, + double theScale ) { QImage aResult; - int aWidth = theWholeScene ? myBorder->width() : myWidth; - int aHeight = theWholeScene ? myBorder->height() : myHeight; + GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer(); + if( !aViewer ) + return aResult; + + int aWidth = theWholeScene ? myBorder->width() * theScale : myWidth; + int aHeight = theWholeScene ? myBorder->height() * theScale : myHeight; // try to initialize framebuffer GLViewer_FrameBuffer aFrameBuffer; @@ -1469,13 +1480,23 @@ QImage GLViewer_ViewPort2d::dumpContents( bool theWholeScene ) // bind the framebuffer aFrameBuffer.bind(); + bool isGridEnabled = ( myGrid && myGrid->isEnabled() ); + if( theWholeScene ) { + // enable printing mode (to disable selection indicating) + aViewer->setPrintingModeEnabled( true ); + + // disable grid + turnGrid( false ); + // centre the scene and reset the scale int aXOffset = myBorder->left(); int aYOffset = myBorder->bottom(); - myGLWidget->setPan( -aWidth/2 - aXOffset, -aHeight/2 - aYOffset, 0.0 ); - myGLWidget->setScale( 1.0, 1.0, 1.0 ); + myGLWidget->setPan( -aWidth / 2 / theScale - aXOffset, + -aHeight / 2 / theScale - aYOffset, + 0.0 ); + myGLWidget->setScale( theScale, theScale, 1.0 ); } // draw the scene to the framebuffer @@ -1503,6 +1524,12 @@ QImage GLViewer_ViewPort2d::dumpContents( bool theWholeScene ) if( theWholeScene ) { + // disable printing mode (to enable selection indicating) + aViewer->setPrintingModeEnabled( false ); + + // restore grid enable state + turnGrid( isGridEnabled ); + // restore the scene parameters myGLWidget->setPan( myXPan, myYPan, 0.0 ); myGLWidget->setScale( myXScale, myYScale, 1.0 ); diff --git a/src/GLViewer/GLViewer_ViewPort2d.h b/src/GLViewer/GLViewer_ViewPort2d.h index fed5967d4..8d9419ae1 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.h +++ b/src/GLViewer/GLViewer_ViewPort2d.h @@ -168,7 +168,8 @@ public: QRect GLV2win( const GLViewer_Rect& ) const; //! Dumps contents of the scene - QImage dumpContents( bool theWholeScene = false ); + QImage dumpContents( bool theWholeScene = false, + double theScale = 1.0 ); signals: //! Emits after any transformation diff --git a/src/GLViewer/GLViewer_Viewer2d.cxx b/src/GLViewer/GLViewer_Viewer2d.cxx index 2fb24d28b..f6e7f7005 100644 --- a/src/GLViewer/GLViewer_Viewer2d.cxx +++ b/src/GLViewer/GLViewer_Viewer2d.cxx @@ -344,6 +344,18 @@ void GLViewer_Viewer2d::activateAllDrawers( bool onlyUpdate, GLboolean swap ) activateDrawers( anActiveObjs, onlyUpdate, swap ); } +/*! + Enables/disables printing mode (in particular, rendering without selection) + \param theFlag printing mode state +*/ +void GLViewer_Viewer2d::setPrintingModeEnabled( bool theFlag ) +{ + QList::iterator anIter, anIterEnd = myDrawers.end(); + for( anIter = myDrawers.begin(); anIter != anIterEnd; anIter++ ) + if( GLViewer_Drawer* aDrawer = *anIter ) + aDrawer->setPrintingModeEnabled( theFlag ); +} + /*! Creates set of marker \param theMarkersNum - number of markers diff --git a/src/GLViewer/GLViewer_Viewer2d.h b/src/GLViewer/GLViewer_Viewer2d.h index 7b7956fe7..33d35bbde 100644 --- a/src/GLViewer/GLViewer_Viewer2d.h +++ b/src/GLViewer/GLViewer_Viewer2d.h @@ -144,6 +144,9 @@ public: /* \param onlyUpdate is passed to drawers*/ void activateAllDrawers( bool onlyUpdate, GLboolean swap = GL_FALSE ); + //! Enables/disables printing mode (in particular, rendering without selection) + void setPrintingModeEnabled( bool theFlag ); + //! Translates point (x,y) from global CS to curreent viewer CS void transPoint( GLfloat& x, GLfloat& y ); //! Returns object rect in window CS