Salome HOME
Correct processing of the fixed arc in PlaneGCS (issue #1280)
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MultiTranslation.cpp
index bc4a1675580c4d4019d10e6a62ec74b9d4b11781..0b43bf38ada6e9ba291a9ec00dadf5553616d25f 100755 (executable)
@@ -20,6 +20,7 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <SketchPlugin_SketchEntity.h>
 #include <SketcherPrs_Factory.h>
 
 SketchPlugin_MultiTranslation::SketchPlugin_MultiTranslation()
@@ -62,10 +63,8 @@ void SketchPlugin_MultiTranslation::execute()
     return;
 
   DataPtr aData = data();
-  std::shared_ptr<GeomDataAPI_Point2D> aStart = GeomDataAPI_Point2D::getPoint2D(aData,
-                                                                                START_POINT_ID());
-  std::shared_ptr<GeomDataAPI_Point2D> aEnd = GeomDataAPI_Point2D::getPoint2D(aData,
-                                                                              END_POINT_ID());
+  AttributePoint2DPtr aStart = GeomDataAPI_Point2D::getPoint2D(aData, START_POINT_ID());
+  AttributePoint2DPtr aEnd = GeomDataAPI_Point2D::getPoint2D(aData, END_POINT_ID());
   if (!aStart || !aEnd)
     return;
 
@@ -199,6 +198,45 @@ AISObjectPtr SketchPlugin_MultiTranslation::getAISObject(AISObjectPtr thePreviou
   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(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()) {
+              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();
+}
+
 ObjectPtr SketchPlugin_MultiTranslation::copyFeature(ObjectPtr theObject)
 {
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(theObject);