X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelAPI%2FModelAPI_Feature.cpp;h=d9533e83e33d17c570bcc013ab65332f3be084dd;hb=d6c21ab46cf9e95cbad9d1c5ac7961f579b56cc5;hp=18ca3f55015333a596bf8856b7d944976fe6a73c;hpb=4efc05cb5fbd0d77175c25168e5809277c582922;p=modules%2Fshaper.git diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 18ca3f550..d9533e83e 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: ModelAPI_Feature.cpp // Created: 17 Jul 2014 // Author: Mikhail PONIKAROV @@ -5,20 +7,27 @@ #include "ModelAPI_Feature.h" #include #include +#include #include +#include #include -const std::list >& ModelAPI_Feature::results() +const std::list >& ModelAPI_Feature::results() { return myResults; } -boost::shared_ptr ModelAPI_Feature::firstResult() +std::shared_ptr ModelAPI_Feature::firstResult() +{ + return myResults.empty() ? std::shared_ptr() : *(myResults.begin()); +} + +std::shared_ptr ModelAPI_Feature::lastResult() { - return myResults.empty() ? boost::shared_ptr() : *(myResults.begin()); + return myResults.empty() ? std::shared_ptr() : *(myResults.rbegin()); } -void ModelAPI_Feature::setResult(const boost::shared_ptr& theResult) +void ModelAPI_Feature::setResult(const std::shared_ptr& theResult) { if (firstResult() == theResult) { // just updated static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); @@ -27,7 +36,7 @@ void ModelAPI_Feature::setResult(const boost::shared_ptr& theRe } // created while (!myResults.empty()) { // remove one by one with messages - boost::shared_ptr aRes = *(myResults.begin()); + std::shared_ptr aRes = *(myResults.begin()); myResults.erase(myResults.begin()); ModelAPI_EventCreator::get()->sendDeleted(aRes->document(), aRes->groupName()); } @@ -38,10 +47,10 @@ void ModelAPI_Feature::setResult(const boost::shared_ptr& theRe Events_Loop::loop()->flush(anEvent); } -void ModelAPI_Feature::setResult(const boost::shared_ptr& theResult, +void ModelAPI_Feature::setResult(const std::shared_ptr& theResult, const int theIndex) { - std::list >::iterator aResIter = myResults.begin(); + std::list >::iterator aResIter = myResults.begin(); for (int anIndex = 0; anIndex < theIndex; anIndex++) { aResIter++; } @@ -50,6 +59,7 @@ void ModelAPI_Feature::setResult(const boost::shared_ptr& theRe static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent); // Create event for first Feature, send it to make "created" earlier than "updated" + // VSV: Commenting out of this statement causes problems with circle operation for example Events_Loop::loop()->flush(anEvent); } else { // update *aResIter = theResult; @@ -58,35 +68,102 @@ void ModelAPI_Feature::setResult(const boost::shared_ptr& theRe } } -void ModelAPI_Feature::removeResult(const boost::shared_ptr& theResult) +void ModelAPI_Feature::removeResult(const std::shared_ptr& theResult) { - std::list >::iterator aResIter = myResults.begin(); + std::list >::iterator aResIter = myResults.begin(); for(; aResIter != myResults.end(); aResIter++) { - if (*aResIter == theResult) { + ResultPtr aRes = *aResIter; + if (aRes == theResult) { + std::string aGroup = aRes->groupName(); + aRes->data()->erase(); myResults.erase(aResIter); + + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED); + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + ModelAPI_EventCreator::get()->sendDeleted(document(), aGroup); + aECreator->sendUpdated(aRes, EVENT_DISP); + break; } } } -boost::shared_ptr ModelAPI_Feature::documentToAdd() +void ModelAPI_Feature::removeResults(const int theSinceIndex) { - return ModelAPI_PluginManager::get()->currentDocument(); + if (theSinceIndex == 0) { + eraseResults(); + return; + } + + std::list >::iterator aResIter = myResults.begin(); + for(int anIndex = 0; anIndex < theSinceIndex && aResIter != myResults.end(); anIndex++) + aResIter++; + std::list >::iterator aNextIter = aResIter; + for(; aNextIter != myResults.end(); aNextIter++) { + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED); + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + ModelAPI_EventCreator::get()->sendDeleted(document(), (*aNextIter)->groupName()); + aECreator->sendUpdated(*aNextIter, EVENT_DISP); + } + myResults.erase(aResIter, myResults.end()); } -ModelAPI_Feature::~ModelAPI_Feature() +void ModelAPI_Feature::eraseResults() { + if (!myResults.empty()) { + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + + std::list >::iterator aResIter = myResults.begin(); + for(; aResIter != myResults.end(); aResIter++) { + (*aResIter)->data()->erase(); + ModelAPI_EventCreator::get()->sendDeleted(document(), (*aResIter)->groupName()); + aECreator->sendUpdated(*aResIter, EVENT_DISP); + } + myResults.clear(); + // flush it to avoid left presentations after input of invalid arguments (radius=0) + static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED); + Events_Loop::loop()->flush(anEvent); + Events_Loop::loop()->flush(EVENT_DISP); + } +} + +const std::string& ModelAPI_Feature::documentToAdd() +{ + // empty to use the current document + static const std::string anEmpty; + return anEmpty; +} + +void ModelAPI_Feature::erase() +{ + static Events_Loop* aLoop = Events_Loop::loop(); + static Events_ID EVENT_DISP = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY); + static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get(); + while (!myResults.empty()) { // remove one by one with messages - boost::shared_ptr aRes = *(myResults.begin()); + std::shared_ptr aRes = *(myResults.begin()); myResults.erase(myResults.begin()); - ModelAPI_EventCreator::get()->sendDeleted(aRes->document(), aRes->groupName()); + aECreator->sendDeleted(aRes->document(), aRes->groupName()); + aECreator->sendUpdated(aRes, EVENT_DISP); } + ModelAPI_Object::erase(); +} + +ModelAPI_Feature::~ModelAPI_Feature() +{ + erase(); } FeaturePtr ModelAPI_Feature::feature(ObjectPtr theObject) { - FeaturePtr aFeature = boost::dynamic_pointer_cast(theObject); + FeaturePtr aFeature = std::dynamic_pointer_cast(theObject); if (!aFeature) { - ResultPtr aResult = boost::dynamic_pointer_cast(theObject); + ResultPtr aResult = std::dynamic_pointer_cast(theObject); if (aResult) { DocumentPtr aDoc = aResult->document(); return aDoc->feature(aResult);