1 // File: PartSet_Tools.h
2 // Created: 28 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef PartSet_Tools_H
6 #define PartSet_Tools_H
14 #include <ModelAPI_Feature.h>
16 #include <boost/shared_ptr.hpp>
20 class Handle_V3d_View;
22 class GeomDataAPI_Point2D;
23 class PartSet_FeaturePrs;
27 * \brief The operation for the sketch feature creation
29 class PARTSET_EXPORT PartSet_Tools
32 /// Converts the 2D screen point to the 3D point on the view according to the point of view
33 /// \param thePoint a screen point
34 /// \param theView a 3D view
35 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
37 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
38 /// \param thePoint the 3D point in the viewer
39 /// \param theSketch the sketch feature
40 /// \param theX the X coordinate
41 /// \param theY the Y coordinate
42 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
43 Handle(V3d_View) theView, double& theX, double& theY);
45 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
46 /// \param theX the X coordinate
47 /// \param theY the Y coordinate
48 /// \param theSketch the sketch feature
49 /// \param thePoint the 3D point in the viewer
50 static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
53 /// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3),
54 /// where vi - {xi,yi}. If the v0 is on the second line, the result is a projection of the v1 to this line
55 /// \param theX0 the horizontal coordinate of 0 point
56 /// \param theY0 the vertical coordinate of 0 point
57 /// \param theX1 the horizontal coordinate of 1 point
58 /// \param theY1 the vertical coordinate of 1 point
59 /// \param theX2 the horizontal coordinate of 2 point
60 /// \param theY2 the vertical coordinate of 2 point
61 /// \param theX3 the horizontal coordinate of 3 point
62 /// \param theY3 the vertical coordinate of 3 point
63 /// \param theX the output horizontal coordinate of the intersection point
64 /// \param theY the outpup vertical coordinate of the intersection point
65 static void intersectLines(double theX0, double theY0, double theX1, double theY1,
66 double theX2, double theY2, double theX3, double theY3,
67 double& theX, double& theY);
69 /// Returns the coordinates of projection of the point to the line
70 /// \param thePointX the projected point horizontal coordinate
71 /// \param thePointY the projected point vertictal coordinate
72 /// \param theX1 the horizontal coordinate of the first line point
73 /// \param theY1 the vertical coordinate of the first line point
74 /// \param theX2 the horizontal coordinate of the second line point
75 /// \param theY2 the vertical coordinate of the second line point
76 static void projectPointOnLine(double theX1, double theY1, double theX2, double theY2,
77 double thePointX, double thePointY, double& theX, double& theY);
79 /// Creates the feature presentation
80 /// \param theKind a feature kind
81 /// \param theSketch the sketch of the feature
82 /// \param theFeature the feature
83 static boost::shared_ptr<PartSet_FeaturePrs> createFeaturePrs(const std::string& theKind,
85 FeaturePtr theFeature = FeaturePtr());
88 /// Returns a feature that is under the mouse point
89 /// \param thePoint a screen point
90 /// \param theView a 3D view
91 /// \param theSketch the sketch feature
92 /// \param theFeatures the list of selected presentations
93 static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
94 const std::list<XGUI_ViewerPrs>& theFeatures);
96 /// Returns pointer to the root document.
97 static boost::shared_ptr<ModelAPI_Document> document();
99 /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
100 /// \param theFeature the feature
101 /// \param theX the horizontal coordinate
102 /// \param theY the vertical coordinate
103 /// \param theAttribute the feature attribute
104 static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
105 const std::string& theAttribute);
107 /// \brief Save the double to the feature. If the attribute is double, it is filled.
108 /// \param theFeature the feature
109 /// \param theValue the horizontal coordinate
110 /// \param theAttribute the feature attribute
111 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
113 /// Creates a constraint on two points
114 /// \param thePoint1 the first point
115 /// \param thePoint1 the second point
116 static void createConstraint(FeaturePtr theSketch,
117 boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
118 boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
120 /// Find a point in the line with given coordinates
121 /// \param theFeature the line feature
122 /// \param theX the horizontal point coordinate
123 /// \param theY the vertical point coordinate
124 static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
128 /// Return the distance between the feature and the point
129 /// \param theFeature feature object
130 /// \param theX the horizontal coordinate of the point
131 /// \param theX the vertical coordinate of the point
132 static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);