1 // Copyright (C) 2014-2019 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
20 #ifndef SKETCHPLUGIN_TOOLS_H_
21 #define SKETCHPLUGIN_TOOLS_H_
23 #include <GeomAPI_Pnt2d.h>
25 #include <ModelAPI_Feature.h>
26 #include <ModelAPI_Attribute.h>
27 #include <ModelAPI_AttributeRefAttr.h>
28 #include <GeomDataAPI_Point2D.h>
30 class SketchPlugin_Constraint;
31 class SketchPlugin_Feature;
32 class SketchPlugin_Sketch;
34 namespace SketchPlugin_Tools {
36 /// Clears text expressions for all attributes of the feature
37 void clearExpressions(FeaturePtr theFeature);
39 /// \return coincidence point
40 /// \param[in] theStartCoin coincidence feature
41 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(const FeaturePtr theStartCoin);
43 /// Find all Coincident constraints referred to the feature or its attribute
44 std::set<FeaturePtr> findCoincidentConstraints(const FeaturePtr& theFeature);
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);
56 /// Find all features the point is coincident to.
57 std::set<FeaturePtr> findFeaturesCoincidentToPoint(const AttributePoint2DPtr& thePoint);
59 /// Find all points the given point is coincident to.
60 std::set<AttributePoint2DPtr> findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint);
62 void resetAttribute(SketchPlugin_Feature* theFeature, const std::string& theId);
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);
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);
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);
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);
106 /// Creates passing point or tangent curve basing on the given attributes are initialized.
107 /// \param[in] theRefAttr prefered attribute to be converted
108 /// \param[in] theDefaultAttr default attribute if theRefAttr is not initialized
109 /// \param[out] theTangentCurve tangent curve if theRefAttr refers to an edge
110 /// \param[out] thePassingPoint passing point if theRefAttr does not refer to an edge
111 void convertRefAttrToPointOrTangentCurve(const AttributeRefAttrPtr& theRefAttr,
112 const AttributePtr& theDefaultAttr,
113 std::shared_ptr<GeomAPI_Shape>& theTangentCurve,
114 std::shared_ptr<GeomAPI_Pnt2d>& thePassingPoint);
117 /// Calculate global coordinates for flyout point of Length constraint
118 GeomPnt2dPtr flyoutPointCoordinates(const std::shared_ptr<SketchPlugin_Constraint>& theConstraint);
119 }; // namespace SketchPlugin_Tools
121 #endif // SKETCHPLUGIN_TOOLS_H_