X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_DumpPython.cxx;h=19c46da07fb5bd186afa1a98303547d8ecf23b39;hp=494722b8aee4837c73bfe0e7c9939e93aede4662;hb=ccb5e3c25bf204e839c0094f50f543eacedba5e6;hpb=5d68554076bbca0e1e95fb0db215a6c2b84b6c54 diff --git a/src/SMESH_I/SMESH_DumpPython.cxx b/src/SMESH_I/SMESH_DumpPython.cxx index 494722b8a..19c46da07 100644 --- a/src/SMESH_I/SMESH_DumpPython.cxx +++ b/src/SMESH_I/SMESH_DumpPython.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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 @@ -53,10 +53,10 @@ namespace SMESH size_t TPythonDump::myCounter = 0; const char theNotPublishedObjectName[] = "__NOT__Published__Object__"; - 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()) + TVar::TVar(CORBA::Double value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(CORBA::Long value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(CORBA::Short value):myVals(1), myIsList(false) { myVals[0] = SMESH_Comment(value); } + TVar::TVar(const SMESH::double_array& value):myVals(value.length()), myIsList(true) { for ( size_t i = 0; i < value.length(); i++) myVals[i] = SMESH_Comment(value[i]); @@ -93,12 +93,12 @@ namespace SMESH operator<<(const TVar& theVarValue) { const std::vector< int >& varIDs = SMESH_Gen_i::GetSMESHGen()->GetLastParamIndices(); - if ( theVarValue.myVals.size() != 1 ) + if ( theVarValue.myIsList ) { myStream << "[ "; for ( size_t i = 1; i <= theVarValue.myVals.size(); ++i ) { - if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 ) + if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 ) myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote(); else myStream << theVarValue.myVals[i-1]; @@ -110,7 +110,7 @@ namespace SMESH } else { - if ( myVarsCounter < varIDs.size() && varIDs[ myVarsCounter ] >= 0 ) + if ( myVarsCounter < (int)varIDs.size() && varIDs[ myVarsCounter ] >= 0 ) myStream << TVar::Quote() << varIDs[ myVarsCounter ] << TVar::Quote(); else myStream << theVarValue.myVals[0]; @@ -162,6 +162,13 @@ namespace SMESH return *this; } + TPythonDump& + TPythonDump:: + operator<<(const std::string& theArg){ + myStream< smeshBuilder.py API, "smesh" standing for SMESH_Gen + // For the conversion of IDL API calls -> smeshBuilder.py API, "smesh" standing for SMESH_Gen // was replaces with "smeshgen" (==TPythonDump::SMESHGenName()). // Change "smesh" -> "smeshgen" in the trace saved before passage to smeshBuilder.py API bool isNewVersion = @@ -1145,9 +1199,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl if ( importGeom && isMultiFile ) { initPart += ("\n## import GEOM dump file ## \n" - "import string, os, sys, re\n" - "sys.path.insert( 0, os.path.dirname(__file__) )\n" - "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",__name__)+\" import *\")\n"); + "import string, os, sys, re, inspect\n" + "thisFile = inspect.getfile( inspect.currentframe() )\n" + "thisModule = os.path.splitext( os.path.basename( thisFile ))[0]\n" + "sys.path.insert( 0, os.path.dirname( thisFile ))\n" + "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",thisModule)+\" import *\")\n\n"); } // import python files corresponding to plugins if they are used in anUpdatedScript { @@ -1173,7 +1229,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl initPart += importStr + "\n"; } - if( isMultiFile ) + if ( isMultiFile ) initPart += "def RebuildData(theStudy):"; initPart += "\n"; @@ -1209,6 +1265,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl if ( theNames.IsBound( anEntry )) { aGUIName = theNames.Find(anEntry); + aGUIName.RemoveAll('\''); // remove a quote from a name (issue 22360) setNamePart += nt + aSMESHGen + ".SetName(" + aName; if ( anEntry2AccessorMethod.IsBound( anEntry ) ) setNamePart += helper + "." + anEntry2AccessorMethod( anEntry ); @@ -1236,8 +1293,18 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl anUpdatedScript += removeObjPart + '\n' + setNamePart + '\n' + visualPropertiesPart; - if( isMultiFile ) - anUpdatedScript += "\n\tpass"; + if ( isMultiFile ) + { + anUpdatedScript += + "\n\tpass" + "\n" + "\nif __name__ == '__main__':" + "\n\tSMESH_RebuildData = RebuildData" + "\n\texec('import '+re.sub('SMESH$','GEOM',thisModule)+' as GEOM_dump')" + "\n\tGEOM_dump.RebuildData( salome.myStudy )" + "\n\texec('from '+re.sub('SMESH$','GEOM',thisModule)+' import * ')" + "\n\tSMESH_RebuildData( salome.myStudy )"; + } anUpdatedScript += "\n"; // no need now as we use 'tab' and 'nt' variables depending on isMultiFile @@ -1250,7 +1317,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl TCollection_AsciiString aLongString, aFunctionType; int where = 1; - set< string > functionNameSet; + std::set< std::string > functionNameSet; while ( SMESH::TPythonDump::CutoutLongString( anUpdatedScript, where, aLongString, aFunctionType )) { // make a python string literal