0051789: TC7.2.0: NoteBook cannot update study

Fix approach to storage of NoteBook variables.
Before the fix: names of variables are stored in PythonDump commands
and nothing is stored in the Study.
Problem: after variable removal, the PythonDump script becomes invalid.
Fix: names of variables are stored in the Study, PythonDump commands
store indices of variables within "StringAttribute".

class SMESH_Gen_i {
...
-  void UpdateParameters(/*CORBA::Object_ptr theObject,*/ const char* theParameters);
+  void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);

+  const std::vector< int >&  GetLastParamIndices() const;
+  std::vector< std::string > GetAllParameters(const std::string& theObjectEntry) const;
This commit is contained in:
eap 2013-03-28 15:23:34 +00:00
parent 44ce7a32cd
commit b3cac3834a
7 changed files with 256 additions and 138 deletions

View File

@ -71,26 +71,28 @@ namespace SMESH
std::string aString = myStream.str(); std::string aString = myStream.str();
TCollection_AsciiString aCollection(Standard_CString(aString.c_str())); TCollection_AsciiString aCollection(Standard_CString(aString.c_str()));
SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy(); SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
if(!aStudy->_is_nil() && !aCollection.IsEmpty()){ if(!aStudy->_is_nil() && !aCollection.IsEmpty())
{
aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection); aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection);
if(MYDEBUG) MESSAGE(aString); if(MYDEBUG) MESSAGE(aString);
aSMESHGen->UpdateParameters(""); // prevent misuse of already treated variables // prevent misuse of already treated variables
aSMESHGen->UpdateParameters(CORBA::Object_var().in(),"");
} }
} }
} }
TPythonDump& //!< to store a variable value TPythonDump& //!< store a variable value. Write either a value or '$varID$'
TPythonDump:: TPythonDump::
operator<<(const TVar& theVarValue) operator<<(const TVar& theVarValue)
{ {
const std::vector< std::string >& varNames = SMESH_Gen_i::GetSMESHGen()->GetLastParameters(); const std::vector< int >& varIDs = SMESH_Gen_i::GetSMESHGen()->GetLastParamIndices();
if ( theVarValue.myVals.size() != 1 ) if ( theVarValue.myVals.size() != 1 )
{ {
myStream << "[ "; myStream << "[ ";
for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i ) for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i )
{ {
if ( myVarsCounter < varNames.size() && !varNames[ myVarsCounter ].empty() ) if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
myStream << TVar::Quote() << varNames[ myVarsCounter ] << TVar::Quote(); myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
else else
myStream << theVarValue.myVals[i-1]; myStream << theVarValue.myVals[i-1];
if ( i < theVarValue.myVals.size() ) if ( i < theVarValue.myVals.size() )
@ -101,8 +103,8 @@ namespace SMESH
} }
else else
{ {
if ( myVarsCounter < varNames.size() && !varNames[ myVarsCounter ].empty() ) if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 )
myStream << TVar::Quote() << varNames[ myVarsCounter ] << TVar::Quote(); myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote();
else else
myStream << theVarValue.myVals[0]; myStream << theVarValue.myVals[0];
++myVarsCounter; ++myVarsCounter;
@ -657,7 +659,6 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
} }
// Get trace of restored study // Get trace of restored study
//SALOMEDS::SObject_wrap aSO = SMESH_Gen_i::ObjectToSObject(theStudy, _this());
SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
SALOMEDS::GenericAttribute_wrap anAttr = SALOMEDS::GenericAttribute_wrap anAttr =
aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject"); aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject");

View File

