X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_DumpPython.cxx;h=38864d1ac4d9db08b96cf3cefcb6e058f6397d03;hb=95a77fcb020f1b1aebf6939093a446c8acbcf649;hp=013824fc8ed01552084021f5fadd20341e4e32e0;hpb=56793b53d1b42075b688ac58dbd418c5f901fb8f;p=modules%2Fsmesh.git diff --git a/src/SMESH_I/SMESH_DumpPython.cxx b/src/SMESH_I/SMESH_DumpPython.cxx index 013824fc8..38864d1ac 100644 --- a/src/SMESH_I/SMESH_DumpPython.cxx +++ b/src/SMESH_I/SMESH_DumpPython.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -51,8 +51,17 @@ namespace SMESH size_t TPythonDump::myCounter = 0; + TVar::TVar(CORBA::Double value):myVals(1) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(CORBA::Long value):myVals(1) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(CORBA::Short value):myVals(1) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(const SMESH::double_array& value):myVals(value.length()) + { + for ( size_t i = 0; i < value.length(); i++) + myVals[i] = SMESH_Comment(value[i]); + } + TPythonDump:: - TPythonDump() + TPythonDump():myVarsCounter(0) { ++myCounter; } @@ -67,10 +76,44 @@ namespace SMESH if(!aStudy->_is_nil() && !aCollection.IsEmpty()){ aSMESHGen->AddToPythonScript(aStudy->StudyId(),aCollection); if(MYDEBUG) MESSAGE(aString); + aSMESHGen->UpdateParameters(""); // prevent misuse of already treated variables } } } + TPythonDump& //!< to store a variable value + TPythonDump:: + operator<<(const TVar& theVarValue) + { + if ( theVarValue.myVals.empty() ) return *this; + + const std::vector< std::string >& varNames = SMESH_Gen_i::GetSMESHGen()->GetLastParameters(); + if ( theVarValue.myVals.size() > 1 ) + { + myStream << "[ "; + for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i ) + { + if ( myVarsCounter < varNames.size() && !varNames[ myVarsCounter ].empty() ) + myStream << TVar::Quote() << varNames[ myVarsCounter ] << TVar::Quote(); + else + myStream << theVarValue.myVals[i-1]; + if ( i < theVarValue.myVals.size() ) + myStream << ", "; + ++myVarsCounter; + } + myStream << " ]"; + } + else + { + if ( myVarsCounter < varNames.size() && !varNames[ myVarsCounter ].empty() ) + myStream << TVar::Quote() << varNames[ myVarsCounter ] << TVar::Quote(); + else + myStream << theVarValue.myVals[0]; + ++myVarsCounter; + } + return *this; + } + TPythonDump& TPythonDump:: operator<<(long int theArg){ @@ -178,6 +221,19 @@ namespace SMESH return *this; } + TPythonDump& + TPythonDump::operator<<(const SMESH::string_array& theArray) + { + myStream << "[ "; + for (int i = 1; i <= theArray.length(); i++) { + myStream << "'" << theArray[i-1] << "'"; + if ( i < theArray.length() ) + myStream << ", "; + } + myStream << " ]"; + return *this; + } + TPythonDump& TPythonDump:: operator<<(SALOMEDS::SObject_ptr aSObject) @@ -362,23 +418,32 @@ namespace SMESH TPythonDump& TPythonDump::operator<<(const SMESH::AxisStruct & theAxis) { - myStream << "SMESH.AxisStruct( " - << theAxis.x << ", " - << theAxis.y << ", " - << theAxis.z << ", " - << theAxis.vx << ", " - << theAxis.vy << ", " - << theAxis.vz << " )"; + *this << "SMESH.AxisStruct( " + << TVar( theAxis.x ) << ", " + << TVar( theAxis.y ) << ", " + << TVar( theAxis.z ) << ", " + << TVar( theAxis.vx ) << ", " + << TVar( theAxis.vy ) << ", " + << TVar( theAxis.vz ) << " )"; return *this; } TPythonDump& TPythonDump::operator<<(const SMESH::DirStruct & theDir) { const SMESH::PointStruct & P = theDir.PS; - myStream << "SMESH.DirStruct( SMESH.PointStruct ( " - << P.x << ", " - << P.y << ", " - << P.z << " ))"; + *this << "SMESH.DirStruct( SMESH.PointStruct ( " + << TVar( P.x ) << ", " + << TVar( P.y ) << ", " + << TVar( P.z ) << " ))"; + return *this; + } + + TPythonDump& TPythonDump::operator<<(const SMESH::PointStruct & P) + { + *this << "SMESH.PointStruct ( " + << TVar( P.x ) << ", " + << TVar( P.y ) << ", " + << TVar( P.z ) << " )"; return *this; } @@ -558,8 +623,8 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy, // Add trace of API methods calls and replace study entries by names TCollection_AsciiString aScript; - aScript += DumpPython_impl(aStudy, aMap, aMapNames, - isPublished, isMultiFile, isValidScript, aSavedTrace); + aScript += DumpPython_impl(aStudy, aMap, aMapNames, isPublished, isMultiFile, + myIsHistoricalPythonDump, isValidScript, aSavedTrace); int aLen = aScript.Length(); unsigned char* aBuffer = new unsigned char[aLen+1]; @@ -695,20 +760,28 @@ namespace { const TCollection_AsciiString allowedChars = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM0987654321_"; bool isValidName = true; - int p=1; // replace not allowed chars with underscore + int nbUnderscore = 0; + int p=1; // replace not allowed chars by underscore while (p <= aName.Length() && (p = aName.FirstLocationNotInSet(allowedChars, p, aName.Length()))) { if ( p == 1 || p == aName.Length() || aName.Value(p-1) == '_') - aName.Remove( p, 1 ); // remove double _ and from the start and the end + aName.Remove( p, 1 ); // remove double _ from the start and the end else - aName.SetValue(p, '_'); + aName.SetValue(p, '_'), nbUnderscore++; isValidName = false; } if ( aName.IsIntegerValue() ) { // aName must not start with a digit aName.Insert( 1, 'a' ); isValidName = false; } + // shorten names like CartesianParameters3D_400_400_400_1000000_1 + if ( aName.Length() > 20 && nbUnderscore > 2 ) + { + p = aName.Location( "_", 20, aName.Length()); + if ( p > 1 ) + aName.Trunc( p-1 ); + } return isValidName; } } @@ -724,6 +797,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl Resource_DataMapOfAsciiStringAsciiString& theNames, bool isPublished, bool isMultiFile, + bool isHistoricalDump, bool& aValidScript, const TCollection_AsciiString& theSavedTrace) { @@ -791,13 +865,22 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl // Some objects are wrapped with python classes and // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod; - aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod, theObjectNames ); + if ( !getenv("NO_2smeshpy_conversion")) + aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod, + theObjectNames, theStudy, isHistoricalDump ); + + // Replace characters used instead of quote marks to quote notebook variables + { + int pos = 1; + while (( pos = aScript.Location( 1, SMESH::TVar::Quote(), pos, aScript.Length() ))) + aScript.SetValue( pos, '"' ); + } // Find entries to be replaced by names Handle(TColStd_HSequenceOfInteger) aSeq = FindEntries(aScript); Standard_Integer aLen = aSeq->Length(); - if (aLen == 0) + if (aLen == 0 && isMultiFile) return aScript; // Replace entries by the names @@ -807,7 +890,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl Standard_Integer objectCounter = 0, aStart = 1, aScriptLength = aScript.Length(); TCollection_AsciiString anUpdatedScript, anEntry, aName, aBaseName("smeshObj_"); - // Collect names of GEOM objects to exclude same names for SMESH objects + // Collect names of GEOM objects to exclude same names of SMESH objects GEOM::string_array_var aGeomNames = geom->GetAllDumpNames(); int ign = 0, nbgn = aGeomNames->length(); for (; ign < nbgn; ign++) { @@ -875,7 +958,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl anUpdatedScript.Insert ( 1, initPart ); // add final part of aScript - if (aSeq->Value(aLen) < aScriptLength) + if (aLen && aSeq->Value(aLen) < aScriptLength) anUpdatedScript += aScript.SubString(aSeq->Value(aLen) + 1, aScriptLength); // Remove removed objects