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