@ -571,10 +571,12 @@ public:
*/ */
SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo); SALOMEDS::SObject_ptr GetAlgoSO(const ::SMESH_Algo* algo);
void UpdateParameters(/*CORBA::Object_ptr theObject,*/ const char* theParameters); void UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters);
char* GetParameters(CORBA::Object_ptr theObject); char* GetParameters(CORBA::Object_ptr theObject);
char* ParseParameters(const char* theParameters); //char* ParseParameters(const char* theParameters);
const std::vector< int >& GetLastParamIndices() const { return myLastParamIndex; }
const std::vector< std::string >& GetLastParameters() const { return myLastParameters; } const std::vector< std::string >& GetLastParameters() const { return myLastParameters; }
std::vector< std::string > GetAllParameters(const std::string& theObjectEntry) const;
private: private:
// Create hypothesis of given type // Create hypothesis of given type
@ -620,6 +622,7 @@ private:
// Dump Python: trace of API methods calls // Dump Python: trace of API methods calls
std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts; std::map < int, Handle(TColStd_HSequenceOfAsciiString) > myPythonScripts;
bool myIsHistoricalPythonDump; bool myIsHistoricalPythonDump;
std::vector< int > myLastParamIndex;
std::vector< std::string > myLastParameters; std::vector< std::string > myLastParameters;
}; };

View File

