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 /// \param theOperation the previous running operation
41 virtual bool isGranted(ModuleBase_IOperation* theOperation) const;
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;
48 /// Initializes some fields accorging to the feature
49 /// \param theSelected the list of selected presentations
50 /// \param theHighlighted the list of highlighted presentations
51 virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
52 const std::list<XGUI_ViewerPrs>& theSelected,
53 const std::list<XGUI_ViewerPrs>& theHighlighted);
55 /// Returns the operation sketch feature
56 /// \returns the sketch instance
57 virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
59 /// Gives the current selected objects to be processed by the operation
60 /// \param theEvent the mouse event
61 /// \param theView a viewer to have the viewer the eye position
62 /// \param theSelected the list of selected presentations
63 /// \param theHighlighted the list of highlighted presentations
64 virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
65 const std::list<XGUI_ViewerPrs>& theSelected,
66 const std::list<XGUI_ViewerPrs>& theHighlighted);
67 /// Gives the current mouse point in the viewer
68 /// \param thePoint a point clicked in the viewer
69 /// \param theEvent the mouse event
70 virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
71 /// Processes the key pressed in the view
72 /// \param theKey a key value
73 virtual void keyReleased(const int theKey);
76 /// \brief Virtual method called when operation is started
77 /// Virtual method called when operation started (see start() method for more description)
78 /// After the parent operation body perform, set sketch feature to the created line feature
79 virtual void startOperation();
81 /// Virtual method called when operation aborted (see abort() method for more description)
82 /// Before the feature is aborted, it should be hidden from the viewer
83 virtual void abortOperation();
85 /// Virtual method called when operation stopped - committed or aborted.
86 /// Restore the multi selection state
87 virtual void stopOperation();
89 /// Creates an operation new feature
90 /// In addition to the default realization it appends the created line feature to
91 /// the sketch feature
92 /// \param theFlushMessage the flag whether the create message should be flushed
93 /// \returns the created feature
94 virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
96 /// Creates a constraint on two points
97 /// \param thePoint1 the first point
98 /// \param thePoint1 the second point
99 void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
100 boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
102 /// Creates constrains of the current
103 /// \param theX the horizontal coordnate of the point
104 /// \param theY the vertical coordnate of the point
105 void setConstraints(double theX, double theY);
107 /// \brief Get the line point 2d coordinates.
108 /// \param theFeature the line feature
109 /// \param theAttribute the start or end attribute of the line
110 /// \param theX the horizontal coordinate
111 /// \param theY the vertical coordinate
112 void getLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature, const std::string& theAttribute,
113 double& theX, double& theY);
114 /// Find a point in the line with given coordinates
115 /// \param theFeature the line feature
116 /// \param theX the horizontal point coordinate
117 /// \param theY the vertical point coordinate
118 boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
119 double theX, double theY);
121 /// \brief Save the point to the line.
122 /// \param theFeature the line feature
123 /// \param theX the horizontal coordinate
124 /// \param theY the vertical coordinate
125 /// \param theAttribute the start or end attribute of the line
126 void setLinePoint(boost::shared_ptr<ModelAPI_Feature>, double theX, double theY,
127 const std::string& theAttribute);
128 /// \brief Save the point to the line.
129 /// \param thePoint the 3D point in the viewer
130 /// \param theAttribute the start or end attribute of the line
131 void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
134 ///< Structure to lists the possible types of point selection modes
135 enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint};
138 boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
139 boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
140 PointSelectionMode myPointSelectionMode; ///< point selection mode