Salome HOME
Create Presentation for rigid constraint
[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_CompositeFeature.h>
15
16 #include <boost/shared_ptr.hpp>
17
18 #include <list>
19
20 class Handle_V3d_View;
21 class ModuleBase_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,
46                           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   /// Returns a feature that is under the mouse point
57   /// \param thePoint a screen point
58   /// \param theView a 3D view
59   /// \param theSketch the sketch feature
60   /// \param theFeatures the list of selected presentations
61   static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
62                                    const std::list<ModuleBase_ViewerPrs>& theFeatures);
63
64   /// Returns pointer to the root document.
65   static boost::shared_ptr<ModelAPI_Document> document();
66
67   /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
68   /// \param theFeature the feature
69   /// \param theX the horizontal coordinate
70   /// \param theY the vertical coordinate
71   /// \param theAttribute the feature attribute
72   static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
73                               const std::string& theAttribute);
74
75   /// \brief Save the double to the feature. If the attribute is double, it is filled.
76   /// \param theFeature the feature
77   /// \param theValue the horizontal coordinate
78   /// \param theAttribute the feature attribute
79   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
80
81   /// \brief Returns the feature double value if it is.
82   /// \param theFeature the feature
83   /// \param theAttribute the feature attribute
84   /// \param isValid an output parameter whether the value is valid
85   /// \returns the feature value
86   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, 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(CompositeFeaturePtr 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(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
111                              const std::string& theAttribute, double theClickedX,
112                              double theClickedY);
113
114   /// Create a sketch plane instance
115   /// \param theSketch a sketch feature
116   /// \return API object of geom plane
117   static boost::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
118
119   /// Create a point 3D on a basis of point 2D and sketch feature
120   /// \param thePoint2D a point on a sketch
121   /// \param theSketch a sketch feature
122   /// \return API object of point 3D
123   static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
124                                                 CompositeFeaturePtr theSketch);
125   /// Check whether there is a constraint with the feature kind given
126   /// \param theKind a feature kind
127   /// \return the boolean value
128   static bool isConstraintFeature(const std::string& theKind);
129 };
130
131 #endif