1 // File: PartSet_OperationSketchLine.h
2 // Created: 20 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef PartSet_OperationSketchLine_H
6 #define PartSet_OperationSketchLine_H
10 #include <PartSet_OperationSketchBase.h>
13 class GeomDataAPI_Point2D;
17 \class PartSet_OperationSketchLine
18 * \brief The operation for the sketch feature creation
20 class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase
25 /// Returns the operation type key
26 static std::string Type() { return "SketchLine"; }
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);
36 virtual ~PartSet_OperationSketchLine();
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;
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;
47 /// Initializes some fields accorging to the feature
48 /// \param theFeature the feature
49 virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature);
51 /// Gives the current selected objects to be processed by the operation
52 /// \param thePoint a point clicked in the viewer
53 /// \param theEvent the mouse event
54 /// \param theSelected the list of selected presentations
55 virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
56 const std::list<XGUI_ViewerPrs>& theSelected);
57 /// Gives the current mouse point in the viewer
58 /// \param thePoint a point clicked in the viewer
59 /// \param theEvent the mouse event
60 /// \param theSelected the list of selected presentations
61 virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView,
62 const std::list<XGUI_ViewerPrs>& theSelected);
63 /// Processes the key pressed in the view
64 /// \param theKey a key value
65 virtual void keyReleased(const int theKey);
68 /// \brief Virtual method called when operation is started
69 /// Virtual method called when operation started (see start() method for more description)
70 /// After the parent operation body perform, set sketch feature to the created line feature
71 virtual void startOperation();
73 /// Virtual method called when operation aborted (see abort() method for more description)
74 /// Before the feature is aborted, it should be hidden from the viewer
75 virtual void abortOperation();
77 /// Virtual method called when operation stopped - committed or aborted.
78 /// Restore the multi selection state
79 virtual void stopOperation();
81 /// Creates an operation new feature
82 /// In addition to the default realization it appends the created line feature to
83 /// the sketch feature
84 /// \returns the created feature
85 virtual boost::shared_ptr<ModelAPI_Feature> createFeature();
87 /// Creates a constraint on two points
88 /// \param thePoint1 the first point
89 /// \param thePoint1 the second point
90 void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
91 boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
93 /// Creates constrains of the current
94 /// \param theX the horizontal coordnate of the point
95 /// \param theY the vertical coordnate of the point
96 void setConstraints(double theX, double theY);
98 /// \brief Get the line point 2d coordinates.
99 /// \param theFeature the line feature
100 /// \param theAttribute the start or end attribute of the line
101 /// \param theX the horizontal coordinate
102 /// \param theY the vertical coordinate
103 void getLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature, const std::string& theAttribute,
104 double& theX, double& theY);
105 /// Find a point in the line with given coordinates
106 /// \param theFeature the line feature
107 /// \param theX the horizontal point coordinate
108 /// \param theY the vertical point coordinate
109 boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
110 double theX, double theY);
112 /// \brief Save the point to the line.
113 /// \param theX the horizontal coordinate
114 /// \param theY the vertical coordinate
115 /// \param theAttribute the start or end attribute of the line
116 void setLinePoint(double theX, double theY, const std::string& theAttribute);
117 /// \brief Save the point to the line.
118 /// \param thePoint the 3D point in the viewer
119 /// \param theAttribute the start or end attribute of the line
120 void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
123 ///< Structure to lists the possible types of point selection modes
124 enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint};
127 boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
128 boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
129 PointSelectionMode myPointSelectionMode; ///< point selection mode