From 21a7cf3d64c8499394969d2e23ee63ccc7c39354 Mon Sep 17 00:00:00 2001 From: eap Date: Fri, 29 Mar 2013 13:35:25 +0000 Subject: [PATCH] 0051789: TC7.2.0: NoteBook cannot update study Fix for "LayerDistribution" hypothesis + // string preceding an entry of object storing the attribute holding var names + static const char* ObjPrefix() { return " # OBJ: "; } --- src/SMESH_I/SMESH_DumpPython.cxx | 5 ++++- src/SMESH_I/SMESH_NoteBook.cxx | 25 ++++++++++++++++++++++--- src/SMESH_I/SMESH_PythonDump.hxx | 2 ++ 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/src/SMESH_I/SMESH_DumpPython.cxx b/src/SMESH_I/SMESH_DumpPython.cxx index 0e3ae652f..15770dcc8 100644 --- a/src/SMESH_I/SMESH_DumpPython.cxx +++ b/src/SMESH_I/SMESH_DumpPython.cxx @@ -73,6 +73,9 @@ namespace SMESH SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy(); if(!aStudy->_is_nil() && !aCollection.IsEmpty()) { + const std::string & objEntry = SMESH_Gen_i::GetSMESHGen()->GetLastObjEntry(); + if ( !objEntry.empty() ) + aCollection += (TVar::ObjPrefix() + objEntry ).c_str(); aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection); if(MYDEBUG) MESSAGE(aString); // prevent misuse of already treated variables @@ -312,7 +315,7 @@ namespace SMESH if(aSObject->_is_nil() && !CORBA::is_nil(theArg)) myStream << "hyp_" << theArg->GetId(); else - *this << CORBA::Object_ptr( theArg ); + *this << aSObject; return *this; } diff --git a/src/SMESH_I/SMESH_NoteBook.cxx b/src/SMESH_I/SMESH_NoteBook.cxx index 19470f601..0168a96e7 100644 --- a/src/SMESH_I/SMESH_NoteBook.cxx +++ b/src/SMESH_I/SMESH_NoteBook.cxx @@ -250,11 +250,28 @@ void SMESH_NoteBook::ReplaceVariables() } // NEW APPROACH - - TEntry2VarVecMap::iterator ent2varVec = _entry2VarsMap.find( aObject ); + // Names of variables are stored in the Study, in "StringAttribute". Python commands + // store zero-based indices (as e.g.'$1$') of variables within "StringAttribute"; + // An entry of object storing "StringAttribute" is at the end of the command + // after TVar::ObjPrefix(). + + // Get the entry of object storing "StringAttribute" + TCollection_AsciiString & cmdStr = aCmd->GetString(); + TEntry2VarVecMap::iterator ent2varVec; + if (int pos = cmdStr.Location( SMESH::TVar::ObjPrefix(), 6, cmdStr.Length() )) + { + TCollection_AsciiString varHolderEntry = + cmdStr.SubString( pos + strlen( SMESH::TVar::ObjPrefix() ), cmdStr.Length() ); + ent2varVec = _entry2VarsMap.find( varHolderEntry ); + cmdStr.Split( pos - 1 ); + } + else + { + ent2varVec = _entry2VarsMap.find( aObject ); + } + // Set variables in cmdStr if ( ent2varVec != _entry2VarsMap.end() && !ent2varVec->second.empty() ) { - TCollection_AsciiString & cmdStr = aCmd->GetString(); const std::vector< std::string >& vars = ent2varVec->second; int pos = 1, pos2; // look for '$VarIndex$' in cmdStr. TVar::Quote() == '$' @@ -287,6 +304,8 @@ void SMESH_NoteBook::ReplaceVariables() } // OLD APPROACH + // Variable names are stored historically in "StringAttribute", + // i.e. for each command there is a set of either var names or separated empty places. // check if method modifies the object itself TVariablesMap::const_iterator it = _objectMap.find(aObject); diff --git a/src/SMESH_I/SMESH_PythonDump.hxx b/src/SMESH_I/SMESH_PythonDump.hxx index a78563c60..d1ba4f4ce 100644 --- a/src/SMESH_I/SMESH_PythonDump.hxx +++ b/src/SMESH_I/SMESH_PythonDump.hxx @@ -102,6 +102,8 @@ namespace SMESH // string used to temporary quote variable names in order // not to confuse variables with string arguments static char Quote() { return '$'; } + // string preceding an entry of object storing the attribute holding var names + static const char* ObjPrefix() { return " # OBJ: "; } }; // =========================================================================================== -- 2.39.2