Salome HOME
367ece1042b3ffb142a7256685874911edc09e1b
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewSketcher.h
1 // Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
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 #ifndef OCCVIEWER_VIEWSKETCHER_H
20 #define OCCVIEWER_VIEWSKETCHER_H
21
22 #include "OCCViewer.h"
23
24 #include <qobject.h>
25 #include <qcursor.h>
26
27 class OCCViewer_ViewWindow;
28
29 #ifdef WNT
30 #pragma warning ( disable:4251 )
31 #endif
32
33 /*!
34   \class OCCViewer_ViewSketcher
35 */
36
37 class OCCVIEWER_EXPORT OCCViewer_ViewSketcher : public QObject
38 {
39   Q_OBJECT
40
41 public:
42   enum { Neutral, Accept, Reject };
43
44 public:
45   OCCViewer_ViewSketcher( OCCViewer_ViewWindow*, int );
46   virtual ~OCCViewer_ViewSketcher();
47
48 public:
49   int                          type() const;
50   int                          result() const;
51   int                          buttonState() const;
52   void*                        data() const;
53
54   void                         activate();
55   void                         deactivate();
56
57   int                          sketchButton();
58   void                         setSketchButton( int );
59
60   virtual bool                 isDefault() const;
61   virtual bool                 eventFilter( QObject*, QEvent* );
62
63 private slots:
64   void                         onDrawViewPort();
65
66 protected:
67   enum SketchState { Debut, EnTrain, Fin };
68   virtual bool                 onKey( QKeyEvent* );
69   virtual void                 onMouse( QMouseEvent* );
70   virtual void                 onSketch( SketchState ) = 0;
71   virtual void                 onActivate();
72   virtual void                 onDeactivate();
73
74 protected:
75   int                          mySketchButton;
76   OCCViewer_ViewWindow*        mypViewWindow;
77   int                          myType;
78   void*                        mypData;
79   int                          myResult;
80   QCursor                      mySavedCursor;
81   QPoint                       myStart, myCurr;
82   int                          myButtonState;
83 };
84
85 /*!
86   \class OCCViewer_RectSketcher
87 */
88
89 class OCCVIEWER_EXPORT OCCViewer_RectSketcher : public OCCViewer_ViewSketcher
90 {
91 public:
92   OCCViewer_RectSketcher( OCCViewer_ViewWindow*, int );
93   virtual ~OCCViewer_RectSketcher();
94
95 protected:
96   virtual bool                 onKey( QKeyEvent* );
97   virtual void                 onMouse( QMouseEvent* );
98   virtual void                 onSketch( SketchState );
99   virtual void                 onActivate();
100   virtual void                 onDeactivate();
101 };
102
103 /*!
104   \class OCCViewer_PolygonSketcher
105 */
106
107 class OCCVIEWER_EXPORT OCCViewer_PolygonSketcher : public OCCViewer_ViewSketcher
108 {
109 public:
110   OCCViewer_PolygonSketcher( OCCViewer_ViewWindow*, int );
111   virtual ~OCCViewer_PolygonSketcher();
112
113 protected:
114   virtual bool                 onKey( QKeyEvent* );
115   virtual void                 onMouse( QMouseEvent* );
116   virtual void                 onSketch( SketchState );
117   virtual void                 onActivate();
118   virtual void                 onDeactivate();
119
120 private:
121   bool                         isValid( const QPointArray*, const QPoint& ) const;
122   bool                         isIntersect( const QPoint&, const QPoint&,
123                                             const QPoint&, const QPoint& ) const;
124
125 private:
126   bool                         myDbl;
127   QSize                        myToler;
128   QPointArray*                 mypPoints;
129   int                          myAddButton;
130   int                          myDelButton;
131 };
132
133 #ifdef WNT
134 #pragma warning( default:4251 )
135 #endif
136
137 #endif