0031518: Samples - update QtWidget samples to use AIS_ViewController
[occt.git] / samples / qt / Common / src / View.h
CommitLineData
7fd59977 1#ifndef VIEW_H
2#define VIEW_H
3
55a40de8 4#include <Standard_WarningsDisable.hxx>
7fd59977 5#include <QWidget>
6#include <QAction>
7#include <QList>
55a40de8 8#include <Standard_WarningsRestore.hxx>
7fd59977 9
10#include <AIS_InteractiveContext.hxx>
0439d1cf 11#include <AIS_ViewController.hxx>
7fd59977 12#include <V3d_View.hxx>
13
14class TopoDS_Shape;
15class QRubberBand;
16
17//class COMMONSAMPLE_EXPORT View: public QWidget
0439d1cf 18class View: public QWidget, protected AIS_ViewController
7fd59977 19{
20 Q_OBJECT
21protected:
22 enum CurrentAction3d { CurAction3d_Nothing, CurAction3d_DynamicZooming,
de6273a3 23 CurAction3d_WindowZooming, CurAction3d_DynamicPanning,
24 CurAction3d_GlobalPanning, CurAction3d_DynamicRotation };
7fd59977 25
26public:
27 enum ViewAction { ViewFitAllId, ViewFitAreaId, ViewZoomId, ViewPanId, ViewGlobalPanId,
28 ViewFrontId, ViewBackId, ViewTopId, ViewBottomId, ViewLeftId, ViewRightId,
29 ViewAxoId, ViewRotationId, ViewResetId, ViewHlrOffId, ViewHlrOnId };
861a7b03 30 enum RaytraceAction { ToolRaytracingId, ToolShadowsId, ToolReflectionsId, ToolAntialiasingId };
7fd59977 31
861a7b03 32 View( Handle(AIS_InteractiveContext) theContext, QWidget* parent );
e276548b 33
7fd59977 34 ~View();
35
36 virtual void init();
37 bool dump( Standard_CString theFile );
38 QList<QAction*>* getViewActions();
861a7b03 39 QList<QAction*>* getRaytraceActions();
7fd59977 40 void noActiveActions();
41 bool isShadingMode();
42
861a7b03 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; }
e276548b 54
7fd59977 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,
de6273a3 60 Handle(AIS_InteractiveContext)& );
7fd59977 61 Standard_EXPORT static void DoSelection( int Id,
62 Handle(AIS_InteractiveContext)& );
63 Standard_EXPORT static void OnSetSelectionMode( Handle(AIS_InteractiveContext)&,
64 Standard_Integer&,
de6273a3 65 TopAbs_ShapeEnum& SelectionMode,
66 Standard_Boolean& );
67 virtual QPaintEngine* paintEngine() const;
7fd59977 68signals:
69 void selectionChanged();
70
71public 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();
e276548b 90 void onEnvironmentMap();
861a7b03 91 void onRaytraceAction();
7fd59977 92
93protected:
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* );
0439d1cf 99 virtual void wheelEvent (QWheelEvent* );
7fd59977 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();
0439d1cf 108 void updateView();
7fd59977 109
0439d1cf 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;
7fd59977 123
124private:
125 void initCursors();
126 void initViewActions();
861a7b03 127 void initRaytraceActions();
7fd59977 128private:
861a7b03 129 bool myIsRaytracing;
130 bool myIsShadowsEnabled;
131 bool myIsReflectionsEnabled;
132 bool myIsAntialiasingEnabled;
133
7fd59977 134 Handle(V3d_View) myView;
135 Handle(AIS_InteractiveContext) myContext;
0439d1cf 136 AIS_MouseGestureMap myDefaultGestures;
137 Graphic3d_Vec2i myClickPos;
7fd59977 138 CurrentAction3d myCurrentMode;
ee2be2a8 139 Standard_Real myCurZoom;
7fd59977 140 QList<QAction*>* myViewActions;
861a7b03 141 QList<QAction*>* myRaytraceActions;
e276548b 142 QMenu* myBackMenu;
7fd59977 143};
144
145#endif
146
147