1 // File: ModelAPI_Feature.cpp
2 // Created: 17 Jul 2014
3 // Author: Mikhail PONIKAROV
5 #include "ModelAPI_Feature.h"
6 #include <ModelAPI_Events.h>
7 #include <ModelAPI_Result.h>
8 #include <ModelAPI_Document.h>
9 #include <Events_Loop.h>
11 const std::list<boost::shared_ptr<ModelAPI_Result> >& ModelAPI_Feature::results()
16 boost::shared_ptr<ModelAPI_Result> ModelAPI_Feature::firstResult()
18 return myResults.empty() ? boost::shared_ptr<ModelAPI_Result>() : *(myResults.begin());
21 void ModelAPI_Feature::setResult(const boost::shared_ptr<ModelAPI_Result>& theResult)
23 if (firstResult() == theResult) { // just updated
24 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
25 ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
29 while (!myResults.empty()) { // remove one by one with messages
30 boost::shared_ptr<ModelAPI_Result> aRes = *(myResults.begin());
31 myResults.erase(myResults.begin());
32 ModelAPI_EventCreator::get()->sendDeleted(aRes->document(), aRes->groupName());
34 myResults.push_back(theResult);
35 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
36 ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
37 // Create event for first Feature
38 Events_Loop::loop()->flush(anEvent);
41 void ModelAPI_Feature::setResult(const boost::shared_ptr<ModelAPI_Result>& theResult,
44 std::list<boost::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
45 for (int anIndex = 0; anIndex < theIndex; anIndex++) {
48 if (aResIter == myResults.end()) { // append
49 myResults.push_back(theResult);
50 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
51 ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
52 // Create event for first Feature, send it to make "created" earlier than "updated"
53 //Events_Loop::loop()->flush(anEvent);
55 *aResIter = theResult;
56 static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
57 ModelAPI_EventCreator::get()->sendUpdated(theResult, anEvent);
61 void ModelAPI_Feature::removeResult(const boost::shared_ptr<ModelAPI_Result>& theResult)
63 std::list<boost::shared_ptr<ModelAPI_Result> >::iterator aResIter = myResults.begin();
64 for(; aResIter != myResults.end(); aResIter++) {
65 if (*aResIter == theResult) {
66 myResults.erase(aResIter);
71 boost::shared_ptr<ModelAPI_Document> ModelAPI_Feature::documentToAdd()
73 return ModelAPI_PluginManager::get()->currentDocument();
76 ModelAPI_Feature::~ModelAPI_Feature()
78 while (!myResults.empty()) { // remove one by one with messages
79 boost::shared_ptr<ModelAPI_Result> aRes = *(myResults.begin());
80 myResults.erase(myResults.begin());
81 ModelAPI_EventCreator::get()->sendDeleted(aRes->document(), aRes->groupName());
85 FeaturePtr ModelAPI_Feature::feature(ObjectPtr theObject)
87 FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(theObject);
89 ResultPtr aResult = boost::dynamic_pointer_cast<ModelAPI_Result>(theObject);
91 DocumentPtr aDoc = aResult->document();
92 return aDoc->feature(aResult);