Back to index

salome-gui  6.5.0
Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Private Types
GLViewer_ViewPort2d Class Reference

Class GLViewer_ViewPort 2D visualisation canvas of GLViewer. More...

#include <GLViewer_ViewPort2d.h>

Inheritance diagram for GLViewer_ViewPort2d:
Inheritance graph
[legend]
Collaboration diagram for GLViewer_ViewPort2d:
Collaboration graph
[legend]

List of all members.

Signals

void vpUpdateValues ()
 Emits after any transformation.
void objectMoved ()

Public Member Functions

 GLViewer_ViewPort2d (QWidget *parent, GLViewer_ViewFrame *theViewFrame=NULL)
 Constructor.
 ~GLViewer_ViewPort2d ()
 Destructor.
void turnGrid (GLboolean on)
 On/off rectangular grid.
GLViewer_Grid * getGrid () const
 Returns rectangular grid.
void setGridColor (const QColor gridColor, const QColor axisColor)
 Returns grid color.
GLViewer_ViewFramegetViewFrame () const
 Returns parent window.
GLViewer_WidgetgetGLWidget () const
 Returns painted widget.
virtual QPaintDevice * getPaintDevice ()
void setBackgroundColor (const QColor &color)
 Sets background color.
QColor backgroundColor () const
 Returns background color.
void setBorder (GLViewer_Rect *border)
 Sets borders of scene.
GLViewer_Rect * getBorder () const
 Get current borders of scene.
void setMargin (GLfloat margin)
 Sets margin of borders.
GLfloat getMargin () const
 Returns margin of borders.
int getWidth () const
 Returns width of view.
int getHeight () const
 Returns height of view.
void getScale (GLfloat &xSc, GLfloat &ySc) const
 Returns scale factors.
void getPan (GLfloat &xPan, GLfloat &yPan) const
 returns offsets
void initResize (int width, int height)
 Resize view.
void startRotation (int, int)
 Begins rotation.
void rotate (int, int)
 Process rotation.
void endRotation ()
 Completes rotation.
bool isDragProcess ()
 Checks of dragging process state.
void turnCompass (GLboolean on)
 On/off compass.
void drawCompass ()
 Draws compass.
int getViewPortId ()
 Returns unique ID of ViewPort.
virtual BlockStatus currentBlock ()
 Redefined method.
void startSelectByRect (int x, int y)
 Initializes before selecting by rect.
void drawSelectByRect (int x, int y)
 Draw selecting rectandle.
void finishSelectByRect ()
 Pass rect into selector and update.
bool startPulling (GLViewer_Pnt)
 It is for ouv
void drawPulling (GLViewer_Pnt)
 It is for ouv
void finishPulling ()
 It is for ouv
bool isPulling () const
 It is for ouv
QRect selectionRect ()
 Returns selection by rect.
GLViewer_Rect win2GLV (const QRect &) const
 Transforms window rect to global rect.
QRect GLV2win (const GLViewer_Rect &) const
 Transforms global rect to window rect.

Protected Slots

void onStartDragObject ()
 Initializes drag process.
void onPasteObject ()
 Pastes object from clipboard.
void onCutObject ()
 Cuts object to clipboard.
void onCopyObject ()
 Copies object to clipboard.
void onMaybeTip (QPoint thePoint, QString &text, QFont &font, QRect &theTextReg, QRect &theViewReg)
 Sets tool tip with.

Protected Member Functions

void onDragObject (QMouseEvent *)
 SLOT: called when object is being dragged.
virtual void mouseMoveEvent (QMouseEvent *)
 Emits 'mouseEvent' signal.
virtual void mousePressEvent (QMouseEvent *)
 Emits 'mouseEvent' signal.
virtual void mouseReleaseEvent (QMouseEvent *)
 Emits 'mouseEvent' signal.
virtual void mouseDoubleClickEvent (QMouseEvent *)
 Custom mouse double click event handler.
virtual void paintEvent (QPaintEvent *)
 Custom paint event handler.
virtual void resizeEvent (QResizeEvent *)
 Custom resize event handler.
virtual void reset ()
 Returns view to begin state.
virtual void pan (int dx, int dy)
 Sets offset to view.
virtual void setCenter (int x, int y)
 Sets view center in global coords.
virtual void zoom (int x0, int y0, int x1, int y1)
 Process zoming transformation with mouse tracking from ( x0, y0 ) to ( x1, y1 )
virtual void fitRect (const QRect &)
 Transforms view by rectangle.
virtual void fitSelect ()
 Transforms view by selection.
virtual void fitAll (bool keepScale=false, bool withZ=true)
 Transform view by view borders ( if.

Protected Attributes

GLViewer_ViewFramemyViewFrame
GLViewer_WidgetmyGLWidget
GLViewer_Rect * myBorder
QColor myBackgroundColor
GLfloat myMargin
int myHeight
int myWidth
GLfloat myXScale
GLfloat myYScale
GLfloat myXOldScale
GLfloat myYOldScale
GLfloat myXPan
GLfloat myYPan
GLViewer_Grid * myGrid
GLViewer_Compass * myCompass
int myIsDragProcess
float * myCurDragPosX
float * myCurDragPosY
QPoint * mypFirstPoint
QPoint * mypLastPoint
bool myIsPulling
GLViewer_ObjectmyPullingObject
int myViewPortId
QtxToolTip * myObjectTip
bool myIsMouseReleaseBlock
 flag to block mouse release event just after mouse double-click
QRubberBand * myRectBand
 selection rectangle rubber band

Private Types

enum  vpDragState { noDrag, initDrag, inDrag }
 Dragging states. More...

Detailed Description

Class GLViewer_ViewPort 2D visualisation canvas of GLViewer.

Definition at line 63 of file GLViewer_ViewPort2d.h.


Member Enumeration Documentation

Dragging states.

Enumerator:
noDrag 
initDrag 
inDrag 

Definition at line 68 of file GLViewer_ViewPort2d.h.


Constructor & Destructor Documentation

GLViewer_ViewPort2d::GLViewer_ViewPort2d ( QWidget *  parent,
GLViewer_ViewFrame theViewFrame = NULL 
)

Constructor.

Definition at line 74 of file GLViewer_ViewPort2d.cxx.

: 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 )
    myViewFrame = (GLViewer_ViewFrame*)parent;
  else
    myViewFrame = theViewFrame;

  myGrid = 0;
  myCompass = 0;
  myBorder = new GLViewer_Rect();

  QBoxLayout* qbl = new QHBoxLayout( this );
  qbl->setSpacing( 0 );
  qbl->setMargin( 0 );

  myGLWidget = new GLViewer_Widget( this, 0 ) ;
  qbl->addWidget( myGLWidget );
  myGLWidget->setFocusProxy( this );
  setMouseTracking( TRUE );

  myIsDragProcess = noDrag;
  //myCurDragMousePos = QPoint();
  myCurDragPosX = NULL;
  myCurDragPosY = NULL;

  myIsPulling = false;

  myViewPortId = aLastViewPostId;
  aLastViewPostId++;

  mypFirstPoint = NULL;
  mypLastPoint = NULL;

    // TODO: Porting to Qt4
    /*myObjectTip = new QtxToolTip( myGLWidget );///GLViewer_ObjectTip( this );
    myObjectTip->setShowDelayTime( 60000 );
    connect( myObjectTip, SIGNAL( maybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ),
             this, SLOT( onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& ) ) );*/
