Salome HOME
Issue #251. Append Export/Import NewGeom commands in the SALOME desktop.
[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
18 #include <boost/shared_ptr.hpp>
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 class GeomAPI_Edge;
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 an object that is under the mouse point. Firstly it checks the highlighting,
58   /// if it exists, the first object is returned. Secondly, there is an iteration on
59   /// the selected list to find the point. Thirdly, if the object is not found under the
60   /// the point, the first selected object is returned.
61   /// \param thePoint a screen point
62   /// \param theView a 3D view
63   /// \param theSketch the sketch feature
64   /// \param theSelected the list of selected presentations
65   /// \param theHighlighted the list of highlighted presentations
66   static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
67                                   const QList<ModuleBase_ViewerPrs>& theSelected,
68                                   const QList<ModuleBase_ViewerPrs>& theHighlighted);
69
70   /// Returns pointer to the root document.
71   static boost::shared_ptr<ModelAPI_Document> document();
72
73
74   /// Returns a point attribute of the feature by the coordinates if it is
75   /// \param theFeature the feature
76   /// \param theX the horizontal coordinate
77   /// \param theY the vertical coordinate
78   static boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
79                                                                 double theX, double theY);
80
81   /// \brief Save the double to the feature. If the attribute is double, it is filled.
82   /// \param theFeature the feature
83   /// \param theValue the horizontal coordinate
84   /// \param theAttribute the feature attribute
85   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
86
87   /// \brief Returns the feature double value if it is.
88   /// \param theFeature the feature
89   /// \param theAttribute the feature attribute
90   /// \param isValid an output parameter whether the value is valid
91   /// \returns the feature value
92   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
93
94   /// Find a feature in the attribute of the given feature. If the kind is not empty,
95   /// the return feature should be this type. Otherwise it is null
96   /// \param theFeature a source feature
97   /// \param theAttribute a name of the requried attribute attribute
98   /// \param theKind an output feature kind
99   /// \return the feature
100   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
101                             const std::string& theKind);
102
103   /// Creates a constraint on two points
104   /// \param thePoint1 the first point
105   /// \param thePoint1 the second point
106   static void createConstraint(CompositeFeaturePtr theSketch,
107                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
108                                boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
109
110   /// Creates constrains of the current 
111   /// \param theSketch a sketch feature
112   /// \param theFeature a source feature
113   /// \param theAttribute a name of the requried attribute attribute
114   /// \param theClickedX the horizontal coordnate of the point
115   /// \param theClickedY the vertical coordnate of the point
116   static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
117                              const std::string& theAttribute, double theClickedX,
118                              double theClickedY);
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(CompositeFeaturePtr 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                                                 CompositeFeaturePtr 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   /// Creates a line (arc or circle) by given edge
137   /// Created line will have fixed constraint
138   /// \param theEdge - an edge
139   /// \return - result of created feature
140   static ResultPtr createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch);
141
142   /// Checks whether the list of selected presentations contains the given one
143   /// \param theSelected a list of presentations
144   /// \param thePrs a presentation to be found
145   /// \return - result of check, true if the list contains the prs
146   static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
147                                     const ModuleBase_ViewerPrs& thePrs);
148
149   /// Returns Result object if the given skietch contains external edge equal to the given
150   /// \param theSketch - the sketch feature
151   /// \param theEdge - the edge
152   /// \return result object with external edge if it is found
153   static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr<GeomAPI_Edge> theEdge);
154
155   /// Returns whether the selected presentation has a shape with the vertex type
156   /// \param thePrs a selected presentation
157   /// \param theSketch the sketch feature
158   /// \param theView a 3D view
159   /// \param theX the output horizontal coordinate of the point
160   /// \param theY the output vertical coordinate of the point
161   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
162                              Handle_V3d_View theView, double& theX, double& theY);
163 protected:
164   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
165   /// if it exists, the first object is returned. Secondly, there is an iteration on
166   /// the selected list to find the point. Thirdly, if the object is not found under the
167   /// the point, the first selected object is returned.
168   /// \param thePoint a screen point
169   /// \param theView a 3D view
170   /// \param theSketch the sketch feature
171   /// \param thePresentations the list of presentations
172   static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
173                                   const QList<ModuleBase_ViewerPrs>& thePresentations);
174
175 };
176
177 #endif