mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2024-12-26 17:30:35 +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,7 +474,7 @@ 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(\"";
|
||||
@ -483,7 +483,8 @@ SMESH::SMESH_Hypothesis_ptr SMESH_Gen_i::CreateHypothesis( const char* theHypNam
|
||||
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() );
|
||||
|
||||
if ( !aSO->_is_nil() ) {
|
||||
// Update Python script
|
||||
TCollection_AsciiString aStr (aSO->GetID());
|
||||
aStr += " = smesh.CreateMesh(";
|
||||
SMESH_Gen_i::AddObject(aStr, theShapeObject) += ")";
|
||||
|
||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
||||
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 += "\")";
|
||||
|
||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
||||
AddToCurrentPyScript(aStr);
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
// 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 += "\")";
|
||||
|
||||
AddToPythonScript(myCurrentStudy->StudyId(), aStr);
|
||||
AddToCurrentPyScript(aStr);
|
||||
}
|
||||
}
|
||||
|
||||
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, 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
|
||||
|
@ -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 );
|
||||
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\")";
|
||||
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,14 +287,18 @@ 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));
|
||||
theObjectNames.Bind(anEntry, aName);
|
||||
seqRemoved.Append(aName);
|
||||
mapRemoved.Bind(anEntry, "1");
|
||||
}
|
||||
theObjectNames.Bind(anEntry, aName);
|
||||
}
|
||||
theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
|
||||
|
||||
anUpdatedScript += aName;
|
||||
|
Loading…
Reference in New Issue
Block a user