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 /// \enum ConstraintVisibleState types of constraints which visible state can be
45 /// changed in the sketch widget
46 enum ConstraintVisibleState
48 Geometrical = 0, // all constrains excepting dimensional
49 Dimensional // lenght, distance, radius and angle constraints
53 /// Converts the 2D screen point to the 3D point on the view according to the point of view
54 /// \param thePoint a screen point
55 /// \param theView a 3D view
56 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
58 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
59 /// \param thePoint the 3D point in the viewer
60 /// \param theSketch the sketch feature
61 /// \param theView a view 3d object
62 /// \param theX the X coordinate
63 /// \param theY the Y coordinate
64 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
65 Handle(V3d_View) theView,
66 double& theX, double& theY);
68 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
69 /// \param theSketch the sketch feature
70 /// \param thePnt the 3D point in the viewer
71 /// \returns the converted point object
72 static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch, const std::shared_ptr<GeomAPI_Pnt>& thePnt);
74 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
75 /// \param theX the X coordinate
76 /// \param theY the Y coordinate
77 /// \param theSketch the sketch feature
78 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
80 /// Returns pointer to the root document.
81 static std::shared_ptr<ModelAPI_Document> document();
83 /// \brief Save the double to the feature. If the attribute is double, it is filled.
84 /// \param theFeature the feature
85 /// \param theX the horizontal coordinate
86 /// \param theAttribute the feature attribute
87 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
89 /// \brief Returns the feature double value if it is.
90 /// \param theFeature the feature
91 /// \param theAttribute the feature attribute
92 /// \param isValid an output parameter whether the value is valid
93 /// \returns the feature value
94 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
96 /// Find a feature in the attribute of the given feature. If the kind is not empty,
97 /// the return feature should be this type. Otherwise it is null
98 /// \param theFeature a source feature
99 /// \param theAttribute a name of the requried attribute attribute
100 /// \param theKind an output feature kind
101 /// \return the feature
102 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
103 const std::string& theKind);
105 /// Creates a constraint on two points
106 /// \param theSketch a sketch feature
107 /// \param thePoint1 the first point
108 /// \param thePoint2 the second point
109 static void createConstraint(CompositeFeaturePtr theSketch,
110 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
111 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
113 /// Creates constrains of the current
114 /// \param theSketch a sketch feature
115 /// \param theFeature a source feature
116 /// \param theAttribute a name of the requried attribute attribute
117 /// \param theClickedX the horizontal coordnate of the point
118 /// \param theClickedY the vertical coordnate of the point
119 static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
120 const std::string& theAttribute, double theClickedX,
123 /// Create a sketch plane instance
124 /// \param theSketch a sketch feature
125 /// \return API object of geom plane
126 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
128 /// Create a point 3D on a basis of point 2D and sketch feature
129 /// \param thePoint2D a point on a sketch
130 /// \param theSketch a sketch feature
131 /// \return API object of point 3D
132 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
133 CompositeFeaturePtr theSketch);
135 /// Finds a line (arc or circle) by given edge
136 /// \param theShape an edge
137 /// \param theObject a selected result object
138 /// \param theSketch a sketch feature
139 /// \return result of found feature or NULL
140 static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape,
141 const ObjectPtr& theObject,
142 CompositeFeaturePtr theSketch);
144 /// Creates a line (arc or circle) by given edge
145 /// Created line will have fixed constraint
146 /// \param theShape an edge
147 /// \param theObject a selected result object
148 /// \param theSketch a sketch feature
149 /// \param theTemporary the created external object is temporary, execute is not performed for it
150 /// \return result of created feature
151 static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape,
152 const ObjectPtr& theObject,
153 CompositeFeaturePtr theSketch,
154 const bool theTemporary = false);
156 /// Checks whether the list of selected presentations contains the given one
157 /// \param theSelected a list of presentations
158 /// \param thePrs a presentation to be found
159 /// \return - result of check, true if the list contains the prs
160 static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
161 const ModuleBase_ViewerPrs& thePrs);
163 /// Returns Result object if the given skietch contains external edge equal to the given
164 /// \param theSketch - the sketch feature
165 /// \param theEdge - the edge
166 /// \return result object with external edge if it is found
167 static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
169 /// Returns Result object if the given sketch contains external vertex equal to the given
170 /// \param theSketch - the sketch feature
171 /// \param theVert - the vertex
172 /// \return result object with external vertex if it is found
173 static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
175 /// Returns whether the selected presentation has a shape with the vertex type
176 /// \param thePrs a selected presentation
177 /// \param theSketch the sketch feature
178 /// \param theView a 3D view
179 /// \param theX the output horizontal coordinate of the point
180 /// \param theY the output vertical coordinate of the point
181 static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
182 Handle_V3d_View theView, double& theX, double& theY);
186 * Find attribute of object which corresponds to the given shape
187 * \param theObj - an object
188 * \param theShape - a Shape
189 * \param theSketch - a Sketch to get a plane of converting to 2d
191 static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
192 FeaturePtr theSketch);
195 * Finds an attribute value in attribute reference attribute value
196 * \param theAttribute - an attribure reference filled with an attribute
197 * \param theWorkshop a reference to workshop
198 * \return a geometry shape
200 static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute,
201 ModuleBase_IWorkshop* theWorkshop);
204 * Returns point of coincidence feature
205 * \param theFeature the coincidence feature
206 * \param theAttribute the attribute name
208 static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
209 const std::string& theAttribute);
212 * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
213 * and compare the point value to be equal with the given. Returns the first feature, which has
215 * \param theSearchInResults a flag whether the conicidence feature shoudl be searched in
216 * references of the feature results.
217 * \return the coincidence feature or null
219 static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
220 std::shared_ptr<GeomAPI_Pnt2d> thePoint,
221 const bool theSearchInResults = false);
224 * Returns list of features connected in a councedence feature point
225 * \param theStartCoin the coincidence feature
226 * \param theList a list which collects lines features
227 * \param theAttr the attribute name
229 static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
230 std::string theAttr);
233 * Returns point of a coincedence
234 * \param theStartCoin the coincedence feature
236 static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);