82744543d8f02a20811702aedc5a131f6cb4e2da
[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 <V3d_View.hxx>
12
13 class TopoDS_Shape;
14 class QRubberBand;
15
16 //class COMMONSAMPLE_EXPORT View: public QWidget
17 class View: public QWidget
18 {
19     Q_OBJECT
20 protected:
21     enum CurrentAction3d { CurAction3d_Nothing, CurAction3d_DynamicZooming,
22                            CurAction3d_WindowZooming, CurAction3d_DynamicPanning,
23                            CurAction3d_GlobalPanning, CurAction3d_DynamicRotation };
24
25 public:
26     enum ViewAction { ViewFitAllId, ViewFitAreaId, ViewZoomId, ViewPanId, ViewGlobalPanId,
27                       ViewFrontId, ViewBackId, ViewTopId, ViewBottomId, ViewLeftId, ViewRightId,
28                       ViewAxoId, ViewRotationId, ViewResetId, ViewHlrOffId, ViewHlrOnId };
29     enum RaytraceAction { ToolRaytracingId, ToolShadowsId, ToolReflectionsId, ToolAntialiasingId };
30
31     View( Handle(AIS_InteractiveContext) theContext, QWidget* parent );
32
33     ~View();
34
35     virtual void                  init();
36     bool                          dump( Standard_CString theFile );
37     QList<QAction*>*              getViewActions();
38     QList<QAction*>*              getRaytraceActions();
39     void                          noActiveActions();
40     bool                          isShadingMode();
41
42     void                          EnableRaytracing();
43     void                          DisableRaytracing();
44
45     void                          SetRaytracedShadows (bool theState);
46     void                          SetRaytracedReflections (bool theState);
47     void                          SetRaytracedAntialiasing (bool theState);
48
49     bool                          IsRaytracingMode() const { return myIsRaytracing; }
50     bool                          IsShadowsEnabled() const { return myIsShadowsEnabled; }
51     bool                          IsReflectionsEnabled() const { return myIsReflectionsEnabled; }
52     bool                          IsAntialiasingEnabled() const { return myIsAntialiasingEnabled; }
53
54     static QString                GetMessages( int type,TopAbs_ShapeEnum aSubShapeType,
55                                                TopAbs_ShapeEnum aShapeType );
56     static QString                GetShapeType( TopAbs_ShapeEnum aShapeType );
57
58     Standard_EXPORT static void   OnButtonuseraction( int ExerciceSTEP,
59                                                       Handle(AIS_InteractiveContext)& );
60     Standard_EXPORT static void   DoSelection( int Id,
61                                                Handle(AIS_InteractiveContext)& );
62     Standard_EXPORT static void   OnSetSelectionMode( Handle(AIS_InteractiveContext)&,
63                                                       Standard_Integer&,
64                                                       TopAbs_ShapeEnum& SelectionMode,
65                                                       Standard_Boolean& );
66     virtual QPaintEngine*         paintEngine() const;
67 signals:
68     void                          selectionChanged();
69
70 public slots:
71     void                          fitAll();
72     void                          fitArea();
73     void                          zoom();
74     void                          pan();
75     void                          globalPan();
76     void                          front();
77     void                          back();
78     void                          top();
79     void                          bottom();
80     void                          left();
81     void                          right();
82     void                          axo();
83     void                          rotation();
84     void                          reset();
85     void                          hlrOn();
86     void                          hlrOff();
87     void                          updateToggled( bool );
88     void                          onBackground();
89     void                          onEnvironmentMap();
90     void                          onRaytraceAction();
91
92 protected:
93     virtual void                  paintEvent( QPaintEvent* );
94     virtual void                  resizeEvent( QResizeEvent* );
95     virtual void                  mousePressEvent( QMouseEvent* );
96     virtual void                  mouseReleaseEvent(QMouseEvent* );
97     virtual void                  mouseMoveEvent( QMouseEvent* );
98
99     virtual void                  addItemInPopup( QMenu* );
100
101     Handle(V3d_View)&                     getView();
102     Handle(AIS_InteractiveContext)&       getContext();
103     void                                  activateCursor( const CurrentAction3d );
104     void                                  Popup( const int x, const int y );
105     CurrentAction3d                       getCurrentMode();
106
107     virtual void                          onLButtonDown( const int nFlags, const QPoint point );
108     virtual void                          onMButtonDown( const int nFlags, const QPoint point );
109     virtual void                          onRButtonDown( const int nFlags, const QPoint point );
110     virtual void                          onLButtonUp( Qt::MouseButtons nFlags, const QPoint point );
111     virtual void                          onMButtonUp( Qt::MouseButtons nFlags, const QPoint point );
112     virtual void                          onRButtonUp( Qt::MouseButtons nFlags, const QPoint point );
113     virtual void                          onMouseMove( Qt::MouseButtons nFlags, const QPoint point );
114
115 private:
116     void                          initCursors();
117     void                          initViewActions();
118     void                          initRaytraceActions();
119     void                          DragEvent( const int x, const int y, const int TheState );
120     void                          InputEvent( const int x, const int y );
121     void                          MoveEvent( const int x, const int y );
122     void                          MultiMoveEvent( const int x, const int y );
123     void                          MultiDragEvent( const int x, const int y, const int TheState );
124     void                          MultiInputEvent( const int x, const int y );
125     void                          DrawRectangle( const int MinX, const int MinY,
126                                                  const int MaxX, const int MaxY, const bool Draw );
127
128 private:
129     bool                            myIsRaytracing;
130     bool                            myIsShadowsEnabled;
131     bool                            myIsReflectionsEnabled;
132     bool                            myIsAntialiasingEnabled;
133
134     bool                            myDrawRect;           // set when a rect is used for selection or magnify 
135     Handle(V3d_View)                myView;
136     Handle(AIS_InteractiveContext)  myContext;
137     CurrentAction3d                 myCurrentMode;
138     Standard_Integer                myXmin;
139     Standard_Integer                myYmin;
140     Standard_Integer                myXmax;
141     Standard_Integer                myYmax;
142     Standard_Real                   myCurZoom;
143     Standard_Boolean                myHlrModeIsOn;
144     QList<QAction*>*                myViewActions;
145     QList<QAction*>*                myRaytraceActions;
146     QMenu*                          myBackMenu;
147     QRubberBand*                    myRectBand; //!< selection rectangle rubber band
148 };
149
150 #endif
151
152