Salome HOME
Copyright update: 2016
[modules/gui.git] / src / GLViewer / GLViewer_ViewPort.h
1 // Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  Author : OPEN CASCADE
24 // File:      GLViewer_ViewPort.h
25 // Created:   November, 2004
26 //
27 #ifndef GLVIEWER_VIEWPORT_H
28 #define GLVIEWER_VIEWPORT_H
29
30 #include "GLViewer.h"
31
32 //#include <QList>
33 #include <QColor>
34 //#include <QAction>
35 #include <QWidget>
36
37 //#include <Aspect_Window.hxx>
38
39 class QRect;
40 class QCursor;
41 class QPainter;
42 class GLViewer_ViewSketcher;
43 class GLViewer_ViewTransformer;
44
45 #ifdef WIN32
46 #pragma warning( disable:4251 )
47 #endif
48
49 enum BlockStatus
50 {
51     BS_NoBlock          = 0x0000,
52     BS_Highlighting     = 0x0001,
53     BS_Selection        = 0x0002,
54     BS_Dragging         = 0x0004
55 };
56
57 /*!
58   \class GLViewer_ViewPort
59   Visualisation canvas of GLViewer
60 */
61 class GLVIEWER_API GLViewer_ViewPort: public QWidget
62 {
63     Q_OBJECT
64     friend class GLViewer_ViewSketcher;
65     friend class GLViewer_ViewTransformer;
66
67 public:
68     GLViewer_ViewPort( QWidget* parent );
69     ~GLViewer_ViewPort();
70
71 public:
72     //! Activates/deactivates sketching
73     void                             setSketchingEnabled( bool );
74     //! Checks active status of sketcher
75     bool                             isSketchingEnabled() const;
76     //! Activates/deactivates transformer
77     void                             setTransformEnabled( bool );
78     //! Checks active status of transformer
79     bool                             isTransformEnabled() const;
80
81     //! Returns background color
82     virtual QColor                   backgroundColor() const;
83     //! Sets background color
84     virtual void                     setBackgroundColor( const QColor& );
85
86     //! Redraw external pa inters
87     void                             redrawPainters();
88
89     //! Updates view
90     virtual void                     onUpdate();
91
92     //! Returns blocking status for current started operations
93     virtual BlockStatus              currentBlock(){ return BS_NoBlock; }
94
95 protected:
96     enum ViewType { Type2D, Type3D };
97     void                             selectVisualId( ViewType );
98
99     virtual QPaintDevice*            getPaintDevice() { return this; }
100     virtual void                     contextMenuEvent( QContextMenuEvent * e );
101
102 //! STATICS
103     static void                      createCursors();
104     static void                      destroyCursors();
105     static QCursor*                  getHandCursor() { return handCursor; }
106     static void                      setHandCursor( const QCursor& newCursor );
107     static QCursor*                  getPanCursor() { return panCursor; }
108     static void                      setPanCursor( const QCursor& newCursor );
109     static QCursor*                  getPanglCursor() { return panglCursor; }
110     static void                      setPanglCursor( const QCursor& newCursor );
111     static QCursor*                  getZoomCursor() { return zoomCursor; }
112     static void                      setZoomCursor( const QCursor& newCursor );
113
114 public://ouv
115     static QCursor*                  getDefaultCursor() { return defCursor; }
116     static void                      setDefaultCursor( const QCursor& newCursor );
117     static QCursor*                  getRotCursor() { return rotCursor; }
118     static void                      setRotCursor( const QCursor& newCursor );
119     static QCursor*                  getSketchCursor() { return sketchCursor; }
120     static void                      setSketchCursor( const QCursor& newCursor );
121
122 protected:
123 //! EVENTS
124     virtual void                     paintEvent( QPaintEvent *);
125     virtual void                     mouseMoveEvent( QMouseEvent *);
126     virtual void                     mouseReleaseEvent( QMouseEvent *);
127     virtual void                     mousePressEvent( QMouseEvent *);
128     virtual void                     mouseDoubleClickEvent( QMouseEvent *);
129     virtual void                     keyPressEvent( QKeyEvent *);
130     virtual void                     keyReleaseEvent( QKeyEvent *);
131     virtual void                     wheelEvent( QWheelEvent *);
132
133 //! TO BE REDEFINED
134     virtual void                     reset() = 0;
135     virtual void                     pan( int, int ) = 0;
136     virtual void                     setCenter( int, int ) = 0;    
137     virtual void                     zoom( int, int, int, int ) = 0;
138     virtual void                     fitRect( const QRect& ) = 0;
139     virtual void                     fitSelect() = 0;
140     virtual void                     fitAll( bool keepScale = false, bool withZ = true ) = 0;
141
142 protected slots:
143     virtual void                     onChangeBgColor();
144
145 signals:
146     void                             vpKeyEvent( QKeyEvent* );
147     void                             vpMouseEvent( QMouseEvent* );
148     void                             vpWheelEvent( QWheelEvent* );
149     void                             vpDrawExternal( QPainter* );
150
151     void                             contextMenuRequested( QContextMenuEvent* );
152
153 private:
154     void                             initialize();
155     void                             cleanup();
156
157 protected:
158     //Handle(Aspect_Window)            myWindow;
159     bool                             myEnableSketching;
160     bool                             myEnableTransform;
161     bool                             myPaintersRedrawing;   /* set to draw externally */
162     //QList<QAction>                   myPopupActions;
163
164 private:
165     static int                       nCounter;              /* objects counter */
166     static QCursor*                  defCursor;
167     static QCursor*                  panglCursor;
168     static QCursor*                  handCursor;
169     static QCursor*                  panCursor;
170     static QCursor*                  zoomCursor;
171     static QCursor*                  rotCursor;
172     static QCursor*                  sketchCursor;
173 };
174
175 #ifdef WIN32
176 #pragma warning ( default:4251 )
177 #endif
178
179 #endif