From: mpv Date: Wed, 3 Sep 2014 13:02:03 +0000 (+0400) Subject: Make bodies list updated on undo/redo/open/abort X-Git-Tag: V_0.4.4~89^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=4efc05cb5fbd0d77175c25168e5809277c582922;p=modules%2Fshaper.git Make bodies list updated on undo/redo/open/abort --- diff --git a/src/Model/Model_Document.cpp b/src/Model/Model_Document.cpp index dfcb4b659..5e3088a44 100644 --- a/src/Model/Model_Document.cpp +++ b/src/Model/Model_Document.cpp @@ -649,8 +649,11 @@ void Model_Document::initData(ObjectPtr theObj, TDF_Label theLab, const int theT void Model_Document::synchronizeFeatures(const bool theMarkUpdated) { - boost::shared_ptr aThis = Model_Application::getApplication()->getDocument( - myID); + boost::shared_ptr aThis = + Model_Application::getApplication()->getDocument(myID); + // after all updates, sends a message that groups of features were created or updated + boost::static_pointer_cast(Model_PluginManager::get()) + ->setCheckTransactions(false); // update all objects by checking are they of labels or not std::set aNewFeatures, aKeptFeatures; TDF_ChildIDIterator aLabIter(featuresLabel(), TDataStd_Comment::GetID()); @@ -674,13 +677,17 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) // event: model is updated static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_CREATED); ModelAPI_EventCreator::get()->sendUpdated(aNewObj, anEvent); - // feature for this label is added, so go to the next label + + // update results of the appeared feature + updateResults(aNewObj); } else { // nothing is changed, both iterators are incremented - aKeptFeatures.insert(myObjs.Find(aFeatureLabel)); + FeaturePtr aFeature = myObjs.Find(aFeatureLabel); + aKeptFeatures.insert(aFeature); if (theMarkUpdated) { static Events_ID anEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED); - ModelAPI_EventCreator::get()->sendUpdated(myObjs.Find(aFeatureLabel), anEvent); + ModelAPI_EventCreator::get()->sendUpdated(aFeature, anEvent); } + updateResults(aFeature); } } // execute new features to restore results: after features creation to make all references valid @@ -717,32 +724,33 @@ void Model_Document::synchronizeFeatures(const bool theMarkUpdated) aFIter.Next(); } - // after all updates, sends a message that groups of features were created or updated - boost::static_pointer_cast(Model_PluginManager::get())->setCheckTransactions( - false); myExecuteFeatures = false; Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_CREATED)); if (theMarkUpdated) Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED)); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY)); - boost::static_pointer_cast(Model_PluginManager::get())->setCheckTransactions( - true); + boost::static_pointer_cast(Model_PluginManager::get()) + ->setCheckTransactions(true); myExecuteFeatures = true; } +TDF_Label Model_Document::resultLabel( + const boost::shared_ptr& theFeatureData, const int theResultIndex) +{ + const boost::shared_ptr& aData = + boost::dynamic_pointer_cast(theFeatureData); + return aData->label().Father().FindChild(TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1); +} + void Model_Document::storeResult(boost::shared_ptr theFeatureData, boost::shared_ptr theResult, const int theResultIndex) { - boost::shared_ptr aThis = Model_Application::getApplication()->getDocument( - myID); + boost::shared_ptr aThis = + Model_Application::getApplication()->getDocument(myID); theResult->setDoc(aThis); - initData( - theResult, - boost::dynamic_pointer_cast(theFeatureData)->label().Father().FindChild( - TAG_FEATURE_RESULTS).FindChild(theResultIndex + 1), - TAG_FEATURE_ARGUMENTS); + initData(theResult, resultLabel(theFeatureData, theResultIndex), TAG_FEATURE_ARGUMENTS); if (theResult->data()->name().empty()) { // if was not initialized, generate event and set a name theResult->data()->setName(theFeatureData->name()); } @@ -751,9 +759,7 @@ void Model_Document::storeResult(boost::shared_ptr theFeatureData boost::shared_ptr Model_Document::createConstruction( const boost::shared_ptr& theFeatureData, const int theIndex) { - ObjectPtr anOldObject = object( - boost::dynamic_pointer_cast(theFeatureData)->label().Father().FindChild( - TAG_FEATURE_RESULTS).FindChild(theIndex + 1)); + ObjectPtr anOldObject = object(resultLabel(theFeatureData, theIndex)); boost::shared_ptr aResult; if (anOldObject) { aResult = boost::dynamic_pointer_cast(anOldObject); @@ -768,9 +774,7 @@ boost::shared_ptr Model_Document::createConstructio boost::shared_ptr Model_Document::createBody( const boost::shared_ptr& theFeatureData, const int theIndex) { - ObjectPtr anOldObject = object( - boost::dynamic_pointer_cast(theFeatureData)->label().Father().FindChild( - TAG_FEATURE_RESULTS).FindChild(theIndex + 1)); + ObjectPtr anOldObject = object(resultLabel(theFeatureData, theIndex)); boost::shared_ptr aResult; if (anOldObject) { aResult = boost::dynamic_pointer_cast(anOldObject); @@ -785,9 +789,7 @@ boost::shared_ptr Model_Document::createBody( boost::shared_ptr Model_Document::createPart( const boost::shared_ptr& theFeatureData, const int theIndex) { - ObjectPtr anOldObject = object( - boost::dynamic_pointer_cast(theFeatureData)->label().Father().FindChild( - TAG_FEATURE_RESULTS).FindChild(theIndex + 1)); + ObjectPtr anOldObject = object(resultLabel(theFeatureData, theIndex)); boost::shared_ptr aResult; if (anOldObject) { aResult = boost::dynamic_pointer_cast(anOldObject); @@ -810,6 +812,40 @@ boost::shared_ptr Model_Document::feature( return FeaturePtr(); } +void Model_Document::updateResults(FeaturePtr theFeature) +{ + // for not persistent is will be done by parametric updater automatically + if (!theFeature->isPersistentResult()) return; + // check the existing results and remove them if there is nothing on the label + std::list::const_iterator aResIter = theFeature->results().cbegin(); + while(aResIter != theFeature->results().cend()) { + ResultBodyPtr aBody = boost::dynamic_pointer_cast(*aResIter); + if (aBody) { + if (!aBody->data()->isValid()) { + // found a disappeared result => remove it + theFeature->removeResult(aBody); + // start iterate from beginning because iterator is corrupted by removing + aResIter = theFeature->results().cbegin(); + continue; + } + } + aResIter++; + } + // check that results are presented on all labels + int aResSize = theFeature->results().size(); + TDF_ChildIterator aLabIter(resultLabel(theFeature->data(), 0).Father()); + for(; aLabIter.More(); aLabIter.Next()) { + // here must be at least Name + int aResIndex = aLabIter.Value().Tag() - 1; + if (aLabIter.Value().FindChild(TAG_FEATURE_ARGUMENTS).HasAttribute() && + aResSize <= aResIndex) + { + ResultBodyPtr aNewBody = createBody(theFeature->data(), aResIndex); + theFeature->setResult(aNewBody, aResIndex); + } + } +} + Standard_Integer HashCode(const TDF_Label& theLab, const Standard_Integer theUpper) { return TDF_LabelMapHasher::HashCode(theLab, theUpper); diff --git a/src/Model/Model_Document.h b/src/Model/Model_Document.h index e7b92a945..21f535939 100644 --- a/src/Model/Model_Document.h +++ b/src/Model/Model_Document.h @@ -152,6 +152,13 @@ class Model_Document : public ModelAPI_Document boost::shared_ptr theResult, const int theResultIndex = 0); + //! returns the label of result by index; creates this label if it was not created before + TDF_Label Model_Document::resultLabel( + const boost::shared_ptr& theFeatureData, const int theResultIndex); + + //! Updates the results list of the feature basing on the current data tree + void updateResults(FeaturePtr theFeature); + friend class Model_Application; friend class Model_PluginManager; friend class DFBrowser; diff --git a/src/ModelAPI/ModelAPI_Feature.cpp b/src/ModelAPI/ModelAPI_Feature.cpp index 07079fe14..18ca3f550 100644 --- a/src/ModelAPI/ModelAPI_Feature.cpp +++ b/src/ModelAPI/ModelAPI_Feature.cpp @@ -58,6 +58,16 @@ void ModelAPI_Feature::setResult(const boost::shared_ptr& theRe } } +void ModelAPI_Feature::removeResult(const boost::shared_ptr& theResult) +{ + std::list >::iterator aResIter = myResults.begin(); + for(; aResIter != myResults.end(); aResIter++) { + if (*aResIter == theResult) { + myResults.erase(aResIter); + } + } +} + boost::shared_ptr ModelAPI_Feature::documentToAdd() { return ModelAPI_PluginManager::get()->currentDocument(); diff --git a/src/ModelAPI/ModelAPI_Feature.h b/src/ModelAPI/ModelAPI_Feature.h index 910807423..fed0ea648 100644 --- a/src/ModelAPI/ModelAPI_Feature.h +++ b/src/ModelAPI/ModelAPI_Feature.h @@ -57,6 +57,8 @@ class ModelAPI_Feature : public ModelAPI_Object /// sets the result by index (zero based), results before this must be set before MODELAPI_EXPORT void setResult(const boost::shared_ptr& theResult, const int theIndex); + /// removes the result from the feature + MODELAPI_EXPORT void removeResult(const boost::shared_ptr& theResult); /// Returns true if result is persistent (stored in document) and on undo-redo, save-open /// it is not needed to recompute it.