Salome HOME
Implement generic "Dump view" method to be used by all views (toolbar & context menu)
[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.02
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_ViewFrame.h"
24 #include "GLViewer_Drawer.h"
25
26 #include <TColStd_SequenceOfInteger.hxx>
27
28 #include <GL/gl.h>
29
30 class GLViewer_Object;
31 class GLViewer_Rect;
32 class GLViewer_Context;
33 class GLViewer_Selector2d;
34 //class GLViewer_Sketcher;
35
36 class SUIT_Desktop;
37 class SUIT_ViewWindow;
38
39 const double Sizes[2*5] = { 
40     /* A1 */ 594.0, 840.0,
41     /* A2 */ 420.0, 594.0,
42     /* A3 */ 297.0, 420.0,
43     /* A4 */ 210.0, 297.0,
44     /* A5 */ 148.5, 210.0
45 };
46
47 #ifdef WNT
48 #pragma warning( disable:4251 )
49 #endif
50
51 class GLVIEWER_EXPORT GLViewer_Viewer2d : public GLViewer_Viewer
52 {
53     Q_OBJECT
54
55 public:
56     enum GLSketchingType { None, Polyline, Arc, Curve, Scribble, Oval, Rectangle };
57     enum VectorFileType { POST_SCRIPT, HPGL
58 #ifdef WIN32
59         , ENH_METAFILE
60 #endif
61     };
62
63     enum PaperType { A1=0, A2, A3, A4, A5 };
64
65 public:
66     GLViewer_Viewer2d( const QString& title );
67     ~GLViewer_Viewer2d();
68
69 public:
70     SUIT_ViewWindow*     createView( SUIT_Desktop* );
71
72     virtual void         contextMenuPopup( QPopupMenu* );
73
74     //void                activateGLSketching( int );
75
76     GLViewer_Context*    getGLContext() const { return myGLContext; }
77     void                 updateColors( QColor colorH, QColor colorS );
78     void                 updateBorders( const QRect& rect );
79     void                 updateBorders();
80
81     void                 updateAll();
82     void                 updateDrawers( GLboolean update, GLfloat scX = 0.0, GLfloat scY = 0.0 );
83     void                 activateDrawers( TColStd_SequenceOfInteger& list, bool onlyUpdate,
84                                           GLboolean swap = GL_TRUE );
85     void                 activateDrawers( QValueList<GLViewer_Object*>& theObjects, bool onlyUpdate, GLboolean swap = GL_FALSE );
86     void                 activateDrawer( int index, bool onlyUpdate, GLboolean swap = GL_FALSE );
87     void                 activateDrawer( GLViewer_Object*, bool onlyUpdate, GLboolean swap = GL_FALSE );
88     void                 activateAllDrawers( bool onlyUpdate, GLboolean swap = GL_FALSE );
89
90     void                 transPoint( GLfloat& x, GLfloat& y );
91     QRect*               getWinObjectRect( GLViewer_Object* theObject );
92
93     GLViewer_Rect        getGLVRect( const QRect& ) const;
94     QRect                getQRect( const GLViewer_Rect& ) const;
95
96     virtual void         insertHeader( VectorFileType aType, QFile& hFile );
97     virtual void         insertEnding( VectorFileType aType, QFile& hFile );
98     virtual bool         translateTo( VectorFileType aType, QString FileName, PaperType aPType, 
99                                       double mmLeft, double mmRight, double mmTop, double mmBottom );
100     
101     //bool                 isSketchingActive();
102     //int                  getSketchingType();
103
104     //virtual void         startSketching();
105     //virtual void         finishSketching();
106
107     void                 repaintView( GLViewer_ViewFrame* theView = NULL, bool makeCurrent = false );
108
109 public slots:
110     //void                 onSketchDelObject();
111     //void                 onSketchUndoLast();
112     //void                 onSketchFinish();
113     void                 onChangeBgColor();
114     void                 onCreateGLMarkers( int = 1000, int = 5 );
115     void                 onCreateGLPolyline( int = 100, int = 10, int = 100 );
116     void                 onCreateGLText( QString = "Text", int = 1 );
117
118 protected:
119     GLViewer_Selector*        createSelector();
120     GLViewer_ViewTransformer* createTransformer( int );
121
122     void                 transformCoordsToPS( double& x, double& y );
123     void                 transformCoordsToHPGL( double& x, double& y );
124
125     virtual void         startOperations( QMouseEvent* );
126     virtual bool         updateOperations( QMouseEvent* );
127     virtual void         finishOperations( QMouseEvent* );
128     virtual void         startOperations( QWheelEvent* );
129
130 protected slots:
131     void                 onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
132     void                 onDumpView();
133
134 private:
135     bool                 testRotation( QMouseEvent* );
136
137 protected:    
138     GLViewer_Context*    myGLContext;
139     QValueList<GLViewer_Drawer*> myDrawers;
140
141     //GLViewer_Sketcher*   myGLSketcher;
142 };
143
144 /****************************************************************
145 **  Class: GLViewer_View2dTransformer
146 **
147 *****************************************************************/
148 class GLVIEWER_EXPORT GLViewer_View2dTransformer : public GLViewer_ViewTransformer
149 {
150 public:
151     GLViewer_View2dTransformer( GLViewer_Viewer*, int );
152     ~GLViewer_View2dTransformer();
153
154 public:
155     virtual void         exec();
156
157     /*! Sets/returns mouse butto which will be used for rotation ( MB1 by default ) */
158     static int           rotateButton() { return rotateBtn; }
159     static void          setRotateButton( int b ) { rotateBtn = b; }
160
161 protected:
162     void                 onTransform( TransformState );
163
164 protected:
165     static  int          rotateBtn;
166 };
167
168 #ifdef WNT
169 #pragma warning ( default:4251 )
170 #endif
171
172 #endif