myFeatureCount.clear();
while (!myEntitiesStack.empty())
myEntitiesStack.pop();
+
+ myPostponed.clear();
+ myDumpPostponedInProgress = false;
}
}
aName = aFolder->data()->name();
aKind = ModelAPI_Folder::ID();
isSaveNotDumped = false;
- myNotDumpedFolders.insert(aFolder);
}
}
const std::list<ResultPtr>& aResults = theFeature->results();
std::list<ResultPtr>::const_iterator aResIt = aResults.begin();
for (int i = 0; aResIt != aResults.end(); ++aResIt, ++i) {
- std::string aDefaultName = ModelAPI_Tools::getDefaultName(*aResIt, i);
+ std::pair<std::string, bool> aName = ModelAPI_Tools::getDefaultName(*aResIt, i);
+ std::string aDefaultName = aName.first;
std::string aResName = (*aResIt)->data()->name();
bool isUserDefined = !(isFeatureDefaultName && aDefaultName == aResName);
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,
CompositeFeaturePtr aCompFeat = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*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<ModelAPI_Folder>(*anObjIt);
if (aFolder)
}
}
}
+ // dump folders if any
+ dumpPostponed(true);
return isOk;
}
// increase composite features stack
++gCompositeStackDepth;
// dump composite itself
- if (!isDumped(theComposite) || isForce)
+ if (!isDumped(EntityPtr(theComposite)) || isForce)
dumpFeature(FeaturePtr(theComposite), isForce);
// sub-part is processed independently, because it provides separate document
// decrease composite features stack
--gCompositeStackDepth;
+ // dump folders if any
+ dumpPostponed(true);
return isOk;
}
int aNbSubs = theComposite->numberOfSubs();
for (int anIndex = 0; anIndex < aNbSubs; ++anIndex) {
FeaturePtr aFeature = theComposite->subFeature(anIndex);
- if (isDumped(aFeature))
+ if (isDumped(EntityPtr(aFeature)))
continue;
isSubDumped = true;
// 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<EntityPtr> aPostponedCopy = myPostponed;
+ myPostponed.clear();
+
+ // iterate over postponed entities and try to dump them
+ std::list<EntityPtr>::const_iterator anIt = aPostponedCopy.begin();
+ for (; anIt != aPostponedCopy.end(); ++anIt) {
+ FolderPtr aFolder = std::dynamic_pointer_cast<ModelAPI_Folder>(*anIt);
+ if (aFolder) {
+ if (theDumpFolders)
+ dumpFolder(aFolder);
+ else
+ myPostponed.push_back(*anIt);
+ }
+ else {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+ if (aFeature)
+ dumpFeature(aFeature);
+ }
+ }
+ myDumpPostponedInProgress = false;
+}
+
void ModelHighAPI_Dumper::dumpSubFeatureNameAndColor(const std::string theSubFeatureGet,
const FeaturePtr& theSubFeature)
{
{
EntityNameMap::const_iterator aFound = myNames.find(theEntity);
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(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<ObjectPtr> aRefs = theRefList->list();
+ std::list<ObjectPtr>::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
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const FolderPtr& theFolder)
{
myDumpBuffer << name(theFolder);
- myNotDumpedFolders.erase(theFolder);
return *this;
}
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(
const std::shared_ptr<ModelAPI_AttributeSelectionList>& theAttrSelList)
{
- myDumpBuffer << "[";
+ static const int aThreshold = 2;
+ // if number of elements in the list if greater than a threshold,
+ // dump it in a separate line with specific name
+ std::string aDumped = myDumpBuffer.str();
- GeomShapePtr aShape;
- std::string aShapeTypeStr;
+ if (aDumped.empty() || theAttrSelList->size() <= aThreshold) {
+ myDumpBuffer << "[";
- bool isAdded = false;
+ GeomShapePtr aShape;
+ std::string aShapeTypeStr;
- for(int anIndex = 0; anIndex < theAttrSelList->size(); ++anIndex) {
- AttributeSelectionPtr anAttribute = theAttrSelList->value(anIndex);
- aShape = anAttribute->value();
- if(!aShape.get()) {
- ResultPtr aContext = anAttribute->context();
- if (aContext.get())
- aShape = aContext->shape();
- }
+ bool isAdded = false;
- if(!aShape.get()) {
- continue;
- }
+ for(int anIndex = 0; anIndex < theAttrSelList->size(); ++anIndex) {
+ AttributeSelectionPtr anAttribute = theAttrSelList->value(anIndex);
+ aShape = anAttribute->value();
+ if(!aShape.get()) {
+ ResultPtr aContext = anAttribute->context();
+ if (aContext.get())
+ aShape = aContext->shape();
+ }
- if(isAdded) {
- myDumpBuffer << ", ";
- } else {
- isAdded = true;
+ if(!aShape.get()) {
+ continue;
+ }
+
+ if(isAdded) {
+ myDumpBuffer << ", ";
+ } else {
+ isAdded = true;
+ }
+ myDumpBuffer << "model.selection(\"" <<
+ aShape->shapeTypeStr() << "\", \"" << anAttribute->namingName() << "\")";
}
- myDumpBuffer << "model.selection(\"" <<
- aShape->shapeTypeStr() << "\", \"" << anAttribute->namingName() << "\")";
- }
- myDumpBuffer << "]";
+ myDumpBuffer << "]";
+ } else {
+ // clear buffer and store list "as is"
+ myDumpBuffer.str("");
+ *this << theAttrSelList;
+ // save buffer and clear it again
+ std::string aDumpedList = myDumpBuffer.str();
+ myDumpBuffer.str("");
+ // obtain name of list
+ FeaturePtr anOwner = ModelAPI_Feature::feature(theAttrSelList->owner());
+ std::string aListName = name(anOwner) + "_objects";
+ // store all previous data
+ myDumpBuffer << aListName << " = " << aDumpedList << std::endl
+ << aDumped << aListName;
+ }
return *this;
}
isCopy = aCopyAttr.get() && aCopyAttr->value();
}
}
- } while (isCopy);
+ } while (isCopy && !theDumper.myEntitiesStack.empty());
}
// store all not-dumped entities first
else {
FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*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<AttributePtr>& aRefs = aFeature->data()->refsToMe();
std::set<AttributePtr>::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);
+ }
}
}
}
// then store currently dumped string
theDumper.myFullDump << aBufCopy;
- // now, store all not dumped folders
- std::set<FolderPtr>::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;
}