@ -935,16 +935,27 @@ bool SMESH_Gen_i::RemoveHypothesisFromShape(SALOMEDS::Study_ptr theStudy
return true; return true;
} }
//======================================================================= //================================================================================
//function : UpdateParameters /*!
//purpose : * \brief Stores names of variables that WILL be passes as parameters when calling
//======================================================================= * some method of a given object.
void SMESH_Gen_i::UpdateParameters(/*CORBA::Object_ptr theObject,*/ const char* theParameters) * \param [in] theObject - the object whose a method WILL be called with \a theParameters.
* \param [in] theParameters - a string contating parameters separated by ':'.
*/
//================================================================================
void SMESH_Gen_i::UpdateParameters(CORBA::Object_ptr theObject, const char* theParameters)
{ {
SALOMEDS::Study_var aStudy = GetCurrentStudy(); SALOMEDS::Study_var aStudy = GetCurrentStudy();
if ( aStudy->_is_nil() ) if ( aStudy->_is_nil() )
return; return;
// find variable names within theParameters
myLastParameters.clear(); myLastParameters.clear();
myLastParamIndex.clear(); /* vector holding indices of virables within the string
of all varibles used for theObject */
int nbVars = 0;
int pos = 0, prevPos = 0, len = strlen( theParameters ); int pos = 0, prevPos = 0, len = strlen( theParameters );
if ( len == 0 ) return; if ( len == 0 ) return;
while ( pos <= len ) while ( pos <= len )
@ -953,10 +964,11 @@ void SMESH_Gen_i::UpdateParameters(/*CORBA::Object_ptr theObject,*/ const char*
{ {
if ( prevPos < pos ) if ( prevPos < pos )
{ {
string val(theParameters + prevPos, theParameters + pos ); string val( theParameters + prevPos, theParameters + pos );
if ( !aStudy->IsVariable( val.c_str() )) if ( !aStudy->IsVariable( val.c_str() ))
val.clear(); val.clear();
myLastParameters.push_back( val ); myLastParameters.push_back( val );
nbVars += (! myLastParameters.back().empty() );
} }
else else
{ {
@ -966,123 +978,179 @@ void SMESH_Gen_i::UpdateParameters(/*CORBA::Object_ptr theObject,*/ const char*
} }
++pos; ++pos;
} }
return;
// OLD VARIANT if ( nbVars < 1 )
return;
// if(VARIABLE_DEBUG) // store
// cout<<"UpdateParameters : "<<theParameters<<endl; // (1) variable names in the string of all varibles used for theObject and
// //SALOMEDS::Study_var aStudy = GetCurrentStudy(); // (2) indices of found variables in myLastParamIndex.
// if(aStudy->_is_nil() || CORBA::is_nil(theObject))
// return;
// SALOMEDS::SObject_wrap aSObj = ObjectToSObject(aStudy,theObject); SALOMEDS::SObject_wrap aSObj = ObjectToSObject(aStudy,theObject);
// if(aSObj->_is_nil()) if ( aSObj->_is_nil() )
// return; return;
// SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder(); // get a string of variable names
SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
SALOMEDS::GenericAttribute_wrap anAttr =
aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
CORBA::String_var oldVars = aStringAttr->Value();
std::string varStr = oldVars.in();
// SALOMEDS::GenericAttribute_var aFindAttr; // add new variables and find indices of variables
// bool hasAttr = aSObj->FindAttribute(aFindAttr, "AttributeString"); for ( size_t i = 0; i < myLastParameters.size(); ++i )
// if(VARIABLE_DEBUG) {
// cout<<"Find Attribute "<<hasAttr<<endl; int varIndex = -1;
if ( !myLastParameters[i].empty() )
{
// find index of myLastParameters[i] in varStr
int curIndex = 0;
bool varFound = false;
size_t pos = 0;
// varStr can be "A|B::C;*=2|D"
const std::string separators(":|;*=");
while ( pos < varStr.size() && !varFound )
{
// skip separators
while ( separators.find( varStr[ pos ]) != std::string::npos )
if ( ++pos >= varStr.size() )
break;
// skip repetition number following '='
if ( varStr[ pos-1 ] == '=' )
{
while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
++pos;
continue; // to skip next separator
}
// compare variable name
if ( pos < varStr.size() )
{
varFound = ( varStr.compare( pos, myLastParameters[i].size(), myLastParameters[i] ) == 0 &&
// same string begining but is length same?
( pos + myLastParameters[i].size() >= varStr.size() ||
separators.find( varStr[ pos+1 ]) != std::string::npos ));
if ( varFound )
varIndex = curIndex;
else
pos = varStr.find_first_of( separators, pos ); // goto the next separator
++curIndex;
}
}
// add new variable
if ( !varFound )
{
varStr += ":" + myLastParameters[i];
varIndex = curIndex;
}
}
myLastParamIndex.push_back( varIndex );
}
aStringAttr->SetValue( varStr.c_str() );
}
// SALOMEDS::GenericAttribute_var anAttr; //================================================================================
// anAttr = aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString"); /*!
// SALOMEDS::AttributeString_var aStringAttr = SALOMEDS::AttributeString::_narrow(anAttr); * \brief Return all variables used to create an object
* \param [in] theObjectEntry - an object entry in the current study
* \return std::vector< std::string > - all variable names (or values of removed variables)
*/
//================================================================================
// CORBA::String_var oldparVar = aStringAttr->Value(); std::vector< std::string > SMESH_Gen_i::GetAllParameters(const std::string& theObjectEntry) const
// CORBA::String_var inpparVar = ParseParameters(theParameters); {
// TCollection_AsciiString aNewParams; std::vector< std::string > varNames;
// TCollection_AsciiString aOldParameters(oldparVar.inout()); if ( myCurrentStudy->_is_nil() )
// TCollection_AsciiString anInputParams(inpparVar.inout()); return varNames;
// if(!hasAttr)
// aNewParams = anInputParams;
// else
// {
// int pos = aOldParameters.SearchFromEnd("|");
// if(pos==-1) pos = 0;
// TCollection_AsciiString previousParamFull(aOldParameters.Split(pos));
// TCollection_AsciiString previousParam(previousParamFull);
// TCollection_AsciiString theRepet("1");
// pos = previousParam.SearchFromEnd(";*=");
// if(pos >= 0)
// {
// theRepet = previousParam.Split(pos+2);
// pos = pos-1;
// if(pos==-1) pos = 0;
// previousParam.Split(pos);
// }
// if(previousParam == anInputParams)
// {
// theRepet = theRepet.IntegerValue()+1;
// aNewParams = aOldParameters + previousParam + ";*=" + theRepet;
// }
// else
// {
// aNewParams = aOldParameters + previousParamFull + "|" + anInputParams;
// }
// }
// if(VARIABLE_DEBUG) SALOMEDS::SObject_wrap aSObj = myCurrentStudy->FindObjectID( theObjectEntry.c_str() );
// { if ( myCurrentStudy->_is_nil() )
// cout<<"Input Parameters : "<<anInputParams<<endl; return varNames;
// cout<<"Old Parameters : "<<aOldParameters<<endl;
// cout<<"New Parameters : "<<aNewParams<<endl;
// }
// aStringAttr->SetValue( aNewParams.ToCString() ); // get a string of variable names
SALOMEDS::StudyBuilder_var aStudyBuilder = myCurrentStudy->NewBuilder();
SALOMEDS::GenericAttribute_wrap anAttr =
aStudyBuilder->FindOrCreateAttribute( aSObj, "AttributeString" );
SALOMEDS::AttributeString_wrap aStringAttr = anAttr;
CORBA::String_var oldVars = aStringAttr->Value();
std::string varStr = oldVars.in();
// separate variables within varStr;
// varStr can be "A|B::C;*=2|D"
size_t pos = 0;
const std::string separators(":|;*=");
while ( pos < varStr.size() )
{
// skip separators
while ( separators.find( varStr[ pos ]) != std::string::npos )
if ( ++pos >= varStr.size() )
break;
// skip repetition number following '='
if ( varStr[ pos-1 ] == '=' )
{
while ( '0' <= varStr[ pos ] && varStr[ pos ] <= '9' )
++pos;
continue; // to skip next separator
}
// store variable name
if ( pos < varStr.size() )
{
size_t pos2 = varStr.find_first_of( separators, pos );
varNames.push_back( varStr.substr( pos, pos2-1 ));
pos = pos2;
}
}
return varNames;
} }
//======================================================================= //=======================================================================
//function : ParseParameters //function : ParseParameters
//purpose : Replace variables by their values //purpose : Replace variables by their values
//======================================================================= //=======================================================================
char* SMESH_Gen_i::ParseParameters(const char* theParameters) // char* SMESH_Gen_i::ParseParameters(const char* theParameters)
{ // {
//const char* aParameters = theParameters; // //const char* aParameters = theParameters;
// const char* aParameters = CORBA::string_dup(theParameters); // // const char* aParameters = CORBA::string_dup(theParameters);
TCollection_AsciiString anInputParams; // TCollection_AsciiString anInputParams;
SALOMEDS::Study_var aStudy = GetCurrentStudy(); // SALOMEDS::Study_var aStudy = GetCurrentStudy();
if( !aStudy->_is_nil() ) { // if( !aStudy->_is_nil() ) {
// SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters); // // SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(theParameters);
// for(int j=0;j<aSections->length();j++) { // // for(int j=0;j<aSections->length();j++) {
// SALOMEDS::ListOfStrings aVars= aSections[j]; // // SALOMEDS::ListOfStrings aVars= aSections[j];
// for(int i=0;i<aVars.length();i++ ) { // // for(int i=0;i<aVars.length();i++ ) {
// anInputParams += aStudy->IsVariable(aVars[i].in()) ? // // anInputParams += aStudy->IsVariable(aVars[i].in()) ?
// TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString(""); // // TCollection_AsciiString(aVars[i].in()) : TCollection_AsciiString("");
// if(i != aVars.length()-1) // // if(i != aVars.length()-1)
// anInputParams+=":"; // // anInputParams+=":";
// // }
// // if(j!=aSections->length()-1)
// // anInputParams+="|";
// // }
// TCollection_AsciiString paramStr( theParameters );
// int beg = 0, end;
// char sep, *pParams = (char*)paramStr.ToCString();
// while ( beg < paramStr.Length() )
// {
// end = beg-1;
// while ( ++end < paramStr.Length() )
// if ( pParams[end] == ':' || pParams[end] == '|')
// break;
// if ( end < paramStr.Length())
// {
// sep = pParams[end];
// pParams[end] = '\0';
// } // }
// if(j!=aSections->length()-1) // if ( aStudy->IsVariable( pParams+beg ))
// anInputParams+="|"; // anInputParams += pParams+beg;
// if ( end < paramStr.Length() )
// anInputParams += sep;
// else
// break;
// beg = end + 1;
// } // }
TCollection_AsciiString paramStr( theParameters ); // }
static TCollection_AsciiString separators(":|"); // return CORBA::string_dup(anInputParams.ToCString());
int beg = 0, end; // }
char sep, *pParams = (char*)paramStr.ToCString();
while ( beg < paramStr.Length() )
{
end = beg-1;
while ( ++end < paramStr.Length() )
if ( pParams[end] == ':' || pParams[end] == '|')
break;
if ( end < paramStr.Length())
{
sep = pParams[end];
pParams[end] = '\0';
}
if ( aStudy->IsVariable( pParams+beg ))
anInputParams += pParams+beg;
if ( end < paramStr.Length() )
anInputParams += sep;
else
break;
beg = end + 1;
}
}
return CORBA::string_dup(anInputParams.ToCString());
}
//======================================================================= //=======================================================================
//function : GetParameters //function : GetParameters

