Salome HOME
4ed77c29dd164295cee677b2295b52e75d95feb2
[modules/geom.git] / src / MeasureGUI / MeasureGUI_DimensionInteractor.h
1 // Copyright (C) 2007-2013  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
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File   : MeasureGUI_DimensionEditor.h
25 // Author : Anton POLETAEV, Open CASCADE S.A.S.
26 //
27 #ifndef MEASUREGUI_DIMENSIONINTERACTOR_H
28 #define MEASUREGUI_DIMENSIONINTERACTOR_H
29
30 #include <GeometryGUI.h>
31 #include <QObject>
32
33 #include <SelectMgr_EntityOwner.hxx>
34 #include <NCollection_Sequence.hxx>
35 #include <AIS_ListOfInteractive.hxx>
36 #include <AIS_InteractiveObject.hxx>
37 #include <AIS_Dimension.hxx>
38 #include <gp_Pln.hxx>
39
40 class OCCViewer_ViewManager;
41 class OCCViewer_Viewer;
42 class SUIT_ViewWindow;
43 class Handle(V3d_View);
44
45 //=================================================================================
46 // class    : MeasureGUI_DimensionInteractor
47 // purpose  : Interactive editor of dimension presentations
48 //=================================================================================
49 class MeasureGUI_DimensionInteractor : public QObject
50 {
51   Q_OBJECT
52
53 public:
54   enum Operation
55   {
56     Operation_MoveFlyoutFree,
57     Operation_MoveFlyoutInPlane,
58     Operation_MoveText,
59     Operation_None
60   };
61
62 public:
63   MeasureGUI_DimensionInteractor( GeometryGUI*, QObject* );
64   ~MeasureGUI_DimensionInteractor();
65
66 public:
67   void                   Enable();
68   void                   Disable();
69
70 protected:
71   /*!
72    * \brief Identify interactive operation by picked entity and pressed buttons with modifiers
73    *
74    * \param theEntity [in] the picked entity.
75    * \param theButtons [in] the mouse buttons.
76    * \param theKeys [in] the keyboard modifiers.
77    */
78   Operation              GetOperation( const Handle(SelectMgr_EntityOwner)& theEntity,
79                                        const Qt::MouseButtons theButtons,
80                                        const Qt::KeyboardModifiers theKeys );
81
82   /*!
83    * \brief Prepare for interactive operation.
84    * 
85    * \param theOp [in] the operation.
86    * \param theView [in] the interacted view.
87    * \param theX [in] the mouse position x.
88    * \param theY [in] the mouse position y.
89    * \return TRUE if operation can be started.
90    */
91   bool                  StartOperation( const Operation theOperation,
92                                         const Handle(V3d_View)& theView,
93                                         const int theX,
94                                         const int theY );
95
96   /*!
97    * \brief Perform "Operation_MoveFlyoutFree".
98    * Modify flyout of interactive dimension so as the flyout follows
99    * the mouse by its length and orientation.
100    *
101    * \param theView [in] the interacted view.
102    * \param theX [in] the mouse position x.
103    * \param theY [in] the mouse position y.
104    */
105   void                   MoveFlyoutFree( const Handle(V3d_View)& theView, const int theX, const int theY );
106
107   /*!
108    * \brief Perform "Operation_MoveFlyoutInPlane".
109    * Modify flyout of interactive dimension so as the flyout is extended
110    * to the mouse point location in the presentation plane.
111    *
112    * \param theView [in] the interacted view.
113    * \param theX [in] the mouse position x.
114    * \param theY [in] the mouse position y.
115    */
116   void                   MoveFlyoutInPlane( const Handle(V3d_View)& theView, const int theX, const int theY );
117
118   /*!
119    * \brief Perform "Operation_MoveText". 
120    * Modify text of interactive dimension so as the text is moved to its fixed positions.
121    *
122    * \param theView [in] the interacted view.
123    * \param theX [in] the mouse position x.
124    * \param theY [in] the mouse position y.
125    */
126   void                   MoveText( const Handle(V3d_View)& theView, const int theX, const int theY );
127
128 signals:
129   void                   InteractionStarted( Handle_AIS_InteractiveObject theIO );
130   void                   InteractionFinished( Handle_AIS_InteractiveObject theIO );
131
132 protected:
133   void                   ConnectView( SUIT_ViewWindow* );
134   void                   DisconnectView( SUIT_ViewWindow* );
135   gp_Lin                 Projection( const Handle(V3d_View)&, const int, const int );
136   gp_Pnt                 ProjectPlane( const Handle(V3d_View)&, 
137                                        const int,
138                                        const int,
139                                        const gp_Pln&,
140                                        bool& );
141   Standard_Real          SensitivityTolerance( const Handle(V3d_View)& );
142
143 protected:
144   /*!
145    * \brief Process events from OCC viewer prior to their coming into the base viewer class.
146    *
147    * It handles the events coming to viewport and identifies whether the events correspond to
148    * interactive operation on dimension. If yes, the operation is performed within the
149    * interactor class and events are "accepted". Otherwise, the events are passed to
150    * viewer subroutines.
151    *
152    * The method manages internal workflow related to starting and stopping interactive 
153    * operations to modify the presentations which were passed for this interactor class.
154    *
155    */
156   virtual bool           eventFilter( QObject*, QEvent* );
157
158 protected slots:
159   void                   OnViewCreated( SUIT_ViewWindow* );
160   void                   OnViewRemoved( SUIT_ViewWindow* );
161
162 private:
163   typedef NCollection_Sequence<Handle(SelectMgr_EntityOwner)> SeqOfOwners;
164
165 private:
166   GeometryGUI*            myGeomGUI;
167   bool                    myIsEnabled;
168   OCCViewer_ViewManager*  myVM;
169   OCCViewer_Viewer*       myViewer;
170   Operation               myOperation;
171   bool                    myOperationStarted;
172   gp_Pln                  myFreeMovePlane;
173   Handle(AIS_Dimension)   myInteractedIO;
174   SeqOfOwners             mySelection;
175 };
176
177 #endif