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;
18 typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
20 /** \class SketchPlugin_Trim
22 * \brief Feature for creation of a new constraint trimming object. Entities for split:
24 class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentable
27 /// Split constraint kind
28 inline static const std::string& ID()
30 static const std::string MY_TRIM_ID("SketchTrim");
33 /// \brief Returns the kind of a feature
34 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
36 static std::string MY_KIND = SketchPlugin_Trim::ID();
40 /// The value parameter for the constraint
41 inline static const std::string& SELECTED_OBJECT()
43 static const std::string MY_SELECTED_OBJECT("SelectedObject");
44 return MY_SELECTED_OBJECT;
47 /// Start 2D point of the split segment
48 inline static const std::string& SELECTED_POINT()
50 static const std::string MY_SELECTED_POINT("SelectedPoint");
51 return MY_SELECTED_POINT;
54 /// The value parameter for the preview object
55 inline static const std::string& PREVIEW_OBJECT()
57 static const std::string MY_PREVIEW_OBJECT("PreviewObject");
58 return MY_PREVIEW_OBJECT;
61 /// Start 2D point of the split segment
62 inline static const std::string& PREVIEW_POINT()
64 static const std::string MY_PREVIEW_POINT("PreviewPoint");
65 return MY_PREVIEW_POINT;
68 /// \brief Creates a new part document if needed
69 SKETCHPLUGIN_EXPORT virtual void execute();
71 /// \brief Request for initialization of data model of the feature: adding all attributes
72 SKETCHPLUGIN_EXPORT virtual void initAttributes();
74 /// Reimplemented from ModelAPI_Feature::isMacro()
76 SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
78 /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
79 /// This is necessary to perform execute only by apply the feature
80 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
82 /// \brief Use plugin manager for features creation
85 /// Returns the AIS preview
86 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
88 /// Moves the feature : Empty
89 SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
91 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
92 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
93 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
95 static void fillObjectShapes(const ObjectPtr& theObject,
97 std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
98 std::map<ObjectPtr, PointToRefsMap>& theObjectToPoints);
101 GeomShapePtr getSubShape(const std::string& theObjectAttributeId,
102 const std::string& thePointAttributeId);
104 /// Returns geom point attribute of the feature bounds. It processes line or arc.
105 /// For circle feature, the result attributes are null
106 /// \param theFeature a source feature
107 /// \param theStartPointAttr an out attribute to start point
108 /// \param theStartPointAttr an out attribute to end point
109 void getFeaturePoints(const FeaturePtr& theFeature,
110 std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
111 std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
113 /// Obtains those constraints of the feature that should be modified. output maps contain
114 /// point of coincidence and attribute id to be modified after split
115 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
116 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
118 /// Obtains references to feature point attributes and to feature,
119 /// e.g. for feature line: 1st container is
120 /// <1st line point, list<entity_a in distance, entity_b in parallel> >
121 /// <2nd line point, list<> >
122 /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
123 /// \param theFeature an investigated feature
124 /// \param theRefs a container of list of referenced attributes
125 void getRefAttributes(const FeaturePtr& theFeature,
126 std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
127 std::list<AttributePtr>& theRefsToFeature);
129 /// Obtains coincident features to the given object. It is collected in a container
130 /// by the coincident attribute
131 /// \param theObject an investigated object
132 /// \param theCoincidencesToBaseFeature a container of list of referenced attributes
133 void getCoincidencesToObject(const ObjectPtr& theObject,
134 std::map<AttributePtr, FeaturePtr>& theCoincidencesToBaseFeature);
136 /// Move constraints from attribute of base feature to attribute after modification
137 /// \param theBaseRefAttributes container of references to the attributes of base feature
138 /// \param theModifiedAttributes container of attributes placed instead of base attributes
139 /// at the same place
140 void updateRefAttConstraints(
141 const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
142 const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
143 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
145 /// Make the base object is splitted by the point attributes
146 /// \param theSplitFeature a result split feature
147 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
148 /// \param theAfterFeature a feature between last point of split feature and the end point
149 /// \param thePoints a list of points where coincidences will be build
150 /// \param theModifiedAttributes a container of attribute on base
151 /// feature to attribute on new feature
152 void trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
153 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
154 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
155 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
157 /// Make the base object is splitted by the point attributes
158 /// \param theSplitFeature a result split feature
159 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
160 /// \param theAfterFeature a feature between last point of split feature and the end point
161 /// \param thePoints a list of points where coincidences will be build
162 void trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
163 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
164 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
165 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
167 /// Make the base object is splitted by the point attributes
168 /// \param theSplitFeature a result split feature
169 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
170 /// \param theAfterFeature a feature between last point of split feature and the end point
171 /// \param thePoints a list of points where coincidences will be build
172 FeaturePtr trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
173 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
174 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
175 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
177 /// Correct the first and the second point to provide condition that the first is closer to
178 /// the start point and the second point - to the last end of current segment. To rearrange
179 /// them if this condition is not satisfied.
180 /// \param theStartPointAttr a start point of a segment
181 /// \param theEndPointAttr an end point of a segment
182 /// \param theFirstPoint a start point of a segment
183 /// \param theSecondPoint an end point of a segment
184 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
185 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
186 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
187 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
189 /// Correct the first and the second point to provide condition that the first is closer to
190 /// the start point and the second point - to the last end of current segment. To rearrange
191 /// them if this condition is not satisfied.
192 /// \param theArc an arc to be split
193 /// \param theStartPointAttr a start point of a segment
194 /// \param theEndPointAttr an end point of a segment
195 /// \param theFirstPoint a start point of a segment
196 /// \param theSecondPoint an end point of a segment
197 void arrangePointsOnArc(const FeaturePtr& theArc,
198 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
199 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
200 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
201 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
203 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
204 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
205 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
206 void fillAttribute(const AttributePtr& theModifiedAttribute,
207 const AttributePtr& theSourceAttribute);
209 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
210 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
211 /// \param thePoint a point value
212 void fillPointAttribute(const AttributePtr& theModifiedAttribute,
213 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
215 /// Creates a line feature filled by center of base feature and given points
216 /// \param theBaseFeature another arc feature
217 /// \param theFirstAttribute an attribute with coordinates for the start point
218 /// \param theSecondAttribute an attribute with coordinates for the end point
219 FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
220 const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
221 const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
223 /// Creates an arc feature filled by center of base feature and given points
224 /// \param theBaseFeature another arc feature
225 /// \param theFirstAttribute an attribute with coordinates for the start point
226 /// \param theSecondAttribute an attribute with coordinates for the end point
227 FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
228 const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
229 const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
231 /// Add feature coincidence constraint between given attributes
232 /// \param theConstraintId a constraint index
233 /// \param theFirstAttribute an attribute of further coincidence
234 /// \param theSecondAttribute an attribute of further coincidence
235 std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
236 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
237 const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
239 /// Add feature coincidence constraint between given attributes
240 /// \param theConstraintId a constraint index
241 /// \param theFirstAttribute an attribute of further coincidence
242 /// \param theSecondObject an object of further coincidence
243 std::shared_ptr<ModelAPI_Feature> createConstraintToObject(const std::string& theConstraintId,
244 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
245 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
247 /// Add feature coincidence constraint between given attributes
248 /// \param theConstraintId a constraint index
249 /// \param theFirstAttribute an attribute of further coincidence
250 /// \param theFirstAttribute an attribute of further coincidence
251 std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
252 const std::shared_ptr<ModelAPI_Object>& theFirstObject,
253 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
255 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
256 /// \param theFeature a feature
257 /// \return result object
258 std::shared_ptr<ModelAPI_Result> getFeatureResult(
259 const std::shared_ptr<ModelAPI_Feature>& theFeature);
262 void findShapePoints(const std::string& theObjectAttributeId,
263 const std::string& thePointAttributeId,
264 std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
265 std::shared_ptr<GeomAPI_Pnt>& aLastPoint);
267 std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
270 std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
272 std::map<ObjectPtr, PointToRefsMap> myObjectToPoints;