X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_I%2FSMESH_2smeshpy.cxx;h=416f43b6f1df5ceb9d7ca1d517b128a183ed2923;hp=bb9106fe61d50a0bf7216948f460dd3d043b8898;hb=ef3921b2afe32874a6a266ceea8a12a30cc6f17c;hpb=02ac54c6f33c5437c1d2204d704cf3da6fd31a8e diff --git a/src/SMESH_I/SMESH_2smeshpy.cxx b/src/SMESH_I/SMESH_2smeshpy.cxx index bb9106fe6..416f43b6f 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; @@ -692,6 +676,23 @@ 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 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( excStr, ++myNbCommands )); + myCommands.push_back( new _pyCommand( msgStr, ++myNbCommands )); + } // check for mesh editor object if ( aCommand->GetMethod() == "GetMeshEditor" ) { // MeshEditor creation _pyID editorID = aCommand->GetResultValue(); @@ -894,7 +895,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" }; @@ -902,14 +903,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", @@ -921,8 +922,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 } } @@ -1512,9 +1513,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; } @@ -1560,8 +1562,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 = Handle(_pyObject)::DownCast( FindHyp( theObj->GetID() ) ); + else + existing = FindObject( theObj->GetID() ); if ( !existing.IsNull() && existing != theObj ) { existing->SetRemovedFromStudy( true ); @@ -1619,7 +1624,7 @@ Handle(_pyObject) _pyGen::FindObject( const _pyID& theObjID ) const { map< _pyID, Handle(_pyMesh) >::const_iterator id_obj = myMeshes.find( theObjID ); if ( id_obj != myMeshes.end() ) - return id_obj->second; + return Handle(_pyObject)::DownCast( id_obj->second ); } // { // map< _pyID, Handle(_pyMeshEditor) >::const_iterator id_obj = myMeshEditors.find( theObjID ); @@ -1880,6 +1885,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 @@ -1909,7 +1918,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 ) { @@ -3112,7 +3121,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"; @@ -3179,7 +3188,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 } @@ -3564,11 +3573,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 ); } //================================================================================ @@ -3723,12 +3732,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 );