Back to index

salome-gui  6.5.0
GLViewer_Viewer2d.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  Author : OPEN CASCADE
00024 // File:      GLViewer_Viewer2d.h
00025 // Created:   November, 2004
00026 //
00027 #ifndef GLVIEWER_VIEWER2D_H
00028 #define GLVIEWER_VIEWER2D_H
00029 
00030 #ifdef WIN32
00031 #include <windows.h>
00032 #endif
00033 
00034 class QRect;
00035 class QFile;
00036 
00037 #include "GLViewer_Viewer.h"
00038 
00039 #include <TColStd_SequenceOfInteger.hxx>
00040 
00041 #include <GL/gl.h>
00042 
00043 class GLViewer_Object;
00044 class GLViewer_ViewFrame;
00045 class GLViewer_Drawer;
00046 class GLViewer_Context;
00047 class GLViewer_Rect;
00048 //class GLViewer_Sketcher;
00049 
00050 class SUIT_Desktop;
00051 class SUIT_ViewWindow;
00052 
00054 const double Sizes[2*5] = { 
00055     /* A1 */ 594.0, 840.0,
00056     /* A2 */ 420.0, 594.0,
00057     /* A3 */ 297.0, 420.0,
00058     /* A4 */ 210.0, 297.0,
00059     /* A5 */ 148.5, 210.0
00060 };
00061 
00062 #ifdef WIN32
00063 #pragma warning( disable:4251 )
00064 #endif
00065 
00071 class GLVIEWER_API GLViewer_Viewer2d : public GLViewer_Viewer
00072 {
00073   Q_OBJECT
00074 
00075 public:
00077   enum GLSketchingType
00078   {
00079     None,
00080     Polyline,
00081     Arc,
00082     Curve,
00083     Scribble,
00084     Oval,
00085     Rectangle
00086   };
00088   enum VectorFileType
00089   {
00090     POST_SCRIPT,
00091     HPGL
00092 #ifdef WIN32
00093     , ENH_METAFILE
00094 #endif
00095   };
00096 
00098   enum PaperType
00099   {
00100     A1=0,
00101     A2,
00102     A3,
00103     A4,
00104     A5
00105   };
00106 
00107 public:
00109   GLViewer_Viewer2d( const QString& title );
00111   ~GLViewer_Viewer2d();
00112 
00113 public:
00115   /*Returns GLViewer_ViewFrame*/
00116   virtual SUIT_ViewWindow*  createView( SUIT_Desktop* );
00117   
00119   void                 addPopupItems( QMenu* );
00120 
00121   //void                activateGLSketching( int );
00122 
00124   const QList<GLViewer_Drawer*>& getDrawers() const { return myDrawers; }
00125   
00127   GLViewer_Context*    getGLContext() const { return myGLContext; }
00129   void                 updateColors( QColor colorH, QColor colorS );
00130   
00132   void                 updateBorders( GLViewer_Rect* theRect );
00134   void                 updateBorders();
00135 
00137   void                 updateAll();
00139   /* \param onlyUpdate is passed to method activateAllDrawersdrawers*/
00140   void                 updateDrawers( GLboolean onlyUpdate, GLfloat scX = 0.0, GLfloat scY = 0.0 );
00142   void                 activateDrawers( QList<GLViewer_Object*>& theObjects, bool onlyUpdate, GLboolean swap = GL_FALSE );
00144   void                 activateDrawer( GLViewer_Object* theObject, bool onlyUpdate, GLboolean swap = GL_FALSE );
00146   /* \param onlyUpdate is passed to drawers*/
00147   void                 activateAllDrawers( bool onlyUpdate, GLboolean swap = GL_FALSE );
00148   
00150   void                 transPoint( GLfloat& x, GLfloat& y );
00152   QRect*               getWinObjectRect( GLViewer_Object* theObject);
00153   
00155   GLViewer_Rect        getGLVRect( const QRect& ) const;
00157   QRect                getQRect( const GLViewer_Rect& ) const;
00158   
00160   virtual void         insertHeader( VectorFileType aType, QFile& hFile );
00162   virtual void         insertEnding( VectorFileType aType, QFile& hFile );
00164   /* Translates current view content to vector file with type \param aType, name \param FileName,
00165    * output paper size \param aPType, with margins in mm
00166   */
00167   virtual bool         translateTo( VectorFileType aType, QString FileName, PaperType aPType, 
00168                                    double mmLeft, double mmRight, double mmTop, double mmBottom );
00169     
00170   //bool                 isSketchingActive();
00171   //int                  getSketchingType();
00172   
00173   //virtual void         startSketching();
00174   //virtual void         finishSketching();
00175 
00177   void                 repaintView( GLViewer_ViewFrame* theView = NULL, bool makeCurrent = false );
00178 
00179 signals:
00182   void                 wheelZoomChange( bool );
00183 
00184 public slots:
00185   //void                 onSketchDelObject();
00186   //void                 onSketchUndoLast();
00187   //void                 onSketchFinish();
00188 
00190   void                 onChangeBgColor();
00192   void                 onCreateGLMarkers( int number = 1000, int size = 5 );
00194   void                 onCreateGLPolyline( int number = 100, int angles = 10, int size = 100 );
00196   void                 onCreateGLText( QString text = "Text", int number = 1 );
00197 
00198 protected:
00200   GLViewer_Selector*        createSelector();
00202   GLViewer_ViewTransformer* createTransformer( int type);
00203   
00205   void                 transformCoordsToPS( double& x, double& y );
00207   void                 transformCoordsToHPGL( double& x, double& y );
00208   
00210   virtual void         startOperations( QMouseEvent* );
00212   virtual bool         updateOperations( QMouseEvent* );
00214   virtual void         finishOperations( QMouseEvent* );
00216   virtual void         startOperations( QWheelEvent* );
00217 
00218 protected slots:
00219   void                 onMouseEvent( SUIT_ViewWindow*, QMouseEvent* );
00220 
00221 private:
00223   bool                 testRotation( QMouseEvent* );
00224 protected:
00226   GLViewer_Context*             myGLContext;
00228   QList<GLViewer_Drawer*>  myDrawers;
00229   
00230   //GLViewer_Sketcher*   myGLSketcher;
00231 };
00232 
00233 class GLVIEWER_API GLViewer_View2dTransformer : public GLViewer_ViewTransformer
00234 {
00235 public:
00236   GLViewer_View2dTransformer( GLViewer_Viewer*, int );
00237   ~GLViewer_View2dTransformer();
00238   
00239   virtual void         exec();
00240   
00242   static int           rotateButton() { return rotateBtn; }
00243   static void          setRotateButton( int b ) { rotateBtn = b; }
00244 
00245 protected:
00246   void                 onTransform( TransformState );
00247 
00248   static  int          rotateBtn;
00249 };
00250 
00251 #ifdef WIN32
00252 #pragma warning ( default:4251 )
00253 #endif
00254 
00255 #endif