+ // NEW APPROACH
+ // 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;
+ Standard_Integer fromIndex = 6;
+ Standard_Integer cmdLen = cmdStr.Length();
+ if ( int pos = (fromIndex <= cmdLen) ? cmdStr.Location( SMESH::TVar::ObjPrefix(), fromIndex, cmdLen ) : 0 )
+ {
+ TCollection_AsciiString varHolderEntry =
+ cmdStr.SubString( pos + strlen( SMESH::TVar::ObjPrefix() ), cmdLen );
+ ent2varVec = _entry2VarsMap.find( varHolderEntry );
+ cmdStr.Split( pos - 1 );
+ }
+ else
+ {
+ ent2varVec = _entry2VarsMap.find( aObject );
+ }
+ // Set variables in cmdStr
+ if ( ent2varVec != _entry2VarsMap.end() && !ent2varVec->second.empty() )
+ {
+ 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
+ // Variable names are stored historically in "StringAttribute",
+ // i.e. for each command there is a set of either var names or separated empty places.
+