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