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