- 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<ModelAPI_Result> aRes = *(myResults.begin());
- myResults.erase(myResults.begin());
- ModelAPI_EventCreator::get()->sendDeleted(aRes->document(), aRes->groupName());
+ return myResults.empty() ? std::shared_ptr<ModelAPI_Result>() : *(myResults.rbegin());
+}
+
+void ModelAPI_Feature::setResult(const std::shared_ptr<ModelAPI_Result>& theResult)
+{
+ static Events_ID EVENT_UPD = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
+ static const ModelAPI_EventCreator* aECreator = ModelAPI_EventCreator::get();
+
+ if (firstResult() == theResult) {
+ // nothing to change
+ } else if (!myResults.empty()) { // all except first become disabled
+ std::list<std::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
+ *aResIter = theResult;
+ aECreator->sendUpdated(theResult, EVENT_UPD);
+ for(aResIter++; aResIter != myResults.end(); aResIter++) {
+ (*aResIter)->setDisabled((*aResIter), true);
+ }
+ } else {
+ myResults.push_back(theResult);