//    myGLWidget->installEventFilter( myObjectTip );
}

Destructor.

Definition at line 124 of file GLViewer_ViewPort2d.cxx.

{
    if( myCompass )
        delete myCompass;

    if( myGrid )
        delete myGrid;

    delete myBorder;
    delete myGLWidget;

    if ( myRectBand ) myRectBand->hide();
    delete myRectBand;
}

Member Function Documentation

Returns background color.

Returns:
background color

Definition at line 514 of file GLViewer_ViewPort2d.cxx.

Redefined method.

Returns:
blocking status for current started operations

Definition at line 1150 of file GLViewer_ViewPort2d.cxx.

Draws compass.

Definition at line 987 of file GLViewer_ViewPort2d.cxx.

{
    if( !myCompass->getVisible() )
        return;

    GLfloat xScale, yScale, xPan, yPan;

    int xPos = getWidth();
    int yPos = getHeight();

    int cPos = myCompass->getPos();
    int cSize = myCompass->getSize();
    QColor cCol = myCompass->getColor();
    int cWidthTop = myCompass->getArrowWidthTop();
    int cWidthBot = myCompass->getArrowWidthBottom();
    int cHeightTop = myCompass->getArrowHeightTop();
    int cHeightBot = myCompass->getArrowHeightBottom();

    GLfloat colorR = (cCol.red())/255;
    GLfloat colorG = (cCol.green())/255;
    GLfloat colorB = (cCol.blue())/255;

    float delX = cSize * 0.5;
    float delY = cSize * 0.5;

    getScale( xScale, yScale );
    getPan( xPan, yPan);

    float centerX = (xPos/2 - delX - cSize)/xScale;
    float centerY = (yPos/2 - delY - cSize)/yScale;

    switch ( cPos )
    {
    case GLViewer_Compass::TopLeft:
            centerX = -centerX;
            break;
        case GLViewer_Compass::BottomLeft:
            centerX = -centerX;
            centerY = -centerY;
            break;
        case GLViewer_Compass::BottomRight:
            centerY = -centerY;
            break;
        default: break;
    }

    float ra, rx, ry, rz;
    myGLWidget->getRotation( ra, rx, ry, rz );
    GLfloat angle = ra * PI / 180.;
    GLfloat /*r = 0.0,*/ x = 0.0 , y = 0.0;

    rotate_point( centerX, centerY, -angle );

    centerX -= xPan;
    centerY -= yPan;

    glColor3f( colorR, colorG, colorB );
    glBegin( GL_POLYGON );
    //arrow
        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
        x = centerX + cWidthBot / xScale; y = centerY + ( cSize - cHeightTop ) / yScale ;
        glVertex2f( x, y );
        //point #4
        x = centerX + cWidthBot / xScale; y = centerY - cSize/yScale;
        glVertex2f( x, y );
        //point #5
        x = centerX;                      y = centerY - (cSize - cHeightBot) / yScale ;
        glVertex2f( x, y );
        //point #6
        x = centerX - cWidthBot / xScale; y = centerY - cSize/yScale;
        glVertex2f( x, y );
        //point #7
        x = centerX - cWidthBot / xScale; y = centerY + ( cSize - cHeightTop ) / yScale ;
        glVertex2f( x, y );
        //point #8
        x = centerX - cWidthTop / xScale; y = centerY + ( cSize - cHeightTop ) / yScale ;
        glVertex2f( x, y );
    glEnd();
    glLineWidth( 2.0 );
    glEnable( GL_LINE_SMOOTH );
    glBegin(GL_LINE_LOOP);
    //circle
        float aCircAngle = 0;
        for ( int i = 0; i < 20 * SEGMENTS + 1; i++ )
        {
            x = centerX + cos(aCircAngle) * cSize / xScale;
            y = centerY + sin(aCircAngle) * cSize / yScale;
            glVertex2f( x, y );
            aCircAngle += float( STEP ) / 2;
        }
    glEnd();

    GLdouble        modelMatrix[16], projMatrix[16];
    GLint           viewport[4];
    GLdouble        winxN, winyN, winz;
    GLdouble        winxE, winyE;
    GLdouble        winxS, winyS;
    GLdouble        winxW, winyW;
    GLuint          aTextList;

    GLViewer_TexFont* aFont = myCompass->getFont();
    float widN = (float)aFont->getStringWidth( "N" );
    float widW = (float)aFont->getStringWidth( "W" );
    float widS = (float)aFont->getStringWidth( "S" );
    float widE = (float)aFont->getStringWidth( "E" );
    float heightL = (float)aFont->getStringHeight();

    float xGapN = - widN/2 *( 1.0 + sin(angle) );
    float xGapS = - widS/2 *( 1.0 - sin(angle) );
    float xGapW = - widW/2 *( 1.0 + cos(angle) );
    float xGapE = - widE/2 *( 1.0 - cos(angle) );

    float yGapN = - heightL/2 *( 1.0 - cos(angle) ) * 0.75;
    float yGapS = - heightL/2 *( 1.0 + cos(angle) ) * 0.75;
    float yGapW = - heightL/2 *( 1.0 + sin(angle) ) * 0.75;
    float yGapE = - heightL/2 *( 1.0 - sin(angle) ) * 0.75;

    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 );

    aTextList = glGenLists( 1 );
    glNewList( aTextList, GL_COMPILE );

    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    glOrtho(0,viewport[2],0,viewport[3],-100,100);
    glMatrixMode(GL_MODELVIEW);
    glPushMatrix();
    glLoadIdentity();

    aFont->drawString( "N", winxN + xGapN, winyN + yGapN );
    aFont->drawString( "E", winxE + xGapE, winyE + yGapE );
    aFont->drawString( "S", winxS + xGapS, winyS + yGapS );
    aFont->drawString( "W", winxW + xGapW, winyW + yGapW );

    glMatrixMode(GL_PROJECTION);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);
    glPopMatrix();

    glEndList();

    if ( aTextList != -1 )
        glCallList( aTextList );
}

