1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // Author : OPEN CASCADE
24 // File: GLViewer_Viewer2d.h
25 // Created: November, 2004
27 #ifndef GLVIEWER_VIEWER2D_H
28 #define GLVIEWER_VIEWER2D_H
37 #include "GLViewer_Viewer.h"
39 #include <TColStd_SequenceOfInteger.hxx>
43 class GLViewer_Object;
44 class GLViewer_ViewFrame;
45 class GLViewer_Drawer;
46 class GLViewer_Context;
48 //class GLViewer_Sketcher;
51 class SUIT_ViewWindow;
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,
63 #pragma warning( disable:4251 )
67 \class GLViewer_Viewer2d
71 class GLVIEWER_API GLViewer_Viewer2d : public GLViewer_Viewer
76 //! Type of sketcher operation
87 //! Type of export vector file
97 //! Type of paper for export to vector format
109 GLViewer_Viewer2d( const QString& title );
111 ~GLViewer_Viewer2d();
115 /*Returns GLViewer_ViewFrame*/
116 virtual SUIT_ViewWindow* createView( SUIT_Desktop* );
118 //! Adds item for change background color
119 void addPopupItems( QMenu* );
121 //void activateGLSketching( int );
123 //! Returns all drawers
124 const QList<GLViewer_Drawer*>& getDrawers() const { return myDrawers; }
127 GLViewer_Context* getGLContext() const { return myGLContext; }
128 //! Updates colors for all drawers (does not work)
129 void updateColors( QColor colorH, QColor colorS );
131 //! Updates rect of global scene by adding new rect
132 void updateBorders( GLViewer_Rect* theRect );
133 //! Recomputes global scene rect
134 void updateBorders();
136 //! Redraws all active objects by updating all drawers in all views
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 );
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);
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;
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
167 virtual bool translateTo( VectorFileType aType, QString FileName, PaperType aPType,
168 double mmLeft, double mmRight, double mmTop, double mmBottom );
170 //bool isSketchingActive();
171 //int getSketchingType();
173 //virtual void startSketching();
174 //virtual void finishSketching();
176 //! Repaints view \param theView. If \param theView = NULL repaints all views.
177 void repaintView( GLViewer_ViewFrame* theView = NULL, bool makeCurrent = false );
180 //! Signal needs for optimum recompute of zoom depending objects
181 //! Warning: use recompute without update viewer
182 void wheelZoomChange( bool );
185 //void onSketchDelObject();
186 //void onSketchUndoLast();
187 //void onSketchFinish();
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 );
199 //! Returns new selector
200 GLViewer_Selector* createSelector();
201 //! Returns new Transformer with type \param type
202 GLViewer_ViewTransformer* createTransformer( int type);
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 );
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* );
219 void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
222 //! Rotation transformation
223 bool testRotation( QMouseEvent* );
226 GLViewer_Context* myGLContext;
227 //! Map of active drawers
228 QList<GLViewer_Drawer*> myDrawers;
230 //GLViewer_Sketcher* myGLSketcher;
233 class GLVIEWER_API GLViewer_View2dTransformer : public GLViewer_ViewTransformer
236 GLViewer_View2dTransformer( GLViewer_Viewer*, int );
237 ~GLViewer_View2dTransformer();
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; }
246 void onTransform( TransformState );
248 static int rotateBtn;
252 #pragma warning ( default:4251 )