From d795ab09594cab099d650f04d24ef5d59141229e Mon Sep 17 00:00:00 2001 From: eap Date: Tue, 29 Mar 2005 09:27:31 +0000 Subject: [PATCH] "Dump Python". Import Geom mudule in s script; fix for work without a study --- src/SMESH_I/SMESH_Gen_i.cxx | 75 ++++++++++++++------------ src/SMESH_I/SMESH_Gen_i_DumpPython.cxx | 57 ++++++++++++-------- 2 files changed, 74 insertions(+), 58 deletions(-) diff --git a/src/SMESH_I/SMESH_Gen_i.cxx b/src/SMESH_I/SMESH_Gen_i.cxx index 46802b695..313496a15 100644 --- a/src/SMESH_I/SMESH_Gen_i.cxx +++ b/src/SMESH_I/SMESH_Gen_i.cxx @@ -474,16 +474,17 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypNam // Publish hypothesis/algorithm in the study if ( CanPublishInStudy( hyp ) ) { SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, hyp ); + if ( !aSO->_is_nil() ) { + // Update Python script + TCollection_AsciiString aStr (aSO->GetID()); + aStr += " = smesh.CreateHypothesis(\""; + aStr += Standard_CString(theHypName); + aStr += "\", \""; + aStr += Standard_CString(theLibName); + aStr += "\")"; - // Update Python script - TCollection_AsciiString aStr (aSO->GetID()); - aStr += " = smesh.CreateHypothesis(\""; - aStr += Standard_CString(theHypName); - aStr += "\", \""; - aStr += Standard_CString(theLibName); - aStr += "\")"; - - AddToPythonScript(myCurrentStudy->StudyId(), aStr); + AddToCurrentPyScript(aStr); + } } return hyp._retn(); @@ -512,13 +513,14 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMesh( GEOM::GEOM_Object_ptr theShapeObj // publish mesh in the study if ( CanPublishInStudy( mesh ) ) { SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() ); - - // Update Python script - TCollection_AsciiString aStr (aSO->GetID()); - aStr += " = smesh.CreateMesh("; - SMESH_Gen_i::AddObject(aStr, theShapeObject) += ")"; - - AddToPythonScript(myCurrentStudy->StudyId(), aStr); + if ( !aSO->_is_nil() ) { + // Update Python script + TCollection_AsciiString aStr (aSO->GetID()); + aStr += " = smesh.CreateMesh("; + SMESH_Gen_i::AddObject(aStr, theShapeObject) += ")"; + + AddToCurrentPyScript(aStr); + } } return mesh._retn(); @@ -543,14 +545,15 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName // publish mesh in the study if ( CanPublishInStudy( aMesh ) ) { SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() ); + if ( !aSO->_is_nil() ) { + // Update Python script + TCollection_AsciiString aStr (aSO->GetID()); + aStr += " = smesh.CreateMeshesFromUNV(\""; + aStr += Standard_CString(theFileName); + aStr += "\")"; - // Update Python script - TCollection_AsciiString aStr (aSO->GetID()); - aStr += " = smesh.CreateMeshesFromUNV(\""; - aStr += Standard_CString(theFileName); - aStr += "\")"; - - AddToPythonScript(myCurrentStudy->StudyId(), aStr); + AddToCurrentPyScript(aStr); + } } SMESH_Mesh_i* aServant = dynamic_cast( GetServant( aMesh ).in() ); @@ -598,9 +601,10 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName, SMESH::SMESH_Mesh_var mesh = createMesh(); // publish mesh in the study - if ( CanPublishInStudy( mesh ) ) { - SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() ); - + SALOMEDS::SObject_var aSO; + if ( CanPublishInStudy( mesh ) ) + aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() ); + if ( !aSO->_is_nil() ) { // Python Dump aStr += aSO->GetID(); } else { @@ -626,7 +630,7 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName, aStr += Standard_CString(theFileName); aStr += "\")"; - AddToPythonScript(myCurrentStudy->StudyId(), aStr); + AddToCurrentPyScript(aStr); return aResult._retn(); } @@ -651,14 +655,15 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName if ( CanPublishInStudy( aMesh ) ) { SALOMEDS::SObject_var aSO = PublishInStudy ( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() ); - + if ( !aSO->_is_nil() ) { // Update Python script - TCollection_AsciiString aStr (aSO->GetID()); - aStr += " = smesh.CreateMeshesFromSTL(\""; - aStr += Standard_CString(theFileName); - aStr += "\")"; + TCollection_AsciiString aStr (aSO->GetID()); + aStr += " = smesh.CreateMeshesFromSTL(\""; + aStr += Standard_CString(theFileName); + aStr += "\")"; - AddToPythonScript(myCurrentStudy->StudyId(), aStr); + AddToCurrentPyScript(aStr); + } } SMESH_Mesh_i* aServant = dynamic_cast( GetServant( aMesh ).in() ); @@ -811,11 +816,11 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh, SMESH_Gen_i::AddObject(aStr, theMesh) += ", "; SMESH_Gen_i::AddObject(aStr, theShapeObject) += ")"; - AddToPythonScript(myCurrentStudy->StudyId(), aStr); + AddToCurrentPyScript(aStr); aStr = "if isDone == 0: print \"Mesh "; SMESH_Gen_i::AddObject(aStr, theMesh) += " computation failed\""; - AddToPythonScript(myCurrentStudy->StudyId(), aStr); + AddToCurrentPyScript(aStr); try { // get mesh servant diff --git a/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx b/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx index 9e5f3ed9f..36ec9b1a0 100644 --- a/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx +++ b/src/SMESH_I/SMESH_Gen_i_DumpPython.cxx @@ -117,23 +117,16 @@ void SMESH_Gen_i::AddToCurrentPyScript (const TCollection_AsciiString& theString 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"; - } + 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 += GetORB()->object_to_string( theObject ); + else + theStr += "None"; + return theStr; } @@ -233,9 +226,22 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl aScript += "import geompy\n\n"; aScript += "import SMESH\n"; aScript += "import StdMeshers\n\n"; + aScript += "#import GEOM module\n"; + aScript += "import string\n"; + aScript += "import os\n"; + aScript += "import sys\n"; + aScript += "sys.path.append( os.path.dirname(__file__) )\n"; + aScript += "exec(\"from \"+string.replace(__name__,\"SMESH\",\"GEOM\")+\" import *\")\n\n"; + aScript += "def RebuildData(theStudy):"; aScript += "\n\tsmesh = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"SMESH\")"; - aScript += "\n\tsmesh.SetCurrentStudy(theStudy)"; + if ( isPublished ) + aScript += "\n\tsmesh.SetCurrentStudy(theStudy)"; + else + aScript += "\n\tsmesh.SetCurrentStudy(None)"; + + Standard_Integer posToInertGlobalVars = aScript.Length(); + TCollection_AsciiString globalVars; // Dump trace of restored study if (theSavedTrace.Length() > 0) { @@ -258,6 +264,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl return aScript; // Replace entries by the names + GEOM::GEOM_Gen_ptr geom = GetGeomEngine(); TColStd_SequenceOfAsciiString seqRemoved; Resource_DataMapOfAsciiStringAsciiString mapRemoved; Resource_DataMapOfAsciiStringAsciiString aNames; @@ -280,13 +287,17 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl theObjectNames(anEntry) = aName; } } else { + // is a GEOM object? + aName = geom->GetDumpName( anEntry.ToCString() ); + if ( aName.IsEmpty() ) { // ? Removed Object ? - do { - aName = aBaseName + TCollection_AsciiString(++objectCounter); - } while (theObjectNames.IsBound(aName)); + do { + aName = aBaseName + TCollection_AsciiString(++objectCounter); + } while (theObjectNames.IsBound(aName)); + seqRemoved.Append(aName); + mapRemoved.Bind(anEntry, "1"); + } theObjectNames.Bind(anEntry, aName); - seqRemoved.Append(aName); - mapRemoved.Bind(anEntry, "1"); } theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects