]> SALOME platform Git repositories - modules/kernel.git/blob - src/OCCViewer/OCCViewer_ViewPort.h
Salome HOME
DCQ : Merge with Ecole_ete_a6.
[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 QColor  backgroundColor() const;
134   virtual void    setBackgroundColor( const QColor& color) = 0;
135
136 protected: 
137   virtual void    paintEvent(QPaintEvent *);
138   virtual void    resizeEvent(QResizeEvent *);
139   
140   virtual void    mouseMoveEvent(QMouseEvent *);
141   virtual void    mouseReleaseEvent(QMouseEvent *);
142   virtual void    mousePressEvent(QMouseEvent *);
143   virtual void    mouseDoubleClickEvent(QMouseEvent *); 
144
145   virtual void    keyPressEvent(QKeyEvent *);
146   virtual void    keyReleaseEvent(QKeyEvent *);
147
148   virtual void    focusInEvent(QFocusEvent *event);
149   virtual void    focusOutEvent(QFocusEvent *event);
150
151 signals:
152   void            vpTransformationStarted (OCCViewer_ViewPort::OperationType type);
153   void            vpTransformationFinished (OCCViewer_ViewPort::OperationType type);
154   
155   void            vpMousePress (QMouseEvent*);
156   void            vpMouseRelease (QMouseEvent*);
157   void            vpMouseMove (QMouseEvent*);
158   void            vpMouseDoubleClick (QMouseEvent*);
159   
160   void            vpKeyPress (QKeyEvent*);
161   void            vpKeyRelease (QKeyEvent*);
162   
163   void            vpFocusOut (QFocusEvent*);
164   void            vpFocusIn (QFocusEvent*);
165   
166   void            vpPaint (QPaintEvent*);
167   void            vpDrawExternal (QPainter* painter);
168
169 protected slots:
170  virtual void   onChangeBackgroundColor() = 0;
171
172 protected:    
173  virtual bool   setWindow() = 0;
174  virtual void   windowResize() = 0;     
175  virtual void   pan(int dx, int dy) = 0;        
176  virtual void   setCenter(int x, int y) = 0;
177  virtual void   fitWindow( const QRect& rect) = 0;
178  virtual void   zoom(int x0, int y0, int x, int y) = 0; 
179  virtual void   startRotation(int x0, int y0) = 0;
180  virtual void   rotate(int x, int y) = 0;
181  virtual void   endRotation() = 0;
182         
183 protected:
184  OCCViewer_ViewPort*    myOriginalViewport;
185  OperationType          myOperation;
186  QCursor                myCursor;
187  
188  QRect                  myMagnifyRect;
189  QRect                  myRect;                         
190  bool                   myDrawRect;  /* set when a rect is used for selection or magnify */
191         
192  /* Mouse coordinates */
193  int                    myStartX;       
194  int                    myStartY;
195  int                    myCurrX;
196  int                    myCurrY;
197
198  bool                   myHasWindow;
199  bool                   myCursorIsHand;                 
200  bool                   myEnableDrawMode;
201  bool                   myEventStarted;       /* set when transformation is in process */
202  bool                   myPaintersRedrawing;  /* set to draw with external painters */
203 };
204
205 #endif
206