From 41bc45116b3e954885d6913f73a2fbfc7900b835 Mon Sep 17 00:00:00 2001 From: stv Date: Wed, 26 Mar 2008 09:51:25 +0000 Subject: [PATCH] *** empty log message *** --- src/GLViewer/GLViewer_ViewFrame.cxx | 212 ++------------------- src/GLViewer/GLViewer_ViewFrame.h | 45 ++--- src/GLViewer/GLViewer_ViewPort2d.cxx | 265 ++++++++++++++------------- src/GLViewer/GLViewer_Viewer2d.cxx | 15 +- 4 files changed, 181 insertions(+), 356 deletions(-) diff --git a/src/GLViewer/GLViewer_ViewFrame.cxx b/src/GLViewer/GLViewer_ViewFrame.cxx index dd563adb5..54ca3ce7e 100644 --- a/src/GLViewer/GLViewer_ViewFrame.cxx +++ b/src/GLViewer/GLViewer_ViewFrame.cxx @@ -60,17 +60,14 @@ GLViewer_ViewFrame::GLViewer_ViewFrame( SUIT_Desktop* d, GLViewer_Viewer* vw ) myViewer( vw ), myVP( 0 ) { - QFrame* client = new QFrame( this ); + QFrame* client = new QFrame( this ); setCentralWidget( client ); QBoxLayout* layout = new QHBoxLayout( client ); - layout->setMargin(1); - layout->setSpacing(1); + layout->setMargin( 0 ); + layout->setSpacing( 0 ); GLViewer_ViewPort2d* vp = new GLViewer_ViewPort2d( client, this ); - //vp->turnGrid( true ); - //vp->turnCompass( true ); - //vp->enablePopup( false ); setViewPort( vp ); setBackgroundColor( Qt::white ); layout->addWidget( vp ); @@ -98,7 +95,7 @@ void GLViewer_ViewFrame::createActions() aAction = new QtxAction(tr("MNU_DUMP_VIEW"), aResMgr->loadPixmap( "GLViewer", tr( "ICON_GL_DUMP" ) ), tr( "MNU_DUMP_VIEW" ), 0, this); aAction->setStatusTip(tr("DSC_DUMP_VIEW")); - connect(aAction, SIGNAL(activated()), this, SLOT(onViewDump())); + connect(aAction, SIGNAL(activated()), this, SLOT(onDumpView())); toolMgr()->registerAction( aAction, DumpId ); // FitAll @@ -270,189 +267,16 @@ void GLViewer_ViewFrame::onUpdate( int ) /*! SLOT: called on dump view operation is activated, stores scene to raster file */ -void GLViewer_ViewFrame::onViewDump() -{ - GLViewer_Widget* aWidget = ((GLViewer_ViewPort2d*)myVP)->getGLWidget(); - int width, height; - width = aWidget->width(); - height = aWidget->height(); - - int imageSize = width*height*3; - unsigned char* imageBits = NULL; - - int reserve_bytes = width % 4; //32 bits platform - imageSize = (width+reserve_bytes)*height*3; - imageBits = new unsigned char[imageSize]; - - -#ifdef WIN32 - - int num; - HBITMAP hBmp; - HDC hdc_old, hdc; - HGLRC hglrc_old, hglrc; - - BITMAPINFO bi; - - hglrc_old = wglGetCurrentContext(); - hdc_old = wglGetCurrentDC(); - - hdc = CreateCompatibleDC( hdc_old ); - if( !hdc ) - { - cout << "Can't create compatible DC. Last Error Code: " << GetLastError() << endl; - return; - } - - int sizeBmi = Standard_Integer( sizeof(BITMAPINFO) + sizeof(RGBQUAD)*3 ); - PBITMAPINFO pBmi = (PBITMAPINFO)( new char[sizeBmi] ); - ZeroMemory( pBmi, sizeBmi ); - - pBmi->bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); //sizeBmi - pBmi->bmiHeader.biWidth = width; - pBmi->bmiHeader.biHeight = height; - pBmi->bmiHeader.biPlanes = 1; - pBmi->bmiHeader.biBitCount = 24; - pBmi->bmiHeader.biCompression = BI_RGB; - - LPVOID ppvBits; - hBmp = CreateDIBSection ( hdc, pBmi, DIB_RGB_COLORS, &ppvBits, NULL, 0 ); - SelectObject ( hdc, hBmp ); - delete[] pBmi; - - PIXELFORMATDESCRIPTOR pfd; - ZeroMemory( &pfd, sizeof( PIXELFORMATDESCRIPTOR ) ); - pfd.nSize = sizeof( PIXELFORMATDESCRIPTOR ); - pfd.nVersion = 1; - pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_BITMAP; - pfd.iPixelType = PFD_TYPE_RGBA; - pfd.cColorBits = 24; - pfd.cDepthBits = 32; - pfd.iLayerType = PFD_MAIN_PLANE; - - int iPf = ChoosePixelFormat( hdc, &pfd); - if( iPf == 0 ) - { - if ( !DescribePixelFormat ( hdc, iPf, sizeof(PIXELFORMATDESCRIPTOR), &pfd ) ) - { - cout << "Can't describe Pixel Format. Last Error Code: " << GetLastError() << endl; - } - } - if ( !SetPixelFormat(hdc, iPf, &pfd) ) - { - cout << "Can't set Pixel Format. Last Error Code: " << GetLastError() << endl; - } - - hglrc = wglCreateContext( hdc ); - if( !hglrc ) - { - cout << "Can't create new GL Context. Last Error Code: " << GetLastError() << endl; - return; - } - if( !wglMakeCurrent( hdc, hglrc) ) - { - cout << "Can't make current new context!" << endl; - return; - } - - glViewport( 0, 0, width, height ); - - glMatrixMode( GL_PROJECTION ); - glLoadIdentity(); - GLfloat w_c = width / 2., h_c = height / 2.; - - gluOrtho2D( -w_c, w_c, -h_c, h_c ); - - glMatrixMode( GL_MODELVIEW ); - glLoadIdentity(); - - //set background - QColor aColor = ((GLViewer_ViewPort2d*)myVP)->backgroundColor(); - glClearColor( ( GLfloat )aColor.red() / 255, - ( GLfloat )aColor.green() / 255, - ( GLfloat )aColor.blue() / 255, - 1.0 ); - - aWidget->exportRepaint(); - - memset(&bi, 0, sizeof(BITMAPINFOHEADER)); - bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); - bi.bmiHeader.biPlanes = 1; - bi.bmiHeader.biBitCount = 24; - bi.bmiHeader.biHeight = -height; - bi.bmiHeader.biWidth = width; - bi.bmiHeader.biCompression = BI_RGB; - - num = GetDIBits(hdc, hBmp, 0, height, imageBits, &bi, DIB_RGB_COLORS); - wglMakeCurrent( hdc_old, hglrc_old ); - wglDeleteContext( hglrc ); - - -#else //XWindows -#endif - - unsigned int* aPix = NULL; - QImage anImage( width, height, QImage::Format_RGB32 ); - for( int i = 0; i < height; i++ ) - { - memset( anImage.scanLine( i ), 0, sizeof(unsigned int)*width ); - unsigned char* pos; - for( int j = 0; j < width; j++ ) - { - pos = imageBits + i*width*3 + j*3 + reserve_bytes*i; - aPix = (unsigned int*)anImage.scanLine(i)+j; - *aPix = qRgb( *pos, *(pos+1), *(pos+2) ); - } - } - - delete [] imageBits; - - QString aFilter( "*.bmp\n*.png" ); - - QFileDialog aFileDlg( this, tr( "DUMP_VIEW_SAVE_FILE_DLG_CAPTION" ), QDir::current().absolutePath(), aFilter ); - aFileDlg.setFileMode( QFileDialog::AnyFile ); - - if( !aFileDlg.exec() ) - return; - - QStringList files = aFileDlg.selectedFiles(); - QString aFileName; - if ( !files.isEmpty() ) aFileName = files[0]; - - QString aFileExt = aFileDlg.selectedFilter(); - - if( aFileName.isEmpty() ) - { - SUIT_MessageBox::critical( this, - tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ), - tr( "DUMP_VIEW_ERROR_DLG_TEXT" ) ); - } +QImage GLViewer_ViewFrame::dumpView() +{ + QImage img; - QString aSaveOp = "BMP"; - QString aTypedFileExt = QFileInfo( aFileName ).suffix().toLower(); + GLViewer_Widget* aWidget = ((GLViewer_ViewPort2d*)myVP)->getGLWidget(); + if ( aWidget ) + img = aWidget->grabFrameBuffer(); - if( aFileExt == "*.bmp" ) - { - if( aTypedFileExt.isEmpty() ) - aFileName += ".bmp"; - aSaveOp = "BMP"; - } - else if( aFileExt == "*.png" ) - if( aTypedFileExt.isEmpty() ) - aFileName += ".png"; - aSaveOp = "PNG"; - -//#ifdef WIN32 -// if( !anImage.save( aFileName, aSaveOp ) ) -//#else - if( !aWidget->grabFrameBuffer().save( aFileName, aSaveOp.toLatin1().constData() ) ) -//#endif - { - SUIT_MessageBox::critical( this, - tr( "DUMP_VIEW_ERROR_DLG_CAPTION" ), - tr( "DUMP_VIEW_ERROR_DLG_TEXT" ) ); - } + return img; } /*! @@ -483,7 +307,7 @@ void GLViewer_ViewFrame::onViewFitAll() Start fit area */ void GLViewer_ViewFrame::onViewFitArea() -{ +{ myViewer->activateTransform( GLViewer_Viewer::FitRect ); } @@ -491,7 +315,7 @@ void GLViewer_ViewFrame::onViewFitArea() Start fit selected */ void GLViewer_ViewFrame::onViewFitSelect() -{ +{ myViewer->activateTransform( GLViewer_Viewer::FitSelect ); } @@ -499,7 +323,7 @@ void GLViewer_ViewFrame::onViewFitSelect() Start global panning */ void GLViewer_ViewFrame::onViewGlobalPan() -{ +{ myViewer->activateTransform( GLViewer_Viewer::PanGlobal ); } @@ -507,7 +331,7 @@ void GLViewer_ViewFrame::onViewGlobalPan() Start rotating */ void GLViewer_ViewFrame::onViewRotate() -{ +{ //myViewer->activateTransform( GLViewer_Viewer::Rotate ); } @@ -515,11 +339,11 @@ void GLViewer_ViewFrame::onViewRotate() Start reset default view aspects */ void GLViewer_ViewFrame::onViewReset() -{ +{ myViewer->activateTransform( GLViewer_Viewer::Reset ); } - -/*! + +/*! Dispatches mouse events */ void GLViewer_ViewFrame::mouseEvent( QMouseEvent* e ) diff --git a/src/GLViewer/GLViewer_ViewFrame.h b/src/GLViewer/GLViewer_ViewFrame.h index 03a9687e8..f2fd165bf 100644 --- a/src/GLViewer/GLViewer_ViewFrame.h +++ b/src/GLViewer/GLViewer_ViewFrame.h @@ -49,7 +49,7 @@ class GLViewer_ViewPort; class GLVIEWER_API GLViewer_ViewFrame: public SUIT_ViewWindow { Q_OBJECT - + public: //! Actions ID enum { DumpId, FitAllId, FitRectId, FitSelectId, ZoomId, PanId, GlobalPanId, ResetId }; @@ -57,59 +57,60 @@ public: public: GLViewer_ViewFrame( SUIT_Desktop* , GLViewer_Viewer* ); ~GLViewer_ViewFrame(); - -public: + +public: void setViewer( GLViewer_Viewer* ); GLViewer_Viewer* getViewer() const; - + void setViewPort( GLViewer_ViewPort* ); GLViewer_ViewPort* getViewPort() const; - + void setBackgroundColor( const QColor& ); QColor backgroundColor() const; - + QSize sizeHint() const; - + virtual void onUpdate( int ); virtual QString getVisualParameters(); - virtual void setVisualParameters( const QString& parameters ); - + virtual void setVisualParameters( const QString& parameters ); + + virtual QImage dumpView(); + signals: void vfDrawExternal( QPainter* ); void vfViewClosing( QCloseEvent* ); - + protected: GLViewer_Viewer* myViewer; GLViewer_ViewPort* myVP; - + public: - //ViewType getTypeView() const { return VIEW_GL; }; + //ViewType getTypeView() const { return VIEW_GL; }; QWidget* getViewWidget() { return ( QWidget* )getViewPort(); }; - + protected slots: - void onViewDump(); void onViewPan(); void onViewZoom(); void onViewFitAll(); void onViewFitArea(); void onViewFitSelect(); - void onViewGlobalPan(); + void onViewGlobalPan(); void onViewRotate(); void onViewReset(); - void onViewFront() {}; - void onViewBack() {}; - void onViewRight() {}; - void onViewLeft() {}; + void onViewFront() {}; + void onViewBack() {}; + void onViewRight() {}; + void onViewLeft() {}; void onViewBottom() {}; void onViewTop() {}; - void onViewTrihedron() {}; - + void onViewTrihedron() {}; + private slots: void keyEvent( QKeyEvent* ); void mouseEvent( QMouseEvent* ); void wheelEvent( QWheelEvent* ); - + private: void createActions(); void createToolBar(); diff --git a/src/GLViewer/GLViewer_ViewPort2d.cxx b/src/GLViewer/GLViewer_ViewPort2d.cxx index d80bddadb..3293fd8ec 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.cxx +++ b/src/GLViewer/GLViewer_ViewPort2d.cxx @@ -69,41 +69,44 @@ void rotate_point( float& theX, float& theY, float theAngle ) /*! Constructor */ -GLViewer_ViewPort2d::GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame ) : - GLViewer_ViewPort( parent ), - myMargin( MARGIN ), myWidth( WIDTH ), myHeight( HEIGHT ), - myXScale( 1.0 ), myYScale( 1.0 ), myXOldScale( 1.0 ), myYOldScale( 1.0 ), - myXPan( 0.0 ), myYPan( 0.0 ), - myIsMouseReleaseBlock( false ), - myRectBand(0) +GLViewer_ViewPort2d::GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame ) +: GLViewer_ViewPort( parent ), + myMargin( MARGIN ), myWidth( WIDTH ), myHeight( HEIGHT ), + myXScale( 1.0 ), myYScale( 1.0 ), myXOldScale( 1.0 ), myYOldScale( 1.0 ), + myXPan( 0.0 ), myYPan( 0.0 ), + myIsMouseReleaseBlock( false ), + myRectBand( 0 ) { - if( theViewFrame == NULL ) - myViewFrame = ( GLViewer_ViewFrame* )parent; - else - myViewFrame = theViewFrame; + if ( !theViewFrame ) + myViewFrame = (GLViewer_ViewFrame*)parent; + else + myViewFrame = theViewFrame; - myGrid = 0; - myCompass = 0; - myBorder = new GLViewer_Rect(); + myGrid = 0; + myCompass = 0; + myBorder = new GLViewer_Rect(); - QBoxLayout* qbl = new QHBoxLayout( this ); - myGLWidget = new GLViewer_Widget( this, 0 ) ; - qbl->addWidget( myGLWidget ); - myGLWidget->setFocusProxy( this ); - setMouseTracking( TRUE ); + QBoxLayout* qbl = new QHBoxLayout( this ); + qbl->setSpacing( 0 ); + qbl->setMargin( 0 ); - myIsDragProcess = noDrag; - //myCurDragMousePos = QPoint(); - myCurDragPosX = NULL; - myCurDragPosY = NULL; + myGLWidget = new GLViewer_Widget( this, 0 ) ; + qbl->addWidget( myGLWidget ); + myGLWidget->setFocusProxy( this ); + setMouseTracking( TRUE ); - myIsPulling = false; + myIsDragProcess = noDrag; + //myCurDragMousePos = QPoint(); + myCurDragPosX = NULL; + myCurDragPosY = NULL; - myViewPortId = aLastViewPostId; - aLastViewPostId++; + myIsPulling = false; - mypFirstPoint = NULL; - mypLastPoint = NULL; + myViewPortId = aLastViewPostId; + aLastViewPostId++; + + mypFirstPoint = NULL; + mypLastPoint = NULL; // TODO: Porting to Qt4 /*myObjectTip = new QtxToolTip( myGLWidget );///GLViewer_ObjectTip( this ); @@ -146,20 +149,20 @@ void GLViewer_ViewPort2d::onStartDragObject( ) myCurDragPosX = NULL; myCurDragPosY = NULL; return; - } + } } /*! SLOT: cuts object to clipboard */ void GLViewer_ViewPort2d::onCutObject() -{ +{ /*GLViewer_Object* aMovingObject = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->getCurrentObject(); - if( aMovingObject ) - { + if( aMovingObject ) + { GLViewer_MimeSource* aMimeSource = new GLViewer_MimeSource(); aMimeSource->setObject( aMovingObject ); - + QClipboard *aClipboard = QApplication::clipboard(); aClipboard->clear(); aClipboard->setData( aMimeSource ); @@ -193,11 +196,11 @@ void GLViewer_ViewPort2d::onCutObject() void GLViewer_ViewPort2d::onCopyObject() { /*GLViewer_Object* aMovingObject = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->getCurrentObject(); - if( aMovingObject ) - { + if( aMovingObject ) + { GLViewer_MimeSource* aMimeSource = new GLViewer_MimeSource(); aMimeSource->setObject( aMovingObject ); - + QClipboard *aClipboard = QApplication::clipboard(); aClipboard->clear(); aClipboard->setData( aMimeSource ); @@ -248,7 +251,7 @@ void GLViewer_ViewPort2d::onPasteObject() GLViewer_Object* aObject = GLViewer_MimeSource::getObject( anArray, aType ); if( !aObject ) return; - + ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->insertObject( aObject, true ); } */ @@ -278,14 +281,14 @@ void GLViewer_ViewPort2d::onDragObject( QMouseEvent* e ) GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer(); GLViewer_Context* aContext = aViewer->getGLContext(); GLViewer_Object* anObject = aContext->getCurrentObject(); - + if( !aContext ) return; float aX = e->pos().x(); float anY = e->pos().y(); aViewer->transPoint( aX, anY ); - + if( myCurDragPosX == NULL && myCurDragPosY == NULL ) { myCurDragPosX = new float(aX); @@ -295,7 +298,7 @@ void GLViewer_ViewPort2d::onDragObject( QMouseEvent* e ) //QPoint aNewPos = e->pos(); //GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer(); - + if( anObject && (e->buttons() & Qt::LeftButton ) ) { if( aContext->isSelected( anObject ) ) @@ -313,11 +316,11 @@ void GLViewer_ViewPort2d::onDragObject( QMouseEvent* e ) else if( aContext->NbSelected() && (e->buttons() & Qt::MidButton ) ) for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) (aContext->SelectedObject())->moveObject( aX - *myCurDragPosX, anY - *myCurDragPosY); - + delete myCurDragPosX; delete myCurDragPosY; myCurDragPosX = new float(aX); - myCurDragPosY = new float(anY); + myCurDragPosY = new float(anY); myGLWidget->updateGL(); } @@ -326,20 +329,20 @@ void GLViewer_ViewPort2d::onDragObject( QMouseEvent* e ) Emits 'mouseEvent' signal. [ virtual protected ] */ void GLViewer_ViewPort2d::mousePressEvent( QMouseEvent* e ) -{ +{ emit vpMouseEvent( e ); - - GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer(); + + GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer(); GLViewer_Context* aContext = aViewer->getGLContext(); GLViewer_Object* anObject = NULL; if( aContext ) anObject = aContext->getCurrentObject(); - + bool accel = e->modifiers() & GLViewer_ViewTransformer::accelKey(); if( ( anObject && !( accel || e->button() == Qt::RightButton ) ) || ( aContext->NbSelected() && !accel && e->button() == Qt::MidButton ) ) - { + { myIsDragProcess = inDrag; } } @@ -350,11 +353,11 @@ void GLViewer_ViewPort2d::mousePressEvent( QMouseEvent* e ) void GLViewer_ViewPort2d::mouseMoveEvent( QMouseEvent* e ) { emit vpMouseEvent( e ); - + if( myIsDragProcess == inDrag ) onDragObject( e ); - /*GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer(); + /*GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer(); GLViewer_Context* aContext = aViewer->getGLContext(); GLViewer_Object* anObj = aContext->getCurrentObject(); @@ -379,7 +382,7 @@ void GLViewer_ViewPort2d::mouseMoveEvent( QMouseEvent* e ) Emits 'mouseEvent' signal. [ virtual protected ] */ void GLViewer_ViewPort2d::mouseReleaseEvent( QMouseEvent* e ) -{ +{ if ( myIsMouseReleaseBlock ) { // skip mouse release after double click @@ -396,7 +399,7 @@ void GLViewer_ViewPort2d::mouseReleaseEvent( QMouseEvent* e ) //destroyPopup( /*popup*/ ); } emit vpMouseEvent( e ); - + if( myIsDragProcess == inDrag ) { bool isAnyMoved = false; @@ -409,11 +412,11 @@ void GLViewer_ViewPort2d::mouseReleaseEvent( QMouseEvent* e ) if( aMovingObject ) isAnyMoved = aMovingObject->finishMove() || isAnyMoved; } - + aMovingObject = aContext->getCurrentObject(); if( aMovingObject ) isAnyMoved = aMovingObject->finishMove() || isAnyMoved; - + myIsDragProcess = noDrag; //myCurDragMousePos.setX( 0 ); //myCurDragMousePos.setY( 0 ); @@ -462,7 +465,7 @@ void GLViewer_ViewPort2d::turnGrid( GLboolean on ) if( on ) { myGrid = new GLViewer_Grid( 2*WIDTH, 2*HEIGHT, - 2*WIDTH, 2*HEIGHT, + 2*WIDTH, 2*HEIGHT, GRID_XSIZE, GRID_YSIZE, myXPan, myYPan, myXScale, myYScale ); @@ -527,36 +530,36 @@ void GLViewer_ViewPort2d::initResize( int x, int y ) GLfloat h = y; bool max = FALSE; - xzoom = (GLfloat)x / myWidth; - yzoom = (GLfloat)y / myHeight; + xzoom = (GLfloat)x / myWidth; + yzoom = (GLfloat)y / myHeight; - if ( ( xzoom < yzoom ) && ( xzoom < 1 ) ) - zoom = xzoom; - else if ( ( yzoom < xzoom ) && ( yzoom < 1 ) ) - zoom = yzoom; - else - { - max = TRUE; - zoom = xzoom > yzoom ? xzoom : yzoom; - } + if ( ( xzoom < yzoom ) && ( xzoom < 1 ) ) + zoom = xzoom; + else if ( ( yzoom < xzoom ) && ( yzoom < 1 ) ) + zoom = yzoom; + else + { + max = TRUE; + zoom = xzoom > yzoom ? xzoom : yzoom; + } if ( !max && ( ! ( ( ( myXPan + w/2 ) < xb * myXScale * zoom ) || - ( ( myXPan - w/2 ) > xa * myXScale * zoom ) || + ( ( myXPan - w/2 ) > xa * myXScale * zoom ) || ( ( myYPan + h/2 ) < yb * myYScale * zoom ) || - ( ( myYPan - h/2 ) > ya * myYScale * zoom ) ) ) ) - zoom = 1; + ( ( myYPan - h/2 ) > ya * myYScale * zoom ) ) ) ) + zoom = 1; if ( max && ( ( ( myXPan + w/2 ) < xb * myXScale * zoom ) || - ( ( myXPan - w/2 ) > xa * myXScale * zoom ) || - ( ( myYPan + h/2 ) < yb * myYScale * zoom ) || - ( ( myYPan - h/2 ) > ya * myYScale * zoom ) ) ) - zoom = 1; - + ( ( myXPan - w/2 ) > xa * myXScale * zoom ) || + ( ( myYPan + h/2 ) < yb * myYScale * zoom ) || + ( ( myYPan - h/2 ) > ya * myYScale * zoom ) ) ) + zoom = 1; + myWidth = x; - myHeight = y; + myHeight = y; - myXScale *= zoom; - myYScale = myXScale; + myXScale *= zoom; + myYScale = myXScale; if ( myGrid ) myGrid->setResize( 2*x, 2*y, zoom ); @@ -590,18 +593,18 @@ void GLViewer_ViewPort2d::reset() { //cout << "GLViewer_ViewPort2d::reset" << endl; - GLint val[4]; - GLint vpWidth, vpHeight; + GLint val[4]; + GLint vpWidth, vpHeight; myGLWidget->makeCurrent(); glGetIntegerv( GL_VIEWPORT, val ); - vpWidth = val[2]; - vpHeight = val[3]; + vpWidth = val[2]; + vpHeight = val[3]; GLint w = myGLWidget->getWidth(); GLint h = myGLWidget->getHeight(); - GLfloat zoom = vpWidth / ( GLfloat )w < vpHeight / ( GLfloat )h ? - vpWidth / ( GLfloat )w : vpHeight / ( GLfloat )h; + GLfloat zoom = vpWidth / ( GLfloat )w < vpHeight / ( GLfloat )h ? + vpWidth / ( GLfloat )w : vpHeight / ( GLfloat )h; if( myGrid ) { @@ -665,13 +668,13 @@ void GLViewer_ViewPort2d::setCenter( int x, int y ) { //cout << "GLViewer_ViewPort2d::setCenter" << endl; - GLint val[4]; - GLint vpWidth, vpHeight; + GLint val[4]; + GLint vpWidth, vpHeight; myGLWidget->makeCurrent(); glGetIntegerv( GL_VIEWPORT, val ); - vpWidth = val[2]; - vpHeight = val[3]; + vpWidth = val[2]; + vpHeight = val[3]; myXPan -= ( x - vpWidth/2 ) / myXScale; myYPan += ( y - vpHeight/2 ) / myYScale; @@ -696,7 +699,7 @@ void GLViewer_ViewPort2d::setCenter( int x, int y ) void GLViewer_ViewPort2d::zoom( int x0, int y0, int x, int y ) { //cout << "GLViewer_ViewPort2d::zoom" << endl; - + float dx, dy, zm; dx = x - x0; dy = y - y0; @@ -704,14 +707,14 @@ void GLViewer_ViewPort2d::zoom( int x0, int y0, int x, int y ) if ( dx == 0. && dy == 0. ) return; - zm = sqrt(dx * dx + dy * dy) / 100. + 1; - zm = (dx > 0.) ? zm : 1. / zm; + zm = sqrt(dx * dx + dy * dy) / 100. + 1; + zm = (dx > 0.) ? zm : 1. / zm; //backup values float bX = myXScale; float bY = myYScale; - myXScale *= zm; - myYScale *= zm; + myXScale *= zm; + myYScale *= zm; if( myGrid ) { @@ -725,7 +728,7 @@ void GLViewer_ViewPort2d::zoom( int x0, int y0, int x, int y ) {// undo myXScale = bX; myYScale = bY; - } + } } else { @@ -742,30 +745,30 @@ void GLViewer_ViewPort2d::zoom( int x0, int y0, int x, int y ) void GLViewer_ViewPort2d::fitRect( const QRect& rect ) { float x0, x1, y0, y1; - float dx, dy, zm, centerX, centerY; + float dx, dy, zm, centerX, centerY; - GLint val[4]; - GLint vpWidth, vpHeight; + GLint val[4]; + GLint vpWidth, vpHeight; myGLWidget->makeCurrent(); glGetIntegerv( GL_VIEWPORT, val ); - vpWidth = val[2]; - vpHeight = val[3]; + vpWidth = val[2]; + vpHeight = val[3]; x0 = rect.left(); x1 = rect.right(); y0 = rect.top(); y1 = rect.bottom(); - dx = fabs( x1 - x0 ); - dy = fabs( y1 - y0 ); - centerX = ( x0 + x1 ) / 2.; - centerY = ( y0 + y1 ) / 2.; + dx = fabs( x1 - x0 ); + dy = fabs( y1 - y0 ); + centerX = ( x0 + x1 ) / 2.; + centerY = ( y0 + y1 ) / 2.; if ( dx == 0. || dy == 0. ) return; - zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy; + zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy; float aDX = ( vpWidth / 2. - centerX ) / myXScale; float aDY = ( vpHeight / 2. - centerY ) / myYScale; @@ -800,7 +803,7 @@ void GLViewer_ViewPort2d::fitSelect() GLViewer_Context* aContext = aViewer->getGLContext(); if( !aContext ) return; - + QRect aSelRect; for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) aSelRect |= *(aViewer->getWinObjectRect( aContext->SelectedObject() )); @@ -870,9 +873,9 @@ void GLViewer_ViewPort2d::fitAll( bool keepScale, bool withZ ) dx = fabs( aBorders[1] - aBorders[0] ); dy = fabs( aBorders[3] - aBorders[2] ); - myXPan = -( aBorders[0] + aBorders[1] ) / 2; + myXPan = -( aBorders[0] + aBorders[1] ) / 2; myYPan = -( aBorders[2] + aBorders[3] ) / 2; - + if( keepScale ) { @@ -883,19 +886,19 @@ void GLViewer_ViewPort2d::fitAll( bool keepScale, bool withZ ) xScale = myXScale; yScale = myYScale; if( dx && dy ) - zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy; + zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy; else zm = 1.0; - myXScale = zm; - myYScale = zm; - + myXScale = zm; + myYScale = zm; + if( myGrid ) { myGrid->setPan( myXPan, myYPan ); if( dx > dy ) myGrid->setZoom( zm / xScale ); - else + else myGrid->setZoom( zm / yScale ); } @@ -1009,7 +1012,7 @@ void GLViewer_ViewPort2d::drawCompass() float centerX = (xPos/2 - delX - cSize)/xScale; float centerY = (yPos/2 - delY - cSize)/yScale; - + switch ( cPos ) { case GLViewer_Compass::TopLeft: @@ -1024,7 +1027,7 @@ void GLViewer_ViewPort2d::drawCompass() break; default: break; } - + float ra, rx, ry, rz; myGLWidget->getRotation( ra, rx, ry, rz ); GLfloat angle = ra * PI / 180.; @@ -1036,14 +1039,14 @@ void GLViewer_ViewPort2d::drawCompass() centerY -= yPan; glColor3f( colorR, colorG, colorB ); - glBegin( GL_POLYGON ); + glBegin( GL_POLYGON ); //arrow - x = centerX; y = centerY + cSize / yScale; + x = centerX; y = centerY + cSize / yScale; glVertex2f( x, y ); //point #2 x = centerX + cWidthTop / xScale; y = centerY + ( cSize - cHeightTop ) / yScale ; glVertex2f( x, y ); - //point #3 + //point #3 x = centerX + cWidthBot / xScale; y = centerY + ( cSize - cHeightTop ) / yScale ; glVertex2f( x, y ); //point #4 @@ -1051,7 +1054,7 @@ void GLViewer_ViewPort2d::drawCompass() glVertex2f( x, y ); //point #5 x = centerX; y = centerY - (cSize - cHeightBot) / yScale ; - glVertex2f( x, y ); + glVertex2f( x, y ); //point #6 x = centerX - cWidthBot / xScale; y = centerY - cSize/yScale; glVertex2f( x, y ); @@ -1071,18 +1074,18 @@ void GLViewer_ViewPort2d::drawCompass() { x = centerX + cos(aCircAngle) * cSize / xScale; y = centerY + sin(aCircAngle) * cSize / yScale; - glVertex2f( x, y ); + glVertex2f( x, y ); aCircAngle += float( STEP ) / 2; - } - glEnd(); - + } + glEnd(); + GLdouble modelMatrix[16], projMatrix[16]; GLint viewport[4]; GLdouble winxN, winyN, winz; GLdouble winxE, winyE; GLdouble winxS, winyS; GLdouble winxW, winyW; - GLuint aTextList; + GLuint aTextList; GLViewer_TexFont* aFont = myCompass->getFont(); float widN = (float)aFont->getStringWidth( "N" ); @@ -1104,13 +1107,13 @@ void GLViewer_ViewPort2d::drawCompass() glGetIntegerv (GL_VIEWPORT, viewport); glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix); glGetDoublev (GL_PROJECTION_MATRIX, projMatrix); - + gluProject (centerX, centerY + cSize / yScale, 0, modelMatrix, projMatrix, viewport, &winxN, &winyN, &winz); gluProject (centerX + cSize / xScale, centerY, 0, modelMatrix, projMatrix, viewport, &winxE, &winyE, &winz); gluProject (centerX, centerY - cSize / yScale, 0, modelMatrix, projMatrix, viewport, &winxS, &winyS, &winz); gluProject (centerX - cSize / xScale, centerY, 0, modelMatrix, projMatrix, viewport, &winxW, &winyW, &winz); - glColor3f( 1.0, 1.0, 1.0 ); + glColor3f( 1.0, 1.0, 1.0 ); aTextList = glGenLists( 1 ); glNewList( aTextList, GL_COMPILE ); @@ -1121,7 +1124,7 @@ void GLViewer_ViewPort2d::drawCompass() glOrtho(0,viewport[2],0,viewport[3],-100,100); glMatrixMode(GL_MODELVIEW); glPushMatrix(); - glLoadIdentity(); + glLoadIdentity(); aFont->drawString( "N", winxN + xGapN, winyN + yGapN ); aFont->drawString( "E", winxE + xGapE, winyE + yGapE ); @@ -1135,7 +1138,7 @@ void GLViewer_ViewPort2d::drawCompass() glEndList(); - if ( aTextList != -1 ) + if ( aTextList != -1 ) glCallList( aTextList ); } @@ -1146,10 +1149,10 @@ BlockStatus GLViewer_ViewPort2d::currentBlock() { if( myIsDragProcess == inDrag && myCurDragPosX != NULL && myCurDragPosY != NULL) return BlockStatus(BS_Highlighting | BS_Selection); - + if( mypFirstPoint && mypLastPoint ) return BlockStatus(BS_Highlighting | BS_Selection); - + return BS_NoBlock; } @@ -1183,10 +1186,10 @@ void GLViewer_ViewPort2d::drawSelectByRect( int x, int y ) if( mypFirstPoint && mypLastPoint ) { myRectBand->hide(); /* erase */ - + mypLastPoint->setX( x ); mypLastPoint->setY( y ); - + QRect aRect = selectionRect(); myRectBand->setGeometry( aRect ); /* draw */ myRectBand->setVisible( aRect.isValid() ); @@ -1315,7 +1318,7 @@ GLViewer_Rect GLViewer_ViewPort2d::win2GLV( const QRect& theRect ) const gluUnProject( theRect.left(), viewport[3] - theRect.top(), 0, modelMatrix, projMatrix, viewport, &objx1, &objy1, &objz ); gluUnProject( theRect.right(), viewport[3] - theRect.bottom(), 0, modelMatrix, projMatrix, viewport, &objx2, &objy2, &objz ); - + aRect.setLeft( objx1 ); aRect.setTop( objy1 ); aRect.setRight( objx2 ); @@ -1345,7 +1348,7 @@ QRect GLViewer_ViewPort2d::GLV2win( const GLViewer_Rect& theRect ) const gluProject( theRect.left(), theRect.top(), 0, modelMatrix, projMatrix, viewport, &winx1, &winy1, &winz ); gluProject( theRect.right(), theRect.bottom(), 0, modelMatrix, projMatrix, viewport, &winx2, &winy2, &winz ); - + aRect.setLeft( (int)winx1 ); aRect.setTop( viewport[3] - (int)winy1 ); aRect.setRight( (int)winx2 ); diff --git a/src/GLViewer/GLViewer_Viewer2d.cxx b/src/GLViewer/GLViewer_Viewer2d.cxx index 3a51f5c89..f6f998697 100644 --- a/src/GLViewer/GLViewer_Viewer2d.cxx +++ b/src/GLViewer/GLViewer_Viewer2d.cxx @@ -31,7 +31,6 @@ #include "GLViewer_Context.h" #include "GLViewer_Drawer.h" #include "GLViewer_Selector2d.h" -//#include "GLViewer_Sketcher.h" #include "GLViewer_ViewPort2d.h" #include "SUIT_Desktop.h" @@ -39,11 +38,11 @@ #include "SUIT_ViewManager.h" #include -#include -#include #include #include +#include #include +#include /*! Constructor @@ -52,15 +51,13 @@ GLViewer_Viewer2d::GLViewer_Viewer2d( const QString& title) : GLViewer_Viewer( title ) { - myGLContext = new GLViewer_Context( this ); - - //myGLSketcher = new GLViewer_Sketcher( this ); + myGLContext = new GLViewer_Context( this ); - createSelector(); + createSelector(); - mySelMode = GLViewer_Viewer::Multiple; + mySelMode = GLViewer_Viewer::Multiple; - myDrawers.clear(); + myDrawers.clear(); } /*! -- 2.39.2