Salome HOME
Merge from V6_main_20120808 08Aug12
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewSketcher.h
1 // Copyright (C) 2007-2012  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   void*                        data() const;
61
62   void                         activate();
63   void                         deactivate();
64
65   int                          sketchButton();
66   void                         setSketchButton( int );
67
68   virtual bool                 isDefault() const;
69   virtual bool                 eventFilter( QObject*, QEvent* );
70
71 private slots:
72   void                         onDrawViewPort();
73
74 protected:
75   enum SketchState { Debut, EnTrain, Fin };
76   virtual bool                 onKey( QKeyEvent* );
77   virtual void                 onMouse( QMouseEvent* );
78   virtual void                 onSketch( SketchState ) = 0;
79   virtual void                 onActivate();
80   virtual void                 onDeactivate();
81
82 protected:
83   int                          mySketchButton;
84   OCCViewer_ViewWindow*        mypViewWindow;
85   int                          myType;
86   void*                        mypData;
87   int                          myResult;
88   QCursor                      mySavedCursor;
89   QPoint                       myStart, myCurr;
90   int                          myButtonState;
91 };
92
93 /*!
94   \class OCCViewer_RectSketcher
95 */
96
97 class OCCVIEWER_EXPORT OCCViewer_RectSketcher : public OCCViewer_ViewSketcher
98 {
99 public:
100   OCCViewer_RectSketcher( OCCViewer_ViewWindow*, int );
101   virtual ~OCCViewer_RectSketcher();
102
103 protected:
104   virtual bool                 onKey( QKeyEvent* );
105   virtual void                 onMouse( QMouseEvent* );
106   virtual void                 onSketch( SketchState );
107   virtual void                 onActivate();
108   virtual void                 onDeactivate();
109  private:
110   QtxRectRubberBand*           mypRectRB;
111 };
112
113 /*!
114   \class OCCViewer_PolygonSketcher
115 */
116
117 class OCCVIEWER_EXPORT OCCViewer_PolygonSketcher : public OCCViewer_ViewSketcher
118 {
119 public:
120   OCCViewer_PolygonSketcher( OCCViewer_ViewWindow*, int );
121   virtual ~OCCViewer_PolygonSketcher();
122
123 protected:
124   virtual bool                 onKey( QKeyEvent* );
125   virtual void                 onMouse( QMouseEvent* );
126   virtual void                 onSketch( SketchState );
127   virtual void                 onActivate();
128   virtual void                 onDeactivate();
129
130 private:
131   bool                         isValid( const QPolygon*, const QPoint& ) const;
132   bool                         isIntersect( const QPoint&, const QPoint&,
133                                             const QPoint&, const QPoint& ) const;
134
135 private:
136   bool                         myDbl;
137   QSize                        myToler;
138   QPolygon*                    mypPoints;
139   int                          myAddButton;
140   int                          myDelButton;
141   
142   QtxPolyRubberBand*           mypPolyRB;
143 };
144
145 #ifdef WNT
146 #pragma warning( default:4251 )
147 #endif
148
149 #endif