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);
79 /// \brief Virtual method called when operation is started
80 /// Virtual method called when operation started (see start() method for more description)
81 /// After the parent operation body perform, set sketch feature to the created line feature
82 virtual void startOperation();
84 /// Virtual method called when operation aborted (see abort() method for more description)
85 /// Before the feature is aborted, it should be hidden from the viewer
86 virtual void abortOperation();
88 /// Virtual method called when operation stopped - committed or aborted.
89 /// Restore the multi selection state
90 virtual void stopOperation();
92 /// Creates an operation new feature
93 /// In addition to the default realization it appends the created line feature to
94 /// the sketch feature
95 /// \param theFlushMessage the flag whether the create message should be flushed
96 /// \returns the created feature
97 virtual boost::shared_ptr<ModelAPI_Feature> createFeature(const bool theFlushMessage = true);
99 /// Creates a constraint on two points
100 /// \param thePoint1 the first point
101 /// \param thePoint1 the second point
102 void createConstraint(boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
103 boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
105 /// Creates constrains of the current
106 /// \param theX the horizontal coordnate of the point
107 /// \param theY the vertical coordnate of the point
108 void setConstraints(double theX, double theY);
110 /// \brief Get the line point 2d coordinates.
111 /// \param theFeature the line feature
112 /// \param theAttribute the start or end attribute of the line
113 /// \param theX the horizontal coordinate
114 /// \param theY the vertical coordinate
115 void getLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature, const std::string& theAttribute,
116 double& theX, double& theY);
117 /// Find a point in the line with given coordinates
118 /// \param theFeature the line feature
119 /// \param theX the horizontal point coordinate
120 /// \param theY the vertical point coordinate
121 boost::shared_ptr<GeomDataAPI_Point2D> findLinePoint(boost::shared_ptr<ModelAPI_Feature> theFeature,
122 double theX, double theY);
124 /// \brief Save the point to the line.
125 /// \param theFeature the line feature
126 /// \param theX the horizontal coordinate
127 /// \param theY the vertical coordinate
128 /// \param theAttribute the start or end attribute of the line
129 void setLinePoint(boost::shared_ptr<ModelAPI_Feature>, double theX, double theY,
130 const std::string& theAttribute);
131 /// \brief Save the point to the line.
132 /// \param thePoint the 3D point in the viewer
133 /// \param theAttribute the start or end attribute of the line
134 void setLinePoint(const gp_Pnt& thePoint, Handle(V3d_View) theView, const std::string& theAttribute);
137 ///< Structure to lists the possible types of point selection modes
138 enum PointSelectionMode {SM_FirstPoint, SM_SecondPoint, SM_DonePoint};
140 ///< Set the point selection mode. Emit signal about focus change if necessary.
141 /// \param theMode a new selection mode
142 /// \param isToEmitSignal the neccessity to emit signal
143 void setPointSelectionMode(const PointSelectionMode& theMode, const bool isToEmitSignal = true);
146 boost::shared_ptr<ModelAPI_Feature> mySketch; ///< the sketch feature
147 boost::shared_ptr<GeomDataAPI_Point2D> myInitPoint; ///< the first line point
148 PointSelectionMode myPointSelectionMode; ///< point selection mode