return mySelf;
}
-void ModelHighAPI_Dumper::clear()
+void ModelHighAPI_Dumper::clear(bool bufferOnly)
{
myDumpBuffer = std::ostringstream();
myDumpBuffer << std::setprecision(16);
+
+ clearNotDumped();
+
+ if (!bufferOnly) {
+ myFullDump = std::ostringstream();
+ myFullDump << std::setprecision(16);
+
+ myNames.clear();
+ myModules.clear();
+ myLastEntityWithName = EntityPtr();
+ }
+}
+
+void ModelHighAPI_Dumper::clearNotDumped()
+{
+ myNotDumpedEntities.clear();
}
const std::string& ModelHighAPI_Dumper::name(const EntityPtr& theEntity)
}
myNames[theEntity] = std::pair<std::string, bool>(aName, isNameDefined);
+ myNotDumpedEntities.insert(theEntity);
return myNames[theEntity].first;
}
bool ModelHighAPI_Dumper::process(const std::shared_ptr<ModelAPI_Document>& theDoc)
{
bool isOk = true;
- CompositeFeaturePtr aLastComposite;
// dump all features
std::list<FeaturePtr> aFeatures = theDoc->allFeatures();
std::list<FeaturePtr>::const_iterator aFeatIt = aFeatures.begin();
for (; aFeatIt != aFeatures.end(); ++aFeatIt) {
- // dump feature if and only if it is not a sub-feature of last composite feature
- // (all subs of composite are dumped in special method)
- if (!aLastComposite || !aLastComposite->isSub(*aFeatIt))
+ if (!isDumped(*aFeatIt))
dumpFeature(*aFeatIt);
// iteratively process composite features
myNames[aSubDoc] = myNames[*aFeatIt];
isOk = process(aSubDoc) && isOk;
- } else {
+ } else
isOk = process(aCompFeat) && isOk;
- aLastComposite = aCompFeat;
- }
}
return isOk;
}
int aNbSubs = theComposite->numberOfSubs();
for (int anIndex = 0; anIndex < aNbSubs; ++anIndex) {
FeaturePtr aFeature = theComposite->subFeature(anIndex);
- dumpFeature(aFeature, true);
+ if (!isDumped(aFeature))
+ dumpFeature(aFeature, true);
}
// dump command to update model
myDumpBuffer << "model.do()" << std::endl;
aFile << "model.begin()" << std::endl;
// dump collected data
- aFile << myDumpBuffer.str();
+ aFile << myFullDump.str();
// standard footer
aFile << "model.end()" << std::endl;
myLastEntityWithName = EntityPtr();
}
+bool ModelHighAPI_Dumper::isDumped(const EntityPtr& theEntity) const
+{
+ EntityNameMap::const_iterator aFound = myNames.find(theEntity);
+ return aFound != myNames.end();
+}
+
ModelHighAPI_Dumper& ModelHighAPI_Dumper::operator<<(const char theChar)
{
myDumpBuffer << theChar;
myDumpBuffer << name(theEntity);
if (myNames[theEntity].second)
myLastEntityWithName = theEntity;
+ myNotDumpedEntities.erase(theEntity);
return *this;
}
{
theDumper.myDumpBuffer << theEndl;
theDumper.dumpEntitySetName();
+
+ // store all not-dumped entities first
+ std::set<EntityPtr> aNotDumped = theDumper.myNotDumpedEntities;
+ std::string aBufCopy = theDumper.myDumpBuffer.str();
+ theDumper.clear(true);
+ std::set<EntityPtr>::const_iterator anIt = aNotDumped.begin();
+ for (; anIt != aNotDumped.end(); ++anIt) {
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+ theDumper.dumpFeature(aFeature, true);
+ }
+
+ // then store currently dumped string
+ theDumper.myFullDump << aBufCopy;
+
return theDumper;
}
MODELHIGHAPI_EXPORT
ModelHighAPI_Dumper& operator<<(const std::shared_ptr<ModelAPI_AttributeSelection>& theAttrSelect);
+ /// Clear dump buffer
+ MODELHIGHAPI_EXPORT
+ void clear(bool bufferOnly = false);
+ /// clear list of not dumped entities
+ MODELHIGHAPI_EXPORT void clearNotDumped();
+
protected:
/// Dump "setName" command if last entity had user-defined name
MODELHIGHAPI_EXPORT void dumpEntitySetName();
- /// Clear dump buffer
- void clear();
-
private:
ModelHighAPI_Dumper(const ModelHighAPI_Dumper&);
const ModelHighAPI_Dumper& operator=(const ModelHighAPI_Dumper&);
/// Iterate all features in composite feature and dump them into intermediate buffer
bool process(const std::shared_ptr<ModelAPI_CompositeFeature>& theComposite);
+ /// Check the entity is already dumped
+ bool isDumped(const EntityPtr& theEntity) const;
+
private:
typedef std::map<EntityPtr, std::pair<std::string, bool> > EntityNameMap;
typedef std::map<std::string, std::set<std::string> > ModulesMap;
static ModelHighAPI_Dumper* mySelf;
std::ostringstream myDumpBuffer; ///< intermediate buffer to store dumping data
+ std::ostringstream myFullDump; ///< full buffer of dumped data
+
ModulesMap myModules; ///< modules and entities to be imported
EntityNameMap myNames; ///< names of the entities
EntityPtr myLastEntityWithName; ///< not null, if last dumped entity had user defined name
+
+protected:
+ std::set<EntityPtr> myNotDumpedEntities; ///< list of entities, used by other features but not dumped yet
};
#endif