Here is the call graph for this function:

void GLViewer_ViewPort2d::drawPulling ( GLViewer_Pnt  point)

It is for ouv

Definition at line 1268 of file GLViewer_ViewPort2d.cxx.

{
    GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
    GLViewer_Context* aContext = aViewer->getGLContext();
    ObjList anObjects = aContext->getObjects();

    GLViewer_Object* aLockedObject = 0;
    for( ObjList::Iterator it = anObjects.begin(); it != anObjects.end(); ++it )
    {
        GLViewer_Object* anObject = *it;
        if( !anObject->getVisible() )
            continue;

        GLViewer_Rect aRect = anObject->getPullingRect();

        if( aRect.contains( point ) && anObject->portContains( point ) )
        {
            aLockedObject = anObject;
            break;
        }
    }

    myPullingObject->pull( point, aLockedObject );
}

Here is the call graph for this function:

Draw selecting rectandle.

Draws rectangle selection.

Parameters:
x,y- current point

Definition at line 1186 of file GLViewer_ViewPort2d.cxx.

{
    if( mypFirstPoint && mypLastPoint )
    {
        myRectBand->hide();    /* erase */

        mypLastPoint->setX( x );
        mypLastPoint->setY( y );

        QRect aRect = selectionRect();
        myRectBand->setGeometry( aRect );    /* draw */
        myRectBand->setVisible( aRect.isValid() );
    }

}

Here is the call graph for this function:

Completes rotation.

Finishes rotation.

Definition at line 977 of file GLViewer_ViewPort2d.cxx.

{
    float ra, rx, ry, rz;
    myGLWidget->getRotation( ra, rx, ry, rz );
    myGLWidget->setRotationAngle( ra );
}

It is for ouv

Definition at line 1295 of file GLViewer_ViewPort2d.cxx.

{
    myIsPulling = false;
    myPullingObject->finishPulling();
    setCursor( *getDefaultCursor() );
}

Pass rect into selector and update.

Finishes rectangle selection.

Definition at line 1205 of file GLViewer_ViewPort2d.cxx.

{
    if( mypFirstPoint && mypLastPoint )
    {


        if ( myRectBand ) myRectBand->hide();    /* erase */

        delete mypFirstPoint;
        delete mypLastPoint;

        mypFirstPoint = NULL;
        mypLastPoint = NULL;

        delete myRectBand;
        myRectBand = 0;
    }
}
void GLViewer_ViewPort2d::fitAll ( bool  keepScale = false,
bool  withZ = true 
) [protected, virtual]

Transform view by view borders ( if.

Transform view by view borders.

Parameters:
keepScale= true, zoom does not change )
keepScale- if it is true, zoom does not change

Definition at line 827 of file GLViewer_ViewPort2d.cxx.

{
    //cout << "GLViewer_ViewPort2d::fitAll" << endl;

    float xa, xb, ya, yb;
    float dx, dy, zm;
    float xScale, yScale;

    myMargin = qMax( myBorder->width(), myBorder->height() ) / 5;

    xa = myBorder->left() - myMargin;
    xb = myBorder->right() + myMargin;
    ya = myBorder->bottom() - myMargin;
    yb = myBorder->top() + myMargin;

    float aPoints[8] = { xa, ya, xb, ya, xa, yb, xb, yb };

    float ra, rx, ry, rz;
    myGLWidget->getRotation( ra, rx, ry, rz );
    float angle = ra * PI / 180.;

    int i;
    for( i = 0; i < 7; i = i + 2 )
        rotate_point( aPoints[i], aPoints[i+1], angle );

    float aBorders[4] = { aPoints[0], aPoints[0], aPoints[1], aPoints[1] };

    for( i = 2; i < 7; i = i + 2 )
    {
        if( aBorders[0] < aPoints[i] )
            aBorders[0] = aPoints[i];
        if( aBorders[1] > aPoints[i] )
            aBorders[1] = aPoints[i];

        if( aBorders[2] < aPoints[i+1] )
            aBorders[2] = aPoints[i+1];
        if( aBorders[3] > aPoints[i+1] )
            aBorders[3] = aPoints[i+1];
    }

    GLint val[4];
    GLint vpWidth, vpHeight;

    myGLWidget->makeCurrent();
    glGetIntegerv( GL_VIEWPORT, val );
    vpWidth = val[2];
    vpHeight = val[3];

    dx = fabs( aBorders[1] - aBorders[0] );
    dy = fabs( aBorders[3] - aBorders[2] );

    myXPan = -( aBorders[0] + aBorders[1] ) / 2;
    myYPan = -( aBorders[2] + aBorders[3] ) / 2;


    if( keepScale )
    {
        myXOldScale = myXScale;
        myYOldScale = myYScale;
    }

    xScale = myXScale;
    yScale = myYScale;
    if( dx && dy )
        zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy;
    else
        zm = 1.0;
    myXScale = zm;
    myYScale = zm;


    if( myGrid )
    {
        myGrid->setPan( myXPan, myYPan );
        if( dx > dy )
            myGrid->setZoom(  zm / xScale );
        else
            myGrid->setZoom( zm / yScale );
    }

    myGLWidget->setPan( myXPan, myYPan, 0.0 );
    myGLWidget->setScale( myXScale, myYScale, 1.0 );
    myGLWidget->updateGL();

    if( keepScale )
        emit vpUpdateValues();
}

Here is the call graph for this function:

void GLViewer_ViewPort2d::fitRect ( const QRect &  rect) [protected, virtual]

Transforms view by rectangle.

Parameters:
rect- rectangle

Definition at line 747 of file GLViewer_ViewPort2d.cxx.

{
    float x0, x1, y0, y1;
    float dx, dy, zm, centerX, centerY;

    GLint val[4];
    GLint vpWidth, vpHeight;

    myGLWidget->makeCurrent();
    glGetIntegerv( GL_VIEWPORT, val );
    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.;

    if ( dx == 0. || dy == 0. )
        return;

    zm = vpWidth / dx < vpHeight / dy ? vpWidth / dx : vpHeight / dy;

    float aDX = ( vpWidth / 2. - centerX ) / myXScale;
    float aDY = ( vpHeight / 2. - centerY ) / myYScale;

    float ra, rx, ry, rz;
    myGLWidget->getRotation( ra, rx, ry, rz );
    GLfloat angle = ra * PI / 180.;

    myXPan += (aDX*cos(angle) - aDY*sin(angle));
    myYPan -= (aDX*sin(angle) + aDY*cos(angle));

    if( myGrid )
        myGrid->setPan( myXPan, myYPan );

    myXScale *= zm;
    myYScale = myXScale;

    if( myGrid )
        myGrid->setZoom( zm );

    myGLWidget->setPan( myXPan, myYPan, 0.0 );
    myGLWidget->setScale( myXScale, myYScale, 1.0 );
    myGLWidget->updateGL();
}

