1 // File: PartSet_Tools.h
2 // Created: 28 Apr 2014
3 // Author: Natalia ERMOLAEVA
5 #ifndef PartSet_Tools_H
6 #define PartSet_Tools_H
10 #include <ModuleBase_ViewerPrs.h>
16 #include <ModelAPI_CompositeFeature.h>
20 class Handle_V3d_View;
21 class ModuleBase_ViewerPrs;
22 class GeomDataAPI_Point2D;
30 * \brief The operation for the sketch feature creation
32 class PARTSET_EXPORT PartSet_Tools
35 /// Converts the 2D screen point to the 3D point on the view according to the point of view
36 /// \param thePoint a screen point
37 /// \param theView a 3D view
38 // Transferred to ModuleBase
39 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
41 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
42 /// \param thePoint the 3D point in the viewer
43 /// \param theSketch the sketch feature
44 /// \param theX the X coordinate
45 /// \param theY the Y coordinate
46 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
47 Handle(V3d_View) theView,
48 double& theX, double& theY);
50 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
51 /// \param theX the X coordinate
52 /// \param theY the Y coordinate
53 /// \param theSketch the sketch feature
54 /// \param thePoint the 3D point in the viewer
55 static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
58 /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
59 /// if it exists, the first object is returned. Secondly, there is an iteration on
60 /// the selected list to find the point. Thirdly, if the object is not found under the
61 /// the point, the first selected object is returned.
62 /// \param thePoint a screen point
63 /// \param theView a 3D view
64 /// \param theSketch the sketch feature
65 /// \param theSelected the list of selected presentations
66 /// \param theHighlighted the list of highlighted presentations
67 static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
68 const QList<ModuleBase_ViewerPrs>& theSelected,
69 const QList<ModuleBase_ViewerPrs>& theHighlighted);
71 /// Returns pointer to the root document.
72 static std::shared_ptr<ModelAPI_Document> document();
75 /// Returns a point attribute of the feature by the coordinates if it is
76 /// \param theFeature the feature
77 /// \param theX the horizontal coordinate
78 /// \param theY the vertical coordinate
79 static std::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
80 double theX, double theY);
82 /// \brief Save the double to the feature. If the attribute is double, it is filled.
83 /// \param theFeature the feature
84 /// \param theValue the horizontal coordinate
85 /// \param theAttribute the feature attribute
86 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
88 /// \brief Returns the feature double value if it is.
89 /// \param theFeature the feature
90 /// \param theAttribute the feature attribute
91 /// \param isValid an output parameter whether the value is valid
92 /// \returns the feature value
93 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
95 /// Find a feature in the attribute of the given feature. If the kind is not empty,
96 /// the return feature should be this type. Otherwise it is null
97 /// \param theFeature a source feature
98 /// \param theAttribute a name of the requried attribute attribute
99 /// \param theKind an output feature kind
100 /// \return the feature
101 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
102 const std::string& theKind);
104 /// Creates a constraint on two points
105 /// \param thePoint1 the first point
106 /// \param thePoint1 the second point
107 static void createConstraint(CompositeFeaturePtr theSketch,
108 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
109 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
111 /// Creates constrains of the current
112 /// \param theSketch a sketch feature
113 /// \param theFeature a source feature
114 /// \param theAttribute a name of the requried attribute attribute
115 /// \param theClickedX the horizontal coordnate of the point
116 /// \param theClickedY the vertical coordnate of the point
117 static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
118 const std::string& theAttribute, double theClickedX,
121 /// Create a sketch plane instance
122 /// \param theSketch a sketch feature
123 /// \return API object of geom plane
124 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
126 /// Create a point 3D on a basis of point 2D and sketch feature
127 /// \param thePoint2D a point on a sketch
128 /// \param theSketch a sketch feature
129 /// \return API object of point 3D
130 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
131 CompositeFeaturePtr theSketch);
132 /// Check whether there is a constraint with the feature kind given
133 /// \param theKind a feature kind
134 /// \return the boolean value
135 static bool isConstraintFeature(const std::string& theKind);
137 /// Creates a line (arc or circle) by given edge
138 /// Created line will have fixed constraint
139 /// \param theEdge - an edge
140 /// \return - result of created feature
141 static ResultPtr createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch);
143 /// Checks whether the list of selected presentations contains the given one
144 /// \param theSelected a list of presentations
145 /// \param thePrs a presentation to be found
146 /// \return - result of check, true if the list contains the prs
147 static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
148 const ModuleBase_ViewerPrs& thePrs);
150 /// Returns Result object if the given skietch contains external edge equal to the given
151 /// \param theSketch - the sketch feature
152 /// \param theEdge - the edge
153 /// \return result object with external edge if it is found
154 static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
156 /// Returns whether the selected presentation has a shape with the vertex type
157 /// \param thePrs a selected presentation
158 /// \param theSketch the sketch feature
159 /// \param theView a 3D view
160 /// \param theX the output horizontal coordinate of the point
161 /// \param theY the output vertical coordinate of the point
162 static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
163 Handle_V3d_View theView, double& theX, double& theY);
165 /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
166 /// if it exists, the first object is returned. Secondly, there is an iteration on
167 /// the selected list to find the point. Thirdly, if the object is not found under the
168 /// the point, the first selected object is returned.
169 /// \param thePoint a screen point
170 /// \param theView a 3D view
171 /// \param theSketch the sketch feature
172 /// \param thePresentations the list of presentations
173 static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
174 const QList<ModuleBase_ViewerPrs>& thePresentations);