Salome HOME
Moved some functionality to VTKViewer_Utilities.h
[modules/kernel.git] / src / OCCViewer / OCCViewer_ViewPort.h
1 //  SALOME OCCViewer : build OCC Viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : OCCViewer_ViewPort.h
25 //  Author : Nicolas REJNERI
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef OCCViewer_ViewPort_H
30 #define OCCViewer_ViewPort_H
31
32 #include "QAD.h"
33 #include "QAD_Popup.h"
34
35 // QT Includes
36 #include <qrect.h>
37 #include <qcolor.h>
38 #include <qwidget.h>
39 #include <qcursor.h>
40 #include <qpainter.h>
41
42 class QAD_EXPORT OCCViewer_ViewPort: public QWidget, 
43   public QAD_PopupClientServer
44 {
45   Q_OBJECT
46
47   /* Objects counter */
48   static int            nCounter;                               
49         
50   /* Cursors */
51   static QCursor*       defCursor;
52   static QCursor*       handCursor;
53   static QCursor*       panCursor;
54   static QCursor*       zoomCursor;
55   static QCursor*       rotCursor;
56   static QCursor*       glPanCursor;
57
58   void  initialize();
59   void  cleanup();
60
61 public:
62   enum OperationType    {
63     NOTHING,
64     PANVIEW,
65     ZOOMVIEW,
66     ROTATE,
67     PANGLOBAL,
68     WINDOWFIT
69   };
70
71 protected:
72   static void createCursors();
73   static void destroyCursors();
74   
75   static const QCursor* getDefaultCursor() { return defCursor; }
76   static void setDefaultCursor(const QCursor& newCursor);
77   static const QCursor* getHandCursor() { return handCursor; }
78   static void setHandCursor(const QCursor& newCursor);
79   static const QCursor* getPanCursor() { return panCursor; }
80   static void setPanCursor(const QCursor& newCursor);
81   static const QCursor* getZoomCursor() { return zoomCursor; }
82   static void setZoomCursor(const QCursor& newCursor);
83   static const QCursor* getRotCursor() { return rotCursor; }
84   static void setRotCursor(const QCursor& newCursor);
85   static const QCursor* getGlPanCursor() { return rotCursor; }
86   static void setGlPanCursor(const QCursor& newCursor);
87   
88   /* Transformation selected but not started yet */
89   bool          transformRequested() const { return ( myOperation != NOTHING ); }
90   void          setTransformRequested ( OperationType op );
91
92   /* Transformation is selected and already started */
93   bool          transformInProcess() const { return myEventStarted; }
94   void          setTransformInProcess( bool bOn ) { myEventStarted = bOn; }
95
96 public:
97   OCCViewer_ViewPort( QWidget* parent );
98   ~OCCViewer_ViewPort();
99   
100   /* Draw mode management */
101   void          enableDrawMode( bool bEnable );
102   bool          enableDrawMode() const;
103
104   /* Cursors management */
105   void          setDefaultCursorOn();
106   void          setHandCursorOn();
107   void          setPanCursorOn();
108   void          setZoomCursorOn();
109   void          setRotCursorOn();
110   void          setGlPanCursorOn();
111
112   void          resetState();
113   bool          hasWindow() const;
114   void          windowChanged();
115   void          redrawPainters();
116   void          update(int x, int y, int w, int h);
117   
118   void                setOriginalView( OCCViewer_ViewPort* view, const QRect& magnify );
119   OCCViewer_ViewPort* getOriginalView() const;
120   const QRect&        getMagnifyRect() const;
121   const QRect&        getSelectionRect() const;
122
123   /* View transformations */
124   virtual void    activateZoom();       
125   virtual void    activatePanning();
126   virtual void    activateRotation();
127   virtual void    activateWindowFit();
128   virtual void    activateGlobalPanning();      
129   
130   virtual void    fitAll( bool withZ = true ) = 0;
131   virtual void    reset() = 0;
132
133   virtual void    incrementalPan   ( const int incrX, const int incrY ) = 0;
134   virtual void    incrementalZoom  ( const int incr ) = 0;
135   virtual void    incrementalRotate( const int incrX, const int incrY ) = 0;
136
137   /* background color */
138   virtual QColor  backgroundColor() const;
139   virtual void    setBackgroundColor( const QColor& color) = 0;
140
141 protected: 
142   virtual void    paintEvent(QPaintEvent *);
143   virtual void    resizeEvent(QResizeEvent *);
144   
145   virtual void    mouseMoveEvent(QMouseEvent *);
146   virtual void    mouseReleaseEvent(QMouseEvent *);
147   virtual void    mousePressEvent(QMouseEvent *);
148   virtual void    mouseDoubleClickEvent(QMouseEvent *); 
149
150   virtual void    keyPressEvent(QKeyEvent *);
151   virtual void    keyReleaseEvent(QKeyEvent *);
152
153   virtual void    focusInEvent(QFocusEvent *event);
154   virtual void    focusOutEvent(QFocusEvent *event);
155
156 signals:
157   void            vpTransformationStarted (OCCViewer_ViewPort::OperationType type);
158   void            vpTransformationFinished (OCCViewer_ViewPort::OperationType type);
159   
160   void            vpMousePress (QMouseEvent*);
161   void            vpMouseRelease (QMouseEvent*);
162   void            vpMouseMove (QMouseEvent*);
163   void            vpMouseDoubleClick (QMouseEvent*);
164   
165   void            vpKeyPress (QKeyEvent*);
166   void            vpKeyRelease (QKeyEvent*);
167   
168   void            vpFocusOut (QFocusEvent*);
169   void            vpFocusIn (QFocusEvent*);
170   
171   void            vpPaint (QPaintEvent*);
172   void            vpDrawExternal (QPainter* painter);
173
174 protected slots:
175  virtual void   onChangeBackgroundColor() = 0;
176
177 protected:    
178  virtual bool   setWindow() = 0;
179  virtual void   windowResize() = 0;     
180  virtual void   pan(int dx, int dy) = 0;        
181  virtual void   setCenter(int x, int y) = 0;
182  virtual void   fitWindow( const QRect& rect) = 0;
183  virtual void   zoom(int x0, int y0, int x, int y) = 0; 
184  virtual void   startRotation(int x0, int y0) = 0;
185  virtual void   rotate(int x, int y) = 0;
186  virtual void   endRotation() = 0;
187         
188 protected:
189  OCCViewer_ViewPort*    myOriginalViewport;
190  OperationType          myOperation;
191  QCursor                myCursor;
192  
193  QRect                  myMagnifyRect;
194  QRect                  myRect;                         
195  bool                   myDrawRect;  /* set when a rect is used for selection or magnify */
196         
197  /* Mouse coordinates */
198  int                    myStartX;       
199  int                    myStartY;
200  int                    myCurrX;
201  int                    myCurrY;
202
203  bool                   myHasWindow;
204  bool                   myCursorIsHand;                 
205  bool                   myEnableDrawMode;
206  bool                   myEventStarted;       /* set when transformation is in process */
207  bool                   myPaintersRedrawing;  /* set to draw with external painters */
208 };
209
210 #endif
211