Salome HOME
Sketch should stop contour in origin point if the contour is closed.
[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   /// \brief Save the double to the feature. If the attribute is double, it is filled.
75   /// \param theFeature the feature
76   /// \param theX the horizontal coordinate
77   /// \param theAttribute the feature attribute
78   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
79
80   /// \brief Returns the feature double value if it is.
81   /// \param theFeature the feature
82   /// \param theAttribute the feature attribute
83   /// \param isValid an output parameter whether the value is valid
84   /// \returns the feature value
85   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
86
87   /// Find a feature in the attribute of the given feature. If the kind is not empty,
88   /// the return feature should be this type. Otherwise it is null
89   /// \param theFeature a source feature
90   /// \param theAttribute a name of the requried attribute attribute
91   /// \param theKind an output feature kind
92   /// \return the feature
93   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
94                             const std::string& theKind);
95
96   /// Creates a constraint on two points
97   /// \param theSketch a sketch feature
98   /// \param thePoint1 the first point
99   /// \param thePoint2 the second point
100   static void createConstraint(CompositeFeaturePtr theSketch,
101                                std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
102                                std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
103
104   /// Creates constrains of the current 
105   /// \param theSketch a sketch feature
106   /// \param theFeature a source feature
107   /// \param theAttribute a name of the requried attribute attribute
108   /// \param theClickedX the horizontal coordnate of the point
109   /// \param theClickedY the vertical coordnate of the point
110   static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
111                              const std::string& theAttribute, double theClickedX,
112                              double theClickedY);
113
114   /// Create a sketch plane instance
115   /// \param theSketch a sketch feature
116   /// \return API object of geom plane
117   static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
118
119   /// Create a point 3D on a basis of point 2D and sketch feature
120   /// \param thePoint2D a point on a sketch
121   /// \param theSketch a sketch feature
122   /// \return API object of point 3D
123   static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
124                                                 CompositeFeaturePtr theSketch);
125
126   /// Finds a line (arc or circle) by given edge
127   /// \param theShape an edge
128   /// \param theObject a selected result object
129   /// \param theSketch a sketch feature
130   /// \return result of found feature or NULL
131   static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape, 
132                                              const ObjectPtr& theObject, 
133                                              CompositeFeaturePtr theSketch);
134
135   /// Creates a line (arc or circle) by given edge
136   /// Created line will have fixed constraint
137   /// \param theShape an edge
138   /// \param theObject a selected result object
139   /// \param theSketch a sketch feature
140   /// \param theTemporary the created external object is temporary, execute is not performed for it
141   /// \return result of created feature
142   static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape, 
143                                                const ObjectPtr& theObject, 
144                                                CompositeFeaturePtr theSketch,
145                                                const bool theTemporary = false);
146
147   /// Checks whether the list of selected presentations contains the given one
148   /// \param theSelected a list of presentations
149   /// \param thePrs a presentation to be found
150   /// \return - result of check, true if the list contains the prs
151   static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
152                                     const ModuleBase_ViewerPrs& thePrs);
153
154   /// Returns Result object if the given skietch contains external edge equal to the given
155   /// \param theSketch - the sketch feature
156   /// \param theEdge - the edge
157   /// \return result object with external edge if it is found
158   static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
159
160   /// Returns Result object if the given sketch contains external vertex equal to the given
161   /// \param theSketch - the sketch feature
162   /// \param theVert - the vertex
163   /// \return result object with external vertex if it is found
164   static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
165
166   /// Returns whether the selected presentation has a shape with the vertex type
167   /// \param thePrs a selected presentation
168   /// \param theSketch the sketch feature
169   /// \param theView a 3D view
170   /// \param theX the output horizontal coordinate of the point
171   /// \param theY the output vertical coordinate of the point
172   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
173                              Handle_V3d_View theView, double& theX, double& theY);
174
175
176   /**
177   * Find attribute of object which corresponds to the given shape
178   * \param theObj - an object
179   * \param theShape - a Shape
180   * \param theSketch - a Sketch to get a plane of converting to 2d
181   */
182   static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
183                                              FeaturePtr theSketch);
184
185   /**
186   * Finds an attribute value in attribute reference attribute value
187   * \param theAttribute - an attribure reference filled with an attribute
188   * \param theWorkshop a reference to workshop
189   * \return a geometry shape
190   */
191   static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute,
192                                          ModuleBase_IWorkshop* theWorkshop);
193
194   /**
195   * Returns point of coincidence feature
196   * \param theFeature the coincidence feature
197   * \param theAttribute the attribute name
198   */
199   static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
200                                                  const std::string& theAttribute);
201
202   /**
203   * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
204   * and compare the point value to be equal with the given. Returns the first feature, which has
205   * equal points.
206   * \param theSearchInResults a flag whether the conicidence feature shoudl be searched in
207   * references of the feature results.
208   * \return the coincidence feature or null
209   */
210   static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
211                                          std::shared_ptr<GeomAPI_Pnt2d> thePoint,
212                                          const bool theSearchInResults = false);
213
214   /**
215   * Returns list of features connected in a councedence feature point
216   * \param theStartCoin the coincidence feature
217   * \param theList a list which collects lines features
218   * \param theAttr the attribute name
219   */
220   static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
221                                std::string theAttr);
222
223   /**
224   * Returns point of a coincedence
225   * \param theStartCoin the coincedence feature
226   */
227   static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
228 };
229
230 #endif