]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Tools.h
Salome HOME
bceef165aa4b03801364da28ca8b65b94349fdea
[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 TopoDS_Shape& theShape, 
145                                            const ObjectPtr& theObject, 
146                                            CompositeFeaturePtr theSketch);
147
148   /// Checks whether the list of selected presentations contains the given one
149   /// \param theSelected a list of presentations
150   /// \param thePrs a presentation to be found
151   /// \return - result of check, true if the list contains the prs
152   static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
153                                     const ModuleBase_ViewerPrs& thePrs);
154
155   /// Returns Result object if the given skietch contains external edge equal to the given
156   /// \param theSketch - the sketch feature
157   /// \param theEdge - the edge
158   /// \return result object with external edge if it is found
159   static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
160
161   /// Returns whether the selected presentation has a shape with the vertex type
162   /// \param thePrs a selected presentation
163   /// \param theSketch the sketch feature
164   /// \param theView a 3D view
165   /// \param theX the output horizontal coordinate of the point
166   /// \param theY the output vertical coordinate of the point
167   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
168                              Handle_V3d_View theView, double& theX, double& theY);
169
170
171   /**
172   * Find attribute of object which corresponds to the given shape
173   * \param theObj - an object
174   * \param theShape - a Shape
175   * \param theSketch - a Sketch to get a plane of converting to 2d
176   */
177   static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch);
178
179 protected:
180   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
181   /// if it exists, the first object is returned. Secondly, there is an iteration on
182   /// the selected list to find the point. Thirdly, if the object is not found under the
183   /// the point, the first selected object is returned.
184   /// \param thePoint a screen point
185   /// \param theView a 3D view
186   /// \param theSketch the sketch feature
187   /// \param thePresentations the list of presentations
188   static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
189                                   const QList<ModuleBase_ViewerPrs>& thePresentations);
190
191 };
192
193 #endif