Salome HOME
Fix for the issue #593: do not remove naming attribute, but use TNaming_Builder for...
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_Sketch.cpp
index 2d02f0dd10f3a64e2900c035b30f96cb48e06cb9..f7d09acbba8c470885577364080549c77b94cb5d 100644 (file)
@@ -137,7 +137,7 @@ std::shared_ptr<ModelAPI_Feature> SketchPlugin_Sketch::addFeature(std::string th
 
 void SketchPlugin_Sketch::removeFeature(std::shared_ptr<ModelAPI_Feature> theFeature)
 {
-  if (!data().get()) // sketch is already removed (case on undo of sketch), sync is not needed
+  if (!data()->isValid()) // sketch is already removed (case on undo of sketch), sync is not needed
     return;
   list<ObjectPtr> aSubs = data()->reflist(SketchPlugin_Sketch::FEATURES_ID())->list();
   list<ObjectPtr>::iterator aSubIt = aSubs.begin(), aLastIt = aSubs.end();
@@ -280,3 +280,17 @@ void SketchPlugin_Sketch::createPoint2DResult(ModelAPI_Feature* theFeature,
 
   theFeature->setResult(aResult, theIndex);
 }
+
+FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeature,
+                                                            SketchPlugin_Sketch* theSketch)
+{
+  FeaturePtr aNewFeature = theSketch->addFeature(theFeature->getKind());
+  // addFeature generates a unique name for the feature, it caches the name
+  std::string aUniqueFeatureName = aNewFeature->data()->name();
+  // all attribute values are copied\pasted to the new feature, name is not an exception
+  theFeature->data()->copyTo(aNewFeature->data());
+  // as a name for the feature, the generated unique name is set
+  aNewFeature->data()->setName(aUniqueFeatureName);
+
+  return aNewFeature;
+}