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