Salome HOME
Avoid direct link to SketchPlugin
[modules/shaper.git] / src / PartSet / PartSet_OperationFeatureEdit.h
1 // File:        PartSet_OperationFeatureEdit.h
2 // Created:     05 May 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef PartSet_OperationFeatureEdit_H
6 #define PartSet_OperationFeatureEdit_H
7
8 #include "PartSet.h"
9
10 #include <PartSet_OperationFeatureBase.h>
11 #include <QObject>
12
13 class QMouseEvent;
14
15 /*!
16  \class PartSet_OperationFeatureEdit
17  * \brief The operation for the sketch feature creation
18  */
19 class PARTSET_EXPORT PartSet_OperationFeatureEdit : public PartSet_OperationFeatureBase
20 {
21 Q_OBJECT
22   /// Struct to define gp point, with the state is the point is initialized
23   struct Point
24   {
25     /// Constructor
26     Point()
27     {
28       myIsInitialized = false;
29     }
30     /// Constructor
31     /// \param thePoint the point
32     Point(gp_Pnt thePoint)
33     {
34       setPoint(thePoint);
35     }
36     ~Point()
37     {
38     }
39
40     /// clear the initialized flag.
41     void clear()
42     {
43       myIsInitialized = false;
44     }
45     /// set the point and switch on the initialized flag
46     /// \param thePoint the point
47     void setPoint(const gp_Pnt& thePoint)
48     {
49       myIsInitialized = true;
50       myPoint = thePoint;
51     }
52
53     bool myIsInitialized;  /// the state whether the point is set
54     gp_Pnt myPoint;  /// the point
55   };
56
57  public:
58   /// Returns the operation type key
59   static std::string Type()
60   {
61     return "EditLine";
62   }
63
64  public:
65   /// Constructor
66   /// \param theId the feature identifier
67   /// \param theParent the operation parent
68   /// \param theFeature the parent feature
69   PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, FeaturePtr theFeature);
70   /// Destructor
71   virtual ~PartSet_OperationFeatureEdit();
72
73   /// Initializes the operation with previously created feature. It is used in sequental operations
74   virtual void initFeature(FeaturePtr theFeature);
75
76   /// Processes the mouse pressed in the point
77   /// \param theEvent the mouse event
78   /// \param theView a viewer to have the viewer the eye position
79   /// \param theSelected the list of selected presentations
80   /// \param theHighlighted the list of highlighted presentations
81   virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
82                             const std::list<ModuleBase_ViewerPrs>& theSelected,
83                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
84   /// Gives the current mouse point in the viewer
85   /// \param theEvent the mouse event
86   /// \param theView a viewer to have the viewer the eye position
87   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
88   /// Gives the current selected objects to be processed by the operation
89   /// \param thePoint a point clicked in the viewer
90   /// \param theEvent the mouse event
91   /// \param theSelected the list of selected presentations
92   /// \param theHighlighted the list of highlighted presentations
93   virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
94                              const std::list<ModuleBase_ViewerPrs>& theSelected,
95                              const std::list<ModuleBase_ViewerPrs>& theHighlighted);
96
97   /// Processes the mouse double click in the point
98   /// \param theEvent the mouse event
99   /// \param theView a viewer to have the viewer the eye position
100   /// \param theSelected the list of selected presentations
101   /// \param theHighlighted the list of highlighted presentations
102   virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
103                                 const std::list<ModuleBase_ViewerPrs>& theSelected,
104                                 const std::list<ModuleBase_ViewerPrs>& theHighlighted);
105
106  protected:
107   /// \brief Virtual method called when operation is started
108   /// Virtual method called when operation started (see start() method for more description)
109   /// Switch off the multi selection state
110   virtual void startOperation();
111
112   /// Virtual method called when operation stopped - committed or aborted.
113   /// Restore the multi selection state
114   virtual void stopOperation();
115
116   /// Creates an operation new feature
117   /// Returns NULL feature. This is an operation of edition, not creation.
118   /// \param theFlushMessage the flag whether the create message should be flushed
119   /// \returns the created feature
120   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
121
122  protected:
123   /// Emits a signal about the selection blocking. Emits a signal to change the selection.
124   /// If the block is true, the signal clear selection, otherwise if restore selection flag allows,
125   /// the internal operation features are to be selected
126   /// \param isBlocked the state whether the operation is blocked or unblocked
127   /// \param isRestoreSelection the state whether the selected objects should be reselected
128   void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
129
130   /// Sends the features
131   void sendFeatures();
132
133  private:
134   Point myCurPoint;  ///< the current 3D point clicked or moved
135   bool myIsBlockedSelection;  ///< the state of the last state of selection blocked signal
136 };
137
138 #endif