//
// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
+// File : SMESH_DumpPython.cxx
+// Created : Thu Mar 24 17:17:59 2005
+// Author : Julia DOROVSKIKH
+// Module : SMESH
-// File : SMESH_Gen_i_DumpPython.cxx
-// Created : Thu Mar 24 17:17:59 2005
-// Author : Julia DOROVSKIKH
-// Module : SMESH
-// $Header : $
-//
#include "SMESH_PythonDump.hxx"
#include "SMESH_Gen_i.hxx"
#include "SMESH_Filter_i.hxx"
}
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(long int theArg){
myStream<<theArg;
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(int theArg){
myStream<<theArg;
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(double theArg){
myStream<<theArg;
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(float theArg){
myStream<<theArg;
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(const void* theArg){
myStream<<theArg;
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(const char* theArg){
if ( theArg )
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(const SMESH::ElementType& theArg)
{
theStream << " ]";
}
- TPythonDump&
+ TPythonDump&
TPythonDump::operator<<(const SMESH::long_array& theArg)
{
DumpArray( theArg, *this );
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::operator<<(const SMESH::double_array& theArg)
{
DumpArray( theArg, *this );
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(SALOMEDS::SObject_ptr aSObject)
{
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(CORBA::Object_ptr theArg)
{
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(SMESH::SMESH_Hypothesis_ptr theArg)
{
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(SMESH::SMESH_IDSource_ptr theArg)
{
return *this << mesh << ".GetIDSource(" << anElementsId << ", " << type << ")";
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(SMESH::FilterLibrary_i* theArg)
{
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(SMESH::FilterManager_i* theArg)
{
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(SMESH::Filter_i* theArg)
{
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(SMESH::Functor_i* theArg)
{
return *this;
}
- TPythonDump&
+ TPythonDump&
TPythonDump::
operator<<(SMESH::Measurements_i* theArg)
{
DumpArray( theList, *this );
return *this;
}
+ TPythonDump& TPythonDump::operator<<(const SMESH::ListOfGroups * theList)
+ {
+ DumpArray( *theList, *this );
+ return *this;
+ }
TPythonDump& TPythonDump::operator<<(const SMESH::ListOfIDSources& theList)
{
DumpArray( theList, *this );
//================================================================================
/*!
* \brief Return marker of long string literal beginning
- * \param type - a name of functionality producing the string literal
+ * \param type - a name of functionality producing the string literal
* \retval TCollection_AsciiString - the marker string to be written into
* a raw python script
*/
* \param theLongString - the retrieved literal
* \param theStringType - a name of functionality produced the literal
* \retval bool - true if a string literal found
- *
+ *
* The literal is removed from theText; theFrom points position right after
* the removed literal
*/
}
//=======================================================================
-//function : DumpPython
+//function : RemoveTabulation
//purpose :
//=======================================================================
+void RemoveTabulation( TCollection_AsciiString& theScript )
+{
+ std::string aString( theScript.ToCString() );
+ std::string::size_type aPos = 0;
+ while( aPos < aString.length() )
+ {
+ aPos = aString.find( "\n\t", aPos );
+ if( aPos == std::string::npos )
+ break;
+ aString.replace( aPos, 2, "\n" );
+ aPos++;
+ }
+ theScript = aString.c_str();
+}
+
+//=======================================================================
+//function : DumpPython
+//purpose :
+//=======================================================================
Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Object_ptr theStudy,
CORBA::Boolean isPublished,
+ CORBA::Boolean isMultiFile,
CORBA::Boolean& isValidScript)
{
SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow(theStudy);
// Add trace of API methods calls and replace study entries by names
TCollection_AsciiString aScript;
aScript += DumpPython_impl(aStudy, aMap, aMapNames,
- isPublished, isValidScript, aSavedTrace);
+ isPublished, isMultiFile, isValidScript, aSavedTrace);
+
+ if( !isMultiFile ) // remove unnecessary tabulation
+ RemoveTabulation( aScript );
- int aLen = aScript.Length();
+ int aLen = aScript.Length();
unsigned char* aBuffer = new unsigned char[aLen+1];
strcpy((char*)aBuffer, aScript.ToCString());
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);
isValidScript = isValidScript && !hasNotPublishedObjects;
- return aStreamFile._retn();
+ return aStreamFile._retn();
}
//=============================================================================
//=======================================================================
//function : SavePython
-//purpose :
+//purpose :
//=======================================================================
void SMESH_Gen_i::SavePython (SALOMEDS::Study_ptr theStudy)
{
int c = (int)arr[i];
j = i+1;
if ( isdigit( c )) { //Is digit?
-
+
isFound = Standard_False;
while((j < aLen) && ( isdigit(c) || c == ':' )) { //Check if it is an entry
- c = (int)arr[j++];
+ c = (int)arr[j++];
if(c == ':') isFound = Standard_True;
}
*/
//=============================================================================
TCollection_AsciiString SMESH_Gen_i::DumpPython_impl
- (SALOMEDS::Study_ptr theStudy,
+ (SALOMEDS::Study_ptr theStudy,
Resource_DataMapOfAsciiStringAsciiString& theObjectNames,
Resource_DataMapOfAsciiStringAsciiString& theNames,
- bool isPublished,
+ bool isPublished,
+ bool isMultiFile,
bool& aValidScript,
const TCollection_AsciiString& theSavedTrace)
{
TCollection_AsciiString anOldGen( SMESH::TPythonDump::SMESHGenName() );
TCollection_AsciiString aScript;
- aScript = "def RebuildData(theStudy):\n\t";
+ if( isMultiFile )
+ aScript += "def RebuildData(theStudy):";
+ else
+ aScript += "theStudy = salome.myStudy";
+ aScript += "\n\t";
aScript += helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()\n\t";
aScript += helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()\n\t";
if ( isPublished )
// set initial part of aSript
TCollection_AsciiString initPart = "import salome, SMESH, SALOMEDS\n";
- initPart += helper + "import " + aSmeshpy + "\n\n";
- if ( importGeom )
+ initPart += helper + "import " + aSmeshpy + "\n";
+ if ( importGeom && isMultiFile )
{
- initPart += ("## import GEOM dump file ## \n"
+ initPart += ("\n## import GEOM dump file ## \n"
"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");
+ "exec(\"from \"+re.sub(\"SMESH$\",\"GEOM\",__name__)+\" import *\")\n");
}
anUpdatedScript.Insert ( 1, initPart );
CORBA::string_free(script);
}
}
- anUpdatedScript += "\n\n\tpass\n";
+
+ if( isMultiFile )
+ anUpdatedScript += "\n\tpass";
+ anUpdatedScript += "\n";
// -----------------------------------------------------------------
// put string literals describing patterns into separate functions