Salome HOME
d43feb7bfc329a18620783226076a6bc78336fcd
[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 class GeomAPI_Pln;
24 class GeomAPI_Pnt2d;
25 class GeomAPI_Pnt;
26 class PartSet_FeaturePrs;
27
28 /*!
29  \class PartSet_Tools
30  * \brief The operation for the sketch feature creation
31 */
32 class PARTSET_EXPORT PartSet_Tools
33 {
34 public:
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);
39
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);
47
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,
54                           gp_Pnt& thePoint);
55
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,
61                                                                 FeaturePtr theSketch,
62                                                                 FeaturePtr theFeature = FeaturePtr());
63
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);
71
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);
77
78   /// Returns pointer to the root document.
79   static boost::shared_ptr<ModelAPI_Document> document();
80
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);
88
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);
94
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,
101                              bool& isValid);
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   /// 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,
115                                                           double theY);
116
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);
121
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 private:
129   /// Return the distance between the feature and the point
130   /// \param theFeature feature object
131   /// \param theX the horizontal coordinate of the point
132   /// \param theX the vertical coordinate of the point
133   static double distanceToPoint(FeaturePtr theFeature, double theX, double theY);
134 };
135
136 #endif