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