Salome HOME
826a5f9aedf77a4132e8dcf6fc3d94db16e2a0fc
[modules/shaper.git] / src / PartSet / PartSet_OperationEditLine.h
1 // File:        PartSet_OperationEditLine.h
2 // Created:     05 May 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef PartSet_OperationEditLine_H
6 #define PartSet_OperationEditLine_H
7
8 #include "PartSet.h"
9
10 #include <PartSet_OperationSketchBase.h>
11 #include <QObject>
12
13 class QMouseEvent;
14
15 /*!
16  \class PartSet_OperationEditLine
17  * \brief The operation for the sketch feature creation
18 */
19 class PARTSET_EXPORT PartSet_OperationEditLine : 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     /// Constructor
28     /// \param thePoint the point
29     Point(gp_Pnt thePoint)
30     {
31       setPoint(thePoint);
32     }
33     ~Point() {}
34
35     /// clear the initialized flag.
36     void clear() { myIsInitialized = false; }
37     /// set the point and switch on the initialized flag
38     /// \param thePoint the point
39     void setPoint(const gp_Pnt& thePoint)
40     {
41       myIsInitialized = true;
42       myPoint = thePoint;
43     }
44
45     bool myIsInitialized; /// the state whether the point is set
46     gp_Pnt myPoint; /// the point
47   };
48
49 public:
50   /// Returns the operation type key
51   static std::string Type() { return "EditLine"; }
52
53 public:
54   /// Constructor
55   /// \param theId the feature identifier
56   /// \param theParent the operation parent
57   /// \param theFeature the parent feature
58   PartSet_OperationEditLine(const QString& theId, QObject* theParent,
59                             boost::shared_ptr<ModelAPI_Feature> theFeature);
60   /// Destructor
61   virtual ~PartSet_OperationEditLine();
62
63    /// Returns that this operator can be started above already running one.
64    /// The runned operation should be the sketch feature modified operation
65   virtual bool isGranted() const;
66
67   /// Returns the operation local selection mode
68   /// \param theFeature the feature object to get the selection mode
69   /// \return the selection mode
70   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
71
72   /// Initializes some fields accorging to the feature
73   /// \param theFeature the feature
74   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
75
76   /// Processes the mouse pressed in the point
77   /// \param thePoint a point clicked in the viewer
78   /// \param theEvent the mouse event
79   virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView);
80   /// Gives the current mouse point in the viewer
81   /// \param thePoint a point clicked in the viewer
82   /// \param theEvent the mouse event
83   /// \param theSelected the list of selected presentations
84   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView,
85                           const std::list<XGUI_ViewerPrs>& theSelected);
86   /// Gives the current selected objects to be processed by the operation
87   /// \param thePoint a point clicked in the viewer
88   /// \param theEvent the mouse event
89   /// \param theSelected the list of selected presentations
90  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
91                             const std::list<XGUI_ViewerPrs>& theSelected);
92 protected:
93   /// \brief Virtual method called when operation is started
94   /// Virtual method called when operation started (see start() method for more description)
95   /// Switch off the multi selection state
96   virtual void startOperation();
97
98   /// Virtual method called when operation stopped - committed or aborted.
99   /// Restore the multi selection state
100   virtual void stopOperation();
101
102   /// Creates an operation new feature
103   /// Returns NULL feature. This is an operation of edition, not creation.
104   /// \returns the created feature
105   virtual boost::shared_ptr<ModelAPI_Feature> createFeature();
106
107 protected:
108   /// \brief Save the point to the line.
109   /// \param theFeature the source feature
110   /// \param theDeltaX the delta for X coordinate is moved
111   /// \param theDeltaY the delta for Y coordinate is moved
112   /// \param theAttribute the start or end attribute of the line
113   void  moveLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
114                       double theDeltaX, double theDeltaY,
115                       const std::string& theAttribute);
116
117 private:
118   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
119   Point myCurPoint; ///< the current 3D point clicked or moved
120   gp_Pnt myCurPressed; ///< the current 3D point clicked or moved
121 };
122
123 #endif