Salome HOME
Updated copyright comment
[modules/gui.git] / src / GLViewer / GLViewer_ViewPort2d.h
index 4968b74c67d7a597207a26bc92bdbf83575447e3..0639c6248f4387d4ea78fe895ef836d82a5f738e 100644 (file)
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  Author : OPEN CASCADE
 // File:      GLViewer_ViewPort2d.h
 // Created:   November, 2004
-// Author:    OCC team
-// Copyright (C) CEA 2004
-
-/* GLViewer_ViewPort2d Header File */
+//
+#ifndef GLVIEWER_VIEWPORT2D_H
+#define GLVIEWER_VIEWPORT2D_H
 
-#ifdef WNT
+#ifdef WIN32
 #include <windows.h>
 #endif
 
+#ifdef __APPLE__
+#include <OpenGL/gl.h>
+#include <OpenGL/glu.h>
+#else
 #include <GL/gl.h>
 #include <GL/glu.h>
+#endif
 
 #include "GLViewer_ViewPort.h"
-#include "GLViewer_Drawer.h"
-
-#include <qcolor.h>
-
-class GLViewer_ViewFrame;
-class GLViewer_Object;
-class GLViewer_Pnt;
-class GLViewer_Rect;
-
-/***************************************************************************
-**  Class:   GLViewer_RectangularGrid
-**  Descr:   OpenGL Grid for GLViewer_ViewPort2d
-**  Module:  QAD
-**  Created: UI team, 16.09.02
-****************************************************************************/
-#ifndef GLVIEWER_RECTANGULARGRID_H
-#define GLVIEWER_RECTANGULARGRID_H
-
-class GLVIEWER_EXPORT GLViewer_RectangularGrid 
-{
-public:
-  GLViewer_RectangularGrid();
-  GLViewer_RectangularGrid( float, float, float, float, float, float, float, float, float, float );
-  ~GLViewer_RectangularGrid();
-
-  void                   draw();
-
-  void                   setGridColor( GLfloat, GLfloat, GLfloat );
-  void                   setAxisColor( GLfloat, GLfloat, GLfloat );
-  void                   setGridWidth( float );
-  void                   setCenterRadius( int );
-
-  void                   setSize( float, float );
-  void                   setPan( float, float );
-  bool                   setZoom( float );
-  void                   setResize( float, float, float );
-
-  void                   getSize( float&, float& ) const;
-  void                   getPan( float&, float& ) const;
-  void                   getScale( float&, float& ) const;
-
-  void                   setScaleFactor( int );
-  int                    getScaleFactor();
+#include "GLViewer_Widget.h"
+#include "GLViewer_Geom.h"
 
-protected:
-  bool                   initList();
-
-  GLuint                 myGridList;
-  GLfloat                myGridColor[3];
-  GLfloat                myAxisColor[3];
-  GLfloat                myGridHeight;
-  GLfloat                myGridWidth;
-  GLfloat                myWinW;
-  GLfloat                myWinH;
-  GLfloat                myXSize;
-  GLfloat                myYSize;
-  GLfloat                myXPan;
-  GLfloat                myYPan;
-  GLfloat                myXScale;
-  GLfloat                myYScale;
-  GLfloat                myLineWidth;
-  GLfloat                myCenterWidth;
-  GLint                  myCenterRadius;
-  GLint                  myScaleFactor;
-  GLboolean              myIsUpdate;
-};
+#include <QtOpenGL>
+#include <QColor>
+#include <QPaintDevice>
 
+#ifdef WIN32
+#pragma warning( disable:4251 )
 #endif
 
