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