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;
89 /// Returns geom point attribute of the feature bounds. It processes line or arc.
90 /// For circle feature, the result attributes are null
91 /// \param theStartPointAttr an out attribute to start point
92 /// \param theStartPointAttr an out attribute to end point
93 void getFeaturePoints(std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
94 std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
96 /// Returns cast of attribute to geometrical point if the attribute is a ref attr attribute
97 /// \param theAttribute an attribute
98 /// \param geom point 2D or NULL
99 std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(const AttributePtr& theAttribute);
101 /// Obtains those constraints of the feature that should be modified. output maps contain
102 /// point of coincidence and attribute id to be modified after split
103 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
104 /// \param theTangentFeatures [out] tangent feature to be connected to new feature
105 /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
106 /// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
107 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
108 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
109 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
110 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToPoint);
112 void getRefAttributes(const FeaturePtr& theFeature,
113 std::map<AttributePtr, std::list<AttributePtr> >& theRefs);
115 /// Move coincidence constraint from feature to point if it is found
116 /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature
117 /// \param theFurtherCoincidences a list of points where coincidences will be build
118 /// \paramv theFeatureResults created results after split where constaint might be connected
119 void updateCoincidenceConstraintsToFeature(
120 const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
121 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
122 const std::set<ResultPtr>& theFeatureResults);
124 /// Move tangency constraint to the nearest split feature that has a coincidence to the tangent
125 /// \param theTangentFeatures tangencies to feature to be connected to nearest feature
126 /// \param theFurtherCoincidences a list of points where coincidences is built
127 void updateTangentConstraintsToFeature(
128 const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
129 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences);
131 /// Make the base object is splitted by the point attributes
132 /// \param theSplitFeature a result split feature
133 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
134 /// \param theAfterFeature a feature between last point of split feature and the end point
135 /// \param thePoints a list of points where coincidences will be build
136 /// \param theCreatedFeatures a container of created features
137 void splitLine(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
138 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
139 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
140 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
141 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
143 /// Make the base object is splitted by the point attributes
144 /// \param theSplitFeature a result split feature
145 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
146 /// \param theAfterFeature a feature between last point of split feature and the end point
147 /// \param thePoints a list of points where coincidences will be build
148 /// \param theCreatedFeatures a container of created features
149 void splitArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
150 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
151 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
152 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
153 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
155 /// Make the base object is splitted by the point attributes
156 /// \param theSplitFeature a result split feature
157 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
158 /// \param theAfterFeature a feature between last point of split feature and the end point
159 /// \param thePoints a list of points where coincidences will be build
160 /// \param theCreatedFeatures a container of created features
161 void splitCircle(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
162 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
163 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
164 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
165 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
167 /// Correct the first and the second point to provide condition that the first is closer to
168 /// the start point and the second point - to the last end of current segment. To rearrange
169 /// them if this condition is not satisfied.
170 /// \param theStartPointAttr a start point of a segment
171 /// \param theEndPointAttr an end point of a segment
172 /// \param theFirstPointAttr a start point of a segment
173 /// \param theSecondPointAttr an end point of a segment
174 void arrangePoints(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
175 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
176 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
177 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr);
179 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
180 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
181 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
182 void fillAttribute(const AttributePtr& theModifiedAttribute,
183 const AttributePtr& theSourceAttribute);
185 /// Creates a line feature filled by center of base feature and given points
186 /// \param theBaseFeature another arc feature
187 /// \param theFirstAttribute an attribute with coordinates for the start point
188 /// \param theSecondAttribute an attribute with coordinates for the end point
189 FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
190 const AttributePtr& theFirstPointAttr,
191 const AttributePtr& theSecondPointAttr);
193 /// Creates an arc feature filled by center of base feature and given points
194 /// \param theBaseFeature another arc feature
195 /// \param theFirstAttribute an attribute with coordinates for the start point
196 /// \param theSecondAttribute an attribute with coordinates for the end point
197 FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
198 const AttributePtr& theFirstPointAttr,
199 const AttributePtr& theSecondPointAttr);
201 /// Add feature coincidence constraint between given attributes
202 /// \param theConstraintId a constraint index
203 /// \param theFirstAttribute an attribute of further coincidence
204 /// \param theSecondAttribute an attribute of further coincidence
205 std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
206 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
207 const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
209 /// Add feature coincidence constraint between given attributes
210 /// \param theConstraintId a constraint index
211 /// \param theFirstAttribute an attribute of further coincidence
212 /// \param theFirstAttribute an attribute of further coincidence
213 std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
214 const std::shared_ptr<ModelAPI_Object>& theFirstObject,
215 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
217 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
218 /// \param theFeature a feature
219 /// \return result object
220 std::shared_ptr<ModelAPI_Result> getFeatureResult(
221 const std::shared_ptr<ModelAPI_Feature>& theFeature);
223 /// Returns attributes of the feature, used in edge build, for arc it is end and start points
224 /// \param theFeature a feature
225 /// \return container of attributes
226 std::set<std::shared_ptr<ModelAPI_Attribute> > getEdgeAttributes(
227 const std::shared_ptr<ModelAPI_Feature>& theFeature);
229 /// Return feature name, kind, point attribute values united in a string
230 /// \param theFeature an investigated feature
231 /// \return string value
232 std::string getFeatureInfo(const std::shared_ptr<ModelAPI_Feature>& theFeature,
233 const bool isUseAttributesInfo = true);