View File

@ -153,7 +153,7 @@ void SMESH_Hypothesis_i::SetVarParameter (const char* theParameter,
{ {
if ( SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen() ) if ( SMESH_Gen_i *gen = SMESH_Gen_i::GetSMESHGen() )
{ {
gen->UpdateParameters(theParameter); gen->UpdateParameters( CORBA::Object_var( _this() ).in(), theParameter );
const std::vector< std::string >& pars = gen->GetLastParameters(); const std::vector< std::string >& pars = gen->GetLastParameters();
if ( !pars.empty() ) if ( !pars.empty() )
@ -201,7 +201,7 @@ void SMESH_Hypothesis_i::setOldParameters (const char* theParameters)
if ( pos >= 0 ) aOldParameters = aOldParameters.Split(pos); if ( pos >= 0 ) aOldParameters = aOldParameters.Split(pos);
pos = aOldParameters.SearchFromEnd(";*="); pos = aOldParameters.SearchFromEnd(";*=");
if ( pos >= 0 ) aOldParameters.Split(pos-1); if ( pos >= 0 ) aOldParameters.Split(pos-1);
gen->UpdateParameters( aOldParameters.ToCString() ); gen->UpdateParameters( CORBA::Object_var( _this() ).in(), aOldParameters.ToCString() );
myMethod2VarParams.clear(); myMethod2VarParams.clear();
const std::vector< std::string >& pars = gen->GetLastParameters(); const std::vector< std::string >& pars = gen->GetLastParameters();
@ -210,7 +210,7 @@ void SMESH_Hypothesis_i::setOldParameters (const char* theParameters)
std::string meth = getMethodOfParameter( i, pars.size() ); std::string meth = getMethodOfParameter( i, pars.size() );
myMethod2VarParams[ meth ] = pars[i]; myMethod2VarParams[ meth ] = pars[i];
} }
gen->UpdateParameters(""); // clear params gen->UpdateParameters( CORBA::Object_var( _this() ).in(), "" ); // clear params
} }
} }

