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