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