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 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   /// Returns pointer to the root document.
73   static boost::shared_ptr<ModelAPI_Document> document();
74
75   /// \brief Save the point to the feature. If the attribute is 2D geometry point, it is filled.
76   /// \param theFeature the feature
77   /// \param theX the horizontal coordinate
78   /// \param theY the vertical coordinate
79   /// \param theAttribute the feature attribute
80   static void setFeaturePoint(FeaturePtr theFeature, double theX, double theY,
81                               const std::string& theAttribute);
82
83   /// \brief Save the double to the feature. If the attribute is double, it is filled.
84   /// \param theFeature the feature
85   /// \param theValue the horizontal coordinate
86   /// \param theAttribute the feature attribute
87   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
88
89   /// \brief Returns the feature double value if it is.
90   /// \param theFeature the feature
91   /// \param theAttribute the feature attribute
92   /// \param isValid an output parameter whether the value is valid
93   /// \returns the feature value
94   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute,
95                              bool& isValid);
96
97   /// Find a feature in the attribute of the given feature. If the kind is not empty,
98   /// the return feature should be this type. Otherwise it is null
99   /// \param theFeature a source feature
100   /// \param theAttribute a name of the requried attribute attribute
101   /// \param theKind an output feature kind
102   /// \return the feature
103   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
104                              const std::string& theKind);
105
106   /// Creates a constraint on two points
107   /// \param thePoint1 the first point
108   /// \param thePoint1 the second point
109   static void createConstraint(FeaturePtr theSketch,
110                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
111                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
112
113   /// Find a point in the line with given coordinates
114   /// \param theFeature the line feature
115   /// \param theX the horizontal point coordinate
116   /// \param theY the vertical point coordinate
117   static boost::shared_ptr<GeomDataAPI_Point2D> findPoint(FeaturePtr theFeature, double theX,
118                                                           double theY);
119
120   /// Create a sketch plane instance
121   /// \param theSketch a sketch feature
122   /// \return API object of geom plane
123   static boost::shared_ptr<GeomAPI_Pln> sketchPlane(FeaturePtr theSketch);
124
125   /// Create a point 3D on a basis of point 2D and sketch feature
126   /// \param thePoint2D a point on a sketch
127   /// \param theSketch a sketch feature
128   /// \return API object of point 3D
129   static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
130                                                 FeaturePtr theSketch);
131   /// Check whether there is a constraint with the feature kind given
132   /// \param theKind a feature kind
133   /// \return the boolean value
134   static bool isConstraintFeature(const std::string& theKind);
135 };
136
137 #endif