Salome HOME
3e07b82b8a510b0663c6c2f0d5591360e092c8d7
[modules/shaper.git] / src / PartSet / PartSet_OperationSketchLine.h
1 // File:        PartSet_OperationSketchLine.h
2 // Created:     20 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef PartSet_OperationSketchLine_H
6 #define PartSet_OperationSketchLine_H
7
8 #include "PartSet.h"
9
10 #include <PartSet_OperationSketchBase.h>
11 #include <QObject>
12
13 /*!
14  \class PartSet_OperationSketchLine
15  * \brief The operation for the sketch feature creation
16 */
17 class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase
18 {
19   Q_OBJECT
20 public:
21   /// Constructor
22   /// \param theId the feature identifier
23   /// \param theParent the operation parent
24   /// \param theFeature the parent feature
25   PartSet_OperationSketchLine(const QString& theId, QObject* theParent,
26                               boost::shared_ptr<ModelAPI_Feature> theSketchFeature);
27   /// Destructor
28   virtual ~PartSet_OperationSketchLine();
29
30    /// Returns that this operator can be started above already running one.
31    /// The runned operation should be the sketch feature modified operation
32   virtual bool isGranted() const;
33
34   /// Returns the operation local selection mode
35   /// \param theFeature the feature object to get the selection mode
36   /// \return the selection mode
37   virtual int getSelectionMode(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
38
39   /// Gives the current selected objects to be processed by the operation
40   /// \param thePoint a point clicked in the viewer
41   virtual void mouseReleased(const gp_Pnt& thePoint);
42   /// Gives the current mouse point in the viewer
43   /// \param thePoint a point clicked in the viewer
44   virtual void mouseMoved(const gp_Pnt& thePoint);
45
46 signals:
47   /// signal about the sketch plane is selected
48   /// \param theX the value in the X direction of the plane
49   /// \param theX the value in the Y direction value of the plane
50   /// \param theX the value in the Z direction of the plane
51   void localContextChanged(boost::shared_ptr<ModelAPI_Feature> theFeature,
52                            int theMode);
53
54 protected:
55   /// \brief Virtual method called when operation is started
56   /// Virtual method called when operation started (see start() method for more description)
57   /// After the parent operation body perform, set sketch feature to the created line feature
58   virtual void startOperation();
59
60   /// \brief Virtual method called when operation is started
61   /// Virtual method called when operation stopped - committed or aborted.
62   /// After the parent operation body perform, reset selection point mode of the operation
63   virtual void stopOperation();
64
65 protected:
66   /// \brief Save the point to the line.
67   /// \param thePoint the 3D point in the viewer
68   /// \param theAttribute the start or end attribute of the line
69   void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
70
71   /// \brief Set the point to the line by the point of the source line.
72   /// \param theSourceFeature the feature, where the point is obtained
73   /// \param theSourceAttribute the start or end attribute of the source line
74   /// \param theAttribute the start or end attribute of the line
75   void setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
76                                                const std::string& theSourceAttribute,
77                                                const std::string& theAttribute);
78   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
79   /// \param thePoint the 3D point in the viewer
80   /// \param theX the X coordinate
81   /// \param theY the Y coordinate
82   void convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY);
83
84 protected:
85   ///< Structure to lists the possible types of point selection modes
86   enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None};
87
88 private:
89   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
90   PointSelectionMode myPointSelectionMode; ///< point selection mode
91 };
92
93 #endif