myObjectType = "GLViewer_Object";
myTextFormat = DTF_BITMAP;
myTextScale = 0.125;
+ myIsPrintingModeEnabled = false;
}
/*!
//! 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 );
//! 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
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;
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;
*/
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
}
/*!
- Changes grid width
+ Sets grid width
\param w - new grid width
*/
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
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
*/
{
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 ) )
{
glDeleteLists( myGridList, 1 );
if ( glGetError() != GL_NO_ERROR )
- return FALSE;
+ return FALSE;
}
float xLoc = (int)(myXPan / myXSize) * myXSize;
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();
}
//! 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 );
//! 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];
{
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;
}
/*!
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;
// 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
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 );
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
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<GLViewer_Drawer*>::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
/* \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