X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelAPI%2FModelAPI_Feature.cpp;h=65cfa361ed3e8645cbf3812d45a90d83f5e31f68;hb=38afbd899a8645c83e17f2c24a17a2b7414911b4;hp=028f17385affbd04b928466274a9ee08cb5d904b;hpb=3ce4e2cad0e6802282a5a1d10c49c041e8a9f287;p=modules%2Fshaper.git diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 028f17385..65cfa361e 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,29 +7,36 @@ #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 + if (firstResult() == theResult) { // just updated static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent); return; } // created - while(!myResults.empty()) { // remove one by one with messages - boost::shared_ptr aRes = *(myResults.begin()); + while (!myResults.empty()) { // remove one by one with messages + std::shared_ptr aRes = *(myResults.begin()); myResults.erase(myResults.begin()); ModelAPI_EventCreator::get()->sendDeleted(aRes->document(), aRes->groupName()); } @@ -38,45 +47,98 @@ void ModelAPI_Feature::setResult(const boost::shared_ptr& theRe Events_Loop::loop()->flush(anEvent); } -void ModelAPI_Feature::setResult( - const boost::shared_ptr& theResult, const int theIndex) +void ModelAPI_Feature::setResult(const std::shared_ptr& theResult, + const int theIndex) { - std::list >::iterator aResIter = myResults.begin(); - for(int anIndex = 0; anIndex < theIndex; anIndex++) { + std::list >::iterator aResIter = myResults.begin(); + for (int anIndex = 0; anIndex < theIndex; anIndex++) { aResIter++; } - if (aResIter == myResults.end()) { // append + if (aResIter == myResults.end()) { // append myResults.push_back(theResult); 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 + } else { // update *aResIter = theResult; static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent); } } -boost::shared_ptr ModelAPI_Feature::documentToAdd() +void ModelAPI_Feature::removeResult(const std::shared_ptr& theResult) { - return ModelAPI_PluginManager::get()->currentDocument(); + std::list >::iterator aResIter = myResults.begin(); + for(; aResIter != myResults.end(); aResIter++) { + 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; + } + } } -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); + } +} + +std::shared_ptr ModelAPI_Feature::documentToAdd() +{ + return ModelAPI_Session::get()->activeDocument(); +} + +void ModelAPI_Feature::erase() { - while(!myResults.empty()) { // remove one by one with messages - boost::shared_ptr aRes = *(myResults.begin()); + 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 + 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);