SHAPER 9.16.0
SketchPlugin_Trim.h
1// Copyright (C) 2014-2026 CEA, EDF
2//
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.
7//
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.
12//
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
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#ifndef SketchPlugin_Trim_H_
21#define SketchPlugin_Trim_H_
22
23#include "SketchPlugin.h"
24#include <SketchPlugin_Tools.h>
25
26#include <GeomAPI_IPresentable.h>
27#include <ModelAPI_IReentrant.h>
28#include <SketchPlugin_Sketch.h>
29
32class ModelAPI_Result;
33class ModelAPI_Object;
34
35typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
36
43{
44 public:
46 inline static const std::string& ID()
47 {
48 static const std::string MY_TRIM_ID("SketchTrim");
49 return MY_TRIM_ID;
50 }
52 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
53 {
54 static std::string MY_KIND = SketchPlugin_Trim::ID();
55 return MY_KIND;
56 }
57
59 inline static const std::string& SELECTED_OBJECT()
60 {
61 static const std::string MY_SELECTED_OBJECT("SelectedObject");
62 return MY_SELECTED_OBJECT;
63 }
64
66 inline static const std::string& SELECTED_POINT()
67 {
68 static const std::string MY_SELECTED_POINT("SelectedPoint");
69 return MY_SELECTED_POINT;
70 }
71
73 inline static const std::string& PREVIEW_OBJECT()
74 {
75 static const std::string MY_PREVIEW_OBJECT("PreviewObject");
76 return MY_PREVIEW_OBJECT;
77 }
78
80 inline static const std::string& PREVIEW_POINT()
81 {
82 static const std::string MY_PREVIEW_POINT("PreviewPoint");
83 return MY_PREVIEW_POINT;
84 }
85
87 SKETCHPLUGIN_EXPORT virtual void execute();
88
90 SKETCHPLUGIN_EXPORT virtual void initAttributes();
91
94 SKETCHPLUGIN_EXPORT virtual bool isMacro() const { return true; }
95
98 SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
99
102
104 SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
105
107 virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
108
109private:
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);
116 bool moveTangency(const AttributePtr& theAttribute, const FeaturePtr& theFeature);
117
122 void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
123 std::set<FeaturePtr>& theFeaturesToUpdate);
124
128 void removeReferencesToAttribute(const AttributePtr& theAttribute,
129 std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes);
130
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);
142
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);
151
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);
160
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);
167
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;
179
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;
193
197 void fillAttribute(const AttributePtr& theModifiedAttribute,
198 const AttributePtr& theSourceAttribute);
199
203 void fillPointAttribute(const AttributePtr& theModifiedAttribute,
204 const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
205
206private:
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);
211
212 std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
213
214private:
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;
218};
219
220#endif
A class which defines an interface of object which is able to create its own presentation.
Definition: GeomAPI_IPresentable.h:29
Attribute that contains 2D point coordinates.
Definition: GeomDataAPI_Point2D.h:37
Feature function that represents the particular functionality of this operation.
Definition: ModelAPI_Feature.h:41
Interface of a class which can process specific messages.
Definition: ModelAPI_IReentrant.h:36
Represents any object in the data model and in the object browser.
Definition: ModelAPI_Object.h:45
The result of a feature.
Definition: ModelAPI_Result.h:37
Feature for creation of the new feature in PartSet.
Definition: SketchPlugin_Feature.h:40
Feature for creation of a new constraint trimming object.
Definition: SketchPlugin_Trim.h:43
virtual bool isMacro() const
Reimplemented from ModelAPI_Feature::isMacro()
Definition: SketchPlugin_Trim.h:94
static const std::string & PREVIEW_POINT()
Start 2D point of the split segment.
Definition: SketchPlugin_Trim.h:80
static const std::string & SELECTED_OBJECT()
The value parameter for the constraint.
Definition: SketchPlugin_Trim.h:59
virtual std::string processEvent(const std::shared_ptr< Events_Message > &theMessage)
Apply information of the message to current object. It fills selected point and object.
Definition: SketchPlugin_Trim.cpp:510
virtual void initAttributes()
Request for initialization of data model of the feature: adding all attributes.
Definition: SketchPlugin_Trim.cpp:83
static const std::string & ID()
Split constraint kind.
Definition: SketchPlugin_Trim.h:46
virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious)
Returns the AIS preview.
Definition: SketchPlugin_Trim.cpp:647
SketchPlugin_Trim()
Use plugin manager for features creation.
Definition: SketchPlugin_Trim.cpp:79
virtual void execute()
Creates a new part document if needed.
Definition: SketchPlugin_Trim.cpp:195
virtual const std::string & getKind()
Returns the kind of a feature.
Definition: SketchPlugin_Trim.h:52
static const std::string & PREVIEW_OBJECT()
The value parameter for the preview object.
Definition: SketchPlugin_Trim.h:73
virtual bool isPreviewNeeded() const
Reimplemented from ModelAPI_Feature::isPreviewNeeded().
Definition: SketchPlugin_Trim.h:98
static const std::string & SELECTED_POINT()
Start 2D point of the split segment.
Definition: SketchPlugin_Trim.h:66