Salome HOME
Replace boost::shared_ptr<ModelAPI_Feature> on FeaturePtr
[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
12 #include <SketchPlugin_Line.h>
13
14 #include <QObject>
15
16 class GeomDataAPI_Point2D;
17 class QMouseEvent;
18 class QKeyEvent;
19
20 /*!
21  \class PartSet_OperationSketchLine
22  * \brief The operation for the sketch feature creation
23 */
24 class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase
25 {
26   Q_OBJECT
27
28 public:
29   /// Returns the operation type key
30   static std::string Type() { return SKETCH_LINE_KIND; }
31
32 public:
33   /// Constructor
34   /// \param theId the feature identifier
35   /// \param theParent the operation parent
36   /// \param theFeature the parent feature
37   PartSet_OperationSketchLine(const QString& theId, QObject* theParent,
38                               FeaturePtr theSketchFeature);
39   /// Destructor
40   virtual ~PartSet_OperationSketchLine();
41
42   /// Verifies whether this operator can be commited.
43   /// \return Returns TRUE if current operation can be committed, e.g. all parameters are filled
44   virtual bool canBeCommitted() const;
45
46   /// Returns that this operator can be started above already running one.
47    /// The runned operation should be the sketch feature modified operation
48   /// \param theOperation the previous running operation
49   virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
50
51   /// Returns the operation local selection mode
52   /// \param theFeature the feature object to get the selection mode
53   /// \return the selection mode
54   virtual std::list<int> getSelectionModes(FeaturePtr theFeature) const;
55
56   /// Initializes some fields accorging to the feature
57   /// \param theSelected the list of selected presentations
58   /// \param theHighlighted the list of highlighted presentations
59   virtual void init(FeaturePtr theFeature,
60                     const std::list<XGUI_ViewerPrs>& theSelected,
61                     const std::list<XGUI_ViewerPrs>& theHighlighted);
62
63   /// Returns the operation sketch feature
64   /// \returns the sketch instance
65   virtual FeaturePtr sketch() const;
66
67   /// Gives the current selected objects to be processed by the operation
68   /// \param theEvent the mouse event
69   /// \param theView a viewer to have the viewer the eye position
70   /// \param theSelected the list of selected presentations
71   /// \param theHighlighted the list of highlighted presentations
72  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
73                             const std::list<XGUI_ViewerPrs>& theSelected,
74                             const std::list<XGUI_ViewerPrs>& theHighlighted);
75   /// Gives the current mouse point in the viewer
76   /// \param thePoint a point clicked in the viewer
77   /// \param theEvent the mouse event
78   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
79   /// Processes the key pressed in the view
80   /// \param theKey a key value
81   virtual void keyReleased(const int theKey);
82
83   virtual void keyReleased(std::string theName, QKeyEvent* theEvent);
84
85   /// \brief Save the point to the line.
86   /// \param theFeature the line feature
87   /// \param theX the horizontal coordinate
88   /// \param theY the vertical coordinate
89   /// \param theAttribute the start or end attribute of the line
90   static void setLinePoint(FeaturePtr, double theX, double theY,
91                            const std::string& theAttribute);
92
93 protected:
94   /// \brief Virtual method called when operation is started
95   /// Virtual method called when operation started (see start() method for more description)
96   /// After the parent operation body perform, set sketch feature to the created line feature
97   virtual void startOperation();
98
99   /// Virtual method called when operation aborted (see abort() method for more description)
100   /// Before the feature is aborted, it should be hidden from the viewer
101   virtual void abortOperation();
102
103   /// Virtual method called when operation stopped - committed or aborted.
104   /// Restore the multi selection state
105   virtual void stopOperation();
106
107   /// Virtual method called after operation committed (see commit() method for more description)
108   virtual void afterCommitOperation();
109
110   /// Creates an operation new feature
111   /// In addition to the default realization it appends the created line feature to
112   /// the sketch feature
113   /// \param theFlushMessage the flag whether the create message should be flushed
114   /// \returns the created feature
115   virtual FeaturePtr createFeature(const bool theFlushMessage = true);
116
117   /// Creates a constraint on two points
118   /// \param thePoint1 the first point
119   /// \param thePoint1 the second point
120   void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
121                         boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
122
123   /// Creates constrains of the current 
124   /// \param theX the horizontal coordnate of the point
125   /// \param theY the vertical coordnate of the point
126   void setConstraints(double theX, double theY);
127
128 protected:
129   /// \brief Get the line point 2d coordinates.
130   /// \param theFeature the line feature
131   /// \param theAttribute the start or end attribute of the line
132   /// \param theX the horizontal coordinate
133   /// \param theY the vertical coordinate
134   void getLinePoint(FeaturePtr theFeature, const std::string& theAttribute,
135                     double& theX, double& theY);
136   /// Find a point in the line with given coordinates
137   /// \param theFeature the line feature
138   /// \param theX the horizontal point coordinate
139   /// \param theY the vertical point coordinate
140   boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(FeaturePtr theFeature,
141                                                        double theX, double theY);
142
143   /// \brief Save the point to the line.
144   /// \param thePoint the 3D point in the viewer
145   /// \param theAttribute the start or end attribute of the line
146   void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
147
148 protected:
149   ///< Structure to lists the possible types of point selection modes
150   enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint};
151
152   ///< Set the point selection mode. Emit signal about focus change if necessary.
153   /// \param theMode a new selection mode
154   /// \param isToEmitSignal the neccessity to emit signal
155   void setPointSelectionMode(const PointSelectionMode& theMode, const bool isToEmitSignal = true);
156
157 private:
158   FeaturePtr mySketch; ///< the sketch feature
159   boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
160   PointSelectionMode myPointSelectionMode; ///< point selection mode
161 };
162
163 #endif