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 /// 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;
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;
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);
56 /// Returns the operation sketch feature
57 /// \returns the sketch instance
58 virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
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);
76 virtual void keyReleased(std::string theName, QKeyEvent* theEvent);
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);
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();
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();
96 /// Virtual method called when operation stopped - committed or aborted.
97 /// Restore the multi selection state
98 virtual void stopOperation();
100 /// Virtual method called after operation committed (see commit() method for more description)
101 virtual void afterCommitOperation();
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);
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);
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);
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);
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);
142 ///< Structure to lists the possible types of point selection modes
143 enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint};
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);
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