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>
20 #include <ModelAPI_AttributeSelection.h>
22 #include <Events_Message.h>
24 #include <TopoDS_Shape.hxx>
29 class ModuleBase_IViewWindow;
30 class ModuleBase_ViewerPrs;
31 class ModuleBase_IWorkshop;
32 class GeomDataAPI_Point2D;
39 class ModelAPI_Result;
44 * \class PartSet_Tools
46 * \brief The operation for the sketch feature creation
48 class PARTSET_EXPORT PartSet_Tools
51 /// \enum ConstraintVisibleState types of constraints which visible state can be
52 /// changed in the sketch widget
53 enum ConstraintVisibleState
55 Geometrical = 0, // all constrains excepting dimensional
56 Dimensional, // lenght, distance, radius and angle constraints
57 Expressions, // parameter text should be shown in dimensional constraint
58 Any // both, geometrical and dimensional, types of constraints
62 /// Returns default value of AIS presentation
63 /// \return integer value
64 static int getAISDefaultWidth();
66 /// Converts the 2D screen point to the 3D point on the view according to the point of view
67 /// \param thePoint a screen point
68 /// \param theView a 3D view
69 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView);
71 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
72 /// \param thePoint the 3D point in the viewer
73 /// \param theSketch the sketch feature
74 /// \param theView a view 3d object
75 /// \param theX the X coordinate
76 /// \param theY the Y coordinate
77 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
78 Handle(V3d_View) theView,
79 double& theX, double& theY);
81 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
82 /// \param theSketch the sketch feature
83 /// \param thePnt the 3D point in the viewer
84 /// \returns the converted point object
85 static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch,
86 const std::shared_ptr<GeomAPI_Pnt>& thePnt);
88 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
89 /// \param theX the X coordinate
90 /// \param theY the Y coordinate
91 /// \param theSketch the sketch feature
92 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY,
93 FeaturePtr theSketch);
95 /// Returns pointer to the root document.
96 static std::shared_ptr<ModelAPI_Document> document();
98 /// \brief Save the double to the feature. If the attribute is double, it is filled.
99 /// \param theFeature the feature
100 /// \param theX the horizontal coordinate
101 /// \param theAttribute the feature attribute
102 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
104 /// \brief Returns the feature double value if it is.
105 /// \param theFeature the feature
106 /// \param theAttribute the feature attribute
107 /// \param isValid an output parameter whether the value is valid
108 /// \returns the feature value
109 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
111 /// Find a feature in the attribute of the given feature. If the kind is not empty,
112 /// the return feature should be this type. Otherwise it is null
113 /// \param theFeature a source feature
114 /// \param theAttribute a name of the requried attribute attribute
115 /// \param theKind an output feature kind
116 /// \return the feature
117 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
118 const std::string& theKind);
120 /// Creates a constraint on two points
121 /// \param theSketch a sketch feature
122 /// \param thePoint1 the first point
123 /// \param thePoint2 the second point
124 static void createConstraint(CompositeFeaturePtr theSketch,
125 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
126 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
128 /// Create a sketch plane instance
129 /// \param theSketch a sketch feature
130 /// \return API object of geom plane
131 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
133 /// Create a point 3D on a basis of point 2D and sketch feature
134 /// \param thePoint2D a point on a sketch
135 /// \param theSketch a sketch feature
136 /// \return API object of point 3D
137 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
138 CompositeFeaturePtr theSketch);
140 /// Finds a line (arc or circle) by given edge
141 /// \param theShape an edge
142 /// \param theObject a selected result object
143 /// \param theSketch a sketch feature
144 /// \return result of found feature or NULL
145 static std::shared_ptr<ModelAPI_Result> findFixedObjectByExternal(
146 const TopoDS_Shape& theShape,
147 const ObjectPtr& theObject,
148 CompositeFeaturePtr theSketch);
150 /// Creates a line (arc or circle) by given edge
151 /// Created line will have fixed constraint
152 /// \param theShape an edge
153 /// \param theObject a selected result object
154 /// \param theSketch a sketch feature
155 /// \param theTemporary the created external object is temporary, execute is not performed for it
156 /// \return result of created feature
157 static std::shared_ptr<ModelAPI_Result> createFixedObjectByExternal(
158 const TopoDS_Shape& theShape,
159 const ObjectPtr& theObject,
160 CompositeFeaturePtr theSketch,
161 const bool theTemporary = false);
163 /// Checks whether the list of selected presentations contains the given one
164 /// \param theSelected a list of presentations
165 /// \param thePrs a presentation to be found
166 /// \return - result of check, true if the list contains the prs
167 static bool isContainPresentation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected,
168 const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
170 /// Returns Result object if the given skietch contains external edge equal to the given
171 /// \param theSketch - the sketch feature
172 /// \param theEdge - the edge
173 /// \return result object with external edge if it is found
174 static std::shared_ptr<ModelAPI_Result> findExternalEdge(CompositeFeaturePtr theSketch,
175 std::shared_ptr<GeomAPI_Edge> theEdge);
177 /// Returns Result object if the given sketch contains external vertex equal to the given
178 /// \param theSketch - the sketch feature
179 /// \param theVert - the vertex
180 /// \return result object with external vertex if it is found
181 static std::shared_ptr<ModelAPI_Result> findExternalVertex(CompositeFeaturePtr theSketch,
182 std::shared_ptr<GeomAPI_Vertex> theVert);
184 /// Returns whether the selected presentation has a shape with the vertex type
185 /// \param thePrs a selected presentation
186 /// \param theSketch the sketch feature
187 /// \param theView a 3D view
188 /// \param theX the output horizontal coordinate of the point
189 /// \param theY the output vertical coordinate of the point
190 static bool hasVertexShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
191 FeaturePtr theSketch,
192 Handle(V3d_View) theView, double& theX, double& theY);
196 * Find attribute of object which corresponds to the given shape
197 * \param theObj - an object
198 * \param theShape - a Shape
199 * \param theSketch - a Sketch to get a plane of converting to 2d
201 static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
202 FeaturePtr theSketch);
205 * Finds an attribute value in attribute reference attribute value
206 * \param theAttribute - an attribure reference filled with an attribute
207 * \param theWorkshop a reference to workshop
208 * \return a geometry shape
210 static std::shared_ptr<GeomAPI_Shape> findShapeBy2DPoint(const AttributePtr& theAttribute,
211 ModuleBase_IWorkshop* theWorkshop);
214 * Returns point of coincidence feature
215 * \param theFeature the coincidence feature
216 * \param theAttribute the attribute name
218 static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
219 const std::string& theAttribute);
222 * Convertes parameters into a geom point
223 * \theEvent a Qt event to find mouse position
224 * \param theWindow view window to define eye of view
225 * \param theSketch to convert 3D point coordinates into coorditates of the sketch plane
227 static std::shared_ptr<GeomAPI_Pnt2d> getPnt2d(QMouseEvent* theEvent,
228 ModuleBase_IViewWindow* theWindow,
229 const FeaturePtr& theSketch);
232 * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
233 * and compare the point value to be equal with the given. Returns the first feature, which has
235 * \param theFeature the coincidence feature
236 * \param thePoint a 2d point
237 * \return the coincidence feature or null
239 static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
240 std::shared_ptr<GeomAPI_Pnt2d> thePoint);
243 * Returns list of features connected in a councedence feature point
244 * \param theStartCoin the coincidence feature
245 * \param theList a list which collects lines features
246 * \param theCoincidencies a list of coincidence features
247 * \param theAttr the attribute name
249 static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
250 QList<FeaturePtr>& theCoincidencies,
251 std::string theAttr);
254 * Returns point of a coincedence
255 * \param theStartCoin the coincedence feature
257 static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
259 /// Sends redisplay event for all sub-features of the composite. Flush it.
260 static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
261 const Events_ID theId);
264 * Returns true if the object is a sketch entity, where auxiliary attribute has true vlaue
265 * \param theObject a result or feature
266 * \return boolean result
268 static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);
270 static ResultPtr createFixedByExternalCenter(const ObjectPtr& theObject,
271 const std::shared_ptr<GeomAPI_Edge>& theEdge,
272 ModelAPI_AttributeSelection::CenterType theType,
273 const CompositeFeaturePtr& theSketch,
274 bool theTemporary = false);