1 // Copyright (C) 2014-2017 CEA/DEN, EDF R&D
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
21 #ifndef SketchPlugin_Split_H_
22 #define SketchPlugin_Split_H_
24 #include "SketchPlugin.h"
26 #include "GeomAPI_IPresentable.h"
27 #include <ModelAPI_IReentrant.h>
29 #include <SketchPlugin_Sketch.h>
31 class GeomDataAPI_Point2D;
32 class ModelAPI_Feature;
33 class ModelAPI_Result;
35 typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
37 /** \class SketchPlugin_Split
39 * \brief Feature for creation of a new constraint splitting object. Entities for split:
40 * - Linear segment by point(s) on this line
41 * - Arc by point(s) on this arc
42 * - Circle by at least 2 split-points on this circle
44 * The following constraints will be applied after split to keep the divided segments geometry:
45 * - Coincident constraints for both parts of created segments in the point of splitting
46 * - For linear segments parallel, for circles - tangent constraint, for arc - tangent and equal
47 * constraints. In case of three segments in result two couple of constraints are created
48 * - parallel and equal constraints: the first is between 1st and middle entity, the second is
49 * between 1st and 3rd.
50 * - tangency constraints: the first between 1st and 2nd, the second between 2nd and 3rd.
51 * - Constraints assigned to the feature before split operation are assigned after using rules:
52 * - Coincident constraints are assigned to the segment where they belong to. Segment of split
53 * has only a coincidence to the neighbor segment. All constraints used in the splitting of
54 * this segment are moved to point of neighbor segment. If constraint was initially built
55 * to the point of splitting segment, it stays for this point.
56 * - Geometrical and dimensional constraints are assigned to one of result segment, not the
57 * selected for split. In case of 3 result segments, this will be the segment nearest to the
58 * start point of arc/line.
59 * - Replication constraint used split feature will be deleted in the same way as it is deleted
60 * by any of entity delete in sketch which is used in this constraint.
62 * This constraint has three attributes:
63 * SketchPlugin_Constraint::VALUE() contains reference object to be splitted
64 * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() for the points of split;
67 class SketchPlugin_Split : public SketchPlugin_Feature, public GeomAPI_IPresentable,
68 public ModelAPI_IReentrant
71 /// Split constraint kind
72 inline static const std::string& ID()
74 static const std::string MY_SPLIT_ID("SketchSplit");
77 /// \brief Returns the kind of a feature
78 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
80 static std::string MY_KIND = SketchPlugin_Split::ID();
83 /// The value parameter for the constraint
84 inline static const std::string& SELECTED_OBJECT()
86 static const std::string MY_SELECTED_OBJECT("SelectedObject");
87 return MY_SELECTED_OBJECT;
90 /// Start 2D point of the split segment
91 inline static const std::string& SELECTED_POINT()
93 static const std::string MY_SELECTED_POINT("SelectedPoint");
94 return MY_SELECTED_POINT;
97 /// The value parameter for the preview object
98 inline static const std::string& PREVIEW_OBJECT()
100 static const std::string MY_PREVIEW_OBJECT("PreviewObject");
101 return MY_PREVIEW_OBJECT;
104 /// Start 2D point of the split segment
105 inline static const std::string& PREVIEW_POINT()
107 static const std::string MY_PREVIEW_POINT("PreviewPoint");
108 return MY_PREVIEW_POINT;
111 /// \brief Creates a new part document if needed
112 SKETCHPLUGIN_EXPORT virtual void execute();
114 /// \brief Request for initialization of data model of the feature: adding all attributes
115 SKETCHPLUGIN_EXPORT virtual void initAttributes();
117 /// Reimplemented from ModelAPI_Feature::isMacro().
119 SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return true; }
121 /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
122 /// This is necessary to perform execute only by apply the feature
123 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
125 /// \brief Use plugin manager for features creation
126 SketchPlugin_Split();
128 /// Returns the AIS preview
129 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
131 /// Apply information of the message to current object. It fills selected point and object
132 virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
135 /// Fulfill an internal container by shapes obtained from the parameter object
136 /// Shapes are result of split operation by points coincident to shape of the object
137 /// \param theObject a source object (will be splitted)
138 /// \param theSketch a sketch object
139 void fillObjectShapes(const ObjectPtr& theObject, const ObjectPtr& theSketch);
141 GeomShapePtr getSubShape(const std::string& theObjectAttributeId,
142 const std::string& thePointAttributeId);
143 /// Returns geom point attribute of the feature bounds. It processes line or arc.
144 /// For circle feature, the result attributes are null
145 /// \param theFeature a source feature
146 /// \param theStartPointAttr an out attribute to start point
147 /// \param theStartPointAttr an out attribute to end point
148 void getFeaturePoints(const FeaturePtr& theFeature,
149 std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
150 std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
152 /// Returns cast of attribute to geometrical point if the attribute is a ref attr attribute
153 /// \param theAttribute an attribute
154 /// \param geom point 2D or NULL
155 std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(const AttributePtr& theAttribute);
157 /// Obtains those constraints of the feature that should be modified. output maps contain
158 /// point of coincidence and attribute id to be modified after split
159 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
160 /// \param theFeaturesToUpdate [out] constrains that will be updated after split
161 /// \param theTangentFeatures [out] tangent feature to be connected to new feature
162 /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
163 /// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
164 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
165 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate,
166 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature);
168 /// Obtains references to feature point attributes and to feature,
169 /// e.g. for feature line: 1st container is
170 /// <1st line point, list<entity_a in distance, entity_b in parallel> >
171 /// <2nd line point, list<> >
172 /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
173 /// \param theFeature an investigated feature
174 /// \param theRefs a container of list of referenced attributes
175 void getRefAttributes(const FeaturePtr& theFeature,
176 std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
177 std::list<AttributePtr>& theRefsToFeature);
179 /// Move coincidence constraint from feature to point if it is found
180 /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature
181 /// \param theFurtherCoincidences a list of points where coincidences will be build
182 /// \param theFeatureResults created results after split where constaint might be connected
183 /// \param theSplitFeature feature created by split, new coincidences to points should be created
184 /// \param theFeaturesToDelete the list of removed features (will be updated here by
185 /// the coincidences to be removed)
186 /// if theCoincidenceToFeature contains equal points
187 void updateCoincidenceConstraintsToFeature(
188 const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
189 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
190 const std::set<ResultPtr>& theFeatureResults,
191 const FeaturePtr& theSplitFeature,
192 std::set<FeaturePtr>& theFeaturesToDelete);
194 /// Move constraints from base feature to given feature
195 /// \param theFeature a base feature
196 /// \param theRefsToFeature list of attributes referenced to base feature
197 void updateRefFeatureConstraints(const std::shared_ptr<ModelAPI_Result>& theFeatureBaseResult,
198 const std::list<AttributePtr>& theRefsToFeature);
200 /// Move constraints from attribute of base feature to attribute after modification
201 /// \param theBaseRefAttributes container of references to the attributes of base feature
202 /// \param theModifiedAttributes container of attributes placed instead of base attributes
203 /// at the same place
204 void updateRefAttConstraints(
205 const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
206 const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes);
208 /// Make the base object is splitted by the point attributes
209 /// \param theSplitFeature a result split feature
210 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
211 /// \param theAfterFeature a feature between last point of split feature and the end point
212 /// \param thePoints a list of points where coincidences will be build
213 /// \param theCreatedFeatures a container of created features
214 /// \param theModifiedAttributes a container of attribute on base
215 /// feature to attribute on new feature
216 /// \return new line if it was created
217 FeaturePtr splitLine(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
218 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
219 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
220 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
221 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
222 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
224 /// Make the base object is splitted by the point attributes
225 /// \param theSplitFeature a result split feature
226 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
227 /// \param theAfterFeature a feature between last point of split feature and the end point
228 /// \param thePoints a list of points where coincidences will be build
229 /// \param theCreatedFeatures a container of created features
230 /// \return new arc if it was created
231 FeaturePtr splitArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
232 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
233 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
234 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
235 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
236 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
238 /// Make the base object is splitted by the point attributes
239 /// \param theSplitFeature a result split feature
240 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
241 /// \param theAfterFeature a feature between last point of split feature and the end point
242 /// \param thePoints a list of points where coincidences will be build
243 /// \param theCreatedFeatures a container of created features
244 /// \return new arc if it was created
245 FeaturePtr splitCircle(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
246 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
247 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
248 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
249 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
250 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
252 /// Correct the first and the second point to provide condition that the first is closer to
253 /// the start point and the second point - to the last end of current segment. To rearrange
254 /// them if this condition is not satisfied.
255 /// \param theStartPointAttr a start point of a segment
256 /// \param theEndPointAttr an end point of a segment
257 /// \param theFirstPointAttr a start point of a segment
258 /// \param theSecondPointAttr an end point of a segment
259 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
260 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
261 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
262 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
264 /// Correct the first and the second point to provide condition that the first is closer to
265 /// the start point and the second point - to the last end of current segment. To rearrange
266 /// them if this condition is not satisfied.
267 /// \param theArc an arc to be split
268 /// \param theStartPointAttr a start point of a segment
269 /// \param theEndPointAttr an end point of a segment
270 /// \param theFirstPointAttr a start point of a segment
271 /// \param theSecondPointAttr an end point of a segment
272 void arrangePointsOnArc(const FeaturePtr& theArc,
273 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
274 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
275 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
276 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
278 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
279 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
280 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
281 void fillAttribute(const AttributePtr& theModifiedAttribute,
282 const AttributePtr& theSourceAttribute);
284 /// Creates a line feature filled by center of base feature and given points
285 /// \param theBaseFeature another arc feature
286 /// \param theFirstAttribute an attribute with coordinates for the start point
287 /// \param theSecondAttribute an attribute with coordinates for the end point
288 FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
289 const AttributePtr& theFirstPointAttr,
290 const AttributePtr& theSecondPointAttr);
292 /// Creates an arc feature filled by center of base feature and given points
293 /// \param theBaseFeature another arc feature
294 /// \param theFirstAttribute an attribute with coordinates for the start point
295 /// \param theSecondAttribute an attribute with coordinates for the end point
296 FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
297 const AttributePtr& theFirstPointAttr,
298 const AttributePtr& theSecondPointAttr);
300 /// Add feature coincidence constraint between given attributes
301 /// \param theFeaturesToUpdate a constraint index
302 void updateFeaturesAfterSplit(const std::set<FeaturePtr>& theFeaturesToUpdate);
304 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
305 /// \param theFeature a feature
306 /// \return result object
307 std::shared_ptr<ModelAPI_Result> getFeatureResult(
308 const std::shared_ptr<ModelAPI_Feature>& theFeature);
310 /// Returns attributes of the feature, used in edge build, for arc it is end and start points
311 /// \param theFeature a feature
312 /// \return container of attributes
313 std::set<std::shared_ptr<ModelAPI_Attribute> > getEdgeAttributes(
314 const std::shared_ptr<ModelAPI_Feature>& theFeature);
316 /// Returns first attribute coincident to the first/second point of selected shape
317 /// \param isFirstAttribute true for getting the first atribute, false otherwise
318 /// \return an attribute or NULL
319 std::shared_ptr<GeomDataAPI_Point2D> getPointAttribute(const bool isFirstAttribute);
322 /// Return feature name, kind, point attribute values united in a string
323 /// \param theFeature an investigated feature
324 /// \return string value
325 std::string getFeatureInfo(const std::shared_ptr<ModelAPI_Feature>& theFeature,
326 const bool isUseAttributesInfo = true);
329 typedef std::map<std::shared_ptr<GeomDataAPI_Point2D>,
330 std::shared_ptr<GeomAPI_Pnt> > PntToAttributesMap;
332 std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
333 std::map<std::shared_ptr<ModelAPI_Object>, PntToAttributesMap> myCashedReferences;