From 7575328a155fcae3c3a1bee50d586d8886f77190 Mon Sep 17 00:00:00 2001 From: srn Date: Wed, 6 Apr 2005 10:40:56 +0000 Subject: [PATCH] Added method dump for out the study's content in the file --- src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 78 +++++++++++++++++++++++++ src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx | 2 + 2 files changed, 80 insertions(+) diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index cf5702b59..9db430603 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -1328,3 +1328,81 @@ bool SALOMEDSImpl_Study::DumpStudy(const TCollection_AsciiString& thePath, fp.close(); return true; } + +void dumpSO(const Handle(SALOMEDSImpl_SObject)& theSO, + fstream& fp, + const TCollection_AsciiString& Tab, + const Handle(SALOMEDSImpl_Study) theStudy); +//============================================================================ +/*! Function : dump + * Purpose : + */ +//============================================================================ +void SALOMEDSImpl_Study::dump(const TCollection_AsciiString& theFileName) +{ + //Create a file that will contain a main Study script + fstream fp; + fp.open(theFileName.ToCString(), ios::out); + +#ifdef WIN32 + bool isOpened = fp.is_open(); +#else + bool isOpened = fp.rdbuf()->is_open(); +#endif + + if(!isOpened) { + _errorCode = TCollection_AsciiString("Can't create a file ")+theFileName; + cout << "### SALOMEDSImpl_Study::dump Error: " << _errorCode << endl; + return; + } + + Handle(SALOMEDSImpl_SObject) aSO = FindObjectID("0:1"); + fp << "0:1" << endl; + Handle(SALOMEDSImpl_ChildIterator) Itr = NewChildIterator(aSO); + TCollection_AsciiString aTab(" "); + for(; Itr->More(); Itr->Next()) { + dumpSO(Itr->Value(), fp, aTab, this); + } + + fp.close(); +} + + +void dumpSO(const Handle(SALOMEDSImpl_SObject)& theSO, + fstream& fp, + const TCollection_AsciiString& Tab, + const Handle(SALOMEDSImpl_Study) theStudy) +{ + TCollection_AsciiString aTab(Tab), anID(theSO->GetID()); + fp << aTab << anID << endl; + int aLength, i; + Handle(TColStd_HSequenceOfTransient) aSeq = theSO->GetAllAttributes(); + aLength = aSeq->Length(); + for(i=1; i<=aLength; i++) { + Handle(SALOMEDSImpl_GenericAttribute) anAttr = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(aSeq->Value(i)); + TCollection_AsciiString aType = anAttr->GetClassType(); + fp << Tab << " -- " << aType; + if(aType == "AttributeReal") { + fp << " : " << Handle(SALOMEDSImpl_AttributeReal)::DownCast(anAttr)->Value(); + } + else if(aType == "AttributeInteger") { + fp << " : " << Handle(SALOMEDSImpl_AttributeInteger)::DownCast(anAttr)->Value(); + } + else if(aType == "AttributeName") { + fp << " : " << Handle(SALOMEDSImpl_AttributeName)::DownCast(anAttr)->Value(); + } + else if(aType == "AttributeComment") { + fp << " : " << Handle(SALOMEDSImpl_AttributeComment)::DownCast(anAttr)->Value(); + } + fp << endl; + } + + Handle(SALOMEDSImpl_ChildIterator) Itr = theStudy->NewChildIterator(theSO); + TCollection_AsciiString aNewTab(" "); + aNewTab+=aTab; + for(; Itr->More(); Itr->Next()) { + dumpSO(Itr->Value(), fp, aNewTab, theStudy); + } + + return; +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index 32bbe1bcb..2baae207f 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -232,6 +232,8 @@ public: virtual Handle(TDocStd_Document) GetDocument() { return _doc; } + //The method dump creates a txt file that contain a dump of the study, for debug use + void dump(const TCollection_AsciiString& theFileName); public: DEFINE_STANDARD_RTTI( SALOMEDSImpl_Study ) -- 2.39.2