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