]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Tools.h
Salome HOME
Merge branch 'Dev_0.6' of newgeom:newgeom into Dev_0.6
[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 <ModelAPI_Object.h>
18 #include <ModelAPI_Attribute.h>
19
20 #include <TopoDS_Shape.hxx>
21
22 #include <memory>
23
24 class Handle_V3d_View;
25 class ModuleBase_ViewerPrs;
26 class GeomDataAPI_Point2D;
27 class GeomAPI_Pln;
28 class GeomAPI_Pnt2d;
29 class GeomAPI_Pnt;
30 class GeomAPI_Edge;
31
32 /*!
33  \class PartSet_Tools
34  * \brief The operation for the sketch feature creation
35  */
36 class PARTSET_EXPORT PartSet_Tools
37 {
38  public:
39   /// Converts the 2D screen point to the 3D point on the view according to the point of view
40   /// \param thePoint a screen point
41   /// \param theView a 3D view
42   // Transferred to ModuleBase
43   static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
44
45   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
46   /// \param thePoint the 3D point in the viewer
47   /// \param theSketch the sketch feature
48   /// \param theX the X coordinate
49   /// \param theY the Y coordinate
50   static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
51                           Handle(V3d_View) theView,
52                           double& theX, double& theY);
53
54   /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
55   /// \param theX the X coordinate
56   /// \param theY the Y coordinate
57   /// \param theSketch the sketch feature
58   /// \param thePoint the 3D point in the viewer
59   static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
60
61   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
62   /// if it exists, the first object is returned. Secondly, there is an iteration on
63   /// the selected list to find the point. Thirdly, if the object is not found under the
64   /// the point, the first selected object is returned.
65   /// \param thePoint a screen point
66   /// \param theView a 3D view
67   /// \param theSketch the sketch feature
68   /// \param theSelected the list of selected presentations
69   /// \param theHighlighted the list of highlighted presentations
70   static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
71                                   const QList<ModuleBase_ViewerPrs>& theSelected,
72                                   const QList<ModuleBase_ViewerPrs>& theHighlighted);
73
74   /// Returns pointer to the root document.
75   static std::shared_ptr<ModelAPI_Document> document();
76
77
78   /// Returns a point attribute of the feature by the coordinates if it is
79   /// \param theFeature the feature
80   /// \param theX the horizontal coordinate
81   /// \param theY the vertical coordinate
82   static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
83                                                                 double theX, double theY);
84
85   /// \brief Save the double to the feature. If the attribute is double, it is filled.
86   /// \param theFeature the feature
87   /// \param theValue the horizontal coordinate
88   /// \param theAttribute the feature attribute
89   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
90
91   /// \brief Returns the feature double value if it is.
92   /// \param theFeature the feature
93   /// \param theAttribute the feature attribute
94   /// \param isValid an output parameter whether the value is valid
95   /// \returns the feature value
96   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
97
98   /// Find a feature in the attribute of the given feature. If the kind is not empty,
99   /// the return feature should be this type. Otherwise it is null
100   /// \param theFeature a source feature
101   /// \param theAttribute a name of the requried attribute attribute
102   /// \param theKind an output feature kind
103   /// \return the feature
104   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
105                             const std::string& theKind);
106
107   /// Creates a constraint on two points
108   /// \param thePoint1 the first point
109   /// \param thePoint1 the second point
110   static void createConstraint(CompositeFeaturePtr theSketch,
111                                std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
112                                std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
113
114   /// Creates constrains of the current 
115   /// \param theSketch a sketch feature
116   /// \param theFeature a source feature
117   /// \param theAttribute a name of the requried attribute attribute
118   /// \param theClickedX the horizontal coordnate of the point
119   /// \param theClickedY the vertical coordnate of the point
120   static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
121                              const std::string& theAttribute, double theClickedX,
122                              double theClickedY);
123
124   /// Create a sketch plane instance
125   /// \param theSketch a sketch feature
126   /// \return API object of geom plane
127   static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
128
129   /// Create a point 3D on a basis of point 2D and sketch feature
130   /// \param thePoint2D a point on a sketch
131   /// \param theSketch a sketch feature
132   /// \return API object of point 3D
133   static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
134                                                 CompositeFeaturePtr theSketch);
135   /// Check whether there is a constraint with the feature kind given
136   /// \param theKind a feature kind
137   /// \return the boolean value
138   static bool isConstraintFeature(const std::string& theKind);
139
140   /// Creates a line (arc or circle) by given edge
141   /// Created line will have fixed constraint
142   /// \param theEdge - an edge
143   /// \return - result of created feature
144   static ResultPtr createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch);
145
146   /// Checks whether the list of selected presentations contains the given one
147   /// \param theSelected a list of presentations
148   /// \param thePrs a presentation to be found
149   /// \return - result of check, true if the list contains the prs
150   static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
151                                     const ModuleBase_ViewerPrs& thePrs);
152
153   /// Returns Result object if the given skietch contains external edge equal to the given
154   /// \param theSketch - the sketch feature
155   /// \param theEdge - the edge
156   /// \return result object with external edge if it is found
157   static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
158
159   /// Returns whether the selected presentation has a shape with the vertex type
160   /// \param thePrs a selected presentation
161   /// \param theSketch the sketch feature
162   /// \param theView a 3D view
163   /// \param theX the output horizontal coordinate of the point
164   /// \param theY the output vertical coordinate of the point
165   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
166                              Handle_V3d_View theView, double& theX, double& theY);
167
168
169   /**
170   * Find attribute of object which corresponds to the given shape
171   * \param theObj - an object
172   * \param theShape - a Shape
173   * \param theSketch - a Sketch to get a plane of converting to 2d
174   */
175   static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch);
176
177 protected:
178   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
179   /// if it exists, the first object is returned. Secondly, there is an iteration on
180   /// the selected list to find the point. Thirdly, if the object is not found under the
181   /// the point, the first selected object is returned.
182   /// \param thePoint a screen point
183   /// \param theView a 3D view
184   /// \param theSketch the sketch feature
185   /// \param thePresentations the list of presentations
186   static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
187                                   const QList<ModuleBase_ViewerPrs>& thePresentations);
188
189 };
190
191 #endif