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;
18 \class PartSet_OperationSketchLine
19 * \brief The operation for the sketch feature creation
21 class PARTSET_EXPORT PartSet_OperationSketchLine : public PartSet_OperationSketchBase
26 /// Returns the operation type key
27 static std::string Type() { return "SketchLine"; }
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);
37 virtual ~PartSet_OperationSketchLine();
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;
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;
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;
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);
60 /// Returns the operation sketch feature
61 /// \returns the sketch instance
62 virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
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);
80 virtual void keyReleased(std::string theName, QKeyEvent* theEvent);
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);
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();
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();
100 /// Virtual method called when operation stopped - committed or aborted.
101 /// Restore the multi selection state
102 virtual void stopOperation();
104 /// Virtual method called after operation committed (see commit() method for more description)
105 virtual void afterCommitOperation();
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);
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);
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);
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);
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);
146 ///< Structure to lists the possible types of point selection modes
147 enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint};
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);
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