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& BASE_OBJECT()
43 static const std::string MY_CONSTRAINT_BASE_OBJECT("BaseObject");
44 return MY_CONSTRAINT_BASE_OBJECT;
47 /// Start 2D point of the split segment
48 inline static const std::string& ENTITY_POINT()
50 static const std::string MY_ENTITY_POINT("ConstraintEntityPoint");
51 return MY_ENTITY_POINT;
54 /// \brief Creates a new part document if needed
55 SKETCHPLUGIN_EXPORT virtual void execute();
57 /// \brief Request for initialization of data model of the feature: adding all attributes
58 SKETCHPLUGIN_EXPORT virtual void initAttributes();
60 /// Reimplemented from ModelAPI_Feature::isMacro()
62 SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
64 /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
65 /// This is necessary to perform execute only by apply the feature
66 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
68 /// Called on change of any argument-attribute of this object
69 /// \param theID identifier of changed attribute
70 SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
72 /// \brief Use plugin manager for features creation
75 /// Returns the AIS preview
76 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
78 /// Moves the feature : Empty
79 SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
82 /// Returns geom point attribute of the feature bounds. It processes line or arc.
83 /// For circle feature, the result attributes are null
84 /// \param theFeature a source feature
85 /// \param theStartPointAttr an out attribute to start point
86 /// \param theStartPointAttr an out attribute to end point
87 void getFeaturePoints(const FeaturePtr& theFeature,
88 std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
89 std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
91 /// Obtains those constraints of the feature that should be modified. output maps contain
92 /// point of coincidence and attribute id to be modified after split
93 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
94 /// \param theFeaturesToUpdate [out] constrains that will be updated after split
95 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
96 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate);
98 /// Obtains references to feature point attributes and to feature,
99 /// e.g. for feature line: 1st container is
100 /// <1st line point, list<entity_a in distance, entity_b in parallel> >
101 /// <2nd line point, list<> >
102 /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
103 /// \param theFeature an investigated feature
104 /// \param theRefs a container of list of referenced attributes
105 void getRefAttributes(const FeaturePtr& theFeature,
106 std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
107 std::list<AttributePtr>& theRefsToFeature);
109 /// Move constraints from base feature to given feature
110 /// \param theFeature a base feature
111 /// \param theRefsToFeature list of attributes referenced to base feature
112 void updateRefFeatureConstraints(const std::shared_ptr<ModelAPI_Result>& theFeatureBaseResult,
113 const std::list<AttributePtr>& theRefsToFeature);
115 /// Move constraints from attribute of base feature to attribute after modification
116 /// \param theBaseRefAttributes container of references to the attributes of base feature
117 /// \param theModifiedAttributes container of attributes placed instead of base attributes
118 /// at the same place
119 void updateRefAttConstraints(
120 const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
121 const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
122 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
124 // /// Make the base object is splitted by the point attributes
125 // /// \param theSplitFeature a result split feature
126 // /// \param theBeforeFeature a feature between start point and the 1st point of split feature
127 // /// \param theAfterFeature a feature between last point of split feature and the end point
128 // /// \param thePoints a list of points where coincidences will be build
129 // /// \param theCreatedFeatures a container of created features
130 // /// \param theModifiedAttributes a container of attribute on base
131 // /// feature to attribute on new feature
132 void trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
133 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
134 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
135 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
136 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
138 /// Make the base object is splitted by the point attributes
139 /// \param theSplitFeature a result split feature
140 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
141 /// \param theAfterFeature a feature between last point of split feature and the end point
142 /// \param thePoints a list of points where coincidences will be build
143 /// \param theCreatedFeatures a container of created features
144 void trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
145 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
146 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
147 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
148 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
150 /// Make the base object is splitted by the point attributes
151 /// \param theSplitFeature a result split feature
152 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
153 /// \param theAfterFeature a feature between last point of split feature and the end point
154 /// \param thePoints a list of points where coincidences will be build
155 /// \param theCreatedFeatures a container of created features
156 void trimCircle(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::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
160 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
162 /// Correct the first and the second point to provide condition that the first is closer to
163 /// the start point and the second point - to the last end of current segment. To rearrange
164 /// them if this condition is not satisfied.
165 /// \param theStartPointAttr a start point of a segment
166 /// \param theEndPointAttr an end point of a segment
167 /// \param theFirstPoint a start point of a segment
168 /// \param theSecondPoint an end point of a segment
169 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
170 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
171 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
172 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
174 /// Correct the first and the second point to provide condition that the first is closer to
175 /// the start point and the second point - to the last end of current segment. To rearrange
176 /// them if this condition is not satisfied.
177 /// \param theArc an arc to be split
178 /// \param theStartPointAttr a start point of a segment
179 /// \param theEndPointAttr an end point of a segment
180 /// \param theFirstPoint a start point of a segment
181 /// \param theSecondPoint an end point of a segment
182 void arrangePointsOnArc(const FeaturePtr& theArc,
183 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
184 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
185 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
186 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
188 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
189 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
190 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
191 void fillAttribute(const AttributePtr& theModifiedAttribute,
192 const AttributePtr& theSourceAttribute);
194 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
195 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
196 /// \param thePoint a point value
197 void fillPointAttribute(const AttributePtr& theModifiedAttribute,
198 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
200 /// Creates a line feature filled by center of base feature and given points
201 /// \param theBaseFeature another arc feature
202 /// \param theFirstAttribute an attribute with coordinates for the start point
203 /// \param theSecondAttribute an attribute with coordinates for the end point
204 FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
205 const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
206 const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
208 /// Creates an arc feature filled by center of base feature and given points
209 /// \param theBaseFeature another arc feature
210 /// \param theFirstAttribute an attribute with coordinates for the start point
211 /// \param theSecondAttribute an attribute with coordinates for the end point
212 FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
213 const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
214 const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
216 /// Add feature coincidence constraint between given attributes
217 /// \param theConstraintId a constraint index
218 /// \param theFirstAttribute an attribute of further coincidence
219 /// \param theSecondAttribute an attribute of further coincidence
220 std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
221 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
222 const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
224 /// Add feature coincidence constraint between given attributes
225 /// \param theConstraintId a constraint index
226 /// \param theFirstAttribute an attribute of further coincidence
227 /// \param theSecondObject an object of further coincidence
228 std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
229 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
230 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
232 /// Add feature coincidence constraint between given attributes
233 /// \param theConstraintId a constraint index
234 /// \param theFirstAttribute an attribute of further coincidence
235 /// \param theFirstAttribute an attribute of further coincidence
236 std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
237 const std::shared_ptr<ModelAPI_Object>& theFirstObject,
238 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
240 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
241 /// \param theFeature a feature
242 /// \return result object
243 std::shared_ptr<ModelAPI_Result> getFeatureResult(
244 const std::shared_ptr<ModelAPI_Feature>& theFeature);
247 bool useGraphicIntersection() const;
249 void fillObjectShapes(const ObjectPtr& theObject);
251 void findShapePoints(std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
252 std::shared_ptr<GeomAPI_Pnt>& aLastPoint);
254 std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
257 std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
259 typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
260 std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
261 std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
263 std::map<ObjectPtr, PointToRefsMap> myObjectToPoints;