1 // Copyright (C) 2014-2023 CEA, EDF
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 email : webmaster.salome@opencascade.com
20 #ifndef SketchPlugin_Split_H_
21 #define SketchPlugin_Split_H_
23 #include "SketchPlugin.h"
24 #include "SketchPlugin_Tools.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 * - Circular/elliptic arc by point(s) on this arc
42 * - Circle/ellipse by at least 2 split-points on it
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/ellipses - tangent constraint,
47 * for arc - tangent and equal constraints. In case of three segments in result
48 * two couple of constraints are created
49 * - parallel and equal constraints: the first is between 1st and middle entity, the second is
50 * between 1st and 3rd.
51 * - tangency constraints: the first between 1st and 2nd, the second between 2nd and 3rd.
52 * - Constraints assigned to the feature before split operation are assigned after using rules:
53 * - Coincident constraints are assigned to the segment where they belong to. Segment of split
54 * has only a coincidence to the neighbor segment. All constraints used in the splitting of
55 * this segment are moved to point of neighbor segment. If constraint was initially built
56 * to the point of splitting segment, it stays for this point.
57 * - Geometrical and dimensional constraints are assigned to one of result segment, not the
58 * selected for split. In case of 3 result segments, this will be the segment nearest to the
59 * start point of arc/line.
60 * - Replication constraint used split feature will be deleted in the same way as it is deleted
61 * by any of entity delete in sketch which is used in this constraint.
63 class SketchPlugin_Split : public SketchPlugin_Feature, public GeomAPI_IPresentable,
64 public ModelAPI_IReentrant
67 /// Split constraint kind
68 inline static const std::string& ID()
70 static const std::string MY_SPLIT_ID("SketchSplit");
73 /// \brief Returns the kind of a feature
74 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
76 static std::string MY_KIND = SketchPlugin_Split::ID();
79 /// The value parameter for the constraint
80 inline static const std::string& SELECTED_OBJECT()
82 static const std::string MY_SELECTED_OBJECT("SelectedObject");
83 return MY_SELECTED_OBJECT;
86 /// Start 2D point of the split segment
87 inline static const std::string& SELECTED_POINT()
89 static const std::string MY_SELECTED_POINT("SelectedPoint");
90 return MY_SELECTED_POINT;
93 /// The value parameter for the preview object
94 inline static const std::string& PREVIEW_OBJECT()
96 static const std::string MY_PREVIEW_OBJECT("PreviewObject");
97 return MY_PREVIEW_OBJECT;
100 /// Start 2D point of the split segment
101 inline static const std::string& PREVIEW_POINT()
103 static const std::string MY_PREVIEW_POINT("PreviewPoint");
104 return MY_PREVIEW_POINT;
107 /// \brief Creates a new part document if needed
108 SKETCHPLUGIN_EXPORT virtual void execute();
110 /// \brief Request for initialization of data model of the feature: adding all attributes
111 SKETCHPLUGIN_EXPORT virtual void initAttributes();
113 /// Reimplemented from ModelAPI_Feature::isMacro().
115 SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return true; }
117 /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
118 /// This is necessary to perform execute only by apply the feature
119 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
121 /// \brief Use plugin manager for features creation
122 SketchPlugin_Split();
124 /// Returns the AIS preview
125 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
127 /// Apply information of the message to current object. It fills selected point and object
128 virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
131 /// Obtains those constraints of the feature that should be modified. output maps contain
132 /// point of coincidence and attribute id to be modified after split
133 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
134 /// \param theFeaturesToUpdate [out] constrains that will be updated after split
135 /// \param theTangentFeatures [out] tangent feature to be connected to new feature
136 /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
137 /// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
138 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
139 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate,
140 std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature);
142 /// Move coincidence constraint from feature to point if it is found
143 /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature
144 /// \param theFurtherCoincidences a list of points where coincidences will be build
145 /// \param theFeatureResults created results after split where constaint might be connected
146 /// \param theSplitFeature feature created by split, new coincidences to points should be created
147 /// \param theFeaturesToDelete the list of removed features (will be updated here by
148 /// the coincidences to be removed)
149 /// if theCoincidenceToFeature contains equal points
150 void updateCoincidenceConstraintsToFeature(
151 const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
152 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
153 const std::set<ResultPtr>& theFeatureResults,
154 const FeaturePtr& theSplitFeature,
155 std::set<FeaturePtr>& theFeaturesToDelete);
157 /// Move constraints from base feature to given feature
158 /// \param theFeature a base feature
159 /// \param theRefsToFeature list of attributes referenced to base feature
160 void updateRefFeatureConstraints(const std::shared_ptr<ModelAPI_Result>& theFeatureBaseResult,
161 const std::list<AttributePtr>& theRefsToFeature);
163 /// Make the base object is splitted by the point attributes
164 /// \param theSplitFeature a result split feature
165 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
166 /// \param theAfterFeature a feature between last point of split feature and the end point
167 /// \param thePoints a list of points where coincidences will be build
168 /// \param theCreatedFeatures a container of created features
169 /// \param theModifiedAttributes a container of attribute on base
170 /// feature to attribute on new feature
171 /// \return new line if it was created
172 FeaturePtr splitLine(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
173 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
174 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
175 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
176 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
177 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
179 /// Make the base object is splitted by the point attributes
180 /// \param theSplitFeature a result split feature
181 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
182 /// \param theAfterFeature a feature between last point of split feature and the end point
183 /// \param thePoints a list of points where coincidences will be build
184 /// \param theCreatedFeatures a container of created features
185 /// \return new arc if it was created
186 FeaturePtr splitArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
187 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
188 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
189 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
190 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
191 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
193 /// Make the base object is splitted by the point attributes
194 /// \param theSplitFeature a result split feature
195 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
196 /// \param theAfterFeature a feature between last point of split feature and the end point
197 /// \param thePoints a list of points where coincidences will be build
198 /// \param theCreatedFeatures a container of created features
199 /// \return new elliptic arc if it was created
200 FeaturePtr splitEllipticArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
201 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
202 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
203 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
204 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
205 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
207 /// Make the base object is splitted by the point attributes
208 /// \param theSplitFeature a result split feature
209 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
210 /// \param theAfterFeature a feature between last point of split feature and the end point
211 /// \param thePoints a list of points where coincidences will be build
212 /// \param theCreatedFeatures a container of created features
213 /// \return new arc if it was created
214 FeaturePtr splitClosed(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
215 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
216 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
217 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
218 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures,
219 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
221 /// Correct the first and the second point to provide condition that the first is closer to
222 /// the start point and the second point - to the last end of current segment. To rearrange
223 /// them if this condition is not satisfied.
224 /// \param theStartPointAttr a start point of a segment
225 /// \param theEndPointAttr an end point of a segment
226 /// \param theFirstPointAttr a start point of a segment
227 /// \param theSecondPointAttr an end point of a segment
228 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
229 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
230 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
231 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
233 /// Correct the first and the second point to provide condition that the first is closer to
234 /// the start point and the second point - to the last end of current segment. To rearrange
235 /// them if this condition is not satisfied.
236 /// \param theArc an arc to be split
237 /// \param theStartPointAttr a start point of a segment
238 /// \param theEndPointAttr an end point of a segment
239 /// \param theFirstPointAttr a start point of a segment
240 /// \param theSecondPointAttr an end point of a segment
241 void arrangePointsOnArc(const FeaturePtr& theArc,
242 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
243 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
244 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
245 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr) const;
247 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
248 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
249 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
250 void fillAttribute(const AttributePtr& theModifiedAttribute,
251 const AttributePtr& theSourceAttribute);
253 /// Returns attributes of the feature, used in edge build, for arc it is end and start points
254 /// \param theFeature a feature
255 /// \return container of attributes
256 std::set<std::shared_ptr<ModelAPI_Attribute> > getEdgeAttributes(
257 const std::shared_ptr<ModelAPI_Feature>& theFeature);
259 /// Returns first attribute coincident to the first/second point of selected shape
260 /// \param isFirstAttribute true for getting the first atribute, false otherwise
261 /// \return an attribute or NULL
262 std::shared_ptr<GeomDataAPI_Point2D> getPointAttribute(const bool isFirstAttribute);
265 /// Return feature name, kind, point attribute values united in a string
266 /// \param theFeature an investigated feature
267 /// \return string value
268 std::string getFeatureInfo(const std::shared_ptr<ModelAPI_Feature>& theFeature,
269 const bool isUseAttributesInfo = true);
273 std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
274 std::map<std::shared_ptr<ModelAPI_Object>,
275 GeomAlgoAPI_ShapeTools::PointToRefsMap> myCashedReferences;