Here is the caller graph for this function:

void GLViewer_ViewPort2d::fitSelect ( ) [protected, virtual]

Transforms view by selection.

Definition at line 802 of file GLViewer_ViewPort2d.cxx.

{
  GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
  GLViewer_Context* aContext = aViewer->getGLContext();
  if( !aContext )
    return;

  QRect aSelRect;
  for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
    aSelRect |= *(aViewer->getWinObjectRect( aContext->SelectedObject() ));

  if( aSelRect.isValid() )
  {
    aSelRect.setTop( aSelRect.top() - SELECTION_RECT_GAP );
    aSelRect.setBottom( aSelRect.bottom() + SELECTION_RECT_GAP );
    aSelRect.setLeft( aSelRect.left() - SELECTION_RECT_GAP );
    aSelRect.setRight( aSelRect.right() + SELECTION_RECT_GAP );
    fitRect( aSelRect );
  }
}

Here is the call graph for this function:

GLViewer_Rect* GLViewer_ViewPort2d::getBorder ( ) const [inline]

Get current borders of scene.

Definition at line 95 of file GLViewer_ViewPort2d.h.

{ return myBorder; }

Returns painted widget.

Definition at line 84 of file GLViewer_ViewPort2d.h.

{ return myGLWidget; }
GLViewer_Grid* GLViewer_ViewPort2d::getGrid ( ) const [inline]

Returns rectangular grid.

Definition at line 77 of file GLViewer_ViewPort2d.h.

{ return myGrid; }
int GLViewer_ViewPort2d::getHeight ( ) const [inline]

Returns height of view.

Definition at line 105 of file GLViewer_ViewPort2d.h.

{ return myHeight; }

Here is the caller graph for this function:

GLfloat GLViewer_ViewPort2d::getMargin ( ) const [inline]

Returns margin of borders.

Definition at line 100 of file GLViewer_ViewPort2d.h.

{ return myMargin; }
virtual QPaintDevice* GLViewer_ViewPort2d::getPaintDevice ( ) [inline, virtual]

Definition at line 85 of file GLViewer_ViewPort2d.h.

{ return myGLWidget; }
void GLViewer_ViewPort2d::getPan ( GLfloat &  xPan,
GLfloat &  yPan 
) const [inline]

returns offsets

Definition at line 111 of file GLViewer_ViewPort2d.h.

{ xPan = myXPan; yPan = myYPan; }

Here is the caller graph for this function:

void GLViewer_ViewPort2d::getScale ( GLfloat &  xSc,
GLfloat &  ySc 
) const [inline]

Returns scale factors.

Definition at line 109 of file GLViewer_ViewPort2d.h.

{ xSc = myXScale; ySc = myYScale; }

Here is the caller graph for this function:

Returns parent window.

Definition at line 82 of file GLViewer_ViewPort2d.h.

{ return myViewFrame; }

Here is the caller graph for this function:

Returns unique ID of ViewPort.

Definition at line 132 of file GLViewer_ViewPort2d.h.

{ return myViewPortId; }
int GLViewer_ViewPort2d::getWidth ( ) const [inline]

Returns width of view.

Definition at line 103 of file GLViewer_ViewPort2d.h.

{ return myWidth; }

Here is the caller graph for this function:

QRect GLViewer_ViewPort2d::GLV2win ( const GLViewer_Rect &  theRect) const

Transforms global rect to window rect.

Convert rectangle in GL co-ordinates to window co-ordinates.

Returns:
converted rectangle

Definition at line 1336 of file GLViewer_ViewPort2d.cxx.

{
  QRect aRect;

  GLdouble        modelMatrix[16], projMatrix[16];
  GLint           viewport[4];

  GLdouble        winx1, winy1;
  GLdouble        winx2, winy2;
  GLdouble        winz;

  glGetIntegerv (GL_VIEWPORT, viewport);
  glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
  glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);

  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 );
  aRect.setBottom( viewport[3] - (int)winy2 );

  return aRect;
}
void GLViewer_ViewPort2d::initResize ( int  width,
int  height 
)

Resize view.

Definition at line 522 of file GLViewer_ViewPort2d.cxx.

{
    float xa, xb, ya, yb;
    xa = myBorder->left() - myMargin;
    xb = myBorder->right() + myMargin;
    ya = myBorder->top() - myMargin;
    yb = myBorder->bottom() + myMargin;

    GLfloat zoom, xzoom, yzoom;
    GLfloat w = x;
    GLfloat h = y;
    bool max = FALSE;

    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 ( !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;

    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;

    myWidth = x;
    myHeight = y;

    myXScale *= zoom;
    myYScale = myXScale;

    if ( myGrid )
        myGrid->setResize( 2*x, 2*y, zoom );

    myGLWidget->setScale( myXScale, myYScale, 1.0 );
}

Here is the call graph for this function:

Checks of dragging process state.

Definition at line 124 of file GLViewer_ViewPort2d.h.

{ return myIsDragProcess; }
bool GLViewer_ViewPort2d::isPulling ( ) const [inline]

It is for ouv

Definition at line 151 of file GLViewer_ViewPort2d.h.

{ return myIsPulling; }
void GLViewer_ViewPort2d::mouseDoubleClickEvent ( QMouseEvent *  e) [protected, virtual]

Custom mouse double click event handler.

Definition at line 441 of file GLViewer_ViewPort2d.cxx.

{
  //redefined to block mouse release after mouse double click
  myIsMouseReleaseBlock = true;
  // invoke base implementation
  GLViewer_ViewPort::mouseDoubleClickEvent( e );
}
void GLViewer_ViewPort2d::mouseMoveEvent ( QMouseEvent *  e) [protected, virtual]

Emits 'mouseEvent' signal.

[ virtual protected ]

Definition at line 355 of file GLViewer_ViewPort2d.cxx.

{
    emit vpMouseEvent( e );

    if( myIsDragProcess == inDrag )
        onDragObject( e );

    /*GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
    GLViewer_Context* aContext = aViewer->getGLContext();

    GLViewer_Object* anObj = aContext->getCurrentObject();
    if( anObj && aContext->currentObjectIsChanged() )
    {
        //cout << "GLViewer_ViewPort2d::mouseMoveEvent{QToolTip::add}" << endl;
        //QToolTip::remove( myGLWidget );
        QRect* aRect = (aViewer->getWinObjectRect(anObj));
        //QToolTip::add( myGLWidget, *aRect, anObj->getToolTipText() );
        myGLWidget->addToolTip( anObj->getToolTipText(), *aRect );
    }
    if(!anObj)
    {
        //cout << "GLViewer_ViewPort2d::mouseMoveEvent{QToolTip::remove}" << endl;
        //QRect* aRect = (aViewer->getWinObjectRect(anObj));
        //QToolTip::remove( myGLWidget, *aRect );
        myGLWidget->removeToolTip();
    }*/
}

Here is the call graph for this function:

void GLViewer_ViewPort2d::mousePressEvent ( QMouseEvent *  e) [protected, virtual]

Emits 'mouseEvent' signal.

[ virtual protected ]

Definition at line 333 of file GLViewer_ViewPort2d.cxx.

{
    emit vpMouseEvent( e );

    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;
    }
}

