Salome HOME
Update classes documentation
[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 <gp_Pnt.hxx>
13
14 #include <QPoint>
15 #include <QList>
16
17 #include <ModelAPI_CompositeFeature.h>
18 #include <ModelAPI_Object.h>
19 #include <ModelAPI_Attribute.h>
20
21 #include <Events_Message.h>
22
23 #include <TopoDS_Shape.hxx>
24
25 #include <memory>
26
27 class Handle_V3d_View;
28 class ModuleBase_ViewerPrs;
29 class ModuleBase_IWorkshop;
30 class GeomDataAPI_Point2D;
31 class GeomAPI_Shape;
32 class GeomAPI_Pln;
33 class GeomAPI_Pnt2d;
34 class GeomAPI_Pnt;
35 class GeomAPI_Edge;
36 class GeomAPI_Vertex;
37 class ModelAPI_Result;
38
39 /*!
40  * \class PartSet_Tools
41  * \ingroup Modules
42  * \brief The operation for the sketch feature creation
43  */
44 class PARTSET_EXPORT PartSet_Tools
45 {
46 public:
47   /// \enum ConstraintVisibleState types of constraints which visible state can be
48   /// changed in the sketch widget
49   enum ConstraintVisibleState
50   {
51     Geometrical = 0, // all constrains excepting dimensional
52     Dimensional,     // lenght, distance, radius and angle constraints
53     Expressions,     // parameter text should be shown in dimensional constraint
54     Any              // both, geometrical and dimensional, types of constraints
55   };
56
57  public:
58   /// Returns default value of AIS presentation
59   /// \return integer value
60   static int getAISDefaultWidth();
61
62   /// Converts the 2D screen point to the 3D point on the view according to the point of view
63   /// \param thePoint a screen point
64   /// \param theView a 3D view
65   static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
66
67   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
68   /// \param thePoint the 3D point in the viewer
69   /// \param theSketch the sketch feature
70   /// \param theView a view 3d object
71   /// \param theX the X coordinate
72   /// \param theY the Y coordinate
73   static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
74                           Handle(V3d_View) theView,
75                           double& theX, double& theY);
76
77   /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
78   /// \param theSketch the sketch feature
79   /// \param thePnt the 3D point in the viewer
80   /// \returns the converted point object
81   static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch, const std::shared_ptr<GeomAPI_Pnt>& thePnt);
82
83   /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
84   /// \param theX the X coordinate
85   /// \param theY the Y coordinate
86   /// \param theSketch the sketch feature
87   static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
88
89   /// Returns pointer to the root document.
90   static std::shared_ptr<ModelAPI_Document> document();
91
92   /// \brief Save the double to the feature. If the attribute is double, it is filled.
93   /// \param theFeature the feature
94   /// \param theX the horizontal coordinate
95   /// \param theAttribute the feature attribute
96   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
97
98   /// \brief Returns the feature double value if it is.
99   /// \param theFeature the feature
100   /// \param theAttribute the feature attribute
101   /// \param isValid an output parameter whether the value is valid
102   /// \returns the feature value
103   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
104
105   /// Find a feature in the attribute of the given feature. If the kind is not empty,
106   /// the return feature should be this type. Otherwise it is null
107   /// \param theFeature a source feature
108   /// \param theAttribute a name of the requried attribute attribute
109   /// \param theKind an output feature kind
110   /// \return the feature
111   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
112                             const std::string& theKind);
113
114   /// Creates a constraint on two points
115   /// \param theSketch a sketch feature
116   /// \param thePoint1 the first point
117   /// \param thePoint2 the second point
118   static void createConstraint(CompositeFeaturePtr theSketch,
119                                std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
120                                std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
121
122   /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates
123   /// \param theFeature a feature with sub-feature attributes
124   /// \param thePoint a point to provided searched coordinates
125   /// \return found point or null
126   static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInArgumentFeatures(
127                   const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
128
129   /// Finds in the feature first Point2D attribute with the given point coordinates
130   /// \param theFeature a feature with point attributes
131   /// \param thePoint a point to provided searched coordinates
132   /// \return found point or null
133   static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPoint(const FeaturePtr& theFeature,
134                                        const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
135
136   /// Creates constrains of the current 
137   /// \param theSketch a sketch feature
138   /// \param theFeature a source feature
139   /// \param theAttribute a name of the requried attribute attribute
140   /// \param theClickedX the horizontal coordnate of the point
141   /// \param theClickedY the vertical coordnate of the point
142   static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
143                              const std::string& theAttribute, double theClickedX,
144                              double theClickedY);
145
146   /// Create a sketch plane instance
147   /// \param theSketch a sketch feature
148   /// \return API object of geom plane
149   static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
150
151   /// Create a point 3D on a basis of point 2D and sketch feature
152   /// \param thePoint2D a point on a sketch
153   /// \param theSketch a sketch feature
154   /// \return API object of point 3D
155   static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
156                                                 CompositeFeaturePtr theSketch);
157
158   /// Finds a line (arc or circle) by given edge
159   /// \param theShape an edge
160   /// \param theObject a selected result object
161   /// \param theSketch a sketch feature
162   /// \return result of found feature or NULL
163   static std::shared_ptr<ModelAPI_Result> findFixedObjectByExternal(
164                                              const TopoDS_Shape& theShape,
165                                              const ObjectPtr& theObject, 
166                                              CompositeFeaturePtr theSketch);
167
168   /// Creates a line (arc or circle) by given edge
169   /// Created line will have fixed constraint
170   /// \param theShape an edge
171   /// \param theObject a selected result object
172   /// \param theSketch a sketch feature
173   /// \param theTemporary the created external object is temporary, execute is not performed for it
174   /// \return result of created feature
175   static std::shared_ptr<ModelAPI_Result> createFixedObjectByExternal(
176                                                const TopoDS_Shape& theShape, 
177                                                const ObjectPtr& theObject, 
178                                                CompositeFeaturePtr theSketch,
179                                                const bool theTemporary = false);
180
181   /// Checks whether the list of selected presentations contains the given one
182   /// \param theSelected a list of presentations
183   /// \param thePrs a presentation to be found
184   /// \return - result of check, true if the list contains the prs
185   static bool isContainPresentation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected,
186                                     const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
187
188   /// Returns Result object if the given skietch contains external edge equal to the given
189   /// \param theSketch - the sketch feature
190   /// \param theEdge - the edge
191   /// \return result object with external edge if it is found
192   static std::shared_ptr<ModelAPI_Result> findExternalEdge(CompositeFeaturePtr theSketch,
193                                                            std::shared_ptr<GeomAPI_Edge> theEdge);
194
195   /// Returns Result object if the given sketch contains external vertex equal to the given
196   /// \param theSketch - the sketch feature
197   /// \param theVert - the vertex
198   /// \return result object with external vertex if it is found
199   static std::shared_ptr<ModelAPI_Result> findExternalVertex(CompositeFeaturePtr theSketch,
200                                                         std::shared_ptr<GeomAPI_Vertex> theVert);
201
202   /// Returns whether the selected presentation has a shape with the vertex type
203   /// \param thePrs a selected presentation
204   /// \param theSketch the sketch feature
205   /// \param theView a 3D view
206   /// \param theX the output horizontal coordinate of the point
207   /// \param theY the output vertical coordinate of the point
208   static bool hasVertexShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs, FeaturePtr theSketch,
209                              Handle_V3d_View theView, double& theX, double& theY);
210
211
212   /**
213   * Find attribute of object which corresponds to the given shape
214   * \param theObj - an object
215   * \param theShape - a Shape
216   * \param theSketch - a Sketch to get a plane of converting to 2d
217   */
218   static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
219                                              FeaturePtr theSketch);
220
221   /**
222   * Finds an attribute value in attribute reference attribute value
223   * \param theAttribute - an attribure reference filled with an attribute
224   * \param theWorkshop a reference to workshop
225   * \return a geometry shape
226   */
227   static std::shared_ptr<GeomAPI_Shape> findShapeBy2DPoint(const AttributePtr& theAttribute,
228                                          ModuleBase_IWorkshop* theWorkshop);
229
230   /**
231   * Returns point of coincidence feature
232   * \param theFeature the coincidence feature
233   * \param theAttribute the attribute name
234   */
235   static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
236                                                  const std::string& theAttribute);
237
238   /**
239   * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
240   * and compare the point value to be equal with the given. Returns the first feature, which has
241   * equal points.
242   * \param theFeature the coincidence feature
243   * \param thePoint a 2d point
244   * \return the coincidence feature or null
245   */
246   static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
247                                          std::shared_ptr<GeomAPI_Pnt2d> thePoint);
248
249   /**
250   * Returns list of features connected in a councedence feature point
251   * \param theStartCoin the coincidence feature
252   * \param theList a list which collects lines features
253   * \param theCoincidencies a list of coincidence features
254   * \param theAttr the attribute name
255   */
256   static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
257                                QList<FeaturePtr>& theCoincidencies,
258                                std::string theAttr);
259
260   /**
261   * Returns point of a coincedence
262   * \param theStartCoin the coincedence feature
263   */
264   static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
265
266   /// Sends redisplay event for all sub-features of the composite. Flush it.
267   static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
268                                    const Events_ID theId);
269
270   /**
271    * Returns true if the object is a sketch entity, where auxiliary attribute has true vlaue
272    * \param theObject a result or feature
273    * \return boolean result
274    */
275   static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);
276 };
277
278 #endif