]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_OperationSketchLine.h
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 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   virtual bool isGranted() const;
41
42   /// Returns the operation local selection mode
43   /// \param theFeature the feature object to get the selection mode
44   /// \return the selection mode
45   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
46
47   /// Initializes some fields accorging to the feature
48   /// \param theFeature the feature
49   /// \param thePresentations the list of additional presentations
50   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
51                     const std::list<XGUI_ViewerPrs>& thePresentations);
52
53   /// Gives the current selected objects to be processed by the operation
54   /// \param thePoint a point clicked in the viewer
55   /// \param theEvent the mouse event
56   /// \param theSelected the list of selected presentations
57  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
58                              const std::list<XGUI_ViewerPrs>& theSelected);
59   /// Gives the current mouse point in the viewer
60   /// \param thePoint a point clicked in the viewer
61   /// \param theEvent the mouse event
62   /// \param theSelected the list of selected presentations
63   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView,
64                           const std::list<XGUI_ViewerPrs>& theSelected);
65   /// Processes the key pressed in the view
66   /// \param theKey a key value
67   virtual void keyReleased(const int theKey);
68
69 protected:
70   /// \brief Virtual method called when operation is started
71   /// Virtual method called when operation started (see start() method for more description)
72   /// After the parent operation body perform, set sketch feature to the created line feature
73   virtual void startOperation();
74
75   /// Virtual method called when operation aborted (see abort() method for more description)
76   /// Before the feature is aborted, it should be hidden from the viewer
77   virtual void abortOperation();
78
79   /// Virtual method called when operation stopped - committed or aborted.
80   /// Restore the multi selection state
81   virtual void stopOperation();
82
83   /// Creates an operation new feature
84   /// In addition to the default realization it appends the created line feature to
85   /// the sketch feature
86   /// \returns the created feature
87   virtual boost::shared_ptr<ModelAPI_Feature> createFeature();
88
89   /// Creates a constraint on two points
90   /// \param thePoint1 the first point
91   /// \param thePoint1 the second point
92   void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
93                         boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
94
95   /// Creates constrains of the current 
96   /// \param theX the horizontal coordnate of the point
97   /// \param theY the vertical coordnate of the point
98   void setConstraints(double theX, double theY);
99 protected:
100   /// \brief Get the line point 2d coordinates.
101   /// \param theFeature the line feature
102   /// \param theAttribute the start or end attribute of the line
103   /// \param theX the horizontal coordinate
104   /// \param theY the vertical coordinate
105   void getLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature, const std::string& theAttribute,
106                     double& theX, double& theY);
107   /// Find a point in the line with given coordinates
108   /// \param theFeature the line feature
109   /// \param theX the horizontal point coordinate
110   /// \param theY the vertical point coordinate
111   boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
112                                                        double theX, double theY);
113
114   /// \brief Save the point to the line.
115   /// \param theX the horizontal coordinate
116   /// \param theY the vertical coordinate
117   /// \param theAttribute the start or end attribute of the line
118   void setLinePoint(double theX, double theY, const std::string& theAttribute);
119   /// \brief Save the point to the line.
120   /// \param thePoint the 3D point in the viewer
121   /// \param theAttribute the start or end attribute of the line
122   void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
123
124 protected:
125   ///< Structure to lists the possible types of point selection modes
126   enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint};
127
128 private:
129   boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
130   boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
131   PointSelectionMode myPointSelectionMode; ///< point selection mode
132 };
133
134 #endif