Back to index

salome-gui  6.5.0
GLViewer_ViewPort.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  Author : OPEN CASCADE
00024 // File:      GLViewer_ViewPort.h
00025 // Created:   November, 2004
00026 //
00027 #ifndef GLVIEWER_VIEWPORT_H
00028 #define GLVIEWER_VIEWPORT_H
00029 
00030 #include "GLViewer.h"
00031 
00032 //#include <QList>
00033 #include <QColor>
00034 //#include <QAction>
00035 #include <QWidget>
00036 
00037 //#include <Aspect_Window.hxx>
00038 
00039 class QRect;
00040 class QCursor;
00041 class QPainter;
00042 class GLViewer_ViewSketcher;
00043 class GLViewer_ViewTransformer;
00044 
00045 #ifdef WIN32
00046 #pragma warning( disable:4251 )
00047 #endif
00048 
00049 enum BlockStatus
00050 {
00051     BS_NoBlock          = 0x0000,
00052     BS_Highlighting     = 0x0001,
00053     BS_Selection        = 0x0002,
00054     BS_Dragging         = 0x0004
00055 };
00056 
00061 class GLVIEWER_API GLViewer_ViewPort: public QWidget
00062 {
00063     Q_OBJECT
00064     friend class GLViewer_ViewSketcher;
00065     friend class GLViewer_ViewTransformer;
00066 
00067 public:
00068     GLViewer_ViewPort( QWidget* parent );
00069     ~GLViewer_ViewPort();
00070 
00071 public:
00073     void                             setSketchingEnabled( bool );
00075     bool                             isSketchingEnabled() const;
00077     void                             setTransformEnabled( bool );
00079     bool                             isTransformEnabled() const;
00080 
00082     virtual QColor                   backgroundColor() const;
00084     virtual void                     setBackgroundColor( const QColor& );
00085 
00087     void                             redrawPainters();
00088 
00090     virtual void                     onUpdate();
00091 
00093     virtual BlockStatus              currentBlock(){ return BS_NoBlock; }
00094 
00095 protected:
00096     enum ViewType { Type2D, Type3D };
00097     void                             selectVisualId( ViewType );
00098 
00099     virtual QPaintDevice*            getPaintDevice() { return this; }
00100     virtual void                     contextMenuEvent( QContextMenuEvent * e );
00101 
00103     static void                      createCursors();
00104     static void                      destroyCursors();
00105     static QCursor*                  getHandCursor() { return handCursor; }
00106     static void                      setHandCursor( const QCursor& newCursor );
00107     static QCursor*                  getPanCursor() { return panCursor; }
00108     static void                      setPanCursor( const QCursor& newCursor );
00109     static QCursor*                  getPanglCursor() { return panglCursor; }
00110     static void                      setPanglCursor( const QCursor& newCursor );
00111     static QCursor*                  getZoomCursor() { return zoomCursor; }
00112     static void                      setZoomCursor( const QCursor& newCursor );
00113 
00114 public://ouv
00115     static QCursor*                  getDefaultCursor() { return defCursor; }
00116     static void                      setDefaultCursor( const QCursor& newCursor );
00117     static QCursor*                  getRotCursor() { return rotCursor; }
00118     static void                      setRotCursor( const QCursor& newCursor );
00119     static QCursor*                  getSketchCursor() { return sketchCursor; }
00120     static void                      setSketchCursor( const QCursor& newCursor );
00121 
00122 protected:
00124     virtual void                     paintEvent( QPaintEvent *);
00125     virtual void                     mouseMoveEvent( QMouseEvent *);
00126     virtual void                     mouseReleaseEvent( QMouseEvent *);
00127     virtual void                     mousePressEvent( QMouseEvent *);
00128     virtual void                     mouseDoubleClickEvent( QMouseEvent *);
00129     virtual void                     keyPressEvent( QKeyEvent *);
00130     virtual void                     keyReleaseEvent( QKeyEvent *);
00131     virtual void                     wheelEvent( QWheelEvent *);
00132 
00134     virtual void                     reset() = 0;
00135     virtual void                     pan( int, int ) = 0;
00136     virtual void                     setCenter( int, int ) = 0;    
00137     virtual void                     zoom( int, int, int, int ) = 0;
00138     virtual void                     fitRect( const QRect& ) = 0;
00139     virtual void                     fitSelect() = 0;
00140     virtual void                     fitAll( bool keepScale = false, bool withZ = true ) = 0;
00141 
00142 protected slots:
00143     virtual void                     onChangeBgColor();
00144 
00145 signals:
00146     void                             vpKeyEvent( QKeyEvent* );
00147     void                             vpMouseEvent( QMouseEvent* );
00148     void                             vpWheelEvent( QWheelEvent* );
00149     void                             vpDrawExternal( QPainter* );
00150 
00151     void                             contextMenuRequested( QContextMenuEvent* );
00152 
00153 private:
00154     void                             initialize();
00155     void                             cleanup();
00156 
00157 protected:
00158     //Handle(Aspect_Window)            myWindow;
00159     bool                             myEnableSketching;
00160     bool                             myEnableTransform;
00161     bool                             myPaintersRedrawing;   /* set to draw externally */
00162     //QList<QAction>                   myPopupActions;
00163 
00164 private:
00165     static int                       nCounter;              /* objects counter */
00166     static QCursor*                  defCursor;
00167     static QCursor*                  panglCursor;
00168     static QCursor*                  handCursor;
00169     static QCursor*                  panCursor;
00170     static QCursor*                  zoomCursor;
00171     static QCursor*                  rotCursor;
00172     static QCursor*                  sketchCursor;
00173 };
00174 
00175 #ifdef WIN32
00176 #pragma warning ( default:4251 )
00177 #endif
00178 
00179 #endif