1 // File: GLViewer_Viewer2d.h
2 // Created: November, 2004
4 // Copyright (C) CEA 2004
6 /***************************************************************************
7 ** Class: GLViewer_Viewer2d
8 ** Descr: OpenGL Viewer 2D
10 ** Created: UI team, 04.09.04
11 ****************************************************************************/
12 #ifndef GLVIEWER_VIEWER2D_H
13 #define GLVIEWER_VIEWER2D_H
22 #include "GLViewer_Viewer.h"
23 #include "GLViewer_Object.h"
24 #include "GLViewer_ViewFrame.h"
25 #include "GLViewer_Drawer.h"
27 #include <TColStd_SequenceOfInteger.hxx>
31 class GLViewer_Object;
32 class GLViewer_Context;
33 class GLViewer_Selector2d;
34 //class GLViewer_Sketcher;
37 class SUIT_ViewWindow;
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,
49 #pragma warning( disable:4251 )
53 * Class GLViewer_Object
54 * 2D viewer for GLViewer
56 class GLVIEWER_API GLViewer_Viewer2d : public GLViewer_Viewer
61 //! Type of sketcher operation
72 //! Type of export vector file
82 //! Type of paper for export to vector format
94 GLViewer_Viewer2d( const QString& title );
100 /*Returns GLViewer_ViewFrame*/
101 virtual SUIT_ViewWindow* createView( SUIT_Desktop* );
103 //! Adds item for change background color
104 void addPopupItems( QPopupMenu* );
106 //void activateGLSketching( int );
108 //! Returns all drawers
109 const QValueList<GLViewer_Drawer*>& getDrawers() const { return myDrawers; }
112 GLViewer_Context* getGLContext() const { return myGLContext; }
113 //! Updates colors for all drawers (does not work)
114 void updateColors( QColor colorH, QColor colorS );
116 //! Updates rect of global scene by adding new rect
117 void updateBorders( GLViewer_Rect* theRect );
118 //! Recomputes global scene rect
119 void updateBorders();
121 //! Redraws all active objects by updating all drawers in all views
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 );
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);
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;
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
152 virtual bool translateTo( VectorFileType aType, QString FileName, PaperType aPType,
153 double mmLeft, double mmRight, double mmTop, double mmBottom );
155 //bool isSketchingActive();
156 //int getSketchingType();
158 //virtual void startSketching();
159 //virtual void finishSketching();
161 //! Repaints view \param theView. If \param theView = NULL repaints all views.
162 void repaintView( GLViewer_ViewFrame* theView = NULL, bool makeCurrent = false );
165 //void onSketchDelObject();
166 //void onSketchUndoLast();
167 //void onSketchFinish();
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 );
179 //! Returns new selector
180 GLViewer_Selector* createSelector();
181 //! Returns new Transformer with type \param type
182 GLViewer_ViewTransformer* createTransformer( int type);
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 );
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* );
199 void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
202 //! Rotation transformation
203 bool testRotation( QMouseEvent* );
206 GLViewer_Context* myGLContext;
207 //! Map of active drawers
208 QValueList<GLViewer_Drawer*> myDrawers;
210 //GLViewer_Sketcher* myGLSketcher;
213 /****************************************************************
214 ** Class: GLViewer_View2dTransformer
216 *****************************************************************/
217 class GLVIEWER_API GLViewer_View2dTransformer : public GLViewer_ViewTransformer
220 GLViewer_View2dTransformer( GLViewer_Viewer*, int );
221 ~GLViewer_View2dTransformer();
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; }
230 void onTransform( TransformState );
232 static int rotateBtn;
236 #pragma warning ( default:4251 )