X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_PythonDump.cxx;h=6b90f80f5fe3a82ee9e6ba451b3310d5e3ae8d2b;hp=d92f15da7f32c0ca2df32aae57bf553f173b6082;hb=6472eab132825fec572beda8276947593f85ffa1;hpb=d3e1cabf77f67408ac401e2d387e721605cb3b10 diff --git a/src/SMESH_I/SMESH_PythonDump.cxx b/src/SMESH_I/SMESH_PythonDump.cxx index d92f15da7..6b90f80f5 100644 --- a/src/SMESH_I/SMESH_PythonDump.cxx +++ b/src/SMESH_I/SMESH_PythonDump.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2019 CEA/DEN, EDF R&D, OPEN CASCADE // // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS @@ -32,6 +32,7 @@ #include "SMESH_Gen_i.hxx" #include "SMESH_MeshEditor_i.hxx" +#include #include #include @@ -233,6 +234,7 @@ namespace SMESH case Entity_TriQuad_Hexa: myStream<<"Entity_TriQuad_Hexa"; break; case Entity_Penta: myStream<<"Entity_Penta"; break; case Entity_Quad_Penta: myStream<<"Entity_Quad_Penta"; break; + case Entity_BiQuad_Penta: myStream<<"Entity_BiQuad_Penta"; break; case Entity_Hexagonal_Prism: myStream<<"Entity_Hexagonal_Prism"; break; case Entity_Polyhedra: myStream<<"Entity_Polyhedra"; break; case Entity_Quad_Polyhedra: myStream<<"Entity_Quad_Polyhedra"; break; @@ -243,25 +245,6 @@ namespace SMESH return *this; } - template - void DumpArray(const TArray& theArray, TPythonDump & theStream) - { - if ( theArray.length() == 0 ) - { - theStream << "[]"; - } - else - { - theStream << "[ "; - for (CORBA::ULong i = 1; i <= theArray.length(); i++) { - theStream << theArray[i-1]; - if ( i < theArray.length() ) - theStream << ", "; - } - theStream << " ]"; - } - } - TPythonDump& TPythonDump::operator<<(const SMESH::long_array& theArg) { @@ -348,7 +331,6 @@ namespace SMESH { if ( CORBA::is_nil( theArg ) ) return *this << "None"; - SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen(); SALOMEDS::SObject_wrap aSObject = SMESH_Gen_i::ObjectToSObject(theArg); if(!aSObject->_is_nil()) { @@ -426,6 +408,8 @@ namespace SMESH case FT_MultiConnection2D: myStream<< "aMultiConnection2D"; break; case FT_Length: myStream<< "aLength"; break; case FT_Length2D: myStream<< "aLength2D"; break; + case FT_Length3D: myStream<< "aLength3D"; break; + case FT_Deflection2D: myStream<< "aDeflection2D"; break; case FT_NodeConnectivityNumber:myStream<< "aNodeConnectivityNumber";break; case FT_BelongToMeshGroup: myStream<< "aBelongToMeshGroup"; break; case FT_BelongToGeom: myStream<< "aBelongToGeom"; break; @@ -539,6 +523,16 @@ namespace SMESH DumpArray( theList, *this ); return *this; } + TPythonDump& TPythonDump::operator<<(const SMESH::submesh_array& theList) + { + DumpArray( theList, *this ); + return *this; + } + TPythonDump& TPythonDump::operator<<(const SMESH::ListOfHypothesis& theList) + { + DumpArray( theList, *this ); + return *this; + } TPythonDump& TPythonDump::operator<<(const SMESH::CoincidentFreeBorders& theCFB) { // dump CoincidentFreeBorders as a list of lists, each enclosed list @@ -674,38 +668,41 @@ namespace SMESH void printException( const char* text ) { #ifdef _DEBUG_ - cout << "Exception in SMESH_Gen_i::DumpPython(): " << text << endl; + std::cout << "Exception in SMESH_Gen_i::DumpPython(): " << text << std::endl; #endif } -} //======================================================================= //function : RemoveTabulation //purpose : //======================================================================= -void RemoveTabulation( TCollection_AsciiString& theScript ) -{ - std::string aString( theScript.ToCString() ); - std::string::size_type aPos = 0; - while( aPos < aString.length() ) + void RemoveTabulation( TCollection_AsciiString& theScript ) { - aPos = aString.find( "\n\t", aPos ); - if( aPos == std::string::npos ) - break; - aString.replace( aPos, 2, "\n" ); - aPos++; + 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(); } - theScript = aString.c_str(); } //======================================================================= //function : DumpPython //purpose : //======================================================================= -Engines::TMPFile* SMESH_Gen_i::DumpPython (CORBA::Boolean isPublished, - CORBA::Boolean isMultiFile, +Engines::TMPFile* SMESH_Gen_i::DumpPython( CORBA::Boolean isPublished, + CORBA::Boolean isMultiFile, CORBA::Boolean& isValidScript) { + // localizing + Kernel_Utils::Localizer loc; + SALOMEDS::Study_var aStudy = getStudyServant(); if (CORBA::is_nil(aStudy)) return new Engines::TMPFile(0); @@ -961,7 +958,7 @@ namespace { //================================================================================ /*! - * \brief Createa a Dump Python script + * \brief Creates a Dump Python script * \param [in,out] theObjectNames - map of an entry to a study and python name * \param [in] theNames - - map of an entry to a study name * \param [in] isPublished - \c true if dump of object publication in study is needed @@ -990,14 +987,16 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl const TCollection_AsciiString anOldGen ( SMESH::TPythonDump::SMESHGenName() ); const TCollection_AsciiString helper; // to comfortably append C strings to TCollection_AsciiString const TCollection_AsciiString tab( isMultiFile ? "\t" : "" ), nt = helper + "\n" + tab; - + TCollection_AsciiString optionalComment; + std::list< TCollection_AsciiString > lines; // lines of a script std::list< TCollection_AsciiString >::iterator linesIt; + lines.push_back( aSMESHGen + " = smeshBuilder.New()" ); if ( isPublished ) - lines.push_back( aSMESHGen + " = smeshBuilder.New()" ); - else - lines.push_back( aSMESHGen + " = smeshBuilder.New(False)" ); + optionalComment = "#"; + lines.push_back( optionalComment + aSMESHGen + ".SetEnablePublish( False ) # Set to False to avoid publish in study if not needed or in some particular situations:" ); + lines.push_back( " # multiples meshes built in parallel, complex and numerous mesh edition (performance)\n" ); lines.push_back( helper + "aFilterManager = " + aSMESHGen + ".CreateFilterManager()" ); lines.push_back( helper + "aMeasurements = " + aSMESHGen + ".CreateMeasurements()" ); @@ -1062,12 +1061,15 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl isHistoricalDump ); bool importGeom = false; - GEOM::GEOM_Gen_ptr geom = GetGeomEngine(); + GEOM::GEOM_Gen_ptr geom[2]; + for ( int isShaper = 0; isShaper < 2; ++isShaper ) { + geom[ isShaper ] = GetGeomEngine( isShaper ); + if ( CORBA::is_nil( geom[ isShaper ])) + continue; // Add names of GEOM objects to theObjectNames to exclude same names of SMESH objects - GEOM::string_array_var aGeomNames = geom->GetAllDumpNames(); - int ign = 0, nbgn = aGeomNames->length(); - for (; ign < nbgn; ign++) { + GEOM::string_array_var aGeomNames = geom[ isShaper ]->GetAllDumpNames(); + for ( CORBA::ULong ign = 0; ign < aGeomNames->length(); ign++) { TCollection_AsciiString aName = aGeomNames[ign].in(); theObjectNames.Bind(aName, "1"); } @@ -1101,7 +1103,11 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl anUpdatedScript += aLine.SubString( aStart, aSeq->Value(i) - 1 ); // line part before i-th entry anEntry = aLine.SubString( aSeq->Value(i), aSeq->Value(i + 1) ); // is a GEOM object? - CORBA::String_var geomName = geom->GetDumpName( anEntry.ToCString() ); + CORBA::String_var geomName; + if ( !CORBA::is_nil( geom[0] )) + geomName = geom[0]->GetDumpName( anEntry.ToCString() ); + if (( !geomName.in() || !geomName.in()[0] ) && !CORBA::is_nil( geom[1] )) + geomName = geom[1]->GetDumpName( anEntry.ToCString() ); if ( !geomName.in() || !geomName.in()[0] ) { // is a SMESH object if ( theObjectNames.IsBound( anEntry )) { @@ -1175,26 +1181,28 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl } // import python files corresponding to plugins if they are used in anUpdatedScript { - TCollection_AsciiString importStr; + //TCollection_AsciiString importStr; std::vector pluginNames = getPluginNames(); for ( size_t i = 0; i < pluginNames.size(); ++i ) { // Convert access to plugin members: - // e.g. StdMeshers.QUAD_REDUCED -> StdMeshersBuilder.QUAD_REDUCED + // e.g. StdMeshers.QUAD_REDUCED -> smeshBuilder.QUAD_REDUCED TCollection_AsciiString pluginAccess = (pluginNames[i] + ".").c_str() ; int iFrom = 1, iPos; while (( iPos = anUpdatedScript.Location( pluginAccess, iFrom, anUpdatedScript.Length() ))) { - anUpdatedScript.Insert( iPos + pluginNames[i].size(), "Builder" ); - iFrom = iPos + pluginNames[i].size() + 8; + //anUpdatedScript.Insert( iPos + pluginNames[i].size(), "Builder" ); + anUpdatedScript.Remove( iPos, pluginNames[i].size() ); + anUpdatedScript.Insert( iPos, "smeshBuilder" ); + iFrom = iPos - pluginNames[i].size() + 12; } // if any plugin member is used, import the plugin - if ( iFrom > 1 ) - importStr += ( helper + "\n" "from salome." + pluginNames[i].c_str() + - " import " + pluginNames[i].c_str() +"Builder" ); + // if ( iFrom > 1 ) + // importStr += ( helper + "\n" "from salome." + pluginNames[i].c_str() + + // " import " + pluginNames[i].c_str() +"Builder" ); } - if ( !importStr.IsEmpty() ) - initPart += importStr + "\n"; + // if ( !importStr.IsEmpty() ) + // initPart += importStr + "\n"; } if ( isMultiFile ) @@ -1300,7 +1308,7 @@ TCollection_AsciiString SMESH_Gen_i::DumpPython_impl { // find the function name int functBeg = posAlready; - char* script = (char*) anUpdatedScript.ToCString() + posAlready - 1; // look at ":" after "def fuction()" + char* script = (char*) anUpdatedScript.ToCString() + posAlready - 1; // look at ":" after "def function()" while ( *script != ' ' ) { script--; functBeg--;