]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_Trim.h
Salome HOME
#2027 Sketcher Trim Feature: 1. preview/selected attributes in trim; 2. avoid includi...
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Trim.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:    SketchPlugin_Trim.h
4 // Created: 22 Feb 2017
5 // Author:  Natalia ERMOLAEVA
6
7 #ifndef SketchPlugin_Trim_H_
8 #define SketchPlugin_Trim_H_
9
10 #include "SketchPlugin.h"
11 #include <SketchPlugin_Sketch.h>
12 #include "SketchPlugin_ConstraintBase.h"
13
14 class GeomDataAPI_Point2D;
15 class ModelAPI_Feature;
16 class ModelAPI_Result;
17
18 typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
19
20 /** \class SketchPlugin_Trim
21  *  \ingroup Plugins
22  *  \brief Feature for creation of a new constraint trimming object. Entities for split:
23  */
24 class SketchPlugin_Trim : public SketchPlugin_Feature, public GeomAPI_IPresentable
25 {
26  public:
27   /// Split constraint kind
28   inline static const std::string& ID()
29   {
30     static const std::string MY_TRIM_ID("SketchTrim");
31     return MY_TRIM_ID;
32   }
33   /// \brief Returns the kind of a feature
34   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
35   {
36     static std::string MY_KIND = SketchPlugin_Trim::ID();
37     return MY_KIND;
38   }
39
40   /// The value parameter for the constraint
41   inline static const std::string& SELECTED_OBJECT()
42   {
43     static const std::string MY_SELECTED_OBJECT("SelectedObject");
44     return MY_SELECTED_OBJECT;
45   }
46
47   /// Start 2D point of the split segment
48   inline static const std::string& SELECTED_POINT()
49   {
50     static const std::string MY_SELECTED_POINT("SelectedPoint");
51     return MY_SELECTED_POINT;
52   }
53
54   /// The value parameter for the preview object
55   inline static const std::string& PREVIEW_OBJECT()
56   {
57     static const std::string MY_PREVIEW_OBJECT("PreviewObject");
58     return MY_PREVIEW_OBJECT;
59   }
60
61   /// Start 2D point of the split segment
62   inline static const std::string& PREVIEW_POINT()
63   {
64     static const std::string MY_PREVIEW_POINT("PreviewPoint");
65     return MY_PREVIEW_POINT;
66   }
67
68   /// \brief Creates a new part document if needed
69   SKETCHPLUGIN_EXPORT virtual void execute();
70
71   /// \brief Request for initialization of data model of the feature: adding all attributes
72   SKETCHPLUGIN_EXPORT virtual void initAttributes();
73
74   /// Reimplemented from ModelAPI_Feature::isMacro()
75   /// \returns true
76   SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
77
78   /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
79   /// This is necessary to perform execute only by apply the feature
80   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
81
82   /// \brief Use plugin manager for features creation
83   SketchPlugin_Trim();
84
85   /// Returns the AIS preview
86   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
87
88   /// Moves the feature : Empty
89   SKETCHPLUGIN_EXPORT virtual void move(const double theDeltaX, const double theDeltaY) {};
90
91   typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
92                    std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
93                              std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
94
95   static void fillObjectShapes(const ObjectPtr& theObject,
96                    ObjectPtr& theSketch,
97                    std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
98                    std::map<ObjectPtr, PointToRefsMap>& theObjectToPoints);
99
100 private:
101   GeomShapePtr getSubShape(const std::string& theObjectAttributeId,
102                            const std::string& thePointAttributeId);
103
104   /// Returns geom point attribute of the feature bounds. It processes line or arc.
105   /// For circle feature, the result attributes are null
106   /// \param theFeature a source feature
107   /// \param theStartPointAttr an out attribute to start point
108   /// \param theStartPointAttr an out attribute to end point
109   void getFeaturePoints(const FeaturePtr& theFeature,
110                         std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
111                         std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
112
113   /// Obtains those constraints of the feature that should be modified. output maps contain
114   /// point of coincidence and attribute id to be modified after split
115   /// \param theFeaturesToDelete [out] constrains that will be deleted after split
116   void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
117
118   /// Obtains references to feature point attributes and to feature,
119   /// e.g. for feature line: 1st container is
120   ///             <1st line point, list<entity_a in distance, entity_b in parallel> >
121   ///             <2nd line point, list<> >
122   ///      for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
123   /// \param theFeature an investigated feature
124   /// \param theRefs a container of list of referenced attributes
125   void getRefAttributes(const FeaturePtr& theFeature,
126                         std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
127                         std::list<AttributePtr>& theRefsToFeature);
128
129   /// Obtains coincident features to the given object. It is collected in a container
130   /// by the coincident attribute
131   /// \param theObject an investigated object
132   /// \param theCoincidencesToBaseFeature a container of list of referenced attributes
133   void getCoincidencesToObject(const ObjectPtr& theObject,
134                                std::map<AttributePtr, FeaturePtr>& theCoincidencesToBaseFeature);
135
136   /// Move constraints from attribute of base feature to attribute after modification
137   /// \param theBaseRefAttributes container of references to the attributes of base feature
138   /// \param theModifiedAttributes container of attributes placed instead of base attributes
139   /// at the same place
140   void updateRefAttConstraints(
141                const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
142                const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
143                std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
144
145   /// Make the base object is splitted by the point attributes
146   /// \param theSplitFeature a result split feature
147   /// \param theBeforeFeature a feature between start point and the 1st point of split feature
148   /// \param theAfterFeature a feature between last point of split feature and the end point
149   /// \param thePoints a list of points where coincidences will be build
150   /// \param theModifiedAttributes a container of attribute on base
151   /// feature to attribute on new feature
152   void trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
153                 const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
154                 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
155                 std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
156
157   /// Make the base object is splitted by the point attributes
158   /// \param theSplitFeature a result split feature
159   /// \param theBeforeFeature a feature between start point and the 1st point of split feature
160   /// \param theAfterFeature a feature between last point of split feature and the end point
161   /// \param thePoints a list of points where coincidences will be build
162   void trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
163                const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
164                std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
165                std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
166
167   /// Make the base object is splitted by the point attributes
168   /// \param theSplitFeature a result split feature
169   /// \param theBeforeFeature a feature between start point and the 1st point of split feature
170   /// \param theAfterFeature a feature between last point of split feature and the end point
171   /// \param thePoints a list of points where coincidences will be build
172   FeaturePtr trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
173                   const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
174                   std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
175                   std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes);
176
177   /// Correct the first and the second point to provide condition that the first is closer to
178   /// the start point and the second point - to the last end of current segment. To rearrange
179   /// them if this condition is not satisfied.
180   /// \param theStartPointAttr a start point of a segment
181   /// \param theEndPointAttr an end point of a segment
182   /// \param theFirstPoint a start point of a segment
183   /// \param theSecondPoint an end point of a segment
184   void arrangePointsOnLine(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
185                            const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
186                            std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
187                            std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
188
189   /// Correct the first and the second point to provide condition that the first is closer to
190   /// the start point and the second point - to the last end of current segment. To rearrange
191   /// them if this condition is not satisfied.
192   /// \param theArc an arc to be split
193   /// \param theStartPointAttr a start point of a segment
194   /// \param theEndPointAttr an end point of a segment
195   /// \param theFirstPoint a start point of a segment
196   /// \param theSecondPoint an end point of a segment
197   void arrangePointsOnArc(const FeaturePtr& theArc,
198                           const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
199                           const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
200                           std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
201                           std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint) const;
202
203   /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
204   /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
205   /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
206   void fillAttribute(const AttributePtr& theModifiedAttribute,
207                      const AttributePtr& theSourceAttribute);
208
209   /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
210   /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
211   /// \param thePoint a point value
212   void fillPointAttribute(const AttributePtr& theModifiedAttribute,
213                           const std::shared_ptr<GeomAPI_Pnt2d>& thePoint);
214
215   /// Creates a line feature filled by center of base feature and given points
216   /// \param theBaseFeature another arc feature
217   /// \param theFirstAttribute an attribute with coordinates for the start point
218   /// \param theSecondAttribute an attribute with coordinates for the end point
219   FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
220                                const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
221                                const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
222
223   /// Creates an arc feature filled by center of base feature and given points
224   /// \param theBaseFeature another arc feature
225   /// \param theFirstAttribute an attribute with coordinates for the start point
226   /// \param theSecondAttribute an attribute with coordinates for the end point
227   FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
228                               const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
229                               const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
230
231   /// Add feature coincidence constraint between given attributes
232   /// \param theConstraintId a constraint index
233   /// \param theFirstAttribute an attribute of further coincidence
234   /// \param theSecondAttribute an attribute of further coincidence
235   std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
236                         const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
237                         const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
238
239   /// Add feature coincidence constraint between given attributes
240   /// \param theConstraintId a constraint index
241   /// \param theFirstAttribute an attribute of further coincidence
242   /// \param theSecondObject an object of further coincidence
243   std::shared_ptr<ModelAPI_Feature> createConstraintToObject(const std::string& theConstraintId,
244                         const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
245                         const std::shared_ptr<ModelAPI_Object>& theSecondObject);
246
247   /// Add feature coincidence constraint between given attributes
248   /// \param theConstraintId a constraint index
249   /// \param theFirstAttribute an attribute of further coincidence
250   /// \param theFirstAttribute an attribute of further coincidence
251   std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
252                         const std::shared_ptr<ModelAPI_Object>& theFirstObject,
253                         const std::shared_ptr<ModelAPI_Object>& theSecondObject);
254
255   /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
256   /// \param theFeature a feature
257   /// \return result object
258   std::shared_ptr<ModelAPI_Result> getFeatureResult(
259                                     const std::shared_ptr<ModelAPI_Feature>& theFeature);
260
261 private:
262   void findShapePoints(const std::string& theObjectAttributeId,
263                        const std::string& thePointAttributeId,
264                        std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
265                        std::shared_ptr<GeomAPI_Pnt>& aLastPoint);
266
267   std::shared_ptr<GeomAPI_Pnt2d> convertPoint(const std::shared_ptr<GeomAPI_Pnt>& thePoint);
268
269 private:
270   std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
271
272   std::map<ObjectPtr, PointToRefsMap> myObjectToPoints;
273 };
274
275 #endif