Salome HOME
dba5570028fa4212ee0111b72b0284d9dcc22180
[modules/gui.git] / src / GLViewer / GLViewer_Viewer2d.h
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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 #ifdef __APPLE__
42 #include <OpenGL/gl.h>
43 #else
44 #include <GL/gl.h>
45 #endif
46
47 class GLViewer_Object;
48 class GLViewer_ViewFrame;
49 class GLViewer_Drawer;
50 class GLViewer_Context;
51 class GLViewer_Rect;
52 //class GLViewer_Sketcher;
53
54 class SUIT_Desktop;
55 class SUIT_ViewWindow;
56
57 //! Paper sizes array
58 const double Sizes[2*5] = { 
59     /* A1 */ 594.0, 840.0,
60     /* A2 */ 420.0, 594.0,
61     /* A3 */ 297.0, 420.0,
62     /* A4 */ 210.0, 297.0,
63     /* A5 */ 148.5, 210.0
64 };
65
66 #ifdef WIN32
67 #pragma warning( disable:4251 )
68 #endif
69
70 /*!
71   \class GLViewer_Viewer2d
72   OpenGL Viewer 2D
73 */
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( QMenu* );
124
125   //void                activateGLSketching( int );
126
127   //! Returns all drawers
128   const QList<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( QList<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   QList<GLViewer_Drawer*>  myDrawers;
233   
234   //GLViewer_Sketcher*   myGLSketcher;
235 };
236
237 class GLVIEWER_API GLViewer_View2dTransformer : public GLViewer_ViewTransformer
238 {
239 public:
240   GLViewer_View2dTransformer( GLViewer_Viewer*, int );
241   ~GLViewer_View2dTransformer();
242   
243   virtual void         exec();
244   
245   /*! Sets/returns mouse butto which will be used for rotation ( MB1 by default ) */
246   static int           rotateButton() { return rotateBtn; }
247   static void          setRotateButton( int b ) { rotateBtn = b; }
248
249 protected:
250   void                 onTransform( TransformState );
251
252   static  int          rotateBtn;
253 };
254
255 #ifdef WIN32
256 #pragma warning ( default:4251 )
257 #endif
258
259 #endif