0021122: EDF 1735 SMESH: Bug when saving in .hdf

Fix dump of multiply published objects
This commit is contained in:
eap 2011-02-04 17:26:34 +00:00
parent ca0d85f801
commit e76c7f020e
3 changed files with 208 additions and 170 deletions

View File

@ -64,9 +64,6 @@
#include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx> #include <Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString.hxx>
#include <set> #include <set>
#include <map>
#include <string>
#include <vector>
#include <Standard_Failure.hxx> #include <Standard_Failure.hxx>
#include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
@ -84,6 +81,10 @@ static int MYDEBUG = 0;
static int MYDEBUG = 0; static int MYDEBUG = 0;
#endif #endif
typedef std::map< TCollection_AsciiString, TCollection_AsciiString > TSting2StringMap;
typedef std::map< TCollection_AsciiString, TObjectData > TSting2ObjDataMap;
typedef std::map< TCollection_AsciiString, TObjectData* > TSting2ObjDataPtrMap;
static GEOM_Engine* TheEngine = NULL; static GEOM_Engine* TheEngine = NULL;
@ -115,7 +116,7 @@ bool ProcessFunction(Handle(GEOM_Function)& theFunction,
const TVariablesList& theVariables, const TVariablesList& theVariables,
const bool theIsPublished, const bool theIsPublished,
TDF_LabelMap& theProcessed, TDF_LabelMap& theProcessed,
std::set<std::string>& theIgnoreObjs, std::set<TCollection_AsciiString>& theIgnoreObjs,
bool& theIsDumpCollected); bool& theIsDumpCollected);
void ReplaceVariables(TCollection_AsciiString& theCommand, void ReplaceVariables(TCollection_AsciiString& theCommand,
@ -124,27 +125,59 @@ void ReplaceVariables(TCollection_AsciiString& theCommand,
Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theString); Handle(TColStd_HSequenceOfInteger) FindEntries(TCollection_AsciiString& theString);
void ReplaceEntriesByNames (TCollection_AsciiString& theScript, void ReplaceEntriesByNames (TCollection_AsciiString& theScript,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames, TSting2ObjDataMap& aEntry2ObjData,
const bool theIsPublished, const bool theIsPublished,
Resource_DataMapOfAsciiStringAsciiString& theEntryToBadName,
TColStd_SequenceOfAsciiString& theObjListToPublish, TColStd_SequenceOfAsciiString& theObjListToPublish,
Standard_Integer& objectCounter, Standard_Integer& objectCounter,
Resource_DataMapOfAsciiStringAsciiString& aNameToEntry); Resource_DataMapOfAsciiStringAsciiString& aNameToEntry);
void AddObjectColors (int theDocID, void AddObjectColors (int theDocID,
TCollection_AsciiString& theScript, TCollection_AsciiString& theScript,
const Resource_DataMapOfAsciiStringAsciiString& theObjectNames); const TSting2ObjDataMap& theEntry2ObjData);
void AddTextures (int theDocID, TCollection_AsciiString& theScript); void AddTextures (int theDocID, TCollection_AsciiString& theScript);
void PublishObject (const TCollection_AsciiString& theEntry, void PublishObject (TObjectData& theObjectData,
const TCollection_AsciiString& theName, TSting2ObjDataMap& theEntry2ObjData,
const Resource_DataMapOfAsciiStringAsciiString& theObjectNames, const TSting2ObjDataPtrMap& theStEntry2ObjDataPtr,
const Resource_DataMapOfAsciiStringAsciiString& theEntry2StEntry, Resource_DataMapOfAsciiStringAsciiString& theNameToEntry,
const Resource_DataMapOfAsciiStringAsciiString& theStEntry2Entry, TSting2StringMap& theEntryToCmdMap,
const Resource_DataMapOfAsciiStringAsciiString& theEntryToBadName, std::set<TCollection_AsciiString>& theMapOfPublished);
std::map< int, std::string >& theEntryToCommandMap,
std::set<std::string>& theMapOfPublished); namespace
{
//================================================================================
/*!
* \brief Fix up the name of python variable
*/
//================================================================================
void healPyName( TCollection_AsciiString& pyName,
const TCollection_AsciiString& anEntry,
Resource_DataMapOfAsciiStringAsciiString& aNameToEntry)
{
const TCollection_AsciiString allowedChars
("qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_");
if ( pyName.IsIntegerValue() ) { // pyName must not start with a digit
pyName.Insert( 1, 'a' );
}
int p, p2=1; // replace not allowed chars
while ((p = pyName.FirstLocationNotInSet(allowedChars, p2, pyName.Length()))) {
pyName.SetValue(p, '_');
p2=p;
}
if ( aNameToEntry.IsBound( pyName ) && anEntry != aNameToEntry( pyName ))
{ // diff objects have same name - make a new name by appending a digit
TCollection_AsciiString aName2;
Standard_Integer i = 0;
do {
aName2 = pyName + "_" + ++i;
} while ( aNameToEntry.IsBound( aName2 ) && anEntry != aNameToEntry( aName2 ));
pyName = aName2;
}
}
}
//======================================================================= //=======================================================================
//function : GetTextureGUID //function : GetTextureGUID
@ -525,7 +558,7 @@ void GEOM_Engine::Close(int theDocID)
*/ */
//============================================================================= //=============================================================================
TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID, TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames, std::vector<TObjectData>& theObjectData,
TVariablesList theVariables, TVariablesList theVariables,
bool isPublished, bool isPublished,
bool& aValidScript) bool& aValidScript)
@ -549,24 +582,30 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
Standard_Integer posToInsertGlobalVars = aScript.Length() + 1; Standard_Integer posToInsertGlobalVars = aScript.Length() + 1;
Resource_DataMapOfAsciiStringAsciiString aEntry2StEntry, aStEntry2Entry; // a map containing copies of TObjectData from theObjectData
Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString anEntryToNameIt; TSting2ObjDataMap aEntry2ObjData;
// build maps entry <-> studyEntry // contains pointers to TObjectData of either aEntry2ObjData or theObjectData; the latter
for (anEntryToNameIt.Initialize( theObjectNames ); // occures when several StudyEntries correspond to one Entry
anEntryToNameIt.More(); TSting2ObjDataPtrMap aStEntry2ObjDataPtr;
anEntryToNameIt.Next())
//Resource_DataMapOfAsciiStringAsciiString aEntry2StEntry, aStEntry2Entry, theObjectNames;
for (unsigned i = 0; i < theObjectData.size(); ++i )
{ {
const TCollection_AsciiString& aEntry = anEntryToNameIt.Key(); TObjectData& data = theObjectData[i];
// look for an object by entry // look for an object by entry
TDF_Label L; TDF_Label L;
TDF_Tool::Label( aDoc->GetData(), aEntry, L ); TDF_Tool::Label( aDoc->GetData(), data._entry, L );
if ( L.IsNull() ) continue; if ( L.IsNull() ) continue;
Handle(GEOM_Object) obj = GEOM_Object::GetObject( L ); Handle(GEOM_Object) obj = GEOM_Object::GetObject( L );
// fill maps // fill maps
if ( !obj.IsNull() ) { if ( !obj.IsNull() ) {
TCollection_AsciiString aStudyEntry (obj->GetAuxData()); TSting2ObjDataMap::iterator ent2Data =
aEntry2StEntry.Bind( aEntry, aStudyEntry); aEntry2ObjData.insert( std::make_pair( data._entry, data )).first;
aStEntry2Entry.Bind( aStudyEntry, aEntry );
if ( ent2Data->second._studyEntry == data._studyEntry ) // Entry encounters 1st time
aStEntry2ObjDataPtr.insert( std::make_pair( data._studyEntry, & ent2Data->second ));
else
aStEntry2ObjDataPtr.insert( std::make_pair( data._studyEntry, & data ));
} }
} }
@ -577,10 +616,9 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
Handle(TDataStd_TreeNode) aNode, aRoot; Handle(TDataStd_TreeNode) aNode, aRoot;
Handle(GEOM_Function) aFunction; Handle(GEOM_Function) aFunction;
TDF_LabelMap aCheckedFuncMap; TDF_LabelMap aCheckedFuncMap;
std::set<std::string> anIgnoreObjMap; std::set< TCollection_AsciiString > anIgnoreObjMap;
TCollection_AsciiString aFuncScript; TCollection_AsciiString aFuncScript;
Resource_DataMapOfAsciiStringAsciiString anEntryToBadName;
// Mantis issue 0020768 // Mantis issue 0020768
Standard_Integer objectCounter = 0; Standard_Integer objectCounter = 0;
@ -606,26 +644,22 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
aFuncScript += aCurScript; aFuncScript += aCurScript;
if (isDumpCollected ) { if (isDumpCollected ) {
// Replace entries by the names // Replace entries by the names
ReplaceEntriesByNames( aFuncScript, theObjectNames, ReplaceEntriesByNames( aFuncScript, aEntry2ObjData, isPublished,
isPublished, anEntryToBadName, aObjListToPublish, aObjListToPublish, objectCounter, aNameToEntry );
objectCounter, aNameToEntry );
// publish collected objects // publish collected objects
std::map< int, std::string > anEntryToCommandMap; // sort publishing commands by object entry TSting2StringMap anEntryToCmdMap; // sort publishing commands by study entry
int i = 1, n = aObjListToPublish.Length(); int i = 1, n = aObjListToPublish.Length();
for ( ; i <= n; i++ ) for ( ; i <= n; i++ )
{ {
const TCollection_AsciiString& aEntry = aObjListToPublish.Value(i); const TCollection_AsciiString& aEntry = aObjListToPublish.Value(i);
if (!theObjectNames.IsBound( aEntry )) PublishObject( aEntry2ObjData[aEntry], aEntry2ObjData, aStEntry2ObjDataPtr,
continue; aNameToEntry, anEntryToCmdMap, anIgnoreObjMap );
PublishObject( aEntry, theObjectNames.Find(aEntry),
theObjectNames, aEntry2StEntry, aStEntry2Entry,
anEntryToBadName, anEntryToCommandMap, anIgnoreObjMap );
} }
// add publishing commands to the script // add publishing commands to the script
std::map< int, std::string >::iterator anEntryToCommand = anEntryToCommandMap.begin(); TSting2StringMap::iterator anEntryToCmd = anEntryToCmdMap.begin();
for ( ; anEntryToCommand != anEntryToCommandMap.end(); ++anEntryToCommand ) for ( ; anEntryToCmd != anEntryToCmdMap.end(); ++anEntryToCmd )
aFuncScript += (char*)anEntryToCommand->second.c_str(); aFuncScript += anEntryToCmd->second;
// PTv, 0020001 add result objects from RestoreGivenSubShapes into ignore list, // PTv, 0020001 add result objects from RestoreGivenSubShapes into ignore list,
// because they will be published during command execution // because they will be published during command execution
@ -639,7 +673,6 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
for ( ; i <= n; i+=2) { for ( ; i <= n; i+=2) {
TCollection_AsciiString anEntry = TCollection_AsciiString anEntry =
aSubStr.SubString(aSeq->Value(i), aSeq->Value(i+1)); aSubStr.SubString(aSeq->Value(i), aSeq->Value(i+1));
if (!anIgnoreObjMap.count(anEntry.ToCString()))
anIgnoreObjMap.insert(anEntry.ToCString()); anIgnoreObjMap.insert(anEntry.ToCString());
} }
} }
@ -654,35 +687,34 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
// Replace entries by the names // Replace entries by the names
aObjListToPublish.Clear(); aObjListToPublish.Clear();
ReplaceEntriesByNames( aFuncScript, theObjectNames, ReplaceEntriesByNames( aFuncScript, aEntry2ObjData, isPublished, aObjListToPublish,
isPublished, anEntryToBadName, aObjListToPublish,
objectCounter, aNameToEntry ); objectCounter, aNameToEntry );
aScript += aFuncScript; aScript += aFuncScript;
// ouv : NPAL12872 // ouv : NPAL12872
AddObjectColors( theDocID, aScript, theObjectNames ); AddObjectColors( theDocID, aScript, aEntry2ObjData );
// Make script to publish in study // Make script to publish in study
TSting2ObjDataPtrMap::iterator aStEntry2ObjDataPtrIt;
if ( isPublished ) if ( isPublished )
{ {
std::map< int, std::string > anEntryToCommandMap; // sort publishing commands by object entry TSting2StringMap anEntryToCmdMap; // sort publishing commands by object entry
for (anEntryToNameIt.Initialize( theObjectNames );
anEntryToNameIt.More(); for (aStEntry2ObjDataPtrIt = aStEntry2ObjDataPtr.begin();
anEntryToNameIt.Next()) aStEntry2ObjDataPtrIt != aStEntry2ObjDataPtr.end();
++aStEntry2ObjDataPtrIt)
{ {
const TCollection_AsciiString& aEntry = anEntryToNameIt.Key(); TObjectData* data = aStEntry2ObjDataPtrIt->second;
if (anIgnoreObjMap.count(aEntry.ToCString())) if ( anIgnoreObjMap.count( data->_entry ))
continue; // should not be dumped continue; // should not be dumped
const TCollection_AsciiString& aName = anEntryToNameIt.Value(); PublishObject( *data, aEntry2ObjData, aStEntry2ObjDataPtr,
PublishObject( aEntry, aName, theObjectNames, aNameToEntry, anEntryToCmdMap, anIgnoreObjMap );
aEntry2StEntry, aStEntry2Entry,
anEntryToBadName, anEntryToCommandMap, anIgnoreObjMap );
} }
// add publishing commands to the script // add publishing commands to the script
std::map< int, std::string >::iterator anEntryToCommand = anEntryToCommandMap.begin(); TSting2StringMap::iterator anEntryToCmd = anEntryToCmdMap.begin();
for ( ; anEntryToCommand != anEntryToCommandMap.end(); ++anEntryToCommand ) for ( ; anEntryToCmd != anEntryToCmdMap.end(); ++anEntryToCmd )
aScript += (char*)anEntryToCommand->second.c_str(); aScript += anEntryToCmd->second;
} }
//aScript += "\n\tpass\n"; //aScript += "\n\tpass\n";
@ -692,16 +724,16 @@ TCollection_AsciiString GEOM_Engine::DumpPython(int theDocID,
// fill _studyEntry2NameMap and build globalVars // fill _studyEntry2NameMap and build globalVars
TCollection_AsciiString globalVars; TCollection_AsciiString globalVars;
_studyEntry2NameMap.Clear(); _studyEntry2NameMap.Clear();
Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString aStEntryToEntryIt; for (aStEntry2ObjDataPtrIt = aStEntry2ObjDataPtr.begin();
for (aStEntryToEntryIt.Initialize( aStEntry2Entry ); aStEntry2ObjDataPtrIt != aStEntry2ObjDataPtr.end();
aStEntryToEntryIt.More(); ++aStEntry2ObjDataPtrIt)
aStEntryToEntryIt.Next() )
{ {
const TCollection_AsciiString & name = theObjectNames( aStEntryToEntryIt.Value() ); const TCollection_AsciiString& studyEntry = aStEntry2ObjDataPtrIt->first;
_studyEntry2NameMap.Bind (aStEntryToEntryIt.Key(), name ); const TObjectData* data = aStEntry2ObjDataPtrIt->second;
_studyEntry2NameMap.Bind ( studyEntry, data->_pyName );
if ( !globalVars.IsEmpty() ) if ( !globalVars.IsEmpty() )
globalVars += ", "; globalVars += ", ";
globalVars += name; globalVars += data->_pyName;
} }
if ( !globalVars.IsEmpty() ) { if ( !globalVars.IsEmpty() ) {
globalVars.Insert( 1, "\n\tglobal " ); globalVars.Insert( 1, "\n\tglobal " );
@ -868,7 +900,7 @@ bool ProcessFunction(Handle(GEOM_Function)& theFunction,
const TVariablesList& theVariables, const TVariablesList& theVariables,
const bool theIsPublished, const bool theIsPublished,
TDF_LabelMap& theProcessed, TDF_LabelMap& theProcessed,
std::set<std::string>& theIgnoreObjs, std::set<TCollection_AsciiString>& theIgnoreObjs,
bool& theIsDumpCollected) bool& theIsDumpCollected)
{ {
theIsDumpCollected = false; theIsDumpCollected = false;
@ -910,7 +942,7 @@ bool ProcessFunction(Handle(GEOM_Function)& theFunction,
if (doNotProcess) { if (doNotProcess) {
TCollection_AsciiString anObjEntry; TCollection_AsciiString anObjEntry;
TDF_Tool::Entry(theFunction->GetOwnerEntry(), anObjEntry); TDF_Tool::Entry(theFunction->GetOwnerEntry(), anObjEntry);
theIgnoreObjs.insert(anObjEntry.ToCString()); theIgnoreObjs.insert(anObjEntry);
return false; return false;
} }
theProcessed.Add(theFunction->GetEntry()); theProcessed.Add(theFunction->GetEntry());
@ -921,7 +953,7 @@ bool ProcessFunction(Handle(GEOM_Function)& theFunction,
//Check if its internal function which doesn't requires dumping //Check if its internal function which doesn't requires dumping
if(aDescr == "None") return false; if(aDescr == "None") return false;
// 0020001 PTv, check for critical functions, which requier dump of objects // 0020001 PTv, check for critical functions, which require dump of objects
if (theIsPublished) if (theIsPublished)
{ {
// currently, there is only one function "RestoreGivenSubShapes", // currently, there is only one function "RestoreGivenSubShapes",
@ -1253,17 +1285,14 @@ void ReplaceVariables(TCollection_AsciiString& theCommand,
*/ */
//============================================================================= //=============================================================================
void ReplaceEntriesByNames (TCollection_AsciiString& theScript, void ReplaceEntriesByNames (TCollection_AsciiString& theScript,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames, TSting2ObjDataMap& aEntry2ObjData,
const bool theIsPublished, const bool theIsPublished,
Resource_DataMapOfAsciiStringAsciiString& theEntryToBadName,
TColStd_SequenceOfAsciiString& theObjListToPublish, TColStd_SequenceOfAsciiString& theObjListToPublish,
Standard_Integer& objectCounter, Standard_Integer& objectCounter,
Resource_DataMapOfAsciiStringAsciiString& aNameToEntry) Resource_DataMapOfAsciiStringAsciiString& aNameToEntry)
{ {
Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(theScript); Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(theScript);
//Standard_Integer objectCounter = 0;
Standard_Integer aLen = aSeq->Length(), aStart = 1, aScriptLength = theScript.Length(); Standard_Integer aLen = aSeq->Length(), aStart = 1, aScriptLength = theScript.Length();
//Resource_DataMapOfAsciiStringAsciiString aNameToEntry;
//Replace entries by the names //Replace entries by the names
TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("geomObj_"), TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("geomObj_"),
@ -1274,45 +1303,22 @@ void ReplaceEntriesByNames (TCollection_AsciiString& theScript,
anUpdatedScript += theScript.SubString(aStart, aSeq->Value(i)-1); anUpdatedScript += theScript.SubString(aStart, aSeq->Value(i)-1);
anEntry = theScript.SubString(aSeq->Value(i), aSeq->Value(i+1)); anEntry = theScript.SubString(aSeq->Value(i), aSeq->Value(i+1));
theObjListToPublish.Append( anEntry ); theObjListToPublish.Append( anEntry );
if (theObjectNames.IsBound(anEntry)) {
aName = theObjectNames.Find(anEntry); TObjectData& data = aEntry2ObjData[ anEntry ];
// check validity of aName if ( !data._name.IsEmpty() ) { // published object
bool isValidName = true; if ( data._pyName.IsEmpty() ) { // encounted for the 1st time
if ( aName.IsIntegerValue() ) { // aName must not start with a digit data._pyName = data._name;
aName.Insert( 1, 'a' ); healPyName( data._pyName, anEntry, aNameToEntry);
isValidName = false;
}
int p, p2=1; // replace not allowed chars
while ((p = aName.FirstLocationNotInSet(allowedChars, p2, aName.Length()))) {
aName.SetValue(p, '_');
p2=p;
isValidName = false;
}
if ( aNameToEntry.IsBound( aName ) && anEntry != aNameToEntry( aName ))
{ // diff objects have same name - make a new name by appending a digit
TCollection_AsciiString aName2;
Standard_Integer i = 0;
do {
aName2 = aName + "_" + ++i;
} while ( aNameToEntry.IsBound( aName2 ) && anEntry != aNameToEntry( aName2 ));
aName = aName2;
isValidName = false;
}
if ( !isValidName ) {
if ( theIsPublished )
theEntryToBadName.Bind( anEntry, theObjectNames.Find(anEntry) );
theObjectNames( anEntry ) = aName;
} }
} }
else { else {
do { do {
aName = aBaseName + TCollection_AsciiString(++objectCounter); data._pyName = aBaseName + TCollection_AsciiString(++objectCounter);
} while(aNameToEntry.IsBound(aName)); } while(aNameToEntry.IsBound(data._pyName));
theObjectNames.Bind(anEntry, aName);
} }
aNameToEntry.Bind(aName, anEntry); // to detect same name of diff objects aNameToEntry.Bind(data._pyName, anEntry); // to detect same name of diff objects
anUpdatedScript += aName; anUpdatedScript += data._pyName;
aStart = aSeq->Value(i+1) + 1; aStart = aSeq->Value(i+1) + 1;
} }
@ -1330,18 +1336,18 @@ void ReplaceEntriesByNames (TCollection_AsciiString& theScript,
//============================================================================= //=============================================================================
void AddObjectColors (int theDocID, void AddObjectColors (int theDocID,
TCollection_AsciiString& theScript, TCollection_AsciiString& theScript,
const Resource_DataMapOfAsciiStringAsciiString& theObjectNames) const TSting2ObjDataMap& theEntry2ObjData)
{ {
GEOM_Engine* engine = GEOM_Engine::GetEngine(); GEOM_Engine* engine = GEOM_Engine::GetEngine();
Handle(TDocStd_Document) aDoc = engine->GetDocument(theDocID); Handle(TDocStd_Document) aDoc = engine->GetDocument(theDocID);
Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString anEntryToNameIt; TSting2ObjDataMap::const_iterator anEntryToNameIt;
for (anEntryToNameIt.Initialize( theObjectNames ); for (anEntryToNameIt = theEntry2ObjData.begin();
anEntryToNameIt.More(); anEntryToNameIt!= theEntry2ObjData.end();
anEntryToNameIt.Next()) ++anEntryToNameIt)
{ {
const TCollection_AsciiString& aEntry = anEntryToNameIt.Key(); const TCollection_AsciiString& aEntry = anEntryToNameIt->first;
const TCollection_AsciiString& aName = anEntryToNameIt.Value(); const TCollection_AsciiString& aName = anEntryToNameIt->second._pyName;
TDF_Label L; TDF_Label L;
TDF_Tool::Label( aDoc->GetData(), aEntry, L ); TDF_Tool::Label( aDoc->GetData(), aEntry, L );
@ -1477,46 +1483,61 @@ void AddTextures (int theDocID, TCollection_AsciiString& theScript)
* PublishObject: publish object in study script * PublishObject: publish object in study script
*/ */
//============================================================================= //=============================================================================
void PublishObject (const TCollection_AsciiString& theEntry, void PublishObject (TObjectData& theObjectData,
const TCollection_AsciiString& theName, TSting2ObjDataMap& theEntry2ObjData,
const Resource_DataMapOfAsciiStringAsciiString& theObjectNames, const TSting2ObjDataPtrMap& theStEntry2ObjDataPtr,
const Resource_DataMapOfAsciiStringAsciiString& theEntry2StEntry, Resource_DataMapOfAsciiStringAsciiString& theNameToEntry,
const Resource_DataMapOfAsciiStringAsciiString& theStEntry2Entry, TSting2StringMap& theEntryToCmdMap,
const Resource_DataMapOfAsciiStringAsciiString& theEntryToBadName, std::set< TCollection_AsciiString>& theIgnoreMap)
std::map< int, std::string >& theEntryToCommandMap,
std::set<std::string>& theMapOfPublished)
{ {
if ( !theEntry2StEntry.IsBound( theEntry )) if ( theObjectData._studyEntry.IsEmpty() )
return; // was not published return; // was not published
if ( theMapOfPublished.count(theEntry.ToCString()) ) if ( theIgnoreMap.count( theObjectData._entry ) )
return; // aready published return; // not to publish
theMapOfPublished.insert( theEntry.ToCString() );
TCollection_AsciiString aCommand("\n\tgeompy."), aFatherEntry; TCollection_AsciiString aCommand("\n\tgeompy.");
// find a father entry // find a father entry
const TCollection_AsciiString& aStudyEntry = theEntry2StEntry( theEntry ); TObjectData* aFatherData = 0;
TCollection_AsciiString aFatherStudyEntry = TCollection_AsciiString aFatherStudyEntry =
aStudyEntry.SubString( 1, aStudyEntry.SearchFromEnd(":") - 1 ); theObjectData._studyEntry.SubString( 1, theObjectData._studyEntry.SearchFromEnd(":") - 1 );
if ( theStEntry2Entry.IsBound( aFatherStudyEntry )) TSting2ObjDataPtrMap::const_iterator stEntry2DataPtr =
aFatherEntry = theStEntry2Entry( aFatherStudyEntry ); theStEntry2ObjDataPtr.find( aFatherStudyEntry );
if ( stEntry2DataPtr != theStEntry2ObjDataPtr.end() )
aFatherData = stEntry2DataPtr->second;
// treat multiply published object
if ( theObjectData._pyName.IsEmpty() )
{
TObjectData& data0 = theEntry2ObjData[ theObjectData._entry ];
if ( data0._pyName.IsEmpty() ) return; // something wrong
theObjectData._pyName = theObjectData._name;
healPyName( theObjectData._pyName, theObjectData._entry, theNameToEntry);
TCollection_AsciiString aCreationCommand("\n\t");
aCreationCommand += theObjectData._pyName + " = " + data0._pyName;
// store aCreationCommand before publishing commands
TCollection_AsciiString mapKey(" ");
mapKey += theObjectData._studyEntry;
theEntryToCmdMap.insert( std::make_pair( mapKey, aCreationCommand ));
}
// make a command // make a command
if ( !aFatherEntry.IsEmpty() && theObjectNames.IsBound( aFatherEntry )) { if ( aFatherData && !aFatherData->_pyName.IsEmpty() ) {
aCommand += "addToStudyInFather( "; aCommand += "addToStudyInFather( ";
aCommand += theObjectNames( aFatherEntry ) + ", "; aCommand += aFatherData->_pyName + ", ";
} }
else else {
aCommand += "addToStudy( "; aCommand += "addToStudy( ";
if ( theEntryToBadName.IsBound( theEntry )) }
aCommand += theName + ", \"" + theEntryToBadName( theEntry ) + "\" )"; aCommand += theObjectData._pyName + ", '" + theObjectData._name + "' )";
else
aCommand += theName + ", \"" + theName + "\" )";
// bind a command to the last digit of the entry // bind a command to the study entry
int tag = theEntryToCmdMap.insert( std::make_pair( theObjectData._studyEntry, aCommand ));
theEntry.SubString( theEntry.SearchFromEnd(":")+1, theEntry.Length() ).IntegerValue();
theEntryToCommandMap.insert( std::make_pair( tag, aCommand.ToCString() )); theObjectData._studyEntry.Clear(); // not to publish any more
} }
//================================================================================ //================================================================================

View File

@ -37,6 +37,18 @@
#include <map> #include <map>
#include <list> #include <list>
#include <vector> #include <vector>
#include <string>
/*!
* \brief Data of GEOM_Object
*/
struct TObjectData
{
TCollection_AsciiString _entry;
TCollection_AsciiString _studyEntry;
TCollection_AsciiString _name;
TCollection_AsciiString _pyName;
};
class Handle_TDataStd_HArray1OfByte; class Handle_TDataStd_HArray1OfByte;
@ -124,7 +136,7 @@ class GEOM_Engine
bool isStandaloneOperation = false); bool isStandaloneOperation = false);
Standard_EXPORT TCollection_AsciiString DumpPython(int theDocID, Standard_EXPORT TCollection_AsciiString DumpPython(int theDocID,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames, std::vector<TObjectData>& theObjectData,
TVariablesList theVariables, TVariablesList theVariables,
bool isPublished, bool isPublished,
bool& aValidScript); bool& aValidScript);

View File

@ -53,7 +53,8 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
if(CORBA::is_nil(aSO)) if(CORBA::is_nil(aSO))
return new Engines::TMPFile(0); return new Engines::TMPFile(0);
Resource_DataMapOfAsciiStringAsciiString aMap; TObjectData objData;
std::vector<TObjectData> objectDataVec;
TVariablesList aVariableMap; TVariablesList aVariableMap;
@ -67,7 +68,11 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
if(!CORBA::is_nil(GO)) { if(!CORBA::is_nil(GO)) {
CORBA::String_var aName = aValue->GetName(); CORBA::String_var aName = aValue->GetName();
CORBA::String_var anEntry = GO->GetEntry(); CORBA::String_var anEntry = GO->GetEntry();
aMap.Bind( (char*)anEntry.in(), (char*)aName.in() ); CORBA::String_var aStudyEntry = aValue->GetID();
objData._name = aName.in();
objData._entry = anEntry.in();
objData._studyEntry = aStudyEntry.in();
objectDataVec.push_back( objData );
//Find attribute with list of used notebook variables //Find attribute with list of used notebook variables
SALOMEDS::GenericAttribute_var anAttr; SALOMEDS::GenericAttribute_var anAttr;
@ -86,14 +91,14 @@ Engines::TMPFile* GEOM_Gen_i::DumpPython(CORBA::Object_ptr theStudy,
} }
aStates->AddState(aState); aStates->AddState(aState);
} }
aVariableMap.insert(std::pair<TCollection_AsciiString,ObjectStates*>(TCollection_AsciiString(anEntry),aStates)); aVariableMap.insert(std::make_pair(TCollection_AsciiString(anEntry),aStates));
} }
} }
} }
} }
TCollection_AsciiString aScript; TCollection_AsciiString aScript;
aScript += _impl->DumpPython(aStudy->StudyId(), aMap, aVariableMap, isPublished, isValidScript); aScript += _impl->DumpPython(aStudy->StudyId(), objectDataVec, aVariableMap, isPublished, isValidScript);
if (isPublished) if (isPublished)
{ {