From: eap Date: Mon, 17 Dec 2012 15:39:30 +0000 (+0000) Subject: Add missing try/catch using SMESH_TryCatch.hxx X-Git-Tag: pluginMGCleaner~233 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bd7cecec9a437150365ea95a1cc023791f9c2db5;p=modules%2Fsmesh.git Add missing try/catch using SMESH_TryCatch.hxx --- diff --git a/src/SMESH_I/SMESH_MeshEditor_i.cxx b/src/SMESH_I/SMESH_MeshEditor_i.cxx index e6cbf330f..02539efa5 100644 --- a/src/SMESH_I/SMESH_MeshEditor_i.cxx +++ b/src/SMESH_I/SMESH_MeshEditor_i.cxx @@ -81,6 +81,8 @@ #include #include +#include "SMESH_TryCatch.hxx" // include after OCCT headers! + #define cast2Node(elem) static_cast( elem ) using namespace std; @@ -856,6 +858,8 @@ CORBA::Long SMESH_MeshEditor_i::AddBall(CORBA::Long IDOfNode, CORBA::Double diam if ( diameter < std::numeric_limits::min() ) THROW_SALOME_CORBA_EXCEPTION("Invalid diameter", SALOME::BAD_PARAM); + SMESH_TRY; + const SMDS_MeshNode* aNode = getMeshDS()->FindNode(IDOfNode); SMDS_MeshElement* elem = getMeshDS()->AddBall(aNode, diameter); @@ -869,6 +873,8 @@ CORBA::Long SMESH_MeshEditor_i::AddBall(CORBA::Long IDOfNode, CORBA::Double diam if (elem) return elem->GetID(); + SMESH_CATCH( SMESH::throwCorbaException ); + return 0; } @@ -1137,6 +1143,8 @@ SMESH_MeshEditor_i::Create0DElementsOnAllNodes(SMESH::SMESH_IDSource_ptr theObje SMESH::SMESH_IDSource_var result; TPythonDump pyDump; + SMESH_TRY; + TIDSortedElemSet elements, elems0D; if ( idSourceToSet( theObject, getMeshDS(), elements, SMDSAbs_All, /*emptyIfIsMesh=*/1)) getEditor().Create0DElementsOnAllNodes( elements, elems0D ); @@ -1183,6 +1191,8 @@ SMESH_MeshEditor_i::Create0DElementsOnAllNodes(SMESH::SMESH_IDSource_ptr theObje pyDump << " = " << this << ".Create0DElementsOnAllNodes( " << theObject << ", '" << theGroupName << "' )"; + SMESH_CATCH( SMESH::throwCorbaException ); + return result._retn(); } @@ -6192,8 +6202,10 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li CORBA::Boolean createJointElems ) throw (SALOME::SALOME_Exception) { - initData(); + bool aResult = false; + SMESH_TRY; + initData(); SMESHDS_Mesh* aMeshDS = getMeshDS(); @@ -6215,7 +6227,7 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li } } - bool aResult = getEditor().DoubleNodesOnGroupBoundaries( domains, createJointElems ); + aResult = getEditor().DoubleNodesOnGroupBoundaries( domains, createJointElems ); // TODO publish the groups of flat elements in study myMesh->GetMeshDS()->Modified(); @@ -6223,6 +6235,9 @@ CORBA::Boolean SMESH_MeshEditor_i::DoubleNodesOnGroupBoundaries( const SMESH::Li // Update Python script TPythonDump() << "isDone = " << this << ".DoubleNodesOnGroupBoundaries( " << &theDomains << ", " << createJointElems << " )"; + + SMESH_CATCH( SMESH::throwCorbaException ); + return aResult; } @@ -6282,8 +6297,10 @@ void SMESH_MeshEditor_i::CreateHoleSkin(CORBA::Double radius, const char* groupName, const SMESH::double_array& theNodesCoords, SMESH::array_of_long_array_out GroupsOfNodes) -throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { + SMESH_TRY; + initData(); std::vector > aListOfListOfNodes; ::SMESH_MeshEditor aMeshEditor( myMesh ); @@ -6294,27 +6311,33 @@ throw (SALOME::SALOME_Exception) vector nodesCoords; for (int i = 0; i < theNodesCoords.length(); i++) - { - nodesCoords.push_back( theNodesCoords[i] ); + { + nodesCoords.push_back( theNodesCoords[i] ); } TopoDS_Shape aShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theShape ); - aMeshEditor.CreateHoleSkin(radius, aShape, theNodeSearcher, groupName, nodesCoords, aListOfListOfNodes); + aMeshEditor.CreateHoleSkin(radius, aShape, theNodeSearcher, groupName, + nodesCoords, aListOfListOfNodes); GroupsOfNodes = new SMESH::array_of_long_array; GroupsOfNodes->length( aListOfListOfNodes.size() ); std::vector >::iterator llIt = aListOfListOfNodes.begin(); for ( CORBA::Long i = 0; llIt != aListOfListOfNodes.end(); llIt++, i++ ) - { - vector& aListOfNodes = *llIt; - vector::iterator lIt = aListOfNodes.begin();; - SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ]; - aGroup.length( aListOfNodes.size() ); - for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ ) - aGroup[ j ] = (*lIt); - } + { + vector& aListOfNodes = *llIt; + vector::iterator lIt = aListOfNodes.begin();; + SMESH::long_array& aGroup = (*GroupsOfNodes)[ i ]; + aGroup.length( aListOfNodes.size() ); + for ( int j = 0; lIt != aListOfNodes.end(); lIt++, j++ ) + aGroup[ j ] = (*lIt); + } TPythonDump() << "lists_nodes = " << this << ".CreateHoleSkin( " - << radius << ", " << theShape << ", " << ", " << groupName << ", " << theNodesCoords << " )"; + << radius << ", " + << theShape + << ", '" << groupName << "', " + << theNodesCoords << " )"; + + SMESH_CATCH( SMESH::throwCorbaException ); } diff --git a/src/SMESH_I/SMESH_Mesh_i.cxx b/src/SMESH_I/SMESH_Mesh_i.cxx index d9a372db1..e81c3a7e7 100644 --- a/src/SMESH_I/SMESH_Mesh_i.cxx +++ b/src/SMESH_I/SMESH_Mesh_i.cxx @@ -55,7 +55,6 @@ #include #include #include -#include #include #include #include @@ -80,11 +79,14 @@ #include #include +#include "SMESH_TryCatch.hxx" // include after OCCT headers! + // STL Includes #include #include #include #include + #include #ifdef _DEBUG_ @@ -98,7 +100,6 @@ using SMESH::TPythonDump; int SMESH_Mesh_i::_idGenerator = 0; - //============================================================================= /*! * Constructor @@ -449,11 +450,15 @@ char* SMESH_Mesh_i::GetVersionString(SMESH::MED_VERSION version, CORBA::Short nb int SMESH_Mesh_i::ImportUNVFile( const char* theFileName ) throw ( SALOME::SALOME_Exception ) { + SMESH_TRY; + // Read mesh with name = into SMESH_Mesh _impl->UNVToMesh( theFileName ); CreateGroupServants(); + SMESH_CATCH( SMESH::throwCorbaException ); + return 1; } @@ -467,12 +472,30 @@ int SMESH_Mesh_i::ImportUNVFile( const char* theFileName ) int SMESH_Mesh_i::ImportSTLFile( const char* theFileName ) throw ( SALOME::SALOME_Exception ) { + SMESH_TRY; + // Read mesh with name = into SMESH_Mesh _impl->STLToMesh( theFileName ); + SMESH_CATCH( SMESH::throwCorbaException ); + return 1; } +//================================================================================ +/*! + * \brief Function used in SMESH_CATCH by ImportGMFFile() + */ +//================================================================================ + +namespace +{ + SMESH_ComputeErrorPtr exceptionToComputeError(const char* excText) + { + return SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, excText ); + } +} + //================================================================================ /*! * \brief Imports data from a GMF file and returns an error description @@ -484,29 +507,16 @@ SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName, throw (SALOME::SALOME_Exception) { SMESH_ComputeErrorPtr error; - try { - error = _impl->GMFToMesh( theFileName, theMakeRequiredGroups ); - } - catch ( std::bad_alloc& exc ) { - error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "std::bad_alloc raised" ); - } - catch ( Standard_OutOfMemory& exc ) { - error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "Standard_OutOfMemory raised" ); - } - catch (Standard_Failure& ex) { - error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, ex.DynamicType()->Name() ); - if ( ex.GetMessageString() && strlen( ex.GetMessageString() )) - error->myComment += string(": ") + ex.GetMessageString(); - } - catch ( SALOME_Exception& S_ex ) { - error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, S_ex.what() ); - } - catch ( std::exception& exc ) { - error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, exc.what() ); - } - catch (...) { - error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "Unknown exception" ); - } + +#undef SMESH_CAUGHT +#define SMESH_CAUGHT error = + SMESH_TRY; + + error = _impl->GMFToMesh( theFileName, theMakeRequiredGroups ); + + SMESH_CATCH( exceptionToComputeError ); +#undef SMESH_CAUGHT +#define SMESH_CAUGHT CreateGroupServants(); @@ -846,7 +856,8 @@ SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetSubMesh(GEOM::GEOM_Object_ptr aSubShap void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh ) throw (SALOME::SALOME_Exception) { - if(MYDEBUG) MESSAGE("SMESH_Mesh_i::RemoveSubMesh"); + SMESH_TRY; + if ( theSubMesh->_is_nil() ) return; @@ -878,6 +889,8 @@ void SMESH_Mesh_i::RemoveSubMesh( SMESH::SMESH_subMesh_ptr theSubMesh ) if ( removeSubMesh( theSubMesh, aSubShapeObject.in() )) if ( _preMeshInfo ) _preMeshInfo->ForgetOrLoad(); + + SMESH_CATCH( SMESH::throwCorbaException ); } //============================================================================= @@ -1010,6 +1023,8 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup ) if ( theGroup->_is_nil() ) return; + SMESH_TRY; + SMESH_GroupBase_i* aGroup = dynamic_cast( SMESH_Gen_i::GetServant( theGroup ).in() ); if ( !aGroup ) @@ -1031,6 +1046,8 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup ) // Remove the group from SMESH data structures removeGroup( aGroup->GetLocalID() ); + + SMESH_CATCH( SMESH::throwCorbaException ); } //============================================================================= @@ -1042,6 +1059,7 @@ void SMESH_Mesh_i::RemoveGroup( SMESH::SMESH_GroupBase_ptr theGroup ) void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup ) throw (SALOME::SALOME_Exception) { + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); @@ -1069,6 +1087,8 @@ void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup // Remove group RemoveGroup( theGroup ); + + SMESH_CATCH( SMESH::throwCorbaException ); } //================================================================================ @@ -1137,60 +1157,58 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr the const char* theName ) throw (SALOME::SALOME_Exception) { + SMESH::SMESH_Group_var aResGrp; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - try - { - if ( theGroup1->_is_nil() || theGroup2->_is_nil() || - theGroup1->GetType() != theGroup2->GetType() ) - return SMESH::SMESH_Group::_nil(); + if ( theGroup1->_is_nil() || theGroup2->_is_nil() || + theGroup1->GetType() != theGroup2->GetType() ) + return SMESH::SMESH_Group::_nil(); - TPythonDump pyDump; + TPythonDump pyDump; - // Create Union - SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName ); - if ( aResGrp->_is_nil() ) - return SMESH::SMESH_Group::_nil(); + // Create Union + aResGrp = CreateGroup( theGroup1->GetType(), theName ); + if ( aResGrp->_is_nil() ) + return SMESH::SMESH_Group::_nil(); - SMESH::long_array_var anIds1 = theGroup1->GetListOfID(); - SMESH::long_array_var anIds2 = theGroup2->GetListOfID(); + SMESH::long_array_var anIds1 = theGroup1->GetListOfID(); + SMESH::long_array_var anIds2 = theGroup2->GetListOfID(); - TColStd_MapOfInteger aResMap; + TColStd_MapOfInteger aResMap; - for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ ) - aResMap.Add( anIds1[ i1 ] ); + for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ ) + aResMap.Add( anIds1[ i1 ] ); - for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ ) - aResMap.Add( anIds2[ i2 ] ); + for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ ) + aResMap.Add( anIds2[ i2 ] ); - SMESH::long_array_var aResIds = new SMESH::long_array; - aResIds->length( aResMap.Extent() ); + SMESH::long_array_var aResIds = new SMESH::long_array; + aResIds->length( aResMap.Extent() ); - int resI = 0; - TColStd_MapIteratorOfMapOfInteger anIter( aResMap ); - for( ; anIter.More(); anIter.Next() ) - aResIds[ resI++ ] = anIter.Key(); + int resI = 0; + TColStd_MapIteratorOfMapOfInteger anIter( aResMap ); + for( ; anIter.More(); anIter.Next() ) + aResIds[ resI++ ] = anIter.Key(); - aResGrp->Add( aResIds ); + aResGrp->Add( aResIds ); - // Update Python script - pyDump << aResGrp << " = " << _this() << ".UnionGroups( " - << theGroup1 << ", " << theGroup2 << ", '" - << theName << "' )"; + // Update Python script + pyDump << aResGrp << " = " << _this() << ".UnionGroups( " + << theGroup1 << ", " << theGroup2 << ", '" + << theName << "' )"; - return aResGrp._retn(); - } - catch( ... ) - { - return SMESH::SMESH_Group::_nil(); - } + SMESH_CATCH( SMESH::throwCorbaException ); + + return aResGrp._retn(); } //============================================================================= /*! \brief Union list of groups. New group is created. All mesh elements that are - present in initial groups are added to the new one. + present in initial groups are added to the new one. \param theGroups list of groups \param theName name of group to be created \return pointer on the group @@ -1198,7 +1216,7 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr the //============================================================================= SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups, const char* theName ) -throw (SALOME::SALOME_Exception) + throw (SALOME::SALOME_Exception) { if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); @@ -1206,60 +1224,59 @@ throw (SALOME::SALOME_Exception) if ( !theName ) return SMESH::SMESH_Group::_nil(); - try + SMESH::SMESH_Group_var aResGrp; + + SMESH_TRY; + + vector< int > anIds; + SMESH::ElementType aType = SMESH::ALL; + for ( int g = 0, n = theGroups.length(); g < n; g++ ) { - vector< int > anIds; - SMESH::ElementType aType = SMESH::ALL; - for ( int g = 0, n = theGroups.length(); g < n; g++ ) - { - SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ]; - if ( CORBA::is_nil( aGrp ) ) - continue; + SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ]; + if ( CORBA::is_nil( aGrp ) ) + continue; - // check type - SMESH::ElementType aCurrType = aGrp->GetType(); - if ( aType == SMESH::ALL ) - aType = aCurrType; - else - { - if ( aType != aCurrType ) - return SMESH::SMESH_Group::_nil(); - } + // check type + SMESH::ElementType aCurrType = aGrp->GetType(); + if ( aType == SMESH::ALL ) + aType = aCurrType; + else + { + if ( aType != aCurrType ) + return SMESH::SMESH_Group::_nil(); + } - // unite ids - SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); - for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) - { - int aCurrId = aCurrIds[ i ]; - anIds.push_back( aCurrId ); - } + // unite ids + SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); + for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) + { + int aCurrId = aCurrIds[ i ]; + anIds.push_back( aCurrId ); } + } - TPythonDump pyDump; + TPythonDump pyDump; - // Create group - SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName ); - if ( aResGrp->_is_nil() ) - return SMESH::SMESH_Group::_nil(); - - // Create array of identifiers - SMESH::long_array_var aResIds = new SMESH::long_array; - aResIds->length( anIds.size() ); - - for ( size_t i = 0; iAdd( aResIds ); + // Create group + aResGrp = CreateGroup( aType, theName ); + if ( aResGrp->_is_nil() ) + return SMESH::SMESH_Group::_nil(); - // Update Python script - pyDump << aResGrp << " = " << _this() << ".UnionListOfGroups( " - << &theGroups << ", '" << theName << "' )"; + // Create array of identifiers + SMESH::long_array_var aResIds = new SMESH::long_array; + aResIds->length( anIds.size() ); - return aResGrp._retn(); - } - catch( ... ) - { - return SMESH::SMESH_Group::_nil(); - } + for ( size_t i = 0; iAdd( aResIds ); + + // Update Python script + pyDump << aResGrp << " = " << _this() << ".UnionListOfGroups( " + << &theGroups << ", '" << theName << "' )"; + + SMESH_CATCH( SMESH::throwCorbaException ); + + return aResGrp._retn(); } //============================================================================= @@ -1273,6 +1290,9 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr const char* theName ) throw (SALOME::SALOME_Exception) { + SMESH::SMESH_Group_var aResGrp; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); @@ -1283,7 +1303,7 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr TPythonDump pyDump; // Create Intersection - SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName ); + aResGrp = CreateGroup( theGroup1->GetType(), theName ); if ( aResGrp->_is_nil() ) return aResGrp; @@ -1310,6 +1330,8 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr pyDump << aResGrp << " = " << _this() << ".IntersectGroups( " << theGroup1 << ", " << theGroup2 << ", '" << theName << "')"; + SMESH_CATCH( SMESH::throwCorbaException ); + return aResGrp._retn(); } @@ -1327,81 +1349,79 @@ SMESH_Mesh_i::IntersectListOfGroups(const SMESH::ListOfGroups& theGroups, const char* theName ) throw (SALOME::SALOME_Exception) { + SMESH::SMESH_Group_var aResGrp; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); if ( !theName ) return SMESH::SMESH_Group::_nil(); - try + NCollection_DataMap< int, int > anIdToCount; + SMESH::ElementType aType = SMESH::ALL; + for ( int g = 0, n = theGroups.length(); g < n; g++ ) { - NCollection_DataMap< int, int > anIdToCount; - SMESH::ElementType aType = SMESH::ALL; - for ( int g = 0, n = theGroups.length(); g < n; g++ ) - { - SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ]; - if ( CORBA::is_nil( aGrp ) ) - continue; - - // check type - SMESH::ElementType aCurrType = aGrp->GetType(); - if ( aType == SMESH::ALL ) - aType = aCurrType; - else - { - if ( aType != aCurrType ) - return SMESH::SMESH_Group::_nil(); - } + SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ]; + if ( CORBA::is_nil( aGrp ) ) + continue; - // calculates number of occurance ids in groups - SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); - for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) - { - int aCurrId = aCurrIds[ i ]; - if ( !anIdToCount.IsBound( aCurrId ) ) - anIdToCount.Bind( aCurrId, 1 ); - else - anIdToCount( aCurrId ) = anIdToCount( aCurrId ) + 1; - } - } - - // create map of ids - int nbGrp = theGroups.length(); - vector< int > anIds; - NCollection_DataMap< int, int >::Iterator anIter( anIdToCount ); - for ( ; anIter.More(); anIter.Next() ) + // check type + SMESH::ElementType aCurrType = aGrp->GetType(); + if ( aType == SMESH::ALL ) + aType = aCurrType; + else { - int aCurrId = anIter.Key(); - int aCurrNb = anIter.Value(); - if ( aCurrNb == nbGrp ) - anIds.push_back( aCurrId ); + if ( aType != aCurrType ) + return SMESH::SMESH_Group::_nil(); } - TPythonDump pyDump; + // calculates number of occurance ids in groups + SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); + for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) + { + int aCurrId = aCurrIds[ i ]; + if ( !anIdToCount.IsBound( aCurrId ) ) + anIdToCount.Bind( aCurrId, 1 ); + else + anIdToCount( aCurrId ) = anIdToCount( aCurrId ) + 1; + } + } - // Create group - SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName ); - if ( aResGrp->_is_nil() ) - return SMESH::SMESH_Group::_nil(); - - // Create array of identifiers - SMESH::long_array_var aResIds = new SMESH::long_array; - aResIds->length( anIds.size() ); - - for ( size_t i = 0; iAdd( aResIds ); + // create map of ids + int nbGrp = theGroups.length(); + vector< int > anIds; + NCollection_DataMap< int, int >::Iterator anIter( anIdToCount ); + for ( ; anIter.More(); anIter.Next() ) + { + int aCurrId = anIter.Key(); + int aCurrNb = anIter.Value(); + if ( aCurrNb == nbGrp ) + anIds.push_back( aCurrId ); + } - // Update Python script - pyDump << aResGrp << " = " << _this() << ".IntersectListOfGroups( " - << &theGroups << ", '" << theName << "' )"; + TPythonDump pyDump; - return aResGrp._retn(); - } - catch( ... ) - { + // Create group + aResGrp = CreateGroup( aType, theName ); + if ( aResGrp->_is_nil() ) return SMESH::SMESH_Group::_nil(); - } + + // Create array of identifiers + SMESH::long_array_var aResIds = new SMESH::long_array; + aResIds->length( anIds.size() ); + + for ( size_t i = 0; iAdd( aResIds ); + + // Update Python script + pyDump << aResGrp << " = " << _this() << ".IntersectListOfGroups( " + << &theGroups << ", '" << theName << "' )"; + + SMESH_CATCH( SMESH::throwCorbaException ); + + return aResGrp._retn(); } //============================================================================= @@ -1415,6 +1435,9 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr const char* theName ) throw (SALOME::SALOME_Exception) { + SMESH::SMESH_Group_var aResGrp; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); @@ -1425,7 +1448,7 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr TPythonDump pyDump; // Perform Cutting - SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName ); + aResGrp = CreateGroup( theGroup1->GetType(), theName ); if ( aResGrp->_is_nil() ) return aResGrp; @@ -1454,6 +1477,8 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGr << theGroup1 << ", " << theGroup2 << ", '" << theName << "' )"; + SMESH_CATCH( SMESH::throwCorbaException ); + return aResGrp._retn(); } @@ -1473,104 +1498,102 @@ SMESH_Mesh_i::CutListOfGroups(const SMESH::ListOfGroups& theMainGroups, const char* theName ) throw (SALOME::SALOME_Exception) { + SMESH::SMESH_Group_var aResGrp; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); if ( !theName ) return SMESH::SMESH_Group::_nil(); - try + set< int > aToolIds; + SMESH::ElementType aType = SMESH::ALL; + int g, n; + // iterate through tool groups + for ( g = 0, n = theToolGroups.length(); g < n; g++ ) { - set< int > aToolIds; - SMESH::ElementType aType = SMESH::ALL; - int g, n; - // iterate through tool groups - for ( g = 0, n = theToolGroups.length(); g < n; g++ ) - { - SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ]; - if ( CORBA::is_nil( aGrp ) ) - continue; - - // check type - SMESH::ElementType aCurrType = aGrp->GetType(); - if ( aType == SMESH::ALL ) - aType = aCurrType; - else - { - if ( aType != aCurrType ) - return SMESH::SMESH_Group::_nil(); - } + SMESH::SMESH_GroupBase_var aGrp = theToolGroups[ g ]; + if ( CORBA::is_nil( aGrp ) ) + continue; - // unite tool ids - SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); - for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) - { - int aCurrId = aCurrIds[ i ]; - aToolIds.insert( aCurrId ); - } + // check type + SMESH::ElementType aCurrType = aGrp->GetType(); + if ( aType == SMESH::ALL ) + aType = aCurrType; + else + { + if ( aType != aCurrType ) + return SMESH::SMESH_Group::_nil(); } - vector< int > anIds; // result - - // Iterate through main group - for ( g = 0, n = theMainGroups.length(); g < n; g++ ) + // unite tool ids + SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); + for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) { - SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ]; - if ( CORBA::is_nil( aGrp ) ) - continue; + int aCurrId = aCurrIds[ i ]; + aToolIds.insert( aCurrId ); + } + } - // check type - SMESH::ElementType aCurrType = aGrp->GetType(); - if ( aType == SMESH::ALL ) - aType = aCurrType; - else - { - if ( aType != aCurrType ) - return SMESH::SMESH_Group::_nil(); - } + vector< int > anIds; // result - // unite tool ids - SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); - for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) - { - int aCurrId = aCurrIds[ i ]; - if ( !aToolIds.count( aCurrId ) ) - anIds.push_back( aCurrId ); - } + // Iterate through main group + for ( g = 0, n = theMainGroups.length(); g < n; g++ ) + { + SMESH::SMESH_GroupBase_var aGrp = theMainGroups[ g ]; + if ( CORBA::is_nil( aGrp ) ) + continue; + + // check type + SMESH::ElementType aCurrType = aGrp->GetType(); + if ( aType == SMESH::ALL ) + aType = aCurrType; + else + { + if ( aType != aCurrType ) + return SMESH::SMESH_Group::_nil(); } - TPythonDump pyDump; + // unite tool ids + SMESH::long_array_var aCurrIds = aGrp->GetListOfID(); + for ( int i = 0, n = aCurrIds->length(); i < n; i++ ) + { + int aCurrId = aCurrIds[ i ]; + if ( !aToolIds.count( aCurrId ) ) + anIds.push_back( aCurrId ); + } + } - // Create group - SMESH::SMESH_Group_var aResGrp = CreateGroup( aType, theName ); - if ( aResGrp->_is_nil() ) - return SMESH::SMESH_Group::_nil(); - - // Create array of identifiers - SMESH::long_array_var aResIds = new SMESH::long_array; - aResIds->length( anIds.size() ); - - for (int i=0; iAdd( aResIds ); + TPythonDump pyDump; - // Update Python script - pyDump << aResGrp << " = " << _this() << ".CutListOfGroups( " - << &theMainGroups << ", " << &theToolGroups << ", '" - << theName << "' )"; - - return aResGrp._retn(); - } - catch( ... ) - { + // Create group + aResGrp = CreateGroup( aType, theName ); + if ( aResGrp->_is_nil() ) return SMESH::SMESH_Group::_nil(); - } + + // Create array of identifiers + SMESH::long_array_var aResIds = new SMESH::long_array; + aResIds->length( anIds.size() ); + + for (int i=0; iAdd( aResIds ); + + // Update Python script + pyDump << aResGrp << " = " << _this() << ".CutListOfGroups( " + << &theMainGroups << ", " << &theToolGroups << ", '" + << theName << "' )"; + + SMESH_CATCH( SMESH::throwCorbaException ); + + return aResGrp._retn(); } //============================================================================= /*! \brief Create groups of entities from existing groups of superior dimensions - System + System 1) extract all nodes from each group, 2) combine all elements of specified dimension laying on these nodes. \param theGroups list of source groups @@ -1588,6 +1611,9 @@ SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups, const char* theName ) throw (SALOME::SALOME_Exception) { + SMESH::SMESH_Group_var aResGrp; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); @@ -1602,7 +1628,7 @@ SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups, TPythonDump pyDump; - SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, theName ); + aResGrp = CreateGroup( theElemType, theName ); if ( aResGrp->_is_nil() ) return SMESH::SMESH_Group::_nil(); @@ -1610,66 +1636,61 @@ SMESH_Mesh_i::CreateDimGroup(const SMESH::ListOfGroups& theGroups, SMESH::DownCast( aResGrp )->GetGroupDS(); SMDS_MeshGroup& resGroupCore = static_cast< SMESHDS_Group* >( groupBaseDS )->SMDSGroup(); - try + for ( int g = 0, n = theGroups.length(); g < n; g++ ) // loop on theGroups { - for ( int g = 0, n = theGroups.length(); g < n; g++ ) // loop on theGroups - { - SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ]; - if ( CORBA::is_nil( aGrp ) ) - continue; + SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ]; + if ( CORBA::is_nil( aGrp ) ) + continue; - groupBaseDS = SMESH::DownCast( aGrp )->GetGroupDS(); - SMDS_ElemIteratorPtr elIt = groupBaseDS->GetElements(); + groupBaseDS = SMESH::DownCast( aGrp )->GetGroupDS(); + SMDS_ElemIteratorPtr elIt = groupBaseDS->GetElements(); - if ( theElemType == SMESH::NODE ) // get all nodes of elements - { - while ( elIt->more() ) { - const SMDS_MeshElement* el = elIt->next(); - SMDS_ElemIteratorPtr nIt = el->nodesIterator(); - while ( nIt->more() ) - resGroupCore.Add( nIt->next() ); - } + if ( theElemType == SMESH::NODE ) // get all nodes of elements + { + while ( elIt->more() ) { + const SMDS_MeshElement* el = elIt->next(); + SMDS_ElemIteratorPtr nIt = el->nodesIterator(); + while ( nIt->more() ) + resGroupCore.Add( nIt->next() ); } - else // get elements of theElemType based on nodes of every element of group + } + else // get elements of theElemType based on nodes of every element of group + { + while ( elIt->more() ) { - while ( elIt->more() ) + const SMDS_MeshElement* el = elIt->next(); // an element of group + TIDSortedElemSet elNodes( el->begin_nodes(), el->end_nodes() ); + TIDSortedElemSet checkedElems; + SMDS_ElemIteratorPtr nIt = el->nodesIterator(); + while ( nIt->more() ) { - const SMDS_MeshElement* el = elIt->next(); // an element of group - TIDSortedElemSet elNodes( el->begin_nodes(), el->end_nodes() ); - TIDSortedElemSet checkedElems; - SMDS_ElemIteratorPtr nIt = el->nodesIterator(); - while ( nIt->more() ) + const SMDS_MeshNode* n = static_cast( nIt->next() ); + SMDS_ElemIteratorPtr elOfTypeIt = n->GetInverseElementIterator( anElemType ); + // check nodes of elements of theElemType around el + while ( elOfTypeIt->more() ) { - const SMDS_MeshNode* n = static_cast( nIt->next() ); - SMDS_ElemIteratorPtr elOfTypeIt = n->GetInverseElementIterator( anElemType ); - // check nodes of elements of theElemType around el - while ( elOfTypeIt->more() ) - { - const SMDS_MeshElement* elOfType = elOfTypeIt->next(); - if ( !checkedElems.insert( elOfType ).second ) continue; - - SMDS_ElemIteratorPtr nIt2 = elOfType->nodesIterator(); - bool allNodesOK = true; - while ( nIt2->more() && allNodesOK ) - allNodesOK = elNodes.count( nIt2->next() ); - if ( allNodesOK ) - resGroupCore.Add( elOfType ); - } + const SMDS_MeshElement* elOfType = elOfTypeIt->next(); + if ( !checkedElems.insert( elOfType ).second ) continue; + + SMDS_ElemIteratorPtr nIt2 = elOfType->nodesIterator(); + bool allNodesOK = true; + while ( nIt2->more() && allNodesOK ) + allNodesOK = elNodes.count( nIt2->next() ); + if ( allNodesOK ) + resGroupCore.Add( elOfType ); } } } } + } - // Update Python script - pyDump << aResGrp << " = " << _this() << ".CreateDimGroup( " - << &theGroups << ", " << theElemType << ", '" << theName << "' )"; + // Update Python script + pyDump << aResGrp << " = " << _this() << ".CreateDimGroup( " + << &theGroups << ", " << theElemType << ", '" << theName << "' )"; - return aResGrp._retn(); - } - catch( ... ) - { - return SMESH::SMESH_Group::_nil(); - } + SMESH_CATCH( SMESH::throwCorbaException ); + + return aResGrp._retn(); } //================================================================================ @@ -2034,16 +2055,18 @@ void SMESH_Mesh_i::CheckGeomGroupModif() //============================================================================= SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase_ptr theGroup ) + throw (SALOME::SALOME_Exception) { + SMESH::SMESH_Group_var aGroup; + + SMESH_TRY; + if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESH::SMESH_Group_var aGroup; if ( theGroup->_is_nil() ) return aGroup._retn(); - Unexpect aCatch(SALOME_SalomeException); - SMESH_GroupBase_i* aGroupToRem = dynamic_cast( SMESH_Gen_i::GetServant( theGroup ).in() ); if ( !aGroupToRem ) @@ -2105,6 +2128,8 @@ SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase CORBA::String_var ior = _gen_i->GetORB()->object_to_string( aGroup ); builder->SetIOR( aGroupSO, ior.in() ); + SMESH_CATCH( SMESH::throwCorbaException ); + return aGroup._retn(); } @@ -2287,57 +2312,57 @@ void SMESH_Mesh_i::removeGroup( const int theId ) //============================================================================= SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet) -throw(SALOME::SALOME_Exception) + throw(SALOME::SALOME_Exception) { + SMESH::log_array_var aLog; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESH::log_array_var aLog; - try{ - list < SMESHDS_Command * >logDS = _impl->GetLog(); - aLog = new SMESH::log_array; - int indexLog = 0; - int lg = logDS.size(); - SCRUTE(lg); - aLog->length(lg); - list < SMESHDS_Command * >::iterator its = logDS.begin(); - while(its != logDS.end()){ - SMESHDS_Command *com = *its; - int comType = com->GetType(); - //SCRUTE(comType); - int lgcom = com->GetNumber(); - //SCRUTE(lgcom); - const list < int >&intList = com->GetIndexes(); - int inum = intList.size(); - //SCRUTE(inum); - list < int >::const_iterator ii = intList.begin(); - const list < double >&coordList = com->GetCoords(); - int rnum = coordList.size(); - //SCRUTE(rnum); - list < double >::const_iterator ir = coordList.begin(); - aLog[indexLog].commandType = comType; - aLog[indexLog].number = lgcom; - aLog[indexLog].coords.length(rnum); - aLog[indexLog].indexes.length(inum); - for(int i = 0; i < rnum; i++){ - aLog[indexLog].coords[i] = *ir; - //MESSAGE(" "<logDS = _impl->GetLog(); + aLog = new SMESH::log_array; + int indexLog = 0; + int lg = logDS.size(); + SCRUTE(lg); + aLog->length(lg); + list < SMESHDS_Command * >::iterator its = logDS.begin(); + while(its != logDS.end()){ + SMESHDS_Command *com = *its; + int comType = com->GetType(); + //SCRUTE(comType); + int lgcom = com->GetNumber(); + //SCRUTE(lgcom); + const list < int >&intList = com->GetIndexes(); + int inum = intList.size(); + //SCRUTE(inum); + list < int >::const_iterator ii = intList.begin(); + const list < double >&coordList = com->GetCoords(); + int rnum = coordList.size(); + //SCRUTE(rnum); + list < double >::const_iterator ir = coordList.begin(); + aLog[indexLog].commandType = comType; + aLog[indexLog].number = lgcom; + aLog[indexLog].coords.length(rnum); + aLog[indexLog].indexes.length(inum); + for(int i = 0; i < rnum; i++){ + aLog[indexLog].coords[i] = *ir; + //MESSAGE(" "<ClearLog(); - } - catch(SALOME_Exception & S_ex){ - THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM); + for(int i = 0; i < inum; i++){ + aLog[indexLog].indexes[i] = *ii; + //MESSAGE(" "<ClearLog(); + + SMESH_CATCH( SMESH::throwCorbaException ); + return aLog._retn(); } @@ -2350,8 +2375,9 @@ throw(SALOME::SALOME_Exception) void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception) { - if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog"); + SMESH_TRY; _impl->ClearLog(); + SMESH_CATCH( SMESH::throwCorbaException ); } //============================================================================= @@ -2362,7 +2388,6 @@ void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception) CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception) { - if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId"); return _id; } @@ -2438,18 +2463,24 @@ void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl) //============================================================================= SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor() + throw (SALOME::SALOME_Exception) { + SMESH::SMESH_MeshEditor_var aMeshEdVar; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); // Create MeshEditor SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false ); - SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this(); + aMeshEdVar = aMeshEditor->_this(); // Update Python script TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()"; - return aMesh._retn(); + SMESH_CATCH( SMESH::throwCorbaException ); + + return aMeshEdVar._retn(); } //============================================================================= @@ -2459,13 +2490,20 @@ SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor() //============================================================================= SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer() + throw (SALOME::SALOME_Exception) { + SMESH::SMESH_MeshEditor_var aMeshEdVar; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true ); - SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this(); - return aMesh._retn(); + aMeshEdVar = aMeshEditor->_this(); + + SMESH_CATCH( SMESH::throwCorbaException ); + + return aMeshEdVar._retn(); } //================================================================================ @@ -3374,10 +3412,17 @@ SMESH::long_array* SMESH_Mesh_i::GetNodesId() SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem ) throw (SALOME::SALOME_Exception) { + SMESH::ElementType type; + SMESH_TRY; + if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - return ( SMESH::ElementType )_impl->GetElementType( id, iselem ); + type = ( SMESH::ElementType ) _impl->GetElementType( id, iselem ); + + SMESH_CATCH( SMESH::throwCorbaException ); + + return type; } //============================================================================= @@ -3407,11 +3452,12 @@ SMESH::EntityType SMESH_Mesh_i::GetElementGeomType( const CORBA::Long id ) SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID) throw (SALOME::SALOME_Exception) { + SMESH::long_array_var aResult = new SMESH::long_array(); + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESH::long_array_var aResult = new SMESH::long_array(); - SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID); if(!SM) return aResult._retn(); @@ -3426,6 +3472,8 @@ SMESH::long_array* SMESH_Mesh_i::GetSubMeshElementsId(const CORBA::Long ShapeID) aResult[i++] = eIt->next()->GetID(); } + SMESH_CATCH( SMESH::throwCorbaException ); + return aResult._retn(); } @@ -3441,11 +3489,12 @@ SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, CORBA::Boolean all) throw (SALOME::SALOME_Exception) { + SMESH::long_array_var aResult = new SMESH::long_array(); + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); - SMESH::long_array_var aResult = new SMESH::long_array(); - SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID); if(!SM) return aResult._retn(); @@ -3478,6 +3527,8 @@ SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ ) aResult[i++] = *itElem; + SMESH_CATCH( SMESH::throwCorbaException ); + return aResult._retn(); } @@ -3490,6 +3541,9 @@ SMESH::long_array* SMESH_Mesh_i::GetSubMeshNodesId(const CORBA::Long ShapeID, SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID) throw (SALOME::SALOME_Exception) { + SMESH::ElementType type; + + SMESH_TRY; if ( _preMeshInfo ) _preMeshInfo->FullLoadFromFile(); @@ -3504,7 +3558,12 @@ SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID SMDS_ElemIteratorPtr eIt = SDSM->GetElements(); const SMDS_MeshElement* anElem = eIt->next(); - return ( SMESH::ElementType ) anElem->GetType(); + + type = ( SMESH::ElementType ) anElem->GetType(); + + SMESH_CATCH( SMESH::throwCorbaException ); + + return type; }