Salome HOME
Updated copyright comment
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewWindow.h
old mode 100755 (executable)
new mode 100644 (file)
index b6bda96..00a376e
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 // Lesser General Public License for more details.
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 #ifndef OCCVIEWER_VIEWWINDOW_H
 #define OCCVIEWER_VIEWWINDOW_H
 
-#include "OCCViewer_ViewModel.h"
-
+#include "OCCViewer.h"
+#include "Qtx.h"
 #include "SUIT_ViewWindow.h"
+#include <gp_Pnt.hxx>
+#include <V3d_Plane.hxx>
+#include <TopAbs_ShapeEnum.hxx>
 
-#include "QtxAction.h"
-
-#include <qcursor.h>
-#include <qvaluelist.h>
-
+class QtxRectRubberBand;
 class SUIT_Desktop;
 class OCCViewer_ViewPort3d;
+class OCCViewer_ViewSketcher;
+class OCCViewer_AutoRotate;
+class OCCViewer_AxialScaleDlg;
+class OCCViewer_SetRotationPointDlg;
+class OCCViewer_Viewer;
+class OCCViewer_CubeAxesDlg;
+class QtxAction;
+
+struct viewAspect
+{
+public:
+  double    scale;
+  double  centerX; // deprecated since OCCT 6.7.1
+  double  centerY; // deprecated since OCCT 6.7.1
+  double    projX;
+  double    projY;
+  double    projZ;
+  double    twist;
+  double      atX;
+  double      atY;
+  double      atZ;
+  double     eyeX;
+  double     eyeY;
+  double     eyeZ;
+  double   scaleX;
+  double   scaleY;
+  double   scaleZ;
+  QString    name;
+  // trihedron
+  bool     isVisible;
+  double   size;
+  // view cube
+  bool     vcIsVisible;
+  // graduated trihedron
+  bool    gtIsVisible;
+  bool    gtDrawNameX;
+  bool    gtDrawNameY;
+  bool    gtDrawNameZ;
+  QString gtNameX;
+  QString gtNameY;
+  QString gtNameZ;
+  int     gtNameColorRX;
+  int     gtNameColorGX;
+  int     gtNameColorBX;
+  int     gtNameColorRY;
+  int     gtNameColorGY;
+  int     gtNameColorBY;
+  int     gtNameColorRZ;
+  int     gtNameColorGZ;
+  int     gtNameColorBZ;
+  bool    gtDrawValuesX;
+  bool    gtDrawValuesY;
+  bool    gtDrawValuesZ;
+  int     gtNbValuesX;
+  int     gtNbValuesY;
+  int     gtNbValuesZ;
+  int     gtOffsetX;
+  int     gtOffsetY;
+  int     gtOffsetZ;
+  int     gtColorRX;
+  int     gtColorGX;
+  int     gtColorBX;
+  int     gtColorRY;
+  int     gtColorGY;
+  int     gtColorBY;
+  int     gtColorRZ;
+  int     gtColorGZ;
+  int     gtColorBZ;
+  bool    gtDrawTickmarksX;
+  bool    gtDrawTickmarksY;
+  bool    gtDrawTickmarksZ;
+  int     gtTickmarkLengthX;
+  int     gtTickmarkLengthY;
+  int     gtTickmarkLengthZ;
+
+public:
+  viewAspect()
+  : scale( 0.0 ),
+    centerX( 0.0 ), centerY( 0.0 ),
+    projX( 0.0 ), projY( 0.0 ), projZ( 0.0 ),
+    twist( 0.0 ),
+    atX( 0.0 ), atY( 0.0 ), atZ( 0.0 ),
+    eyeX( 0.0 ), eyeY( 0.0 ), eyeZ( 0.0 ),
+    scaleX( 0.0 ), scaleY( 0.0 ), scaleZ( 0.0 ),
+    name(),
+    isVisible( false ),
+    size( 0.0 ),
+    vcIsVisible( false ),
+    gtIsVisible( false ),
+    gtDrawNameX( false ), gtDrawNameY( false ), gtDrawNameZ( false ),
+    gtNameX(), gtNameY(), gtNameZ(), 
+    gtNameColorRX( 0 ), gtNameColorGX( 0 ), gtNameColorBX( 0 ),
+    gtNameColorRY( 0 ), gtNameColorGY( 0 ), gtNameColorBY( 0 ),
+    gtNameColorRZ( 0 ), gtNameColorGZ( 0 ), gtNameColorBZ( 0 ),
+    gtDrawValuesX( false ), gtDrawValuesY( false ), gtDrawValuesZ( false ),
+    gtNbValuesX( 0 ), gtNbValuesY( 0 ), gtNbValuesZ( 0 ),
+    gtOffsetX( 0 ), gtOffsetY( 0 ), gtOffsetZ( 0 ),
+    gtColorRX( 0 ), gtColorGX( 0 ), gtColorBX( 0 ),
+    gtColorRY( 0 ), gtColorGY( 0 ), gtColorBY( 0 ),
+    gtColorRZ( 0 ), gtColorGZ( 0 ), gtColorBZ( 0 ),
+    gtDrawTickmarksX( false ), gtDrawTickmarksY( false ), gtDrawTickmarksZ( false ),
+    gtTickmarkLengthX( 0 ), gtTickmarkLengthY( 0 ), gtTickmarkLengthZ( 0 ) {}
+};
 
