]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ConstraintSplit.h
Salome HOME
d06c7d548a610a07fce5bd43bbb4928ca8869821
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintSplit.h
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
2
3 // File:    SketchPlugin_ConstraintSplit.h
4 // Created: 19 Mar 2015
5 // Author:  Artem ZHIDKOV
6
7 #ifndef SketchPlugin_ConstraintSplit_H_
8 #define SketchPlugin_ConstraintSplit_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_ConstraintSplit
21  *  \ingroup Plugins
22  *  \brief Feature for creation of a new constraint filleting two objects which have coincident point
23  *
24  *  This constraint has three attributes:
25  *  SketchPlugin_Constraint::VALUE() contains reference object to be splitted
26  *  SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() for the points of split;
27  *
28  *  Also the constraint has attribute SketchPlugin_Constraint::ENTITY_C()
29  *  which contains created list objects forming the fillet
30  */
31 class SketchPlugin_ConstraintSplit : public SketchPlugin_ConstraintBase
32 {
33  public:
34    /*struct FilletFeatures {
35     std::list<std::pair<FeaturePtr, bool>> baseEdgesState; ///< list of objects the fillet is based and its states
36     std::list<FeaturePtr> resultEdges; ///< list of result edges
37     std::list<FeaturePtr> resultConstraints; ///< list of constraints provided by the fillet
38    };*/
39
40   /// Split constraint kind
41   inline static const std::string& ID()
42   {
43     static const std::string MY_CONSTRAINT_SPLIT_ID("SketchConstraintSplit");
44     return MY_CONSTRAINT_SPLIT_ID;
45   }
46   /// \brief Returns the kind of a feature
47   SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
48   {
49     static std::string MY_KIND = SketchPlugin_ConstraintSplit::ID();
50     return MY_KIND;
51   }
52
53   /// \brief Creates a new part document if needed
54   SKETCHPLUGIN_EXPORT virtual void execute();
55
56   /// \brief Request for initialization of data model of the feature: adding all attributes
57   SKETCHPLUGIN_EXPORT virtual void initAttributes();
58
59   /// Returns the AIS preview
60   //SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
61
62   /// Reimplemented from ModelAPI_Feature::isMacro().
63   /// \returns true
64   SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
65
66   /// Reimplemented from ModelAPI_Feature::isPreviewNeeded(). Returns false.
67   /// This is necessary to perform execute only by apply the feature
68   SKETCHPLUGIN_EXPORT virtual bool isPreviewNeeded() const { return false; }
69
70   /// \brief Use plugin manager for features creation
71   SketchPlugin_ConstraintSplit();
72
73   /// \return map of base points and features;
74   //SKETCHPLUGIN_EXPORT const std::map<AttributePtr, FilletFeatures> pointsFeaturesMap() const {
75   //  return myPointFeaturesMap;
76   //};
77
78 private:
79   /// Returns geom point attribute of the feature bounds. It processes line or arc.
80   /// For circle feature, the result attributes are null
81   /// \param theStartPointAttr an out attribute to start point
82   /// \param theStartPointAttr an out attribute to end point
83   void getFeaturePoints(std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
84                         std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
85
86   /// Returns cast of attribute to geometrical point if the attribute is a ref attr attribute
87   /// \param theAttribute an attribute
88   /// \param geom point 2D or NULL
89   std::shared_ptr<GeomDataAPI_Point2D> getPointOfRefAttr(const AttributePtr& theAttribute);
90
91   /// Creates a new feature in the base shape type with bounding points given in parameters
92   /// \param theStartPointAttr an attribute of the start point
93   /// \param theEndPointAttr an attribute of the end point
94   //std::shared_ptr<ModelAPI_Feature> createFeature(
95   //                                  const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
96   //                                  const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
97
98   /// Obtains those constraints of the feature that should be modified. output maps contain
99   /// point of coincidence and attribute id to be modified after split
100   /// \param theFeaturesToDelete [out] constrains that will be deleted after split
101   /// \param theTangentFeatures  [out] tangent feature to be connected to new feature
102   /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
103   /// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
104   void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
105               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
106               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
107               std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToPoint);
108
109   /// Move coincidence constraint from feature to point if it is found
110   /// \param theCoincidenceToFeature coincidence to feature to be connected to new feature
111   /// \param theFurtherCoincidences a list of points where coincidences will be build
112   /// \paramv theFeatureResults created results after split where constaint might be connected
113   void updateCoincidenceConstraintsToFeature(
114               const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
115               const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
116               const std::set<ResultPtr>& theFeatureResults);
117
118   /// Move tangency constraint to the nearest split feature that has a coincidence to the tangent
119   /// \param theTangentFeatures tangencies to feature to be connected to nearest feature
120   /// \param theFurtherCoincidences a list of points where coincidences is built
121   void updateTangentConstraintsToFeature(
122               const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
123               const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences);
124
125   /// Make the base object is splitted by the point attributes
126   /// \param theSplitFeature a result split feature
127   /// \param theBeforeFeature a feature between start point and the 1st point of split feature
128   /// \param theAfterFeature a feature between last point of split feature and the end point
129   /// \param thePoints a list of points where coincidences will be build
130   /// \param theCreatedFeatures a container of created features
131   void splitLine(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
132                  std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
133                  std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
134                  std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
135                  std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
136
137   /// Make the base object is splitted by the point attributes
138   /// \param theSplitFeature a result split feature
139   /// \param theBeforeFeature a feature between start point and the 1st point of split feature
140   /// \param theAfterFeature a feature between last point of split feature and the end point
141   /// \param thePoints a list of points where coincidences will be build
142   /// \param theCreatedFeatures a container of created features
143   void splitArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
144                 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
145                 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
146                 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
147                 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
148
149   /// Make the base object is splitted by the point attributes
150   /// \param theSplitFeature a result split feature
151   /// \param theBeforeFeature a feature between start point and the 1st point of split feature
152   /// \param theAfterFeature a feature between last point of split feature and the end point
153   /// \param thePoints a list of points where coincidences will be build
154   /// \param theCreatedFeatures a container of created features
155   void splitCircle(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
156                    std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
157                    std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
158                    std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
159                    std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
160
161   /// Correct the first and the second point to provide condition that the first is closer to
162   /// the start point and the second point - to the last end of current segment. To rearrange
163   /// them if this condition is not satisfied.
164   /// \param theStartPointAttr a start point of a segment
165   /// \param theEndPointAttr an end point of a segment
166   /// \param theFirstPointAttr a start point of a segment
167   /// \param theSecondPointAttr an end point of a segment
168   void arrangePoints(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
169                      const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
170                      std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
171                      std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr);
172
173   /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
174   /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
175   /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
176   void fillAttribute(const AttributePtr& theModifiedAttribute,
177                      const AttributePtr& theSourceAttribute);
178
179   /// Creates a line feature filled by center of base feature and given points
180   /// \param theBaseFeature another arc feature
181   /// \param theFirstAttribute an attribute with coordinates for the start point
182   /// \param theSecondAttribute an attribute with coordinates for the end point
183   FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
184                                const AttributePtr& theFirstPointAttr,
185                                const AttributePtr& theSecondPointAttr);
186
187   /// Creates an arc feature filled by center of base feature and given points
188   /// \param theBaseFeature another arc feature
189   /// \param theFirstAttribute an attribute with coordinates for the start point
190   /// \param theSecondAttribute an attribute with coordinates for the end point
191   FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
192                               const AttributePtr& theFirstPointAttr,
193                               const AttributePtr& theSecondPointAttr);
194
195   /// Add feature coincidence constraint between given attributes
196   /// \param theConstraintId a constraint index
197   /// \param theFirstAttribute an attribute of further coincidence
198   /// \param theSecondAttribute an attribute of further coincidence
199   std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
200                         const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
201                         const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
202
203   /// Add feature coincidence constraint between given attributes
204   /// \param theConstraintId a constraint index
205   /// \param theFirstAttribute an attribute of further coincidence
206   /// \param theFirstAttribute an attribute of further coincidence
207   std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
208                         const std::shared_ptr<ModelAPI_Object>& theFirstObject,
209                         const std::shared_ptr<ModelAPI_Object>& theSecondObject);
210
211   /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
212   /// \param theFeature a feature
213   /// \return result object
214   std::shared_ptr<ModelAPI_Result> getFeatureResult(
215                                     const std::shared_ptr<ModelAPI_Feature>& theFeature);
216
217   /// Returns attributes of the feature, used in edge build, for arc it is end and start points
218   /// \param theFeature a feature
219   /// \return container of attributes
220   std::set<std::shared_ptr<ModelAPI_Attribute> > getEdgeAttributes(
221                                     const std::shared_ptr<ModelAPI_Feature>& theFeature);
222
223   /// Return feature name, kind, point attribute values united in a string
224   /// \param theFeature an investigated feature
225   /// \return string value
226   std::string getFeatureInfo(const std::shared_ptr<ModelAPI_Feature>& theFeature,
227                              const bool isUseAttributesInfo = true);
228
229 private:
230   //std::set<AttributePtr> myNewPoints; ///< set of new points
231   //std::map<AttributePtr, FilletFeatures> myPointFeaturesMap; ///< map of point and features for fillet
232   //bool myListOfPointsChangedInCode; ///< flag to track that list of points changed in code
233   //bool myRadiusChangedByUser; ///< flag to track that radius changed by user
234   //bool myRadiusChangedInCode; ///< flag to track that radius changed in code
235   //bool myRadiusInitialized; /// < flag to track that radius initialized
236 };
237
238 #endif