View File

@ -4285,9 +4285,8 @@ void SMESH_Mesh_i::checkGroupNames()
//============================================================================= //=============================================================================
void SMESH_Mesh_i::SetParameters(const char* theParameters) void SMESH_Mesh_i::SetParameters(const char* theParameters)
{ {
// SMESH_Gen_i::GetSMESHGen()->UpdateParameters(SMESH::SMESH_Mesh::_narrow(_this()), SMESH_Gen_i::GetSMESHGen()->UpdateParameters( CORBA::Object_var( _this() ).in(),
// CORBA::string_dup(theParameters)); theParameters );
SMESH_Gen_i::GetSMESHGen()->UpdateParameters(theParameters);
} }
//============================================================================= //=============================================================================

View File

@ -236,10 +236,11 @@ SMESH_NoteBook::~SMESH_NoteBook()
//================================================================================ //================================================================================
void SMESH_NoteBook::ReplaceVariables() void SMESH_NoteBook::ReplaceVariables()
{ {
for(int i=0;i<_commands.size();i++) { for(int i=0;i<_commands.size();i++)
{
Handle(_pyCommand) aCmd = _commands[i]; Handle(_pyCommand) aCmd = _commands[i];
TCollection_AsciiString aMethod = aCmd->GetMethod(); TCollection_AsciiString aMethod = aCmd->GetMethod();
TCollection_AsciiString aObject = aCmd->GetObject(); TCollection_AsciiString aObject = aCmd->GetObject();
TCollection_AsciiString aResultValue = aCmd->GetResultValue(); TCollection_AsciiString aResultValue = aCmd->GetResultValue();
if(MYDEBUG) { if(MYDEBUG) {
cout<<"Command before : "<< aCmd->GetString()<<endl; cout<<"Command before : "<< aCmd->GetString()<<endl;
@ -248,14 +249,53 @@ void SMESH_NoteBook::ReplaceVariables()
cout<<"Result : "<< aResultValue<<endl; cout<<"Result : "<< aResultValue<<endl;
} }
// NEW APPROACH
TEntry2VarVecMap::iterator ent2varVec = _entry2VarsMap.find( aObject );
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() == '$'
while (( pos = cmdStr.Location( 1, SMESH::TVar::Quote(), pos, cmdStr.Length() )) &&
( pos2 = cmdStr.Location( 1, SMESH::TVar::Quote(), pos+1, cmdStr.Length() )) )
{
size_t varIndex = std::string::npos;
const char* varIndexPtr = cmdStr.ToCString() + pos;
if ( '0' <= *varIndexPtr && *varIndexPtr <= '9' )
varIndex = atoi( varIndexPtr );
if ( 0 <= varIndex && varIndex < vars.size() && !vars[varIndex].empty() )
{
// replace '$VarIndex$' either by var name of var value
const char var0 = vars[varIndex][0];
const bool isValue = (( '0' <= var0 && var0 <= '9' ) || var0 == '-');
if ( isValue ) // remove TVar::Quote() as well
pos2 += 2; // pos still points to '$'
int indexLen = pos2 - pos - 1;
int lenDiff = int( vars[varIndex].size() ) - indexLen;
if ( lenDiff > 0 )
cmdStr.InsertBefore( pos2, vars[varIndex].c_str() + vars[varIndex].size() - lenDiff );
else if ( lenDiff < 0 )
cmdStr.Remove( pos+1, -lenDiff );
cmdStr.SetValue( pos+(!isValue), vars[varIndex].c_str() );
}
pos = pos2 + 1;
if ( pos + 2 >= cmdStr.Length() )
break;
}
}
// OLD APPROACH
// check if method modifies the object itself // check if method modifies the object itself
TVariablesMap::const_iterator it = _objectMap.find(aObject); TVariablesMap::const_iterator it = _objectMap.find(aObject);
if(it == _objectMap.end()) // check if method returns a new object if(it == _objectMap.end()) // check if method returns a new object
it = _objectMap.find(aResultValue); it = _objectMap.find(aResultValue);
if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor if(it == _objectMap.end()) { // check if method modifies a mesh using mesh editor
TMeshEditorMap::const_iterator meIt = myMeshEditors.find(aObject); TMeshEditorMap::const_iterator meIt = _meshEditors.find(aObject);
if(meIt != myMeshEditors.end()) { if(meIt != _meshEditors.end()) {
TCollection_AsciiString aMesh = (*meIt).second; TCollection_AsciiString aMesh = (*meIt).second;
it = _objectMap.find(aMesh); it = _objectMap.find(aMesh);
} }
@ -694,7 +734,6 @@ void SMESH_NoteBook::InitObjectMap()
return; return;
SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO); SALOMEDS::ChildIterator_wrap Itr = aStudy->NewChildIterator(aSO);
CORBA::String_var aParameters;
for( Itr->InitEx(true); Itr->More(); Itr->Next()) for( Itr->InitEx(true); Itr->More(); Itr->Next())
{ {
SALOMEDS::SObject_wrap aSObject = Itr->Value(); SALOMEDS::SObject_wrap aSObject = Itr->Value();
@ -702,12 +741,15 @@ void SMESH_NoteBook::InitObjectMap()
if ( aSObject->FindAttribute( anAttr.inout(), "AttributeString")) if ( aSObject->FindAttribute( anAttr.inout(), "AttributeString"))
{ {
SALOMEDS::AttributeString_wrap strAttr = anAttr; SALOMEDS::AttributeString_wrap strAttr = anAttr;
aParameters = strAttr->Value(); CORBA::String_var aParameters = strAttr->Value();
CORBA::String_var anID = aSObject->GetID();
std::vector< std::string > allVars = aGen->GetAllParameters( anID.in() );
SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters.in()); SALOMEDS::ListOfListOfStrings_var aSections = aStudy->ParseVariables(aParameters.in());
_entry2VarsMap[ TCollection_AsciiString( anID.in() )] = allVars;
if(MYDEBUG) { if(MYDEBUG) {
cout<<"Entry : "<< aSObject->GetID()<<endl; cout<<"Entry : "<< anID<<endl;
cout<<"aParameters : "<<aParameters<<endl; cout<<"aParameters : "<<aParameters<<endl;
} }
TCollection_AsciiString anObjType; TCollection_AsciiString anObjType;
CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject); CORBA::Object_var anObject = SMESH_Gen_i::SObjectToObject(aSObject);
SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject); SMESH::SMESH_Hypothesis_var aHyp = SMESH::SMESH_Hypothesis::_narrow(anObject);
@ -770,8 +812,8 @@ void SMESH_NoteBook::AddCommand(const TCollection_AsciiString& theString)
_commands.push_back(aCommand); _commands.push_back(aCommand);
if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation
myMeshEditors.insert( make_pair( aCommand->GetResultValue(), _meshEditors.insert( make_pair( aCommand->GetResultValue(),
aCommand->GetObject() ) ); aCommand->GetObject() ) );
} }
} }

