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