1 // SALOME OCCViewer : build OCC Viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : OCCViewer_ViewPort.h
25 // Author : Nicolas REJNERI
29 #ifndef OCCViewer_ViewPort_H
30 #define OCCViewer_ViewPort_H
33 #include "QAD_Popup.h"
42 class QAD_EXPORT OCCViewer_ViewPort: public QWidget,
43 public QAD_PopupClientServer
51 static QCursor* defCursor;
52 static QCursor* handCursor;
53 static QCursor* panCursor;
54 static QCursor* zoomCursor;
55 static QCursor* rotCursor;
56 static QCursor* glPanCursor;
72 static void createCursors();
73 static void destroyCursors();
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);
88 /* Transformation selected but not started yet */
89 bool transformRequested() const { return ( myOperation != NOTHING ); }
90 void setTransformRequested ( OperationType op );
92 /* Transformation is selected and already started */
93 bool transformInProcess() const { return myEventStarted; }
94 void setTransformInProcess( bool bOn ) { myEventStarted = bOn; }
97 OCCViewer_ViewPort( QWidget* parent );
98 ~OCCViewer_ViewPort();
100 /* Draw mode management */
101 void enableDrawMode( bool bEnable );
102 bool enableDrawMode() const;
104 /* Cursors management */
105 void setDefaultCursorOn();
106 void setHandCursorOn();
107 void setPanCursorOn();
108 void setZoomCursorOn();
109 void setRotCursorOn();
110 void setGlPanCursorOn();
113 bool hasWindow() const;
114 void windowChanged();
115 void redrawPainters();
116 void update(int x, int y, int w, int h);
118 void setOriginalView( OCCViewer_ViewPort* view, const QRect& magnify );
119 OCCViewer_ViewPort* getOriginalView() const;
120 const QRect& getMagnifyRect() const;
121 const QRect& getSelectionRect() const;
123 /* View transformations */
124 virtual void activateZoom();
125 virtual void activatePanning();
126 virtual void activateRotation();
127 virtual void activateWindowFit();
128 virtual void activateGlobalPanning();
130 virtual void fitAll( bool withZ = true ) = 0;
131 virtual void reset() = 0;
133 virtual QColor backgroundColor() const;
134 virtual void setBackgroundColor( const QColor& color) = 0;
137 virtual void paintEvent(QPaintEvent *);
138 virtual void resizeEvent(QResizeEvent *);
140 virtual void mouseMoveEvent(QMouseEvent *);
141 virtual void mouseReleaseEvent(QMouseEvent *);
142 virtual void mousePressEvent(QMouseEvent *);
143 virtual void mouseDoubleClickEvent(QMouseEvent *);
145 virtual void keyPressEvent(QKeyEvent *);
146 virtual void keyReleaseEvent(QKeyEvent *);
148 virtual void focusInEvent(QFocusEvent *event);
149 virtual void focusOutEvent(QFocusEvent *event);
152 void vpTransformationStarted (OCCViewer_ViewPort::OperationType type);
153 void vpTransformationFinished (OCCViewer_ViewPort::OperationType type);
155 void vpMousePress (QMouseEvent*);
156 void vpMouseRelease (QMouseEvent*);
157 void vpMouseMove (QMouseEvent*);
158 void vpMouseDoubleClick (QMouseEvent*);
160 void vpKeyPress (QKeyEvent*);
161 void vpKeyRelease (QKeyEvent*);
163 void vpFocusOut (QFocusEvent*);
164 void vpFocusIn (QFocusEvent*);
166 void vpPaint (QPaintEvent*);
167 void vpDrawExternal (QPainter* painter);
170 virtual void onChangeBackgroundColor() = 0;
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;
184 OCCViewer_ViewPort* myOriginalViewport;
185 OperationType myOperation;
190 bool myDrawRect; /* set when a rect is used for selection or magnify */
192 /* Mouse coordinates */
200 bool myEnableDrawMode;
201 bool myEventStarted; /* set when transformation is in process */
202 bool myPaintersRedrawing; /* set to draw with external painters */