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 ModuleBase_IWorkshop;
29 class GeomDataAPI_Point2D;
37 * \class PartSet_Tools
39 * \brief The operation for the sketch feature creation
41 class PARTSET_EXPORT PartSet_Tools
44 /// Converts the 2D screen point to the 3D point on the view according to the point of view
45 /// \param thePoint a screen point
46 /// \param theView a 3D view
47 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
49 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
50 /// \param thePoint the 3D point in the viewer
51 /// \param theSketch the sketch feature
52 /// \param theView a view 3d object
53 /// \param theX the X coordinate
54 /// \param theY the Y coordinate
55 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
56 Handle(V3d_View) theView,
57 double& theX, double& theY);
59 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
60 /// \param theSketch the sketch feature
61 /// \param thePnt the 3D point in the viewer
62 /// \returns the converted point object
63 static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch, const std::shared_ptr<GeomAPI_Pnt>& thePnt);
65 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
66 /// \param theX the X coordinate
67 /// \param theY the Y coordinate
68 /// \param theSketch the sketch feature
69 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
71 /// Returns pointer to the root document.
72 static std::shared_ptr<ModelAPI_Document> document();
74 /// \brief Save the double to the feature. If the attribute is double, it is filled.
75 /// \param theFeature the feature
76 /// \param theX the horizontal coordinate
77 /// \param theAttribute the feature attribute
78 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
80 /// \brief Returns the feature double value if it is.
81 /// \param theFeature the feature
82 /// \param theAttribute the feature attribute
83 /// \param isValid an output parameter whether the value is valid
84 /// \returns the feature value
85 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
87 /// Find a feature in the attribute of the given feature. If the kind is not empty,
88 /// the return feature should be this type. Otherwise it is null
89 /// \param theFeature a source feature
90 /// \param theAttribute a name of the requried attribute attribute
91 /// \param theKind an output feature kind
92 /// \return the feature
93 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
94 const std::string& theKind);
96 /// Creates a constraint on two points
97 /// \param theSketch a sketch feature
98 /// \param thePoint1 the first point
99 /// \param thePoint2 the second point
100 static void createConstraint(CompositeFeaturePtr theSketch,
101 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
102 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
104 /// Creates constrains of the current
105 /// \param theSketch a sketch feature
106 /// \param theFeature a source feature
107 /// \param theAttribute a name of the requried attribute attribute
108 /// \param theClickedX the horizontal coordnate of the point
109 /// \param theClickedY the vertical coordnate of the point
110 static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
111 const std::string& theAttribute, double theClickedX,
114 /// Create a sketch plane instance
115 /// \param theSketch a sketch feature
116 /// \return API object of geom plane
117 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
119 /// Create a point 3D on a basis of point 2D and sketch feature
120 /// \param thePoint2D a point on a sketch
121 /// \param theSketch a sketch feature
122 /// \return API object of point 3D
123 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
124 CompositeFeaturePtr theSketch);
126 /// Finds a line (arc or circle) by given edge
127 /// \param theShape an edge
128 /// \param theObject a selected result object
129 /// \param theSketch a sketch feature
130 /// \return result of found feature or NULL
131 static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape,
132 const ObjectPtr& theObject,
133 CompositeFeaturePtr theSketch);
135 /// Creates a line (arc or circle) by given edge
136 /// Created line will have fixed constraint
137 /// \param theShape an edge
138 /// \param theObject a selected result object
139 /// \param theSketch a sketch feature
140 /// \param theTemporary the created external object is temporary, execute is not performed for it
141 /// \return result of created feature
142 static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape,
143 const ObjectPtr& theObject,
144 CompositeFeaturePtr theSketch,
145 const bool theTemporary = false);
147 /// Checks whether the list of selected presentations contains the given one
148 /// \param theSelected a list of presentations
149 /// \param thePrs a presentation to be found
150 /// \return - result of check, true if the list contains the prs
151 static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
152 const ModuleBase_ViewerPrs& thePrs);
154 /// Returns Result object if the given skietch contains external edge equal to the given
155 /// \param theSketch - the sketch feature
156 /// \param theEdge - the edge
157 /// \return result object with external edge if it is found
158 static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
160 /// Returns Result object if the given sketch contains external vertex equal to the given
161 /// \param theSketch - the sketch feature
162 /// \param theVert - the vertex
163 /// \return result object with external vertex if it is found
164 static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
166 /// Returns whether the selected presentation has a shape with the vertex type
167 /// \param thePrs a selected presentation
168 /// \param theSketch the sketch feature
169 /// \param theView a 3D view
170 /// \param theX the output horizontal coordinate of the point
171 /// \param theY the output vertical coordinate of the point
172 static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
173 Handle_V3d_View theView, double& theX, double& theY);
177 * Find attribute of object which corresponds to the given shape
178 * \param theObj - an object
179 * \param theShape - a Shape
180 * \param theSketch - a Sketch to get a plane of converting to 2d
182 static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
183 FeaturePtr theSketch);
186 * Finds an attribute value in attribute reference attribute value
187 * \param theAttribute - an attribure reference filled with an attribute
188 * \param theWorkshop a reference to workshop
189 * \return a geometry shape
191 static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute,
192 ModuleBase_IWorkshop* theWorkshop);
195 * Returns point of coincidence feature
196 * \param theFeature the coincidence feature
197 * \param theAttribute the attribute name
199 static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
200 const std::string& theAttribute);
203 * Returns list of features connected in a councedence feature point
204 * \param theStartCoin the coincidence feature
205 * \param theList a list which collects lines features
206 * \param theAttr the attribute name
208 static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
209 std::string theAttr);
212 * Returns point of a coincedence
213 * \param theStartCoin the coincedence feature
215 static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);