]> SALOME platform Git repositories - modules/shaper.git/blob - src/SketchPlugin/SketchPlugin_ConstraintSplit.h
Salome HOME
Merge remote-tracking branch 'remotes/origin/HighLevelDump'
[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   /// Obtains those constraints of the feature that should be modified
110   /// \param theSplitFeature a result split feature
111   /// \param theBaseFeature a modified base feature
112   /// \param theAfterFeature an additional created feature if source segement contain three parts
113   /// \param theFeaturesToDelete [out] constrains that will be deleted after split
114   /// \param theTangentFeatures  [out] tangent feature to be connected to new feature
115   /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
116   /// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
117   /*void setConstraints(const FeaturePtr& theSplitFeature,
118                       const FeaturePtr& theBaseFeature,
119                       const FeaturePtr& theAfterFeature,
120     const std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
121     const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
122     const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
123     const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToPoint);*/
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   void splitArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
131                 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
132                 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
133                 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints);
134
135   /// Correct the first and the second point to provide condition that the first is closer to
136   /// the start point and the second point - to the last end of current segment. To rearrange
137   /// them if this condition is not satisfied.
138   /// \param theStartPointAttr a start point of a segment
139   /// \param theEndPointAttr an end point of a segment
140   /// \param theFirstPointAttr a start point of a segment
141   /// \param theSecondPointAttr an end point of a segment
142   void arrangePoints(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
143                      const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
144                      std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
145                      std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr);
146
147   /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
148   /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
149   /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
150   void fillAttribute(const AttributePtr& theModifiedAttribute,
151                      const AttributePtr& theSourceAttribute);
152
153   /// Creates an arc feature filled by center of base feature and given points
154   /// \param theBaseFeature another arc feature
155   /// \param theFirstAttribute an attribute with coordinates for the start point
156   /// \param theSecondAttribute an attribute with coordinates for the end point
157   FeaturePtr createArcFeature(const FeaturePtr& theBaseFeature,
158                               const AttributePtr& theFirstPointAttr,
159                               const AttributePtr& theSecondPointAttr);
160
161   /// Add feature coincidence constraint between given attributes
162   /// \param theConstraintId a constraint index
163   /// \param theFirstAttribute an attribute of further coincidence
164   /// \param theSecondAttribute an attribute of further coincidence
165   void createConstraint(const std::string& theConstraintId,
166                         const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
167                         const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
168
169   /// Add feature coincidence constraint between given attributes
170   /// \param theConstraintId a constraint index
171   /// \param theFirstAttribute an attribute of further coincidence
172   /// \param theFirstAttribute an attribute of further coincidence
173   void createConstraintForObjects(const std::string& theConstraintId,
174                         const std::shared_ptr<ModelAPI_Object>& theFirstObject,
175                         const std::shared_ptr<ModelAPI_Object>& theSecondObject);
176
177   /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
178   /// \param theFeature a feature
179   /// \return result object
180   std::shared_ptr<ModelAPI_Result> getFeatureResult(
181                                     const std::shared_ptr<ModelAPI_Feature>& theFeature);
182 private:
183   //std::set<AttributePtr> myNewPoints; ///< set of new points
184   //std::map<AttributePtr, FilletFeatures> myPointFeaturesMap; ///< map of point and features for fillet
185   //bool myListOfPointsChangedInCode; ///< flag to track that list of points changed in code
186   //bool myRadiusChangedByUser; ///< flag to track that radius changed by user
187   //bool myRadiusChangedInCode; ///< flag to track that radius changed in code
188   //bool myRadiusInitialized; /// < flag to track that radius initialized
189 };
190
191 #endif