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