Salome HOME
0022077: EDF 2272 : Selection with the Paraview interaction mode in GEOM/SMESH
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewSketcher.h
1 // Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #ifndef OCCVIEWER_VIEWSKETCHER_H
21 #define OCCVIEWER_VIEWSKETCHER_H
22
23 #include "OCCViewer.h"
24
25 #include <QObject>
26 #include <QCursor>
27 #include <QSize>
28
29 class OCCViewer_ViewWindow;
30 class QKeyEvent;
31 class QMouseEvent;
32 class QPolygon;
33
34 class QtxRectRubberBand;
35 class QtxPolyRubberBand;
36
37 #ifdef WNT
38 #pragma warning ( disable:4251 )
39 #endif
40
41 /*!
42   \class OCCViewer_ViewSketcher
43 */
44
45 class OCCVIEWER_EXPORT OCCViewer_ViewSketcher : public QObject
46 {
47   Q_OBJECT
48
49 public:
50   enum { Neutral, Accept, Reject };
51
52 public:
53   OCCViewer_ViewSketcher( OCCViewer_ViewWindow*, int );
54   virtual ~OCCViewer_ViewSketcher();
55
56 public:
57   int                          type() const;
58   int                          result() const;
59   int                          buttonState() const;
60   bool                         isHasShift() const;
61   void*                        data() const;
62
63   void                         activate();
64   void                         deactivate();
65
66   int                          sketchButton();
67   void                         setSketchButton( int );
68
69   virtual bool                 isDefault() const;
70   virtual bool                 eventFilter( QObject*, QEvent* );
71
72 private slots:
73   void                         onDrawViewPort();
74
75 protected:
76   enum SketchState { Debut, EnTrain, Fin };
77   virtual bool                 onKey( QKeyEvent* );
78   virtual void                 onMouse( QMouseEvent* );
79   virtual void                 onSketch( SketchState ) = 0;
80   virtual void                 onActivate();
81   virtual void                 onDeactivate();
82
83 protected:
84   int                          mySketchButton;
85   OCCViewer_ViewWindow*        mypViewWindow;
86   int                          myType;
87   void*                        mypData;
88   int                          myResult;
89   QCursor                      mySavedCursor;
90   QPoint                       myStart, myCurr;
91   int                          myButtonState;
92   bool                         myHasShift;
93 };
94
95 /*!
96   \class OCCViewer_RectSketcher
97 */
98
99 class OCCVIEWER_EXPORT OCCViewer_RectSketcher : public OCCViewer_ViewSketcher
100 {
101 public:
102   OCCViewer_RectSketcher( OCCViewer_ViewWindow*, int );
103   virtual ~OCCViewer_RectSketcher();
104
105 protected:
106   virtual bool                 onKey( QKeyEvent* );
107   virtual void                 onMouse( QMouseEvent* );
108   virtual void                 onSketch( SketchState );
109   virtual void                 onActivate();
110   virtual void                 onDeactivate();
111  private:
112   QtxRectRubberBand*           mypRectRB;
113 };
114
115 /*!
116   \class OCCViewer_PolygonSketcher
117 */
118
119 class OCCVIEWER_EXPORT OCCViewer_PolygonSketcher : public OCCViewer_ViewSketcher
120 {
121 public:
122   OCCViewer_PolygonSketcher( OCCViewer_ViewWindow*, int );
123   virtual ~OCCViewer_PolygonSketcher();
124
125 protected:
126   virtual bool                 onKey( QKeyEvent* );
127   virtual void                 onMouse( QMouseEvent* );
128   virtual void                 onSketch( SketchState );
129   virtual void                 onActivate();
130   virtual void                 onDeactivate();
131
132 private:
133   bool                         isValid( const QPolygon*, const QPoint& ) const;
134   bool                         isIntersect( const QPoint&, const QPoint&,
135                                             const QPoint&, const QPoint& ) const;
136
137 private:
138   bool                         myDbl;
139   QSize                        myToler;
140   QPolygon*                    mypPoints;
141   int                          myAddButton;
142   int                          myDelButton;
143   
144   QtxPolyRubberBand*           mypPolyRB;
145 };
146
147 #ifdef WNT
148 #pragma warning( default:4251 )
149 #endif
150
151 #endif