Here is the call graph for this function:

void GLViewer_ViewPort2d::mouseReleaseEvent ( QMouseEvent *  e) [protected, virtual]

Emits 'mouseEvent' signal.

[ virtual protected ]

Definition at line 386 of file GLViewer_ViewPort2d.cxx.

{
    if ( myIsMouseReleaseBlock )
    {
      // skip mouse release after double click
      myIsMouseReleaseBlock = false;
      return;
    }

    /* show popup menu */
    if ( e->button() == Qt::RightButton )
    {
        //QPopupMenu* popup = createPopup();
        //if ( popup && popup->count() )
        //    popup->exec( QCursor::pos() );
        //destroyPopup( /*popup*/ );
    }
    emit vpMouseEvent( e );

    if( myIsDragProcess == inDrag )
    {
      bool isAnyMoved = false;
      GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
      GLViewer_Context* aContext = aViewer->getGLContext();
      GLViewer_Object* aMovingObject;
      for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
      {
        aMovingObject = aContext->SelectedObject();
        if( aMovingObject )
          isAnyMoved = aMovingObject->finishMove() || isAnyMoved;
      }

      aMovingObject = aContext->getCurrentObject();
      if( aMovingObject )
        isAnyMoved = aMovingObject->finishMove() || isAnyMoved;

      myIsDragProcess = noDrag;
      //myCurDragMousePos.setX( 0 );
      //myCurDragMousePos.setY( 0 );
      delete myCurDragPosX;
      delete myCurDragPosY;
      myCurDragPosX = NULL;
      myCurDragPosY = NULL;

      if( isAnyMoved )
      {
        emit objectMoved();
        aViewer->updateBorders();
      }
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLViewer_ViewPort2d::onCopyObject ( ) [protected, slot]

Copies object to clipboard.

SLOT: copies object to clipboard.

Definition at line 198 of file GLViewer_ViewPort2d.cxx.

{
    /*GLViewer_Object* aMovingObject = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->getCurrentObject();
    if( aMovingObject )
    {
        GLViewer_MimeSource* aMimeSource = new GLViewer_MimeSource();
        aMimeSource->setObject( aMovingObject );

        QClipboard *aClipboard = QApplication::clipboard();
        aClipboard->clear();
        aClipboard->setData( aMimeSource );
    }
    */
    GLViewer_Context* aContext = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext();
    int aObjNum = aContext->NbSelected();
    if( aObjNum > 0 )
    {
        QList<GLViewer_Object*> aObjects;
        GLViewer_MimeData* aMimeData = new GLViewer_MimeData();
        aContext->InitSelected();
        for( ; aContext->MoreSelected(); aContext->NextSelected() )
            aObjects.append( aContext->SelectedObject() );

        //aMimeData->setObjects( aObjects ); ouv 6.05.04

        QClipboard *aClipboard = QApplication::clipboard();
        aClipboard->clear();
        aClipboard->setMimeData( aMimeData );
    }
}

Here is the call graph for this function:

void GLViewer_ViewPort2d::onCutObject ( ) [protected, slot]

Cuts object to clipboard.

SLOT: cuts object to clipboard.

Definition at line 160 of file GLViewer_ViewPort2d.cxx.

{
    /*GLViewer_Object* aMovingObject = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->getCurrentObject();
    if( aMovingObject )
    {
        GLViewer_MimeSource* aMimeSource = new GLViewer_MimeSource();
        aMimeSource->setObject( aMovingObject );

        QClipboard *aClipboard = QApplication::clipboard();
        aClipboard->clear();
        aClipboard->setData( aMimeSource );

        ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->deleteObject( aMovingObject );
    }*/
    GLViewer_Context* aContext = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext();
    int aObjNum = aContext->NbSelected();
    if( aObjNum > 0 )
    {
        QList<GLViewer_Object*> aObjects;
        GLViewer_MimeData* aMimeData = new GLViewer_MimeData();
        aContext->InitSelected();
        for( ; aContext->MoreSelected(); aContext->NextSelected() )
            aObjects.append( aContext->SelectedObject() );

        //aMimeData->setObjects( aObjects ); ouv 6.05.04

        QClipboard *aClipboard = QApplication::clipboard();
        aClipboard->clear();
        aClipboard->setMimeData( aMimeData );

        for( int i = 0; i < aObjNum; i++ )
            aContext->deleteObject( aObjects[i] );
    }
}

Here is the call graph for this function:

void GLViewer_ViewPort2d::onDragObject ( QMouseEvent *  e) [protected]

SLOT: called when object is being dragged.

Definition at line 280 of file GLViewer_ViewPort2d.cxx.

{
  //cout << "---GLViewer_ViewPort2d::onDragObject()---" << endl;
  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);
    myCurDragPosY = new float(anY);
    return;
  }

  //QPoint aNewPos = e->pos();
  //GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();

  if( anObject && (e->buttons() & Qt::LeftButton ) )
  {
    if( aContext->isSelected( anObject ) )
    {
      for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() )
      {
        GLViewer_Object* aMovingObject = aContext->SelectedObject();
        if( aMovingObject )
          aMovingObject->moveObject( aX - *myCurDragPosX, anY - *myCurDragPosY);
      }
    }
    else
      anObject->moveObject( aX - *myCurDragPosX, anY - *myCurDragPosY);
  }
  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);

  myGLWidget->updateGL();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void GLViewer_ViewPort2d::onMaybeTip ( QPoint  thePoint,
QString &  text,
QFont &  font,
QRect &  theTextReg,
QRect &  theViewReg 
) [protected, slot]

