]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Tools.h
Salome HOME
Merge branch 'master' of newgeom:newgeom
[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 #include <QList>
14
15 #include <ModelAPI_CompositeFeature.h>
16
17 #include <boost/shared_ptr.hpp>
18
19 class Handle_V3d_View;
20 class ModuleBase_ViewerPrs;
21 class GeomDataAPI_Point2D;
22 class GeomAPI_Pln;
23 class GeomAPI_Pnt2d;
24 class GeomAPI_Pnt;
25
26 /*!
27  \class PartSet_Tools
28  * \brief The operation for the sketch feature creation
29  */
30 class PARTSET_EXPORT PartSet_Tools
31 {
32  public:
33   /// Converts the 2D screen point to the 3D point on the view according to the point of view
34   /// \param thePoint a screen point
35   /// \param theView a 3D view
36   static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
37
38   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
39   /// \param thePoint the 3D point in the viewer
40   /// \param theSketch the sketch feature
41   /// \param theX the X coordinate
42   /// \param theY the Y coordinate
43   static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
44   Handle(V3d_View) theView,
45                           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 QList<ModuleBase_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, bool& isValid);
86
87   /// Find a feature in the attribute of the given feature. If the kind is not empty,
88   /// the return feature should be this type. Otherwise it is null
89   /// \param theFeature a source feature
90   /// \param theAttribute a name of the requried attribute attribute
91   /// \param theKind an output feature kind
92   /// \return the feature
93   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
94                             const std::string& theKind);
95
96   /// Creates a constraint on two points
97   /// \param thePoint1 the first point
98   /// \param thePoint1 the second point
99   static void createConstraint(CompositeFeaturePtr theSketch,
100                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
101                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
102
103   /// Creates constrains of the current 
104   /// \param theSketch a sketch feature
105   /// \param theFeature a source feature
106   /// \param theAttribute a name of the requried attribute attribute
107   /// \param theClickedX the horizontal coordnate of the point
108   /// \param theClickedY the vertical coordnate of the point
109   static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
110                              const std::string& theAttribute, double theClickedX,
111                              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(CompositeFeaturePtr 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                                                 CompositeFeaturePtr 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