#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
*/
//! 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;
class GLViewer_Group;
class GLViewer_CoordSystem;
class GLViewer_Text;
-//class GLViewer_Owner;
+class GLViewer_Viewer2d;
class SUIT_DataOwner;
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; }
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();
}
// 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();
}