mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-04-12 12:07:28 +05:00
"Dump Python". Import Geom mudule in s script; fix for work without a study
This commit is contained in:
parent
17d6338a7e
commit
d795ab0959
@ -474,16 +474,17 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypNam
|
|||||||
// Publish hypothesis/algorithm in the study
|
// Publish hypothesis/algorithm in the study
|
||||||
if ( CanPublishInStudy( hyp ) ) {
|
if ( CanPublishInStudy( hyp ) ) {
|
||||||
SALOMEDS::SObject_var aSO = PublishHypothesis( myCurrentStudy, 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
|
AddToCurrentPyScript(aStr);
|
||||||
TCollection_AsciiString aStr (aSO->GetID());
|
}
|
||||||
aStr += " = smesh.CreateHypothesis(\"";
|
|
||||||
aStr += Standard_CString(theHypName);
|
|
||||||
aStr += "\", \"";
|
|
||||||
aStr += Standard_CString(theLibName);
|
|
||||||
aStr += "\")";
|
|
||||||
|
|
||||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return hyp._retn();
|
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
|
// publish mesh in the study
|
||||||
if ( CanPublishInStudy( mesh ) ) {
|
if ( CanPublishInStudy( mesh ) ) {
|
||||||
SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
|
SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in() );
|
||||||
|
if ( !aSO->_is_nil() ) {
|
||||||
// Update Python script
|
// Update Python script
|
||||||
TCollection_AsciiString aStr (aSO->GetID());
|
TCollection_AsciiString aStr (aSO->GetID());
|
||||||
aStr += " = smesh.CreateMesh(";
|
aStr += " = smesh.CreateMesh(";
|
||||||
SMESH_Gen_i::AddObject(aStr, theShapeObject) += ")";
|
SMESH_Gen_i::AddObject(aStr, theShapeObject) += ")";
|
||||||
|
|
||||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
AddToCurrentPyScript(aStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return mesh._retn();
|
return mesh._retn();
|
||||||
@ -543,14 +545,15 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromUNV( const char* theFileName
|
|||||||
// publish mesh in the study
|
// publish mesh in the study
|
||||||
if ( CanPublishInStudy( aMesh ) ) {
|
if ( CanPublishInStudy( aMesh ) ) {
|
||||||
SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, aMesh.in(), aFileName.c_str() );
|
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
|
AddToCurrentPyScript(aStr);
|
||||||
TCollection_AsciiString aStr (aSO->GetID());
|
}
|
||||||
aStr += " = smesh.CreateMeshesFromUNV(\"";
|
|
||||||
aStr += Standard_CString(theFileName);
|
|
||||||
aStr += "\")";
|
|
||||||
|
|
||||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
|
SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
|
||||||
@ -598,9 +601,10 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
|
|||||||
SMESH::SMESH_Mesh_var mesh = createMesh();
|
SMESH::SMESH_Mesh_var mesh = createMesh();
|
||||||
|
|
||||||
// publish mesh in the study
|
// publish mesh in the study
|
||||||
if ( CanPublishInStudy( mesh ) ) {
|
SALOMEDS::SObject_var aSO;
|
||||||
SALOMEDS::SObject_var aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
|
if ( CanPublishInStudy( mesh ) )
|
||||||
|
aSO = PublishMesh( myCurrentStudy, mesh.in(), (*it).c_str() );
|
||||||
|
if ( !aSO->_is_nil() ) {
|
||||||
// Python Dump
|
// Python Dump
|
||||||
aStr += aSO->GetID();
|
aStr += aSO->GetID();
|
||||||
} else {
|
} else {
|
||||||
@ -626,7 +630,7 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMED( const char* theFileName,
|
|||||||
aStr += Standard_CString(theFileName);
|
aStr += Standard_CString(theFileName);
|
||||||
aStr += "\")";
|
aStr += "\")";
|
||||||
|
|
||||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
AddToCurrentPyScript(aStr);
|
||||||
|
|
||||||
return aResult._retn();
|
return aResult._retn();
|
||||||
}
|
}
|
||||||
@ -651,14 +655,15 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName
|
|||||||
if ( CanPublishInStudy( aMesh ) ) {
|
if ( CanPublishInStudy( aMesh ) ) {
|
||||||
SALOMEDS::SObject_var aSO = PublishInStudy
|
SALOMEDS::SObject_var aSO = PublishInStudy
|
||||||
( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
|
( myCurrentStudy, SALOMEDS::SObject::_nil(), aMesh.in(), aFileName.c_str() );
|
||||||
|
if ( !aSO->_is_nil() ) {
|
||||||
// Update Python script
|
// Update Python script
|
||||||
TCollection_AsciiString aStr (aSO->GetID());
|
TCollection_AsciiString aStr (aSO->GetID());
|
||||||
aStr += " = smesh.CreateMeshesFromSTL(\"";
|
aStr += " = smesh.CreateMeshesFromSTL(\"";
|
||||||
aStr += Standard_CString(theFileName);
|
aStr += Standard_CString(theFileName);
|
||||||
aStr += "\")";
|
aStr += "\")";
|
||||||
|
|
||||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
AddToCurrentPyScript(aStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( GetServant( aMesh ).in() );
|
SMESH_Mesh_i* aServant = dynamic_cast<SMESH_Mesh_i*>( 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, theMesh) += ", ";
|
||||||
SMESH_Gen_i::AddObject(aStr, theShapeObject) += ")";
|
SMESH_Gen_i::AddObject(aStr, theShapeObject) += ")";
|
||||||
|
|
||||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
AddToCurrentPyScript(aStr);
|
||||||
|
|
||||||
aStr = "if isDone == 0: print \"Mesh ";
|
aStr = "if isDone == 0: print \"Mesh ";
|
||||||
SMESH_Gen_i::AddObject(aStr, theMesh) += " computation failed\"";
|
SMESH_Gen_i::AddObject(aStr, theMesh) += " computation failed\"";
|
||||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
AddToCurrentPyScript(aStr);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// get mesh servant
|
// get mesh servant
|
||||||
|
@ -117,23 +117,16 @@ void SMESH_Gen_i::AddToCurrentPyScript (const TCollection_AsciiString& theString
|
|||||||
TCollection_AsciiString& SMESH_Gen_i::AddObject(TCollection_AsciiString& theStr,
|
TCollection_AsciiString& SMESH_Gen_i::AddObject(TCollection_AsciiString& theStr,
|
||||||
CORBA::Object_ptr theObject)
|
CORBA::Object_ptr theObject)
|
||||||
{
|
{
|
||||||
GEOM::GEOM_Object_var geomObj = GEOM::GEOM_Object::_narrow( theObject );
|
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
|
||||||
if ( !geomObj->_is_nil() ) {
|
SALOMEDS::SObject_var aSO =
|
||||||
theStr += "salome.IDToObject(\"";
|
aSMESHGen->ObjectToSObject(aSMESHGen->GetCurrentStudy(), theObject);
|
||||||
theStr += geomObj->GetStudyEntry();
|
if ( !aSO->_is_nil() )
|
||||||
theStr += "\")";
|
theStr += aSO->GetID();
|
||||||
}
|
else if ( !CORBA::is_nil( theObject ) )
|
||||||
else {
|
theStr += GetORB()->object_to_string( theObject );
|
||||||
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
|
else
|
||||||
SALOMEDS::SObject_var aSO =
|
theStr += "None";
|
||||||
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;
|
return theStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,9 +226,22 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
|
|||||||
aScript += "import geompy\n\n";
|
aScript += "import geompy\n\n";
|
||||||
aScript += "import SMESH\n";
|
aScript += "import SMESH\n";
|
||||||
aScript += "import StdMeshers\n\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 += "def RebuildData(theStudy):";
|
||||||
aScript += "\n\tsmesh = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"SMESH\")";
|
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
|
// Dump trace of restored study
|
||||||
if (theSavedTrace.Length() > 0) {
|
if (theSavedTrace.Length() > 0) {
|
||||||
@ -258,6 +264,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
|
|||||||
return aScript;
|
return aScript;
|
||||||
|
|
||||||
// Replace entries by the names
|
// Replace entries by the names
|
||||||
|
GEOM::GEOM_Gen_ptr geom = GetGeomEngine();
|
||||||
TColStd_SequenceOfAsciiString seqRemoved;
|
TColStd_SequenceOfAsciiString seqRemoved;
|
||||||
Resource_DataMapOfAsciiStringAsciiString mapRemoved;
|
Resource_DataMapOfAsciiStringAsciiString mapRemoved;
|
||||||
Resource_DataMapOfAsciiStringAsciiString aNames;
|
Resource_DataMapOfAsciiStringAsciiString aNames;
|
||||||
@ -280,13 +287,17 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
|
|||||||
theObjectNames(anEntry) = aName;
|
theObjectNames(anEntry) = aName;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// is a GEOM object?
|
||||||
|
aName = geom->GetDumpName( anEntry.ToCString() );
|
||||||
|
if ( aName.IsEmpty() ) {
|
||||||
// ? Removed Object ?
|
// ? Removed Object ?
|
||||||
do {
|
do {
|
||||||
aName = aBaseName + TCollection_AsciiString(++objectCounter);
|
aName = aBaseName + TCollection_AsciiString(++objectCounter);
|
||||||
} while (theObjectNames.IsBound(aName));
|
} while (theObjectNames.IsBound(aName));
|
||||||
|
seqRemoved.Append(aName);
|
||||||
|
mapRemoved.Bind(anEntry, "1");
|
||||||
|
}
|
||||||
theObjectNames.Bind(anEntry, aName);
|
theObjectNames.Bind(anEntry, aName);
|
||||||
seqRemoved.Append(aName);
|
|
||||||
mapRemoved.Bind(anEntry, "1");
|
|
||||||
}
|
}
|
||||||
theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
|
theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user