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 /// Obtains those constraints of the feature that should be modified. output maps contain
153 /// point of coincidence and attribute id to be modified after split
154 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
155 /// \param theFeaturesToUpdate [out] constrains that will be updated after split
156 /// \param theTangentFeatures [out] tangent feature to be connected to new feature
157 /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
158 /// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
159 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
160 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate,
161 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature);
163 /// Obtains references to feature point attributes and to feature,
164 /// e.g. for feature line: 1st container is
165 /// <1st line point, list<entity_a in distance, entity_b in parallel> >
166 /// <2nd line point, list<> >
167 /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
168 /// \param theFeature an investigated feature
169 /// \param theRefs a container of list of referenced attributes
170 void getRefAttributes(const FeaturePtr& theFeature,
171 std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
172 std::list<AttributePtr>& theRefsToFeature);
174 /// Move coincidence constraint from feature to point if it is found
175 /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature
176 /// \param theFurtherCoincidences a list of points where coincidences will be build
177 /// \param theFeatureResults created results after split where constaint might be connected
178 /// \param theSplitFeature feature created by split, new coincidences to points should be created
179 /// \param theFeaturesToDelete the list of removed features (will be updated here by
180 /// the coincidences to be removed)
181 /// if theCoincidenceToFeature contains equal points
182 void updateCoincidenceConstraintsToFeature(
183 const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
184 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
185 const std::set<ResultPtr>& theFeatureResults,
186 const FeaturePtr& theSplitFeature,
187 std::set<FeaturePtr>& theFeaturesToDelete);
189 /// Move constraints from base feature to given feature
190 /// \param theFeature a base feature
191 /// \param theRefsToFeature list of attributes referenced to base feature
192 void updateRefFeatureConstraints(const std::shared_ptr<ModelAPI_Result>& theFeatureBaseResult,
193 const std::list<AttributePtr>& theRefsToFeature);
195 /// Move constraints from attribute of base feature to attribute after modification
196 /// \param theBaseRefAttributes container of references to the attributes of base feature
197 /// \param theModifiedAttributes container of attributes placed instead of base attributes
198 /// at the same place
199 void updateRefAttConstraints(
200 const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
201 const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes);
203 /// Make the base object is splitted by the point attributes
204 /// \param theSplitFeature a result split feature
205 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
206 /// \param theAfterFeature a feature between last point of split feature and the end point
207 /// \param thePoints a list of points where coincidences will be build
208 /// \param theCreatedFeatures a container of created features
209 /// \param theModifiedAttributes a container of attribute on base
210 /// feature to attribute on new feature
211 /// \return new line if it was created
212 FeaturePtr splitLine(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
213 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
214 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
215 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
216 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
217 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
219 /// Make the base object is splitted by the point attributes
220 /// \param theSplitFeature a result split feature
221 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
222 /// \param theAfterFeature a feature between last point of split feature and the end point
223 /// \param thePoints a list of points where coincidences will be build
224 /// \param theCreatedFeatures a container of created features
225 /// \return new arc if it was created
226 FeaturePtr splitArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
227 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
228 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
229 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
230 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
231 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
233 /// Make the base object is splitted by the point attributes
234 /// \param theSplitFeature a result split feature
235 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
236 /// \param theAfterFeature a feature between last point of split feature and the end point
237 /// \param thePoints a list of points where coincidences will be build
238 /// \param theCreatedFeatures a container of created features
239 /// \return new arc if it was created
240 FeaturePtr splitCircle(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
241 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
242 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
243 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
244 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
245 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
247 /// Correct the first and the second point to provide condition that the first is closer to
248 /// the start point and the second point - to the last end of current segment. To rearrange
249 /// them if this condition is not satisfied.
250 /// \param theStartPointAttr a start point of a segment
251 /// \param theEndPointAttr an end point of a segment
252 /// \param theFirstPointAttr a start point of a segment
253 /// \param theSecondPointAttr an end point of a segment
254 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
255 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
256 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
257 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
259 /// Correct the first and the second point to provide condition that the first is closer to
260 /// the start point and the second point - to the last end of current segment. To rearrange
261 /// them if this condition is not satisfied.
262 /// \param theArc an arc to be split
263 /// \param theStartPointAttr a start point of a segment
264 /// \param theEndPointAttr an end point of a segment
265 /// \param theFirstPointAttr a start point of a segment
266 /// \param theSecondPointAttr an end point of a segment
267 void arrangePointsOnArc(const FeaturePtr& theArc,
268 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
269 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
270 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
271 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
273 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
274 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
275 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
276 void fillAttribute(const AttributePtr& theModifiedAttribute,
277 const AttributePtr& theSourceAttribute);
279 /// Creates a line feature filled by center of base feature and given points
280 /// \param theBaseFeature another arc feature
281 /// \param theFirstAttribute an attribute with coordinates for the start point
282 /// \param theSecondAttribute an attribute with coordinates for the end point
283 FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
284 const AttributePtr& theFirstPointAttr,
285 const AttributePtr& theSecondPointAttr);
287 /// Creates an arc feature filled by center of base feature and given points
288 /// \param theBaseFeature another arc feature
289 /// \param theFirstAttribute an attribute with coordinates for the start point
290 /// \param theSecondAttribute an attribute with coordinates for the end point
291 FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
292 const AttributePtr& theFirstPointAttr,
293 const AttributePtr& theSecondPointAttr);
295 /// Add feature coincidence constraint between given attributes
296 /// \param theFeaturesToUpdate a constraint index
297 void updateFeaturesAfterSplit(const std::set<FeaturePtr>& theFeaturesToUpdate);
299 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
300 /// \param theFeature a feature
301 /// \return result object
302 std::shared_ptr<ModelAPI_Result> getFeatureResult(
303 const std::shared_ptr<ModelAPI_Feature>& theFeature);
305 /// Returns attributes of the feature, used in edge build, for arc it is end and start points
306 /// \param theFeature a feature
307 /// \return container of attributes
308 std::set<std::shared_ptr<ModelAPI_Attribute> > getEdgeAttributes(
309 const std::shared_ptr<ModelAPI_Feature>& theFeature);
311 /// Returns first attribute coincident to the first/second point of selected shape
312 /// \param isFirstAttribute true for getting the first atribute, false otherwise
313 /// \return an attribute or NULL
314 std::shared_ptr<GeomDataAPI_Point2D> getPointAttribute(const bool isFirstAttribute);
317 /// Return feature name, kind, point attribute values united in a string
318 /// \param theFeature an investigated feature
319 /// \return string value
320 std::string getFeatureInfo(const std::shared_ptr<ModelAPI_Feature>& theFeature,
321 const bool isUseAttributesInfo = true);
324 typedef std::map<std::shared_ptr<GeomDataAPI_Point2D>,
325 std::shared_ptr<GeomAPI_Pnt> > PntToAttributesMap;
327 std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
328 std::map<std::shared_ptr<ModelAPI_Object>, PntToAttributesMap> myCashedReferences;