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