1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: PartSet_Tools.h
4 // Created: 28 Apr 2014
5 // Author: Natalia ERMOLAEVA
7 #ifndef PartSet_Tools_H
8 #define PartSet_Tools_H
12 #include <ModuleBase_ViewerPrs.h>
18 #include <ModelAPI_CompositeFeature.h>
19 #include <ModelAPI_Object.h>
20 #include <ModelAPI_Attribute.h>
22 #include <TopoDS_Shape.hxx>
26 class Handle_V3d_View;
27 class ModuleBase_ViewerPrs;
28 class GeomDataAPI_Point2D;
36 * \class PartSet_Tools
38 * \brief The operation for the sketch feature creation
40 class PARTSET_EXPORT PartSet_Tools
43 /// Converts the 2D screen point to the 3D point on the view according to the point of view
44 /// \param thePoint a screen point
45 /// \param theView a 3D view
46 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
48 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
49 /// \param thePoint the 3D point in the viewer
50 /// \param theSketch the sketch feature
51 /// \param theView a view 3d object
52 /// \param theX the X coordinate
53 /// \param theY the Y coordinate
54 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
55 Handle(V3d_View) theView,
56 double& theX, double& theY);
58 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
59 /// \param theSketch the sketch feature
60 /// \param thePnt the 3D point in the viewer
61 /// \returns the converted point object
62 static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch, const std::shared_ptr<GeomAPI_Pnt>& thePnt);
64 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
65 /// \param theX the X coordinate
66 /// \param theY the Y coordinate
67 /// \param theSketch the sketch feature
68 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
70 /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
71 /// if it exists, the first object is returned. Secondly, there is an iteration on
72 /// the selected list to find the point. Thirdly, if the object is not found under the
73 /// the point, the first selected object is returned.
74 /// \param thePoint a screen point
75 /// \param theView a 3D view
76 /// \param theSketch the sketch feature
77 /// \param theSelected the list of selected presentations
78 /// \param theHighlighted the list of highlighted presentations
79 static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
80 const QList<ModuleBase_ViewerPrs>& theSelected,
81 const QList<ModuleBase_ViewerPrs>& theHighlighted);
83 /// Returns pointer to the root document.
84 static std::shared_ptr<ModelAPI_Document> document();
86 /// Find an attribute which corresponds to a given pont coordinates
87 /// \param theSketch the sketch feature
88 /// \param theX X coordinate
89 /// \param theY Y coordinate
90 /// \param theTolerance tolerance
91 /// \param theIgnore list of features which has to be ignored
92 static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch,
93 double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
95 /// Returns a point attribute of the feature by the coordinates if it is
96 /// \param theFeature the feature
97 /// \param theX the horizontal coordinate
98 /// \param theY the vertical coordinate
99 static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
100 double theX, double theY);
102 /// \brief Save the double to the feature. If the attribute is double, it is filled.
103 /// \param theFeature the feature
104 /// \param theX the horizontal coordinate
105 /// \param theAttribute the feature attribute
106 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
108 /// \brief Returns the feature double value if it is.
109 /// \param theFeature the feature
110 /// \param theAttribute the feature attribute
111 /// \param isValid an output parameter whether the value is valid
112 /// \returns the feature value
113 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
115 /// Find a feature in the attribute of the given feature. If the kind is not empty,
116 /// the return feature should be this type. Otherwise it is null
117 /// \param theFeature a source feature
118 /// \param theAttribute a name of the requried attribute attribute
119 /// \param theKind an output feature kind
120 /// \return the feature
121 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
122 const std::string& theKind);
124 /// Creates a constraint on two points
125 /// \param theSketch a sketch feature
126 /// \param thePoint1 the first point
127 /// \param thePoint2 the second point
128 static void createConstraint(CompositeFeaturePtr theSketch,
129 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
130 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
132 /// Creates constrains of the current
133 /// \param theSketch a sketch feature
134 /// \param theFeature a source feature
135 /// \param theAttribute a name of the requried attribute attribute
136 /// \param theClickedX the horizontal coordnate of the point
137 /// \param theClickedY the vertical coordnate of the point
138 static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
139 const std::string& theAttribute, double theClickedX,
142 /// Create a sketch plane instance
143 /// \param theSketch a sketch feature
144 /// \return API object of geom plane
145 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
147 /// Create a point 3D on a basis of point 2D and sketch feature
148 /// \param thePoint2D a point on a sketch
149 /// \param theSketch a sketch feature
150 /// \return API object of point 3D
151 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
152 CompositeFeaturePtr theSketch);
154 /// Finds a line (arc or circle) by given edge
155 /// \param theShape an edge
156 /// \param theObject a selected result object
157 /// \param theSketch a sketch feature
158 /// \return result of found feature or NULL
159 static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape,
160 const ObjectPtr& theObject,
161 CompositeFeaturePtr theSketch);
163 /// Creates a line (arc or circle) by given edge
164 /// Created line will have fixed constraint
165 /// \param theShape an edge
166 /// \param theObject a selected result object
167 /// \param theSketch a sketch feature
168 /// \return result of created feature
169 static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape,
170 const ObjectPtr& theObject,
171 CompositeFeaturePtr theSketch);
173 /// Checks whether the list of selected presentations contains the given one
174 /// \param theSelected a list of presentations
175 /// \param thePrs a presentation to be found
176 /// \return - result of check, true if the list contains the prs
177 static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
178 const ModuleBase_ViewerPrs& thePrs);
180 /// Returns Result object if the given skietch contains external edge equal to the given
181 /// \param theSketch - the sketch feature
182 /// \param theEdge - the edge
183 /// \return result object with external edge if it is found
184 static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
186 /// Returns Result object if the given sketch contains external vertex equal to the given
187 /// \param theSketch - the sketch feature
188 /// \param theVert - the vertex
189 /// \return result object with external vertex if it is found
190 static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
192 /// Returns whether the selected presentation has a shape with the vertex type
193 /// \param thePrs a selected presentation
194 /// \param theSketch the sketch feature
195 /// \param theView a 3D view
196 /// \param theX the output horizontal coordinate of the point
197 /// \param theY the output vertical coordinate of the point
198 static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
199 Handle_V3d_View theView, double& theX, double& theY);
203 * Find attribute of object which corresponds to the given shape
204 * \param theObj - an object
205 * \param theShape - a Shape
206 * \param theSketch - a Sketch to get a plane of converting to 2d
208 static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch);
211 /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
212 /// if it exists, the first object is returned. Secondly, there is an iteration on
213 /// the selected list to find the point. Thirdly, if the object is not found under the
214 /// the point, the first selected object is returned.
215 /// \param thePoint a screen point
216 /// \param theView a 3D view
217 /// \param theSketch the sketch feature
218 /// \param thePresentations the list of presentations
219 static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
220 const QList<ModuleBase_ViewerPrs>& thePresentations);