Salome HOME
Update help for ellipse and elliptic arc.
[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 <GeomAPI_Shape.h>
29 #include <GeomDataAPI_Point2D.h>
30 #include <GeomAlgoAPI_ShapeTools.h>
31
32 #include <list>
33 #include <map>
34
35 class GeomAPI_AISObject;
36
37 class SketchPlugin_Constraint;
38 class SketchPlugin_Feature;
39 class SketchPlugin_Sketch;
40
41 namespace SketchPlugin_Tools {
42
43 /// Clears text expressions for all attributes of the feature
44 void clearExpressions(FeaturePtr theFeature);
45
46 /// \return coincidence point
47 /// \param[in] theStartCoin coincidence feature
48 std::shared_ptr<GeomAPI_Pnt2d> getCoincidencePoint(const FeaturePtr theStartCoin);
49
50 /// Find all Coincident constraints referred to the feature or its attribute
51 std::set<FeaturePtr> findCoincidentConstraints(const FeaturePtr& theFeature);
52
53 /// Finds lines coincident at point
54 /// \param[in] theStartCoin coincidence feature
55 /// \param[in] theAttr attribute name
56 /// \param[out] theList list of lines
57 /// \param[in] theIsAttrOnly if true includes only coincidences with attributes.
58 void findCoincidences(const FeaturePtr theStartCoin,
59                       const std::string& theAttr,
60                       std::set<FeaturePtr>& theList,
61                       const bool theIsAttrOnly = false);
62
63 /// Find all features the point is coincident to.
64 std::set<FeaturePtr> findFeaturesCoincidentToPoint(const AttributePoint2DPtr& thePoint);
65
66 /// Find all points the given point is coincident to.
67 std::set<AttributePoint2DPtr> findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint);
68
69 void resetAttribute(SketchPlugin_Feature* theFeature, const std::string& theId);
70
71 /// Create new constraint between given attributes
72 /// \param[in] theSketch          a sketch where the constraint will be created
73 /// \param[in] theConstraintId    a constraint identifier
74 /// \param[in] theFirstAttribute  an attribute of further constraint
75 /// \param[in] theSecondAttribute an attribute of further constraint
76 FeaturePtr createConstraintAttrAttr(SketchPlugin_Sketch* theSketch,
77                                     const std::string& theConstraintId,
78                                     const AttributePtr& theFirstAttribute,
79                                     const AttributePtr& theSecondAttribute);
80
81 /// Create new constraint between given attribute and object
82 /// \param[in] theSketch         a sketch where the constraint will be created
83 /// \param[in] theConstraintId   a constraint identifier
84 /// \param[in] theFirstAttribute an attribute of further constraint
85 /// \param[in] theSecondObject   an attribute of further constraint
86 FeaturePtr createConstraintAttrObject(SketchPlugin_Sketch* theSketch,
87                                       const std::string& theConstraintId,
88                                       const AttributePtr& theFirstAttribute,
89                                       const ObjectPtr& theSecondObject);
90
91 /// Create new constraint between given objects
92 /// \param[in] theSketch       a sketch where the constraint will be created
93 /// \param[in] theConstraintId a constraint identifier
94 /// \param[in] theFirstObject  an attribute of further constraint
95 /// \param[in] theSecondObject an attribute of further constraint
96 FeaturePtr createConstraintObjectObject(SketchPlugin_Sketch* theSketch,
97                                         const std::string& theConstraintId,
98                                         const ObjectPtr& theFirstObject,
99                                         const ObjectPtr& theSecondObject);
100
101 /// Creates coincidence or tangent constraint.
102 /// \param[in] theFeature to get selected attribute or object
103 /// \param[in] theId ID of attribute where selection is.
104 /// \param[in] theObject object for constraint
105 /// \param[in] theIsCanBeTangent if true constraint can be tangent or coincidence, depending on
106 ///                              the selection in the attribute with passed ID.
107 void createCoincidenceOrTangency(SketchPlugin_Feature* theFeature,
108                                  const std::string& theId,
109                                  const AttributePtr theAttr,
110                                  const ObjectPtr theObject,
111                                  const bool theIsCanBeTangent);
112
113 /// Creates auxiliary point for ellipse and corresponding internal constraint.
114 /// \param[in] theEllipse   base ellipse feature
115 /// \param[in] theAttrName  name of the attribute of the ellipse,
116 ///                         the new point should be constrained
117 void createAuxiliaryPointOnEllipse(const FeaturePtr& theEllipseFeature,
118                                    const std::string& theAttrName);
119
120 /// Creates auxiliary axis for ellipse and corresponding internal constraints.
121 /// \param[in] theEllipse   base ellipse feature
122 /// \param[in] theStartAttr name of the attribute of the ellipse, the line is started
123 /// \param[in] theEndAttr   name of the attribute of the ellipse, the line is ended
124 void createAuxiliaryAxisOfEllipse(const FeaturePtr& theEllipseFeature,
125                                   const std::string& theStartAttr,
126                                   const std::string& theEndAttr);
127
128 /// Creates passing point or tangent curve basing on the given attributes are initialized.
129 /// \param[in]  theRefAttr       prefered attribute to be converted
130 /// \param[in]  theDefaultAttr   default attribute if theRefAttr is not initialized
131 /// \param[out] theTangentCurve  tangent curve if theRefAttr refers to an edge
132 /// \param[out] thePassingPoint  passing point if theRefAttr does not refer to an edge
133 void convertRefAttrToPointOrTangentCurve(const AttributeRefAttrPtr&      theRefAttr,
134                                          const AttributePtr&             theDefaultAttr,
135                                          std::shared_ptr<GeomAPI_Shape>& theTangentCurve,
136                                          std::shared_ptr<GeomAPI_Pnt2d>& thePassingPoint);
137
138
139 /// Calculate global coordinates for flyout point of Length constraint
140 GeomPnt2dPtr flyoutPointCoordinates(const std::shared_ptr<SketchPlugin_Constraint>& theConstraint);
141 }; // namespace SketchPlugin_Tools
142
143 namespace SketchPlugin_SegmentationTools
144 {
145   /// Returns geom point attribute of the feature bounds. It processes line or arc.
146   /// For circle/ellipse feature, the result attributes are null
147   /// \param theFeature        a source feature
148   /// \param theStartPointAttr an out attribute to start point
149   /// \param theEndPointAttr   an out attribute to end point
150   void getFeaturePoints(const FeaturePtr& theFeature,
151                         std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
152                         std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
153
154   /// Obtains references to feature point attributes and to feature,
155   /// e.g. for feature line: 1st container is
156   ///             <1st line point, list<entity_a in distance, entity_b in parallel> >
157   ///             <2nd line point, list<> >
158   ///      for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
159   /// \param theFeature an investigated feature
160   /// \param theRefs a container of list of referenced attributes
161   /// \param theRefsToFeature references to the feature result
162   void getRefAttributes(const FeaturePtr& theFeature,
163                         std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
164                         std::list<AttributePtr>& theRefsToFeature);
165
166   /// Obtains a part of shape selected/highlighted in the viewer for Split/Trim operation
167   /// \param[in] theFeature            Split/Trim feature
168   /// \param[in] theObjectAttributeId  name of attribute containing selected object
169   /// \param[in] thePointAttributeId   name of attribute containing point selected on the object
170   GeomShapePtr getSubShape(
171       SketchPlugin_Feature* theFeature,
172       const std::string& theObjectAttributeId,
173       const std::string& thePointAttributeId,
174       std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
175       std::map<ObjectPtr, GeomAlgoAPI_ShapeTools::PointToRefsMap>& theObjectToPoints);
176
177   /// Fulfill an internal containers by shapes obtained from the parameter object
178   /// Shapes are results of Split/Trim operation by points coincident to shape of the object
179   /// \param theOpFeture an operation feature (Split/Trim)
180   /// \param theObject a source object (will be splitted)
181   void fillObjectShapes(
182       SketchPlugin_Feature* theOpFeature,
183       const ObjectPtr& theObject,
184       std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
185       std::map<ObjectPtr, GeomAlgoAPI_ShapeTools::PointToRefsMap>& theObjectToPoints);
186
187   /// AIS object for selected/highlighted part of splitting/triming feature
188   /// \param[in] thePrevious  previous presentation
189   /// \param[in] theOpFeture  an operation feature (Split/Trim)
190   std::shared_ptr<GeomAPI_AISObject> getAISObject(std::shared_ptr<GeomAPI_AISObject> thePrevious,
191                                                   SketchPlugin_Feature* theOpFeature,
192                                                   const std::string& thePreviewObjectAttrName,
193                                                   const std::string& thePreviewPointAttrName,
194                                                   const std::string& theSelectedObjectAttrName,
195                                                   const std::string& theSelectedPointAttrName);
196
197   /// Move constraints from attribute of base feature to attribute after modification
198   /// \param theBaseRefAttributes container of references to the attributes of base feature
199   /// \param theModifiedAttributes container of attributes placed instead of base attributes
200   /// at the same place
201   void updateRefAttConstraints(
202       const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
203       const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes);
204
205   /// Updates line length if it exist in the list
206   /// \param theFeaturesToUpdate a constraint index
207   void updateFeaturesAfterOperation(const std::set<FeaturePtr>& theFeaturesToUpdate);
208
209
210   /// Creates a line feature filled by center of base feature and given points
211   /// \param theBaseFeature another arc feature
212   /// \param theFirstAttribute an attribute with coordinates for the start point
213   /// \param theSecondAttribute an attribute with coordinates for the end point
214   FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
215                                const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
216                                const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
217
218   /// Creates a circular/elliptic arc feature filled by center
219   /// (or by center and focus for elliptic arc) of base feature and given points
220   /// \param theBaseFeature     another circle or ellipse or circular/elliptic arc
221   /// \param theFirstAttribute  an attribute with coordinates for the start point
222   /// \param theSecondAttribute an attribute with coordinates for the end point
223   FeaturePtr createArcFeature(
224       const FeaturePtr& theBaseFeature,
225       const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
226       const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
227
228 }; // namespace SketchPlugin_SegmentationTools
229
230 #endif // SKETCHPLUGIN_TOOLS_H_