]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Remove copied objects in Mirror, Translation and Rotation, when the empty space is...
authorazv <azv@opencascade.com>
Thu, 2 Jul 2015 13:34:48 +0000 (16:34 +0300)
committerazv <azv@opencascade.com>
Thu, 2 Jul 2015 13:34:48 +0000 (16:34 +0300)
src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp
src/SketchPlugin/SketchPlugin_ConstraintMirror.h
src/SketchPlugin/SketchPlugin_MultiRotation.cpp
src/SketchPlugin/SketchPlugin_MultiRotation.h
src/SketchPlugin/SketchPlugin_MultiTranslation.cpp
src/SketchPlugin/SketchPlugin_MultiTranslation.h

index 03a3a90058b6d64fb63c7d64ed2961ef713d1c07..dfc90aa492f4668da8338ff74f4357c96305fe90 100644 (file)
@@ -201,3 +201,37 @@ AISObjectPtr SketchPlugin_ConstraintMirror::getAISObject(AISObjectPtr thePreviou
 }
 
 
+void SketchPlugin_ConstraintMirror::attributeChanged(const std::string& theID)
+{
+  if (theID == MIRROR_LIST_ID()) {
+    AttributeSelectionListPtr aMirrorObjectRefs = selectionList(MIRROR_LIST_ID());
+    if (aMirrorObjectRefs->size() == 0) {
+      // Wait all objects being created, then send update events
+      static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+      bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
+      if (isUpdateFlushed)
+        Events_Loop::loop()->setFlushed(anUpdateEvent, false);
+
+      // Clear list of objects
+      AttributeRefListPtr aRefListOfMirrored = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+          data()->attribute(SketchPlugin_Constraint::ENTITY_C()));
+      std::list<ObjectPtr> aTargetList = aRefListOfMirrored->list();
+      std::list<ObjectPtr>::iterator aTargetIter = aTargetList.begin();
+      for (; aTargetIter != aTargetList.end(); aTargetIter++) {
+        aRefListOfMirrored->remove(*aTargetIter);
+        // remove the corresponding feature from the sketch
+        ResultConstructionPtr aRC =
+            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aTargetIter);
+        DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr();
+        FeaturePtr aFeature =  aDoc ? aDoc->feature(aRC) : FeaturePtr();
+        if (aFeature)
+          aDoc->removeFeature(aFeature);
+      }
+
+      // send events to update the sub-features by the solver
+      if (isUpdateFlushed)
+        Events_Loop::loop()->setFlushed(anUpdateEvent, true);
+    }
+  }
+}
+
index 69a26ea8f0f51e0b00a36934d5d67e7b56185c57..5ae07ac19686ea40bc994a5a99481f4af84d22e0 100644 (file)
@@ -51,6 +51,10 @@ class SketchPlugin_ConstraintMirror : public SketchPlugin_ConstraintBase
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
index 5b4f02c81ffbb150807309fbdd16af0d13fd394d..1070ce0ebfe39cefdeebcf9a07ed6f99cfb787c9 100644 (file)
@@ -277,3 +277,42 @@ void SketchPlugin_MultiRotation::rotateFeature(
   aTargetFeature->data()->blockSendAttributeUpdated(false);
 }
 
