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());
87 /// Returns a feature that is under the mouse point
88 /// \param thePoint a screen point
89 /// \param theView a 3D view
90 /// \param theSketch the sketch feature
91 /// \param theFeatures the list of selected presentations
92 static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
93 const std::list<XGUI_ViewerPrs>& theFeatures);
95 /// \brief Move the feature.
96 /// \param theFeature the source feature
97 /// \param theDeltaX the delta for X coordinate is moved
98 /// \param theDeltaY the delta for Y coordinate is moved
99 static void moveFeature(FeaturePtr theFeature, double theDeltaX, double theDeltaY);
101 /// Returns pointer to the root document.
102 static boost::shared_ptr<ModelAPI_Document> document();
104 /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
105 /// \param theFeature the feature
106 /// \param theX the horizontal coordinate
107 /// \param theY the vertical coordinate
108 /// \param theAttribute the feature attribute
109 static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
110 const std::string& theAttribute);
112 /// \brief Save the double to the feature. If the attribute is double, it is filled.
113 /// \param theFeature the feature
114 /// \param theValue the horizontal coordinate
115 /// \param theAttribute the feature attribute
116 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
118 /// Creates a constraint on two points
119 /// \param thePoint1 the first point
120 /// \param thePoint1 the second point
121 static void createConstraint(FeaturePtr theSketch,
122 boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
123 boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
125 /// Find a point in the line with given coordinates
126 /// \param theFeature the line feature
127 /// \param theX the horizontal point coordinate
128 /// \param theY the vertical point coordinate
129 static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
133 /// Return the distance between the feature and the point
134 /// \param theFeature feature object
135 /// \param theX the horizontal coordinate of the point
136 /// \param theX the vertical coordinate of the point
137 static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);