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