-class OCCViewer_ClippingDlg;
+typedef QList<viewAspect> viewAspectList;
 
 #ifdef WIN32
 #pragma warning( disable:4251 )
@@ -42,116 +148,319 @@ class OCCVIEWER_EXPORT OCCViewer_ViewWindow : public SUIT_ViewWindow
   Q_OBJECT
 
 public:
-  enum OperationType{ NOTHING, PANVIEW, ZOOMVIEW, ROTATE, PANGLOBAL, WINDOWFIT, FITALLVIEW, RESETVIEW,
-                      FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW };
+  enum ActionId { DumpId, FitAllId, FitRectId, FitSelectionId, ZoomId, PanId, GlobalPanId,
+                  ChangeRotationPointId, RotationId,
+                  FrontId, BackId, TopId, BottomId, LeftId, RightId, ClockWiseId, AntiClockWiseId,
+                  ResetId, CloneId, ClippingId, MemId, RestoreId,
+                  TrihedronShowId, AxialScaleId, GraduatedAxesId, AmbientId,
+                  SwitchInteractionStyleId, SwitchZoomingStyleId, 
+                  SwitchPreselectionId, SwitchSelectionId,
+                  MaximizedId, SynchronizeId, ReturnTo3dViewId,
+                  OrthographicId, PerspectiveId, StereoId, RayTracingId, EnvTextureId, LightSourceId,
+                  RectangleSelectionStyleId, PolygonSelectionStyleId, CircleSelectionStyleId,
+                  ViewCubeShowId,
+                  UserId };
+
+  enum OperationType{ NOVIEWOP, PANVIEW, ZOOMVIEW, ROTATE, 
+                      PANGLOBAL, WINDOWFIT, FITALLVIEW, FITSELECTION, RESETVIEW,
+                      FRONTVIEW, BACKVIEW, TOPVIEW, BOTTOMVIEW, LEFTVIEW, RIGHTVIEW,
+                     CLOCKWISEVIEW, ANTICLOCKWISEVIEW, PROJECTION };
+
+  enum RotationPointType{ BBCENTER, SELECTED };
+
+  enum SketchingType { NoSketching, Rect, Polygon };
+
+  enum SelectionStyle { RectStyle, PolygonStyle, CyrcleStyle };
+
+  enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane };
+
+  enum ProjectionType { Orthographic, Perspective, Stereo };
+  
+  enum StereoType { QuadBuffer, Anaglyph, RowInterlaced, ColumnInterlaced, ChessBoard, SideBySide, OverUnder, SoftPageFlip, NumberOfModes };
+
+  enum AnaglyphFilter { RedCyan, YellowBlue, GreenMagenta };
+
+  enum FocusIODType { Absolute, Relative };
 
   OCCViewer_ViewWindow(SUIT_Desktop* theDesktop, OCCViewer_Viewer* theModel);
-       virtual ~OCCViewer_ViewWindow() {};
+  virtual ~OCCViewer_ViewWindow();
 
