1 // Copyright (C) 2005 OPEN CASCADE
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
19 // Author : OPEN CASCADE
22 // File: GLViewer_Viewer2d.h
23 // Created: November, 2004
25 #ifndef GLVIEWER_VIEWER2D_H
26 #define GLVIEWER_VIEWER2D_H
35 #include "GLViewer_Viewer.h"
36 #include "GLViewer_Object.h"
37 #include "GLViewer_ViewFrame.h"
38 #include "GLViewer_Drawer.h"
40 #include <TColStd_SequenceOfInteger.hxx>
44 class GLViewer_Object;
45 class GLViewer_Context;
46 class GLViewer_Selector2d;
47 //class GLViewer_Sketcher;
50 class SUIT_ViewWindow;
53 const double Sizes[2*5] = {
54 /* A1 */ 594.0, 840.0,
55 /* A2 */ 420.0, 594.0,
56 /* A3 */ 297.0, 420.0,
57 /* A4 */ 210.0, 297.0,
62 #pragma warning( disable:4251 )
66 \class GLViewer_Viewer2d
70 class GLVIEWER_API GLViewer_Viewer2d : public GLViewer_Viewer
75 //! Type of sketcher operation
86 //! Type of export vector file
96 //! Type of paper for export to vector format
108 GLViewer_Viewer2d( const QString& title );
110 ~GLViewer_Viewer2d();
114 /*Returns GLViewer_ViewFrame*/
115 virtual SUIT_ViewWindow* createView( SUIT_Desktop* );
117 //! Adds item for change background color
118 void addPopupItems( QPopupMenu* );
120 //void activateGLSketching( int );
122 //! Returns all drawers
123 const QValueList<GLViewer_Drawer*>& getDrawers() const { return myDrawers; }
126 GLViewer_Context* getGLContext() const { return myGLContext; }
127 //! Updates colors for all drawers (does not work)
128 void updateColors( QColor colorH, QColor colorS );
130 //! Updates rect of global scene by adding new rect
131 void updateBorders( GLViewer_Rect* theRect );
132 //! Recomputes global scene rect
133 void updateBorders();
135 //! Redraws all active objects by updating all drawers in all views
137 //! Updates all drawers with new scale factor
138 /* \param onlyUpdate is passed to method activateAllDrawersdrawers*/
139 void updateDrawers( GLboolean onlyUpdate, GLfloat scX = 0.0, GLfloat scY = 0.0 );
140 //! Activates drawers for objects from list \param theObjects only
141 void activateDrawers( QValueList<GLViewer_Object*>& theObjects, bool onlyUpdate, GLboolean swap = GL_FALSE );
142 //! Activates drawer for \param theObject
143 void activateDrawer( GLViewer_Object* theObject, bool onlyUpdate, GLboolean swap = GL_FALSE );
144 //! Updates all drawers with new scale factor
145 /* \param onlyUpdate is passed to drawers*/
146 void activateAllDrawers( bool onlyUpdate, GLboolean swap = GL_FALSE );
148 //! Translates point (x,y) from global CS to curreent viewer CS
149 void transPoint( GLfloat& x, GLfloat& y );
150 //! Returns object rect in window CS
151 QRect* getWinObjectRect( GLViewer_Object* theObject);
153 //! Translates rect in window CS to rect in global CS
154 GLViewer_Rect getGLVRect( const QRect& ) const;
155 //! Translates rect in global CS to rect in window CS
156 QRect getQRect( const GLViewer_Rect& ) const;
158 //! Inserts common text lines starting file of \param aType
159 virtual void insertHeader( VectorFileType aType, QFile& hFile );
160 //! Inserts common text lines ending file of \param aType
161 virtual void insertEnding( VectorFileType aType, QFile& hFile );
162 //! Translates current view content to vector file
163 /* Translates current view content to vector file with type \param aType, name \param FileName,
164 * output paper size \param aPType, with margins in mm
166 virtual bool translateTo( VectorFileType aType, QString FileName, PaperType aPType,
167 double mmLeft, double mmRight, double mmTop, double mmBottom );
169 //bool isSketchingActive();
170 //int getSketchingType();
172 //virtual void startSketching();
173 //virtual void finishSketching();
175 //! Repaints view \param theView. If \param theView = NULL repaints all views.
176 void repaintView( GLViewer_ViewFrame* theView = NULL, bool makeCurrent = false );
179 //! Signal needs for optimum recompute of zoom depending objects
180 //! Warning: use recompute without update viewer
181 void wheelZoomChange( bool );
184 //void onSketchDelObject();
185 //void onSketchUndoLast();
186 //void onSketchFinish();
188 //! Changes background color
189 void onChangeBgColor();
190 //! Creates set of marker number \param number and radius = \param size
191 void onCreateGLMarkers( int number = 1000, int size = 5 );
192 //! Creates set of polyline number \param number, number of angles = \param angles and diameter = \param size
193 void onCreateGLPolyline( int number = 100, int angles = 10, int size = 100 );
194 //! Creates set of text number \param number and with text = \param text
195 void onCreateGLText( QString text = "Text", int number = 1 );
198 //! Returns new selector
199 GLViewer_Selector* createSelector();
200 //! Returns new Transformer with type \param type
201 GLViewer_ViewTransformer* createTransformer( int type);
203 //! Transforms point (x,y) in Viewer CS to Post Script CS
204 void transformCoordsToPS( double& x, double& y );
205 //! Transforms point (x,y) in Viewer CS to HPGL CS
206 void transformCoordsToHPGL( double& x, double& y );
208 //! Starts any operations on mouse event
209 virtual void startOperations( QMouseEvent* );
210 //! Updates started operations on mouse event
211 virtual bool updateOperations( QMouseEvent* );
212 //! Completes started operations on mouse event
213 virtual void finishOperations( QMouseEvent* );
214 //! Starts any operations on mouse wheel event
215 virtual void startOperations( QWheelEvent* );
218 void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
221 //! Rotation transformation
222 bool testRotation( QMouseEvent* );
225 GLViewer_Context* myGLContext;
226 //! Map of active drawers
227 QValueList<GLViewer_Drawer*> myDrawers;
229 //GLViewer_Sketcher* myGLSketcher;
232 class GLVIEWER_API GLViewer_View2dTransformer : public GLViewer_ViewTransformer
235 GLViewer_View2dTransformer( GLViewer_Viewer*, int );
236 ~GLViewer_View2dTransformer();
240 /*! Sets/returns mouse butto which will be used for rotation ( MB1 by default ) */
241 static int rotateButton() { return rotateBtn; }
242 static void setRotateButton( int b ) { rotateBtn = b; }
245 void onTransform( TransformState );
247 static int rotateBtn;
251 #pragma warning ( default:4251 )