Sets tool tip with.

SLOT: called when tooltip should be shown.

Parameters:
textto
theTextRegand on
theViewRegwhan mouse is on
thePoint

Definition at line 1365 of file GLViewer_ViewPort2d.cxx.

{
  GLViewer_Context* aContext = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext();

  GLViewer_Object* anObj = aContext->getCurrentObject();
  if( anObj )
  {
    theText = anObj->getToolTipText();
    if( theText.isEmpty() )
      theText = anObj->getName();

    QStringList aList;
    if( anObj->isTooTipHTML() )
      aList = theText.split( "<br>", QString::SkipEmptyParts );
    else
      aList = theText.split( "\n", QString::SkipEmptyParts );

    if( !aList.isEmpty() )
    {
      int str_size = aList.first().length();
      for( int i = 1, size = aList.count(); i < size; i++ )
      {
        if ( str_size < (int)aList[i].length() )
        {
          str_size = aList[i].length();
        }
      }
      theFont = font();
      int cur_height = 24;
      QCursor* aCursor = QApplication::overrideCursor();
      if( aCursor )
      {
        const QBitmap* aBitmap = aCursor->bitmap();
        if( aBitmap )
          cur_height = aBitmap->height();
      }

      //temp
      QSize aSize = QLabel( theText, 0 ).sizeHint();
      theTextReg = QRect( thePoint.x(), thePoint.y() + cur_height,
                          aSize.width(), aSize.height() );
      theRegion = QRect( thePoint.x(), thePoint.y(), 1, 1 );
    }
  }
}

Here is the call graph for this function:

Pastes object from clipboard.

SLOT: pastes object from clipboard.

Definition at line 232 of file GLViewer_ViewPort2d.cxx.

{
    /*QClipboard *aClipboard = QApplication::clipboard();
    QMimeSource* aMimeSource = aClipboard->data();
    if( aMimeSource->provides( "GLViewer_Object" ) )
    {
        const char* aType;
        int i = 1;
        QByteArray anArray;
        do
        {
            aType = aMimeSource->format( i );
            anArray = aMimeSource->encodedData( aType );
            if( anArray.size() != 0 )
                break;
            i++;
        }
        while( aType != 0 );
        if( anArray.size() == 0 )
            return;

        GLViewer_Object* aObject = GLViewer_MimeSource::getObject( anArray, aType );
        if( !aObject )
            return;

        ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext()->insertObject( aObject, true );
    }
    */
    /* ouv 6.05.04
    QClipboard *aClipboard = QApplication::clipboard();

    QMimeSource* aMimeSource = aClipboard->data();
    if( aMimeSource->provides( "GLViewer_Objects" ) )
    {
        QByteArray anArray = aMimeSource->encodedData( "GLViewer_Objects" );
        QList<GLViewer_Object*> aObjects = GLViewer_MimeSource::getObjects( anArray, "GLViewer_Objects" );
        if( aObjects.empty() )
            return;
        GLViewer_Context* aContext = ((GLViewer_Viewer2d*)getViewFrame()->getViewer())->getGLContext();
        for( int i = 0; i < aObjects.count(); i++ )
            aContext->insertObject( aObjects[i], true );
    }
    */
}

Initializes drag process.

SLOT: initializes drag process.

Definition at line 142 of file GLViewer_ViewPort2d.cxx.

{
    if( myIsDragProcess == noDrag )
    {
        myIsDragProcess = initDrag;
        QCursor::setPos( (int)(*myCurDragPosX), (int)(*myCurDragPosY) );
        //myCurDragMousePos = QPoint( 0, 0 );
        delete myCurDragPosX;
        delete myCurDragPosY;
        myCurDragPosX = NULL;
        myCurDragPosY = NULL;
        return;
    }
}
void GLViewer_ViewPort2d::paintEvent ( QPaintEvent *  e) [protected, virtual]

Custom paint event handler.

Definition at line 575 of file GLViewer_ViewPort2d.cxx.

{
    //cout << "GLViewer_ViewPort2d::paintEvent" << endl;
    myGLWidget->updateGL();
    GLViewer_ViewPort::paintEvent( e );
}
void GLViewer_ViewPort2d::pan ( int  dx,
int  dy 
) [protected, virtual]

Sets offset to view.

Parameters:
dx- X offset
dy- Y offset

Definition at line 634 of file GLViewer_ViewPort2d.cxx.

{
    //cout << "GLViewer_ViewPort2d::pan " << dx << " " << dy << endl;

    /*myXPan += dx / myXScale;
    myYPan += dy / myYScale;

    float ra, rx, ry, rz;
    myGLWidget->getRotation( ra, rx, ry, rz );
    GLfloat angle = ra * PI / 180.;

    if( myGrid )
        myGrid->setPan( myXPan*cos(angle) + myYPan*sin(angle),
                        -myXPan*sin(angle) + myYPan*cos(angle) );

    */
    float ra, rx, ry, rz;
    myGLWidget->getRotation( ra, rx, ry, rz );
    GLfloat angle = ra * PI / 180.;

    myXPan += (dx*cos(angle) + dy*sin(angle)) / myXScale;
    myYPan += (-dx*sin(angle) + dy*cos(angle)) / myXScale;

    if( myGrid )
        myGrid->setPan( myXPan, myYPan );

    myGLWidget->setPan( myXPan, myYPan, 0.0 );
    myGLWidget->setScale( myXScale, myYScale, 1.0 );
    myGLWidget->updateGL();
}
void GLViewer_ViewPort2d::reset ( ) [protected, virtual]

Returns view to begin state.

Resets view to start state.

Definition at line 594 of file GLViewer_ViewPort2d.cxx.

{
    //cout << "GLViewer_ViewPort2d::reset" << endl;

    GLint val[4];
    GLint vpWidth, vpHeight;

    myGLWidget->makeCurrent();
    glGetIntegerv( GL_VIEWPORT, val );
    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;

    if( myGrid )
    {
        myGrid->setPan( 0.0, 0.0 );
        myGrid->setZoom( zoom / myXScale );
    }

    myXPan = 0.0;
    myYPan = 0.0;
    myXScale = zoom;
    myYScale = zoom;

    myGLWidget->setPan( myXPan, myYPan, 0.0 );
    myGLWidget->setScale( myXScale, myYScale, 1.0 );
    myGLWidget->setRotationAngle( 0.0 );
    myGLWidget->setRotation( 0.0, 0.0, 0.0, 1.0 );
    myGLWidget->updateGL();
}

