1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_ConstraintSplit.h
4 // Created: 25 Aug 2016
5 // Author: Natalia ERMOLAEVA
7 #ifndef SketchPlugin_ConstraintSplit_H_
8 #define SketchPlugin_ConstraintSplit_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_ConstraintSplit
22 * \brief Feature for creation of a new constraint splitting object. Entities for split:
23 * - Linear segment by point(s) on this line
24 * - Arc by point(s) on this arc
25 * - Circle by at least 2 split-points on this circle
27 * The following constraints will be applied after split to keep the divided segments geometry:
28 * - Coincident constraints for both parts of created segments in the point of splitting
29 * - For linear segments parallel, for circles
\96 tangent constraint, for arc
\96 tangent and equal
30 * constraints. In case of three segments in result two couple of constraints are created
31 * - parallel and equal constraints: the first is between 1st and middle entity, the second is
32 * between 1st and 3rd.
33 * - tangency constraints: the first between 1st and 2nd, the second between 2nd and 3rd.
34 * - Constraints assigned to the feature before split operation are assigned after using rules:
35 * - Coincident constraints are assigned to the segment where they belong to. Segment of split
36 * has only a coincidence to the neighbor segment. All constraints used in the splitting of
37 * this segment are moved to point of neighbor segment. If constraint was initially built
38 * to the point of splitting segment, it stays for this point.
39 * - Geometrical and dimensional constraints are assigned to one of result segment, not the
40 * selected for split. In case of 3 result segments, this will be the segment nearest to the
41 * start point of arc/line.
42 * - Replication constraint used split feature will be deleted in the same way as it is deleted
43 * by any of entity delete in sketch which is used in this constraint.
45 * This constraint has three attributes:
46 * SketchPlugin_Constraint::VALUE() contains reference object to be splitted
47 * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() for the points of split;
50 class SketchPlugin_ConstraintSplit : public SketchPlugin_ConstraintBase
53 /// Split constraint kind
54 inline static const std::string& ID()
56 static const std::string MY_CONSTRAINT_SPLIT_ID("SketchConstraintSplit");
57 return MY_CONSTRAINT_SPLIT_ID;
59 /// \brief Returns the kind of a feature
60 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
62 static std::string MY_KIND = SketchPlugin_ConstraintSplit::ID();
66 /// \brief Creates a new part document if needed
67 SKETCHPLUGIN_EXPORT virtual void execute();
69 /// \brief Request for initialization of data model of the feature: adding all attributes
70 SKETCHPLUGIN_EXPORT virtual void initAttributes();
72 /// Reimplemented from ModelAPI_Feature::isMacro().
74 SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
76 /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
77 /// This is necessary to perform execute only by apply the feature
78 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
80 /// \brief Use plugin manager for features creation
81 SketchPlugin_ConstraintSplit();
83 /// \return map of base points and features;
84 //SKETCHPLUGIN_EXPORT const std::map<AttributePtr, FilletFeatures> pointsFeaturesMap() const {
85 // return myPointFeaturesMap;
88 /// Returns the AIS preview
89 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
92 /// Returns geom point attribute of the feature bounds. It processes line or arc.
93 /// For circle feature, the result attributes are null
94 /// \param theStartPointAttr an out attribute to start point
95 /// \param theStartPointAttr an out attribute to end point
96 void getFeaturePoints(std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
97 std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
99 /// Returns cast of attribute to geometrical point if the attribute is a ref attr attribute
100 /// \param theAttribute an attribute
101 /// \param geom point 2D or NULL
102 std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(const AttributePtr& theAttribute);
104 /// Obtains those constraints of the feature that should be modified. output maps contain
105 /// point of coincidence and attribute id to be modified after split
106 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
107 /// \param theFeaturesToUpdate [out] constrains that will be updated after split
108 /// \param theTangentFeatures [out] tangent feature to be connected to new feature
109 /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
110 /// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
111 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
112 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate,
113 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
114 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature/*,
115 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToPoint*/);
117 /// Obtains references to feature point attributes and to feature,
118 /// e.g. for feature line: 1st container is <1st line point, list<entity_a in distance, entity_b in parallel> >
119 /// <2nd line point, list<> >
120 /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
121 /// \param theFeature an investigated feature
122 /// \param theRefs a container of list of referenced attributes
123 void getRefAttributes(const FeaturePtr& theFeature,
124 std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
125 std::list<AttributePtr>& theRefsToFeature);
127 /// Move coincidence constraint from feature to point if it is found
128 /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature
129 /// \param theFurtherCoincidences a list of points where coincidences will be build
130 /// \paramv theFeatureResults created results after split where constaint might be connected
131 void updateCoincidenceConstraintsToFeature(
132 const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
133 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
134 const std::set<ResultPtr>& theFeatureResults);
136 /// Move tangency constraint to the nearest split feature that has a coincidence to the tangent
137 /// \param theTangentFeatures tangencies to feature to be connected to nearest feature
138 /// \param theFurtherCoincidences a list of points where coincidences is built
139 void updateTangentConstraintsToFeature(
140 const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
141 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences);
144 /// Move constraints from base feature to given feature
145 /// \param theFeature a base feature
146 /// \param theRefsToFeature list of attributes referenced to base feature
147 void updateRefFeatureConstraints(const std::shared_ptr<ModelAPI_Result>& theFeatureBaseResult,
148 const std::list<AttributePtr>& theRefsToFeature);
150 /// Move constraints from attribute of base feature to attribute after modification
151 /// \param theBaseRefAttributes container of references to the attributes of base feature
152 /// \param theModifiedAttributes container of attributes placed instead of base attributes
153 /// at the same place
154 void updateRefAttConstraints(
155 const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
156 const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes);
158 /// Make the base object is splitted by the point attributes
159 /// \param theSplitFeature a result split feature
160 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
161 /// \param theAfterFeature a feature between last point of split feature and the end point
162 /// \param thePoints a list of points where coincidences will be build
163 /// \param theCreatedFeatures a container of created features
164 /// \param theModifiedAttributes a container of attribute on base feature to attribute on new feature
165 void splitLine(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
166 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
167 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
168 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
169 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
170 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
172 /// Make the base object is splitted by the point attributes
173 /// \param theSplitFeature a result split feature
174 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
175 /// \param theAfterFeature a feature between last point of split feature and the end point
176 /// \param thePoints a list of points where coincidences will be build
177 /// \param theCreatedFeatures a container of created features
178 void splitArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
179 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
180 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
181 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
182 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
183 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
185 /// Make the base object is splitted by the point attributes
186 /// \param theSplitFeature a result split feature
187 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
188 /// \param theAfterFeature a feature between last point of split feature and the end point
189 /// \param thePoints a list of points where coincidences will be build
190 /// \param theCreatedFeatures a container of created features
191 void splitCircle(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
192 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
193 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
194 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
195 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
196 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
198 /// Correct the first and the second point to provide condition that the first is closer to
199 /// the start point and the second point - to the last end of current segment. To rearrange
200 /// them if this condition is not satisfied.
201 /// \param theStartPointAttr a start point of a segment
202 /// \param theEndPointAttr an end point of a segment
203 /// \param theFirstPointAttr a start point of a segment
204 /// \param theSecondPointAttr an end point of a segment
205 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
206 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
207 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
208 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
210 /// Correct the first and the second point to provide condition that the first is closer to
211 /// the start point and the second point - to the last end of current segment. To rearrange
212 /// them if this condition is not satisfied.
213 /// \param theArc an arc to be split
214 /// \param theStartPointAttr a start point of a segment
215 /// \param theEndPointAttr an end point of a segment
216 /// \param theFirstPointAttr a start point of a segment
217 /// \param theSecondPointAttr an end point of a segment
218 void arrangePointsOnArc(const FeaturePtr& theArc,
219 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
220 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
221 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
222 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
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 theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
227 void fillAttribute(const AttributePtr& theModifiedAttribute,
228 const AttributePtr& theSourceAttribute);
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 AttributePtr& theFirstPointAttr,
236 const AttributePtr& theSecondPointAttr);
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 AttributePtr& theFirstPointAttr,
244 const AttributePtr& theSecondPointAttr);
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 theFirstAttribute an attribute of further coincidence
258 std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
259 const std::shared_ptr<ModelAPI_Object>& theFirstObject,
260 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
262 /// Add feature coincidence constraint between given attributes
263 /// \param theFeaturesToUpdate a constraint index
264 void updateFeaturesAfterSplit(const std::set<FeaturePtr>& theFeaturesToUpdate);
266 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
267 /// \param theFeature a feature
268 /// \return result object
269 std::shared_ptr<ModelAPI_Result> getFeatureResult(
270 const std::shared_ptr<ModelAPI_Feature>& theFeature);
272 /// Returns attributes of the feature, used in edge build, for arc it is end and start points
273 /// \param theFeature a feature
274 /// \return container of attributes
275 std::set<std::shared_ptr<ModelAPI_Attribute> > getEdgeAttributes(
276 const std::shared_ptr<ModelAPI_Feature>& theFeature);
278 /// Return feature name, kind, point attribute values united in a string
279 /// \param theFeature an investigated feature
280 /// \return string value
281 std::string getFeatureInfo(const std::shared_ptr<ModelAPI_Feature>& theFeature,
282 const bool isUseAttributesInfo = true);