1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
3 // File: SketchPlugin_ConstraintSplit.h
4 // Created: 19 Mar 2015
5 // Author: Artem ZHIDKOV
7 #ifndef SketchPlugin_ConstraintSplit_H_
8 #define SketchPlugin_ConstraintSplit_H_
10 #include "SketchPlugin.h"
11 #include <SketchPlugin_Sketch.h>
12 #include "SketchPlugin_ConstraintBase.h"
14 class GeomDataAPI_Point2D;
15 class ModelAPI_Feature;
16 class ModelAPI_Result;
18 typedef std::pair<std::string, std::shared_ptr<GeomDataAPI_Point2D> > IdToPointPair;
20 /** \class SketchPlugin_ConstraintSplit
22 * \brief Feature for creation of a new constraint filleting two objects which have coincident point
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;
28 * Also the constraint has attribute SketchPlugin_Constraint::ENTITY_C()
29 * which contains created list objects forming the fillet
31 class SketchPlugin_ConstraintSplit : public SketchPlugin_ConstraintBase
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
40 /// Split constraint kind
41 inline static const std::string& ID()
43 static const std::string MY_CONSTRAINT_SPLIT_ID("SketchConstraintSplit");
44 return MY_CONSTRAINT_SPLIT_ID;
46 /// \brief Returns the kind of a feature
47 SKETCHPLUGIN_EXPORT virtual const std::string& getKind()
49 static std::string MY_KIND = SketchPlugin_ConstraintSplit::ID();
53 /// \brief Creates a new part document if needed
54 SKETCHPLUGIN_EXPORT virtual void execute();
56 /// \brief Request for initialization of data model of the feature: adding all attributes
57 SKETCHPLUGIN_EXPORT virtual void initAttributes();
59 /// Returns the AIS preview
60 //SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
62 /// Reimplemented from ModelAPI_Feature::isMacro().
64 SKETCHPLUGIN_EXPORT virtual bool isMacro() const;
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; }
70 /// \brief Use plugin manager for features creation
71 SketchPlugin_ConstraintSplit();
73 /// \return map of base points and features;
74 //SKETCHPLUGIN_EXPORT const std::map<AttributePtr, FilletFeatures> pointsFeaturesMap() const {
75 // return myPointFeaturesMap;
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);
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);
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);
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);
109 /// Move coincidence constraint from feature to point if it is found
110 /// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
111 /// \param theFurtherCoincidences a list of points where coincidences will be build
112 void updateCoincidenceConstraintsToFeature(
113 const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
114 const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
115 const std::set<ResultPtr>& theFeatureResults);
117 /// Make the base object is splitted by the point attributes
118 /// \param theSplitFeature a result split feature
119 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
120 /// \param theAfterFeature a feature between last point of split feature and the end point
121 /// \param thePoints a list of points where coincidences will be build
122 /// \param theCreatedFeatures a container of created features
123 void splitLine(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
124 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
125 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
126 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
127 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
129 /// Make the base object is splitted by the point attributes
130 /// \param theSplitFeature a result split feature
131 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
132 /// \param theAfterFeature a feature between last point of split feature and the end point
133 /// \param thePoints a list of points where coincidences will be build
134 /// \param theCreatedFeatures a container of created features
135 void splitArc(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
136 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
137 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
138 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
139 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
141 /// Make the base object is splitted by the point attributes
142 /// \param theSplitFeature a result split feature
143 /// \param theBeforeFeature a feature between start point and the 1st point of split feature
144 /// \param theAfterFeature a feature between last point of split feature and the end point
145 /// \param thePoints a list of points where coincidences will be build
146 /// \param theCreatedFeatures a container of created features
147 void splitCircle(std::shared_ptr<ModelAPI_Feature>& theSplitFeature,
148 std::shared_ptr<ModelAPI_Feature>& theBeforeFeature,
149 std::shared_ptr<ModelAPI_Feature>& theAfterFeature,
150 std::set<std::shared_ptr<GeomDataAPI_Point2D> >& thePoints,
151 std::set<std::shared_ptr<ModelAPI_Feature>>& theCreatedFeatures);
153 /// Correct the first and the second point to provide condition that the first is closer to
154 /// the start point and the second point - to the last end of current segment. To rearrange
155 /// them if this condition is not satisfied.
156 /// \param theStartPointAttr a start point of a segment
157 /// \param theEndPointAttr an end point of a segment
158 /// \param theFirstPointAttr a start point of a segment
159 /// \param theSecondPointAttr an end point of a segment
160 void arrangePoints(const std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
161 const std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr,
162 std::shared_ptr<GeomDataAPI_Point2D>& theFirstPointAttr,
163 std::shared_ptr<GeomDataAPI_Point2D>& theSecondPointAttr);
165 /// Fill attribute by value of another attribute. It processes only Point 2D attributes.
166 /// \param theModifiedAttribute an attribute of GeomDataAPI_Point2D on feature to be modified
167 /// \param theSourceAttribute an attribute of GeomDataAPI_Point2D to obtain data
168 void fillAttribute(const AttributePtr& theModifiedAttribute,
169 const AttributePtr& theSourceAttribute);
171 /// Creates a line feature filled by center of base feature and given points
172 /// \param theBaseFeature another arc feature
173 /// \param theFirstAttribute an attribute with coordinates for the start point
174 /// \param theSecondAttribute an attribute with coordinates for the end point
175 FeaturePtr createLineFeature(const FeaturePtr& theBaseFeature,
176 const AttributePtr& theFirstPointAttr,
177 const AttributePtr& theSecondPointAttr);
179 /// Creates an arc 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 createArcFeature(const FeaturePtr& theBaseFeature,
184 const AttributePtr& theFirstPointAttr,
185 const AttributePtr& theSecondPointAttr);
187 /// Add feature coincidence constraint between given attributes
188 /// \param theConstraintId a constraint index
189 /// \param theFirstAttribute an attribute of further coincidence
190 /// \param theSecondAttribute an attribute of further coincidence
191 std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
192 const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
193 const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
195 /// Add feature coincidence constraint between given attributes
196 /// \param theConstraintId a constraint index
197 /// \param theFirstAttribute an attribute of further coincidence
198 /// \param theFirstAttribute an attribute of further coincidence
199 std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
200 const std::shared_ptr<ModelAPI_Object>& theFirstObject,
201 const std::shared_ptr<ModelAPI_Object>& theSecondObject);
203 /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
204 /// \param theFeature a feature
205 /// \return result object
206 std::shared_ptr<ModelAPI_Result> getFeatureResult(
207 const std::shared_ptr<ModelAPI_Feature>& theFeature);
209 /// Returns attributes of the feature, used in edge build, for arc it is end and start points
210 /// \param theFeature a feature
211 /// \return container of attributes
212 std::set<std::shared_ptr<ModelAPI_Attribute> > getEdgeAttributes(
213 const std::shared_ptr<ModelAPI_Feature>& theFeature);
215 /// Return feature name, kind, point attribute values united in a string
216 /// \param theFeature an investigated feature
217 /// \return string value
218 std::string getFeatureInfo(const std::shared_ptr<ModelAPI_Feature>& theFeature,
219 const bool isUseAttributesInfo = true);
222 //std::set<AttributePtr> myNewPoints; ///< set of new points
223 //std::map<AttributePtr, FilletFeatures> myPointFeaturesMap; ///< map of point and features for fillet
224 //bool myListOfPointsChangedInCode; ///< flag to track that list of points changed in code
225 //bool myRadiusChangedByUser; ///< flag to track that radius changed by user
226 //bool myRadiusChangedInCode; ///< flag to track that radius changed in code
227 //bool myRadiusInitialized; /// < flag to track that radius initialized