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 /// Converts the 2D screen point to the 3D point on the view according to the point of view
58 /// \param thePoint a screen point
59 /// \param theView a 3D view
60 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle_V3d_View theView);
62 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
63 /// \param thePoint the 3D point in the viewer
64 /// \param theSketch the sketch feature
65 /// \param theView a view 3d object
66 /// \param theX the X coordinate
67 /// \param theY the Y coordinate
68 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
69 Handle(V3d_View) theView,
70 double& theX, double& theY);
72 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
73 /// \param theSketch the sketch feature
74 /// \param thePnt the 3D point in the viewer
75 /// \returns the converted point object
76 static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch, const std::shared_ptr<GeomAPI_Pnt>& thePnt);
78 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
79 /// \param theX the X coordinate
80 /// \param theY the Y coordinate
81 /// \param theSketch the sketch feature
82 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY, FeaturePtr theSketch);
84 /// Returns pointer to the root document.
85 static std::shared_ptr<ModelAPI_Document> document();
87 /// \brief Save the double to the feature. If the attribute is double, it is filled.
88 /// \param theFeature the feature
89 /// \param theX the horizontal coordinate
90 /// \param theAttribute the feature attribute
91 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
93 /// \brief Returns the feature double value if it is.
94 /// \param theFeature the feature
95 /// \param theAttribute the feature attribute
96 /// \param isValid an output parameter whether the value is valid
97 /// \returns the feature value
98 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
100 /// Find a feature in the attribute of the given feature. If the kind is not empty,
101 /// the return feature should be this type. Otherwise it is null
102 /// \param theFeature a source feature
103 /// \param theAttribute a name of the requried attribute attribute
104 /// \param theKind an output feature kind
105 /// \return the feature
106 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
107 const std::string& theKind);
109 /// Creates a constraint on two points
110 /// \param theSketch a sketch feature
111 /// \param thePoint1 the first point
112 /// \param thePoint2 the second point
113 static void createConstraint(CompositeFeaturePtr theSketch,
114 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
115 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
117 /// Finds in the feature's sub-features first Point2D attribute with the given point coordinates
118 /// \param theFeature a feature with sub-feature attributes
119 /// \param thePoint a point to provided searched coordinates
120 /// \return found point or null
121 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPointInArgumentFeatures(
122 const FeaturePtr& theFeature, const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
124 /// Finds in the feature first Point2D attribute with the given point coordinates
125 /// \param theFeature a feature with point attributes
126 /// \param thePoint a point to provided searched coordinates
127 /// \return found point or null
128 static std::shared_ptr<GeomDataAPI_Point2D> findFirstEqualPoint(const FeaturePtr& theFeature,
129 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
131 /// Creates constrains of the current
132 /// \param theSketch a sketch feature
133 /// \param theFeature a source feature
134 /// \param theAttribute a name of the requried attribute attribute
135 /// \param theClickedX the horizontal coordnate of the point
136 /// \param theClickedY the vertical coordnate of the point
137 static void setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
138 const std::string& theAttribute, double theClickedX,
141 /// Create a sketch plane instance
142 /// \param theSketch a sketch feature
143 /// \return API object of geom plane
144 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
146 /// Create a point 3D on a basis of point 2D and sketch feature
147 /// \param thePoint2D a point on a sketch
148 /// \param theSketch a sketch feature
149 /// \return API object of point 3D
150 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
151 CompositeFeaturePtr theSketch);
153 /// Finds a line (arc or circle) by given edge
154 /// \param theShape an edge
155 /// \param theObject a selected result object
156 /// \param theSketch a sketch feature
157 /// \return result of found feature or NULL
158 static ResultPtr findFixedObjectByExternal(const TopoDS_Shape& theShape,
159 const ObjectPtr& theObject,
160 CompositeFeaturePtr theSketch);
162 /// Creates a line (arc or circle) by given edge
163 /// Created line will have fixed constraint
164 /// \param theShape an edge
165 /// \param theObject a selected result object
166 /// \param theSketch a sketch feature
167 /// \param theTemporary the created external object is temporary, execute is not performed for it
168 /// \return result of created feature
169 static ResultPtr createFixedObjectByExternal(const TopoDS_Shape& theShape,
170 const ObjectPtr& theObject,
171 CompositeFeaturePtr theSketch,
172 const bool theTemporary = false);
174 /// Checks whether the list of selected presentations contains the given one
175 /// \param theSelected a list of presentations
176 /// \param thePrs a presentation to be found
177 /// \return - result of check, true if the list contains the prs
178 static bool isContainPresentation(const QList<ModuleBase_ViewerPrs>& theSelected,
179 const ModuleBase_ViewerPrs& thePrs);
181 /// Returns Result object if the given skietch contains external edge equal to the given
182 /// \param theSketch - the sketch feature
183 /// \param theEdge - the edge
184 /// \return result object with external edge if it is found
185 static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
187 /// Returns Result object if the given sketch contains external vertex equal to the given
188 /// \param theSketch - the sketch feature
189 /// \param theVert - the vertex
190 /// \return result object with external vertex if it is found
191 static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
193 /// Returns whether the selected presentation has a shape with the vertex type
194 /// \param thePrs a selected presentation
195 /// \param theSketch the sketch feature
196 /// \param theView a 3D view
197 /// \param theX the output horizontal coordinate of the point
198 /// \param theY the output vertical coordinate of the point
199 static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
200 Handle_V3d_View theView, double& theX, double& theY);
204 * Find attribute of object which corresponds to the given shape
205 * \param theObj - an object
206 * \param theShape - a Shape
207 * \param theSketch - a Sketch to get a plane of converting to 2d
209 static AttributePtr findAttributeBy2dPoint(ObjectPtr theObj, const TopoDS_Shape theShape,
210 FeaturePtr theSketch);
213 * Finds an attribute value in attribute reference attribute value
214 * \param theAttribute - an attribure reference filled with an attribute
215 * \param theWorkshop a reference to workshop
216 * \return a geometry shape
218 static GeomShapePtr findShapeBy2DPoint(const AttributePtr& theAttribute,
219 ModuleBase_IWorkshop* theWorkshop);
222 * Returns point of coincidence feature
223 * \param theFeature the coincidence feature
224 * \param theAttribute the attribute name
226 static std::shared_ptr<GeomAPI_Pnt2d> getPoint(std::shared_ptr<ModelAPI_Feature>& theFeature,
227 const std::string& theAttribute);
230 * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
231 * and compare the point value to be equal with the given. Returns the first feature, which has
233 * \param theSearchInResults a flag whether the conicidence feature shoudl be searched in
234 * references of the feature results.
235 * \return the coincidence feature or null
237 static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
238 std::shared_ptr<GeomAPI_Pnt2d> thePoint);
241 * Returns list of features connected in a councedence feature point
242 * \param theStartCoin the coincidence feature
243 * \param theList a list which collects lines features
244 * \param theAttr the attribute name
246 static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
247 QList<FeaturePtr>& theCoincidencies,
248 std::string theAttr);
251 * Returns point of a coincedence
252 * \param theStartCoin the coincedence feature
254 static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
256 /// Sends redisplay event for all sub-features of the composite. Flush it.
257 static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
258 const Events_ID theId);
261 * Returns true if the object is a sketch entity, where auxiliary attribute has true vlaue
262 * \param theObject a result or feature
263 * \return boolean result
265 static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);