X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FModelHighAPI%2FModelHighAPI_Dumper.cpp;h=20e8ff20f36c221f489705c00c7b8ca20b1eb388;hb=6b615b773dd6e6901cd246ecb55003a9941e2365;hp=84f4eb55653604cf50e7140e754ac4151dbb8789;hpb=8900db7d46dea7a043591601b2dd7f64d8f60e8b;p=modules%2Fshaper.git diff --git a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp index 84f4eb556..20e8ff20f 100644 --- a/src/ModelHighAPI/ModelHighAPI_Dumper.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Dumper.cpp @@ -46,6 +46,7 @@ #include #include #include +#include #include #include #include @@ -95,6 +96,9 @@ void ModelHighAPI_Dumper::clear(bool bufferOnly) myFeatureCount.clear(); while (!myEntitiesStack.empty()) myEntitiesStack.pop(); + + myPostponed.clear(); + myDumpPostponedInProgress = false; } } @@ -124,14 +128,26 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, return aFound->second.myCurrentName; // entity is not found, store it - std::string aName; + std::string aName, aKind; bool isDefaultName = false; + bool isSaveNotDumped = theSaveNotDumped; std::ostringstream aDefaultName; FeaturePtr aFeature = std::dynamic_pointer_cast(theEntity); if (aFeature) { aName = aFeature->name(); - const std::string& aKind = aFeature->getKind(); - DocumentPtr aDoc = aFeature->document(); + aKind = aFeature->getKind(); + } else { + FolderPtr aFolder = std::dynamic_pointer_cast(theEntity); + if (aFolder) { + aName = aFolder->data()->name(); + aKind = ModelAPI_Folder::ID(); + isSaveNotDumped = false; + } + } + + ObjectPtr anObject = std::dynamic_pointer_cast(theEntity); + if (anObject) { + DocumentPtr aDoc = anObject->document(); int& aNbFeatures = myFeatureCount[aDoc][aKind]; aNbFeatures += 1; @@ -164,7 +180,7 @@ const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity, } myNames[theEntity] = EntityName(aDefaultName.str(), aName, isDefaultName); - if (theSaveNotDumped) + if (isSaveNotDumped) myNotDumpedEntities.insert(theEntity); // store names of results @@ -198,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); @@ -213,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, @@ -238,19 +256,33 @@ bool ModelHighAPI_Dumper::process(const std::shared_ptr& theD bool ModelHighAPI_Dumper::process(const std::shared_ptr& theDoc) { bool isOk = true; - std::list aFeatures = theDoc->allFeatures(); - std::list::const_iterator aFeatIt = aFeatures.begin(); + std::list anObjects = theDoc->allObjects(); + std::list::const_iterator anObjIt = anObjects.begin(); // firstly, dump all parameters - for (; aFeatIt != aFeatures.end(); ++ aFeatIt) - dumpParameter(*aFeatIt); + for (; anObjIt != anObjects.end(); ++ anObjIt) { + FeaturePtr aFeature = std::dynamic_pointer_cast(*anObjIt); + if (aFeature) + dumpParameter(aFeature); + } // dump all other features - for (aFeatIt = aFeatures.begin(); aFeatIt != aFeatures.end(); ++aFeatIt) { - CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast(*aFeatIt); + for (anObjIt = anObjects.begin(); anObjIt != anObjects.end(); ++anObjIt) { + CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast(*anObjIt); if (aCompFeat) // iteratively process composite features isOk = process(aCompFeat) && isOk; - else if (!isDumped(*aFeatIt)) // dump common feature - dumpFeature(*aFeatIt); + else if (!isDumped(EntityPtr(*anObjIt))) { + // dump folder + FolderPtr aFolder = std::dynamic_pointer_cast(*anObjIt); + if (aFolder) + dumpFolder(aFolder); + else { + FeaturePtr aFeature = std::dynamic_pointer_cast(*anObjIt); + if (aFeature) // dump common feature + dumpFeature(aFeature); + } + } } + // dump folders if any + dumpPostponed(true); return isOk; } @@ -260,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; @@ -335,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) { @@ -472,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 @@ -659,6 +755,12 @@ ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<( return *this; } +ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FolderPtr& theFolder) +{ + myDumpBuffer << name(theFolder); + return *this; +} + ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FeaturePtr& theEntity) { myDumpBuffer << name(theEntity); @@ -945,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 @@ -962,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); + } } } } @@ -985,5 +1088,8 @@ ModelHighAPI_Dumper& operator<<(ModelHighAPI_Dumper& theDumper, // then store currently dumped string theDumper.myFullDump << aBufCopy; + // now, store all postponed features + theDumper.dumpPostponed(); + return theDumper; }