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
17 #include <ModelAPI_CompositeFeature.h>
18 #include <ModelAPI_Object.h>
19 #include <ModelAPI_Attribute.h>
21 #include <Events_Message.h>
23 #include <TopoDS_Shape.hxx>
27 class Handle_V3d_View;
28 class ModuleBase_ViewerPrs;
29 class ModuleBase_IWorkshop;
30 class GeomDataAPI_Point2D;
37 class ModelAPI_Result;
40 * \class PartSet_Tools
42 * \brief The operation for the sketch feature creation
44 class PARTSET_EXPORT PartSet_Tools
47 /// \enum ConstraintVisibleState types of constraints which visible state can be
48 /// changed in the sketch widget
49 enum ConstraintVisibleState
51 Geometrical = 0, // all constrains excepting dimensional
52 Dimensional, // lenght, distance, radius and angle constraints
53 Expressions, // parameter text should be shown in dimensional constraint
54 Any // both, geometrical and dimensional, types of constraints
58 /// Returns default value of AIS presentation
59 /// \return integer value
60 static int getAISDefaultWidth();
62 /// Converts the 2D screen point to the 3D point on the view according to the point of view
63 /// \param thePoint a screen point
64 /// \param theView a 3D view
65 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
67 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
68 /// \param thePoint the 3D point in the viewer
69 /// \param theSketch the sketch feature
70 /// \param theView a view 3d object
71 /// \param theX the X coordinate
72 /// \param theY the Y coordinate
73 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
74 Handle(V3d_View) theView,
75 double& theX, double& theY);
77 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
78 /// \param theSketch the sketch feature
79 /// \param thePnt the 3D point in the viewer
80 /// \returns the converted point object
81 static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch,
82 const std::shared_ptr<GeomAPI_Pnt>& thePnt);
84 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
85 /// \param theX the X coordinate
86 /// \param theY the Y coordinate
87 /// \param theSketch the sketch feature
88 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY,
89 FeaturePtr theSketch);
91 /// Returns pointer to the root document.
92 static std::shared_ptr<ModelAPI_Document> document();
94 /// \brief Save the double to the feature. If the attribute is double, it is filled.
95 /// \param theFeature the feature
96 /// \param theX the horizontal coordinate
97 /// \param theAttribute the feature attribute
98 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
100 /// \brief Returns the feature double value if it is.
101 /// \param theFeature the feature
102 /// \param theAttribute the feature attribute
103 /// \param isValid an output parameter whether the value is valid
104 /// \returns the feature value
105 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
107 /// Find a feature in the attribute of the given feature. If the kind is not empty,
108 /// the return feature should be this type. Otherwise it is null
109 /// \param theFeature a source feature
110 /// \param theAttribute a name of the requried attribute attribute
111 /// \param theKind an output feature kind
112 /// \return the feature
113 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
114 const std::string& theKind);
116 /// Creates a constraint on two points
117 /// \param theSketch a sketch feature
118 /// \param thePoint1 the first point
119 /// \param thePoint2 the second point
120 static void createConstraint(CompositeFeaturePtr theSketch,
121 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
122 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
124 /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates
125 /// \param theFeature a feature with sub-feature attributes
126 /// \param thePoint a point to provided searched coordinates
127 /// \return found point or null
128 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInArgumentFeatures(
129 const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
131 /// Finds in the feature first Point2D attribute with the given point coordinates
132 /// \param theFeature a feature with point attributes
133 /// \param thePoint a point to provided searched coordinates
134 /// \return found point or null
135 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPoint(const FeaturePtr& theFeature,
136 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
138 /// Creates constrains of the current
139 /// \param theSketch a sketch feature
140 /// \param theFeature a source feature
141 /// \param theAttribute a name of the requried attribute attribute
142 /// \param theClickedX the horizontal coordnate of the point
143 /// \param theClickedY the vertical coordnate of the point
144 static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
145 const std::string& theAttribute, double theClickedX,
148 /// Create a sketch plane instance
149 /// \param theSketch a sketch feature
150 /// \return API object of geom plane
151 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
153 /// Create a point 3D on a basis of point 2D and sketch feature
154 /// \param thePoint2D a point on a sketch
155 /// \param theSketch a sketch feature
156 /// \return API object of point 3D
157 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
158 CompositeFeaturePtr theSketch);
160 /// Finds a line (arc or circle) by given edge
161 /// \param theShape an edge
162 /// \param theObject a selected result object
163 /// \param theSketch a sketch feature
164 /// \return result of found feature or NULL
165 static std::shared_ptr<ModelAPI_Result> findFixedObjectByExternal(
166 const TopoDS_Shape& theShape,
167 const ObjectPtr& theObject,
168 CompositeFeaturePtr theSketch);
170 /// Creates a line (arc or circle) by given edge
171 /// Created line will have fixed constraint
172 /// \param theShape an edge
173 /// \param theObject a selected result object
174 /// \param theSketch a sketch feature
175 /// \param theTemporary the created external object is temporary, execute is not performed for it
176 /// \return result of created feature
177 static std::shared_ptr<ModelAPI_Result> createFixedObjectByExternal(
178 const TopoDS_Shape& theShape,
179 const ObjectPtr& theObject,
180 CompositeFeaturePtr theSketch,
181 const bool theTemporary = false);
183 /// Checks whether the list of selected presentations contains the given one
184 /// \param theSelected a list of presentations
185 /// \param thePrs a presentation to be found
186 /// \return - result of check, true if the list contains the prs
187 static bool isContainPresentation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected,
188 const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
190 /// Returns Result object if the given skietch contains external edge equal to the given
191 /// \param theSketch - the sketch feature
192 /// \param theEdge - the edge
193 /// \return result object with external edge if it is found
194 static std::shared_ptr<ModelAPI_Result> findExternalEdge(CompositeFeaturePtr theSketch,
195 std::shared_ptr<GeomAPI_Edge> theEdge);
197 /// Returns Result object if the given sketch contains external vertex equal to the given
198 /// \param theSketch - the sketch feature
199 /// \param theVert - the vertex
200 /// \return result object with external vertex if it is found
201 static std::shared_ptr<ModelAPI_Result> findExternalVertex(CompositeFeaturePtr theSketch,
202 std::shared_ptr<GeomAPI_Vertex> theVert);
204 /// Returns whether the selected presentation has a shape with the vertex type
205 /// \param thePrs a selected presentation
206 /// \param theSketch the sketch feature
207 /// \param theView a 3D view
208 /// \param theX the output horizontal coordinate of the point
209 /// \param theY the output vertical coordinate of the point
210 static bool hasVertexShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
211 FeaturePtr theSketch,
212 Handle_V3d_View theView, double& theX, double& theY);
216 * Find attribute of object which corresponds to the given shape
217 * \param theObj - an object
218 * \param theShape - a Shape
219 * \param theSketch - a Sketch to get a plane of converting to 2d
221 static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
222 FeaturePtr theSketch);
225 * Finds an attribute value in attribute reference attribute value
226 * \param theAttribute - an attribure reference filled with an attribute
227 * \param theWorkshop a reference to workshop
228 * \return a geometry shape
230 static std::shared_ptr<GeomAPI_Shape> findShapeBy2DPoint(const AttributePtr& theAttribute,
231 ModuleBase_IWorkshop* theWorkshop);
234 * Returns point of coincidence feature
235 * \param theFeature the coincidence feature
236 * \param theAttribute the attribute name
238 static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
239 const std::string& theAttribute);
242 * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
243 * and compare the point value to be equal with the given. Returns the first feature, which has
245 * \param theFeature the coincidence feature
246 * \param thePoint a 2d point
247 * \return the coincidence feature or null
249 static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
250 std::shared_ptr<GeomAPI_Pnt2d> thePoint);
253 * Returns list of features connected in a councedence feature point
254 * \param theStartCoin the coincidence feature
255 * \param theList a list which collects lines features
256 * \param theCoincidencies a list of coincidence features
257 * \param theAttr the attribute name
259 static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
260 QList<FeaturePtr>& theCoincidencies,
261 std::string theAttr);
264 * Returns point of a coincedence
265 * \param theStartCoin the coincedence feature
267 static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
269 /// Sends redisplay event for all sub-features of the composite. Flush it.
270 static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
271 const Events_ID theId);
274 * Returns true if the object is a sketch entity, where auxiliary attribute has true vlaue
275 * \param theObject a result or feature
276 * \return boolean result
278 static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);