void CheckObjectPresence( const Handle(_pyCommand)& cmd, set<_pyID> & presentObjects)
{
+ // either comment or erase a command including NotPublishedObjectName()\r
+ if ( cmd->GetString().Location( TPythonDump::NotPublishedObjectName(), 1, cmd->Length() ))\r
+ {\r
+ bool isResultPublished = false;\r
+ for ( int i = 0; i < cmd->GetNbResultValues(); i++ )\r
+ {\r
+ _pyID objID = cmd->GetResultValue( i+1 );\r
+ if ( cmd->IsStudyEntry( objID ))\r
+ isResultPublished = (! theGen->IsNotPublished( objID ));\r
+ theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed\r
+ }\r
+ if ( isResultPublished )\r
+ cmd->Comment();\r
+ else\r
+ cmd->Clear();\r
+ return;\r
+ }\r
+ // comment a command having not created args
for ( int iArg = cmd->GetNbArgs(); iArg; --iArg )
{
const _pyID& arg = cmd->GetArg( iArg );
cmd->Comment();
cmd->GetString() += " ### " ;
cmd->GetString() += *id + " has not been yet created";
+ for ( int i = 0; i < cmd->GetNbResultValues(); i++ ) {\r
+ _pyID objID = cmd->GetResultValue( i+1 );\r
+ theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed\r
+ }
return;
}
}
+ // comment a command having not created Object
const _pyID& obj = cmd->GetObject();
if ( !obj.IsEmpty() && cmd->IsStudyEntry( obj ) && !presentObjects.count( obj ))
{
cmd->Comment();
cmd->GetString() += " ### not created object" ;
+ for ( int i = 0; i < cmd->GetNbResultValues(); i++ ) {\r
+ _pyID objID = cmd->GetResultValue( i+1 );\r
+ theGen->ObjectCreationRemoved( objID ); // objID.SetName( name ) is not needed\r
+ }
}
const _pyID& result = cmd->GetResultValue();
if ( result.IsEmpty() || result.Value( 1 ) == '"' || result.Value( 1 ) == '\'' )
//================================================================================
/*!
- * \brief Convert python script using commands of smesh.py
- * \param theScript - Input script
- * \retval TCollection_AsciiString - Convertion result
- * \param theToKeepAllCommands - to keep all commands or
- * to exclude commands relating to objects removed from study
- *
- * Class SMESH_2smeshpy declared in SMESH_PythonDump.hxx
+ * \brief Convert a python script using commands of smesh.py\r
+ * \param theScript - Input script\r
+ * \param theEntry2AccessorMethod - returns method names to access to\r
+ * objects wrapped with python class\r
+ * \param theObjectNames - names of objects\r
+ * \param theRemovedObjIDs - entries of objects whose created commands were removed\r
+ * \param theHistoricalDump - true means to keep all commands, false means\r
+ * to exclude commands relating to objects removed from study\r
+ * \retval TCollection_AsciiString - Convertion result\r
*/
//================================================================================
SMESH_2smeshpy::ConvertScript(const TCollection_AsciiString& theScript,
Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+ std::set< TCollection_AsciiString >& theRemovedObjIDs,
SALOMEDS::Study_ptr& theStudy,
const bool theToKeepAllCommands)
{
- theGen = new _pyGen( theEntry2AccessorMethod, theObjectNames, theStudy, theToKeepAllCommands );
+ theGen = new _pyGen( theEntry2AccessorMethod,\r
+ theObjectNames,\r
+ theRemovedObjIDs,\r
+ theStudy,\r
+ theToKeepAllCommands );
// split theScript into separate commands
_pyGen::_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+ std::set< TCollection_AsciiString >& theRemovedObjIDs,
SALOMEDS::Study_ptr& theStudy,
const bool theToKeepAllCommands)
: _pyObject( new _pyCommand( "", 0 )),
myNbCommands( 0 ),
myID2AccessorMethod( theEntry2AccessorMethod ),
myObjectNames( theObjectNames ),
+ myRemovedObjIDs( theRemovedObjIDs ),
myNbFilters( 0 ),
myToKeepAllCommands( theToKeepAllCommands ),
myStudy( SALOMEDS::Study::_duplicate( theStudy )),
}
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);
if ( !theCommand->IsStudyEntry( meshID ) ) continue;
}
return true; // SMESH object not in study
}
+\r
+//================================================================================\r
+/*!\r
+ * \brief Remove object name from myObjectNames that leads to that SetName() for\r
+ * this object is not dumped\r
+ * \param [in] theObjID - entry of the object whose creation command was eliminated\r
+ */\r
+//================================================================================\r
+\r
+void _pyGen::ObjectCreationRemoved(const _pyID& theObjID)\r
+{\r
+ myRemovedObjIDs.insert( theObjID );\r
+}\r
//================================================================================
/*!
//================================================================================
/*!
* \brief Return number of python command result value ResultValue = Obj.Meth()
- * \retval const int
*/
//================================================================================
-const int _pyCommand::GetNbResultValues()
-{
- int begPos = 1;
- int Nb=0;
- int endPos = myString.Location( "=", 1, Length() );
- TCollection_AsciiString str = "";
- while ( begPos < endPos) {
- str = GetWord( myString, begPos, true );
- begPos = begPos+ str.Length();
- Nb++;
- }
- return (Nb-1);
+int _pyCommand::GetNbResultValues()\r
+{\r
+ int nb = 0;\r
+ int begPos = 1;\r
+\r
+ int endPos = myString.Location( "=", 1, Length() );\r
+ while ( begPos < endPos )\r
+ {\r
+ _AString str = GetWord( myString, begPos, true );\r
+ begPos = begPos+ str.Length();\r
+ nb++;\r
+ }\r
+ return (nb-1);\r
}
-
//================================================================================
/*!
* \brief Return substring of python command looking like
bool IsEmpty() const { return myString.IsEmpty(); }
_AString GetIndentation();
const _AString & GetResultValue();
- const int GetNbResultValues();
+ int GetNbResultValues();
_AString GetResultValue(int res);
const _AString & GetObject();
const _AString & GetMethod();
public:
_pyGen(Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+ std::set< TCollection_AsciiString >& theRemovedObjIDs,
SALOMEDS::Study_ptr& theStudy,
const bool theToKeepAllCommands);
Handle(_pyCommand) AddCommand( const _AString& theCommand );
bool IsGeomObject(const _pyID& theObjID) const;
bool IsNotPublished(const _pyID& theObjID) const;
+ void ObjectCreationRemoved(const _pyID& theObjID);
bool IsToKeepAllCommands() const { return myToKeepAllCommands; }
void AddExportedMesh(const _AString& file, const ExportedMeshData& mesh )
{ myFile2ExportedMesh[ file ] = mesh; }
int myNbCommands;
Resource_DataMapOfAsciiStringAsciiString& myID2AccessorMethod;
Resource_DataMapOfAsciiStringAsciiString& myObjectNames;
+ std::set< TCollection_AsciiString >& myRemovedObjIDs;
Handle(_pyCommand) myLastCommand;
int myNbFilters;
bool myToKeepAllCommands;
static int MYDEBUG = 0;
#endif
-static TCollection_AsciiString NotPublishedObjectName()
-{
- return "__NOT__Published__Object__";
-}
-
namespace SMESH
{
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::Long value):myVals(1) { myVals[0] = SMESH_Comment(value); }
TPythonDump::
operator<<(SALOMEDS::SObject_ptr aSObject)
{
- if ( !aSObject->_is_nil() )
- myStream << aSObject->GetID();
- else
- myStream << NotPublishedObjectName();
+ if ( !aSObject->_is_nil() ) {\r
+ CORBA::String_var entry = aSObject->GetID();\r
+ myStream << entry.in();\r
+ }\r
+ else {\r
+ myStream << theNotPublishedObjectName;\r
+ }
return *this;
}
if ( aSMESHGen->CanPublishInStudy( theArg )) // not published SMESH object
myStream << "smeshObj_" << size_t(theArg);
else
- myStream << NotPublishedObjectName();
+ myStream << theNotPublishedObjectName;
}
else
myStream << "None";
SMESH::ElementType type = types->length() ? types[0] : SMESH::ALL;
return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")";
}
- return *this;
+ return *this << theNotPublishedObjectName;
}
TPythonDump&
DumpArray( theList, *this );
return *this;
}
+ const char* TPythonDump::NotPublishedObjectName()\r
+ {\r
+ return theNotPublishedObjectName;\r
+ }
TCollection_AsciiString myLongStringStart( "TPythonDump::LongStringStart" );
TCollection_AsciiString myLongStringEnd ( "TPythonDump::LongStringEnd" );
CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
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;
return aStreamFile._retn();
// Some objects are wrapped with python classes and
// Resource_DataMapOfAsciiStringAsciiString holds methods returning wrapped objects
Resource_DataMapOfAsciiStringAsciiString anEntry2AccessorMethod;
+ std::set< TCollection_AsciiString > aRemovedObjIDs;
if ( !getenv("NO_2smeshpy_conversion"))
- aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,
- theObjectNames, theStudy, isHistoricalDump );
+ aScript = SMESH_2smeshpy::ConvertScript( aScript, anEntry2AccessorMethod,\r
+ theObjectNames, aRemovedObjIDs,\r
+ theStudy, isHistoricalDump );
// Replace characters used instead of quote marks to quote notebook variables
{
anUpdatedScript += "\n\taStudyBuilder = theStudy.NewBuilder()";
}
for (int ir = 1; ir <= seqRemoved.Length(); ir++) {
+ if ( aRemovedObjIDs.count( seqRemoved.Value(ir) )) continue;
anUpdatedScript += "\n\tSO = theStudy.FindObjectIOR(theStudy.ConvertObjectToIOR(";
anUpdatedScript += seqRemoved.Value(ir);
// for object wrapped by class of smesh.py
aName = geom->GetDumpName( anEntry.ToCString() );
if (aName.IsEmpty() && // Not a GEOM object
theNames.IsBound(anEntry) &&
+ !aRemovedObjIDs.count(anEntry) && // a command creating anEntry was erased
!mapEntries.IsBound(anEntry) && // Not yet processed
!mapRemoved.IsBound(anEntry)) // Was not removed
{
#include <sstream>
#include <vector>
+#include <set>
class SMESH_Gen_i;
class SMESH_MeshEditor_i;
{
public:
/*!
- * \brief Convert a python script using commands of smesh.py
- * \param theScript - Input script
- * \param theEntry2AccessorMethod - The returning method names to access to
- * objects wrapped with python class
- * \param theHistoricalDump - true means to keep all commands, false means
- * to exclude commands relating to objects removed from study
+ * \brief Convert a python script using commands of smesh.py\r
+ * \param theScript - Input script\r
+ * \param theEntry2AccessorMethod - returns method names to access to\r
+ * objects wrapped with python class\r
+ * \param theObjectNames - names of objects\r
+ * \param theRemovedObjIDs - entries of objects whose created commands were removed\r
+ * \param theHistoricalDump - true means to keep all commands, false means\r
+ * to exclude commands relating to objects removed from study\r
* \retval TCollection_AsciiString - Convertion result
*/
static TCollection_AsciiString
ConvertScript(const TCollection_AsciiString& theScript,
Resource_DataMapOfAsciiStringAsciiString& theEntry2AccessorMethod,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
+ std::set< TCollection_AsciiString >& theRemovedObjIDs,
SALOMEDS::Study_ptr& theStudy,
const bool theHistoricalDump);
static const char* SMESHGenName() { return "smeshgen"; }
static const char* MeshEditorName() { return "mesh_editor"; }
+ static const char* NotPublishedObjectName();
/*!
* \brief Return marker of long string literal beginning