Salome HOME
Set 2d mode for OCC widget.
[modules/hydro.git] / src / HYDROCurveCreator / OCCViewer_ViewWidget.h
1 #ifndef OCCVIEWER_VIEWWIDGET_H
2 #define OCCVIEWER_VIEWWIDGET_H
3
4 #include "CurveCreator_Macro.hxx"
5 #include <Basics_OCCTVersion.hxx>
6
7 #include <OCCViewer_ViewWindow.h>
8 #include <QtxAction.h>
9 #include <QtxMultiAction.h>
10
11 #include <V3d_Viewer.hxx>
12 #include <AIS_InteractiveContext.hxx>
13 #include <AIS_Trihedron.hxx>
14 #include <TopoDS_Shape.hxx>
15
16 #include <QCursor>
17 #include <QFrame>
18 #include <QColor>
19
20 class OCCViewer_ViewPort3d;
21 class QPushButton;
22 class QToolBar;
23
24 class Handle(V3d_Viewer);
25
26 #ifdef WIN32
27 #pragma warning ( disable:4251 )
28 #endif
29
30 // ---------------- OCC view widget --------
31 class CURVECREATOR_EXPORT OCCViewer_ViewWidget : public QFrame
32 {
33   Q_OBJECT
34
35 public:
36   typedef enum { FitAllId, FitRectId, ZoomId, PanId, GlobalPanId, RotationId, TrihId,
37                  FrontId, BackId, TopId, BottomId, LeftId, RightId, None } ButtonsType;
38
39   OCCViewer_ViewWidget(QWidget* parent, const bool isUseMultiAction = true);
40   ~OCCViewer_ViewWidget();
41
42   OCCViewer_ViewPort3d* getViewPort();
43
44   bool      eventFilter(QObject* watched, QEvent* e);
45
46   void      reset();
47   void      Display(const TopoDS_Shape shape, const bool theShaded,
48                     const QColor& shapeColor);
49
50   enum Mode2dType { No2dMode, XYPlane, XZPlane, YZPlane};
51
52   void       set2dMode( Mode2dType );
53   Mode2dType get2dMode() const { return my2dMode; }
54
55   QAction*   action( const ButtonsType& theId );
56
57 public slots:
58   void      onActivated();
59   void      onTrihChanged();
60   void      onFrontView();
61   void      onBackView();
62   void      onTopView();
63   void      onBottomView();
64   void      onLeftView();
65   void      onRightView();
66
67 private:
68   enum OperationType{ NOTHING, FITALLVIEW, WINDOWFIT, ZOOMVIEW, PANVIEW, PANGLOBAL,
69                       ROTATE };
70
71   void      createActions();
72   void      viewZFitAll();
73   void      activateZoom();
74   void      activateWindowFit();
75   void      activateRotation();
76   void      activatePanning();
77   void      activateGlPanning();
78   OperationType getButtonState(QMouseEvent* theEvent);
79   void      viewerFitAll(const bool theUpdate = true);
80
81   void vpMousePressEvent  (QMouseEvent* theEvent);
82   void vpMouseReleaseEvent(QMouseEvent* theEvent);
83   void vpMouseMoveEvent   (QMouseEvent* theEvent);
84
85   void drawRect();
86   void resetState();
87   bool transformRequested() { return myOperation != NOTHING; }
88   bool setTransformRequested (OperationType op);
89   void clearViewer(const bool theUpdate = true);
90
91   typedef QMap<ButtonsType, QtxAction*> ActionsMap;
92
93 private:
94   OCCViewer_ViewPort3d*          myViewPort;
95   Handle(V3d_Viewer)             myV3dViewer;
96 #if OCC_VERSION_LARGE <= 0x06060000 
97   Handle(V3d_Viewer)             myV3dCollector;
98 #endif
99   Handle(AIS_InteractiveContext) myAISContext;
100   Handle(AIS_Trihedron)          myTrihedron;
101
102   QtxMultiAction       *myZoomBtns, *myPanBtns, *myProjBtns;
103   QToolBar*            myToolBar;
104   OperationType        myOperation;
105
106   ActionsMap           myButsMap;
107   QCursor              myCursor;
108   QRect                myRect;
109
110   double                myCurScale;
111   bool                  myCursorIsHand;
112   bool                  myDrawRect;
113   int                   myStartX;
114   int                   myStartY;
115   int                   myCurrX;
116   int                   myCurrY;
117   OCCViewer_ViewWindow::RotationPointType myCurrPointType;
118   gp_Pnt                mySelectedPoint;
119   bool                  myShowTrihedron;
120
121   Mode2dType            my2dMode;
122   bool                  myUseMultiAction;
123 };
124
125 #endif