Salome HOME
Fix for issue #1594
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintMirror.cpp
index 7539c18e38ab868e7a4c6c327130ec435eb141cb..2161806ebd3a21c805f4d2661645e482e216cda1 100755 (executable)
@@ -13,6 +13,7 @@
 #include <ModelAPI_Events.h>
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
+#include <ModelAPI_Tools.h>
 
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Sketch.h>
@@ -70,6 +71,7 @@ void SketchPlugin_ConstraintMirror::execute()
   std::list<ObjectPtr>::iterator anInitIter = anInitialList.begin();
   std::list<ObjectPtr>::iterator aMirrorIter = aMirroredList.begin();
   std::vector<bool>::iterator aUsedIter = isUsed.begin();
+  std::set<FeaturePtr> aFeaturesToBeRemoved;
   for (; aUsedIter != isUsed.end(); aUsedIter++) {
     if (!(*aUsedIter)) {
       aRefListOfShapes->remove(*anInitIter);
@@ -81,7 +83,7 @@ void SketchPlugin_ConstraintMirror::execute()
         DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr();
         FeaturePtr aFeature =  aDoc ? aDoc->feature(aRC) : FeaturePtr();
         if (aFeature)
-          aDoc->removeFeature(aFeature);
+          aFeaturesToBeRemoved.insert(aFeature);
       }
     }
     if (anInitIter != anInitialList.end())
@@ -89,6 +91,7 @@ void SketchPlugin_ConstraintMirror::execute()
     if (aMirrorIter != aMirroredList.end())
       aMirrorIter++;
   }
+  ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved);
 
   static Events_ID aRedisplayEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY);
 
@@ -188,10 +191,8 @@ AISObjectPtr SketchPlugin_ConstraintMirror::getAISObject(AISObjectPtr thePreviou
   if (!sketch())
     return thePrevious;
 
-  AISObjectPtr anAIS = thePrevious;
-  if (!anAIS) {
-    anAIS = SketcherPrs_Factory::mirrorConstraint(this, sketch()->coordinatePlane());
-  }
+  AISObjectPtr anAIS = SketcherPrs_Factory::mirrorConstraint(this, sketch()->coordinatePlane(),
+                                                             thePrevious);
   return anAIS;
 }
 
@@ -214,7 +215,8 @@ void SketchPlugin_ConstraintMirror::erase()
           if(aFeature.get()) {
             AttributeBooleanPtr aBooleanAttr = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
             if(aBooleanAttr.get()) {
-              aBooleanAttr->setValue(false);
+              if (ModelAPI_Session::get()->isOperation()) // if this is not undo or redo
+                aBooleanAttr->setValue(false);
               // Redisplay object as it is not copy anymore.
               ModelAPI_EventCreator::get()->sendUpdated(aRes, aRedispEvent);
             }