Salome HOME
refs #30 - Sketch base GUI: create, draw lines
[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 std::list<int> getSelectionModes(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   /// Processes the key pressed in the view
46   /// \param theKey a key value
47   virtual void keyReleased(const int theKey);
48
49 signals:
50   /// signal about the sketch plane is selected
51   /// \param theX the value in the X direction of the plane
52   /// \param theX the value in the Y direction value of the plane
53   /// \param theX the value in the Z direction of the plane
54   void localContextChanged(boost::shared_ptr<ModelAPI_Feature> theFeature,
55                            int theMode);
56
57 protected:
58   /// \brief Virtual method called when operation is started
59   /// Virtual method called when operation started (see start() method for more description)
60   /// After the parent operation body perform, set sketch feature to the created line feature
61   virtual void startOperation();
62
63   /// \brief Virtual method called when operation is started
64   /// Virtual method called when operation stopped - committed or aborted.
65   /// After the parent operation body perform, reset selection point mode of the operation
66   virtual void stopOperation();
67
68   /// Creates an operation new feature
69   /// In addition to the default realization it appends the created line feature to
70   /// the sketch feature
71   /// \returns the created feature
72   virtual boost::shared_ptr<ModelAPI_Feature> createFeature();
73
74 protected:
75   /// \brief Save the point to the line.
76   /// \param thePoint the 3D point in the viewer
77   /// \param theAttribute the start or end attribute of the line
78   void setLinePoint(const gp_Pnt& thePoint, const std::string& theAttribute);
79
80   /// \brief Set the point to the line by the point of the source line.
81   /// \param theSourceFeature the feature, where the point is obtained
82   /// \param theSourceAttribute the start or end attribute of the source line
83   /// \param theAttribute the start or end attribute of the line
84   void setLinePoint(boost::shared_ptr<ModelAPI_Feature> theSourceFeature,
85                                                const std::string& theSourceAttribute,
86                                                const std::string& theAttribute);
87   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
88   /// \param thePoint the 3D point in the viewer
89   /// \param theX the X coordinate
90   /// \param theY the Y coordinate
91   void convertTo2D(const gp_Pnt& thePoint, double& theX, double& theY);
92
93 protected:
94   ///< Structure to lists the possible types of point selection modes
95   enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_None};
96
97 private:
98   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
99   PointSelectionMode myPointSelectionMode; ///< point selection mode
100 };
101
102 #endif