Salome HOME
Fixes for crashes and bad behavior on delete of features and Parts. For now delete...
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_ConstraintMirror.cpp
index bfcbf14e72d2110bfa7e03e8f800406fc55a0af9..e17a704c5b5238d08f313cc0766a8eb9e39ec147 100755 (executable)
@@ -188,13 +188,43 @@ 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;
 }
 
+void SketchPlugin_ConstraintMirror::erase()
+{
+  // Set copy attribute to false on all copied features.
+  AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+      data()->attribute(SketchPlugin_Constraint::ENTITY_C()));
+
+  if(aRefListOfMirrored.get()) {
+    static Events_Loop* aLoop = Events_Loop::loop();
+    static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+
+    std::list<ObjectPtr> aTargetList = aRefListOfMirrored->list();
+    for(std::list<ObjectPtr>::const_iterator aTargetIt = aTargetList.cbegin(); aTargetIt != aTargetList.cend(); aTargetIt++) {
+      if((*aTargetIt).get()) {
+        ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(*aTargetIt);
+        if(aRes.get()) {
+          FeaturePtr aFeature = aRes->document()->feature(aRes);
+          if(aFeature.get()) {
+            AttributeBooleanPtr aBooleanAttr = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID());
+            if(aBooleanAttr.get()) {
+              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);
+            }
+          }
+        }
+      }
+    }
+  }
+
+  SketchPlugin_ConstraintBase::erase();
+}
 
 void SketchPlugin_ConstraintMirror::attributeChanged(const std::string& theID)
 {