X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_DumpPython.cxx;h=92506466cdbd268668025cb1c8106b4745bb1861;hp=a676b7a167ff3fc0fccd19fe5d5e4dc66f3f1582;hb=264eeb2edd6977ccf2d2bd88cbb210353f63f7c9;hpb=02ac54c6f33c5437c1d2204d704cf3da6fd31a8e diff --git a/src/SMESH_I/SMESH_DumpPython.cxx b/src/SMESH_I/SMESH_DumpPython.cxx index a676b7a16..92506466c 100644 --- a/src/SMESH_I/SMESH_DumpPython.cxx +++ b/src/SMESH_I/SMESH_DumpPython.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 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]); @@ -74,13 +74,12 @@ namespace SMESH SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); std::string aString = myStream.str(); TCollection_AsciiString aCollection(Standard_CString(aString.c_str())); - SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy(); - if(!aStudy->_is_nil() && !aCollection.IsEmpty()) + if(!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); + aSMESHGen->AddToPythonScript(aCollection); if(MYDEBUG) MESSAGE(aString); // prevent misuse of already treated variables aSMESHGen->UpdateParameters(CORBA::Object_var().in(),""); @@ -93,12 +92,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 +109,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 +161,13 @@ namespace SMESH return *this; } + TPythonDump& + TPythonDump:: + operator<<(const std::string& theArg){ + myStream<GetCurrentStudy(); - SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg); + SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg); if(!aSObject->_is_nil()) { CORBA::String_var id = aSObject->GetID(); myStream << id; @@ -329,8 +334,7 @@ namespace SMESH TPythonDump:: operator<<(SMESH::SMESH_Hypothesis_ptr theArg) { - SALOMEDS::Study_var aStudy = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy(); - SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg); + SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg); if(aSObject->_is_nil() && !CORBA::is_nil(theArg)) myStream << "hyp_" << theArg->GetId(); else @@ -345,8 +349,7 @@ namespace SMESH if ( CORBA::is_nil( theArg ) ) return *this << "None"; SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); - SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy(); - SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg); + SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg); if(!aSObject->_is_nil()) { return *this << aSObject; @@ -361,7 +364,7 @@ namespace SMESH SMESH::long_array_var anElementsId = theArg->GetIDs(); SMESH::array_of_ElementType_var types = theArg->GetTypes(); SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL; - SALOMEDS::SObject_wrap meshSO = SMESH_Gen_i::ObjectToSObject(aStudy,mesh); + SALOMEDS::SObject_wrap meshSO = SMESH_Gen_i::ObjectToSObject(mesh); if ( meshSO->_is_nil() ) // don't waste memory for dumping not published objects return *this << mesh << ".GetIDSource([], " << type << ")"; else @@ -423,6 +426,7 @@ namespace SMESH case FT_MultiConnection2D: myStream<< "aMultiConnection2D"; break; case FT_Length: myStream<< "aLength"; break; case FT_Length2D: myStream<< "aLength2D"; break; + case FT_NodeConnectivityNumber:myStream<< "aNodeConnectivityNumber";break; case FT_BelongToMeshGroup: myStream<< "aBelongToMeshGroup"; break; case FT_BelongToGeom: myStream<< "aBelongToGeom"; break; case FT_BelongToPlane: myStream<< "aBelongToPlane"; break; @@ -448,8 +452,8 @@ namespace SMESH case FT_LogicalNOT: myStream<< "aLogicalNOT"; break; case FT_LogicalAND: myStream<< "aLogicalAND"; break; case FT_LogicalOR: myStream<< "aLogicalOR"; break; - case FT_Undefined: - default: myStream<< "anUndefined"; break; + case FT_Undefined: myStream<< "anUndefined"; break; + //default: -- commented to have a compilation warning } myStream<Append(theString); + myPythonScript->Append(theString); } //============================================================================= @@ -787,11 +790,11 @@ void SMESH_Gen_i::AddToPythonScript (int theStudyID, const TCollection_AsciiStri * RemoveLastFromPythonScript */ //============================================================================= -void SMESH_Gen_i::RemoveLastFromPythonScript (int theStudyID) +void SMESH_Gen_i::RemoveLastFromPythonScript() { - if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) { - int aLen = myPythonScripts[theStudyID]->Length(); - myPythonScripts[theStudyID]->Remove(aLen); + if (!myPythonScript.IsNull()) { + int aLen = myPythonScript->Length(); + myPythonScript->Remove(aLen); } } @@ -799,15 +802,15 @@ void SMESH_Gen_i::RemoveLastFromPythonScript (int theStudyID) //function : SavePython //purpose : //======================================================================= -void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy) +void SMESH_Gen_i::SavePython() { // Dump trace of API methods calls - TCollection_AsciiString aScript = GetNewPythonLines(theStudy->StudyId()); + TCollection_AsciiString aScript = GetNewPythonLines(); // Check contents of PythonObject attribute CORBA::String_var compDataType = ComponentDataType(); - SALOMEDS::SObject_wrap aSO = theStudy->FindComponent( compDataType.in() ); - SALOMEDS::StudyBuilder_var aStudyBuilder = theStudy->NewBuilder(); + SALOMEDS::SObject_wrap aSO = getStudyServant()->FindComponent( compDataType.in() ); + SALOMEDS::StudyBuilder_var aStudyBuilder = getStudyServant()->NewBuilder(); SALOMEDS::GenericAttribute_wrap anAttr = aStudyBuilder->FindOrCreateAttribute(aSO, "AttributePythonObject"); @@ -827,7 +830,7 @@ void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy) pyAttr->SetObject(oldScript.ToCString(), 1); // Clean trace of API methods calls - CleanPythonTrace(theStudy->StudyId()); + CleanPythonTrace(); } @@ -971,7 +974,6 @@ namespace { //================================================================================ /*! * \brief Createa a Dump Python script - * \param [in] theStudy - the study to dump * \param [in,out] theObjectNames - map of an entry to a study and python name * \param [in] theNames - - map of an entry to a study name * \param [in] isPublished - \c true if dump of object publication in study is needed @@ -985,8 +987,7 @@ namespace { //================================================================================ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl - (SALOMEDS::Study_ptr theStudy, - Resource_DataMapOfAsciiStringAsciiString& theObjectNames, + (Resource_DataMapOfAsciiStringAsciiString& theObjectNames, Resource_DataMapOfAsciiStringAsciiString& theNames, bool isPublished, bool isMultiFile, @@ -995,7 +996,6 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl TCollection_AsciiString& theSavedTrace) { SMESH_TRY; - const int aStudyID = theStudy->StudyId(); const TCollection_AsciiString aSmeshpy ( SMESH_2smeshpy::SmeshpyName() ); const TCollection_AsciiString aSMESHGen( SMESH_2smeshpy::GenName() ); @@ -1007,9 +1007,9 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl std::list< TCollection_AsciiString >::iterator linesIt; if ( isPublished ) - lines.push_back( aSMESHGen + " = smeshBuilder.New(theStudy)" ); + lines.push_back( aSMESHGen + " = smeshBuilder.New()" ); else - lines.push_back( aSMESHGen + " = smeshBuilder.New(None)" ); + lines.push_back( aSMESHGen + " = smeshBuilder.New(False)" ); lines.push_back( helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" ); lines.push_back( helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()" ); @@ -1027,7 +1027,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl lines.push_back( theSavedTrace.SubString( from, to - 1 )); from = to + 1; } - // For the convertion of IDL API calls -> 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 = @@ -1055,9 +1055,9 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl } // Add new dump trace of API methods calls to script lines - if (myPythonScripts.find( aStudyID ) != myPythonScripts.end()) + if (!myPythonScript.IsNull()) { - Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScripts[ aStudyID ]; + Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript; Standard_Integer istr, aLen = aPythonScript->Length(); for (istr = 1; istr <= aLen; istr++) lines.push_back( aPythonScript->Value( istr )); @@ -1071,7 +1071,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl if ( !getenv("NO_2smeshpy_conversion")) SMESH_2smeshpy::ConvertScript( lines, anEntry2AccessorMethod, theObjectNames, aRemovedObjIDs, - theStudy, isHistoricalDump ); + isHistoricalDump ); bool importGeom = false; GEOM::GEOM_Gen_ptr geom = GetGeomEngine(); @@ -1179,9 +1179,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 { @@ -1207,8 +1209,8 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl initPart += importStr + "\n"; } - if( isMultiFile ) - initPart += "def RebuildData(theStudy):"; + if ( isMultiFile ) + initPart += "def RebuildData():"; initPart += "\n"; anUpdatedScript.Prepend( initPart ); @@ -1219,12 +1221,12 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl TCollection_AsciiString removeObjPart; if ( !mapRemoved.IsEmpty() ) { removeObjPart += nt + "## some objects were removed"; - removeObjPart += nt + "aStudyBuilder = theStudy.NewBuilder()"; + removeObjPart += nt + "aStudyBuilder = salome.myStudy.NewBuilder()"; Resource_DataMapIteratorOfDataMapOfAsciiStringAsciiString mapRemovedIt; for ( mapRemovedIt.Initialize( mapRemoved ); mapRemovedIt.More(); mapRemovedIt.Next() ) { aName = mapRemovedIt.Value(); // python name anEntry = mapRemovedIt.Key(); - removeObjPart += nt + "SO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR("; + removeObjPart += nt + "SO = salome.myStudy.FindObjectIOR(salome.myStudy.ConvertObjectToIOR("; removeObjPart += aName; // for object wrapped by class of smeshBuilder.py if ( anEntry2AccessorMethod.IsBound( anEntry ) ) @@ -1262,7 +1264,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl { //Output the script that sets up the visual parameters. CORBA::String_var compDataType = ComponentDataType(); - CORBA::String_var script = theStudy->GetDefaultScript( compDataType.in(), tab.ToCString() ); + CORBA::String_var script = getStudyServant()->GetDefaultScript( compDataType.in(), tab.ToCString() ); if ( script.in() && script.in()[0] ) { visualPropertiesPart += nt + "### Store presentation parameters of displayed objects\n"; visualPropertiesPart += script.in(); @@ -1271,8 +1273,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()" + "\n\texec('from '+re.sub('SMESH$','GEOM',thisModule)+' import * ')" + "\n\tSMESH_RebuildData()"; + } anUpdatedScript += "\n"; // no need now as we use 'tab' and 'nt' variables depending on isMultiFile @@ -1285,7 +1297,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 @@ -1348,13 +1360,13 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl * GetNewPythonLines */ //============================================================================= -TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines (int theStudyID) +TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines() { TCollection_AsciiString aScript; // Dump trace of API methods calls - if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) { - Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScripts[theStudyID]; + if (!myPythonScript.IsNull()) { + Handle(TColStd_HSequenceOfAsciiString) aPythonScript = myPythonScript; Standard_Integer istr, aLen = aPythonScript->Length(); for (istr = 1; istr <= aLen; istr++) { aScript += "\n"; @@ -1371,12 +1383,12 @@ TCollection_AsciiString SMESH_Gen_i::GetNewPythonLines (int theStudyID) * CleanPythonTrace */ //============================================================================= -void SMESH_Gen_i::CleanPythonTrace (int theStudyID) +void SMESH_Gen_i::CleanPythonTrace() { TCollection_AsciiString aScript; // Clean trace of API methods calls - if (myPythonScripts.find(theStudyID) != myPythonScripts.end()) { - myPythonScripts[theStudyID]->Clear(); + if (!myPythonScript.IsNull()) { + myPythonScript->Clear(); } }