Salome HOME
refs #80 - Sketch base GUI: create/draw point, circle and arc
[modules/shaper.git] / src / PartSet / PartSet_Tools.h
1 // File:        PartSet_Tools.h
2 // Created:     28 Apr 2014
3 // Author:      Natalia ERMOLAEVA
4
5 #ifndef PartSet_Tools_H
6 #define PartSet_Tools_H
7
8 #include "PartSet.h"
9
10 #include <gp_Pnt.hxx>
11
12 #include <QPoint>
13
14 #include <ModelAPI_Feature.h>
15
16 #include <boost/shared_ptr.hpp>
17
18 #include <list>
19
20 class Handle_V3d_View;
21 class XGUI_ViewerPrs;
22 class GeomDataAPI_Point2D;
23
24 /*!
25  \class PartSet_Tools
26  * \brief The operation for the sketch feature creation
27 */
28 class PARTSET_EXPORT PartSet_Tools
29 {
30 public:
31   /// Converts the 2D screen point to the 3D point on the view according to the point of view
32   /// \param thePoint a screen point
33   /// \param theView a 3D view
34   static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
35
36   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
37   /// \param thePoint the 3D point in the viewer
38   /// \param theSketch the sketch feature
39   /// \param theX the X coordinate
40   /// \param theY the Y coordinate
41   static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
42                           Handle(V3d_View) theView, double& theX, double& theY);
43
44   /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
45   /// \param theX the X coordinate
46   /// \param theY the Y coordinate
47   /// \param theSketch the sketch feature
48   /// \param thePoint the 3D point in the viewer
49   static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
50                           gp_Pnt& thePoint);
51
52   /// Returns the point of intersection of the two lines, the first is (v0, v1), the second is (v2, v3),
53   /// where vi - {xi,yi}. If the v0 is on the second line, the result is a projection of the v1 to this line
54   /// \param theX0 the horizontal coordinate of 0 point
55   /// \param theY0 the vertical coordinate of 0 point
56   /// \param theX1 the horizontal coordinate of 1 point
57   /// \param theY1 the vertical coordinate of 1 point
58   /// \param theX2 the horizontal coordinate of 2 point
59   /// \param theY2 the vertical coordinate of 2 point
60   /// \param theX3 the horizontal coordinate of 3 point
61   /// \param theY3 the vertical coordinate of 3 point
62   /// \param theX the output horizontal coordinate of the intersection point
63   /// \param theY the outpup vertical coordinate of the intersection point
64   static void intersectLines(double theX0, double theY0, double theX1, double theY1,
65                              double theX2, double theY2, double theX3, double theY3,
66                              double& theX, double& theY);
67
68   /// Returns the coordinates of projection of the point to the line
69   /// \param thePointX the projected point horizontal coordinate
70   /// \param thePointY the projected point vertictal coordinate
71   /// \param theX1 the horizontal coordinate of the first line point
72   /// \param theY1 the vertical coordinate of the first line point
73   /// \param theX2 the horizontal coordinate of the second line point
74   /// \param theY2 the vertical coordinate of the second line point
75   static void projectPointOnLine(double theX1, double theY1, double theX2, double theY2,
76                                  double thePointX, double thePointY, double& theX, double& theY);
77
78   /// Returns a feature that is under the mouse point
79   /// \param thePoint a screen point
80   /// \param theView a 3D view
81   /// \param theSketch the sketch feature
82   /// \param theFeatures the list of selected presentations
83   static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
84                                    const std::list<XGUI_ViewerPrs>& theFeatures);
85
86   /// Returns pointer to the root document.
87   static boost::shared_ptr<ModelAPI_Document> document();
88
89   /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
90   /// \param theFeature the feature
91   /// \param theX the horizontal coordinate
92   /// \param theY the vertical coordinate
93   /// \param theAttribute the feature attribute
94   static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
95                               const std::string& theAttribute);
96
97   /// \brief Save the double to the feature. If the attribute is double, it is filled.
98   /// \param theFeature the feature
99   /// \param theValue the horizontal coordinate
100   /// \param theAttribute the feature attribute
101   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
102
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);
109
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   static void getLinePoint(FeaturePtr 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   static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
122                                                           double theY);
123
124 private:
125   /// Return the distance between the feature and the point
126   /// \param theFeature feature object
127   /// \param theX the horizontal coordinate of the point
128   /// \param theX the vertical coordinate of the point
129   static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
130 };
131
132 #endif