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>
18 #include <boost/shared_ptr.hpp>
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 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
40 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
41 /// \param thePoint the 3D point in the viewer
42 /// \param theSketch the sketch feature
43 /// \param theX the X coordinate
44 /// \param theY the Y coordinate
45 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
46 Handle(V3d_View) theView,
47 double& theX, double& theY);
49 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
50 /// \param theX the X coordinate
51 /// \param theY the Y coordinate
52 /// \param theSketch the sketch feature
53 /// \param thePoint the 3D point in the viewer
54 static void convertTo3D(const double theX, const double theY, FeaturePtr theSketch,
57 /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
58 /// if it exists, the first object is returned. Secondly, there is an iteration on
59 /// the selected list to find the point. Thirdly, if the object is not found under the
60 /// the point, the first selected object is returned.
61 /// \param thePoint a screen point
62 /// \param theView a 3D view
63 /// \param theSketch the sketch feature
64 /// \param theSelected the list of selected presentations
65 /// \param theHighlighted the list of highlighted presentations
66 static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
67 const QList<ModuleBase_ViewerPrs>& theSelected,
68 const QList<ModuleBase_ViewerPrs>& theHighlighted);
70 /// Returns pointer to the root document.
71 static boost::shared_ptr<ModelAPI_Document> document();
74 /// Returns a point attribute of the feature by the coordinates if it is
75 /// \param theFeature the feature
76 /// \param theX the horizontal coordinate
77 /// \param theY the vertical coordinate
78 static boost::shared_ptr<GeomDataAPI_Point2D> getFeaturePoint(FeaturePtr theFeature,
79 double theX, double theY);
81 /// \brief Save the double to the feature. If the attribute is double, it is filled.
82 /// \param theFeature the feature
83 /// \param theValue the horizontal coordinate
84 /// \param theAttribute the feature attribute
85 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
87 /// \brief Returns the feature double value if it is.
88 /// \param theFeature the feature
89 /// \param theAttribute the feature attribute
90 /// \param isValid an output parameter whether the value is valid
91 /// \returns the feature value
92 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
94 /// Find a feature in the attribute of the given feature. If the kind is not empty,
95 /// the return feature should be this type. Otherwise it is null
96 /// \param theFeature a source feature
97 /// \param theAttribute a name of the requried attribute attribute
98 /// \param theKind an output feature kind
99 /// \return the feature
100 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
101 const std::string& theKind);
103 /// Creates a constraint on two points
104 /// \param thePoint1 the first point
105 /// \param thePoint1 the second point
106 static void createConstraint(CompositeFeaturePtr theSketch,
107 boost::shared_ptr<GeomDataAPI_Point2D> thePoint1,
108 boost::shared_ptr<GeomDataAPI_Point2D> thePoint2);
110 /// Creates constrains of the current
111 /// \param theSketch a sketch feature
112 /// \param theFeature a source feature
113 /// \param theAttribute a name of the requried attribute attribute
114 /// \param theClickedX the horizontal coordnate of the point
115 /// \param theClickedY the vertical coordnate of the point
116 static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
117 const std::string& theAttribute, double theClickedX,
120 /// Create a sketch plane instance
121 /// \param theSketch a sketch feature
122 /// \return API object of geom plane
123 static boost::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
125 /// Create a point 3D on a basis of point 2D and sketch feature
126 /// \param thePoint2D a point on a sketch
127 /// \param theSketch a sketch feature
128 /// \return API object of point 3D
129 static boost::shared_ptr<GeomAPI_Pnt> point3D(boost::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
130 CompositeFeaturePtr theSketch);
131 /// Check whether there is a constraint with the feature kind given
132 /// \param theKind a feature kind
133 /// \return the boolean value
134 static bool isConstraintFeature(const std::string& theKind);
136 /// Creates a line (arc or circle) by given edge
137 /// Created line will have fixed constraint
138 /// \param theEdge - an edge
139 /// \return - result of created feature
140 static ResultPtr createFixedObjectByEdge(const ModuleBase_ViewerPrs& thePrs, CompositeFeaturePtr theSketch);
142 /// Checks whether the list of selected presentations contains the given one
143 /// \param theSelected a list of presentations
144 /// \param thePrs a presentation to be found
145 /// \return - result of check, true if the list contains the prs
146 static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
147 const ModuleBase_ViewerPrs& thePrs);
149 /// Returns Result object if the given skietch contains external edge equal to the given
150 /// \param theSketch - the sketch feature
151 /// \param theEdge - the edge
152 /// \return result object with external edge if it is found
153 static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr<GeomAPI_Edge> theEdge);