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