1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
20 #ifndef PartSet_Tools_H
21 #define PartSet_Tools_H
30 #include <ModelAPI_CompositeFeature.h>
31 #include <ModelAPI_Object.h>
32 #include <ModelAPI_Attribute.h>
34 #include <Events_Message.h>
36 #include <TopoDS_Shape.hxx>
41 class ModuleBase_IViewWindow;
42 class ModuleBase_ViewerPrs;
43 class ModuleBase_IWorkshop;
44 class GeomDataAPI_Point2D;
51 class ModelAPI_Result;
56 * \class PartSet_Tools
58 * \brief The operation for the sketch feature creation
60 class PARTSET_EXPORT PartSet_Tools
63 /// \enum ConstraintVisibleState types of constraints which visible state can be
64 /// changed in the sketch widget
65 enum ConstraintVisibleState
67 Geometrical = 0, // all constrains excepting dimensional
68 Dimensional, // lenght, distance, radius and angle constraints
69 Expressions, // parameter text should be shown in dimensional constraint
70 Any // both, geometrical and dimensional, types of constraints
74 /// Returns default value of AIS presentation
75 /// \return integer value
76 static int getAISDefaultWidth();
78 /// Converts the 2D screen point to the 3D point on the view according to the point of view
79 /// \param thePoint a screen point
80 /// \param theView a 3D view
81 static gp_Pnt convertClickToPoint(QPoint thePoint, Handle(V3d_View) theView);
83 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
84 /// \param thePoint the 3D point in the viewer
85 /// \param theSketch the sketch feature
86 /// \param theView a view 3d object
87 /// \param theX the X coordinate
88 /// \param theY the Y coordinate
89 static void convertTo2D(const gp_Pnt& thePoint, FeaturePtr theSketch,
90 Handle(V3d_View) theView,
91 double& theX, double& theY);
93 /// \brief Converts the 3D point to the projected coodinates on the sketch plane.
94 /// \param theSketch the sketch feature
95 /// \param thePnt the 3D point in the viewer
96 /// \returns the converted point object
97 static std::shared_ptr<GeomAPI_Pnt2d> convertTo2D(FeaturePtr theSketch,
98 const std::shared_ptr<GeomAPI_Pnt>& thePnt);
100 /// \brief Converts the 2D projected coodinates on the sketch plane to the 3D point.
101 /// \param theX the X coordinate
102 /// \param theY the Y coordinate
103 /// \param theSketch the sketch feature
104 static std::shared_ptr<GeomAPI_Pnt> convertTo3D(const double theX, const double theY,
105 FeaturePtr theSketch);
107 /// Returns pointer to the root document.
108 static std::shared_ptr<ModelAPI_Document> document();
110 /// \brief Save the double to the feature. If the attribute is double, it is filled.
111 /// \param theFeature the feature
112 /// \param theX the horizontal coordinate
113 /// \param theAttribute the feature attribute
114 static void setFeatureValue(FeaturePtr theFeature, double theX, const std::string& theAttribute);
116 /// \brief Returns the feature double value if it is.
117 /// \param theFeature the feature
118 /// \param theAttribute the feature attribute
119 /// \param isValid an output parameter whether the value is valid
120 /// \returns the feature value
121 static double featureValue(FeaturePtr theFeature, const std::string& theAttribute, bool& isValid);
123 /// Find a feature in the attribute of the given feature. If the kind is not empty,
124 /// the return feature should be this type. Otherwise it is null
125 /// \param theFeature a source feature
126 /// \param theAttribute a name of the requried attribute attribute
127 /// \param theKind an output feature kind
128 /// \return the feature
129 static FeaturePtr feature(FeaturePtr theFeature, const std::string& theAttribute,
130 const std::string& theKind);
132 /// Creates a constraint on two points
133 /// \param theSketch a sketch feature
134 /// \param thePoint1 the first point
135 /// \param thePoint2 the second point
136 static void createConstraint(CompositeFeaturePtr theSketch,
137 std::shared_ptr<GeomDataAPI_Point2D> thePoint1,
138 std::shared_ptr<GeomDataAPI_Point2D> thePoint2);
140 /// Create a sketch plane instance
141 /// \param theSketch a sketch feature
142 /// \return API object of geom plane
143 static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
145 /// Create a point 3D on a basis of point 2D and sketch feature
146 /// \param thePoint2D a point on a sketch
147 /// \param theSketch a sketch feature
148 /// \return API object of point 3D
149 static std::shared_ptr<GeomAPI_Pnt> point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
150 CompositeFeaturePtr theSketch);
152 /// Finds a line (arc or circle) by given edge
153 /// \param theShape an edge
154 /// \param theObject a selected result object
155 /// \param theSketch a sketch feature
156 /// \return result of found feature or NULL
157 static std::shared_ptr<ModelAPI_Result> findFixedObjectByExternal(
158 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 std::shared_ptr<ModelAPI_Result> createFixedObjectByExternal(
170 const TopoDS_Shape& theShape,
171 const ObjectPtr& theObject,
172 CompositeFeaturePtr theSketch,
173 const bool theTemporary = false);
175 /// Checks whether the list of selected presentations contains the given one
176 /// \param theSelected a list of presentations
177 /// \param thePrs a presentation to be found
178 /// \return - result of check, true if the list contains the prs
179 static bool isContainPresentation(const QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theSelected,
180 const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
182 /// Returns Result object if the given skietch contains external edge equal to the given
183 /// \param theSketch - the sketch feature
184 /// \param theEdge - the edge
185 /// \return result object with external edge if it is found
186 static std::shared_ptr<ModelAPI_Result> findExternalEdge(CompositeFeaturePtr theSketch,
187 std::shared_ptr<GeomAPI_Edge> theEdge);
189 /// Returns Result object if the given sketch contains external vertex equal to the given
190 /// \param theSketch - the sketch feature
191 /// \param theVert - the vertex
192 /// \return result object with external vertex if it is found
193 static std::shared_ptr<ModelAPI_Result> findExternalVertex(CompositeFeaturePtr theSketch,
194 std::shared_ptr<GeomAPI_Vertex> theVert);
196 /// Returns whether the selected presentation has a shape with the vertex type
197 /// \param thePrs a selected presentation
198 /// \param theSketch the sketch feature
199 /// \param theView a 3D view
200 /// \param theX the output horizontal coordinate of the point
201 /// \param theY the output vertical coordinate of the point
202 static bool hasVertexShape(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
203 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 std::shared_ptr<GeomAPI_Shape> 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 * Convertes parameters into a geom point
235 * \theEvent a Qt event to find mouse position
236 * \param theWindow view window to define eye of view
237 * \param theSketch to convert 3D point coordinates into coorditates of the sketch plane
239 static std::shared_ptr<GeomAPI_Pnt2d> getPnt2d(QMouseEvent* theEvent,
240 ModuleBase_IViewWindow* theWindow,
241 const FeaturePtr& theSketch);
244 * Gets all references to the feature, take coincidence constraint features, get point 2d attributes
245 * and compare the point value to be equal with the given. Returns the first feature, which has
247 * \param theFeature the coincidence feature
248 * \param thePoint a 2d point
249 * \return the coincidence feature or null
251 static FeaturePtr findFirstCoincidence(const FeaturePtr& theFeature,
252 std::shared_ptr<GeomAPI_Pnt2d> thePoint);
255 * Returns list of features connected in a councedence feature point
256 * \param theStartCoin the coincidence feature
257 * \param theList a list which collects lines features
258 * \param theCoincidencies a list of coincidence features
259 * \param theAttr the attribute name
261 static void findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
262 QList<FeaturePtr>& theCoincidencies,
263 std::string theAttr, QList<bool>& theIsAttributes);
266 * Returns point of a coincedence
267 * \param theStartCoin the coincedence feature
269 static std::shared_ptr<GeomAPI_Pnt2d> getCoincedencePoint(FeaturePtr theStartCoin);
271 /// Sends redisplay event for all sub-features of the composite. Flush it.
272 static void sendSubFeaturesEvent(const CompositeFeaturePtr& theComposite,
273 const Events_ID theId);
276 * Returns true if the object is a sketch entity, where auxiliary attribute has true vlaue
277 * \param theObject a result or feature
278 * \return boolean result
280 static bool isAuxiliarySketchEntity(const ObjectPtr& theObject);