0031518: Samples - update QtWidget samples to use AIS_ViewController
[occt.git] / samples / qt / Common / src / View.h
1 #ifndef VIEW_H
2 #define VIEW_H
3
4 #include <Standard_WarningsDisable.hxx>
5 #include <QWidget>
6 #include <QAction>
7 #include <QList>
8 #include <Standard_WarningsRestore.hxx>
9
10 #include <AIS_InteractiveContext.hxx>
11 #include <AIS_ViewController.hxx>
12 #include <V3d_View.hxx>
13
14 class TopoDS_Shape;
15 class QRubberBand;
16
17 //class COMMONSAMPLE_EXPORT View: public QWidget
18 class View: public QWidget, protected AIS_ViewController
19 {
20     Q_OBJECT
21 protected:
22     enum CurrentAction3d { CurAction3d_Nothing, CurAction3d_DynamicZooming,
23                            CurAction3d_WindowZooming, CurAction3d_DynamicPanning,
24                            CurAction3d_GlobalPanning, CurAction3d_DynamicRotation };
25
26 public:
27     enum ViewAction { ViewFitAllId, ViewFitAreaId, ViewZoomId, ViewPanId, ViewGlobalPanId,
28                       ViewFrontId, ViewBackId, ViewTopId, ViewBottomId, ViewLeftId, ViewRightId,
29                       ViewAxoId, ViewRotationId, ViewResetId, ViewHlrOffId, ViewHlrOnId };
30     enum RaytraceAction { ToolRaytracingId, ToolShadowsId, ToolReflectionsId, ToolAntialiasingId };
31
32     View( Handle(AIS_InteractiveContext) theContext, QWidget* parent );
33
34     ~View();
35
36     virtual void                  init();
37     bool                          dump( Standard_CString theFile );
38     QList<QAction*>*              getViewActions();
39     QList<QAction*>*              getRaytraceActions();
40     void                          noActiveActions();
41     bool                          isShadingMode();
42
43     void                          EnableRaytracing();
44     void                          DisableRaytracing();
45
46     void                          SetRaytracedShadows (bool theState);
47     void                          SetRaytracedReflections (bool theState);
48     void                          SetRaytracedAntialiasing (bool theState);
49
50     bool                          IsRaytracingMode() const { return myIsRaytracing; }
51     bool                          IsShadowsEnabled() const { return myIsShadowsEnabled; }
52     bool                          IsReflectionsEnabled() const { return myIsReflectionsEnabled; }
53     bool                          IsAntialiasingEnabled() const { return myIsAntialiasingEnabled; }
54
55     static QString                GetMessages( int type,TopAbs_ShapeEnum aSubShapeType,
56                                                TopAbs_ShapeEnum aShapeType );
57     static QString                GetShapeType( TopAbs_ShapeEnum aShapeType );
58
59     Standard_EXPORT static void   OnButtonuseraction( int ExerciceSTEP,
60                                                       Handle(AIS_InteractiveContext)& );
61     Standard_EXPORT static void   DoSelection( int Id,
62                                                Handle(AIS_InteractiveContext)& );
63     Standard_EXPORT static void   OnSetSelectionMode( Handle(AIS_InteractiveContext)&,
64                                                       Standard_Integer&,
65                                                       TopAbs_ShapeEnum& SelectionMode,
66                                                       Standard_Boolean& );
67     virtual QPaintEngine*         paintEngine() const;
68 signals:
69     void                          selectionChanged();
70
71 public slots:
72     void                          fitAll();
73     void                          fitArea();
74     void                          zoom();
75     void                          pan();
76     void                          globalPan();
77     void                          front();
78     void                          back();
79     void                          top();
80     void                          bottom();
81     void                          left();
82     void                          right();
83     void                          axo();
84     void                          rotation();
85     void                          reset();
86     void                          hlrOn();
87     void                          hlrOff();
88     void                          updateToggled( bool );
89     void                          onBackground();
90     void                          onEnvironmentMap();
91     void                          onRaytraceAction();
92
93 protected:
94     virtual void                  paintEvent( QPaintEvent* );
95     virtual void                  resizeEvent( QResizeEvent* );
96     virtual void                  mousePressEvent( QMouseEvent* );
97     virtual void                  mouseReleaseEvent(QMouseEvent* );
98     virtual void                  mouseMoveEvent( QMouseEvent* );
99     virtual void                  wheelEvent (QWheelEvent* );
100
101     virtual void                  addItemInPopup( QMenu* );
102
103     Handle(V3d_View)&                     getView();
104     Handle(AIS_InteractiveContext)&       getContext();
105     void                                  activateCursor( const CurrentAction3d );
106     void                                  Popup( const int x, const int y );
107     CurrentAction3d                       getCurrentMode();
108     void                                  updateView();
109
110     //! Setup mouse gestures.
111     void defineMouseGestures();
112
113     //! Set current action.
114     void setCurrentAction (CurrentAction3d theAction)
115     {
116       myCurrentMode = theAction;
117       defineMouseGestures();
118     }
119
120     //! Handle selection changed event.
121     void OnSelectionChanged (const Handle(AIS_InteractiveContext)& theCtx,
122                              const Handle(V3d_View)& theView) Standard_OVERRIDE;
123
124 private:
125     void                          initCursors();
126     void                          initViewActions();
127     void                          initRaytraceActions();
128 private:
129     bool                            myIsRaytracing;
130     bool                            myIsShadowsEnabled;
131     bool                            myIsReflectionsEnabled;
132     bool                            myIsAntialiasingEnabled;
133
134     Handle(V3d_View)                myView;
135     Handle(AIS_InteractiveContext)  myContext;
136     AIS_MouseGestureMap             myDefaultGestures;
137     Graphic3d_Vec2i                 myClickPos;
138     CurrentAction3d                 myCurrentMode;
139     Standard_Real                   myCurZoom;
140     QList<QAction*>*                myViewActions;
141     QList<QAction*>*                myRaytraceActions;
142     QMenu*                          myBackMenu;
143 };
144
145 #endif
146
147