Back to index

salome-gui  6.5.0
OCCViewer_ViewWindow.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 #ifndef OCCVIEWER_VIEWWINDOW_H
00024 #define OCCVIEWER_VIEWWINDOW_H
00025 
00026 #include "OCCViewer.h"
00027 #include "Qtx.h"
00028 #include "SUIT_ViewWindow.h"
00029 #include <gp_Pnt.hxx>
00030 #include <V3d_Plane.hxx>
00031 
00032 class QtxRectRubberBand;
00033 class SUIT_Desktop;
00034 class OCCViewer_ViewPort3d;
00035 class OCCViewer_ViewSketcher;
00036 class OCCViewer_ClippingDlg;
00037 class OCCViewer_AxialScaleDlg;
00038 class OCCViewer_SetRotationPointDlg;
00039 class OCCViewer_Viewer;
00040 class OCCViewer_CubeAxesDlg;
00041 class QtxAction;
00042 
00043 struct viewAspect
00044 {
00045 public:
00046         double    scale;
00047         double  centerX;
00048         double  centerY;
00049         double    projX;
00050         double    projY;
00051         double    projZ;
00052         double    twist;
00053         double      atX;
00054         double      atY;
00055         double      atZ;
00056         double     eyeX;
00057         double     eyeY;
00058         double     eyeZ;
00059         double   scaleX;
00060         double   scaleY;
00061         double   scaleZ;
00062         QString    name;
00063         bool     isVisible;
00064         double   size;
00065         // graduated trihedron
00066         bool    gtIsVisible;
00067         bool    gtDrawNameX;
00068         bool    gtDrawNameY;
00069         bool    gtDrawNameZ;
00070         QString gtNameX;
00071         QString gtNameY;
00072         QString gtNameZ;
00073         int     gtNameColorRX;
00074         int     gtNameColorGX;
00075         int     gtNameColorBX;
00076         int     gtNameColorRY;
00077         int     gtNameColorGY;
00078         int     gtNameColorBY;
00079         int     gtNameColorRZ;
00080         int     gtNameColorGZ;
00081         int     gtNameColorBZ;
00082         bool    gtDrawValuesX;
00083         bool    gtDrawValuesY;
00084         bool    gtDrawValuesZ;
00085         int     gtNbValuesX;
00086         int     gtNbValuesY;
00087         int     gtNbValuesZ;
00088         int     gtOffsetX;
00089         int     gtOffsetY;
00090         int     gtOffsetZ;
00091         int     gtColorRX;
00092         int     gtColorGX;
00093         int     gtColorBX;
00094         int     gtColorRY;
00095         int     gtColorGY;
00096         int     gtColorBY;
00097         int     gtColorRZ;
00098         int     gtColorGZ;
00099         int     gtColorBZ;
00100         bool    gtDrawTickmarksX;
00101         bool    gtDrawTickmarksY;
00102         bool    gtDrawTickmarksZ;
00103         int     gtTickmarkLengthX;
00104         int     gtTickmarkLengthY;
00105         int     gtTickmarkLengthZ;
00106 };
00107 
00108 typedef QList<viewAspect> viewAspectList;
00109 
00110 #ifdef WIN32
00111 #pragma warning( disable:4251 )
00112 #endif
00113 
00114 class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow  
00115 {
00116   Q_OBJECT
00117 
00118 public:
00119   enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId,
00120          ChangeRotationPointId, RotationId,
00121          FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId,
00122         ResetId, CloneId, ClippingId, MemId, RestoreId,
00123          TrihedronShowId, AxialScaleId, GraduatedAxesId, AmbientId,
00124         SwitchInteractionStyleId, SwitchZoomingStyleId, MaximizedId, SynchronizeId, UserId };
00125 
00126   enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, 
00127                       PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW,
00128                       FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW,
00129                     CLOCKWISEVIEW, ANTICLOCKWISEVIEW };
00130 
00131   enum RotationPointType{ GRAVITY, SELECTED };
00132 
00133   enum SketchingType { NoSketching, Rect, Polygon };
00134 
00135   enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane};
00136 
00137 
00138   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
00139   virtual ~OCCViewer_ViewWindow();
00140 
00141   virtual OCCViewer_ViewWindow* getView( const int ) const;
00142 
00143   virtual OCCViewer_ViewPort3d* getViewPort();
00144 
00145   virtual bool eventFilter(QObject* watched, QEvent* e);
00146 
00147   virtual void performRestoring( const viewAspect&, bool = false );
00148   
00149   virtual void initLayout();
00150 
00151   virtual void updateEnabledDrawMode();
00152 
00153   virtual void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
00154                             const double dx = 0, const double dy = 0, const double dz = 1);
00155 
00156   virtual void setCuttingPlane( bool on, const gp_Pln thePln );
00157 
00158   virtual bool isCuttingPlane();
00159 
00160   virtual QString   getVisualParameters();
00161   virtual void      setVisualParameters( const QString& parameters );
00162 
00163   virtual void                    initSketchers();
00164   virtual OCCViewer_ViewSketcher* getSketcher( const int );
00165 
00166   virtual void                    activateSketching( int );
00167 
00168   virtual int                     interactionStyle() const;
00169   virtual void                    setInteractionStyle( const int );
00170  
00171   virtual int                     zoomingStyle() const;
00172   virtual void                    setZoomingStyle( const int );
00173  
00174   void setTransformEnabled( const OperationType, const bool );
00175   bool transformEnabled( const OperationType ) const;
00176 
00177 
00178   void            set2dMode( Mode2dType );
00179   Mode2dType      get2dMode() const { return my2dMode; }
00180 
00181   void            setMaximized( bool, bool = true );
00182   bool            isMaximized() const;
00183   
00184   void            setSketcherStyle( bool enable );
00185   bool            isSketcherStyle() const;
00186 
00187   virtual QColor  backgroundColor() const;                      // obsolete
00188   virtual void    setBackgroundColor( const QColor& );          // obsolete
00189 
00190   virtual Qtx::BackgroundData  background() const;
00191   virtual void                 setBackground( const Qtx::BackgroundData& );
00192 
00193   virtual const   viewAspectList& getViewAspects();
00194   virtual void                    appendViewAspect( const viewAspect& );
00195   virtual void                    updateViewAspects( const viewAspectList& );
00196   virtual void                    clearViewAspects();
00197 
00198 public slots:
00199   virtual void onFrontView();
00200   virtual void onViewFitAll();
00201   virtual void onBackView();
00202   virtual void onTopView();
00203   virtual void onBottomView();
00204   virtual void onLeftView();
00205   virtual void onRightView();
00206   virtual void onClockWiseView();
00207   virtual void onAntiClockWiseView();
00208   virtual void onResetView();
00209   virtual void onFitAll();
00210   virtual void activateZoom();
00211   virtual void activateWindowFit();
00212   virtual void activateRotation();
00213   virtual void activatePanning();
00214   virtual void activateGlobalPanning();
00215   virtual void onSetRotationPoint( bool on );
00216   virtual void onCloneView();
00217   virtual void onClipping( bool on );
00218   virtual void onAxialScale();
00219   virtual void onGraduatedAxes();
00220   virtual void onAmbientToogle();
00221   virtual void onMemorizeView();
00222   virtual void onRestoreView();
00223   virtual void onTrihedronShow();
00224   virtual void setRestoreFlag();
00225   virtual void onSwitchInteractionStyle( bool on );
00226   virtual void onSwitchZoomingStyle( bool on );
00227 
00228   virtual void activateSetRotationGravity();
00229   virtual void activateSetRotationSelected( double theX, double theY, double theZ );
00230   virtual void activateStartPointSelection();
00231   virtual void updateGravityCoords();
00232    
00233   virtual void showEvent( QShowEvent * );
00234   virtual void hideEvent( QHideEvent * );
00235 
00236   virtual void onMaximizedView();
00237 
00238 signals:
00239   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
00240   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
00241   void viewCloned( SUIT_ViewWindow* );
00242 
00243   void Show( QShowEvent * );
00244   void Hide( QHideEvent * );
00245   void maximized( OCCViewer_ViewWindow*, bool );
00246 
00247 public:
00248   virtual QImage dumpView();
00249   virtual bool   dumpViewToFormat( const QImage&, const QString& fileName, const QString& format );
00250 
00251 protected:
00252   virtual QString  filter() const;
00253 
00254   /* Transformation selected but not started yet */
00255   bool transformRequested() const;
00256   bool setTransformRequested ( OperationType );
00257 
00258   /* Transformation is selected and already started */
00259   bool          transformInProcess() const;
00260   void          setTransformInProcess( bool );
00261 
00262   void vpMousePressEvent(QMouseEvent* theEvent);
00263   void vpMouseReleaseEvent(QMouseEvent* theEvent);
00264   void vpMouseMoveEvent(QMouseEvent* theEvent);
00265 
00266   void resetState();
00267   void drawRect();
00268   void endDrawRect();
00269 
00270   void createActions();
00271   void createToolBar();
00272  
00273   virtual OperationType getButtonState(QMouseEvent* theEvent, int theInteractionStyle);
00274 
00275   viewAspect getViewParams() const;
00276 
00277   bool computeGravityCenter( double& theX, double& theY, double& theZ );
00278 
00279   virtual void                          onSketchingStarted();
00280   virtual void                          onSketchingFinished();
00281 
00282   virtual OCCViewer_ViewSketcher*       createSketcher( int );
00283 
00284   OCCViewer_ViewSketcher*               mypSketcher;
00285   QList<OCCViewer_ViewSketcher*>        mySketchers;
00286 
00287   int                                   myCurSketch;
00288 
00289   OperationType         myOperation;
00290   OCCViewer_Viewer*     myModel;
00291   OCCViewer_ViewPort3d* myViewPort;
00292 
00293   OCCViewer_CubeAxesDlg* myCubeAxesDlg;
00294 
00295   RotationPointType     myCurrPointType;
00296   RotationPointType     myPrevPointType;
00297   gp_Pnt                mySelectedPoint;
00298   bool                  myRotationPointSelection;
00299 
00300   int                                   myRestoreFlag;
00301 
00302   int                                   myStartX;
00303   int                                   myStartY;
00304   int                                   myCurrX;
00305   int                                   myCurrY;
00306 
00307   bool                  myEventStarted;       // set when transformation is in process 
00308   bool                  myCursorIsHand;                 
00309   bool                  myDrawRect;           // set when a rect is used for selection or magnify 
00310   bool                  myEnableDrawMode;
00311   bool                  myPaintersRedrawing;  // set to draw with external painters  
00312   bool                  IsSketcherStyle;
00313   
00314   QCursor               myCursor;
00315 
00316   double myCurScale;
00317 
00318 private slots:
00319   void                  onSynchronizeView(bool);
00320   void                  updateSyncViews();
00321 
00322 private:
00323   static void           synchronizeView( OCCViewer_ViewWindow*, int );
00324 
00325 private:
00326   OCCViewer_ClippingDlg* myClippingDlg;
00327   QtxAction* myClippingAction;
00328 
00329   OCCViewer_AxialScaleDlg* myScalingDlg;
00330 
00331   OCCViewer_SetRotationPointDlg* mySetRotationPointDlg;
00332   QtxAction* mySetRotationPointAction;
00333 
00334   QtxRectRubberBand* myRectBand; 
00335 
00336   int myInteractionStyle;
00337 
00338   typedef QMap<OperationType, bool> MapOfTransformStatus;
00339   MapOfTransformStatus myStatus;
00340 
00341   Mode2dType my2dMode;
00342 
00343   Handle(V3d_Plane) myReserveClippingPlane;
00344 
00345   viewAspectList myViewAspects;
00346 };
00347 
00348 #ifdef WIN32
00349 #pragma warning( default:4251 )
00350 #endif
00351 
00352 #endif