1 // Copyright (C) 2007-2019 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, or (at your option) any later version.
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>
42 #include <OpenGL/gl.h>
47 class GLViewer_Object;
48 class GLViewer_ViewFrame;
49 class GLViewer_Drawer;
50 class GLViewer_Context;
52 //class GLViewer_Sketcher;
55 class SUIT_ViewWindow;
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,
67 #pragma warning( disable:4251 )
71 \class GLViewer_Viewer2d
75 class GLVIEWER_API GLViewer_Viewer2d : public GLViewer_Viewer
80 //! Type of sketcher operation
91 //! Type of export vector file
101 //! Type of paper for export to vector format
113 GLViewer_Viewer2d( const QString& title );
115 ~GLViewer_Viewer2d();
119 /*Returns GLViewer_ViewFrame*/
120 virtual SUIT_ViewWindow* createView( SUIT_Desktop* );
122 //! Adds item for change background color
123 void addPopupItems( QMenu* );
125 //void activateGLSketching( int );
127 //! Returns all drawers
128 const QList<GLViewer_Drawer*>& getDrawers() const { return myDrawers; }
131 GLViewer_Context* getGLContext() const { return myGLContext; }
132 //! Updates colors for all drawers (does not work)
133 void updateColors( QColor colorH, QColor colorS );
135 //! Updates rect of global scene by adding new rect
136 void updateBorders( GLViewer_Rect* theRect );
137 //! Recomputes global scene rect
138 void updateBorders();
140 //! Redraws all active objects by updating all drawers in all views
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 );
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);
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;
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
171 virtual bool translateTo( VectorFileType aType, QString FileName, PaperType aPType,
172 double mmLeft, double mmRight, double mmTop, double mmBottom );
174 //bool isSketchingActive();
175 //int getSketchingType();
177 //virtual void startSketching();
178 //virtual void finishSketching();
180 //! Repaints view \param theView. If \param theView = NULL repaints all views.
181 void repaintView( GLViewer_ViewFrame* theView = NULL, bool makeCurrent = false );
184 //! Signal needs for optimum recompute of zoom depending objects
185 //! Warning: use recompute without update viewer
186 void wheelZoomChange( bool );
189 //void onSketchDelObject();
190 //void onSketchUndoLast();
191 //void onSketchFinish();
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 );
203 //! Returns new selector
204 GLViewer_Selector* createSelector();
205 //! Returns new Transformer with type \param type
206 GLViewer_ViewTransformer* createTransformer( int type);
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 );
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* );
223 void onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
226 //! Rotation transformation
227 bool testRotation( QMouseEvent* );
230 GLViewer_Context* myGLContext;
231 //! Map of active drawers
232 QList<GLViewer_Drawer*> myDrawers;
234 //GLViewer_Sketcher* myGLSketcher;
237 class GLVIEWER_API GLViewer_View2dTransformer : public GLViewer_ViewTransformer
240 GLViewer_View2dTransformer( GLViewer_Viewer*, int );
241 ~GLViewer_View2dTransformer();
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; }
250 void onTransform( TransformState );
252 static int rotateBtn;
256 #pragma warning ( default:4251 )