-/***************************************************************************
-**  Class:   GLViewer_ViewPort2d
-**  Descr:   OpenGL ViewPort 2D
-**  Module:  QAD
-**  Created: UI team, 02.09.02
-****************************************************************************/
-
-//********* class compass for viewport******************
-class GLVIEWER_EXPORT GLViewer_Compass {   
-public:
-    enum Position { TopLeft, TopRight, BottomLeft, BottomRight };
-
-    GLViewer_Compass( const QColor& color = QColor ( 0, 255, 0 ), 
-                   const int size = 60,
-                   const Position pos = TopRight,
-                   const int WidthTop = 20,
-                   const int WidthBottom = 10,
-                   const int HeightTop = 25,
-                   const int HeightBottom = 7 );
-    ~GLViewer_Compass(){ delete myFont; }
-
-    void        setCompass( const QColor& color, const int size, const Position pos )
-                                                    {myCol=color;mySize=size;myPos=pos;};
-    void        setVisible( const bool vis = true );
-    bool        getVisible(){ return myIsVisible; };
-
-    void        setSize( const int size ){mySize=size;};
-    int         getSize(){ return mySize; };
-
-    void        setPos( const Position pos ){myPos=pos;};
-    int         getPos(){ return myPos; };
-
-    void        setColor( const QColor& color ){myCol=color;};
-    QColor      getColor(){ return myCol; };
-
-    void        setArrowWidthTop( const int WidthTop ){ if( WidthTop<myArrowWidthBottom || 
-                                                            WidthTop>mySize ) return;
-                                                        myArrowWidthTop=WidthTop; };
-    int         getArrowWidthTop(){return myArrowWidthTop;};
-
-    void        setArrowWidthBottom( const int WidthBot ){ if( WidthBot>myArrowWidthTop || WidthBot<1 )return;
-                                                           myArrowWidthBottom=WidthBot; };
-    int         getArrowWidthBottom(){return myArrowWidthBottom;};
-
-    void        setArrowHeightTop( const int HeightTop ){ if( HeightTop>(2*mySize-myArrowHeightBottom ) ||
-                                                              HeightTop<1 )return;
-                                                          myArrowHeightTop=HeightTop;};
-    int         getArrowHeightTop(){return myArrowHeightTop;};
-
-    void        setArrowHeightBottom( const int HeightBot ){ if( HeightBot>( 2*mySize-myArrowHeightTop ) ||
-                                                                 HeightBot<1)return;
-                                                          myArrowHeightBottom=HeightBot;};
-    int         getArrowHeightBottom(){return myArrowHeightBottom;};        
-
-    GLViewer_TexFont* getFont();
-    void           setFont( QFont theFont ){ delete myFont; myFont = new GLViewer_TexFont( &theFont ); } 
-
-protected:
-    QColor          myCol;
-    int             mySize;
-    int             myPos;
-    bool            myIsVisible;
-    int             myArrowWidthTop;
-    int             myArrowWidthBottom;
-    int             myArrowHeightTop;
-    int             myArrowHeightBottom;
-    GLViewer_TexFont*  myFont;
-    bool            isGenereted;
-};
-
-
-#ifndef GLVIEWER_VIEWPORT2D_H
-#define GLVIEWER_VIEWPORT2D_H
-
-#include <qwidget.h>
-#include <qmap.h>
-#include <qpaintdevice.h>
-#include <qgl.h>
-
-#include "GLViewer_Widget.h"
+class GLViewer_Compass;
+class GLViewer_Grid;
+class GLViewer_Object;
+class GLViewer_ViewFrame;
 
 class QtxToolTip;
 