Here is the call graph for this function:

void GLViewer_ViewPort2d::resizeEvent ( QResizeEvent *  e) [protected, virtual]

Custom resize event handler.

Definition at line 585 of file GLViewer_ViewPort2d.cxx.

{
    //cout << "GLViewer_ViewPort2d::resizeEvent" << endl;
    GLViewer_ViewPort::resizeEvent( e );
}
void GLViewer_ViewPort2d::rotate ( int  intX,
int  intY 
)

Process rotation.

Performs rotation.

Parameters:
intX,intY- current point

Definition at line 928 of file GLViewer_ViewPort2d.cxx.

{
    GLint val[4];
    GLint vpWidth, vpHeight;

    myGLWidget->makeCurrent();
    glGetIntegerv( GL_VIEWPORT, val );
    vpWidth = val[2];
    vpHeight = val[3];

    float x = intX, y = intY;
    float x0 = vpWidth/2;
    float y0 = vpHeight/2;

    float xs, ys, zs, dx, dy;
    myGLWidget->getRotationStart( xs, ys, zs );

    xs = xs - x0;
    x = x - x0;
    dx = x - xs;
    ys = y0 - ys;
    y = y0 - y;
    dy = y - ys;

    float l1 = pow( double( xs*xs + ys*ys ), 0.5 );
    float l2 = pow( double( x*x + y*y ), 0.5 );
    float l = pow( double( dx*dx + dy*dy ), 0.5 );

    double mult = xs * y - x * ys;
    short sign;
    if( mult > 0 ) sign = 1;
    else if( mult < 0 ) sign = -1;
    else sign = 0;

    float anglePrev = myGLWidget->getRotationAngle();
    float angleNew = sign * acos( ( l1*l1 + l2*l2 - l*l ) / ( 2 * l1 * l2 )) * 180. / PI;
    float angle = anglePrev + angleNew;

    // GLfloat anAngle = angle * PI / 180.; unused

    float ra, rx, ry, rz;
    myGLWidget->getRotation( ra, rx, ry, rz );
    myGLWidget->setRotation( angle, rx, ry, rz );
    myGLWidget->updateGL();
}

Returns selection by rect.

Returns:
rectangle selection

Definition at line 1227 of file GLViewer_ViewPort2d.cxx.

{
    QRect aRect;
    if( mypFirstPoint && mypLastPoint )
    {
        aRect.setLeft( qMin( mypFirstPoint->x(), mypLastPoint->x() ) );
        aRect.setTop( qMin( mypFirstPoint->y(), mypLastPoint->y() ) );
        aRect.setRight( qMax( mypFirstPoint->x(), mypLastPoint->x() ) );
        aRect.setBottom( qMax( mypFirstPoint->y(), mypLastPoint->y() ) );
    }

    return aRect;
}

Here is the caller graph for this function:

void GLViewer_ViewPort2d::setBackgroundColor ( const QColor &  color)

Sets background color.

Changes background color.

Parameters:
color- new background color

Definition at line 501 of file GLViewer_ViewPort2d.cxx.

{
    GLViewer_ViewPort::setBackgroundColor( color );
    myGLWidget->makeCurrent();
    glClearColor( ( GLfloat )color.red() / 255,
            ( GLfloat )color.green() / 255,
            ( GLfloat )color.blue() / 255, 1.0 );
    myGLWidget->repaint();
}
void GLViewer_ViewPort2d::setBorder ( GLViewer_Rect *  border) [inline]

Sets borders of scene.

Definition at line 93 of file GLViewer_ViewPort2d.h.

{ myBorder = border; }
void GLViewer_ViewPort2d::setCenter ( int  x,
int  y 
) [protected, virtual]

Sets view center in global coords.

Parameters:
x,y- global co-ordinates of center

Definition at line 669 of file GLViewer_ViewPort2d.cxx.

{
    //cout << "GLViewer_ViewPort2d::setCenter" << endl;

    GLint val[4];
    GLint vpWidth, vpHeight;

    myGLWidget->makeCurrent();
    glGetIntegerv( GL_VIEWPORT, val );
    vpWidth = val[2];
    vpHeight = val[3];

    myXPan -= ( x - vpWidth/2 ) / myXScale;
    myYPan += ( y - vpHeight/2 ) / myYScale;

    if( myGrid )
    {
        myGrid->setPan( myXPan, myYPan );
        myGrid->setZoom( myXOldScale / myXScale );
    }

    myXScale = myXOldScale;
    myYScale = myYOldScale;

    myGLWidget->setPan( myXPan, myYPan, 0.0 );
    myGLWidget->setScale( myXScale, myYScale, 1.0 );
    myGLWidget->updateGL();
}
void GLViewer_ViewPort2d::setGridColor ( const QColor  gridColor,
const QColor  axisColor 
)

Returns grid color.

Changes grid color.

Parameters:
gridColor- new grid color
axisColor- new axis color

Definition at line 484 of file GLViewer_ViewPort2d.cxx.

{
    if( myGrid )
    {
        myGrid->setGridColor( ( GLfloat )gridColor.red() / 255,
                  ( GLfloat )gridColor.green() / 255,
                  ( GLfloat )gridColor.blue() / 255 );
        myGrid->setAxisColor( ( GLfloat )axisColor.red() / 255,
                  ( GLfloat )axisColor.green() / 255,
                  ( GLfloat )axisColor.blue() / 255 );
    }
}
void GLViewer_ViewPort2d::setMargin ( GLfloat  margin) [inline]

Sets margin of borders.

Definition at line 98 of file GLViewer_ViewPort2d.h.

{ myMargin = margin; }
bool GLViewer_ViewPort2d::startPulling ( GLViewer_Pnt  point)

It is for ouv

Definition at line 1243 of file GLViewer_ViewPort2d.cxx.

{
    GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer();
    GLViewer_Context* aContext = aViewer->getGLContext();
    ObjList anObjects = aContext->getObjects();

    for( ObjList::Iterator it = anObjects.begin(); it != anObjects.end(); ++it )
    {
        GLViewer_Object* anObject = *it;
        GLViewer_Rect aRect = anObject->getPullingRect();

        if( aRect.contains( point ) && anObject->startPulling( point ) )
        {
            myIsPulling = true;
            myPullingObject = anObject;
            setCursor( *getHandCursor() );
            return true;
        }
    }

    return false;
}

Here is the call graph for this function:

