Salome HOME
Update unit-tests for SketchPlugin. Test case for the Projection has been added
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MultiTranslation.cpp
index df58c765db0a0f62a52f68ed0a069d5d60f06766..5e0a93098924892d5c215b3c6db5ddcbfa16b9a6 100755 (executable)
@@ -191,33 +191,38 @@ AISObjectPtr SketchPlugin_MultiTranslation::getAISObject(AISObjectPtr thePreviou
   if (!sketch())
     return thePrevious;
 
-  AISObjectPtr anAIS = thePrevious;
-  if (!anAIS) {
-    anAIS = SketcherPrs_Factory::translateConstraint(this, sketch()->coordinatePlane());
-  }
+  AISObjectPtr anAIS = SketcherPrs_Factory::translateConstraint(this, sketch()->coordinatePlane(),
+                                                                thePrevious);
   return anAIS;
 }
 
 void SketchPlugin_MultiTranslation::erase()
 {
+  static Events_Loop* aLoop = Events_Loop::loop();
+  static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+
   // Set copy attribute to false on all copied features.
+  AttributeRefListPtr aRefListOfShapes = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+      data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
   AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
       data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
 
-  if(aRefListOfTranslated.get()) {
-    static Events_Loop* aLoop = Events_Loop::loop();
-    static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
-
-    std::list<ObjectPtr> aTargetList = aRefListOfTranslated->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(aRefListOfShapes.get() && aRefListOfTranslated.get()) {
+    for(int anIndex = 0; anIndex < aRefListOfTranslated->size(); anIndex++) {
+      ObjectPtr anObject = aRefListOfTranslated->object(anIndex);
+      if(aRefListOfShapes->isInList(anObject)) {
+        // Don't modify attribute of original features, just skip.
+        continue;
+      }
+      if(anObject.get()) {
+        ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(anObject);
         if(aRes.get()) {
           FeaturePtr aFeature = aRes->document()->feature(aRes);
           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);
             }