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