Salome HOME
Issue #2618: PlaneGCS errors processing
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Tools.h
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
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.
7 //
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.
12 //
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
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #ifndef SKETCHPLUGIN_TOOLS_H_
22 #define SKETCHPLUGIN_TOOLS_H_
23
24 #include <GeomAPI_Pnt2d.h>
25
26 #include <ModelAPI_Feature.h>
27 #include <ModelAPI_Attribute.h>
28 #include <ModelAPI_AttributeRefAttr.h>
29 #include <GeomDataAPI_Point2D.h>
30
31 class SketchPlugin_Constraint;
32 class SketchPlugin_Feature;
33 class SketchPlugin_Sketch;
34
35 namespace SketchPlugin_Tools {
36
37 /// Clears text expressions for all attributes of the feature
38 void clearExpressions(FeaturePtr theFeature);
39
40 /// \return coincidence point
41 /// \param[in] theStartCoin coincidence feature
42 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(const FeaturePtr theStartCoin);
43
44 /// Find all Coincident constraints referred to the feature or its attribute
45 std::set<FeaturePtr> findCoincidentConstraints(const FeaturePtr& theFeature);
46
47 /// Finds lines coincident at point
48 /// \param[in] theStartCoin coincidence feature
49 /// \param[in] theAttr attribute name
50 /// \param[out] theList list of lines
51 /// \param[in] theIsAttrOnly if true includes only coincidences with attributes.
52 void findCoincidences(const FeaturePtr theStartCoin,
53                       const std::string& theAttr,
54                       std::set<FeaturePtr>& theList,
55                       const bool theIsAttrOnly = false);
56
57 /// Find all features the point is coincident to.
58 std::set<FeaturePtr> findFeaturesCoincidentToPoint(const AttributePoint2DPtr& thePoint);
59
60 /// Find all points the given point is coincident to.
61 std::set<AttributePoint2DPtr> findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint);
62
63 void resetAttribute(SketchPlugin_Feature* theFeature, const std::string& theId);
64
65 /// Create new constraint between given attributes
66 /// \param[in] theSketch          a sketch where the constraint will be created
67 /// \param[in] theConstraintId    a constraint identifier
68 /// \param[in] theFirstAttribute  an attribute of further constraint
69 /// \param[in] theSecondAttribute an attribute of further constraint
70 FeaturePtr createConstraintAttrAttr(SketchPlugin_Sketch* theSketch,
71                                     const std::string& theConstraintId,
72                                     const AttributePtr& theFirstAttribute,
73                                     const AttributePtr& theSecondAttribute);
74
75 /// Create new constraint between given attribute and object
76 /// \param[in] theSketch         a sketch where the constraint will be created
77 /// \param[in] theConstraintId   a constraint identifier
78 /// \param[in] theFirstAttribute an attribute of further constraint
79 /// \param[in] theSecondObject   an attribute of further constraint
80 FeaturePtr createConstraintAttrObject(SketchPlugin_Sketch* theSketch,
81                                       const std::string& theConstraintId,
82                                       const AttributePtr& theFirstAttribute,
83                                       const ObjectPtr& theSecondObject);
84
85 /// Create new constraint between given objects
86 /// \param[in] theSketch       a sketch where the constraint will be created
87 /// \param[in] theConstraintId a constraint identifier
88 /// \param[in] theFirstObject  an attribute of further constraint
89 /// \param[in] theSecondObject an attribute of further constraint
90 FeaturePtr createConstraintObjectObject(SketchPlugin_Sketch* theSketch,
91                                         const std::string& theConstraintId,
92                                         const ObjectPtr& theFirstObject,
93                                         const ObjectPtr& theSecondObject);
94
95 /// Creates coincidence or tangent constraint.
96 /// \param[in] theFeature to get selected attribute or object
97 /// \param[in] theId ID of attribute where selection is.
98 /// \param[in] theObject object for constraint
99 /// \param[in] theIsCanBeTangent if true constraint can be tangent or coincidence, depending on
100 ///                              the selection in the attribute with passed ID.
101 void createCoincidenceOrTangency(SketchPlugin_Feature* theFeature,
102                                  const std::string& theId,
103                                  const AttributePtr theAttr,
104                                  const ObjectPtr theObject,
105                                  const bool theIsCanBeTangent);
106
107 /// Creates passing point or tangent curve basing on the given attributes are initialized.
108 /// \param[in]  theRefAttr       prefered attribute to be converted
109 /// \param[in]  theDefaultAttr   default attribute if theRefAttr is not initialized
110 /// \param[out] theTangentCurve  tangent curve if theRefAttr refers to an edge
111 /// \param[out] thePassingPoint  passing point if theRefAttr does not refer to an edge
112 void convertRefAttrToPointOrTangentCurve(const AttributeRefAttrPtr&      theRefAttr,
113                                          const AttributePtr&             theDefaultAttr,
114                                          std::shared_ptr<GeomAPI_Shape>& theTangentCurve,
115                                          std::shared_ptr<GeomAPI_Pnt2d>& thePassingPoint);
116
117
118 /// Calculate global coordinates for flyout point of Length constraint
119 GeomPnt2dPtr flyoutPointCoordinates(const std::shared_ptr<SketchPlugin_Constraint>& theConstraint);
120 }; // namespace SketchPlugin_Tools
121
122 #endif // SKETCHPLUGIN_TOOLS_H_