From: azv Date: Thu, 2 Jul 2015 13:34:48 +0000 (+0300) Subject: Remove copied objects in Mirror, Translation and Rotation, when the empty space is... X-Git-Tag: V_1.3.0~124 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=d7a4accddf64dfbe704738e6b7708164643aeba7;p=modules%2Fshaper.git Remove copied objects in Mirror, Translation and Rotation, when the empty space is selected --- diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp index 03a3a9005..dfc90aa49 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.cpp @@ -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( + data()->attribute(SketchPlugin_Constraint::ENTITY_C())); + std::list aTargetList = aRefListOfMirrored->list(); + std::list::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(*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); + } + } +} + diff --git a/src/SketchPlugin/SketchPlugin_ConstraintMirror.h b/src/SketchPlugin/SketchPlugin_ConstraintMirror.h index 69a26ea8f..5ae07ac19 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintMirror.h +++ b/src/SketchPlugin/SketchPlugin_ConstraintMirror.h @@ -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); diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp index 5b4f02c81..1070ce0eb 100644 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.cpp @@ -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( + data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + std::list aTargetList = aRefListOfRotated->list(); + std::list::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(*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); + } + } +} diff --git a/src/SketchPlugin/SketchPlugin_MultiRotation.h b/src/SketchPlugin/SketchPlugin_MultiRotation.h index e743386f4..245ffb980 100644 --- a/src/SketchPlugin/SketchPlugin_MultiRotation.h +++ b/src/SketchPlugin/SketchPlugin_MultiRotation.h @@ -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); diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index c0e4b9946..b644a2f73 100644 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -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( + data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + std::list aTargetList = aRefListOfTranslated->list(); + std::list::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(*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); + } + } +} diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.h b/src/SketchPlugin/SketchPlugin_MultiTranslation.h index f741d2ee7..5bebd1882 100644 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.h +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.h @@ -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);