-  OCCViewer_ViewPort3d* getViewPort() { return myViewPort; }
+  virtual OCCViewer_ViewWindow* getView( const int ) const;
 
-  bool eventFilter(QObject* watched, QEvent* e);
+  virtual OCCViewer_ViewPort3d* getViewPort();
 
-  QToolBar* getToolBar() { return myToolBar; }
+  virtual bool eventFilter(QObject* watched, QEvent* e);
 
-  void performRestoring( const viewAspect& );
+  virtual void performRestoring( const viewAspect&, bool = false );
   
   virtual void initLayout();
 
-  void updateEnabledDrawMode();
+  virtual bool enableDrawMode( bool );
+
+  virtual void updateEnabledDrawMode();
+
+  virtual void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
+                               const double dx = 0, const double dy = 0, const double dz = 1);
 
-  void setCuttingPlane( bool on, const double x = 0 , const double y = 0 , const double z = 0,
-                                 const double dx = 0, const double dy = 0, const double dz = 1);
+  virtual void setCuttingPlane( bool on, const gp_Pln thePln );
+
+  virtual bool isCuttingPlane();
 
   virtual QString   getVisualParameters();
   virtual void      setVisualParameters( const QString& parameters );
+
+  virtual void                    initSketchers();
+  virtual OCCViewer_ViewSketcher* getSketcher( const int ) const;
+
+  virtual void                    activateSketching( int );
+
+  virtual int                     interactionStyle() const;
+  virtual void                    setInteractionStyle( const int );
  
-public slots:
-  void onFrontView();
-  void onViewFitAll();
-  void onBackView();
-  void onTopView();
-  void onBottomView();
-  void onLeftView();
-  void onRightView();
-  void onResetView();
-  void onFitAll();
-  void activateZoom();
-  void activateWindowFit();
-  void activateRotation();
-  void activatePanning();
-  void activateGlobalPanning();
-  void onCloneView();
-  void onClipping( bool on );
-  void onMemorizeView();
-  void onRestoreView();
-  void onTrihedronShow();
-  void setRestoreFlag();
+  virtual int                     zoomingStyle() const;
+  virtual void                    setZoomingStyle( const int );
+
+  virtual bool                    isPreselectionEnabled() const;
+  virtual void                    enablePreselection( bool );   
+  virtual bool                    isSelectionEnabled() const;
+  virtual void                    enableSelection( bool );
+  virtual int                     projectionType() const;
+  virtual void                    setProjectionType( int );
+
+  virtual SelectionStyle          selectionStyle() const;
+  virtual void                    setSelectionStyle(SelectionStyle);
+
+  virtual int                     stereoType() const;
+  virtual void                    setStereoType( const int );
+
+  virtual int                     anaglyphFilter() const;
+  virtual void                    setAnaglyphFilter( const int );
+
+  virtual void                    setStereographicFocus( const int, const double );
+  virtual int                     stereographicFocusType() const;
+  virtual double                  stereographicFocusValue() const;
+
+  virtual void                    setInterocularDistance( const int, const double );
+  virtual int                     interocularDistanceType() const;
+  virtual double                  interocularDistanceValue() const;
+
+  virtual bool                    isReverseStereo() const;
+  virtual void                    setReverseStereo( const bool );
+
+  virtual bool                    isVSync() const;
+  virtual void                    setVSync( const bool );
+
+  virtual bool                    isQuadBufferSupport() const;
+  virtual void                    setQuadBufferSupport( const bool );
+
+  virtual bool                    isAutomaticZoom() const;
+  virtual void                    setAutomaticZoom( const bool );
+
+  virtual void                    enableAutoRotation( const bool );
+
+  void setTransformEnabled( const OperationType, const bool );
+  bool transformEnabled( const OperationType ) const;
+
+  void            set2dMode( Mode2dType );
+  Mode2dType      get2dMode() const { return my2dMode; }
+
+  void            setMaximized( bool, bool = true );
+  bool            isMaximized() const;
+  void            setReturnedTo3dView( bool = true );
   
