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