Back to index

salome-gui  6.5.0
OCCViewer_ViewSketcher.h
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 
00020 #ifndef OCCVIEWER_VIEWSKETCHER_H
00021 #define OCCVIEWER_VIEWSKETCHER_H
00022 
00023 #include "OCCViewer.h"
00024 
00025 #include <QObject>
00026 #include <QCursor>
00027 #include <QSize>
00028 
00029 class OCCViewer_ViewWindow;
00030 class QKeyEvent;
00031 class QMouseEvent;
00032 class QPolygon;
00033 
00034 class QtxRectRubberBand;
00035 class QtxPolyRubberBand;
00036 
00037 #ifdef WNT
00038 #pragma warning ( disable:4251 )
00039 #endif
00040 
00045 class OCCVIEWER_EXPORT OCCViewer_ViewSketcher : public QObject
00046 {
00047   Q_OBJECT
00048 
00049 public:
00050   enum { Neutral, Accept, Reject };
00051 
00052 public:
00053   OCCViewer_ViewSketcher( OCCViewer_ViewWindow*, int );
00054   virtual ~OCCViewer_ViewSketcher();
00055 
00056 public:
00057   int                          type() const;
00058   int                          result() const;
00059   int                          buttonState() const;
00060   void*                        data() const;
00061 
00062   void                         activate();
00063   void                         deactivate();
00064 
00065   int                          sketchButton();
00066   void                         setSketchButton( int );
00067 
00068   virtual bool                 isDefault() const;
00069   virtual bool                 eventFilter( QObject*, QEvent* );
00070 
00071 private slots:
00072   void                         onDrawViewPort();
00073 
00074 protected:
00075   enum SketchState { Debut, EnTrain, Fin };
00076   virtual bool                 onKey( QKeyEvent* );
00077   virtual void                 onMouse( QMouseEvent* );
00078   virtual void                 onSketch( SketchState ) = 0;
00079   virtual void                 onActivate();
00080   virtual void                 onDeactivate();
00081 
00082 protected:
00083   int                          mySketchButton;
00084   OCCViewer_ViewWindow*        mypViewWindow;
00085   int                          myType;
00086   void*                        mypData;
00087   int                          myResult;
00088   QCursor                      mySavedCursor;
00089   QPoint                       myStart, myCurr;
00090   int                          myButtonState;
00091 };
00092 
00097 class OCCVIEWER_EXPORT OCCViewer_RectSketcher : public OCCViewer_ViewSketcher
00098 {
00099 public:
00100   OCCViewer_RectSketcher( OCCViewer_ViewWindow*, int );
00101   virtual ~OCCViewer_RectSketcher();
00102 
00103 protected:
00104   virtual bool                 onKey( QKeyEvent* );
00105   virtual void                 onMouse( QMouseEvent* );
00106   virtual void                 onSketch( SketchState );
00107   virtual void                 onActivate();
00108   virtual void                 onDeactivate();
00109  private:
00110   QtxRectRubberBand*           mypRectRB;
00111 };
00112 
00117 class OCCVIEWER_EXPORT OCCViewer_PolygonSketcher : public OCCViewer_ViewSketcher
00118 {
00119 public:
00120   OCCViewer_PolygonSketcher( OCCViewer_ViewWindow*, int );
00121   virtual ~OCCViewer_PolygonSketcher();
00122 
00123 protected:
00124   virtual bool                 onKey( QKeyEvent* );
00125   virtual void                 onMouse( QMouseEvent* );
00126   virtual void                 onSketch( SketchState );
00127   virtual void                 onActivate();
00128   virtual void                 onDeactivate();
00129 
00130 private:
00131   bool                         isValid( const QPolygon*, const QPoint& ) const;
00132   bool                         isIntersect( const QPoint&, const QPoint&,
00133                                             const QPoint&, const QPoint& ) const;
00134 
00135 private:
00136   bool                         myDbl;
00137   QSize                        myToler;
00138   QPolygon*                    mypPoints;
00139   int                          myAddButton;
00140   int                          myDelButton;
00141   
00142   QtxPolyRubberBand*           mypPolyRB;
00143 };
00144 
00145 #ifdef WNT
00146 #pragma warning( default:4251 )
00147 #endif
00148 
00149 #endif