+  void            setSketcherStyle( bool enable );
+  bool            isSketcherStyle() const;
+
+  virtual QColor  backgroundColor() const;                      // obsolete
+  virtual void    setBackgroundColor( const QColor& );          // obsolete
+
+  virtual void    showStaticTrihedron( bool );
+
+  virtual Qtx::BackgroundData  background() const;
+  virtual void                 setBackground( const Qtx::BackgroundData& );
+
+  virtual const   viewAspectList& getViewAspects();
+  virtual void                    appendViewAspect( const viewAspect& );
+  virtual void                    updateViewAspects( const viewAspectList& );
+  virtual void                    clearViewAspects();
+
+  virtual SUIT_CameraProperties   cameraProperties();
+
+  bool isActionVisible( ActionId theId ) const;
+  void setActionVisible( ActionId theId, bool isVisible );
+
+  void resetState();
+
+public slots:
+  virtual void onFrontView();
+  virtual void onViewFitAll();
+  virtual void onBackView();
+  virtual void onClipping(bool on);
+  virtual void onTopView();
+  virtual void onBottomView();
+  virtual void onLeftView();
+  virtual void onRightView();
+  virtual void onClockWiseView();
+  virtual void onAntiClockWiseView();
+  virtual void onProjectionType( QAction* theAction );
+  virtual void onStereoType( bool activate );
+  virtual void onProjectionType();
+  virtual void onResetView();
+  virtual void onFitAll();
+  virtual void onFitSelection();
+  virtual void activateZoom();
+  virtual void activateWindowFit();
+  virtual void activateRotation();
+  virtual void activatePanning();
+  virtual void activateGlobalPanning();
+  virtual void onSetRotationPoint( bool on );
+  virtual void onCloneView();
+  virtual void onAxialScale();
+  virtual void onGraduatedAxes();
+  virtual void onAmbientToogle();
+  virtual void onMemorizeView();
+  virtual void onRestoreView();
+  virtual void onTrihedronShow(bool);
+  virtual void onViewCubeShow(bool);
+  virtual void setRestoreFlag();
+  virtual void onSwitchInteractionStyle( bool on );
+  virtual void onSwitchZoomingStyle( bool on );
+  virtual void onSwitchPreselection( bool on );
+  virtual void onSwitchSelection( bool on );
+  virtual void onSwitchSelectionStyle(QAction* theAction);
+  virtual void onRayTracing();
+  virtual void onEnvTexture();
+  virtual void onLightSource();
+  virtual void onPanning();
+
+  virtual void activateSetRotationGravity();
+  virtual void activateSetRotationSelected( double theX, double theY, double theZ );
+  virtual void activateStartPointSelection( TopAbs_ShapeEnum );
+  virtual void updateGravityCoords();
+   
+  virtual void showEvent( QShowEvent * );
+  virtual void hideEvent( QHideEvent * );
+
+  virtual void onMaximizedView();
+  virtual void returnTo3dView();
+
 signals:
   void vpTransformationStarted(OCCViewer_ViewWindow::OperationType type);
   void vpTransformationFinished(OCCViewer_ViewWindow::OperationType type);
-  void cloneView();
+  void viewCloned( SUIT_ViewWindow* );
 
-protected:
-  enum { DumpId, FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId,
-         FrontId, BackId, TopId, BottomId, LeftId, RightId, ResetId, CloneId, ClippingId, MemId, RestoreId,
-         TrihedronShowId };
+  void Show( QShowEvent * );
+  void Hide( QHideEvent * );
+  void maximized( OCCViewer_ViewWindow*, bool );
+  void returnedTo3d( );
 
-  typedef QMap<int, QtxAction*> ActionsMap;
+protected slots:
+  void synchronize( SUIT_ViewWindow* );
 
-  QImage dumpView();
+public:
+  virtual QImage dumpView();
+  virtual bool   dumpViewToFormat( const QImage&, const QString& fileName, const QString& format );
+
+protected:
+  virtual QString  filter() const;
+
+  bool isOpenGlStereoSupport() const;
 
   /* Transformation selected but not started yet */
-  bool transformRequested() const { return ( myOperation != NOTHING ); }
-  void setTransformRequested ( OperationType op );
+  bool transformRequested() const;
+  bool setTransformRequested ( OperationType );
 
   /* Transformation is selected and already started */
