- std::shared_ptr<ModelAPI_Document> aThis = Model_Application::getApplication()->getDocument(
- myID);
- std::shared_ptr<Model_Data> aData(new Model_Data);
- aData->setLabel(theLab.FindChild(theTag));
- aData->setObject(theObj);
- theObj->setDoc(aThis);
- theObj->setData(aData);
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theObj);
- if (aFeature) {
- setUniqueName(aFeature); // must be before "initAttributes" because duplicate part uses name
- }
- theObj->initAttributes();
-}
-
-void Model_Document::synchronizeFeatures(
- const bool theMarkUpdated, const bool theUpdateReferences, const bool theFlush)
-{
- std::shared_ptr<ModelAPI_Document> aThis =
- Model_Application::getApplication()->getDocument(myID);
- // after all updates, sends a message that groups of features were created or updated
- Events_Loop* aLoop = Events_Loop::loop();
- static Events_ID aDispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- static Events_ID aCreateEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED);
- static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
- static Events_ID aRedispEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- static Events_ID aDeleteEvent = Events_Loop::eventByName(EVENT_OBJECT_DELETED);
- static Events_ID aToHideEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
- aLoop->activateFlushes(false);
-
- // update all objects by checking are they on labels or not
- std::set<FeaturePtr> aNewFeatures, aKeptFeatures;
- TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID());
- for (; aLabIter.More(); aLabIter.Next()) {
- TDF_Label aFeatureLabel = aLabIter.Value()->Label();
- FeaturePtr aFeature;
- if (!myObjs.IsBound(aFeatureLabel)) { // a new feature is inserted
- // create a feature
- aFeature = std::dynamic_pointer_cast<Model_Session>(ModelAPI_Session::get())->createFeature(
- TCollection_AsciiString(Handle(TDataStd_Comment)::DownCast(aLabIter.Value())->Get())
- .ToCString(), this);
- if (!aFeature) { // somethig is wrong, most probably, the opened document has invalid structure
- Events_Error::send("Invalid type of object in the document");
- aLabIter.Value()->Label().ForgetAllAttributes();
- continue;
- }
- // this must be before "setData" to redo the sketch line correctly
- myObjs.Bind(aFeatureLabel, aFeature);
- aNewFeatures.insert(aFeature);
- initData(aFeature, aFeatureLabel, TAG_FEATURE_ARGUMENTS);
-
- // event: model is updated
- ModelAPI_EventCreator::get()->sendUpdated(aFeature, aCreateEvent);
- } else { // nothing is changed, both iterators are incremented
- aFeature = myObjs.Find(aFeatureLabel);
- aKeptFeatures.insert(aFeature);
- if (theMarkUpdated) {
- ModelAPI_EventCreator::get()->sendUpdated(aFeature, anUpdateEvent);