+
+void SketchPlugin_MultiRotation::attributeChanged(const std::string& theID)
+{
+  if (theID == ROTATION_LIST_ID()) {
+    AttributeSelectionListPtr aRotationObjectRefs = selectionList(ROTATION_LIST_ID());
+    if (aRotationObjectRefs->size() == 0) {
+      // Wait all objects being created, then send update events
+      static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+      bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
+      if (isUpdateFlushed)
+        Events_Loop::loop()->setFlushed(anUpdateEvent, false);
+
+      int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value();
+      // Clear list of objects
+      AttributeRefListPtr aRefListOfRotated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+          data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
+      std::list<ObjectPtr> aTargetList = aRefListOfRotated->list();
+      std::list<ObjectPtr>::iterator aTargetIter = aTargetList.begin();
+      while (aTargetIter != aTargetList.end()) {
+        aTargetIter++;
+        for (int i = 0; i < aNbCopies && aTargetIter != aTargetList.end(); i++, aTargetIter++) {
+          aRefListOfRotated->remove(*aTargetIter);
+          // remove the corresponding feature from the sketch
+          ResultConstructionPtr aRC =
+            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aTargetIter);
+          DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr();
+          FeaturePtr aFeature =  aDoc ? aDoc->feature(aRC) : FeaturePtr();
+          if (aFeature)
+            aDoc->removeFeature(aFeature);
+        }
+      }
+      integer(NUMBER_OF_COPIES_ID())->setValue(0);
+
+      // send events to update the sub-features by the solver
+      if (isUpdateFlushed)
+        Events_Loop::loop()->setFlushed(anUpdateEvent, true);
+    }
+  }
+}
index e743386f48b338cad8edc05638c4b277c3584604..245ffb980bc37de56e07cd4483de659950a771d1 100644 (file)
@@ -72,6 +72,10 @@ class SketchPlugin_MultiRotation : public SketchPlugin_ConstraintBase
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
 
index c0e4b994638af037f9cbf207a6accadd1f1933d8..b644a2f73170f6a6af9dffbc4c223a4685d3498d 100644 (file)
@@ -220,3 +220,41 @@ ObjectPtr SketchPlugin_MultiTranslation::copyFeature(ObjectPtr theObject)
   return ObjectPtr();
 }
 
+void SketchPlugin_MultiTranslation::attributeChanged(const std::string& theID)
+{
+  if (theID == TRANSLATION_LIST_ID()) {
+    AttributeSelectionListPtr aTranslationObjectRefs = selectionList(TRANSLATION_LIST_ID());
+    if (aTranslationObjectRefs->size() == 0) {
+      // Wait all objects being created, then send update events
+      static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+      bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
+      if (isUpdateFlushed)
+        Events_Loop::loop()->setFlushed(anUpdateEvent, false);
+
+      int aNbCopies = integer(NUMBER_OF_COPIES_ID())->value();
+      // Clear list of objects
+      AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(
+          data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
+      std::list<ObjectPtr> aTargetList = aRefListOfTranslated->list();
+      std::list<ObjectPtr>::iterator aTargetIter = aTargetList.begin();
+      while (aTargetIter != aTargetList.end()) {
+        aTargetIter++;
+        for (int i = 0; i < aNbCopies && aTargetIter != aTargetList.end(); i++, aTargetIter++) {
+          aRefListOfTranslated->remove(*aTargetIter);
+          // remove the corresponding feature from the sketch
+          ResultConstructionPtr aRC =
+            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aTargetIter);
+          DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr();
+          FeaturePtr aFeature =  aDoc ? aDoc->feature(aRC) : FeaturePtr();
+          if (aFeature)
+            aDoc->removeFeature(aFeature);
+        }
+      }
+      integer(NUMBER_OF_COPIES_ID())->setValue(0);
+
+      // send events to update the sub-features by the solver
+      if (isUpdateFlushed)
+        Events_Loop::loop()->setFlushed(anUpdateEvent, true);
+    }
+  }
+}
index f741d2ee722f3b8942762b54f6e2bc8ea6a540a3..5bebd18825b6a04e5a4d511c70cc74981417b33e 100644 (file)
@@ -72,6 +72,10 @@ class SketchPlugin_MultiTranslation : public SketchPlugin_ConstraintBase
   /// \brief Request for initialization of data model of the feature: adding all attributes
   SKETCHPLUGIN_EXPORT virtual void initAttributes();
 
+  /// Called on change of any argument-attribute of this object
+  /// \param theID identifier of changed attribute
+  SKETCHPLUGIN_EXPORT virtual void attributeChanged(const std::string& theID);
+
   /// Returns the AIS preview
   SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);