X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_MultiTranslation.cpp;h=1c4086acd55bf0ed83b5386db663f93d9f16b1a0;hb=b5893b0a30fac08134c24de4565cb513a43affa6;hp=df58c765db0a0f62a52f68ed0a069d5d60f06766;hpb=86469f18d7a0d509914e1fc9ffac53a2393c7776;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp index df58c765d..1c4086acd 100755 --- a/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp +++ b/src/SketchPlugin/SketchPlugin_MultiTranslation.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -38,8 +39,10 @@ void SketchPlugin_MultiTranslation::initAttributes() data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefList::typeId()); data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefList::typeId()); data()->addAttribute(TRANSLATION_LIST_ID(), ModelAPI_AttributeRefList::typeId()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SketchPlugin_Constraint::ENTITY_A()); - ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SketchPlugin_Constraint::ENTITY_B()); + ModelAPI_Session::get()->validators()-> + registerNotObligatory(getKind(), SketchPlugin_Constraint::ENTITY_A()); + ModelAPI_Session::get()->validators()-> + registerNotObligatory(getKind(), SketchPlugin_Constraint::ENTITY_B()); } void SketchPlugin_MultiTranslation::execute() @@ -68,7 +71,8 @@ void SketchPlugin_MultiTranslation::execute() if (!aStart || !aEnd) return; - std::shared_ptr aShiftVec(new GeomAPI_XY(aEnd->x() - aStart->x(), aEnd->y() - aStart->y())); + std::shared_ptr + aShiftVec(new GeomAPI_XY(aEnd->x() - aStart->x(), aEnd->y() - aStart->y())); // Wait all objects being created, then send update events static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); @@ -104,11 +108,13 @@ void SketchPlugin_MultiTranslation::execute() std::list::iterator anInitIter = anInitialList.begin(); std::list::iterator aTargetIter = aTargetList.begin(); std::vector::iterator aUsedIter = isUsed.begin(); + std::set aFeaturesToBeRemoved; for (; aUsedIter != isUsed.end(); aUsedIter++) { if (!(*aUsedIter)) { aRefListOfShapes->remove(*anInitIter); aRefListOfTranslated->remove(*aTargetIter++); - for (int i = 0; i < aCurrentNbCopies && aTargetIter != aTargetList.end(); i++, aTargetIter++) { + for (int i = 0; i < aCurrentNbCopies && aTargetIter != aTargetList.end(); + i++, aTargetIter++) { aRefListOfTranslated->remove(*aTargetIter); // remove the corresponding feature from the sketch ResultConstructionPtr aRC = @@ -116,7 +122,7 @@ void SketchPlugin_MultiTranslation::execute() DocumentPtr aDoc = aRC ? aRC->document() : DocumentPtr(); FeaturePtr aFeature = aDoc ? aDoc->feature(aRC) : FeaturePtr(); if (aFeature) - aDoc->removeFeature(aFeature); + aFeaturesToBeRemoved.insert(aFeature); } } else { for (int i = 0; i <= aNbCopies && aTargetIter != aTargetList.end(); i++) @@ -125,6 +131,7 @@ void SketchPlugin_MultiTranslation::execute() if (anInitIter != anInitialList.end()) anInitIter++; } + ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToBeRemoved); // change number of copies if (aCurrentNbCopies != 0 && aNbCopies != aCurrentNbCopies) { bool isAdd = aNbCopies > aCurrentNbCopies; @@ -191,33 +198,39 @@ 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( + data()->attribute(SketchPlugin_Constraint::ENTITY_A())); AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast( 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 aTargetList = aRefListOfTranslated->list(); - for(std::list::const_iterator aTargetIt = aTargetList.cbegin(); aTargetIt != aTargetList.cend(); aTargetIt++) { - if((*aTargetIt).get()) { - ResultPtr aRes = std::dynamic_pointer_cast(*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(anObject); if(aRes.get()) { FeaturePtr aFeature = aRes->document()->feature(aRes); if(aFeature.get()) { - AttributeBooleanPtr aBooleanAttr = aFeature->boolean(SketchPlugin_SketchEntity::COPY_ID()); + 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); } @@ -237,7 +250,8 @@ ObjectPtr SketchPlugin_MultiTranslation::copyFeature(ObjectPtr theObject) if (!aFeature || !aResult) return ObjectPtr(); - FeaturePtr aNewFeature = SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeature, sketch(), true); + FeaturePtr aNewFeature = + SketchPlugin_Sketch::addUniqueNamedCopiedFeature(aFeature, sketch(), true); aNewFeature->execute(); static Events_ID aRedisplayEvent = Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY); @@ -266,29 +280,23 @@ void SketchPlugin_MultiTranslation::attributeChanged(const std::string& theID) int aNbCopies = integer(NUMBER_OF_OBJECTS_ID())->value()-1; if (aNbCopies <= 0) return; + + DocumentPtr aDoc = document(); // Clear list of objects - AttributeRefListPtr aRefListOfTranslated = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + AttributeRefListPtr aRefListOfTranslated = reflist(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(); + FeaturePtr aFeature = ModelAPI_Feature::feature(*aTargetIter); if (aFeature) aDoc->removeFeature(aFeature); } } aRefListOfTranslated->clear(); - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_A()))->clear(); - std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::ENTITY_B()))->clear(); + reflist(SketchPlugin_Constraint::ENTITY_A())->clear(); } } }