Salome HOME
Renamed SHAPER_CONFIG_FILE to PLUGINS_CONFIG_FILE
[modules/shaper.git] / src / SketchPlugin / SketchPlugin_MultiRotation.cpp
index e878ea50d612b3a9db9d9899f0ec7bb2879f4853..fcfd0262485515979dc1ff078482ac9c0e0f2fff 100755 (executable)
@@ -19,6 +19,8 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <SketchPlugin_SketchEntity.h>
+
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_XY.h>
 
@@ -202,13 +204,49 @@ AISObjectPtr SketchPlugin_MultiRotation::getAISObject(AISObjectPtr thePrevious)
   if (!sketch())
     return thePrevious;
 
-  AISObjectPtr anAIS = thePrevious;
-  if (!anAIS) {
-    anAIS = SketcherPrs_Factory::rotateConstraint(this, sketch()->coordinatePlane());
-  }
+  AISObjectPtr anAIS = SketcherPrs_Factory::rotateConstraint(this, sketch()->coordinatePlane(),
+                                                             thePrevious);
   return anAIS;
 }
 
+void SketchPlugin_MultiRotation::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 aRefListOfRotated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+      data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
+
+  if(aRefListOfShapes.get() && aRefListOfRotated.get()) {
+    for(int anIndex = 0; anIndex < aRefListOfRotated->size(); anIndex++) {
+      ObjectPtr anObject = aRefListOfRotated->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_MultiRotation::copyFeature(ObjectPtr theObject)
 {