X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelHighAPI%2FModelHighAPI_Dumper.cpp;h=20e8ff20f36c221f489705c00c7b8ca20b1eb388;hb=6b615b773dd6e6901cd246ecb55003a9941e2365;hp=90b6655b7a03d76d15fc6873ca82e47b6ee17bfd;hpb=c5c451ec3d7b112e169d0e82dd5b7e8f8f05e16a;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 90b6655b7..20e8ff20f 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -96,6 +96,9 @@ void ModelHighAPI_Dumper::clear(bool bufferOnly) myFeatureCount.clear(); while (!myEntitiesStack.empty()) myEntitiesStack.pop(); + + myPostponed.clear(); + myDumpPostponedInProgress = false; } } @@ -139,7 +142,6 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, aName = aFolder->data()->name(); aKind = ModelAPI_Folder::ID(); isSaveNotDumped = false; - myNotDumpedFolders.insert(aFolder); } } @@ -212,7 +214,8 @@ void ModelHighAPI_Dumper::saveResultNames(const FeaturePtr& theFeature) const std::list& aResults = theFeature->results(); std::list::const_iterator aResIt = aResults.begin(); for (int i = 0; aResIt != aResults.end(); ++aResIt, ++i) { - std::string aDefaultName = ModelAPI_Tools::getDefaultName(*aResIt, i); + std::pair aName = ModelAPI_Tools::getDefaultName(*aResIt, i); + std::string aDefaultName = aName.first; std::string aResName = (*aResIt)->data()->name(); bool isUserDefined = !(isFeatureDefaultName && aDefaultName == aResName); @@ -227,7 +230,8 @@ void ModelHighAPI_Dumper::saveResultNames(const FeaturePtr& theFeature) for (int j = 0; j < aNbSubs; ++j) { ResultPtr aSub = aCompSolid->subResult(j); std::string aSubName = aSub->data()->name(); - aDefaultName = ModelAPI_Tools::getDefaultName(aSub, j); + aName = ModelAPI_Tools::getDefaultName(aSub, j); + aDefaultName = aName.first; bool isUserDefinedSubName = isUserDefined || aDefaultName != aSubName; myNames[aSub] = EntityName(aSubName, @@ -265,7 +269,7 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr& theD CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast(*anObjIt); if (aCompFeat) // iteratively process composite features isOk = process(aCompFeat) && isOk; - else if (!isDumped(*anObjIt)) { + else if (!isDumped(EntityPtr(*anObjIt))) { // dump folder FolderPtr aFolder = std::dynamic_pointer_cast(*anObjIt); if (aFolder) @@ -277,6 +281,8 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr& theD } } } + // dump folders if any + dumpPostponed(true); return isOk; } @@ -286,7 +292,7 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptrnumberOfSubs(); for (int anIndex = 0; anIndex < aNbSubs; ++anIndex) { FeaturePtr aFeature = theComposite->subFeature(anIndex); - if (isDumped(aFeature)) + if (isDumped(EntityPtr(aFeature))) continue; isSubDumped = true; @@ -361,9 +369,48 @@ bool ModelHighAPI_Dumper::processSubs( // dump "setName" for composite feature if (isDumpSetName) dumpEntitySetName(); + // dump folders if any + dumpPostponed(true); return isOk; } +void ModelHighAPI_Dumper::postpone(const EntityPtr& theEntity) +{ + // keep the name + name(theEntity, false); + myPostponed.push_back(theEntity); +} + +void ModelHighAPI_Dumper::dumpPostponed(bool theDumpFolders) +{ + if (myDumpPostponedInProgress) + return; + + myDumpPostponedInProgress = true; + // make a copy of postponed entities, because the list will be updated + // if some features are not able to be dumped + std::list aPostponedCopy = myPostponed; + myPostponed.clear(); + + // iterate over postponed entities and try to dump them + std::list::const_iterator anIt = aPostponedCopy.begin(); + for (; anIt != aPostponedCopy.end(); ++anIt) { + FolderPtr aFolder = std::dynamic_pointer_cast(*anIt); + if (aFolder) { + if (theDumpFolders) + dumpFolder(aFolder); + else + myPostponed.push_back(*anIt); + } + else { + FeaturePtr aFeature = std::dynamic_pointer_cast(*anIt); + if (aFeature) + dumpFeature(aFeature); + } + } + myDumpPostponedInProgress = false; +} + void ModelHighAPI_Dumper::dumpSubFeatureNameAndColor(const std::string theSubFeatureGet, const FeaturePtr& theSubFeature) { @@ -498,7 +545,30 @@ bool ModelHighAPI_Dumper::isDumped(const EntityPtr& theEntity) const { EntityNameMap::const_iterator aFound = myNames.find(theEntity); FeaturePtr aFeature = std::dynamic_pointer_cast(theEntity); - return aFound != myNames.end() || myFeaturesToSkip.find(aFeature) != myFeaturesToSkip.end(); + return (aFound != myNames.end() && aFound->second.myIsDumped) || + myFeaturesToSkip.find(aFeature) != myFeaturesToSkip.end(); +} + +bool ModelHighAPI_Dumper::isDumped(const AttributeRefAttrPtr& theRefAttr) const +{ + FeaturePtr aFeature; + if (theRefAttr->isObject()) + aFeature = ModelAPI_Feature::feature(theRefAttr->object()); + else + aFeature = ModelAPI_Feature::feature(theRefAttr->attr()->owner()); + return aFeature && isDumped(EntityPtr(aFeature)); +} + +bool ModelHighAPI_Dumper::isDumped(const AttributeRefListPtr& theRefList) const +{ + std::list aRefs = theRefList->list(); + std::list::iterator anIt = aRefs.begin(); + for (; anIt != aRefs.end(); ++anIt) { + FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt); + if (aFeature && !isDumped(EntityPtr(aFeature))) + return false; + } + return true; } bool ModelHighAPI_Dumper::isDefaultColor(const ResultPtr& theResult) const @@ -688,7 +758,6 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FolderPtr& theFolder) { myDumpBuffer << name(theFolder); - myNotDumpedFolders.erase(theFolder); return *this; } @@ -978,7 +1047,7 @@ ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper, isCopy = aCopyAttr.get() && aCopyAttr->value(); } } - } while (isCopy); + } while (isCopy && !theDumper.myEntitiesStack.empty()); } // store all not-dumped entities first @@ -995,18 +1064,19 @@ ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper, else { FeaturePtr aFeature = std::dynamic_pointer_cast(*anIt); theDumper.dumpFeature(aFeature, true); - // dump all referred features for the "Copy" + // dump the Projection feature which produces this "Copy" entity AttributeBooleanPtr aCopyAttr = aFeature->boolean("Copy"); if (aCopyAttr.get() && aCopyAttr->value()) { const std::set& aRefs = aFeature->data()->refsToMe(); std::set::iterator aRefIt = aRefs.begin(); for (; aRefIt != aRefs.end(); ++aRefIt) - { - FeaturePtr anOwner = ModelAPI_Feature::feature((*aRefIt)->owner()); - if (anOwner && !theDumper.isDumped(anOwner)) - theDumper.dumpFeature(anOwner, true); - } + if ((*aRefIt)->id() == "ProjectedFeature") + { // process projection only + FeaturePtr anOwner = ModelAPI_Feature::feature((*aRefIt)->owner()); + if (anOwner && !theDumper.isDumped(EntityPtr(anOwner))) + theDumper.dumpFeature(anOwner, true); + } } } } @@ -1018,12 +1088,8 @@ ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper, // then store currently dumped string theDumper.myFullDump << aBufCopy; - // now, store all not dumped folders - std::set::const_iterator aFolderIt = theDumper.myNotDumpedFolders.begin(); - while (aFolderIt != theDumper.myNotDumpedFolders.end()) { - FolderPtr aFolder = *aFolderIt++; - theDumper.dumpFolder(aFolder); - } + // now, store all postponed features + theDumper.dumpPostponed(); return theDumper; }