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 <ModelAPI_IReentrant.h>
12 #include "SketchPlugin.h"
13 #include "SketchPlugin_ConstraintBase.h"
14 #include <SketchPlugin_Sketch.h>
16 class GeomDataAPI_Point2D;
17 class ModelAPI_Feature;
18 class ModelAPI_Result;
19 class ModelAPI_Object;
21 typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
23 /** \class SketchPlugin_Trim
25 * \brief Feature for creation of a new constraint trimming object. Entities for split:
27 class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentable,
28 public ModelAPI_IReentrant
31 /// Split constraint kind
32 inline static const std::string& ID()
34 static const std::string MY_TRIM_ID("SketchTrim");
37 /// \brief Returns the kind of a feature
38 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
40 static std::string MY_KIND = SketchPlugin_Trim::ID();
44 /// The value parameter for the constraint
45 inline static const std::string& SELECTED_OBJECT()
47 static const std::string MY_SELECTED_OBJECT("SelectedObject");
48 return MY_SELECTED_OBJECT;
51 /// Start 2D point of the split segment
52 inline static const std::string& SELECTED_POINT()
54 static const std::string MY_SELECTED_POINT("SelectedPoint");
55 return MY_SELECTED_POINT;
58 /// The value parameter for the preview object
59 inline static const std::string& PREVIEW_OBJECT()
61 static const std::string MY_PREVIEW_OBJECT("PreviewObject");
62 return MY_PREVIEW_OBJECT;
65 /// Start 2D point of the split segment
66 inline static const std::string& PREVIEW_POINT()
68 static const std::string MY_PREVIEW_POINT("PreviewPoint");
69 return MY_PREVIEW_POINT;
72 /// \brief Creates a new part document if needed
73 SKETCHPLUGIN_EXPORT virtual void execute();
75 /// \brief Request for initialization of data model of the feature: adding all attributes
76 SKETCHPLUGIN_EXPORT virtual void initAttributes();
78 /// Reimplemented from ModelAPI_Feature::isMacro()
80 SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
82 /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
83 /// This is necessary to perform execute only by apply the feature
84 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
86 /// \brief Use plugin manager for features creation
89 /// Returns the AIS preview
90 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
92 /// Moves the feature : Empty
93 SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
95 /// Apply information of the message to current object. It fills selected point and object
96 virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
98 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
99 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
100 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
102 static void fillObjectShapes(const std::shared_ptr<ModelAPI_Object>& theObject,
103 const std::shared_ptr<ModelAPI_Object>& theSketch,
104 std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> >& theCashedShapes,
105 std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap>& theObjectToPoints);
108 bool setCoincidenceToAttribute(const AttributePtr& theAttribute,
109 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences);
111 bool replaceCoincidenceAttribute(const AttributePtr& theCoincidenceAttribute,
112 const std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
114 GeomShapePtr getSubShape(const std::string& theObjectAttributeId,
115 const std::string& thePointAttributeId);
117 /// Returns geom point attribute of the feature bounds. It processes line or arc.
118 /// For circle feature, the result attributes are null
119 /// \param theFeature a source feature
120 /// \param theStartPointAttr an out attribute to start point
121 /// \param theStartPointAttr an out attribute to end point
122 void getFeaturePoints(const FeaturePtr& theFeature,
123 std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
124 std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
126 /// Obtains those constraints of the feature that should be modified. output maps contain
127 /// point of coincidence and attribute id to be modified after split
128 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
129 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
131 /// Obtains references to feature point attributes and to feature,
132 /// e.g. for feature line: 1st container is
133 /// <1st line point, list<entity_a in distance, entity_b in parallel> >
134 /// <2nd line point, list<> >
135 /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
136 /// \param theFeature an investigated feature
137 /// \param theRefs a container of list of referenced attributes
138 void getRefAttributes(const FeaturePtr& theFeature,
139 std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
140 std::list<AttributePtr>& theRefsToFeature);
142 /// Obtains coincident features to the given object. It is collected in a container
143 /// by the coincident attribute
144 /// \param theObject an investigated object
145 /// \param theCoincidencesToBaseFeature a container of list of referenced attributes
146 //void getCoincidencesToObject(const std::shared_ptr<ModelAPI_Object>& theObject,
147 // std::map<AttributePtr, FeaturePtr>& theCoincidencesToBaseFeature);
149 /// Move constraints from attribute of base feature to attribute after modification
150 /// \param theBaseRefAttributes container of references to the attributes of base feature
151 /// \param theModifiedAttributes container of attributes placed instead of base attributes
152 /// at the same place
153 void updateRefAttConstraints(
154 const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
155 const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
156 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
158 /// Remove references constraints from attribute of base feature refer to the given attribute
159 /// \param theAttribute an attribute
160 /// \param theModifiedAttributes modifiable container of attributes
161 void removeReferencesToAttribute(const AttributePtr& theAttribute,
162 std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes);
164 /// Make the base object is splitted by the point attributes
165 /// \param theBaseRefAttributes container of references to the attributes of base feature
166 /// \param thePoints a list of points where coincidences will be build
167 /// \param theModifiedAttributes a container of attribute on base
168 /// feature to attribute on new feature
169 /// \return new line if it was created
170 FeaturePtr trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
171 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
172 std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
173 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
174 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
176 /// Make the base object is splitted by the point attributes
177 /// \param thePoints a list of points where coincidences will be build
178 /// \return new line if it was created
179 FeaturePtr trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
180 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
181 std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
182 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
183 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
185 /// Make the base object is splitted by the point attributes
186 /// \param thePoints a list of points where coincidences will be build
187 FeaturePtr trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
188 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
189 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
190 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
192 /// Correct the first and the second point to provide condition that the first is closer to
193 /// the start point and the second point - to the last end of current segment. To rearrange
194 /// them if this condition is not satisfied.
195 /// \param theStartPointAttr a start point of a segment
196 /// \param theEndPointAttr an end point of a segment
197 /// \param theFirstPoint a start point of a segment
198 /// \param theSecondPoint an end point of a segment
199 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
200 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
201 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
202 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
204 /// Correct the first and the second point to provide condition that the first is closer to
205 /// the start point and the second point - to the last end of current segment. To rearrange
206 /// them if this condition is not satisfied.
207 /// \param theArc an arc to be split
208 /// \param theStartPointAttr a start point of a segment
209 /// \param theEndPointAttr an end point of a segment
210 /// \param theFirstPoint a start point of a segment
211 /// \param theSecondPoint an end point of a segment
212 void arrangePointsOnArc(const FeaturePtr& theArc,
213 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
214 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
215 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
216 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
218 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
219 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
220 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
221 void fillAttribute(const AttributePtr& theModifiedAttribute,
222 const AttributePtr& theSourceAttribute);
224 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
225 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
226 /// \param thePoint a point value
227 void fillPointAttribute(const AttributePtr& theModifiedAttribute,
228 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
230 /// Creates a line feature filled by center of base feature and given points
231 /// \param theBaseFeature another arc feature
232 /// \param theFirstAttribute an attribute with coordinates for the start point
233 /// \param theSecondAttribute an attribute with coordinates for the end point
234 FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
235 const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
236 const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
238 /// Creates an arc feature filled by center of base feature and given points
239 /// \param theBaseFeature another arc feature
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(const FeaturePtr& theBaseFeature,
243 const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
244 const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
246 /// Add feature coincidence constraint between given attributes
247 /// \param theConstraintId a constraint index
248 /// \param theFirstAttribute an attribute of further coincidence
249 /// \param theSecondAttribute an attribute of further coincidence
250 std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
251 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
252 const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
254 /// Add feature coincidence constraint between given attributes
255 /// \param theConstraintId a constraint index
256 /// \param theFirstAttribute an attribute of further coincidence
257 /// \param theSecondObject an object of further coincidence
258 std::shared_ptr<ModelAPI_Feature> createConstraintToObject(const std::string& theConstraintId,
259 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
260 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
262 /// Add feature coincidence constraint between given attributes
263 /// \param theConstraintId a constraint index
264 /// \param theFirstAttribute an attribute of further coincidence
265 /// \param theFirstAttribute an attribute of further coincidence
266 std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
267 const std::shared_ptr<ModelAPI_Object>& theFirstObject,
268 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
270 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
271 /// \param theFeature a feature
272 /// \return result object
273 std::shared_ptr<ModelAPI_Result> getFeatureResult(
274 const std::shared_ptr<ModelAPI_Feature>& theFeature);
277 void findShapePoints(const std::string& theObjectAttributeId,
278 const std::string& thePointAttributeId,
279 std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
280 std::shared_ptr<GeomAPI_Pnt>& aLastPoint);
282 std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
285 std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
286 std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap> myObjectToPoints;