]> SALOME platform Git repositories - modules/shaper.git/blob - src/PartSet/PartSet_Tools.h
Salome HOME
1. Mirror/Rotation/Translation constraint: using RefList instead of SelectionList
[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 an object that is under the mouse point. Firstly it checks the highlighting,
72   /// if it exists, the first object is returned. Secondly, there is an iteration on
73   /// the selected list to find the point. Thirdly, if the object is not found under the
74   /// the point, the first selected object is returned.
75   /// \param thePoint a screen point
76   /// \param theView a 3D view
77   /// \param theSketch the sketch feature
78   /// \param theSelected the list of selected presentations
79   /// \param theHighlighted the list of highlighted presentations
80   static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
81                                   const QList<ModuleBase_ViewerPrs>& theSelected,
82                                   const QList<ModuleBase_ViewerPrs>& theHighlighted);
83
84   /// Returns pointer to the root document.
85   static std::shared_ptr<ModelAPI_Document> document();
86
87   /// Find an attribute which corresponds to a given pont coordinates
88   /// \param theSketch the sketch feature
89   /// \param theX X coordinate
90   /// \param theY Y coordinate
91   /// \param theTolerance tolerance
92   /// \param theIgnore list of features which has to be ignored
93   //static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch, 
94   //  double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
95
96   /// Returns a point attribute of the feature by the coordinates if it is
97   /// \param theFeature the feature
98   /// \param theX the horizontal coordinate
99   /// \param theY the vertical coordinate
100   //static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
101   //                                                              double theX, double theY);
102
103   /// \brief Save the double to the feature. If the attribute is double, it is filled.
104   /// \param theFeature the feature
105   /// \param theX the horizontal coordinate
106   /// \param theAttribute the feature attribute
107   static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
108
109   /// \brief Returns the feature double value if it is.
110   /// \param theFeature the feature
111   /// \param theAttribute the feature attribute
112   /// \param isValid an output parameter whether the value is valid
113   /// \returns the feature value
114   static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
115
116   /// Find a feature in the attribute of the given feature. If the kind is not empty,
117   /// the return feature should be this type. Otherwise it is null
118   /// \param theFeature a source feature
119   /// \param theAttribute a name of the requried attribute attribute
120   /// \param theKind an output feature kind
121   /// \return the feature
122   static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
123                             const std::string& theKind);
124
125   /// Creates a constraint on two points
126   /// \param theSketch a sketch feature
127   /// \param thePoint1 the first point
128   /// \param thePoint2 the second point
129   static void createConstraint(CompositeFeaturePtr theSketch,
130                                std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
131                                std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
132
133   /// Creates constrains of the current 
134   /// \param theSketch a sketch feature
135   /// \param theFeature a source feature
136   /// \param theAttribute a name of the requried attribute attribute
137   /// \param theClickedX the horizontal coordnate of the point
138   /// \param theClickedY the vertical coordnate of the point
139   static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
140                              const std::string& theAttribute, double theClickedX,
141                              double theClickedY);
142
143   /// Create a sketch plane instance
144   /// \param theSketch a sketch feature
145   /// \return API object of geom plane
146   static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
147
148   /// Create a point 3D on a basis of point 2D and sketch feature
149   /// \param thePoint2D a point on a sketch
150   /// \param theSketch a sketch feature
151   /// \return API object of point 3D
152   static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
153                                                 CompositeFeaturePtr theSketch);
154
155   /// Finds a line (arc or circle) by given edge
156   /// \param theShape an edge
157   /// \param theObject a selected result object
158   /// \param theSketch a sketch feature
159   /// \return result of found feature or NULL
160   static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape, 
161                                              const ObjectPtr& theObject, 
162                                              CompositeFeaturePtr theSketch);
163
164   /// Creates a line (arc or circle) by given edge
165   /// Created line will have fixed constraint
166   /// \param theShape an edge
167   /// \param theObject a selected result object
168   /// \param theSketch a sketch feature
169   /// \param theTemporary the created external object is temporary, execute is not performed for it
170   /// \return result of created feature
171   static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape, 
172                                                const ObjectPtr& theObject, 
173                                                CompositeFeaturePtr theSketch,
174                                                const bool theTemporary = false);
175
176   /// Checks whether the list of selected presentations contains the given one
177   /// \param theSelected a list of presentations
178   /// \param thePrs a presentation to be found
179   /// \return - result of check, true if the list contains the prs
180   static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
181                                     const ModuleBase_ViewerPrs& thePrs);
182
183   /// Returns Result object if the given skietch contains external edge equal to the given
184   /// \param theSketch - the sketch feature
185   /// \param theEdge - the edge
186   /// \return result object with external edge if it is found
187   static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
188
189   /// Returns Result object if the given sketch contains external vertex equal to the given
190   /// \param theSketch - the sketch feature
191   /// \param theVert - the vertex
192   /// \return result object with external vertex if it is found
193   static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
194
195   /// Returns whether the selected presentation has a shape with the vertex type
196   /// \param thePrs a selected presentation
197   /// \param theSketch the sketch feature
198   /// \param theView a 3D view
199   /// \param theX the output horizontal coordinate of the point
200   /// \param theY the output vertical coordinate of the point
201   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
202                              Handle_V3d_View theView, double& theX, double& theY);
203
204
205   /**
206   * Find attribute of object which corresponds to the given shape
207   * \param theObj - an object
208   * \param theShape - a Shape
209   * \param theSketch - a Sketch to get a plane of converting to 2d
210   */
211   static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
212                                              FeaturePtr theSketch);
213
214   /**
215   * Finds an attribute value in attribute reference attribute value
216   * \param theAttribute - an attribure reference filled with an attribute
217   * \return a geometry shape
218   */
219   static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute,
220                                          ModuleBase_IWorkshop* theWorkshop);
221
222   /* Returns point of coincidence feature
223   * \param theFeature the coincidence feature
224   * \param theAttribute the attribute name
225   */
226   static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
227                                                  const std::string& theAttribute);
228
229   /**
230   * Returns list of features connected in a councedence feature point
231   * \param theStartCoin the coincidence feature
232   * \param theList a list which collects lines features
233   * \param theAttr the attribute name
234   */
235   static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
236                                std::string theAttr);
237
238 protected:
239   /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
240   /// if it exists, the first object is returned. Secondly, there is an iteration on
241   /// the selected list to find the point. Thirdly, if the object is not found under the
242   /// the point, the first selected object is returned.
243   /// \param thePoint a screen point
244   /// \param theView a 3D view
245   /// \param theSketch the sketch feature
246   /// \param thePresentations the list of presentations
247   static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
248                                   const QList<ModuleBase_ViewerPrs>& thePresentations);
249
250 };
251
252 #endif