mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-04-09 06:27:28 +05:00
Bug IPAL8742. Add comments into generated files of DumpPython
Bug IPAL8749. Make DumpPython() fail if a not published GEOM object encounters. Bug IPAL8752. Import GEOM script only if necessary Bug IPAL8747. Do not produce py names starting with digit
This commit is contained in:
parent
585fb7a063
commit
107c7b6d4b
@ -7,16 +7,23 @@
|
|||||||
#include "SMESH_PythonDump.hxx"
|
#include "SMESH_PythonDump.hxx"
|
||||||
#include "SMESH_Gen_i.hxx"
|
#include "SMESH_Gen_i.hxx"
|
||||||
#include "SMESH_Filter_i.hxx"
|
#include "SMESH_Filter_i.hxx"
|
||||||
|
#include "SALOMEDSImpl_Study.hxx"
|
||||||
|
|
||||||
#include <TColStd_HSequenceOfInteger.hxx>
|
#include <TColStd_HSequenceOfInteger.hxx>
|
||||||
#include <TCollection_AsciiString.hxx>
|
#include <TCollection_AsciiString.hxx>
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG_
|
#ifdef _DEBUG_
|
||||||
static int MYDEBUG = 0;
|
static int MYDEBUG = 0;
|
||||||
#else
|
#else
|
||||||
static int MYDEBUG = 0;
|
static int MYDEBUG = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static TCollection_AsciiString NotPublishedObjectName()
|
||||||
|
{
|
||||||
|
return "__NOT__Published__Object__";
|
||||||
|
}
|
||||||
|
|
||||||
namespace SMESH
|
namespace SMESH
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -130,16 +137,20 @@ namespace SMESH
|
|||||||
TPythonDump::
|
TPythonDump::
|
||||||
operator<<(CORBA::Object_ptr theArg)
|
operator<<(CORBA::Object_ptr theArg)
|
||||||
{
|
{
|
||||||
CORBA::String_var aString("None");
|
TCollection_AsciiString aString("None");
|
||||||
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
|
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
|
||||||
SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
|
SALOMEDS::Study_ptr aStudy = aSMESHGen->GetCurrentStudy();
|
||||||
SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
|
SALOMEDS::SObject_var aSObject = SMESH_Gen_i::ObjectToSObject(aStudy,theArg);
|
||||||
if(!aSObject->_is_nil()){
|
if(!aSObject->_is_nil()){
|
||||||
aString = aSObject->GetID();
|
aString = aSObject->GetID();
|
||||||
}else if(!CORBA::is_nil(theArg)){
|
}else if(!CORBA::is_nil(theArg)){
|
||||||
aString = SMESH_Gen_i::GetORB()->object_to_string(theArg);
|
aString = "smeshObj_";
|
||||||
|
if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object
|
||||||
|
aString += (int) theArg;
|
||||||
|
else
|
||||||
|
aString = NotPublishedObjectName();
|
||||||
}
|
}
|
||||||
myStream<<aString.in();
|
myStream<<aString.ToCString();
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,9 +316,9 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
|
|||||||
TCollection_AsciiString aSavedTrace (oldValue);
|
TCollection_AsciiString aSavedTrace (oldValue);
|
||||||
|
|
||||||
// Add trace of API methods calls and replace study entries by names
|
// Add trace of API methods calls and replace study entries by names
|
||||||
bool aValidScript;
|
TCollection_AsciiString aScript =
|
||||||
TCollection_AsciiString aScript = DumpPython_impl
|
SALOMEDSImpl_Study::GetDumpStudyComment("SMESH") + "\n\n" +
|
||||||
(aStudy->StudyId(), aMap, aMapNames, isPublished, aValidScript, aSavedTrace);
|
DumpPython_impl(aStudy->StudyId(), aMap, aMapNames, isPublished, isValidScript, aSavedTrace);
|
||||||
|
|
||||||
int aLen = aScript.Length();
|
int aLen = aScript.Length();
|
||||||
unsigned char* aBuffer = new unsigned char[aLen+1];
|
unsigned char* aBuffer = new unsigned char[aLen+1];
|
||||||
@ -315,7 +326,9 @@ Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
|
|||||||
|
|
||||||
CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
|
CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
|
||||||
Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
|
Engines::TMPFile_var aStreamFile = new Engines::TMPFile(aLen+1, aLen+1, anOctetBuf, 1);
|
||||||
isValidScript = aValidScript;
|
|
||||||
|
bool hasNotPublishedObjects = aScript.Location( NotPublishedObjectName(), 1, aLen);
|
||||||
|
isValidScript = isValidScript && !hasNotPublishedObjects;
|
||||||
|
|
||||||
return aStreamFile._retn();
|
return aStreamFile._retn();
|
||||||
}
|
}
|
||||||
@ -368,16 +381,20 @@ 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)
|
||||||
{
|
{
|
||||||
|
TCollection_AsciiString aString("None");
|
||||||
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
|
SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
|
||||||
SALOMEDS::SObject_var aSO =
|
SALOMEDS::SObject_var aSObject =
|
||||||
aSMESHGen->ObjectToSObject(aSMESHGen->GetCurrentStudy(), theObject);
|
aSMESHGen->ObjectToSObject(aSMESHGen->GetCurrentStudy(), theObject);
|
||||||
if ( !aSO->_is_nil() )
|
if ( !aSObject->_is_nil() ) {
|
||||||
theStr += aSO->GetID();
|
aString = aSObject->GetID();
|
||||||
else if ( !CORBA::is_nil( theObject ) )
|
} else if ( !CORBA::is_nil( theObject )) {
|
||||||
theStr += GetORB()->object_to_string( theObject );
|
aString = "smeshObj_";
|
||||||
else
|
if ( aSMESHGen->CanPublishInStudy( theObject )) // not published SMESH object
|
||||||
theStr += "None";
|
aString += (int) theObject;
|
||||||
|
else
|
||||||
|
aString = NotPublishedObjectName();
|
||||||
|
}
|
||||||
|
theStr += aString;
|
||||||
return theStr;
|
return theStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -474,19 +491,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
|
|||||||
const TCollection_AsciiString& theSavedTrace)
|
const TCollection_AsciiString& theSavedTrace)
|
||||||
{
|
{
|
||||||
TCollection_AsciiString aScript;
|
TCollection_AsciiString aScript;
|
||||||
aScript += "import salome\n";
|
aScript = "def RebuildData(theStudy):";
|
||||||
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 += "import re\n";
|
|
||||||
aScript += "sys.path.append( os.path.dirname(__file__) )\n";
|
|
||||||
aScript += "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",__name__)+\" import *\")\n\n";
|
|
||||||
|
|
||||||
aScript += "def RebuildData(theStudy):";
|
|
||||||
aScript += "\n\tsmesh = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"SMESH\")";
|
aScript += "\n\tsmesh = salome.lcc.FindOrLoadComponent(\"FactoryServer\", \"SMESH\")";
|
||||||
aScript += "\n\taFilterManager = smesh.CreateFilterManager()";
|
aScript += "\n\taFilterManager = smesh.CreateFilterManager()";
|
||||||
if ( isPublished )
|
if ( isPublished )
|
||||||
@ -529,6 +534,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
|
|||||||
theObjectNames.Bind(aName, "1");
|
theObjectNames.Bind(aName, "1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool importGeom = false;
|
||||||
for (Standard_Integer i = 1; i <= aLen; i += 2) {
|
for (Standard_Integer i = 1; i <= aLen; i += 2) {
|
||||||
anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i) - 1);
|
anUpdatedScript += aScript.SubString(aStart, aSeq->Value(i) - 1);
|
||||||
anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
|
anEntry = aScript.SubString(aSeq->Value(i), aSeq->Value(i + 1));
|
||||||
@ -539,6 +545,8 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
|
|||||||
if (theObjectNames.IsBound(anEntry)) {
|
if (theObjectNames.IsBound(anEntry)) {
|
||||||
// The Object is in Study
|
// The Object is in Study
|
||||||
aName = theObjectNames.Find(anEntry);
|
aName = theObjectNames.Find(anEntry);
|
||||||
|
if ( aName.IsIntegerValue() ) // aName must not start with a digit
|
||||||
|
aName.Insert( 1, 'a' );
|
||||||
if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) {
|
if (theObjectNames.IsBound(aName) && anEntry != theObjectNames(aName)) {
|
||||||
// diff objects have same name - make a new name
|
// diff objects have same name - make a new name
|
||||||
TCollection_AsciiString aName2;
|
TCollection_AsciiString aName2;
|
||||||
@ -560,11 +568,24 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
|
|||||||
}
|
}
|
||||||
theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
|
theObjectNames.Bind(aName, anEntry); // to detect same name of diff objects
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
importGeom = true;
|
||||||
|
}
|
||||||
anUpdatedScript += aName;
|
anUpdatedScript += aName;
|
||||||
aStart = aSeq->Value(i + 1) + 1;
|
aStart = aSeq->Value(i + 1) + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// set initial part of aSript
|
||||||
|
TCollection_AsciiString initPart = "import salome, SMESH, StdMeshers\n\n";
|
||||||
|
if ( importGeom )
|
||||||
|
{
|
||||||
|
initPart += ("import string, os, sys, re\n"
|
||||||
|
"sys.path.insert( 0, os.path.dirname(__file__) )\n"
|
||||||
|
"exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",__name__)+\" import *\")\n\n");
|
||||||
|
}
|
||||||
|
anUpdatedScript.Insert ( 1, initPart );
|
||||||
|
|
||||||
// add final part of aScript
|
// add final part of aScript
|
||||||
if (aSeq->Value(aLen) < aScriptLength)
|
if (aSeq->Value(aLen) < aScriptLength)
|
||||||
anUpdatedScript += aScript.SubString(aSeq->Value(aLen) + 1, aScriptLength);
|
anUpdatedScript += aScript.SubString(aSeq->Value(aLen) + 1, aScriptLength);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user