Salome HOME
Merge branch 'master' of newgeom:newgeom.git
[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_OperationSketchBase.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_OperationSketchBase
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     }
29     /// Constructor
30     /// \param thePoint the point
31     Point(gp_Pnt thePoint)
32     {
33       setPoint(thePoint);
34     }
35     ~Point()
36     {
37     }
38
39     /// clear the initialized flag.
40     void clear()
41     {
42       myIsInitialized = false;
43     }
44     /// set the point and switch on the initialized flag
45     /// \param thePoint the point
46     void setPoint(const gp_Pnt& thePoint)
47     {
48       myIsInitialized = true;
49       myPoint = thePoint;
50     }
51
52     bool myIsInitialized;  /// the state whether the point is set
53     gp_Pnt myPoint;  /// the point
54   };
55
56  public:
57   /// Returns the operation type key
58   static std::string Type()
59   {
60     return "EditLine";
61   }
62
63  public:
64   /// Constructor
65   /// \param theId the feature identifier
66   /// \param theParent the operation parent
67   /// \param theFeature the parent feature
68   PartSet_OperationFeatureEdit(const QString& theId, QObject* theParent, FeaturePtr theFeature);
69   /// Destructor
70   virtual ~PartSet_OperationFeatureEdit();
71
72   /// Returns that this operator can be started above already running one.
73   /// The runned operation should be the sketch feature modified operation
74   /// \param theOperation the previous running operation
75   virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
76
77   /// Returns the operation local selection mode
78   /// \param theFeature the feature object to get the selection mode
79   /// \return the selection mode
80   virtual std::list<int> getSelectionModes(ObjectPtr theFeature) const;
81
82   /// Initializes the operation with previously created feature. It is used in sequental operations
83   virtual void initFeature(FeaturePtr theFeature);
84
85   /// Returns the operation sketch feature
86   /// \returns the sketch instance
87   virtual FeaturePtr sketch() const;
88
89   /// Processes the mouse pressed in the point
90   /// \param theEvent the mouse event
91   /// \param theView a viewer to have the viewer the eye position
92   /// \param theSelected the list of selected presentations
93   /// \param theHighlighted the list of highlighted presentations
94   virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
95                             const std::list<ModuleBase_ViewerPrs>& theSelected,
96                             const std::list<ModuleBase_ViewerPrs>& theHighlighted);
97   /// Gives the current mouse point in the viewer
98   /// \param theEvent the mouse event
99   /// \param theView a viewer to have the viewer the eye position
100   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
101   /// Gives the current selected objects to be processed by the operation
102   /// \param thePoint a point clicked in the viewer
103   /// \param theEvent the mouse event
104   /// \param theSelected the list of selected presentations
105   /// \param theHighlighted the list of highlighted presentations
106   virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
107                              const std::list<ModuleBase_ViewerPrs>& theSelected,
108                              const std::list<ModuleBase_ViewerPrs>& theHighlighted);
109
110   /// Processes the mouse double click in the point
111   /// \param theEvent the mouse event
112   /// \param theView a viewer to have the viewer the eye position
113   /// \param theSelected the list of selected presentations
114   /// \param theHighlighted the list of highlighted presentations
115   virtual void mouseDoubleClick(QMouseEvent* theEvent, Handle_V3d_View theView,
116                                 const std::list<ModuleBase_ViewerPrs>& theSelected,
117                                 const std::list<ModuleBase_ViewerPrs>& theHighlighted);
118
119   /// Processes the key pressed in the view
120   /// \param theKey a key value
121   virtual void keyReleased(const int theKey);
122
123  protected:
124   /// \brief Virtual method called when operation is started
125   /// Virtual method called when operation started (see start() method for more description)
126   /// Switch off the multi selection state
127   virtual void startOperation();
128
129   /// Virtual method called when operation stopped - committed or aborted.
130   /// Restore the multi selection state
131   virtual void stopOperation();
132
133   /// Creates an operation new feature
134   /// Returns NULL feature. This is an operation of edition, not creation.
135   /// \param theFlushMessage the flag whether the create message should be flushed
136   /// \returns the created feature
137   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
138
139  protected:
140   /// Emits a signal about the selection blocking. Emits a signal to change the selection.
141   /// If the block is true, the signal clear selection, otherwise if restore selection flag allows,
142   /// the internal operation features are to be selected
143   /// \param isBlocked the state whether the operation is blocked or unblocked
144   /// \param isRestoreSelection the state whether the selected objects should be reselected
145   void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
146
147   /// Sends the features
148   void sendFeatures();
149
150  private:
151   FeaturePtr mySketch;  ///< the sketch feature
152   Point myCurPoint;  ///< the current 3D point clicked or moved
153   bool myIsBlockedSelection;  ///< the state of the last state of selection blocked signal
154 };
155
156 #endif