+typedef std::map<int, std::shared_ptr<SketchPlugin_Feature>> IndexedFeatureMap;
+
+static void featuresOrderedByCreation(const std::set<ObjectPtr>& theOriginalFeatures,
+ IndexedFeatureMap& theOrderedFeatures)
+{
+ std::set<ObjectPtr>::iterator aFeatIter = theOriginalFeatures.begin();
+ for (; aFeatIter != theOriginalFeatures.end(); aFeatIter++) {
+ std::shared_ptr<SketchPlugin_Feature> aFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+ if (aFeature && !aFeature->isMacro() && aFeature->data() && aFeature->data()->isValid()) {
+ theOrderedFeatures[aFeature->data()->featureId()] = aFeature;
+ }
+ }
+}
+
+static void featuresOrderedByType(const std::set<ObjectPtr>& theOriginalFeatures,
+ IndexedFeatureMap& theOrderedFeatures,
+ CompositeFeaturePtr& theSketch)
+{
+ int aFeatureIndex = 0;
+ int aConstraintIndex = (int)theOriginalFeatures.size();
+
+ std::set<ObjectPtr>::iterator aFeatIter = theOriginalFeatures.begin();
+ for (; aFeatIter != theOriginalFeatures.end(); aFeatIter++) {
+ std::shared_ptr<SketchPlugin_Feature> aFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(*aFeatIter);
+ if (aFeature) {
+ if (!aFeature->isMacro() && aFeature->data() && aFeature->data()->isValid()) {
+ std::shared_ptr<SketchPlugin_Constraint> aConstraint =
+ std::dynamic_pointer_cast<SketchPlugin_Constraint>(aFeature);
+ if (aConstraint)
+ theOrderedFeatures[++aConstraintIndex] = aFeature;
+ else
+ theOrderedFeatures[++aFeatureIndex] = aFeature;
+ }
+ }
+ else {
+ CompositeFeaturePtr aSketch =
+ std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aFeatIter);
+ if (aSketch && aSketch->getKind() == SketchPlugin_Sketch::ID())
+ theSketch = aSketch;
+ }
+ }
+}
+
+static void setPoint(AttributePtr theAttribute,
+ const int thePointIndex,
+ const std::shared_ptr<GeomAPI_Pnt2d> theValue)
+{
+ AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
+ AttributePoint2DArrayPtr aPointArrayAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
+ if (aPointAttr)
+ aPointAttr->setValue(theValue);
+ else if (aPointArrayAttr && thePointIndex >= 0)
+ aPointArrayAttr->setPnt(thePointIndex, theValue);
+}
+