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_Trim_H_
21 #define SketchPlugin_Trim_H_
23 #include "SketchPlugin.h"
24 #include <SketchPlugin_Tools.h>
26 #include <GeomAPI_IPresentable.h>
27 #include <ModelAPI_IReentrant.h>
28 #include <SketchPlugin_Sketch.h>
30 class GeomDataAPI_Point2D;
31 class ModelAPI_Feature;
32 class ModelAPI_Result;
33 class ModelAPI_Object;
35 typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
37 /** \class SketchPlugin_Trim
39 * \brief Feature for creation of a new constraint trimming object. Entities for split:
41 class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentable,
42 public ModelAPI_IReentrant
45 /// Split constraint kind
46 inline static const std::string& ID()
48 static const std::string MY_TRIM_ID("SketchTrim");
51 /// \brief Returns the kind of a feature
52 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
54 static std::string MY_KIND = SketchPlugin_Trim::ID();
58 /// The value parameter for the constraint
59 inline static const std::string& SELECTED_OBJECT()
61 static const std::string MY_SELECTED_OBJECT("SelectedObject");
62 return MY_SELECTED_OBJECT;
65 /// Start 2D point of the split segment
66 inline static const std::string& SELECTED_POINT()
68 static const std::string MY_SELECTED_POINT("SelectedPoint");
69 return MY_SELECTED_POINT;
72 /// The value parameter for the preview object
73 inline static const std::string& PREVIEW_OBJECT()
75 static const std::string MY_PREVIEW_OBJECT("PreviewObject");
76 return MY_PREVIEW_OBJECT;
79 /// Start 2D point of the split segment
80 inline static const std::string& PREVIEW_POINT()
82 static const std::string MY_PREVIEW_POINT("PreviewPoint");
83 return MY_PREVIEW_POINT;
86 /// \brief Creates a new part document if needed
87 SKETCHPLUGIN_EXPORT virtual void execute();
89 /// \brief Request for initialization of data model of the feature: adding all attributes
90 SKETCHPLUGIN_EXPORT virtual void initAttributes();
92 /// Reimplemented from ModelAPI_Feature::isMacro()
94 SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return true; }
96 /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
97 /// This is necessary to perform execute only by apply the feature
98 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
100 /// \brief Use plugin manager for features creation
103 /// Returns the AIS preview
104 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
106 /// Apply information of the message to current object. It fills selected point and object
107 virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
110 bool setCoincidenceToAttribute(const AttributePtr& theAttribute,
111 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
112 std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
113 /// Move tangency constraint to the feature if it is geometrically closely to it
114 /// \param theAttribute an attribute of a tangent constraint feature
115 /// \param theFeature a feature that can be set into the attribute
116 bool moveTangency(const AttributePtr& theAttribute, const FeaturePtr& theFeature);
118 /// Obtains those constraints of the feature that should be modified. output maps contain
119 /// point of coincidence and attribute id to be modified after split
120 /// \param theFeaturesToDelete [out] constrains that will be deleted after split
121 /// \param theFeaturesToUpdate [out] constrains that will be updated after split
122 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
123 std::set<FeaturePtr>& theFeaturesToUpdate);
125 /// Remove references constraints from attribute of base feature refer to the given attribute
126 /// \param theAttribute an attribute
127 /// \param theModifiedAttributes modifiable container of attributes
128 void removeReferencesToAttribute(const AttributePtr& theAttribute,
129 std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes);
131 /// Make the base object is splitted by the point attributes
132 /// \param theBaseRefAttributes container of references to the attributes of base feature
133 /// \param thePoints a list of points where coincidences will be build
134 /// \param theModifiedAttributes a container of attribute on base
135 /// feature to attribute on new feature
136 /// \return new line if it was created
137 FeaturePtr trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
138 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
139 std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
140 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
141 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
143 /// Make the base object is splitted by the point attributes
144 /// \param thePoints a list of points where coincidences will be build
145 /// \return new line if it was created
146 FeaturePtr trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
147 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
148 std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
149 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
150 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
152 /// Make the base object is splitted by the point attributes
153 /// \param thePoints a list of points where coincidences will be build
154 /// \return new elliptic arc if it was created
155 FeaturePtr trimEllipticArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
156 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
157 std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
158 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
159 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
161 /// Make the base object is splitted by the point attributes
162 /// \param thePoints a list of points where coincidences will be build
163 FeaturePtr trimClosed(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
164 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
165 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
166 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
168 /// Correct the first and the second point to provide condition that the first is closer to
169 /// the start point and the second point - to the last end of current segment. To rearrange
170 /// them if this condition is not satisfied.
171 /// \param theStartPointAttr a start point of a segment
172 /// \param theEndPointAttr an end point of a segment
173 /// \param theFirstPoint a start point of a segment
174 /// \param theSecondPoint an end point of a segment
175 void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
176 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
177 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
178 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
180 /// Correct the first and the second point to provide condition that the first is closer to
181 /// the start point and the second point - to the last end of current segment. To rearrange
182 /// them if this condition is not satisfied.
183 /// \param theArc an arc to be split
184 /// \param theStartPointAttr a start point of a segment
185 /// \param theEndPointAttr an end point of a segment
186 /// \param theFirstPoint a start point of a segment
187 /// \param theSecondPoint an end point of a segment
188 void arrangePointsOnArc(const FeaturePtr& theArc,
189 const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
190 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
191 std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
192 std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
194 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
195 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
196 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
197 void fillAttribute(const AttributePtr& theModifiedAttribute,
198 const AttributePtr& theSourceAttribute);
200 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
201 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
202 /// \param thePoint a point value
203 void fillPointAttribute(const AttributePtr& theModifiedAttribute,
204 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
207 void findShapePoints(const std::string& theObjectAttributeId,
208 const std::string& thePointAttributeId,
209 std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
210 std::shared_ptr<GeomAPI_Pnt>& aLastPoint);
212 std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
215 std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
216 std::map<std::shared_ptr<ModelAPI_Object>,
217 GeomAlgoAPI_ShapeTools::PointToRefsMap> myObjectToPoints;