Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / GLViewer / GLViewer_Viewer2d.h
1 //  Copyright (C) 2007-2008  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.
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 //  Author : OPEN CASCADE
23 // File:      GLViewer_Viewer2d.h
24 // Created:   November, 2004
25 //
26 #ifndef GLVIEWER_VIEWER2D_H
27 #define GLVIEWER_VIEWER2D_H
28
29 #ifdef WIN32
30 #include <windows.h>
31 #endif
32
33 class QRect;
34 class QFile;
35
36 #include "GLViewer_Viewer.h"
37
38 #include <TColStd_SequenceOfInteger.hxx>
39
40 #include <GL/gl.h>
41
42 class GLViewer_Object;
43 class GLViewer_ViewFrame;
44 class GLViewer_Drawer;
45 class GLViewer_Context;
46 class GLViewer_Rect;
47 //class GLViewer_Sketcher;
48
49 class SUIT_Desktop;
50 class SUIT_ViewWindow;
51
52 //! Paper sizes array
53 const double Sizes[2*5] = { 
54     /* A1 */ 594.0, 840.0,
55     /* A2 */ 420.0, 594.0,
56     /* A3 */ 297.0, 420.0,
57     /* A4 */ 210.0, 297.0,
58     /* A5 */ 148.5, 210.0
59 };
60
61 #ifdef WIN32
62 #pragma warning( disable:4251 )
63 #endif
64
65 /*!
66   \class GLViewer_Viewer2d
67   OpenGL Viewer 2D
68 */
69
70 class GLVIEWER_API GLViewer_Viewer2d : public GLViewer_Viewer
71 {
72   Q_OBJECT
73
74 public:
75   //! Type of sketcher operation    
76   enum GLSketchingType
77   {
78     None,
79     Polyline,
80     Arc,
81     Curve,
82     Scribble,
83     Oval,
84     Rectangle
85   };
86   //! Type of export vector file
87   enum VectorFileType
88   {
89     POST_SCRIPT,
90     HPGL
91 #ifdef WIN32
92     , ENH_METAFILE
93 #endif
94   };
95
96   //! Type of paper for export to vector format
97   enum PaperType
98   {
99     A1=0,
100     A2,
101     A3,
102     A4,
103     A5
104   };
105
106 public:
107   //! A constructor
108   GLViewer_Viewer2d( const QString& title );
109   //! A destructor
110   ~GLViewer_Viewer2d();
111
112 public:
113   //! Redefined method
114   /*Returns GLViewer_ViewFrame*/
115   virtual SUIT_ViewWindow*  createView( SUIT_Desktop* );
116   
117   //! Adds item for change background color
118   void                 addPopupItems( QMenu* );
119
120   //void                activateGLSketching( int );
121
122   //! Returns all drawers
123   const QList<GLViewer_Drawer*>& getDrawers() const { return myDrawers; }
124   
125   //! Returns context
126   GLViewer_Context*    getGLContext() const { return myGLContext; }
127   //! Updates colors for all drawers (does not work)
128   void                 updateColors( QColor colorH, QColor colorS );
129   
130   //! Updates rect of global scene by adding new rect
131   void                 updateBorders( GLViewer_Rect* theRect );
132   //! Recomputes global scene rect
133   void                 updateBorders();
134
135   //! Redraws all active objects by updating all drawers in all views
136   void                 updateAll();
137   //! Updates all drawers with new scale factor
138   /* \param onlyUpdate is passed to method activateAllDrawersdrawers*/
139   void                 updateDrawers( GLboolean onlyUpdate, GLfloat scX = 0.0, GLfloat scY = 0.0 );
140   //! Activates drawers for objects from list \param theObjects only
141   void                 activateDrawers( QList<GLViewer_Object*>& theObjects, bool onlyUpdate, GLboolean swap = GL_FALSE );
142   //! Activates drawer for \param theObject
143   void                 activateDrawer( GLViewer_Object* theObject, bool onlyUpdate, GLboolean swap = GL_FALSE );
144   //! Updates all drawers with new scale factor
145   /* \param onlyUpdate is passed to drawers*/
146   void                 activateAllDrawers( bool onlyUpdate, GLboolean swap = GL_FALSE );
147   
148   //! Translates point (x,y) from global CS to curreent viewer CS
149   void                 transPoint( GLfloat& x, GLfloat& y );
150   //! Returns object rect in window CS
151   QRect*               getWinObjectRect( GLViewer_Object* theObject);
152   
153   //! Translates rect in window CS to rect in global CS
154   GLViewer_Rect        getGLVRect( const QRect& ) const;
155   //! Translates rect in global CS to rect in window CS
156   QRect                getQRect( const GLViewer_Rect& ) const;
157   
158   //! Inserts common text lines starting file of \param aType
159   virtual void         insertHeader( VectorFileType aType, QFile& hFile );
160   //! Inserts common text lines ending file of \param aType
161   virtual void         insertEnding( VectorFileType aType, QFile& hFile );
162   //! Translates current view content to vector file
163   /* Translates current view content to vector file with type \param aType, name \param FileName,
164    * output paper size \param aPType, with margins in mm
165   */
166   virtual bool         translateTo( VectorFileType aType, QString FileName, PaperType aPType, 
167                                    double mmLeft, double mmRight, double mmTop, double mmBottom );
168     
169   //bool                 isSketchingActive();
170   //int                  getSketchingType();
171   
172   //virtual void         startSketching();
173   //virtual void         finishSketching();
174
175   //! Repaints view \param theView. If \param theView = NULL repaints all views.
176   void                 repaintView( GLViewer_ViewFrame* theView = NULL, bool makeCurrent = false );
177
178 signals:
179   //! Signal needs for optimum recompute of zoom depending objects
180   //! Warning: use recompute without update viewer
181   void                 wheelZoomChange( bool );
182
183 public slots:
184   //void                 onSketchDelObject();
185   //void                 onSketchUndoLast();
186   //void                 onSketchFinish();
187
188   //! Changes background color
189   void                 onChangeBgColor();
190   //! Creates set of marker number \param number and radius = \param size
191   void                 onCreateGLMarkers( int number = 1000, int size = 5 );
192   //! Creates set of polyline number \param number, number of angles = \param angles and diameter = \param size
193   void                 onCreateGLPolyline( int number = 100, int angles = 10, int size = 100 );
194   //! Creates set of text number \param number and with text = \param text
195   void                 onCreateGLText( QString text = "Text", int number = 1 );
196
197 protected:
198   //! Returns new selector
199   GLViewer_Selector*        createSelector();
200   //! Returns new Transformer with type \param type
201   GLViewer_ViewTransformer* createTransformer( int type);
202   
203   //! Transforms point (x,y) in Viewer CS to Post Script CS
204   void                 transformCoordsToPS( double& x, double& y );
205   //! Transforms point (x,y) in Viewer CS to HPGL CS
206   void                 transformCoordsToHPGL( double& x, double& y );
207   
208   //! Starts any operations on mouse event
209   virtual void         startOperations( QMouseEvent* );
210   //! Updates started operations on mouse event
211   virtual bool         updateOperations( QMouseEvent* );
212   //! Completes started operations on mouse event
213   virtual void         finishOperations( QMouseEvent* );
214   //! Starts any operations on mouse wheel event
215   virtual void         startOperations( QWheelEvent* );
216
217 protected slots:
218   void                 onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
219
220 private:
221   //! Rotation transformation
222   bool                 testRotation( QMouseEvent* );
223 protected:
224   //! Current context 
225   GLViewer_Context*             myGLContext;
226   //! Map of active drawers
227   QList<GLViewer_Drawer*>  myDrawers;
228   
229   //GLViewer_Sketcher*   myGLSketcher;
230 };
231
232 class GLVIEWER_API GLViewer_View2dTransformer : public GLViewer_ViewTransformer
233 {
234 public:
235   GLViewer_View2dTransformer( GLViewer_Viewer*, int );
236   ~GLViewer_View2dTransformer();
237   
238   virtual void         exec();
239   
240   /*! Sets/returns mouse butto which will be used for rotation ( MB1 by default ) */
241   static int           rotateButton() { return rotateBtn; }
242   static void          setRotateButton( int b ) { rotateBtn = b; }
243
244 protected:
245   void                 onTransform( TransformState );
246
247   static  int          rotateBtn;
248 };
249
250 #ifdef WIN32
251 #pragma warning ( default:4251 )
252 #endif
253
254 #endif