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;
37 * \brief The operation for the sketch feature creation
39 class PARTSET_EXPORT PartSet_Tools
42 /// Converts the 2D screen point to the 3D point on the view according to the point of view
43 /// \param thePoint a screen point
44 /// \param theView a 3D view
45 // Transferred to ModuleBase
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 theX the X coordinate
52 /// \param theY the Y coordinate
53 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
54 Handle(V3d_View) theView,
55 double& theX, double& theY);
57 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
58 /// \param theX the X coordinate
59 /// \param theY the Y coordinate
60 /// \param theSketch the sketch feature
61 /// \param thePoint the 3D point in the viewer
62 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
64 /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
65 /// if it exists, the first object is returned. Secondly, there is an iteration on
66 /// the selected list to find the point. Thirdly, if the object is not found under the
67 /// the point, the first selected object is returned.
68 /// \param thePoint a screen point
69 /// \param theView a 3D view
70 /// \param theSketch the sketch feature
71 /// \param theSelected the list of selected presentations
72 /// \param theHighlighted the list of highlighted presentations
73 static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
74 const QList<ModuleBase_ViewerPrs>& theSelected,
75 const QList<ModuleBase_ViewerPrs>& theHighlighted);
77 /// Returns pointer to the root document.
78 static std::shared_ptr<ModelAPI_Document> document();
81 static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch,
82 double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
84 /// Returns a point attribute of the feature by the coordinates if it is
85 /// \param theFeature the feature
86 /// \param theX the horizontal coordinate
87 /// \param theY the vertical coordinate
88 static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
89 double theX, double theY);
91 /// \brief Save the double to the feature. If the attribute is double, it is filled.
92 /// \param theFeature the feature
93 /// \param theValue the horizontal coordinate
94 /// \param theAttribute the feature attribute
95 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
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);
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);
113 /// Creates a constraint on two points
114 /// \param thePoint1 the first point
115 /// \param thePoint1 the second point
116 static void createConstraint(CompositeFeaturePtr theSketch,
117 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
118 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
120 /// Creates constrains of the current
121 /// \param theSketch a sketch feature
122 /// \param theFeature a source feature
123 /// \param theAttribute a name of the requried attribute attribute
124 /// \param theClickedX the horizontal coordnate of the point
125 /// \param theClickedY the vertical coordnate of the point
126 static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
127 const std::string& theAttribute, double theClickedX,
130 /// Create a sketch plane instance
131 /// \param theSketch a sketch feature
132 /// \return API object of geom plane
133 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
135 /// Create a point 3D on a basis of point 2D and sketch feature
136 /// \param thePoint2D a point on a sketch
137 /// \param theSketch a sketch feature
138 /// \return API object of point 3D
139 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
140 CompositeFeaturePtr theSketch);
141 /// Check whether there is a constraint with the feature kind given
142 /// \param theKind a feature kind
143 /// \return the boolean value
144 static bool isConstraintFeature(const std::string& theKind);
146 /// Creates a line (arc or circle) by given edge
147 /// Created line will have fixed constraint
148 /// \param theEdge - an edge
149 /// \return - result of created feature
150 static ResultPtr createFixedObjectByEdge(const TopoDS_Shape& theShape,
151 const ObjectPtr& theObject,
152 CompositeFeaturePtr theSketch);
154 /// Checks whether the list of selected presentations contains the given one
155 /// \param theSelected a list of presentations
156 /// \param thePrs a presentation to be found
157 /// \return - result of check, true if the list contains the prs
158 static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
159 const ModuleBase_ViewerPrs& thePrs);
161 /// Returns Result object if the given skietch contains external edge equal to the given
162 /// \param theSketch - the sketch feature
163 /// \param theEdge - the edge
164 /// \return result object with external edge if it is found
165 static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
167 /// Returns Result object if the given sketch contains external vertex equal to the given
168 /// \param theSketch - the sketch feature
169 /// \param theVert - the vertex
170 /// \return result object with external vertex if it is found
171 static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
173 /// Returns whether the selected presentation has a shape with the vertex type
174 /// \param thePrs a selected presentation
175 /// \param theSketch the sketch feature
176 /// \param theView a 3D view
177 /// \param theX the output horizontal coordinate of the point
178 /// \param theY the output vertical coordinate of the point
179 static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
180 Handle_V3d_View theView, double& theX, double& theY);
184 * Find attribute of object which corresponds to the given shape
185 * \param theObj - an object
186 * \param theShape - a Shape
187 * \param theSketch - a Sketch to get a plane of converting to 2d
189 static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape, FeaturePtr theSketch);
192 /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
193 /// if it exists, the first object is returned. Secondly, there is an iteration on
194 /// the selected list to find the point. Thirdly, if the object is not found under the
195 /// the point, the first selected object is returned.
196 /// \param thePoint a screen point
197 /// \param theView a 3D view
198 /// \param theSketch the sketch feature
199 /// \param thePresentations the list of presentations
200 static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
201 const QList<ModuleBase_ViewerPrs>& thePresentations);