View File

@ -84,8 +84,7 @@ private:
class SMESH_NoteBook class SMESH_NoteBook
{ {
public: public:
typedef std::map<TCollection_AsciiString,SMESH_ObjectStates*> TVariablesMap;
typedef std::map<TCollection_AsciiString,TCollection_AsciiString> TMeshEditorMap;
SMESH_NoteBook(); SMESH_NoteBook();
~SMESH_NoteBook(); ~SMESH_NoteBook();
void ReplaceVariables(); void ReplaceVariables();
@ -94,6 +93,7 @@ public:
TCollection_AsciiString GetResultScript() const; TCollection_AsciiString GetResultScript() const;
private: private:
void InitObjectMap(); void InitObjectMap();
void ProcessLayerDistribution(); void ProcessLayerDistribution();
@ -101,9 +101,14 @@ private:
private: private:
TVariablesMap _objectMap; typedef std::map<TCollection_AsciiString,SMESH_ObjectStates*> TVariablesMap;
typedef std::map<TCollection_AsciiString,TCollection_AsciiString> TMeshEditorMap;
typedef std::map<TCollection_AsciiString,std::vector< std::string > > TEntry2VarVecMap;
TVariablesMap _objectMap; // old approach - full states are kept
TEntry2VarVecMap _entry2VarsMap; // new approach - only var names are kept
std::vector<Handle(_pyCommand)> _commands; std::vector<Handle(_pyCommand)> _commands;
TMeshEditorMap myMeshEditors; TMeshEditorMap _meshEditors;
}; };
#endif //SMESH_NoteBook_HeaderFile #endif //SMESH_NoteBook_HeaderFile