Salome HOME
c847a1ad11f205dab6de36a0e1c5ae64f6afdef5
[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 <ModuleBase_ViewerPrs.h>
11 #include <gp_Pnt.hxx>
12
13 #include <QPoint>
14 #include <QList>
15
16 #include <ModelAPI_CompositeFeature.h>
17 #include <TopoDS_Edge.hxx>
18
19 #include <boost/shared_ptr.hpp>
20
21 class Handle_V3d_View;
22 class ModuleBase_ViewerPrs;
23 class GeomDataAPI_Point2D;
24 class GeomAPI_Pln;
25 class GeomAPI_Pnt2d;
26 class GeomAPI_Pnt;
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,
47                           double& theX, double& theY);
48
49   /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
50   /// \param theX the X coordinate
51   /// \param theY the Y coordinate
52   /// \param theSketch the sketch feature
53   /// \param thePoint the 3D point in the viewer
54   static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
55                           gp_Pnt& thePoint);
56
57   /// Returns a feature that is under the mouse point
58   /// \param thePoint a screen point
59   /// \param theView a 3D view
60   /// \param theSketch the sketch feature
61   /// \param theFeatures the list of selected presentations
62   static FeaturePtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
63                                    const QList<ModuleBase_ViewerPrs>& theFeatures);
64
65   /// Returns pointer to the root document.
66   static boost::shared_ptr<ModelAPI_Document> document();
67
68
69   /// Returns a point attribute of the feature by the coordinates if it is
70   /// \param theFeature the feature
71   /// \param theX the horizontal coordinate
72   /// \param theY the vertical coordinate
73   static boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
74                                                                 double theX, double theY);
75
76   /// \brief Save the double to the feature. If the attribute is double, it is filled.
77   /// \param theFeature the feature
78   /// \param theValue the horizontal coordinate
79   /// \param theAttribute the feature attribute
80   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
81
82   /// \brief Returns the feature double value if it is.
83   /// \param theFeature the feature
84   /// \param theAttribute the feature attribute
85   /// \param isValid an output parameter whether the value is valid
86   /// \returns the feature value
87   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
88
89   /// Find a feature in the attribute of the given feature. If the kind is not empty,
90   /// the return feature should be this type. Otherwise it is null
91   /// \param theFeature a source feature
92   /// \param theAttribute a name of the requried attribute attribute
93   /// \param theKind an output feature kind
94   /// \return the feature
95   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
96                             const std::string& theKind);
97
98   /// Creates a constraint on two points
99   /// \param thePoint1 the first point
100   /// \param thePoint1 the second point
101   static void createConstraint(CompositeFeaturePtr theSketch,
102                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
103                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
104
105   /// Creates constrains of the current 
106   /// \param theSketch a sketch feature
107   /// \param theFeature a source feature
108   /// \param theAttribute a name of the requried attribute attribute
109   /// \param theClickedX the horizontal coordnate of the point
110   /// \param theClickedY the vertical coordnate of the point
111   static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
112                              const std::string& theAttribute, double theClickedX,
113                              double theClickedY);
114
115   /// Create a sketch plane instance
116   /// \param theSketch a sketch feature
117   /// \return API object of geom plane
118   static boost::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
119
120   /// Create a point 3D on a basis of point 2D and sketch feature
121   /// \param thePoint2D a point on a sketch
122   /// \param theSketch a sketch feature
123   /// \return API object of point 3D
124   static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
125                                                 CompositeFeaturePtr theSketch);
126   /// Check whether there is a constraint with the feature kind given
127   /// \param theKind a feature kind
128   /// \return the boolean value
129   static bool isConstraintFeature(const std::string& theKind);
130
131   /// Creates a line (arc or circle) by given edge
132   /// Created line will have fixed constraint
133   /// \param theEdge - an edge
134   /// \return - result of created feature
135   static ResultPtr createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch);
136
137   /// Checks whether the list of selected presentations contains the given one
138   /// \param theSelected a list of presentations
139   /// \param thePrs a presentation to be found
140   /// \return - result of check, true if the list contains the prs
141   static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
142                                     const ModuleBase_ViewerPrs& thePrs);
143
144 };
145
146 #endif