Back to index

salome-gui  6.5.0
GLViewer_Viewer.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_Viewer.h
00025 // Created:   November, 2004
00026 //
00027 #ifndef GLVIEWER_VIEWER_H
00028 #define GLVIEWER_VIEWER_H
00029 
00030 #include "GLViewer.h"
00031 #include "GLViewer_Defs.h"
00032 #include <SUIT_ViewModel.h>
00033 
00034 #include <QCursor>
00035 #include <QObject>
00036 
00037 class QMouseEvent;
00038 class QKeyEvent;
00039 class QWheelEvent;
00040 class QRect;
00041 class QRubberBand;
00042 
00043 class GLViewer_Selector;
00044 class GLViewer_ViewSketcher;
00045 class GLViewer_ViewTransformer;
00046 class GLViewer_ViewFrame;
00047 
00048 //class SUIT_Desktop;
00049 class SUIT_ViewWindow;
00050 
00051 #ifdef WIN32
00052 #pragma warning( disable:4251 )
00053 #endif
00054 
00059 class GLVIEWER_API GLViewer_Viewer: public SUIT_ViewModel
00060 {
00061     Q_OBJECT
00062 
00063 public:
00064     enum SelectionMode { NoSelection, Single, Multiple };
00065     enum TransformType { NoTransform, Reset, FitAll, FitRect, FitSelect,
00066                          Zoom, PanGlobal, Pan, Rotate, UserTransform = 100 };
00067     enum SketchingType { NoSketching, Rect, UserSketching = 100 };
00068 
00069 public:
00070     GLViewer_Viewer( const QString& title );
00071     ~GLViewer_Viewer();
00072 
00073 public:
00074     virtual void                 setViewManager( SUIT_ViewManager* theViewManager );
00075     virtual QString              getType() const { return Type(); }
00076     static QString               Type() { return "GLViewer_ViewModel";  }
00077 
00078     virtual void                 contextMenuPopup( QMenu* );
00079 
00080 public:
00081     void                         setSelectionMode( SelectionMode );
00082     SelectionMode                getSelectionMode() const;
00083     GLViewer_Selector*           getSelector() const;
00084 
00085     virtual void                 update( int = 0 );
00086 
00087     void                         activateTransform( int );
00088     void                         activateSketching( int );
00089 
00090     GLViewer_ViewFrame*          getActiveView() const;
00091 
00092 signals:
00093     void                         selectionChanged( SelectionChangeStatus );
00094 
00095 protected:
00096     virtual void                 onSketchingStarted();
00097     virtual void                 onSketchingFinished();
00098     virtual void                 onTransformationStarted();
00099     virtual void                 onTransformationFinished();
00100     virtual void                 onSelectionModeChanged();
00101 
00102     virtual void                 unhilightDetected();
00103     virtual bool                 eventFilter( QObject*, QEvent* );
00104 
00105     /* virtual constructors */
00106     virtual GLViewer_ViewTransformer* createTransformer( int );
00107     virtual GLViewer_ViewSketcher*    createSketcher( int );
00108     virtual GLViewer_Selector*        createSelector();
00109 
00110     virtual void                 startOperations( QMouseEvent* ) {}
00111     virtual bool                 updateOperations( QMouseEvent* ) { return false; }
00112     virtual void                 finishOperations( QMouseEvent* ) {}
00113     virtual void                 startOperations( QWheelEvent* ) {}
00114 
00115 protected slots:
00116     virtual void                 onKeyEvent( SUIT_ViewWindow*, QKeyEvent* );
00117     virtual void                 onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
00118     virtual void                 onWheelEvent( SUIT_ViewWindow*, QWheelEvent* );
00119 
00120     virtual void                 onSelectionCancel();
00121     virtual void                 onSelectionDone( bool add, SelectionChangeStatus status );
00122 
00123     virtual void                 onChangeBgColor();
00124 
00125 private:
00126     void                         handleMouseMove( QMouseEvent* );
00127     void                         handleMousePress( QMouseEvent* );
00128     void                         handleMouseRelease( QMouseEvent* );
00129     void                         handleWheel( QWheelEvent* );
00130 
00131 protected:
00132     GLViewer_Selector*           mySelector;        /* selector */
00133     SelectionMode                mySelMode;         /* current selection mode */
00134     GLViewer_ViewSketcher*       mySketcher;        /* sketch manipulator */
00135     GLViewer_ViewTransformer*    myTransformer;     /* transform manipulator */
00136 };
00137 
00138 class GLVIEWER_API GLViewer_ViewTransformer : public QObject
00139 {
00140 public:
00141     GLViewer_ViewTransformer( GLViewer_Viewer*, int type );
00142     ~GLViewer_ViewTransformer();
00143 
00144 public:
00146     int                          type() const;
00147 
00149     static int                   accelKey() { return acccelKey; }
00150     static void                  setAccelKey( int k ) { acccelKey = k; }
00151 
00153     static int                   zoomButton() { return zoomBtn; }
00154     static void                  setZoomButton( int b ) { zoomBtn = b; }
00155 
00157     static int                   panButton() { return panBtn; }
00158     static void                  setPanButton( int b ) { panBtn = b; }
00159 
00161     static int                   panGlobalButton() { return panGlobalBtn; }
00162     static void                  setPanGlobalButton( int b ) { panGlobalBtn = b; }
00163 
00165     static int                   fitRectButton() { return fitRectBtn; }
00166     static void                  setFitRectButton( int b ) { fitRectBtn = b; }
00167 
00168     virtual void                 exec();
00169     virtual bool                 eventFilter( QObject*, QEvent* );
00170 
00171 protected:
00172     enum TransformState { Debut, EnTrain, Fin };
00173     virtual void                 onTransform( TransformState );
00174     void                         initTransform( bool );
00175 
00176     void                         drawRect(const QRect& theRect);
00177     void                         endDrawRect();
00178 
00179 protected:
00180     static int                   panBtn;
00181     static int                   zoomBtn;
00182     static int                   fitRectBtn;
00183     static int                   panGlobalBtn;
00184 
00185     static int                   acccelKey;
00186 
00187     GLViewer_Viewer*             myViewer;
00188     int                          myType;
00189     QCursor                      mySavedCursor;
00190     bool                         mySavedMouseTrack;
00191     QPoint                       myStart, myCurr;
00192     int                          myButtonState;
00193     int                          myMajorBtn;
00194 
00195     QRubberBand*                 myRectBand; 
00196 };
00197 
00198 class GLVIEWER_API GLViewer_ViewSketcher : public QObject
00199 {
00200 public:
00201     GLViewer_ViewSketcher( GLViewer_Viewer*, int type );
00202     ~GLViewer_ViewSketcher();
00203 
00204 public:
00206     int                          type() const { return myType; }
00207 
00209     void*                        data() const { return myData; }
00210 
00212     int                          buttonState() const { return myButtonState; }
00213 
00215     static int                   sketchButton() { return sketchBtn; }
00216     static void                  setSketchButton( int b ) { sketchBtn = b; }
00217 
00218     virtual bool                 eventFilter( QObject*, QEvent* );
00219 
00220 protected:
00221     enum SketchState { Debut, EnTrain, Fin };
00222     virtual void                 onSketch( SketchState );
00223 
00224     void                         drawRect(const QRect& theRect);
00225     void                         endDrawRect();
00226 
00227 protected:
00228     static int                   sketchBtn;
00229     GLViewer_Viewer*             myViewer;
00230     int                          myType;
00231     void*                        myData;
00232     QCursor                      mySavedCursor;
00233     QPoint                       myStart, myCurr;
00234     int                          myButtonState;
00235 
00236     QRubberBand*                 myRectBand; 
00237 };
00238 
00239 #ifdef WIN32
00240 #pragma warning ( default:4251 )
00241 #endif
00242 
00243 #endif