From: eap Date: Mon, 28 Mar 2005 08:08:52 +0000 (+0000) Subject: Dump Python. Add AddToCurrentPyScript(), AddArray(), AddObject() X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8661759d9c20f1083a76fdcf79d4cde4850e953f;p=modules%2Fsmesh.git Dump Python. Add AddToCurrentPyScript(), AddArray(), AddObject() --- diff --git a/src/SMESH_I/SMESH_Gen_i.hxx b/src/SMESH_I/SMESH_Gen_i.hxx index 09e460a54..97dd9b241 100644 --- a/src/SMESH_I/SMESH_Gen_i.hxx +++ b/src/SMESH_I/SMESH_Gen_i.hxx @@ -50,6 +50,7 @@ #include #include +#include class SMESH_Mesh_i; class SALOME_LifeCycleCORBA; @@ -277,12 +278,18 @@ public: return aResultSO._retn(); } + // ============ + // Dump python + // ============ + virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy, CORBA::Boolean isPublished, CORBA::Boolean& isValidScript); void AddToPythonScript (int theStudyID, const TCollection_AsciiString& theString); + static void AddToCurrentPyScript (const TCollection_AsciiString& theString); + void SavePython (SALOMEDS::Study_ptr theStudy); TCollection_AsciiString DumpPython_impl (int theStudyID, @@ -295,6 +302,29 @@ public: void CleanPythonTrace (int theStudyID); + // Dump python comfort methods + + static TCollection_AsciiString& AddObject(TCollection_AsciiString& theStr, + CORBA::Object_ptr theObject); + // add object to script string + + template + static TCollection_AsciiString& AddArray(TCollection_AsciiString& theStr, + const _array & array) + // put array contents into theStr like this: "[ 1, 2, 5 ]" + { + ostringstream sout; // can convert long int, and TCollection_AsciiString cant + sout << "[ "; + for (int i = 1; i <= array.length(); i++) { + sout << array[i-1]; + if ( i < array.length() ) + sout << ", "; + } + sout << " ]"; + theStr += (char*) sout.str().c_str(); + return theStr; + } + // ***************************************** // Internal methods // ***************************************** diff --git a/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx b/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx index a77f35967..cd2c578fc 100644 --- a/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx +++ b/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx @@ -80,6 +80,46 @@ void SMESH_Gen_i::AddToPythonScript (int theStudyID, const TCollection_AsciiStri myPythonScripts[theStudyID]->Append(theString); } +//======================================================================= +//function : AddToCurrentPyScript +//purpose : +//======================================================================= + +void SMESH_Gen_i::AddToCurrentPyScript (const TCollection_AsciiString& theString) +{ + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + aSMESHGen->AddToPythonScript(aSMESHGen->GetCurrentStudy()->StudyId(), theString); +} + + +//======================================================================= +//function : AddObject +//purpose : add object to script string +//======================================================================= + +TCollection_AsciiString& SMESH_Gen_i::AddObject(TCollection_AsciiString& theStr, + CORBA::Object_ptr theObject) +{ + GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( theObject ); + if ( !geomObj->_is_nil() ) { + theStr += "salome.IDToObject(\""; + theStr += geomObj->GetStudyEntry(); + theStr += "\")"; + } + else { + SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); + SALOMEDS::SObject_var aSO = + aSMESHGen->ObjectToSObject(aSMESHGen->GetCurrentStudy(), theObject); + if ( !aSO->_is_nil() ) + theStr += aSO->GetID(); + else if ( !CORBA::is_nil( theObject ) ) + theStr += aSMESHGen->GetORB()->object_to_string( theObject ); + else + theStr += "None"; + } + return theStr; +} + //======================================================================= //function : SavePython //purpose :