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