void GLViewer_ViewPort2d::startRotation ( int  x,
int  y 
)

Begins rotation.

Parameters:
x,y- start point

Definition at line 919 of file GLViewer_ViewPort2d.cxx.

{
    myGLWidget->setRotationStart( x, y, 1.0 );
}

Initializes before selecting by rect.

Initializes rectangle selection.

Parameters:
x,y- start point

Definition at line 1165 of file GLViewer_ViewPort2d.cxx.

{
    if( !mypFirstPoint && !mypLastPoint )
    {
        mypFirstPoint = new QPoint( x, y );
        mypLastPoint = new QPoint( x, y );
    }

    if ( !myRectBand ) {
      myRectBand = new QRubberBand( QRubberBand::Rectangle, this );
      QPalette palette;
      palette.setColor(myRectBand->foregroundRole(), Qt::white);
      myRectBand->setPalette(palette);
    }
    myRectBand->hide();
}

On/off compass.

Creates or deletes compass.

Parameters:
on- if it is true, then to create

Definition at line 453 of file GLViewer_ViewPort2d.cxx.

{
    if( on )
        myCompass = new GLViewer_Compass( Qt::green, 30, GLViewer_Compass::TopRight, 10, 5, 12, 3 );
    else if( myCompass )
        delete myCompass;
}

On/off rectangular grid.

Creates or deletes grid.

Parameters:
on- if it is true, then to create

Definition at line 465 of file GLViewer_ViewPort2d.cxx.

{
    if( on )
    {
        myGrid = new GLViewer_Grid( 2*WIDTH, 2*HEIGHT,
                                    2*WIDTH, 2*HEIGHT,
                                    GRID_XSIZE, GRID_YSIZE,
                                    myXPan, myYPan,
                                    myXScale, myYScale );
    }
    else if( myGrid )
        delete myGrid;
}

Emits after any transformation.

Here is the caller graph for this function:

GLViewer_Rect GLViewer_ViewPort2d::win2GLV ( const QRect &  theRect) const

Transforms window rect to global rect.

Convert rectangle in window co-ordinates to GL co-ordinates.

Returns:
converted rectangle

Definition at line 1306 of file GLViewer_ViewPort2d.cxx.

{
  GLViewer_Rect aRect;

  GLdouble        modelMatrix[16], projMatrix[16];
  GLint           viewport[4];

  GLdouble        objx1, objy1;
  GLdouble        objx2, objy2;
  GLdouble        objz;

  glGetIntegerv (GL_VIEWPORT, viewport);
  glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix);
  glGetDoublev (GL_PROJECTION_MATRIX, projMatrix);

  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 );
  aRect.setBottom( objy2 );

  return aRect;
}
void GLViewer_ViewPort2d::zoom ( int  x0,
int  y0,
int  x1,
int  y1 
) [protected, virtual]

Process zoming transformation with mouse tracking from ( x0, y0 ) to ( x1, y1 )

Definition at line 701 of file GLViewer_ViewPort2d.cxx.

{
    //cout << "GLViewer_ViewPort2d::zoom" << endl;

    float dx, dy, zm;
    dx = x - x0;
    dy = y - y0;

    if ( dx == 0. && dy == 0. )
        return;

    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;

    if( myGrid )
    {
        if( myGrid->setZoom( zm ) )
        {
            myGLWidget->setPan( myXPan, myYPan, 0.0 );
            myGLWidget->setScale( myXScale, myYScale, 1.0 );
            myGLWidget->updateGL();
        }
        else
        {// undo
            myXScale = bX;
            myYScale = bY;
        }
    }
    else
    {
        myGLWidget->setPan( myXPan, myYPan, 0.0 );
        myGLWidget->setScale( myXScale, myYScale, 1.0 );
        myGLWidget->updateGL();
    }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 210 of file GLViewer_ViewPort2d.h.

GLViewer_Rect* GLViewer_ViewPort2d::myBorder [protected]

Definition at line 209 of file GLViewer_ViewPort2d.h.

GLViewer_Compass* GLViewer_ViewPort2d::myCompass [protected]

Definition at line 224 of file GLViewer_ViewPort2d.h.

Definition at line 228 of file GLViewer_ViewPort2d.h.

Definition at line 229 of file GLViewer_ViewPort2d.h.

Definition at line 208 of file GLViewer_ViewPort2d.h.

GLViewer_Grid* GLViewer_ViewPort2d::myGrid [protected]

Definition at line 223 of file GLViewer_ViewPort2d.h.

Definition at line 213 of file GLViewer_ViewPort2d.h.

Definition at line 227 of file GLViewer_ViewPort2d.h.

flag to block mouse release event just after mouse double-click

Definition at line 244 of file GLViewer_ViewPort2d.h.

Definition at line 236 of file GLViewer_ViewPort2d.h.

GLfloat GLViewer_ViewPort2d::myMargin [protected]

Definition at line 212 of file GLViewer_ViewPort2d.h.

QtxToolTip* GLViewer_ViewPort2d::myObjectTip [protected]

Definition at line 242 of file GLViewer_ViewPort2d.h.

Definition at line 232 of file GLViewer_ViewPort2d.h.

QPoint* GLViewer_ViewPort2d::mypLastPoint [protected]

Definition at line 233 of file GLViewer_ViewPort2d.h.

Definition at line 237 of file GLViewer_ViewPort2d.h.

QRubberBand* GLViewer_ViewPort2d::myRectBand [protected]

selection rectangle rubber band

Definition at line 246 of file GLViewer_ViewPort2d.h.

Definition at line 207 of file GLViewer_ViewPort2d.h.

Definition at line 239 of file GLViewer_ViewPort2d.h.

Definition at line 214 of file GLViewer_ViewPort2d.h.

GLfloat GLViewer_ViewPort2d::myXOldScale [protected]

Definition at line 218 of file GLViewer_ViewPort2d.h.

GLfloat GLViewer_ViewPort2d::myXPan [protected]

Definition at line 220 of file GLViewer_ViewPort2d.h.

GLfloat GLViewer_ViewPort2d::myXScale [protected]

Definition at line 216 of file GLViewer_ViewPort2d.h.

GLfloat GLViewer_ViewPort2d::myYOldScale [protected]

Definition at line 219 of file GLViewer_ViewPort2d.h.

GLfloat GLViewer_ViewPort2d::myYPan [protected]

Definition at line 221 of file GLViewer_ViewPort2d.h.

GLfloat GLViewer_ViewPort2d::myYScale [protected]

Definition at line 217 of file GLViewer_ViewPort2d.h.


The documentation for this class was generated from the following files: