Salome HOME
Processing of "Validators" in XML
[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
27 /*!
28  \class PartSet_Tools
29  * \brief The operation for the sketch feature creation
30 */
31 class PARTSET_EXPORT PartSet_Tools
32 {
33 public:
34   /// Converts the 2D screen point to the 3D point on the view according to the point of view
35   /// \param thePoint a screen point
36   /// \param theView a 3D view
37   static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
38
39   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
40   /// \param thePoint the 3D point in the viewer
41   /// \param theSketch the sketch feature
42   /// \param theX the X coordinate
43   /// \param theY the Y coordinate
44   static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
45                           Handle(V3d_View) theView, double& theX, double& theY);
46
47   /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
48   /// \param theX the X coordinate
49   /// \param theY the Y coordinate
50   /// \param theSketch the sketch feature
51   /// \param thePoint the 3D point in the viewer
52   static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
53                           gp_Pnt& thePoint);
54
55   /// Returns a feature that is under the mouse point
56   /// \param thePoint a screen point
57   /// \param theView a 3D view
58   /// \param theSketch the sketch feature
59   /// \param theFeatures the list of selected presentations
60   static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
61                                    const std::list<XGUI_ViewerPrs>& theFeatures);
62
63   /// Returns pointer to the root document.
64   static boost::shared_ptr<ModelAPI_Document> document();
65
66   /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
67   /// \param theFeature the feature
68   /// \param theX the horizontal coordinate
69   /// \param theY the vertical coordinate
70   /// \param theAttribute the feature attribute
71   static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
72                               const std::string& theAttribute);
73
74   /// \brief Save the double to the feature. If the attribute is double, it is filled.
75   /// \param theFeature the feature
76   /// \param theValue the horizontal coordinate
77   /// \param theAttribute the feature attribute
78   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
79
80   /// \brief Returns the feature double value if it is.
81   /// \param theFeature the feature
82   /// \param theAttribute the feature attribute
83   /// \param isValid an output parameter whether the value is valid
84   /// \returns the feature value
85   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute,
86                              bool& isValid);
87
88   /// Find a feature in the attribute of the given feature. If the kind is not empty,
89   /// the return feature should be this type. Otherwise it is null
90   /// \param theFeature a source feature
91   /// \param theAttribute a name of the requried attribute attribute
92   /// \param theKind an output feature kind
93   /// \return the feature
94   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
95                              const std::string& theKind);
96
97   /// Creates a constraint on two points
98   /// \param thePoint1 the first point
99   /// \param thePoint1 the second point
100   static void createConstraint(FeaturePtr theSketch,
101                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
102                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
103
104   /// Creates constrains of the current 
105   /// \param theSketch a sketch feature
106   /// \param theFeature a source feature
107   /// \param theAttribute a name of the requried attribute attribute
108   /// \param theClickedX the horizontal coordnate of the point
109   /// \param theClickedY the vertical coordnate of the point
110   static void setConstraints(FeaturePtr theSketch, FeaturePtr theFeature,
111                              const std::string& theAttribute, double theClickedX, double theClickedY);
112
113   /// Create a sketch plane instance
114   /// \param theSketch a sketch feature
115   /// \return API object of geom plane
116   static boost::shared_ptr<GeomAPI_Pln> sketchPlane(FeaturePtr theSketch);
117
118   /// Create a point 3D on a basis of point 2D and sketch feature
119   /// \param thePoint2D a point on a sketch
120   /// \param theSketch a sketch feature
121   /// \return API object of point 3D
122   static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
123                                                 FeaturePtr theSketch);
124   /// Check whether there is a constraint with the feature kind given
125   /// \param theKind a feature kind
126   /// \return the boolean value
127   static bool isConstraintFeature(const std::string& theKind);
128 };
129
130 #endif