san 2013-03-19 11:48:47 +00:00
parent 93dd4f94d8
commit 7e185db056
4 changed files with 107 additions and 44 deletions

View File

@ -153,6 +153,24 @@ namespace {
void CheckObjectPresence( const Handle(_pyCommand)& cmd, set<_pyID> & presentObjects) void CheckObjectPresence( const Handle(_pyCommand)& cmd, set<_pyID> & presentObjects)
{ {
// either comment or erase a command including NotPublishedObjectName()
if ( cmd->GetString().Location( TPythonDump::NotPublishedObjectName(), 1, cmd->Length() ))
{
bool isResultPublished = false;
for ( int i = 0; i < cmd->GetNbResultValues(); i++ )
{
_pyID objID = cmd->GetResultValue( i+1 );
if ( cmd->IsStudyEntry( objID ))
isResultPublished = (! theGen->IsNotPublished( objID ));
theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
}
if ( isResultPublished )
cmd->Comment();
else
cmd->Clear();
return;
}
// comment a command having not created args
for ( int iArg = cmd->GetNbArgs(); iArg; --iArg ) for ( int iArg = cmd->GetNbArgs(); iArg; --iArg )
{ {
const _pyID& arg = cmd->GetArg( iArg ); const _pyID& arg = cmd->GetArg( iArg );
@ -166,14 +184,23 @@ namespace {
cmd->Comment(); cmd->Comment();
cmd->GetString() += " ### " ; cmd->GetString() += " ### " ;
cmd->GetString() += *id + " has not been yet created"; cmd->GetString() += *id + " has not been yet created";
for ( int i = 0; i < cmd->GetNbResultValues(); i++ ) {
_pyID objID = cmd->GetResultValue( i+1 );
theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
}
return; return;
} }
} }
// comment a command having not created Object
const _pyID& obj = cmd->GetObject(); const _pyID& obj = cmd->GetObject();
if ( !obj.IsEmpty() && cmd->IsStudyEntry( obj ) && !presentObjects.count( obj )) if ( !obj.IsEmpty() && cmd->IsStudyEntry( obj ) && !presentObjects.count( obj ))
{ {
cmd->Comment(); cmd->Comment();
cmd->GetString() += " ### not created object" ; cmd->GetString() += " ### not created object" ;
for ( int i = 0; i < cmd->GetNbResultValues(); i++ ) {
_pyID objID = cmd->GetResultValue( i+1 );
theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed
}
} }
const _pyID& result = cmd->GetResultValue(); const _pyID& result = cmd->GetResultValue();
if ( result.IsEmpty() || result.Value( 1 ) == '"' || result.Value( 1 ) == '\'' ) if ( result.IsEmpty() || result.Value( 1 ) == '"' || result.Value( 1 ) == '\'' )
@ -281,13 +308,15 @@ namespace {
//================================================================================ //================================================================================
/*! /*!
* \brief Convert python script using commands of smesh.py * \brief Convert a python script using commands of smesh.py
* \param theScript - Input script * \param theScript - Input script
* \retval TCollection_AsciiString - Convertion result * \param theEntry2AccessorMethod - returns method names to access to
* \param theToKeepAllCommands - to keep all commands or * objects wrapped with python class
* to exclude commands relating to objects removed from study * \param theObjectNames - names of objects
* * \param theRemovedObjIDs - entries of objects whose created commands were removed
* Class SMESH_2smeshpy declared in SMESH_PythonDump.hxx * \param theHistoricalDump - true means to keep all commands, false means
* to exclude commands relating to objects removed from study
* \retval TCollection_AsciiString - Convertion result
*/ */
//================================================================================ //================================================================================
@ -295,10 +324,15 @@ TCollection_AsciiString
SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript, SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod, Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames, Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
std::set< TCollection_AsciiString >& theRemovedObjIDs,
SALOMEDS::Study_ptr& theStudy, SALOMEDS::Study_ptr& theStudy,
const bool theToKeepAllCommands) const bool theToKeepAllCommands)
{ {
theGen = new _pyGen( theEntry2AccessorMethod, theObjectNames, theStudy, theToKeepAllCommands ); theGen = new _pyGen( theEntry2AccessorMethod,
theObjectNames,
theRemovedObjIDs,
theStudy,
theToKeepAllCommands );
// split theScript into separate commands // split theScript into separate commands
@ -379,12 +413,14 @@ SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScrip
_pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod, _pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames, Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
std::set< TCollection_AsciiString >& theRemovedObjIDs,
SALOMEDS::Study_ptr& theStudy, SALOMEDS::Study_ptr& theStudy,
const bool theToKeepAllCommands) const bool theToKeepAllCommands)
: _pyObject( new _pyCommand( "", 0 )), : _pyObject( new _pyCommand( "", 0 )),
myNbCommands( 0 ), myNbCommands( 0 ),
myID2AccessorMethod( theEntry2AccessorMethod ), myID2AccessorMethod( theEntry2AccessorMethod ),
myObjectNames( theObjectNames ), myObjectNames( theObjectNames ),
myRemovedObjIDs( theRemovedObjIDs ),
myNbFilters( 0 ), myNbFilters( 0 ),
myToKeepAllCommands( theToKeepAllCommands ), myToKeepAllCommands( theToKeepAllCommands ),
myStudy( SALOMEDS::Study::_duplicate( theStudy )), myStudy( SALOMEDS::Study::_duplicate( theStudy )),
@ -719,7 +755,7 @@ void _pyGen::Process( const Handle(_pyCommand)& theCommand )
} }
if( method == "CreateMeshesFromMED" || method == "CreateMeshesFromSAUV") if( method == "CreateMeshesFromMED" || method == "CreateMeshesFromSAUV")
{ {
for(int ind = 0;ind<theCommand->GetNbResultValues();ind++) for ( int ind = 0; ind < theCommand->GetNbResultValues(); ind++ )
{ {
_pyID meshID = theCommand->GetResultValue(ind+1); _pyID meshID = theCommand->GetResultValue(ind+1);
if ( !theCommand->IsStudyEntry( meshID ) ) continue; if ( !theCommand->IsStudyEntry( meshID ) ) continue;
@ -1263,6 +1299,19 @@ bool _pyGen::IsNotPublished(const _pyID& theObjID) const
} }
return true; // SMESH object not in study return true; // SMESH object not in study
} }
//================================================================================
/*!
* \brief Remove object name from myObjectNames that leads to that SetName() for
* this object is not dumped
* \param [in] theObjID - entry of the object whose creation command was eliminated
*/
//================================================================================
void _pyGen::ObjectCreationRemoved(const _pyID& theObjID)
{
myRemovedObjIDs.insert( theObjID );
}
//================================================================================ //================================================================================
/*! /*!
@ -3020,25 +3069,24 @@ const TCollection_AsciiString & _pyCommand::GetResultValue()
//================================================================================ //================================================================================
/*! /*!
* \brief Return number of python command result value ResultValue = Obj.Meth() * \brief Return number of python command result value ResultValue = Obj.Meth()
* \retval const int
*/ */
//================================================================================ //================================================================================
const int _pyCommand::GetNbResultValues() int _pyCommand::GetNbResultValues()
{ {
int begPos = 1; int nb = 0;
int Nb=0; int begPos = 1;
int endPos = myString.Location( "=", 1, Length() );
TCollection_AsciiString str = ""; int endPos = myString.Location( "=", 1, Length() );
while ( begPos < endPos) { while ( begPos < endPos )
str = GetWord( myString, begPos, true ); {
begPos = begPos+ str.Length(); _AString str = GetWord( myString, begPos, true );
Nb++; begPos = begPos+ str.Length();
} nb++;
return (Nb-1); }
return (nb-1);
} }
//================================================================================ //================================================================================
/*! /*!
* \brief Return substring of python command looking like * \brief Return substring of python command looking like

View File

@ -122,7 +122,7 @@ public:
bool IsEmpty() const { return myString.IsEmpty(); } bool IsEmpty() const { return myString.IsEmpty(); }
_AString GetIndentation(); _AString GetIndentation();
const _AString & GetResultValue(); const _AString & GetResultValue();
const int GetNbResultValues(); int GetNbResultValues();
_AString GetResultValue(int res); _AString GetResultValue(int res);
const _AString & GetObject(); const _AString & GetObject();
const _AString & GetMethod(); const _AString & GetMethod();
@ -222,6 +222,7 @@ class _pyGen: public _pyObject
public: public:
_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod, _pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames, Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
std::set< TCollection_AsciiString >& theRemovedObjIDs,
SALOMEDS::Study_ptr& theStudy, SALOMEDS::Study_ptr& theStudy,
const bool theToKeepAllCommands); const bool theToKeepAllCommands);
Handle(_pyCommand) AddCommand( const _AString& theCommand ); Handle(_pyCommand) AddCommand( const _AString& theCommand );
@ -247,6 +248,7 @@ public:
bool IsGeomObject(const _pyID& theObjID) const; bool IsGeomObject(const _pyID& theObjID) const;
bool IsNotPublished(const _pyID& theObjID) const; bool IsNotPublished(const _pyID& theObjID) const;
void ObjectCreationRemoved(const _pyID& theObjID);
bool IsToKeepAllCommands() const { return myToKeepAllCommands; } bool IsToKeepAllCommands() const { return myToKeepAllCommands; }
void AddExportedMesh(const _AString& file, const ExportedMeshData& mesh ) void AddExportedMesh(const _AString& file, const ExportedMeshData& mesh )
{ myFile2ExportedMesh[ file ] = mesh; } { myFile2ExportedMesh[ file ] = mesh; }
@ -274,6 +276,7 @@ private:
int myNbCommands; int myNbCommands;
Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod; Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
Resource_DataMapOfAsciiStringAsciiString& myObjectNames; Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
std::set< TCollection_AsciiString >& myRemovedObjIDs;
Handle(_pyCommand) myLastCommand; Handle(_pyCommand) myLastCommand;
int myNbFilters; int myNbFilters;
bool myToKeepAllCommands; bool myToKeepAllCommands;

View File

@ -41,15 +41,11 @@ static int MYDEBUG = 0;
static int MYDEBUG = 0; static int MYDEBUG = 0;
#endif #endif
static TCollection_AsciiString NotPublishedObjectName()
{
return "__NOT__Published__Object__";
}
namespace SMESH namespace SMESH
{ {
size_t TPythonDump::myCounter = 0; size_t TPythonDump::myCounter = 0;
const char theNotPublishedObjectName[] = "__NOT__Published__Object__";
TVar::TVar(CORBA::Double value):myVals(1) { myVals[0] = SMESH_Comment(value); } TVar::TVar(CORBA::Double value):myVals(1) { myVals[0] = SMESH_Comment(value); }
TVar::TVar(CORBA::Long value):myVals(1) { myVals[0] = SMESH_Comment(value); } TVar::TVar(CORBA::Long value):myVals(1) { myVals[0] = SMESH_Comment(value); }
@ -238,10 +234,13 @@ namespace SMESH
TPythonDump:: TPythonDump::
operator<<(SALOMEDS::SObject_ptr aSObject) operator<<(SALOMEDS::SObject_ptr aSObject)
{ {
if ( !aSObject->_is_nil() ) if ( !aSObject->_is_nil() ) {
myStream << aSObject->GetID(); CORBA::String_var entry = aSObject->GetID();
else myStream << entry.in();
myStream << NotPublishedObjectName(); }
else {
myStream << theNotPublishedObjectName;
}
return *this; return *this;
} }
@ -259,7 +258,7 @@ namespace SMESH
if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object
myStream << "smeshObj_" << size_t(theArg); myStream << "smeshObj_" << size_t(theArg);
else else
myStream << NotPublishedObjectName(); myStream << theNotPublishedObjectName;
} }
else else
myStream << "None"; myStream << "None";
@ -300,7 +299,7 @@ namespace SMESH
SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL; SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL;
return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")"; return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")";
} }
return *this; return *this << theNotPublishedObjectName;
} }
TPythonDump& TPythonDump&
@ -462,6 +461,10 @@ namespace SMESH
DumpArray( theList, *this ); DumpArray( theList, *this );
return *this; return *this;
} }
const char* TPythonDump::NotPublishedObjectName()
{
return theNotPublishedObjectName;
}
TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" ); TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" );
TCollection_AsciiString myLongStringEnd ( "TPythonDump::LongStringEnd" ); TCollection_AsciiString myLongStringEnd ( "TPythonDump::LongStringEnd" );
@ -633,7 +636,7 @@ 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);
bool hasNotPublishedObjects = aScript.Location( NotPublishedObjectName(), 1, aLen); bool hasNotPublishedObjects = aScript.Location( SMESH::theNotPublishedObjectName, 1, aLen);
isValidScript = isValidScript && !hasNotPublishedObjects; isValidScript = isValidScript && !hasNotPublishedObjects;
return aStreamFile._retn(); return aStreamFile._retn();
@ -865,9 +868,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
// Some objects are wrapped with python classes and // Some objects are wrapped with python classes and
// Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects // Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod; Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
std::set< TCollection_AsciiString > aRemovedObjIDs;
if ( !getenv("NO_2smeshpy_conversion")) if ( !getenv("NO_2smeshpy_conversion"))
aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod, aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
theObjectNames, theStudy, isHistoricalDump ); theObjectNames, aRemovedObjIDs,
theStudy, isHistoricalDump );
// Replace characters used instead of quote marks to quote notebook variables // Replace characters used instead of quote marks to quote notebook variables
{ {
@ -967,6 +972,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()"; anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()";
} }
for (int ir = 1; ir <= seqRemoved.Length(); ir++) { for (int ir = 1; ir <= seqRemoved.Length(); ir++) {
if ( aRemovedObjIDs.count( seqRemoved.Value(ir) )) continue;
anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR("; anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(";
anUpdatedScript += seqRemoved.Value(ir); anUpdatedScript += seqRemoved.Value(ir);
// for object wrapped by class of smesh.py // for object wrapped by class of smesh.py
@ -990,6 +996,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
aName = geom->GetDumpName( anEntry.ToCString() ); aName = geom->GetDumpName( anEntry.ToCString() );
if (aName.IsEmpty() && // Not a GEOM object if (aName.IsEmpty() && // Not a GEOM object
theNames.IsBound(anEntry) && theNames.IsBound(anEntry) &&
!aRemovedObjIDs.count(anEntry) && // a command creating anEntry was erased
!mapEntries.IsBound(anEntry) && // Not yet processed !mapEntries.IsBound(anEntry) && // Not yet processed
!mapRemoved.IsBound(anEntry)) // Was not removed !mapRemoved.IsBound(anEntry)) // Was not removed
{ {

View File

@ -31,6 +31,7 @@
#include <sstream> #include <sstream>
#include <vector> #include <vector>
#include <set>
class SMESH_Gen_i; class SMESH_Gen_i;
class SMESH_MeshEditor_i; class SMESH_MeshEditor_i;
@ -49,18 +50,21 @@ class SMESH_2smeshpy
{ {
public: public:
/*! /*!
* \brief Convert a python script using commands of smesh.py * \brief Convert a python script using commands of smesh.py
* \param theScript - Input script * \param theScript - Input script
* \param theEntry2AccessorMethod - The returning method names to access to * \param theEntry2AccessorMethod - returns method names to access to
* objects wrapped with python class * objects wrapped with python class
* \param theHistoricalDump - true means to keep all commands, false means * \param theObjectNames - names of objects
* to exclude commands relating to objects removed from study * \param theRemovedObjIDs - entries of objects whose created commands were removed
* \param theHistoricalDump - true means to keep all commands, false means
* to exclude commands relating to objects removed from study
* \retval TCollection_AsciiString - Convertion result * \retval TCollection_AsciiString - Convertion result
*/ */
static TCollection_AsciiString static TCollection_AsciiString
ConvertScript(const TCollection_AsciiString& theScript, ConvertScript(const TCollection_AsciiString& theScript,
Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod, Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames, Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
std::set< TCollection_AsciiString >& theRemovedObjIDs,
SALOMEDS::Study_ptr& theStudy, SALOMEDS::Study_ptr& theStudy,
const bool theHistoricalDump); const bool theHistoricalDump);
@ -210,6 +214,7 @@ namespace SMESH
static const char* SMESHGenName() { return "smeshgen"; } static const char* SMESHGenName() { return "smeshgen"; }
static const char* MeshEditorName() { return "mesh_editor"; } static const char* MeshEditorName() { return "mesh_editor"; }
static const char* NotPublishedObjectName();
/*! /*!
* \brief Return marker of long string literal beginning * \brief Return marker of long string literal beginning