1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_Trim.h
4 // Created: 22 Feb 2017
5 // Author: Natalia ERMOLAEVA
7 #ifndef SketchPlugin_Trim_H_
8 #define SketchPlugin_Trim_H_
10 #include "SketchPlugin.h"
11 #include <SketchPlugin_Sketch.h>
12 #include "SketchPlugin_ConstraintBase.h"
14 class GeomDataAPI_Point2D;
15 class ModelAPI_Feature;
16 class ModelAPI_Result;
17 class ModelAPI_Object;
19 typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
21 /** \class SketchPlugin_Trim
23 * \brief Feature for creation of a new constraint trimming object. Entities for split:
25 class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentable
28 /// Split constraint kind
29 inline static const std::string& ID()
31 static const std::string MY_TRIM_ID("SketchTrim");
34 /// \brief Returns the kind of a feature
35 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
37 static std::string MY_KIND = SketchPlugin_Trim::ID();
41 /// The value parameter for the constraint
42 inline static const std::string& SELECTED_OBJECT()
44 static const std::string MY_SELECTED_OBJECT("SelectedObject");
45 return MY_SELECTED_OBJECT;
48 /// Start 2D point of the split segment
49 inline static const std::string& SELECTED_POINT()
51 static const std::string MY_SELECTED_POINT("SelectedPoint");
52 return MY_SELECTED_POINT;
55 /// The value parameter for the preview object
56 inline static const std::string& PREVIEW_OBJECT()
58 static const std::string MY_PREVIEW_OBJECT("PreviewObject");
59 return MY_PREVIEW_OBJECT;
62 /// Start 2D point of the split segment
63 inline static const std::string& PREVIEW_POINT()
65 static const std::string MY_PREVIEW_POINT("PreviewPoint");
66 return MY_PREVIEW_POINT;
69 /// \brief Creates a new part document if needed
70 SKETCHPLUGIN_EXPORT virtual void execute();
72 /// \brief Request for initialization of data model of the feature: adding all attributes
73 SKETCHPLUGIN_EXPORT virtual void initAttributes();
75 /// Reimplemented from ModelAPI_Feature::isMacro()
77 SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
79 /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
80 /// This is necessary to perform execute only by apply the feature
81 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
83 /// \brief Use plugin manager for features creation
86 /// Returns the AIS preview
87 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
89 /// Moves the feature : Empty
90 SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
92 bool setCoincidenceToAttribute(const AttributePtr& theAttribute,
93 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences);
95 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
96 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
97 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
99 static void fillObjectShapes(const std::shared_ptr<ModelAPI_Object>& theObject,
100 const std::shared_ptr<ModelAPI_Object>& theSketch,
101 std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> >& theCashedShapes,
102 std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap>& theObjectToPoints);
105 GeomShapePtr getSubShape(const std::string& theObjectAttributeId,
106 const std::string& thePointAttributeId);
108 /// Returns geom point attribute of the feature bounds. It processes line or arc.
109 /// For circle feature, the result attributes are null
110 /// \param theFeature a source feature
111 /// \param theStartPointAttr an out attribute to start point
112 /// \param theStartPointAttr an out attribute to end point
113 void getFeaturePoints(const FeaturePtr& theFeature,
114 std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
115 std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
117 /// Obtains those constraints of the feature that should be modified. output maps contain
118 /// point of coincidence and attribute id to be modified after split
119 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
120 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
122 /// Obtains references to feature point attributes and to feature,
123 /// e.g. for feature line: 1st container is
124 /// <1st line point, list<entity_a in distance, entity_b in parallel> >
125 /// <2nd line point, list<> >
126 /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
127 /// \param theFeature an investigated feature
128 /// \param theRefs a container of list of referenced attributes
129 void getRefAttributes(const FeaturePtr& theFeature,
130 std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
131 std::list<AttributePtr>& theRefsToFeature);
133 /// Obtains coincident features to the given object. It is collected in a container
134 /// by the coincident attribute
135 /// \param theObject an investigated object
136 /// \param theCoincidencesToBaseFeature a container of list of referenced attributes
137 void getCoincidencesToObject(const std::shared_ptr<ModelAPI_Object>& theObject,
138 std::map<AttributePtr, FeaturePtr>& theCoincidencesToBaseFeature);
140 /// Move constraints from attribute of base feature to attribute after modification
141 /// \param theBaseRefAttributes container of references to the attributes of base feature
142 /// \param theModifiedAttributes container of attributes placed instead of base attributes
143 /// at the same place
144 void updateRefAttConstraints(
145 const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
146 const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
147 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
149 /// Make the base object is splitted by the point attributes
150 /// \param theSplitFeature a result split feature
151 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
152 /// \param theAfterFeature a feature between last point of split feature and the end point
153 /// \param thePoints a list of points where coincidences will be build
154 /// \param theModifiedAttributes a container of attribute on base
155 /// feature to attribute on new feature
156 void trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
157 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
158 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
159 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
161 /// Make the base object is splitted by the point attributes
162 /// \param theSplitFeature a result split feature
163 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
164 /// \param theAfterFeature a feature between last point of split feature and the end point
165 /// \param thePoints a list of points where coincidences will be build
166 void trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
167 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
168 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
169 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
171 /// Make the base object is splitted by the point attributes
172 /// \param theSplitFeature a result split feature
173 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
174 /// \param theAfterFeature a feature between last point of split feature and the end point
175 /// \param thePoints a list of points where coincidences will be build
176 FeaturePtr trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
177 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
178 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
179 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
181 /// Correct the first and the second point to provide condition that the first is closer to
182 /// the start point and the second point - to the last end of current segment. To rearrange
183 /// them if this condition is not satisfied.
184 /// \param theStartPointAttr a start point of a segment
185 /// \param theEndPointAttr an end point of a segment
186 /// \param theFirstPoint a start point of a segment
187 /// \param theSecondPoint an end point of a segment
188 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
189 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
190 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
191 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
193 /// Correct the first and the second point to provide condition that the first is closer to
194 /// the start point and the second point - to the last end of current segment. To rearrange
195 /// them if this condition is not satisfied.
196 /// \param theArc an arc to be split
197 /// \param theStartPointAttr a start point of a segment
198 /// \param theEndPointAttr an end point of a segment
199 /// \param theFirstPoint a start point of a segment
200 /// \param theSecondPoint an end point of a segment
201 void arrangePointsOnArc(const FeaturePtr& theArc,
202 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
203 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
204 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
205 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
207 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
208 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
209 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
210 void fillAttribute(const AttributePtr& theModifiedAttribute,
211 const AttributePtr& theSourceAttribute);
213 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
214 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
215 /// \param thePoint a point value
216 void fillPointAttribute(const AttributePtr& theModifiedAttribute,
217 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
219 /// Creates a line feature filled by center of base feature and given points
220 /// \param theBaseFeature another arc feature
221 /// \param theFirstAttribute an attribute with coordinates for the start point
222 /// \param theSecondAttribute an attribute with coordinates for the end point
223 FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
224 const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
225 const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
227 /// Creates an arc feature filled by center of base feature and given points
228 /// \param theBaseFeature another arc feature
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(const FeaturePtr& theBaseFeature,
232 const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
233 const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
235 /// Add feature coincidence constraint between given attributes
236 /// \param theConstraintId a constraint index
237 /// \param theFirstAttribute an attribute of further coincidence
238 /// \param theSecondAttribute an attribute of further coincidence
239 std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
240 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
241 const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
243 /// Add feature coincidence constraint between given attributes
244 /// \param theConstraintId a constraint index
245 /// \param theFirstAttribute an attribute of further coincidence
246 /// \param theSecondObject an object of further coincidence
247 std::shared_ptr<ModelAPI_Feature> createConstraintToObject(const std::string& theConstraintId,
248 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
249 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
251 /// Add feature coincidence constraint between given attributes
252 /// \param theConstraintId a constraint index
253 /// \param theFirstAttribute an attribute of further coincidence
254 /// \param theFirstAttribute an attribute of further coincidence
255 std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
256 const std::shared_ptr<ModelAPI_Object>& theFirstObject,
257 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
259 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
260 /// \param theFeature a feature
261 /// \return result object
262 std::shared_ptr<ModelAPI_Result> getFeatureResult(
263 const std::shared_ptr<ModelAPI_Feature>& theFeature);
266 void findShapePoints(const std::string& theObjectAttributeId,
267 const std::string& thePointAttributeId,
268 std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
269 std::shared_ptr<GeomAPI_Pnt>& aLastPoint);
271 std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
274 std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
275 std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap> myObjectToPoints;