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 /// Creates an operation new feature
101 /// In addition to the default realization it appends the created line feature to
102 /// the sketch feature
103 /// \param theFlushMessage the flag whether the create message should be flushed
104 /// \returns the created feature
105 virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
107 /// Creates a constraint on two points
108 /// \param thePoint1 the first point
109 /// \param thePoint1 the second point
110 void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
111 boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
113 /// Creates constrains of the current
114 /// \param theX the horizontal coordnate of the point
115 /// \param theY the vertical coordnate of the point
116 void setConstraints(double theX, double theY);
119 /// \brief Get the line point 2d coordinates.
120 /// \param theFeature the line feature
121 /// \param theAttribute the start or end attribute of the line
122 /// \param theX the horizontal coordinate
123 /// \param theY the vertical coordinate
124 void getLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature, const std::string& theAttribute,
125 double& theX, double& theY);
126 /// Find a point in the line with given coordinates
127 /// \param theFeature the line feature
128 /// \param theX the horizontal point coordinate
129 /// \param theY the vertical point coordinate
130 boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
131 double theX, double theY);
133 /// \brief Save the point to the line.
134 /// \param thePoint the 3D point in the viewer
135 /// \param theAttribute the start or end attribute of the line
136 void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
139 ///< Structure to lists the possible types of point selection modes
140 enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint};
142 ///< Set the point selection mode. Emit signal about focus change if necessary.
143 /// \param theMode a new selection mode
144 /// \param isToEmitSignal the neccessity to emit signal
145 void setPointSelectionMode(const PointSelectionMode& theMode, const bool isToEmitSignal = true);
148 boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
149 boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
150 PointSelectionMode myPointSelectionMode; ///< point selection mode