-  bool         transformInProcess() const { return myEventStarted; }
-  void         setTransformInProcess( bool bOn ) { myEventStarted = bOn; }
+  bool          transformInProcess() const;
+  void          setTransformInProcess( bool );
 
   void vpMousePressEvent(QMouseEvent* theEvent);
   void vpMouseReleaseEvent(QMouseEvent* theEvent);
   void vpMouseMoveEvent(QMouseEvent* theEvent);
 
-  void resetState();
   void drawRect();
+  void endDrawRect();
 
   void createActions();
   void createToolBar();
-  virtual OperationType getButtonState(QMouseEvent* theEvent);
+
+  virtual OperationType getButtonState(QMouseEvent* theEvent, int theInteractionStyle);
 
   viewAspect getViewParams() const;
 
+  bool computeGravityCenter( double& theX, double& theY, double& theZ );
+
+  void projAndPanToGravity(V3d_TypeOfOrientation CamOri);
+
+  virtual void                          onSketchingStarted();
+  virtual void                          onSketchingFinished();
+
+  virtual OCCViewer_ViewSketcher*       createSketcher( int );
+
+  void                                  saveCursor();
+
+  OCCViewer_ViewSketcher*               mypSketcher;
+  QList<OCCViewer_ViewSketcher*>        mySketchers;
+
+  int                                   myCurSketch;
+
   OperationType         myOperation;
   OCCViewer_Viewer*     myModel;
   OCCViewer_ViewPort3d* myViewPort;
 
-  int                                  myRestoreFlag;
+  OCCViewer_CubeAxesDlg* myCubeAxesDlg;
+
+  RotationPointType     myCurrPointType;
+  RotationPointType     myPrevPointType;
+  gp_Pnt                mySelectedPoint;
+  bool                  myRotationPointSelection;
+
+  int                   myRestoreFlag;
+
+  int                   myStartX;
+  int                   myStartY;
+  qint64                myStartTime;          
+  int                   myCurrX;
+  int                   myCurrY;
+  qint64                myCurrTime;          
+
+  bool                  myEventStarted;       // set when transformation is in process 
+  bool                  myCursorIsHand;                 
+  bool                  myDrawRect;           // set when a rect is used for selection or magnify 
+  bool                  myEnableDrawMode;
+  bool                  myDrawRectEnabled;
+  bool                  myPaintersRedrawing;  // set to draw with external painters  
+  bool                  IsSketcherStyle;
+  bool                  myIsKeyFree;
+  bool                  myAutomaticZoom;
+  QCursor               myCursor;
+
+  double myCurScale;
 
-  int                                  myStartX;
-  int                                  myStartY;
-  int                                  myCurrX;
-  int                                  myCurrY;
+private:
+  OCCViewer_AxialScaleDlg* myScalingDlg;
 
-  bool                 myEventStarted;       // set when transformation is in process 
-  bool                 myCursorIsHand;                 
-  bool                 myDrawRect;           // set when a rect is used for selection or magnify 
-  bool                 myEnableDrawMode;
-  bool                 myPaintersRedrawing;  // set to draw with external painters 
-  QRect                        myRect;                         
-  QCursor              myCursor;
+  OCCViewer_SetRotationPointDlg* mySetRotationPointDlg;
+  QtxAction* mySetRotationPointAction;
 
-  QToolBar*  myToolBar;
-  ActionsMap myActionsMap;
+  QtxRectRubberBand* myRectBand; //!< selection rectangle rubber band
 
-  double myCurScale;
+  OCCViewer_AutoRotate *myAutoRotate;
 
-private:
-  OCCViewer_ClippingDlg* myClippingDlg;
-  
+  bool mySelectionEnabled;
+  bool myPreselectionEnabled;
+  int myInteractionStyle;
+
+  typedef QMap<OperationType, bool> MapOfTransformStatus;
+  MapOfTransformStatus myStatus;
+
+  Mode2dType my2dMode;
+
+  Handle(V3d_Plane) myReserveClipPlane;
+
+  viewAspectList myViewAspects;
+  bool myPanningByBtn;
 };
 
 #ifdef WIN32