From f724bcc2645915584c1e35ed40818cc021feda65 Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 29 Mar 2005 08:42:50 +0000 Subject: [PATCH] "Dump Python". Add GetDumpName(), add global names to script --- src/GEOM/GEOM_Engine.cxx | 67 +++++++++++++++++++++++++++++----------- src/GEOM/GEOM_Engine.hxx | 6 +++- 2 files changed, 54 insertions(+), 19 deletions(-) diff --git a/src/GEOM/GEOM_Engine.cxx b/src/GEOM/GEOM_Engine.cxx index ecfc78330..2fb7c32e2 100644 --- a/src/GEOM/GEOM_Engine.cxx +++ b/src/GEOM/GEOM_Engine.cxx @@ -368,6 +368,8 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID, aScript += "def RebuildData(theStudy):"; aScript += "\n\tgeompy.init_geom(theStudy)"; + Standard_Integer posToInertGlobalVars = aScript.Length() + 1; + Handle(TDataStd_TreeNode) aNode, aRoot; Handle(GEOM_Function) aFunction; TColStd_MapOfTransient aMap; @@ -387,25 +389,22 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID, Resource_DataMapOfAsciiStringAsciiString aEntry2StEntry, aStEntry2Entry; Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString anEntryToNameIt; - if ( isPublished ) + // build maps entry <-> studyEntry + for (anEntryToNameIt.Initialize( theObjectNames ); + anEntryToNameIt.More(); + anEntryToNameIt.Next()) { - // build maps entry <-> studyEntry - for (anEntryToNameIt.Initialize( theObjectNames ); - anEntryToNameIt.More(); - anEntryToNameIt.Next()) - { - const TCollection_AsciiString& aEntry = anEntryToNameIt.Key(); - // look for an object by entry - TDF_Label L; - TDF_Tool::Label( aDoc->GetData(), aEntry, L ); - if ( L.IsNull() ) continue; - Handle(GEOM_Object) obj = GEOM_Object::GetObject( L ); - // fill maps - if ( !obj.IsNull() ) { - TCollection_AsciiString aStudyEntry (obj->GetAuxData()); - aEntry2StEntry.Bind( aEntry, aStudyEntry); - aStEntry2Entry.Bind( aStudyEntry, aEntry ); - } + const TCollection_AsciiString& aEntry = anEntryToNameIt.Key(); + // look for an object by entry + TDF_Label L; + TDF_Tool::Label( aDoc->GetData(), aEntry, L ); + if ( L.IsNull() ) continue; + Handle(GEOM_Object) obj = GEOM_Object::GetObject( L ); + // fill maps + if ( !obj.IsNull() ) { + TCollection_AsciiString aStudyEntry (obj->GetAuxData()); + aEntry2StEntry.Bind( aEntry, aStudyEntry); + aStEntry2Entry.Bind( aStudyEntry, aEntry ); } } @@ -491,10 +490,42 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID, anUpdatedScript += "\n\tpass\n"; aValidScript = true; + + // fill _studyEntry2NameMap and build globalVars + TCollection_AsciiString globalVars; + _studyEntry2NameMap.Clear(); + Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString aStEntryToEntryIt; + for (aStEntryToEntryIt.Initialize( aStEntry2Entry ); + aStEntryToEntryIt.More(); + aStEntryToEntryIt.Next() ) + { + const TCollection_AsciiString & name = theObjectNames( aStEntryToEntryIt.Value() ); + _studyEntry2NameMap.Bind (aStEntryToEntryIt.Key(), name ); + if ( !globalVars.IsEmpty() ) + globalVars += ", "; + globalVars += name; + } + if ( !globalVars.IsEmpty() ) { + globalVars.Insert( 1, "\n\tglobal " ); + anUpdatedScript.Insert( posToInertGlobalVars, globalVars ); + } return anUpdatedScript; } +//======================================================================= +//function : GetDumpName +//purpose : +//======================================================================= + +const char* GEOM_Engine::GetDumpName (const char* theStudyEntry) const +{ + if ( _studyEntry2NameMap.IsBound( (char*)theStudyEntry )) + return _studyEntry2NameMap( (char*)theStudyEntry ).ToCString(); + + return NULL; +} + //=========================================================================== // Internal functions diff --git a/src/GEOM/GEOM_Engine.hxx b/src/GEOM/GEOM_Engine.hxx index 2d7df0999..7765fea9f 100644 --- a/src/GEOM/GEOM_Engine.hxx +++ b/src/GEOM/GEOM_Engine.hxx @@ -68,7 +68,9 @@ class GEOM_Engine Resource_DataMapOfAsciiStringAsciiString& theObjectNames, bool isPublished, bool& aValidScript); - + + const char* GetDumpName (const char* theStudyEntry) const; + protected: static void SetEngine(GEOM_Engine* theEngine); @@ -78,6 +80,8 @@ class GEOM_Engine Interface_DataMapOfIntegerTransient _mapIDDocument; int _UndoLimit; GEOM_DataMapOfAsciiStringTransient _objects; + + Resource_DataMapOfAsciiStringAsciiString _studyEntry2NameMap; }; #endif -- 2.39.2