Salome HOME
updated copyright message
[modules/gui.git] / src / OCCViewer / OCCViewer_ViewSketcher.h
1 // Copyright (C) 2007-2023  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, or (at your option) any later version.
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 class QtxCircleRubberBand;
37
38 #ifdef WIN32
39 #pragma warning ( disable:4251 )
40 #endif
41
42 /*!
43   \class OCCViewer_ViewSketcher
44 */
45
46 class OCCVIEWER_EXPORT OCCViewer_ViewSketcher : public QObject
47 {
48   Q_OBJECT
49
50 public:
51   enum { Neutral, Accept, Reject };
52
53 public:
54   OCCViewer_ViewSketcher( OCCViewer_ViewWindow*, int );
55   virtual ~OCCViewer_ViewSketcher();
56
57 public:
58   int                          type() const;
59   int                          result() const;
60   int                          buttonState() const;
61   bool                         isHasShift() 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   virtual void                 setSketcherMode(int) {}
74   virtual int                  sketcherMode() const { return 0; }
75
76 private slots:
77   void                         onDrawViewPort();
78
79 protected:
80   enum SketchState { Debut, EnTrain, Fin };
81   virtual bool                 onKey( QKeyEvent* );
82   virtual void                 onMouse( QMouseEvent* );
83   virtual void                 onSketch( SketchState ) = 0;
84   virtual void                 onActivate();
85   virtual void                 onDeactivate();
86
87 protected:
88   int                          mySketchButton;
89   OCCViewer_ViewWindow*        mypViewWindow;
90   int                          myType;
91   void*                        mypData;
92   int                          myResult;
93   QCursor                      mySavedCursor;
94   QPoint                       myStart, myCurr;
95   int                          myButtonState;
96   bool                         myHasShift;
97 };
98
99 /*!
100   \class OCCViewer_RectSketcher
101 */
102
103 class OCCVIEWER_EXPORT OCCViewer_RectSketcher : public OCCViewer_ViewSketcher
104 {
105 public:
106   OCCViewer_RectSketcher( OCCViewer_ViewWindow*, int );
107   virtual ~OCCViewer_RectSketcher();
108
109 protected:
110   virtual bool                 onKey( QKeyEvent* );
111   virtual void                 onMouse( QMouseEvent* );
112   virtual void                 onSketch( SketchState );
113   virtual void                 onActivate();
114   virtual void                 onDeactivate();
115  private:
116   QtxRectRubberBand*           mypRectRB;
117 };
118
119 /*!
120   \class OCCViewer_PolygonSketcher
121 */
122
123 class OCCVIEWER_EXPORT OCCViewer_PolygonSketcher : public OCCViewer_ViewSketcher
124 {
125 public:
126   enum SketchMode { Poligone, Circle };
127
128   OCCViewer_PolygonSketcher( OCCViewer_ViewWindow*, int );
129   virtual ~OCCViewer_PolygonSketcher();
130
131   virtual void                 setSketcherMode(int theMode);
132   virtual int                  sketcherMode() const {
133     return myMode;
134   }
135
136 protected:
137   virtual bool                 onKey( QKeyEvent* );
138   virtual void                 onMouse( QMouseEvent* );
139   virtual void                 onSketch( SketchState );
140   virtual void                 onActivate();
141   virtual void                 onDeactivate();
142
143 private:
144   bool                         isValid( const QPolygon*, const QPoint& ) const;
145   bool                         isIntersect( const QPoint&, const QPoint&,
146                                             const QPoint&, const QPoint& ) const;
147
148 private:
149   bool                         myDbl;
150   QSize                        myToler;
151   QPolygon*                    mypPoints;
152   int                          myAddButton;
153   int                          myDelButton;
154   
155   QtxPolyRubberBand*           mypPolyRB;
156   QtxCircleRubberBand*         mypCircleRB;
157
158   SketchMode myMode;
159 };
160
161 #ifdef WIN32
162 #pragma warning( default:4251 )
163 #endif
164
165 #endif