+class QWidget;
+class QRubberBand;
+
+/*! 
+ * Class GLViewer_ViewPort
+ * 2D visualisation canvas of GLViewer
+ */
 class GLViewer_ViewPort2d: public GLViewer_ViewPort
 {
   Q_OBJECT
 
-      enum vpDragState{ noDrag, initDrag, inDrag };
+  //! Dragging states
+  enum vpDragState{ noDrag, initDrag, inDrag };
 
 public:
-    GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
-    ~GLViewer_ViewPort2d();
-
-    void                   turnGrid( GLboolean on );
-    GLViewer_RectangularGrid* getGrid() const { return myGrid; }
-    void                   setGridColor( const QColor gridColor, const QColor axisColor );
-
-    GLViewer_ViewFrame*    getViewFrame() const { return myViewFrame; }
-    GLViewer_Widget*       getGLWidget() const { return myGLWidget; }
-    virtual QPaintDevice*  getPaintDevice() { return myGLWidget; }
-
-    void                   setBackgroundColor( const QColor& color);
-    QColor                 backgroundColor() const;
-
-    void                   setBorder( QRect* border ) { myBorder = border; }
-    QRect*                 getBorder() const { return myBorder; }
-
-    void                   setMargin( GLfloat margin ) { myMargin = margin; }
-    GLfloat                getMargin() const { return myMargin; }
-
-    int                    getHeight() const { return myHeight; }
-    int                    getWidth() const { return myWidth; }
-
-    void                   getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
-    void                   getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
-
-    void                   initResize( int, int );
-
-    void                   startRotation( int, int );
-    void                   rotate( int, int );
-    void                   endRotation();
-
-    bool                   isDragProcess(){ return myIsDragProcess; }
-
-    void                   turnCompass( GLboolean on );
-    void                   drawCompass();
-
-    int                    getViewPortId(){ return myViewPortId; }
-
-    virtual BlockStatus    currentBlock();
-
-    void                   startSelectByRect( int, int );
-    void                   drawSelectByRect( int, int );
-    void                   finishSelectByRect();
-
-    bool                   startPulling( GLViewer_Pnt );
-    void                   drawPulling( GLViewer_Pnt );
-    void                   finishPulling();
-    bool                   isPulling() const { return myIsPulling; }
-
-    //selection by rect
-    QRect                  selectionRect();
-    
-    GLViewer_Rect          win2GLV( const QRect& ) const;
-    QRect                  GLV2win( const GLViewer_Rect& ) const;
+  GLViewer_ViewPort2d( QWidget* parent, GLViewer_ViewFrame* theViewFrame = NULL );
+  ~GLViewer_ViewPort2d();
+
+  //! On/off rectangular grid
+  void                   turnGrid( GLboolean on );
+  //! Returns rectangular grid
+  GLViewer_Grid*         getGrid() const { return myGrid; }
+  //! Returns grid color
+  void                   setGridColor( const QColor gridColor, const QColor axisColor );
+
+  //! Returns parent window
+  GLViewer_ViewFrame*    getViewFrame() const { return myViewFrame; }
+  //! Returns painted widget
+  GLViewer_Widget*       getGLWidget() const { return myGLWidget; }
+  virtual QPaintDevice*  getPaintDevice() { return myGLWidget; }
+
+  //! Sets background color
+  void                   setBackgroundColor( const QColor& color);
+  //! Returns background color
+  QColor                 backgroundColor() const;
+
+  //! Sets borders of scene
+  void                   setBorder( GLViewer_Rect* border ) { myBorder = border; }
+  //! Get current borders of scene
+  GLViewer_Rect*         getBorder() const { return myBorder; }
+  
+  //! Sets margin of borders
+  void                   setMargin( GLfloat margin ) { myMargin = margin; }
+  //! Returns margin of borders
+  GLfloat                getMargin() const { return myMargin; }
+
+  //! Returns width of view
+  int                    getWidth() const { return myWidth; }
+  //! Returns height of view
+  int                    getHeight() const { return myHeight; }
+
+  
+  //! Returns scale factors
+  void                   getScale( GLfloat& xSc, GLfloat& ySc ) const { xSc = myXScale; ySc = myYScale; }
+  //! returns offsets
+  void                   getPan( GLfloat& xPan, GLfloat& yPan ) const { xPan = myXPan; yPan = myYPan; }
+
+  //! Resize view
+  void                   initResize( int width, int height );
+  
+  //! Begins rotation
+  void                   startRotation( int, int );
+  //! Process rotation
+  void                   rotate( int, int );
+  //! Completes rotation
+  void                   endRotation();
+  
+  //! Checks of dragging process state
+  bool                   isDragProcess(){ return myIsDragProcess; }
+  
+  //! On/off compass
+  void                   turnCompass( GLboolean on );
+  //! Draws compass
+  void                   drawCompass();
+  
+  //! Returns unique ID of ViewPort
+  int                    getViewPortId(){ return myViewPortId; }
+  
+  //! Redefined method
+  virtual BlockStatus    currentBlock();
+  
+  //! Initializes before selecting by rect
+  void                   startSelectByRect( int x, int y );
+  //! Draw selecting rectandle
+  void                   drawSelectByRect( int x, int y );
+  //! Pass rect into selector and update
+  void                   finishSelectByRect();
+  
+  //! \warnign It is for ouv
+  bool                   startPulling( GLViewer_Pnt );
+  //! \warnign It is for ouv
+  void                   drawPulling( GLViewer_Pnt );
+  //! \warnign It is for ouv
+  void                   finishPulling();
+  //! \warnign It is for ouv
+  bool                   isPulling() const { return myIsPulling; }
+
+  //! Returns selection by rect
+  QRect                  selectionRect();
+  
+  //! Transforms window rect to global rect 
+  GLViewer_Rect          win2GLV( const QRect& ) const;
+  //! Transforms global rect to window rect
+  QRect                  GLV2win( const GLViewer_Rect& ) const;
 
 signals:
-    void                   vpUpdateValues();
-    void                   objectMoved();
+  //! Emits after any transformation
+  void                   vpUpdateValues();
 
-protected:
-    void                   onCreatePopup();
-    void                   onCreatePopup( QPopupMenu* );
-    void                   onDestroyPopup( QPopupMenu* );
+  void                   objectMoved();
 
-    void                   onDragObject( QMouseEvent* );
+protected:
+  void                   onDragObject( QMouseEvent* );
     
-    virtual void           mouseMoveEvent( QMouseEvent *);
-    virtual void           mousePressEvent( QMouseEvent *);
-    virtual void           mouseReleaseEvent( QMouseEvent *);
-
-    virtual void           paintEvent( QPaintEvent* );
-    virtual void           resizeEvent( QResizeEvent* );
-
-    virtual void           reset();
-    virtual void           pan( int, int );
-    virtual void           setCenter( int, int );    
-    virtual void           zoom( int, int, int, int );
-    virtual void           fitRect( const QRect& );
-    virtual void           fitSelect();
-    virtual void           fitAll( bool keepScale = false, bool withZ = true );
+  virtual void           mouseMoveEvent( QMouseEvent *);
+  virtual void           mousePressEvent( QMouseEvent *);
+  virtual void           mouseReleaseEvent( QMouseEvent *);
+  virtual void           mouseDoubleClickEvent( QMouseEvent *);
+  
+  virtual void           paintEvent( QPaintEvent* );
+  virtual void           resizeEvent( QResizeEvent* );
+
+  //! Returns view to begin state
+  virtual void           reset();
+  //! Sets offset to view
+  virtual void           pan( int dx, int dy );
+  //! Sets view center in global coords
+  virtual void           setCenter( int x, int y );
+  //! Process zoming transformation with mouse tracking from ( x0, y0 ) to ( x1, y1 )
+  virtual void           zoom( int x0, int y0, int x1, int y1 );
+  //! Transforms view by rectangle
+  virtual void           fitRect( const QRect& );
+  //! Transforms view by selection
+  virtual void           fitSelect();
+  //! Transform view by view borders ( if \param keepScale = true, zoom does not change )
+  virtual void           fitAll( bool keepScale = false, bool withZ = true );
 
 protected slots:
-    void                   onStartDragObject();
-    void                   onPasteObject();
-    void                   onCutObject();
-    void                   onCopyObject();
-
-    void                   onMaybeTip( QPoint, QString&, QFont&, QRect&, QRect& );
-
+  //! Initializes drag process
+  void                   onStartDragObject();
+  //! Pastes object from clipboard
+  void                   onPasteObject();
+  //! Cuts object to clipboard
+  void                   onCutObject();
+  //! Copies object to clipboard
+  void                   onCopyObject();
+
+  //! Sets tool tip with \param text to \param theTextReg and on \param theViewReg whan mouse is on \param thePoint
+  void                   onMaybeTip( QPoint thePoint, QString& text, QFont& font, QRect& theTextReg, QRect& theViewReg );
+  
 protected:
-    GLViewer_Widget*       myGLWidget;
-    QColor                 myBackgroundColor;
-    QRect*                 myBorder;
-    GLfloat                myMargin;
-    int                    myHeight;
-    int                    myWidth;
-    GLfloat                myXScale;
-    GLfloat                myYScale;
-    GLfloat                myXOldScale;
-    GLfloat                myYOldScale;
-    GLfloat                myXPan;
-    GLfloat                myYPan;
-    GLViewer_RectangularGrid* myGrid; 
-    GLViewer_ViewFrame*    myViewFrame;
-
-    bool                   myDegenerated;
-
-    //dragging
-    int                    myIsDragProcess;
-    float*                 myCurDragPosX;
-    float*                 myCurDragPosY;
-    
-    GLViewer_Compass*      myCompass;
-
-    //selection by rect
-    QPoint*                mypFirstPoint;
-    QPoint*                mypLastPoint;
+  GLViewer_ViewFrame*    myViewFrame;
+  GLViewer_Widget*       myGLWidget;
+  GLViewer_Rect*         myBorder;
+  QColor                 myBackgroundColor;
+  
+  GLfloat                myMargin;
+  int                    myHeight;
+  int                    myWidth;
+  
+  GLfloat                myXScale;
+  GLfloat                myYScale;
+  GLfloat                myXOldScale;
+  GLfloat                myYOldScale;
+  GLfloat                myXPan;
+  GLfloat                myYPan;
 
-    //pulling
-    bool                   myIsPulling;
-    GLViewer_Object*       myPullingObject;
+  GLViewer_Grid*         myGrid; 
+  GLViewer_Compass*      myCompass;
+
+  //dragging
+  int                    myIsDragProcess;
+  float*                 myCurDragPosX;
+  float*                 myCurDragPosY;
+  
+  //selection by rect
+  QPoint*                mypFirstPoint;
+  QPoint*                mypLastPoint;
+
+  //pulling
+  bool                   myIsPulling;
+  GLViewer_Object*       myPullingObject;
     
-    int                    myViewPortId;
+  int                    myViewPortId;
+
+  //GLViewer_ObjectTip*    myObjectTip;
+  QtxToolTip*            myObjectTip;
+  //! flag to block mouse release event just after mouse double-click
+  bool                   myIsMouseReleaseBlock;
 
-    //GLViewer_ObjectTip*    myObjectTip;
-    QtxToolTip*            myObjectTip;
+  QRubberBand*           myRectBand; //!< selection rectangle rubber band
 };
 
+#ifdef WIN32
+#pragma warning ( default:4251 )
+#endif
+
 #endif