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;
26 class PartSet_FeaturePrs;
30 * \brief The operation for the sketch feature creation
32 class PARTSET_EXPORT PartSet_Tools
35 /// Converts the 2D screen point to the 3D point on the view according to the point of view
36 /// \param thePoint a screen point
37 /// \param theView a 3D view
38 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
40 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
41 /// \param thePoint the 3D point in the viewer
42 /// \param theSketch the sketch feature
43 /// \param theX the X coordinate
44 /// \param theY the Y coordinate
45 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
46 Handle(V3d_View) theView, double& theX, double& theY);
48 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
49 /// \param theX the X coordinate
50 /// \param theY the Y coordinate
51 /// \param theSketch the sketch feature
52 /// \param thePoint the 3D point in the viewer
53 static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
56 /// Creates the feature presentation
57 /// \param theKind a feature kind
58 /// \param theSketch the sketch of the feature
59 /// \param theFeature the feature
60 static boost::shared_ptr<PartSet_FeaturePrs> createFeaturePrs(const std::string& theKind,
62 FeaturePtr theFeature = FeaturePtr());
64 /// Returns a feature that is under the mouse point
65 /// \param thePoint a screen point
66 /// \param theView a 3D view
67 /// \param theSketch the sketch feature
68 /// \param theFeatures the list of selected presentations
69 static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
70 const std::list<XGUI_ViewerPrs>& theFeatures);
72 /// \brief Move the feature.
73 /// \param theFeature the source feature
74 /// \param theDeltaX the delta for X coordinate is moved
75 /// \param theDeltaY the delta for Y coordinate is moved
76 static void moveFeature(FeaturePtr theFeature, double theDeltaX, double theDeltaY);
78 /// Returns pointer to the root document.
79 static boost::shared_ptr<ModelAPI_Document> document();
81 /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
82 /// \param theFeature the feature
83 /// \param theX the horizontal coordinate
84 /// \param theY the vertical coordinate
85 /// \param theAttribute the feature attribute
86 static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
87 const std::string& theAttribute);
89 /// \brief Save the double to the feature. If the attribute is double, it is filled.
90 /// \param theFeature the feature
91 /// \param theValue the horizontal coordinate
92 /// \param theAttribute the feature attribute
93 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
95 /// \brief Returns the feature double value if it is.
96 /// \param theFeature the feature
97 /// \param theAttribute the feature attribute
98 /// \param isValid an output parameter whether the value is valid
99 /// \returns the feature value
100 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute,
103 /// Creates a constraint on two points
104 /// \param thePoint1 the first point
105 /// \param thePoint1 the second point
106 static void createConstraint(FeaturePtr theSketch,
107 boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
108 boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
110 /// Find a point in the line with given coordinates
111 /// \param theFeature the line feature
112 /// \param theX the horizontal point coordinate
113 /// \param theY the vertical point coordinate
114 static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
117 /// Create a sketch plane instance
118 /// \param theSketch a sketch feature
119 /// \return API object of geom plane
120 static boost::shared_ptr<GeomAPI_Pln> sketchPlane(FeaturePtr theSketch);
122 /// Create a point 3D on a basis of point 2D and sketch feature
123 /// \param thePoint2D a point on a sketch
124 /// \param theSketch a sketch feature
125 /// \return API object of point 3D
126 static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
127 FeaturePtr theSketch);
128 /// Check whether there is a constraint with the feature kind given
129 /// \param theKind a feature kind
130 /// \return the boolean value
131 static bool isConstraintFeature(const std::string& theKind);
134 /// Return the distance between the feature and the point
135 /// \param theFeature feature object
136 /// \param theX the horizontal coordinate of the point
137 /// \param theX the vertical coordinate of the point
138 static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);