Fix Python dump of ExportPartToMED()

This commit is contained in:
eap 2018-09-03 14:52:55 +03:00
parent 5552aec787
commit 14866e6309
2 changed files with 41 additions and 30 deletions

View File

@ -2032,21 +2032,32 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand )
TCollection_AsciiString newMethod = method; TCollection_AsciiString newMethod = method;
newMethod.Remove( /*where=*/7, /*howmany=*/6 ); newMethod.Remove( /*where=*/7, /*howmany=*/6 );
theCommand->SetMethod( newMethod ); theCommand->SetMethod( newMethod );
// filter out deprecated version parameter // replace version parameter by minor
vector< _AString > args; std::list< _AString > args;
for ( int i = 1; i <= theCommand->GetNbArgs(); i++ ) { for ( int i = 1; i <= theCommand->GetNbArgs(); i++ ) {
if ( !_FilterArg( theCommand->GetArg( i ) ) ) if ( _FilterArg( theCommand->GetArg( i )))
args.push_back( theCommand->GetArg( i ) ); args.push_back( "minor=0");
else
args.push_back( theCommand->GetArg( i ));
} }
theCommand->RemoveArgs(); // check the 1st arg meshPart, it must be SMESH_IDSource
for ( uint i = 0; i < args.size(); i++ ) _AString meshPart = args.front();
theCommand->SetArg( i+1, args[i] ); if ( _pyCommand::IsStudyEntry( meshPart ) ||
// make the 1st arg be the last one (or last but three for ExportMED()) meshPart.Search( "Filter" ) > 0 ||
_pyID partID = theCommand->GetArg( 1 ); meshPart.Search( "GetIDSource" ) > 0 ||
int nbArgs = theCommand->GetNbArgs() - 3 * (newMethod == "ExportMED"); meshPart.Search( "meshPart" ) > 0 )
for ( int i = 2; i <= nbArgs; ++i ) {
theCommand->SetArg( i-1, theCommand->GetArg( i )); // set the 1st arg meshPart
theCommand->SetArg( nbArgs, partID ); // - to 5th place for ExportMED command
// - to last place for the rest commands
std::list< _AString >::iterator newPos = args.end();
if ( newMethod == "ExportMED" )
std::advance( newPos = args.begin(), 5 );
args.splice( newPos, args, args.begin() );
}
std::list< _AString >::iterator a = args.begin();
for ( uint i = 1; a != args.end(); ++i, ++a )
theCommand->SetArg( i, *a );
} }
// remember file name // remember file name
theGen->AddExportedMesh( theCommand->GetArg( 1 ), theGen->AddExportedMesh( theCommand->GetArg( 1 ),
@ -3712,17 +3723,17 @@ const TCollection_AsciiString & _pyCommand::GetObject()
if ( begPos < 1 ) { if ( begPos < 1 ) {
begPos = myString.Location( "=", 1, Length() ) + 1; begPos = myString.Location( "=", 1, Length() ) + 1;
// is '=' in the string argument (for example, name) or not // is '=' in the string argument (for example, name) or not
int nb1 = 0; // number of ' character at the left of = int nb[4] = { 0, 0, 0, 0 }; // number of '"() character at the left of =
int nb2 = 0; // number of " character at the left of = for ( int i = 1; i < begPos-1; i++ )
for ( int i = 1; i < begPos-1; i++ ) { switch ( myString.Value( i )) {
if ( myString.Value( i )=='\'' ) case '\'': nb[0]++; break;
nb1 += 1; case '"' : nb[1]++; break;
else if ( myString.Value( i )=='"' ) case '(' : nb[2]++; break;
nb2 += 1; case ')' : nb[3]++; break;
} }
// if number of ' or " is not divisible by 2, // if = is inside a string or a list
// then get an object at the start of the command // then get an object at the start of the command
if ( nb1 % 2 != 0 || nb2 % 2 != 0 ) if ( nb[0] % 2 != 0 || nb[1] % 2 != 0 || nb[2] != nb[3])
begPos = 1; begPos = 1;
} }
else { else {

View File

@ -3253,14 +3253,14 @@ void SMESH_Mesh_i::ExportPartToMED(SMESH::SMESH_IDSource_ptr meshPart,
GEOM::GEOM_BaseObject_var gbo = GEOM::GEOM_BaseObject::_narrow( fields[i] ); GEOM::GEOM_BaseObject_var gbo = GEOM::GEOM_BaseObject::_narrow( fields[i] );
goList[i] = gbo; goList[i] = gbo;
} }
TPythonDump() << _this() << ".ExportPartToMED( r'" TPythonDump() << _this() << ".ExportPartToMED( "
<< meshPart << ", r'"
<< file << "', " << file << "', "
<< "auto_groups=" << auto_groups << ", " << auto_groups << ", "
<< "minor=" << minor << ", " << minor << ", "
<< "overwrite=" << overwrite << ", " << overwrite << ", "
<< "meshPart=" << meshPart << ", " << autoDimension << ", "
<< "autoDimension=" << autoDimension << ", " << goList << ", '"
<< "fields=" << goList << ", geomAssocFields='"
<< ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )"; << ( geomAssocFields ? geomAssocFields : "" ) << "'" << " )";
SMESH_CATCH( SMESH::throwCorbaException ); SMESH_CATCH( SMESH::throwCorbaException );