X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_2smeshpy.cxx;h=e8bc862a90dd119667e2afc63ddeaf5a8254f506;hp=c680de4e6a827967dac4417a230282639ef1dcb5;hb=5d0b75d9d1a9935ec419e820e6dde45a665dd978;hpb=bb40f7c1d3542da1ff59b6c3bface0574789dded diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index c680de4e6..e8bc862a9 100644 --- a/src/SMESH_I/SMESH_2smeshpy.cxx +++ b/src/SMESH_I/SMESH_2smeshpy.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 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 @@ -50,38 +50,22 @@ #include #endif - -IMPLEMENT_STANDARD_HANDLE (_pyObject ,Standard_Transient); -IMPLEMENT_STANDARD_HANDLE (_pyCommand ,Standard_Transient); -IMPLEMENT_STANDARD_HANDLE (_pyHypothesisReader,Standard_Transient); -IMPLEMENT_STANDARD_HANDLE (_pyGen ,_pyObject); -IMPLEMENT_STANDARD_HANDLE (_pyMesh ,_pyObject); -IMPLEMENT_STANDARD_HANDLE (_pySubMesh ,_pyObject); -IMPLEMENT_STANDARD_HANDLE (_pyMeshEditor ,_pyObject); -IMPLEMENT_STANDARD_HANDLE (_pyHypothesis ,_pyObject); -IMPLEMENT_STANDARD_HANDLE (_pySelfEraser ,_pyObject); -IMPLEMENT_STANDARD_HANDLE (_pyGroup ,_pyObject); -IMPLEMENT_STANDARD_HANDLE (_pyFilter ,_pyObject); -IMPLEMENT_STANDARD_HANDLE (_pyAlgorithm ,_pyHypothesis); -IMPLEMENT_STANDARD_HANDLE (_pyComplexParamHypo,_pyHypothesis); -IMPLEMENT_STANDARD_HANDLE (_pyNumberOfSegmentsHyp,_pyHypothesis); - -IMPLEMENT_STANDARD_RTTIEXT(_pyObject ,Standard_Transient); -IMPLEMENT_STANDARD_RTTIEXT(_pyCommand ,Standard_Transient); -IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesisReader,Standard_Transient); -IMPLEMENT_STANDARD_RTTIEXT(_pyGen ,_pyObject); -IMPLEMENT_STANDARD_RTTIEXT(_pyMesh ,_pyObject); -IMPLEMENT_STANDARD_RTTIEXT(_pySubMesh ,_pyObject); -IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor ,_pyObject); -IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis ,_pyObject); -IMPLEMENT_STANDARD_RTTIEXT(_pySelfEraser ,_pyObject); -IMPLEMENT_STANDARD_RTTIEXT(_pyGroup ,_pyObject); -IMPLEMENT_STANDARD_RTTIEXT(_pyFilter ,_pyObject); -IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm ,_pyHypothesis); -IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis); -IMPLEMENT_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis); -IMPLEMENT_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis); -IMPLEMENT_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyObject ,Standard_Transient); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyCommand ,Standard_Transient); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesisReader,Standard_Transient); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyGen ,_pyObject); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyMesh ,_pyObject); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pySubMesh ,_pyObject); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyMeshEditor ,_pyObject); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyHypothesis ,_pyObject); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pySelfEraser ,_pyObject); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyGroup ,_pyObject); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyFilter ,_pyObject); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyAlgorithm ,_pyHypothesis); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyComplexParamHypo,_pyHypothesis); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyNumberOfSegmentsHyp,_pyHypothesis); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pyLayerDistributionHypo,_pyHypothesis); +OCCT_IMPLEMENT_STANDARD_RTTIEXT(_pySegmentLengthAroundVertexHyp,_pyHypothesis); using namespace std; using SMESH::TPythonDump; @@ -306,6 +290,10 @@ namespace { // - FT_EntityType = 36 // v 7.3.0: FT_Undefined == 46, new items: // - FT_ConnectedElements = 39 + // v 7.6.0: FT_Undefined == 47, new items: + // - FT_BelongToMeshGroup = 22 + // v 8.1.0: FT_Undefined == 48, new items: + // - FT_NodeConnectivityNumber= 22 // // It's necessary to continue recording this history and to fill // undef2newItems (see below) accordingly. @@ -326,6 +314,8 @@ namespace { undef2newItems[ 44 ].push_back( 37 ); undef2newItems[ 45 ].push_back( 36 ); undef2newItems[ 46 ].push_back( 39 ); + undef2newItems[ 47 ].push_back( 22 ); + undef2newItems[ 48 ].push_back( 22 ); ASSERT( undef2newItems.rbegin()->first == SMESH::FT_Undefined ); } @@ -384,6 +374,7 @@ namespace { "ExtrusionSweepObjectMakeGroups","ExtrusionSweepObject0D", "ExtrusionSweepObject1D","ExtrusionSweepObject1DMakeGroups", "ExtrusionSweepObject2D","ExtrusionSweepObject2DMakeGroups", + "ExtrusionSweepObjects","RotationSweepObjects","ExtrusionAlongPathObjects", "Translate","TranslateMakeGroups","TranslateMakeMesh", "TranslateObject","TranslateObjectMakeGroups", "TranslateObjectMakeMesh", "ExtrusionAlongPathX","ExtrusionAlongPathObjX","SplitHexahedraIntoPrisms" @@ -431,7 +422,8 @@ namespace { "ExportCGNS","ExportGMF", "Create0DElementsOnAllNodes","Reorient2D","QuadTo4Tri", "ScaleMakeGroups","Scale","ScaleMakeMesh", - "FindCoincidentNodesOnPartBut","DoubleElements" + "FindCoincidentNodesOnPartBut","DoubleElements", + "ExtrusionSweepObjects","RotationSweepObjects","ExtrusionAlongPathObjects" ,"" }; // <- mark of the end methodsAcceptingList.Insert( methodNames ); } @@ -687,6 +679,25 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand { //id_mesh->second->AddProcessedCmd( aCommand ); + // Wrap Export*() into try-except + if ( aCommand->MethodStartsFrom("Export")) + { + _AString tab = "\t"; + _AString indent = aCommand->GetIndentation(); + _AString tryStr = indent + "try:"; + _AString newCmd = indent + tab + ( aCommand->GetString().ToCString() + indent.Length() ); + _AString pasCmd = indent + tab + "pass"; // to keep valid if newCmd is erased + _AString excStr = indent + "except:"; + _AString msgStr = indent + "\tprint '"; msgStr += method + "() failed. Invalid file name?'"; + + myCommands.insert( --myCommands.end(), new _pyCommand( tryStr, myNbCommands )); + aCommand->Clear(); + aCommand->GetString() = newCmd; + aCommand->SetOrderNb( ++myNbCommands ); + myCommands.push_back( new _pyCommand( pasCmd, ++myNbCommands )); + myCommands.push_back( new _pyCommand( excStr, ++myNbCommands )); + myCommands.push_back( new _pyCommand( msgStr, ++myNbCommands )); + } // check for mesh editor object if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation _pyID editorID = aCommand->GetResultValue(); @@ -889,7 +900,7 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand { // set SMESH.GeometryType instead of a numerical Threshold const int nbTypes = SMESH::Geom_LAST; - const char* types[nbTypes] = { + const char* types[] = { "Geom_POINT", "Geom_EDGE", "Geom_TRIANGLE", "Geom_QUADRANGLE", "Geom_POLYGON", "Geom_TETRA", "Geom_PYRAMID", "Geom_HEXA", "Geom_PENTA", "Geom_HEXAGONAL_PRISM", "Geom_POLYHEDRA", "Geom_BALL" }; @@ -897,14 +908,14 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand Threshold = SMESH + types[ iGeom ]; #ifdef _DEBUG_ // is types complete? (compilation failure mains that enum GeometryType changed) - int _assert[( sizeof(types) / sizeof(const char*) == nbTypes ) ? 1 : -1 ]; + int _asrt[( sizeof(types) / sizeof(const char*) == nbTypes ) ? 2 : -1 ]; _asrt[0]=_asrt[1]; #endif } if (Type == "SMESH.FT_EntityType") { // set SMESH.EntityType instead of a numerical Threshold const int nbTypes = SMESH::Entity_Last; - const char* types[nbTypes] = { + const char* types[] = { "Entity_Node", "Entity_0D", "Entity_Edge", "Entity_Quad_Edge", "Entity_Triangle", "Entity_Quad_Triangle", "Entity_BiQuad_Triangle", "Entity_Quadrangle", "Entity_Quad_Quadrangle", "Entity_BiQuad_Quadrangle", @@ -916,8 +927,8 @@ Handle(_pyCommand) _pyGen::AddCommand( const TCollection_AsciiString& theCommand if ( -1 < iGeom && iGeom < nbTypes ) Threshold = SMESH + types[ iGeom ]; #ifdef _DEBUG_ - // is types complete? (compilation failure mains that enum EntityType changed) - int _assert[( sizeof(types) / sizeof(const char*) == nbTypes ) ? 1 : -1 ]; + // is 'types' complete? (compilation failure mains that enum EntityType changed) + int _asrt[( sizeof(types) / sizeof(const char*) == nbTypes ) ? 2 : -1 ]; _asrt[0]=_asrt[1]; #endif } } @@ -1507,9 +1518,10 @@ _pyID _pyGen::GenerateNewID( const _pyID& theID ) } while ( myObjectNames.IsBound( aNewID ) ); - myObjectNames.Bind( aNewID, myObjectNames.IsBound( theID ) - ? (myObjectNames.Find( theID ) + _pyID( "_" ) + _pyID( index-1 )) - : _pyID( "A" ) + aNewID ); + if ( myObjectNames.IsBound( theID ) ) + myObjectNames.Bind( aNewID, ( myObjectNames.Find( theID ) + _pyID( "_" ) + _pyID( index-1 ) ) ); + else + myObjectNames.Bind( aNewID, ( _pyID( "A" ) + aNewID ) ); return aNewID; } @@ -1555,8 +1567,11 @@ void _pyGen::CheckObjectIsReCreated( Handle(_pyObject)& theObj ) return; const bool isHyp = theObj->IsKind( STANDARD_TYPE( _pyHypothesis )); - Handle(_pyObject) existing = - isHyp ? FindHyp( theObj->GetID() ) : FindObject( theObj->GetID() ); + Handle(_pyObject) existing; + if( isHyp ) + existing = FindHyp( theObj->GetID() ); + else + existing = FindObject( theObj->GetID() ); if ( !existing.IsNull() && existing != theObj ) { existing->SetRemovedFromStudy( true ); @@ -1612,7 +1627,8 @@ Handle(_pyObject) _pyGen::FindObject( const _pyID& theObjID ) const return id_obj->second; } { - map< _pyID, Handle(_pyMesh) >::const_iterator id_obj = myMeshes.find( theObjID ); + _pyGen* me = const_cast< _pyGen* >( this ); + map< _pyID, Handle(_pyMesh) >::iterator id_obj = me->myMeshes.find( theObjID ); if ( id_obj != myMeshes.end() ) return id_obj->second; } @@ -1867,7 +1883,7 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand ) } } // ---------------------------------------------------------------------- - else if ( method == "GetSubMesh" ) { // collect submeshes of the mesh + else if ( method == "GetSubMesh" ) { // collect sub-meshes of the mesh Handle(_pySubMesh) subMesh = theGen->FindSubMesh( theCommand->GetResultValue() ); if ( !subMesh.IsNull() ) { subMesh->SetCreator( this ); @@ -1875,6 +1891,10 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand ) } } // ---------------------------------------------------------------------- + else if ( method == "GetSubMeshes" ) { // clear as the command does nothing (0023156) + theCommand->Clear(); + } + // ---------------------------------------------------------------------- else if ( method == "AddHypothesis" ) { // mesh.AddHypothesis(geom, HYPO ) myAddHypCmds.push_back( theCommand ); // set mesh to hypo @@ -1889,7 +1909,8 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand ) // ---------------------------------------------------------------------- else if ( method == "CreateGroup" || method == "CreateGroupFromGEOM" || - method == "CreateGroupFromFilter" ) + method == "CreateGroupFromFilter" || + method == "CreateDimGroup" ) { Handle(_pyGroup) group = new _pyGroup( theCommand ); myGroups.push_back( group ); @@ -1903,7 +1924,7 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand ) TCollection_AsciiString grIDs = theCommand->GetResultValue(); list< _pyID > idList = theCommand->GetStudyEntries( grIDs ); list< _pyID >::iterator grID = idList.begin(); - const int nbGroupsBefore = myGroups.size(); + const size_t nbGroupsBefore = myGroups.size(); Handle(_pyObject) obj; for ( ; grID != idList.end(); ++grID ) { @@ -2029,7 +2050,7 @@ void _pyMesh::Process( const Handle(_pyCommand)& theCommand ) { addCmd = *cmd; cmd = addHypCmds.erase( cmd ); - if ( !theGen->IsToKeepAllCommands() && CanClear() ) { + if ( !theGen->IsToKeepAllCommands() /*&& CanClear()*/ ) { addCmd->Clear(); theCommand->Clear(); } @@ -2100,8 +2121,8 @@ bool _pyMesh::NeedMeshAccess( const Handle(_pyCommand)& theCommand ) if ( sameMethods.empty() ) { const char * names[] = { "ExportDAT","ExportUNV","ExportSTL","ExportSAUV", "RemoveGroup","RemoveGroupWithContents", - "GetGroups","UnionGroups","IntersectGroups","CutGroups","GetLog","GetId","ClearLog", - "GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements", + "GetGroups","UnionGroups","IntersectGroups","CutGroups","CreateDimGroup","GetLog","GetId", + "ClearLog","GetStudyId","HasDuplicatedGroupNamesMED","GetMEDMesh","NbNodes","NbElements", "NbEdges","NbEdgesOfOrder","NbFaces","NbFacesOfOrder","NbTriangles", "NbTrianglesOfOrder","NbQuadrangles","NbQuadranglesOfOrder","NbPolygons","NbVolumes", "NbVolumesOfOrder","NbTetras","NbTetrasOfOrder","NbHexas","NbHexasOfOrder", @@ -2402,11 +2423,13 @@ void _pyMeshEditor::Process( const Handle(_pyCommand)& theCommand) "ConvertToQuadratic","ConvertFromQuadratic","RenumberNodes","RenumberElements", "RotationSweep","RotationSweepObject","RotationSweepObject1D","RotationSweepObject2D", "ExtrusionSweep","AdvancedExtrusion","ExtrusionSweepObject","ExtrusionSweepObject1D", - "ExtrusionSweepObject2D","ExtrusionAlongPath","ExtrusionAlongPathObject", + "ExtrusionByNormal", "ExtrusionSweepObject2D","ExtrusionAlongPath","ExtrusionAlongPathObject", "ExtrusionAlongPathX","ExtrusionAlongPathObject1D","ExtrusionAlongPathObject2D", + "ExtrusionSweepObjects","RotationSweepObjects","ExtrusionAlongPathObjects", "Mirror","MirrorObject","Translate","TranslateObject","Rotate","RotateObject", "FindCoincidentNodes","MergeNodes","FindEqualElements", "MergeElements","MergeEqualElements","SewFreeBorders","SewConformFreeBorders", + "FindCoincidentFreeBorders", "SewCoincidentFreeBorders", "SewBorderToSide","SewSideElements","ChangeElemNodes","GetLastCreatedNodes", "GetLastCreatedElems", "MirrorMakeMesh","MirrorObjectMakeMesh","TranslateMakeMesh","TranslateObjectMakeMesh", @@ -3104,7 +3127,7 @@ void _pyHypothesis::setCreationArg( const int argNb, const _AString& arg ) { if ( myCurCrMethod ) { - while ( myCurCrMethod->myArgs.size() < argNb ) + while ( (int) myCurCrMethod->myArgs.size() < argNb ) myCurCrMethod->myArgs.push_back( "None" ); if ( arg.IsEmpty() ) myCurCrMethod->myArgs[ argNb-1 ] = "None"; @@ -3171,7 +3194,7 @@ void _pyComplexParamHypo::Process( const Handle(_pyCommand)& theCommand) for ( ; type2meth != myAlgoType2CreationMethod.end(); ++type2meth ) { CreationMethod& crMethod = type2meth->second; - while ( crMethod.myArgs.size() < i+1 ) + while ( (int) crMethod.myArgs.size() < i+1 ) crMethod.myArgs.push_back( "[]" ); crMethod.myArgs[ i ] = theCommand->GetArg( 1 ); // arg value } @@ -3453,28 +3476,31 @@ bool _pySegmentLengthAroundVertexHyp::Addition2Creation( const Handle(_pyCommand _pyID vertex = theCmd->GetArg( 1 ); - // the problem here is that segment algo will not be found + // the problem here is that segment algo can be not found // by pyHypothesis::Addition2Creation() for , so we try to find // geometry where segment algorithm is assigned - Handle(_pyHypothesis) algo; _pyID geom = vertex; + Handle(_pyHypothesis) algo = theGen->FindAlgo( geom, theMeshID, this ); while ( algo.IsNull() && !geom.IsEmpty()) { // try to find geom as a father of geom = FatherID( geom ); algo = theGen->FindAlgo( geom, theMeshID, this ); } - if ( algo.IsNull() ) + if ( algo.IsNull() || geom.IsEmpty() ) return false; // also possible to find geom as brother of veretex... + // set geom instead of vertex theCmd->SetArg( 1, geom ); - // set vertex as a second arg - if ( myCurCrMethod->myArgs.size() < 1) setCreationArg( 1, "1" ); // :( - setCreationArg( 2, vertex ); - // mesh.AddHypothesis(vertex, SegmentLengthAroundVertex) --> - // theMeshID.LengthNearVertex( length, vertex ) - return _pyHypothesis::Addition2Creation( theCmd, theMeshID ); + // SegmentLengthAroundVertex = Regular_1D.LengthNearVertex( length ) + if ( _pyHypothesis::Addition2Creation( theCmd, theMeshID )) + { + // set vertex as a second arg + theCmd->SetArg( 2, vertex ); + + return true; + } } return false; } @@ -3556,11 +3582,11 @@ void _pyCommand::SetBegPos( int thePartIndex, int thePosition ) TCollection_AsciiString _pyCommand::GetIndentation() { int end = 1; - if ( GetBegPos( RESULT_IND ) == UNKNOWN ) - GetWord( myString, end, true ); - else - end = GetBegPos( RESULT_IND ); - return myString.SubString( 1, Max( end - 1, 1 )); + //while ( end <= Length() && isblank( myString.Value( end ))) + //ANA: isblank() function isn't provided in VC2010 compiler + while ( end <= Length() && ( myString.Value( end ) == ' ' || myString.Value( end ) == '\t') ) + ++end; + return ( end == 1 ) ? _AString("") : myString.SubString( 1, end - 1 ); } //================================================================================ @@ -3715,12 +3741,15 @@ const TCollection_AsciiString & _pyCommand::GetMethod() if ( GetBegPos( METHOD_IND ) == UNKNOWN ) { // beginning - int begPos = GetBegPos( OBJECT_IND ) + myObj.Length(); + int begPos = GetBegPos( OBJECT_IND ); bool forward = true; if ( begPos < 1 ) { begPos = myString.Location( "(", 1, Length() ) - 1; forward = false; } + else { + begPos += myObj.Length(); + } // store myMeth = GetWord( myString, begPos, forward ); SetBegPos( METHOD_IND, begPos );