From: ouv Date: Thu, 2 Sep 2010 15:15:30 +0000 (+0000) Subject: 1) Improvement of the dragging mechanism X-Git-Tag: DIAGRAM_0_1~35 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b43d0a3b425bdc379bd9f9f9e72b302fbd0a0330;p=modules%2Fgui.git 1) Improvement of the dragging mechanism 2) Shadow of the foreground --- diff --git a/src/GLViewer/GLViewer_Geom.cxx b/src/GLViewer/GLViewer_Geom.cxx index 7efc3880b..a296a2219 100644 --- a/src/GLViewer/GLViewer_Geom.cxx +++ b/src/GLViewer/GLViewer_Geom.cxx @@ -25,6 +25,52 @@ #define FAR_POINT 1e10 // Value used as a "very distant" co-ordinate #define TOLERANCE 1e-3 +/*! + Checks that the rectangle contains point +*/ +bool GLViewer_Rect::contains( const GLViewer_Pnt& thePnt ) const +{ + return ( thePnt.x() >= myLeft && thePnt.x() <= myRight && + thePnt.y() >= myBottom && thePnt.y() <= myTop ); +} + +/*! + Checks that the rectangle contains another rectangle +*/ +bool GLViewer_Rect::contains( const GLViewer_Rect& theRect ) const +{ + return ( theRect.left() >= myLeft && theRect.right() <= myRight && + theRect.bottom() >= myBottom && theRect.top() <= myTop ); +} + +/*! + Checks that X projection of the rectangle contains X projection of another rectangle +*/ +bool GLViewer_Rect::containsByX( const GLViewer_Rect& theRect ) const +{ + return ( theRect.left() >= myLeft && theRect.right() <= myRight ); +} + +/*! + Checks that Y projection of the rectangle contains Y projection of another rectangle +*/ +bool GLViewer_Rect::containsByY( const GLViewer_Rect& theRect ) const +{ + return ( theRect.bottom() >= myBottom && theRect.top() <= myTop ); +} + +/*! + Moves the rectangle +*/ +void GLViewer_Rect::move( const float theDX, const float theDY ) +{ + myLeft += theDX; + myRight += theDX; + myTop += theDY; + myBottom += theDY; +} + + /*! constructs a real segment bounded by two points */ diff --git a/src/GLViewer/GLViewer_Geom.h b/src/GLViewer/GLViewer_Geom.h index 770f358b9..522408ac7 100644 --- a/src/GLViewer/GLViewer_Geom.h +++ b/src/GLViewer/GLViewer_Geom.h @@ -116,19 +116,20 @@ public: //! Checks valid status bool isValid() const { return ( myLeft < myRight && myBottom < myTop ); } - //! Checks staus of contains point - bool contains( GLViewer_Pnt pnt ) const { return ( pnt.x() > left() && - pnt.x() < right() && - pnt.y() > bottom() && - pnt.y() < top() ); } - - void move( const float x, const float y ) - { - myLeft += x; - myRight += x; - myTop += y; - myBottom += y; - } + //! Checks that the rectangle contains point + bool contains( const GLViewer_Pnt& thePnt ) const; + + //! Checks that the rectangle contains another rectangle + bool contains( const GLViewer_Rect& theRect ) const; + + //! Checks that X projection of the rectangle contains X projection of another rectangle + bool containsByX( const GLViewer_Rect& theRect ) const; + + //! Checks that Y projection of the rectangle contains Y projection of another rectangle + bool containsByY( const GLViewer_Rect& theRect ) const; + + //! Moves the rectangle + void move( const float theDX, const float theDY ); protected: float myLeft; diff --git a/src/GLViewer/GLViewer_Object.h b/src/GLViewer/GLViewer_Object.h index e946154dc..80c9f7868 100644 --- a/src/GLViewer/GLViewer_Object.h +++ b/src/GLViewer/GLViewer_Object.h @@ -47,7 +47,7 @@ class GLViewer_AspectLine; class GLViewer_Group; class GLViewer_CoordSystem; class GLViewer_Text; -//class GLViewer_Owner; +class GLViewer_Viewer2d; class SUIT_DataOwner; @@ -189,6 +189,10 @@ public: virtual void moveObject( float dx, float dy, bool fromGroup = false ) = 0; //! Finaly recomputing object after moving virtual bool finishMove() { return true; } + //! Checks that moving the object by X axis is allowed + virtual bool isMovingByXAllowed( float theDX ) { return true; } + //! Checks that moving the object by Y axis is allowed + virtual bool isMovingByYAllowed( float theDY ) { return true; } //! Returns visible object status virtual bool getVisible() const { return myIsVisible; } diff --git a/src/GLViewer/GLViewer_ViewPort2d.cxx b/src/GLViewer/GLViewer_ViewPort2d.cxx index 5fc5cd59a..61da7c1dc 100644 --- a/src/GLViewer/GLViewer_ViewPort2d.cxx +++ b/src/GLViewer/GLViewer_ViewPort2d.cxx @@ -294,31 +294,64 @@ void GLViewer_ViewPort2d::onDragObject( QMouseEvent* e ) return; } - //QPoint aNewPos = e->pos(); - //GLViewer_Viewer2d* aViewer = (GLViewer_Viewer2d*)getViewFrame()->getViewer(); - - if( anObject && (e->buttons() & Qt::LeftButton ) ) + ObjList anObjectsToMove; + 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); - } + if( GLViewer_Object* aMovingObject = aContext->SelectedObject() ) + anObjectsToMove.append( aMovingObject ); } else - anObject->moveObject( aX - *myCurDragPosX, anY - *myCurDragPosY); + anObjectsToMove.append( anObject ); } - else if( aContext->NbSelected() && (e->buttons() & Qt::MidButton ) ) + else if( aContext->NbSelected() && ( e->buttons() & Qt::MidButton ) ) + { for( aContext->InitSelected(); aContext->MoreSelected(); aContext->NextSelected() ) - (aContext->SelectedObject())->moveObject( aX - *myCurDragPosX, anY - *myCurDragPosY); + if( GLViewer_Object* aMovingObject = aContext->SelectedObject() ) + anObjectsToMove.append( aMovingObject ); + } + + float aDX = aX - *myCurDragPosX; + float aDY = anY - *myCurDragPosY; + + bool anIsMovingByXAllowed = true, anIsMovingByYAllowed = true; + ObjList::const_iterator anObjIter, anObjIterEnd = anObjectsToMove.end(); + for( anObjIter = anObjectsToMove.begin(); anObjIter != anObjIterEnd; anObjIter++ ) + if( GLViewer_Object* aMovingObject = *anObjIter ) + { + if( !aMovingObject->isMovingByXAllowed( aDX ) ) + anIsMovingByXAllowed = false; + if( !aMovingObject->isMovingByYAllowed( aDY ) ) + anIsMovingByYAllowed = false; + } + + if( !anIsMovingByXAllowed && !anIsMovingByYAllowed ) + return; // myCurDragPosX and myCurDragPosY shouldn't be changed - delete myCurDragPosX; - delete myCurDragPosY; - myCurDragPosX = new float(aX); - myCurDragPosY = new float(anY); + if( !anIsMovingByXAllowed ) + aDX = 0; + + if( !anIsMovingByYAllowed ) + aDY = 0; + + anObjIterEnd = anObjectsToMove.end(); + for( anObjIter = anObjectsToMove.begin(); anObjIter != anObjIterEnd; anObjIter++ ) + if( GLViewer_Object* aMovingObject = *anObjIter ) + aMovingObject->moveObject( aDX, aDY ); + + if( anIsMovingByXAllowed ) + { + delete myCurDragPosX; + myCurDragPosX = new float(aX); + } + + if( anIsMovingByYAllowed ) + { + delete myCurDragPosY; + myCurDragPosY = new float(anY); + } myGLWidget->updateGL(); } diff --git a/src/GLViewer/GLViewer_Widget.cxx b/src/GLViewer/GLViewer_Widget.cxx index f46d2b5fa..4f638570a 100644 --- a/src/GLViewer/GLViewer_Widget.cxx +++ b/src/GLViewer/GLViewer_Widget.cxx @@ -404,27 +404,54 @@ void GLViewer_Widget::paintGL() // foreground if( myIsForegroundEnabled ) { + GLfloat x1 = -myForegroundMargin, x2 = myForegroundWidth + myForegroundMargin; + GLfloat y1 = -myForegroundMargin, y2 = myForegroundHeight + myForegroundMargin; + + // shadow (2 pixels, always black) + GLfloat xs = 2. / myXScale; + GLfloat ys = 2. / myYScale; + + glColor3f( 0.0, 0.0, 0.0 ); + + // right shadow + glBegin( GL_POLYGON ); + glVertex2f( x2, y1 - ys ); + glVertex2f( x2 + xs, y1 - ys ); + glVertex2f( x2 + xs, y2 - ys ); + glVertex2f( x2, y2 - ys ); + glEnd(); + + // bottom shadow + glBegin( GL_POLYGON ); + glVertex2f( x1 + xs, y1 - ys ); + glVertex2f( x2 + xs, y1 - ys ); + glVertex2f( x2 + xs, y1 ); + glVertex2f( x1 + xs, y1 ); + glEnd(); + + // forefround sheet glColor3f( myForegroundColor.redF(), myForegroundColor.greenF(), myForegroundColor.blueF() ); glBegin( GL_POLYGON ); - glVertex2f( - myForegroundMargin, - myForegroundMargin ); - glVertex2f( myForegroundWidth + myForegroundMargin, - myForegroundMargin ); - glVertex2f( myForegroundWidth + myForegroundMargin, myForegroundHeight + myForegroundMargin ); - glVertex2f( - myForegroundMargin, myForegroundHeight + myForegroundMargin ); + glVertex2f( x1, y1 ); + glVertex2f( x2, y1 ); + glVertex2f( x2, y2 ); + glVertex2f( x1, y2 ); glEnd(); + // foreground frame glColor3f( myForegroundFrameColor.redF(), myForegroundFrameColor.greenF(), myForegroundFrameColor.blueF() ); glLineWidth( myForegroundFrameLineWidth ); glBegin( GL_LINE_LOOP ); - glVertex2f( - myForegroundMargin, - myForegroundMargin ); - glVertex2f( myForegroundWidth + myForegroundMargin, - myForegroundMargin ); - glVertex2f( myForegroundWidth + myForegroundMargin, myForegroundHeight + myForegroundMargin ); - glVertex2f( - myForegroundMargin, myForegroundHeight + myForegroundMargin ); + glVertex2f( x1, y1 ); + glVertex2f( x2, y1 ); + glVertex2f( x2, y2 ); + glVertex2f( x1, y2 ); glEnd(); }