Salome HOME
b33b0690d10afc457f590471dd4d6dfc401dca9f
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewSketcher.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 #ifndef OCCVIEWER_VIEWSKETCHER_H
23 #define OCCVIEWER_VIEWSKETCHER_H
24
25 #include "OCCViewer.h"
26
27 #include <QObject>
28 #include <QCursor>
29 #include <QSize>
30
31 class OCCViewer_ViewWindow;
32 class QKeyEvent;
33 class QMouseEvent;
34 class QPolygon;
35
36 class QtxRectRubberBand;
37 class QtxPolyRubberBand;
38
39 #ifdef WNT
40 #pragma warning ( disable:4251 )
41 #endif
42
43 /*!
44   \class OCCViewer_ViewSketcher
45 */
46
47 class OCCVIEWER_EXPORT OCCViewer_ViewSketcher : public QObject
48 {
49   Q_OBJECT
50
51 public:
52   enum { Neutral, Accept, Reject };
53
54 public:
55   OCCViewer_ViewSketcher( OCCViewer_ViewWindow*, int );
56   virtual ~OCCViewer_ViewSketcher();
57
58 public:
59   int                          type() const;
60   int                          result() const;
61   int                          buttonState() const;
62   void*                        data() const;
63
64   void                         activate();
65   void                         deactivate();
66
67   int                          sketchButton();
68   void                         setSketchButton( int );
69
70   virtual bool                 isDefault() const;
71   virtual bool                 eventFilter( QObject*, QEvent* );
72
73 private slots:
74   void                         onDrawViewPort();
75
76 protected:
77   enum SketchState { Debut, EnTrain, Fin };
78   virtual bool                 onKey( QKeyEvent* );
79   virtual void                 onMouse( QMouseEvent* );
80   virtual void                 onSketch( SketchState ) = 0;
81   virtual void                 onActivate();
82   virtual void                 onDeactivate();
83
84 protected:
85   int                          mySketchButton;
86   OCCViewer_ViewWindow*        mypViewWindow;
87   int                          myType;
88   void*                        mypData;
89   int                          myResult;
90   QCursor                      mySavedCursor;
91   QPoint                       myStart, myCurr;
92   int                          myButtonState;
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