Salome HOME
Issue #738 select point by mouse change predefined coordinates of connected object
[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 ModuleBase_IWorkshop;
29 class GeomDataAPI_Point2D;
30 class GeomAPI_Pln;
31 class GeomAPI_Pnt2d;
32 class GeomAPI_Pnt;
33 class GeomAPI_Edge;
34 class GeomAPI_Vertex;
35
36 /*!
37  * \class PartSet_Tools
38  * \ingroup Modules
39  * \brief The operation for the sketch feature creation
40  */
41 class PARTSET_EXPORT PartSet_Tools
42 {
43  public:
44   /// Converts the 2D screen point to the 3D point on the view according to the point of view
45   /// \param thePoint a screen point
46   /// \param theView a 3D view
47   static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
48
49   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
50   /// \param thePoint the 3D point in the viewer
51   /// \param theSketch the sketch feature
52   /// \param theView a view 3d object
53   /// \param theX the X coordinate
54   /// \param theY the Y coordinate
55   static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
56                           Handle(V3d_View) theView,
57                           double& theX, double& theY);
58
59   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
60   /// \param theSketch the sketch feature
61   /// \param thePnt the 3D point in the viewer
62   /// \returns the converted point object
63   static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch, const std::shared_ptr<GeomAPI_Pnt>& thePnt);
64
65   /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
66   /// \param theX the X coordinate
67   /// \param theY the Y coordinate
68   /// \param theSketch the sketch feature
69   static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
70
71   /// Returns pointer to the root document.
72   static std::shared_ptr<ModelAPI_Document> document();
73
74   /// Find an attribute which corresponds to a given pont coordinates
75   /// \param theSketch the sketch feature
76   /// \param theX X coordinate
77   /// \param theY Y coordinate
78   /// \param theTolerance tolerance
79   /// \param theIgnore list of features which has to be ignored
80   //static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch, 
81   //  double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
82
83   /// Returns a point attribute of the feature by the coordinates if it is
84   /// \param theFeature the feature
85   /// \param theX the horizontal coordinate
86   /// \param theY the vertical coordinate
87   //static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
88   //                                                              double theX, double theY);
89
90   /// \brief Save the double to the feature. If the attribute is double, it is filled.
91   /// \param theFeature the feature
92   /// \param theX the horizontal coordinate
93   /// \param theAttribute the feature attribute
94   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
95
96   /// \brief Returns the feature double value if it is.
97   /// \param theFeature the feature
98   /// \param theAttribute the feature attribute
99   /// \param isValid an output parameter whether the value is valid
100   /// \returns the feature value
101   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
102
103   /// Find a feature in the attribute of the given feature. If the kind is not empty,
104   /// the return feature should be this type. Otherwise it is null
105   /// \param theFeature a source feature
106   /// \param theAttribute a name of the requried attribute attribute
107   /// \param theKind an output feature kind
108   /// \return the feature
109   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
110                             const std::string& theKind);
111
112   /// Creates a constraint on two points
113   /// \param theSketch a sketch feature
114   /// \param thePoint1 the first point
115   /// \param thePoint2 the second point
116   static void createConstraint(CompositeFeaturePtr theSketch,
117                                std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
118                                std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
119
120   /// Creates constrains of the current 
121   /// \param theSketch a sketch feature
122   /// \param theFeature a source feature
123   /// \param theAttribute a name of the requried attribute attribute
124   /// \param theClickedX the horizontal coordnate of the point
125   /// \param theClickedY the vertical coordnate of the point
126   static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
127                              const std::string& theAttribute, double theClickedX,
128                              double theClickedY);
129
130   /// Create a sketch plane instance
131   /// \param theSketch a sketch feature
132   /// \return API object of geom plane
133   static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
134
135   /// Create a point 3D on a basis of point 2D and sketch feature
136   /// \param thePoint2D a point on a sketch
137   /// \param theSketch a sketch feature
138   /// \return API object of point 3D
139   static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
140                                                 CompositeFeaturePtr theSketch);
141
142   /// Finds a line (arc or circle) by given edge
143   /// \param theShape an edge
144   /// \param theObject a selected result object
145   /// \param theSketch a sketch feature
146   /// \return result of found feature or NULL
147   static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape, 
148                                              const ObjectPtr& theObject, 
149                                              CompositeFeaturePtr theSketch);
150
151   /// Creates a line (arc or circle) by given edge
152   /// Created line will have fixed constraint
153   /// \param theShape an edge
154   /// \param theObject a selected result object
155   /// \param theSketch a sketch feature
156   /// \param theTemporary the created external object is temporary, execute is not performed for it
157   /// \return result of created feature
158   static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape, 
159                                                const ObjectPtr& theObject, 
160                                                CompositeFeaturePtr theSketch,
161                                                const bool theTemporary = false);
162
163   /// Checks whether the list of selected presentations contains the given one
164   /// \param theSelected a list of presentations
165   /// \param thePrs a presentation to be found
166   /// \return - result of check, true if the list contains the prs
167   static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
168                                     const ModuleBase_ViewerPrs& thePrs);
169
170   /// Returns Result object if the given skietch contains external edge equal to the given
171   /// \param theSketch - the sketch feature
172   /// \param theEdge - the edge
173   /// \return result object with external edge if it is found
174   static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
175
176   /// Returns Result object if the given sketch contains external vertex equal to the given
177   /// \param theSketch - the sketch feature
178   /// \param theVert - the vertex
179   /// \return result object with external vertex if it is found
180   static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
181
182   /// Returns whether the selected presentation has a shape with the vertex type
183   /// \param thePrs a selected presentation
184   /// \param theSketch the sketch feature
185   /// \param theView a 3D view
186   /// \param theX the output horizontal coordinate of the point
187   /// \param theY the output vertical coordinate of the point
188   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
189                              Handle_V3d_View theView, double& theX, double& theY);
190
191
192   /**
193   * Find attribute of object which corresponds to the given shape
194   * \param theObj - an object
195   * \param theShape - a Shape
196   * \param theSketch - a Sketch to get a plane of converting to 2d
197   */
198   static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
199                                              FeaturePtr theSketch);
200
201   /**
202   * Finds an attribute value in attribute reference attribute value
203   * \param theAttribute - an attribure reference filled with an attribute
204   * \return a geometry shape
205   */
206   static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute,
207                                          ModuleBase_IWorkshop* theWorkshop);
208
209   /* Returns point of coincidence feature
210   * \param theFeature the coincidence feature
211   * \param theAttribute the attribute name
212   */
213   static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
214                                                  const std::string& theAttribute);
215
216   /**
217   * Returns list of features connected in a councedence feature point
218   * \param theStartCoin the coincidence feature
219   * \param theList a list which collects lines features
220   * \param theAttr the attribute name
221   */
222   static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
223                                std::string theAttr);
224 };
225
226 #endif