+ // Remove the group from SMESH data structures
+ removeGroup( aGroup->GetLocalID() );
+}
+
+//=============================================================================
+/*! RemoveGroupWithContents
+ * Remove group with its contents
+ */
+//=============================================================================
+void SMESH_Mesh_i::RemoveGroupWithContents( SMESH::SMESH_GroupBase_ptr theGroup )
+ throw (SALOME::SALOME_Exception)
+{
+ if ( theGroup->_is_nil() )
+ return;
+
+ SMESH_GroupBase_i* aGroup =
+ dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
+ if ( !aGroup )
+ return;
+
+ SMESH::long_array_var anIds = aGroup->GetListOfID();
+ SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
+
+ TPythonDump pyDump; // Supress dump from RemoveNodes/Elements() and RemoveGroup()
+
+ // Remove contents
+ if ( aGroup->GetType() == SMESH::NODE )
+ aMeshEditor->RemoveNodes( anIds );
+ else
+ aMeshEditor->RemoveElements( anIds );
+
+ // Remove group
+ RemoveGroup( theGroup );
+
+ // Update Python script
+ pyDump << _this() << ".RemoveGroupWithContents( " << theGroup << " )";
+}
+
+//================================================================================
+/*!
+ * \brief Get the list of groups existing in the mesh
+ * \retval SMESH::ListOfGroups * - list of groups
+ */
+//================================================================================
+
+SMESH::ListOfGroups * SMESH_Mesh_i::GetGroups() throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ if (MYDEBUG) MESSAGE("GetGroups");
+
+ SMESH::ListOfGroups_var aList = new SMESH::ListOfGroups();
+
+ // Python Dump
+ TPythonDump aPythonDump;
+ if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
+ aPythonDump << "[ ";
+
+ try {
+ aList->length( _mapGroups.size() );
+ int i = 0;
+ map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
+ for ( ; it != _mapGroups.end(); it++ ) {
+ if ( CORBA::is_nil( it->second )) continue;
+ aList[i++] = SMESH::SMESH_GroupBase::_duplicate( it->second );
+ // Python Dump
+ if (i > 1) aPythonDump << ", ";
+ aPythonDump << it->second;
+ }
+ aList->length( i );
+ }
+ catch(SALOME_Exception & S_ex) {
+ THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+ }
+
+ // Update Python script
+ if ( !_mapGroups.empty() ) // (IMP13463) avoid "SyntaxError: can't assign to []"
+ aPythonDump << " ] = " << _this() << ".GetGroups()";
+
+ return aList._retn();
+}
+
+//=============================================================================
+/*!
+ * Get number of groups existing in the mesh
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::NbGroups() throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _mapGroups.size();
+}
+
+//=============================================================================
+/*! UnionGroups
+ * New group is created. All mesh elements that are
+ * present in initial groups are added to the new one
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
+ SMESH::SMESH_GroupBase_ptr theGroup2,
+ const char* theName )
+ throw (SALOME::SALOME_Exception)
+{
+ try
+ {
+ if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
+ theGroup1->GetType() != theGroup2->GetType() )
+ return SMESH::SMESH_Group::_nil();
+
+ // Create Union
+ SMESH::SMESH_Group_var 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();
+
+ TColStd_MapOfInteger aResMap;
+
+ 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 ] );
+
+ 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();
+
+ aResGrp->Add( aResIds );
+
+ // Clear python lines, created by CreateGroup() and Add()
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
+ _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
+
+ // Update Python script
+ TPythonDump() << aResGrp << " = " << _this() << ".UnionGroups( "
+ << theGroup1 << ", " << theGroup2 << ", '"
+ << theName << "' )";
+
+ return aResGrp._retn();
+ }
+ catch( ... )
+ {
+ return SMESH::SMESH_Group::_nil();
+ }
+}
+
+//=============================================================================
+/*!
+ \brief Union list of groups. New group is created. All mesh elements that are
+ 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
+*/
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::UnionListOfGroups(const SMESH::ListOfGroups& theGroups,
+ const char* theName )
+throw (SALOME::SALOME_Exception)
+{
+ if ( !theName )
+ return SMESH::SMESH_Group::_nil();
+
+ try
+ {
+ 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;
+
+ // 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 );
+ }
+ }
+
+ // 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() );
+
+ //NCollection_Map< int >::Iterator anIter( anIds );
+ for ( int i = 0; i<anIds.size(); i++ )
+ {
+ aResIds[ i ] = anIds[i];
+ }
+ aResGrp->Add( aResIds );
+
+ // Clear python lines, created by CreateGroup() and Add()
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
+ _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
+
+ // Update Python script
+
+ TPythonDump() << aResGrp << " = " << _this() << ".UnionListOfGroups( "
+ << &theGroups << ", '" << theName << "' )";
+
+ return aResGrp._retn();
+ }
+ catch( ... )
+ {
+ return SMESH::SMESH_Group::_nil();
+ }
+}
+
+//=============================================================================
+/*! IntersectGroups
+ * New group is created. All mesh elements that are
+ * present in both initial groups are added to the new one.
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
+ SMESH::SMESH_GroupBase_ptr theGroup2,
+ const char* theName )
+ throw (SALOME::SALOME_Exception)
+{
+ if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
+ theGroup1->GetType() != theGroup2->GetType() )
+ return SMESH::SMESH_Group::_nil();
+
+ // Create Intersection
+ SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
+ if ( aResGrp->_is_nil() )
+ return aResGrp;
+
+ SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
+ SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
+
+ TColStd_MapOfInteger aMap1;
+
+ for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
+ aMap1.Add( anIds1[ i1 ] );
+
+ TColStd_SequenceOfInteger aSeq;
+
+ for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
+ if ( aMap1.Contains( anIds2[ i2 ] ) )
+ aSeq.Append( anIds2[ i2 ] );
+
+ SMESH::long_array_var aResIds = new SMESH::long_array;
+ aResIds->length( aSeq.Length() );
+
+ for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
+ aResIds[ resI ] = aSeq( resI + 1 );
+
+ aResGrp->Add( aResIds );
+
+ // Clear python lines, created by CreateGroup() and Add()
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
+ _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
+
+ // Update Python script
+ TPythonDump() << aResGrp << " = " << _this() << ".IntersectGroups( "
+ << theGroup1 << ", " << theGroup2 << ", '" << theName << "')";
+
+ return aResGrp._retn();
+}
+
+//=============================================================================
+/*!
+ \brief Intersect list of groups. New group is created. All mesh elements that
+ are present in all initial groups simultaneously are added to the new one.
+ \param theGroups list of groups
+ \param theName name of group to be created
+ \return pointer on the group
+*/
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::IntersectListOfGroups(
+ const SMESH::ListOfGroups& theGroups, const char* theName )
+throw (SALOME::SALOME_Exception)
+{
+ 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++ )
+ {
+ 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();
+ }
+
+ // 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() )
+ {
+ int aCurrId = anIter.Key();
+ int aCurrNb = anIter.Value();
+ if ( aCurrNb == nbGrp )
+ 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() );
+
+ //NCollection_Map< int >::Iterator aListIter( anIds );
+ for ( int i = 0; i<anIds.size(); i++ )
+ {
+ aResIds[ i ] = anIds[i];
+ }
+ aResGrp->Add( aResIds );
+
+ // Clear python lines, created by CreateGroup() and Add()
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
+ _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
+
+ // Update Python script
+
+ TPythonDump() << aResGrp << " = " << _this() << ".IntersectListOfGroups( "
+ << &theGroups << ", '" << theName << "' )";
+
+ return aResGrp._retn();
+ }
+ catch( ... )
+ {
+ return SMESH::SMESH_Group::_nil();
+ }
+}
+
+//=============================================================================
+/*! CutGroups
+ * New group is created. All mesh elements that are present in
+ * main group but do not present in tool group are added to the new one
+ */
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutGroups( SMESH::SMESH_GroupBase_ptr theGroup1,
+ SMESH::SMESH_GroupBase_ptr theGroup2,
+ const char* theName )
+ throw (SALOME::SALOME_Exception)
+{
+ if ( theGroup1->_is_nil() || theGroup2->_is_nil() ||
+ theGroup1->GetType() != theGroup2->GetType() )
+ return SMESH::SMESH_Group::_nil();
+
+ // Perform Cutting
+ SMESH::SMESH_Group_var aResGrp = CreateGroup( theGroup1->GetType(), theName );
+ if ( aResGrp->_is_nil() )
+ return aResGrp;
+
+ SMESH::long_array_var anIds1 = theGroup1->GetListOfID();
+ SMESH::long_array_var anIds2 = theGroup2->GetListOfID();
+
+ TColStd_MapOfInteger aMap2;
+
+ for ( int i2 = 0, n2 = anIds2->length(); i2 < n2; i2++ )
+ aMap2.Add( anIds2[ i2 ] );
+
+ TColStd_SequenceOfInteger aSeq;
+ for ( int i1 = 0, n1 = anIds1->length(); i1 < n1; i1++ )
+ if ( !aMap2.Contains( anIds1[ i1 ] ) )
+ aSeq.Append( anIds1[ i1 ] );
+
+ SMESH::long_array_var aResIds = new SMESH::long_array;
+ aResIds->length( aSeq.Length() );
+
+ for ( int resI = 0, resN = aSeq.Length(); resI < resN; resI++ )
+ aResIds[ resI ] = aSeq( resI + 1 );
+
+ aResGrp->Add( aResIds );
+
+ // Clear python lines, created by CreateGroup() and Add()
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
+ _gen_i->RemoveLastFromPythonScript(aStudy->StudyId());
+
+ // Update Python script
+ TPythonDump() << aResGrp << " = " << _this() << ".CutGroups( "
+ << theGroup1 << ", " << theGroup2 << ", '"
+ << theName << "' )";
+
+ return aResGrp._retn();
+}
+
+//=============================================================================
+/*!
+ \brief Cut lists of groups. New group is created. All mesh elements that are
+ present in main groups but do not present in tool groups are added to the new one
+ \param theMainGroups list of main groups
+ \param theToolGroups list of tool groups
+ \param theName name of group to be created
+ \return pointer on the group
+*/
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::CutListOfGroups(
+ const SMESH::ListOfGroups& theMainGroups,
+ const SMESH::ListOfGroups& theToolGroups,
+ const char* theName )
+ throw (SALOME::SALOME_Exception)
+{
+ 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++ )
+ {
+ 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();
+ }
+
+ // 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 );
+ }
+ }
+
+ vector< int > anIds; // result
+
+ // 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();
+ }
+
+ // 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; i<anIds.size(); i++ )
+ {
+ aResIds[ i ] = anIds[i];
+ }
+ aResGrp->Add( aResIds );
+
+ // Clear python lines, created by CreateGroup() and Add()
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
+ _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
+
+ // Update Python script
+
+ TPythonDump() << aResGrp << " = " << _this() << ".CutListOfGroups( "
+ << &theMainGroups << ", " << &theToolGroups << ", '"
+ << theName << "' )";
+
+ return aResGrp._retn();
+ }
+ catch( ... )
+ {
+ return SMESH::SMESH_Group::_nil();
+ }
+}
+
+//=============================================================================
+/*!
+ \brief Create groups of entities from existing groups of superior dimensions
+ 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
+ \param theElemType dimension of elements
+ \param theName name of new group
+ \return pointer on new group
+*/
+//=============================================================================
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::CreateDimGroup(
+ const SMESH::ListOfGroups& theGroups,
+ SMESH::ElementType theElemType,
+ const char* theName )
+ throw (SALOME::SALOME_Exception)
+{
+ SMESHDS_Mesh* aMeshDS = _impl->GetMeshDS();
+
+ if ( !theName || !aMeshDS )
+ return SMESH::SMESH_Group::_nil();
+
+ SMDSAbs_ElementType anElemType = (SMDSAbs_ElementType)theElemType;
+
+ try
+ {
+ // Create map of nodes from all groups
+
+ set< int > aNodeMap;
+
+ for ( int g = 0, n = theGroups.length(); g < n; g++ )
+ {
+ SMESH::SMESH_GroupBase_var aGrp = theGroups[ g ];
+ if ( CORBA::is_nil( aGrp ) )
+ continue;
+
+ SMESH::ElementType aType = aGrp->GetType();
+ if ( aType == SMESH::ALL )
+ continue;
+ else if ( aType == SMESH::NODE )
+ {
+ SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
+ for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
+ {
+ int aCurrId = aCurrIds[ i ];
+ const SMDS_MeshNode* aNode = aMeshDS->FindNode( aCurrId );
+ if ( aNode )
+ aNodeMap.insert( aNode->GetID() );
+ }
+ }
+ else
+ {
+ SMESH::long_array_var aCurrIds = aGrp->GetListOfID();
+ for ( int i = 0, n = aCurrIds->length(); i < n; i++ )
+ {
+ int aCurrId = aCurrIds[ i ];
+ const SMDS_MeshElement* anElem = aMeshDS->FindElement( aCurrId );
+ if ( !anElem )
+ continue;
+ SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
+ while( aNodeIter->more() )
+ {
+ const SMDS_MeshNode* aNode =
+ dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
+ if ( aNode )
+ aNodeMap.insert( aNode->GetID() );
+ }
+ }
+ }
+ }
+
+ // Get result identifiers
+
+ vector< int > aResultIds;
+ if ( theElemType == SMESH::NODE )
+ {
+ //NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
+ set<int>::iterator iter = aNodeMap.begin();
+ for ( ; iter != aNodeMap.end(); iter++ )
+ aResultIds.push_back( *iter);
+ }
+ else
+ {
+ // Create list of elements of given dimension constructed on the nodes
+ vector< int > anElemList;
+ //NCollection_Map< int >::Iterator aNodeIter( aNodeMap );
+ //for ( ; aNodeIter.More(); aNodeIter.Next() )
+ set<int>::iterator iter = aNodeMap.begin();
+ for ( ; iter != aNodeMap.end(); iter++ )
+ {
+ const SMDS_MeshElement* aNode =
+ dynamic_cast<const SMDS_MeshElement*>( aMeshDS->FindNode( *iter ) );
+ if ( !aNode )
+ continue;
+
+ SMDS_ElemIteratorPtr anElemIter = aNode->elementsIterator( anElemType );
+ while( anElemIter->more() )
+ {
+ const SMDS_MeshElement* anElem =
+ dynamic_cast<const SMDS_MeshElement*>( anElemIter->next() );
+ if ( anElem && anElem->GetType() == anElemType )
+ anElemList.push_back( anElem->GetID() );
+ }
+ }
+
+ // check whether all nodes of elements are present in nodes map
+ //NCollection_Map< int >::Iterator anIter( anElemList );
+ //for ( ; anIter.More(); anIter.Next() )
+ for (int i=0; i< anElemList.size(); i++)
+ {
+ const SMDS_MeshElement* anElem = aMeshDS->FindElement( anElemList[i] );
+ if ( !anElem )
+ continue;
+
+ bool isOk = true;
+ SMDS_ElemIteratorPtr aNodeIter = anElem->nodesIterator();
+ while( aNodeIter->more() )
+ {
+ const SMDS_MeshNode* aNode =
+ dynamic_cast<const SMDS_MeshNode*>( aNodeIter->next() );
+ if ( !aNode || !aNodeMap.count( aNode->GetID() ) )
+ {
+ isOk = false;
+ break;
+ }
+ }
+ if ( isOk )
+ aResultIds.push_back( anElem->GetID() );
+ }
+ }
+
+ // Create group
+
+ SMESH::SMESH_Group_var aResGrp = CreateGroup( theElemType, 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( aResultIds.size() );
+
+ //NCollection_Map< int >::Iterator aResIter( aResultIds );
+ //for ( int i = 0; aResIter.More(); aResIter.Next(), i++ )
+ for (int i=0; i< aResultIds.size(); i++)
+ aResIds[ i ] = aResultIds[i];
+ aResGrp->Add( aResIds );
+
+ // Remove strings corresponding to group creation
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
+ _gen_i->RemoveLastFromPythonScript( aStudy->StudyId() );
+
+ // Update Python script
+
+ TPythonDump() << aResGrp << " = " << _this() << ".CreateDimGroup( "
+ << &theGroups << ", " << theElemType << ", '" << theName << "' )";
+
+ return aResGrp._retn();
+ }
+ catch( ... )
+ {
+ return SMESH::SMESH_Group::_nil();
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Remember GEOM group data
+ */
+//================================================================================
+
+void SMESH_Mesh_i::addGeomGroupData(GEOM::GEOM_Object_ptr theGeomObj,
+ CORBA::Object_ptr theSmeshObj)
+{
+ if ( CORBA::is_nil( theGeomObj ) || theGeomObj->GetType() != GEOM_GROUP )
+ return;
+ // group SO
+ SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
+ SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study, theGeomObj );
+ if ( groupSO->_is_nil() )
+ return;
+ // group indices
+ GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
+ GEOM::GEOM_IGroupOperations_var groupOp =
+ geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
+ GEOM::ListOfLong_var ids = groupOp->GetObjects( theGeomObj );
+
+ // store data
+ _geomGroupData.push_back( TGeomGroupData() );
+ TGeomGroupData & groupData = _geomGroupData.back();
+ // entry
+ CORBA::String_var entry = groupSO->GetID();
+ groupData._groupEntry = entry.in();
+ // indices
+ for ( int i = 0; i < ids->length(); ++i )
+ groupData._indices.insert( ids[i] );
+ // SMESH object
+ groupData._smeshObject = theSmeshObj;
+}
+
+//================================================================================
+/*!
+ * Remove GEOM group data relating to removed smesh object
+ */
+//================================================================================
+
+void SMESH_Mesh_i::removeGeomGroupData(CORBA::Object_ptr theSmeshObj)
+{
+ list<TGeomGroupData>::iterator
+ data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
+ for ( ; data != dataEnd; ++data ) {
+ if ( theSmeshObj->_is_equivalent( data->_smeshObject )) {
+ _geomGroupData.erase( data );
+ return;
+ }
+ }
+}
+
+//================================================================================
+/*!
+ * \brief Return new group contents if it has been changed and update group data
+ */
+//================================================================================
+
+TopoDS_Shape SMESH_Mesh_i::newGroupShape( TGeomGroupData & groupData)
+{
+ TopoDS_Shape newShape;
+
+ // get geom group
+ SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
+ if ( study->_is_nil() ) return newShape; // means "not changed"
+ SALOMEDS::SObject_var groupSO = study->FindObjectID( groupData._groupEntry.c_str() );
+ if ( !groupSO->_is_nil() )
+ {
+ CORBA::Object_var groupObj = _gen_i->SObjectToObject( groupSO );
+ if ( CORBA::is_nil( groupObj )) return newShape;
+ GEOM::GEOM_Object_var geomGroup = GEOM::GEOM_Object::_narrow( groupObj );
+
+ // get indices of group items
+ set<int> curIndices;
+ GEOM::GEOM_Gen_var geomGen = _gen_i->GetGeomEngine();
+ GEOM::GEOM_IGroupOperations_var groupOp =
+ geomGen->GetIGroupOperations( _gen_i->GetCurrentStudyID() );
+ GEOM::ListOfLong_var ids = groupOp->GetObjects( geomGroup );
+ for ( int i = 0; i < ids->length(); ++i )
+ curIndices.insert( ids[i] );
+
+ if ( groupData._indices == curIndices )
+ return newShape; // group not changed
+
+ // update data
+ groupData._indices = curIndices;
+
+ GEOM_Client* geomClient = _gen_i->GetShapeReader();
+ if ( !geomClient ) return newShape;
+ TCollection_AsciiString groupIOR = geomGen->GetStringFromIOR( geomGroup );
+ geomClient->RemoveShapeFromBuffer( groupIOR );
+ newShape = _gen_i->GeomObjectToShape( geomGroup );
+ }
+
+ if ( newShape.IsNull() ) {
+ // geom group becomes empty - return empty compound
+ TopoDS_Compound compound;
+ BRep_Builder().MakeCompound(compound);
+ newShape = compound;
+ }
+ return newShape;
+}
+
+namespace {
+ //=============================================================================
+ /*!
+ * \brief Storage of shape and index used in CheckGeomGroupModif()
+ */
+ //=============================================================================
+ struct TIndexedShape {
+ int _index;
+ TopoDS_Shape _shape;
+ TIndexedShape( int i, const TopoDS_Shape& s ):_index(i), _shape(s) {}
+ };
+}
+//=============================================================================
+/*!
+ * \brief Update objects depending on changed geom groups
+ *
+ * NPAL16168: geometrical group edition from a submesh don't modifiy mesh computation
+ * issue 0020210: Update of a smesh group after modification of the associated geom group
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::CheckGeomGroupModif()
+{
+ if ( !_impl->HasShapeToMesh() ) return;
+
+ SALOMEDS::Study_var study = _gen_i->GetCurrentStudy();
+ if ( study->_is_nil() ) return;
+
+ CORBA::Long nbEntities = NbNodes() + NbElements();
+
+ // Check if group contents changed
+
+ typedef map< string, TopoDS_Shape > TEntry2Geom;
+ TEntry2Geom newGroupContents;
+
+ list<TGeomGroupData>::iterator
+ data = _geomGroupData.begin(), dataEnd = _geomGroupData.end();
+ for ( ; data != dataEnd; ++data )
+ {
+ pair< TEntry2Geom::iterator, bool > it_new =
+ newGroupContents.insert( make_pair( data->_groupEntry, TopoDS_Shape() ));
+ bool processedGroup = !it_new.second;
+ TopoDS_Shape& newShape = it_new.first->second;
+ if ( !processedGroup )
+ newShape = newGroupShape( *data );
+ if ( newShape.IsNull() )
+ continue; // no changes
+
+ if ( processedGroup ) { // update group indices
+ list<TGeomGroupData>::iterator data2 = data;
+ for ( --data2; data2->_groupEntry != data->_groupEntry; --data2) {}
+ data->_indices = data2->_indices;
+ }
+
+ // Update SMESH objects according to new GEOM group contents
+
+ SMESH::SMESH_subMesh_var submesh = SMESH::SMESH_subMesh::_narrow( data->_smeshObject );
+ if ( !submesh->_is_nil() ) // -------------- Sub mesh ---------------------
+ {
+ int oldID = submesh->GetId();
+ if ( _mapSubMeshIor.find( oldID ) == _mapSubMeshIor.end() )
+ continue;
+ TopoDS_Shape oldShape = _mapSubMesh[oldID]->GetSubShape();
+
+ // update hypotheses
+ list <const SMESHDS_Hypothesis * > hyps = _impl->GetHypothesisList(oldShape);
+ list <const SMESHDS_Hypothesis * >::iterator hypIt;
+ for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
+ {
+ _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
+ _impl->AddHypothesis ( newShape, (*hypIt)->GetID());
+ }
+ // care of submeshes
+ SMESH_subMesh* newSubmesh = _impl->GetSubMesh( newShape );
+ int newID = newSubmesh->GetId();
+ if ( newID != oldID ) {
+ _mapSubMesh [ newID ] = newSubmesh;
+ _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
+ _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
+ _mapSubMesh. erase(oldID);
+ _mapSubMesh_i. erase(oldID);
+ _mapSubMeshIor.erase(oldID);
+ _mapSubMesh_i [ newID ]->changeLocalId( newID );
+ }
+ continue;
+ }
+
+ SMESH::SMESH_GroupOnGeom_var smeshGroup =
+ SMESH::SMESH_GroupOnGeom::_narrow( data->_smeshObject );
+ if ( !smeshGroup->_is_nil() ) // ------------ GROUP -----------------------
+ {
+ SMESH_GroupOnGeom_i* group_i = SMESH::DownCast<SMESH_GroupOnGeom_i*>( smeshGroup );
+ if ( group_i ) {
+ ::SMESH_Group* group = _impl->GetGroup( group_i->GetLocalID() );
+ SMESHDS_GroupOnGeom* ds = static_cast<SMESHDS_GroupOnGeom*>( group->GetGroupDS() );
+ ds->SetShape( newShape );
+ }
+ continue;
+ }
+
+ SMESH::SMESH_Mesh_var mesh = SMESH::SMESH_Mesh::_narrow( data->_smeshObject );
+ if ( !mesh->_is_nil() ) // -------------- MESH ----------------------------
+ {
+ // Remove groups and submeshes basing on removed sub-shapes
+
+ TopTools_MapOfShape newShapeMap;
+ TopoDS_Iterator shapeIt( newShape );
+ for ( ; shapeIt.More(); shapeIt.Next() )
+ newShapeMap.Add( shapeIt.Value() );
+
+ SMESHDS_Mesh* meshDS = _impl->GetMeshDS();
+ for ( shapeIt.Initialize( meshDS->ShapeToMesh() ); shapeIt.More(); shapeIt.Next() )
+ {
+ if ( newShapeMap.Contains( shapeIt.Value() ))
+ continue;
+ TopTools_IndexedMapOfShape oldShapeMap;
+ TopExp::MapShapes( shapeIt.Value(), oldShapeMap );
+ for ( int i = 1; i <= oldShapeMap.Extent(); ++i )
+ {
+ const TopoDS_Shape& oldShape = oldShapeMap(i);
+ int oldInd = meshDS->ShapeToIndex( oldShape );
+ // -- submeshes --
+ map<int, SMESH::SMESH_subMesh_ptr>::iterator i_smIor = _mapSubMeshIor.find( oldInd );
+ if ( i_smIor != _mapSubMeshIor.end() ) {
+ RemoveSubMesh( i_smIor->second ); // one submesh per shape index
+ }
+ // --- groups ---
+ map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_grp = _mapGroups.begin();
+ for ( ; i_grp != _mapGroups.end(); ++i_grp )
+ {
+ // check if a group bases on oldInd shape
+ SMESHDS_GroupOnGeom* grpOnGeom = 0;
+ if ( ::SMESH_Group* g = _impl->GetGroup( i_grp->first ))
+ grpOnGeom = dynamic_cast<SMESHDS_GroupOnGeom*>( g->GetGroupDS() );
+ if ( grpOnGeom && oldShape.IsSame( grpOnGeom->GetShape() ))
+ { // remove
+ RemoveGroup( i_grp->second ); // several groups can base on same shape
+ i_grp = _mapGroups.begin(); // _mapGroups changed - restart iteration
+ }
+ }
+ }
+ }
+ // Reassign hypotheses and update groups after setting the new shape to mesh
+
+ // collect anassigned hypotheses
+ typedef list< pair< TIndexedShape, list<const SMESHDS_Hypothesis*> > > TShapeHypList;
+ list <const SMESHDS_Hypothesis * >::const_iterator hypIt;
+ TShapeHypList assignedHyps;
+ for ( int i = 1; i <= meshDS->MaxShapeIndex(); ++i )
+ {
+ const TopoDS_Shape& oldShape = meshDS->IndexToShape(i);
+ list<const SMESHDS_Hypothesis*> hyps = meshDS->GetHypothesis( oldShape );// copy
+ if ( !hyps.empty() ) {
+ assignedHyps.push_back( make_pair( TIndexedShape(i,oldShape), hyps ));
+ for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
+ _impl->RemoveHypothesis( oldShape, (*hypIt)->GetID());
+ }
+ }
+ // collect shapes supporting groups
+ typedef list < pair< TIndexedShape, SMDSAbs_ElementType > > TShapeTypeList;
+ TShapeTypeList groupData;
+ const set<SMESHDS_GroupBase*>& groups = meshDS->GetGroups();
+ set<SMESHDS_GroupBase*>::const_iterator grIt = groups.begin();
+ for ( ; grIt != groups.end(); ++grIt )
+ {
+ if ( SMESHDS_GroupOnGeom* gog = dynamic_cast<SMESHDS_GroupOnGeom*>( *grIt ))
+ groupData.push_back
+ ( make_pair( TIndexedShape( gog->GetID(),gog->GetShape()), gog->GetType()));
+ }
+ // set new shape to mesh -> DS of submeshes and geom groups is deleted
+ _impl->ShapeToMesh( newShape );
+
+ // reassign hypotheses
+ TShapeHypList::iterator indS_hyps = assignedHyps.begin();
+ for ( ; indS_hyps != assignedHyps.end(); ++indS_hyps )
+ {
+ TIndexedShape& geom = indS_hyps->first;
+ list<const SMESHDS_Hypothesis*>& hyps = indS_hyps->second;
+ int oldID = geom._index;
+ int newID = meshDS->ShapeToIndex( geom._shape );
+ if ( !newID )
+ continue;
+ if ( oldID == 1 ) { // main shape
+ newID = 1;
+ geom._shape = newShape;
+ }
+ for ( hypIt = hyps.begin(); hypIt != hyps.end(); ++hypIt )
+ _impl->AddHypothesis( geom._shape, (*hypIt)->GetID());
+ // care of submeshes
+ SMESH_subMesh* newSubmesh = _impl->GetSubMesh( geom._shape );
+ if ( newID != oldID ) {
+ _mapSubMesh [ newID ] = newSubmesh;
+ _mapSubMesh_i [ newID ] = _mapSubMesh_i [ oldID ];
+ _mapSubMeshIor[ newID ] = _mapSubMeshIor[ oldID ];
+ _mapSubMesh. erase(oldID);
+ _mapSubMesh_i. erase(oldID);
+ _mapSubMeshIor.erase(oldID);
+ _mapSubMesh_i [ newID ]->changeLocalId( newID );
+ }
+ }
+ // recreate groups
+ TShapeTypeList::iterator geomType = groupData.begin();
+ for ( ; geomType != groupData.end(); ++geomType )
+ {
+ const TIndexedShape& geom = geomType->first;
+ int oldID = geom._index;
+ if ( _mapGroups.find( oldID ) == _mapGroups.end() )
+ continue;
+ // get group name
+ SALOMEDS::SObject_var groupSO = _gen_i->ObjectToSObject( study,_mapGroups[oldID] );
+ CORBA::String_var name = groupSO->GetName();
+ // update
+ SMESH_GroupBase_i* group_i = SMESH::DownCast<SMESH_GroupBase_i*>(_mapGroups[oldID] );
+ int newID;
+ if ( group_i && _impl->AddGroup( geomType->second, name.in(), newID, geom._shape ))
+ group_i->changeLocalId( newID );
+ }
+
+ break; // everything has been updated
+
+ } // update mesh
+ } // loop on group data
+
+ // Update icons
+
+ CORBA::Long newNbEntities = NbNodes() + NbElements();
+ list< SALOMEDS::SObject_var > soToUpdateIcons;
+ if ( newNbEntities != nbEntities )
+ {
+ // Add all SObjects with icons
+ soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, _this() )); // mesh
+
+ for (map<int, SMESH::SMESH_subMesh_ptr>::iterator i_sm = _mapSubMeshIor.begin();
+ i_sm != _mapSubMeshIor.end(); ++i_sm ) // submeshes
+ soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_sm->second ));
+
+ for ( map<int, SMESH::SMESH_GroupBase_ptr>::iterator i_gr = _mapGroups.begin();
+ i_gr != _mapGroups.end(); ++i_gr ) // groups
+ soToUpdateIcons.push_back( _gen_i->ObjectToSObject( study, i_gr->second ));
+ }
+
+ list< SALOMEDS::SObject_var >::iterator so = soToUpdateIcons.begin();
+ for ( ; so != soToUpdateIcons.end(); ++so )
+ _gen_i->SetPixMap( *so, "ICON_SMESH_TREE_MESH_WARN" );
+}
+
+//=============================================================================
+/*!
+ * \brief Create standalone group from a group on geometry or filter
+ */
+//=============================================================================
+
+SMESH::SMESH_Group_ptr SMESH_Mesh_i::ConvertToStandalone( SMESH::SMESH_GroupBase_ptr theGroup )
+{
+ SMESH::SMESH_Group_var aGroup;
+ if ( theGroup->_is_nil() )
+ return aGroup._retn();
+
+ Unexpect aCatch(SALOME_SalomeException);
+
+ SMESH_GroupBase_i* aGroupToRem =
+ dynamic_cast<SMESH_GroupBase_i*>( SMESH_Gen_i::GetServant( theGroup ).in() );
+ if ( !aGroupToRem )
+ return aGroup._retn();
+
+ const bool isOnFilter = ( SMESH::DownCast< SMESH_GroupOnFilter_i* > ( theGroup ));
+
+ int anId = aGroupToRem->GetLocalID();
+ if ( !_impl->ConvertToStandalone( anId ) )
+ return aGroup._retn();
+ removeGeomGroupData( theGroup );
+
+ SMESH_GroupBase_i* aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
+
+ // remove old instance of group from own map
+ _mapGroups.erase( anId );
+
+ SALOMEDS::StudyBuilder_var builder;
+ SALOMEDS::SObject_var aGroupSO;
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ if ( !aStudy->_is_nil() ) {
+ builder = aStudy->NewBuilder();
+ aGroupSO = _gen_i->ObjectToSObject( aStudy, theGroup );
+ if ( !aGroupSO->_is_nil() ) {
+
+ // remove reference to geometry
+ SALOMEDS::ChildIterator_var chItr = aStudy->NewChildIterator(aGroupSO);
+ for ( ; chItr->More(); chItr->Next() )
+ // Remove group's child SObject
+ builder->RemoveObject( chItr->Value() );
+
+ // Update Python script
+ TPythonDump() << aGroupSO << " = " << _this() << ".ConvertToStandalone( "
+ << aGroupSO << " )";
+
+ // change icon of Group on Filter
+ if ( isOnFilter )
+ {
+ SMESH::array_of_ElementType_var elemTypes = aGroupImpl->GetTypes();
+ const int isEmpty = ( elemTypes->length() == 0 );
+ if ( !isEmpty )
+ {
+ SALOMEDS::GenericAttribute_var anAttr =
+ builder->FindOrCreateAttribute( aGroupSO, "AttributePixMap" );
+ SALOMEDS::AttributePixMap_var pm = SALOMEDS::AttributePixMap::_narrow( anAttr );
+ pm->SetPixMap( "ICON_SMESH_TREE_GROUP" );
+ }
+ }
+ }
+ }
+
+ // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
+ SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
+ aGroupImpl->Register();
+ // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
+
+ // remember new group in own map
+ aGroup = SMESH::SMESH_Group::_narrow( aGroupImpl->_this() );
+ _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
+
+ // register CORBA object for persistence
+ /*int nextId =*/ _gen_i->RegisterObject( aGroup );
+
+ builder->SetIOR( aGroupSO, _gen_i->GetORB()->object_to_string( aGroup ) );
+
+ return aGroup._retn();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::createSubMesh( GEOM::GEOM_Object_ptr theSubShapeObject )
+{
+ if(MYDEBUG) MESSAGE( "createSubMesh" );
+ TopoDS_Shape myLocSubShape = _gen_i->GeomObjectToShape(theSubShapeObject);
+
+ ::SMESH_subMesh * mySubMesh = _impl->GetSubMesh(myLocSubShape);
+ int subMeshId = _impl->GetMeshDS()->ShapeToIndex( myLocSubShape );
+ SMESH_subMesh_i *subMeshServant = new SMESH_subMesh_i(myPOA, _gen_i, this, subMeshId);
+ SMESH::SMESH_subMesh_var subMesh
+ = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
+
+ _mapSubMesh[subMeshId] = mySubMesh;
+ _mapSubMesh_i[subMeshId] = subMeshServant;
+ _mapSubMeshIor[subMeshId] = SMESH::SMESH_subMesh::_duplicate(subMesh);
+
+ // register CORBA object for persistence
+ int nextId = _gen_i->RegisterObject( subMesh );
+ if(MYDEBUG) MESSAGE( "Add submesh to map with id = "<< nextId);
+
+ // to track changes of GEOM groups
+ addGeomGroupData( theSubShapeObject, subMesh );
+
+ return subMesh._retn();
+}
+
+//=======================================================================
+//function : getSubMesh
+//purpose :
+//=======================================================================
+
+SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::getSubMesh(int shapeID)
+{
+ map<int, SMESH::SMESH_subMesh_ptr>::iterator it = _mapSubMeshIor.find( shapeID );
+ if ( it == _mapSubMeshIor.end() )
+ return SMESH::SMESH_subMesh::_nil();
+
+ return SMESH::SMESH_subMesh::_duplicate( (*it).second );
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::removeSubMesh (SMESH::SMESH_subMesh_ptr theSubMesh,
+ GEOM::GEOM_Object_ptr theSubShapeObject )
+{
+ MESSAGE("SMESH_Mesh_i::removeSubMesh()");
+ if ( theSubMesh->_is_nil() /*|| theSubShapeObject->_is_nil()*/ )
+ return;
+
+ if ( theSubShapeObject->_is_nil() ) // not published shape (IPAL13617)
+ {
+ CORBA::Long shapeId = theSubMesh->GetId();
+ if ( _mapSubMesh.find( shapeId ) != _mapSubMesh.end())
+ {
+ TopoDS_Shape S = _mapSubMesh[ shapeId ]->GetSubShape();
+ if ( !S.IsNull() )
+ {
+ list<const SMESHDS_Hypothesis*> hyps = _impl->GetHypothesisList( S );
+ list<const SMESHDS_Hypothesis*>::const_iterator hyp = hyps.begin();
+ for ( ; hyp != hyps.end(); ++hyp )
+ _impl->RemoveHypothesis(S, (*hyp)->GetID());
+ }
+ }
+ }
+ else
+ {
+ try {
+ SMESH::ListOfHypothesis_var aHypList = GetHypothesisList( theSubShapeObject );
+ for ( int i = 0, n = aHypList->length(); i < n; i++ ) {
+ removeHypothesis( theSubShapeObject, aHypList[i] );
+ }
+ }
+ catch( const SALOME::SALOME_Exception& ) {
+ INFOS("SMESH_Mesh_i::removeSubMesh(): exception caught!");
+ }
+ removeGeomGroupData( theSubShapeObject );
+ }
+ int subMeshId = theSubMesh->GetId();
+
+ _mapSubMesh.erase(subMeshId);
+ _mapSubMesh_i.erase(subMeshId);
+ _mapSubMeshIor.erase(subMeshId);
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeSubMesh() completed");
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::SMESH_GroupBase_ptr SMESH_Mesh_i::createGroup (SMESH::ElementType theElemType,
+ const char* theName,
+ const TopoDS_Shape& theShape,
+ const SMESH_PredicatePtr& thePredicate )
+{
+ std::string newName;
+ if ( !theName || strlen( theName ) == 0 )
+ {
+ std::set< std::string > presentNames;
+ std::map<int, SMESH::SMESH_GroupBase_ptr>::const_iterator i_gr = _mapGroups.begin();
+ for ( ; i_gr != _mapGroups.end(); ++i_gr )
+ presentNames.insert( i_gr->second->GetName() );
+ do {
+ newName = "noname_Group_" + SMESH_Comment( presentNames.size() + 1 );
+ } while ( !presentNames.insert( newName ).second );
+ theName = newName.c_str();
+ }
+ int anId;
+ SMESH::SMESH_GroupBase_var aGroup;
+ if ( _impl->AddGroup( (SMDSAbs_ElementType)theElemType, theName, anId, theShape, thePredicate ))
+ {
+ SMESH_GroupBase_i* aGroupImpl;
+ if ( !theShape.IsNull() )
+ aGroupImpl = new SMESH_GroupOnGeom_i( SMESH_Gen_i::GetPOA(), this, anId );
+ else if ( thePredicate )
+ aGroupImpl = new SMESH_GroupOnFilter_i( SMESH_Gen_i::GetPOA(), this, anId );
+ else
+ aGroupImpl = new SMESH_Group_i( SMESH_Gen_i::GetPOA(), this, anId );
+
+ // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
+ SMESH_Gen_i::GetPOA()->activate_object( aGroupImpl );
+ aGroupImpl->Register();
+ // PAL7962: san -- To ensure correct mapping of servant and correct reference counting in GenericObj_i
+
+ aGroup = SMESH::SMESH_GroupBase::_narrow( aGroupImpl->_this() );
+ _mapGroups[anId] = SMESH::SMESH_GroupBase::_duplicate( aGroup );
+
+ // register CORBA object for persistence
+ int nextId = _gen_i->RegisterObject( aGroup );
+ if(MYDEBUG) MESSAGE( "Add group to map with id = "<< nextId);
+
+ // to track changes of GEOM groups
+ if ( !theShape.IsNull() ) {
+ GEOM::GEOM_Object_var geom = _gen_i->ShapeToGeomObject( theShape );
+ addGeomGroupData( geom, aGroup );
+ }
+ }
+ return aGroup._retn();
+}
+
+//=============================================================================
+/*!
+ * SMESH_Mesh_i::removeGroup
+ *
+ * Should be called by ~SMESH_Group_i()
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::removeGroup( const int theId )
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::removeGroup()" );
+ if ( _mapGroups.find( theId ) != _mapGroups.end() ) {
+ SMESH::SMESH_GroupBase_ptr group = _mapGroups[theId];
+ _mapGroups.erase( theId );
+ removeGeomGroupData( group );
+ if (! _impl->RemoveGroup( theId ))
+ {
+ // it seems to be a call up from _impl caused by hyp modification (issue 0020918)
+ RemoveGroup( group );
+ }
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::log_array * SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
+throw(SALOME::SALOME_Exception)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetLog");
+
+ 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(" "<<i<<" "<<ir.Value());
+ ir++;
+ }
+ for(int i = 0; i < inum; i++){
+ aLog[indexLog].indexes[i] = *ii;
+ //MESSAGE(" "<<i<<" "<<ii.Value());
+ ii++;
+ }
+ indexLog++;
+ its++;
+ }
+ if(clearAfterGet)
+ _impl->ClearLog();
+ }
+ catch(SALOME_Exception & S_ex){
+ THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
+ }
+ return aLog._retn();
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::ClearLog() throw(SALOME::SALOME_Exception)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::ClearLog");
+ _impl->ClearLog();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetId()throw(SALOME::SALOME_Exception)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetId");
+ return _id;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetStudyId()throw(SALOME::SALOME_Exception)
+{
+ return _studyId;
+}
+
+//=============================================================================
+namespace
+{
+ //!< implementation of struct used to call SMESH_Mesh_i::removeGroup() from
+ // SMESH_Mesh::RemoveGroup() (issue 0020918)
+ struct TRmGroupCallUp_i : public SMESH_Mesh::TRmGroupCallUp
+ {
+ SMESH_Mesh_i* _mesh;
+ TRmGroupCallUp_i(SMESH_Mesh_i* mesh):_mesh(mesh) {}
+ virtual void RemoveGroup (const int theGroupID) { _mesh->removeGroup( theGroupID ); }
+ };
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+void SMESH_Mesh_i::SetImpl(::SMESH_Mesh * impl)
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::SetImpl");
+ _impl = impl;
+ if ( _impl )
+ _impl->SetRemoveGroupCallUp( new TRmGroupCallUp_i(this));
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+::SMESH_Mesh & SMESH_Mesh_i::GetImpl()
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh_i::GetImpl()");
+ return *_impl;
+}
+
+//=============================================================================
+/*!
+ * Return mesh editor
+ */
+//=============================================================================
+
+SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
+{
+ // Create MeshEditor
+ SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, false );
+ SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
+
+ // Update Python script
+ TPythonDump() << aMeshEditor << " = " << _this() << ".GetMeshEditor()";
+
+ return aMesh._retn();
+}
+
+//=============================================================================
+/*!
+ * Return mesh edition previewer
+ */
+//=============================================================================
+
+SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditPreviewer()
+{
+ SMESH_MeshEditor_i *aMeshEditor = new SMESH_MeshEditor_i( this, true );
+ SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
+ return aMesh._retn();
+}
+
+//================================================================================
+/*!
+ * \brief Return true if the mesh has been edited since a last total re-compute
+ * and those modifications may prevent successful partial re-compute
+ */
+//================================================================================
+
+CORBA::Boolean SMESH_Mesh_i::HasModificationsToDiscard() throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->HasModificationsToDiscard();
+}
+
+static SALOMEDS::Color getUniqueColor( const std::list<SALOMEDS::Color>& theReservedColors )
+{
+ const int MAX_ATTEMPTS = 100;
+ int cnt = 0;
+ double tolerance = 0.5;
+ SALOMEDS::Color col;
+
+ bool ok = false;
+ while ( !ok ) {
+ // generate random color
+ double red = (double)rand() / RAND_MAX;
+ double green = (double)rand() / RAND_MAX;
+ double blue = (double)rand() / RAND_MAX;
+ // check existence in the list of the existing colors
+ bool matched = false;
+ std::list<SALOMEDS::Color>::const_iterator it;
+ for ( it = theReservedColors.begin(); it != theReservedColors.end() && !matched; ++it ) {
+ SALOMEDS::Color color = *it;
+ double tol = fabs( color.R - red ) + fabs( color.G - green ) + fabs( color.B - blue );
+ matched = tol < tolerance;
+ }
+ if ( (cnt+1) % 20 == 0 ) tolerance = tolerance/2;
+ ok = ( ++cnt == MAX_ATTEMPTS ) || !matched;
+ col.R = red;
+ col.G = green;
+ col.B = blue;
+ }
+ return col;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+void SMESH_Mesh_i::SetAutoColor(CORBA::Boolean theAutoColor) throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ _impl->SetAutoColor(theAutoColor);
+
+ TPythonDump pyDump; // not to dump group->SetColor() from below code
+ pyDump<<_this()<<".SetAutoColor( "<<theAutoColor<<" )";
+
+ std::list<SALOMEDS::Color> aReservedColors;
+ map<int, SMESH::SMESH_GroupBase_ptr>::iterator it = _mapGroups.begin();
+ for ( ; it != _mapGroups.end(); it++ ) {
+ if ( CORBA::is_nil( it->second )) continue;
+ SALOMEDS::Color aColor = getUniqueColor( aReservedColors );
+ it->second->SetColor( aColor );
+ aReservedColors.push_back( aColor );
+ }
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Boolean SMESH_Mesh_i::GetAutoColor() throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->GetAutoColor();
+}
+
+
+//=============================================================================
+/*!
+ * Export in different formats
+ */
+//=============================================================================
+
+CORBA::Boolean SMESH_Mesh_i::HasDuplicatedGroupNamesMED()
+{
+ return _impl->HasDuplicatedGroupNamesMED();
+}
+
+void SMESH_Mesh_i::PrepareForWriting (const char* file, bool overwrite)
+{
+ TCollection_AsciiString aFullName ((char*)file);
+ OSD_Path aPath (aFullName);
+ OSD_File aFile (aPath);
+ if (aFile.Exists()) {
+ // existing filesystem node
+ if (aFile.KindOfFile() == OSD_FILE) {
+ if (aFile.IsWriteable()) {
+ if (overwrite) {
+ aFile.Reset();
+ aFile.Remove();
+ }
+ if (aFile.Failed()) {
+ TCollection_AsciiString msg ("File ");
+ msg += aFullName + " cannot be replaced.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ TCollection_AsciiString msg ("File ");
+ msg += aFullName + " cannot be overwritten.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ TCollection_AsciiString msg ("Location ");
+ msg += aFullName + " is not a file.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ }
+ } else {
+ // nonexisting file; check if it can be created
+ aFile.Reset();
+ aFile.Build(OSD_WriteOnly, OSD_Protection());
+ if (aFile.Failed()) {
+ TCollection_AsciiString msg ("You cannot create the file ");
+ msg += aFullName + ". Check the directory existance and access rights.";
+ THROW_SALOME_CORBA_EXCEPTION(msg.ToCString(), SALOME::BAD_PARAM);
+ } else {
+ aFile.Close();
+ aFile.Remove();
+ }
+ }
+}
+
+void SMESH_Mesh_i::ExportToMEDX (const char* file,
+ CORBA::Boolean auto_groups,
+ SMESH::MED_VERSION theVersion,
+ CORBA::Boolean overwrite)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // Perform Export
+ PrepareForWriting(file, overwrite);
+ string aMeshName = "Mesh";
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ if ( !aStudy->_is_nil() ) {
+ SALOMEDS::SObject_var aMeshSO = _gen_i->ObjectToSObject( aStudy, _this() );
+ if ( !aMeshSO->_is_nil() ) {
+ CORBA::String_var name = aMeshSO->GetName();
+ aMeshName = name;
+ // asv : 27.10.04 : fix of 6903: check for StudyLocked before adding attributes
+ if ( !aStudy->GetProperties()->IsLocked() )
+ {
+ SALOMEDS::GenericAttribute_var anAttr;
+ SALOMEDS::StudyBuilder_var aStudyBuilder = aStudy->NewBuilder();
+ SALOMEDS::AttributeExternalFileDef_var aFileName;
+ anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeExternalFileDef");
+ aFileName = SALOMEDS::AttributeExternalFileDef::_narrow(anAttr);
+ ASSERT(!aFileName->_is_nil());
+ aFileName->SetValue(file);
+ SALOMEDS::AttributeFileType_var aFileType;
+ anAttr=aStudyBuilder->FindOrCreateAttribute(aMeshSO, "AttributeFileType");
+ aFileType = SALOMEDS::AttributeFileType::_narrow(anAttr);
+ ASSERT(!aFileType->_is_nil());
+ aFileType->SetValue("FICHIERMED");
+ }
+ }
+ }
+ // Update Python script
+ // set name of mesh before export
+ TPythonDump() << _gen_i << ".SetName(" << _this() << ", '" << aMeshName.c_str() << "')";
+
+ // check names of groups
+ checkGroupNames();
+
+ TPythonDump() << _this() << ".ExportToMEDX( r'"
+ << file << "', " << auto_groups << ", " << theVersion << ", " << overwrite << " )";
+
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, theVersion );
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to a med file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportToMED (const char* file,
+ CORBA::Boolean auto_groups,
+ SMESH::MED_VERSION theVersion)
+ throw(SALOME::SALOME_Exception)
+{
+ ExportToMEDX(file,auto_groups,theVersion,true);
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to a med file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportMED (const char* file,
+ CORBA::Boolean auto_groups)
+ throw(SALOME::SALOME_Exception)
+{
+ ExportToMEDX(file,auto_groups,SMESH::MED_V2_2,true);
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to a DAT file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportDAT (const char *file)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << _this() << ".ExportDAT( r'" << file << "' )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportDAT(file);
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to an UNV file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportUNV (const char *file)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << _this() << ".ExportUNV( r'" << file << "' )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportUNV(file);
+}
+
+//================================================================================
+/*!
+ * \brief Export a mesh to an STL file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ // Update Python script
+ // check names of groups
+ checkGroupNames();
+ TPythonDump() << _this() << ".ExportSTL( r'" << file << "', " << isascii << " )";
+
+ // Perform Export
+ PrepareForWriting(file);
+ _impl->ExportSTL(file, isascii);
+}
+
+//=============================================================================
+/*!
+ * \brief Class providing SMESHDS_Mesh API to SMESH_IDSource.
+ * It is used to export a part of mesh as a whole mesh.
+ */
+class SMESH_MeshPartDS : public SMESHDS_Mesh
+{
+public:
+ SMESH_MeshPartDS(SMESH::SMESH_IDSource_ptr meshPart);
+
+ virtual SMDS_NodeIteratorPtr nodesIterator (bool idInceasingOrder=false) const;
+ virtual SMDS_0DElementIteratorPtr elements0dIterator(bool idInceasingOrder=false) const;
+ virtual SMDS_EdgeIteratorPtr edgesIterator (bool idInceasingOrder=false) const;
+ virtual SMDS_FaceIteratorPtr facesIterator (bool idInceasingOrder=false) const;
+ virtual SMDS_VolumeIteratorPtr volumesIterator (bool idInceasingOrder=false) const;
+
+ virtual SMDS_ElemIteratorPtr elementsIterator(SMDSAbs_ElementType type=SMDSAbs_All) const;
+
+private:
+ TIDSortedElemSet _elements[ SMDSAbs_NbElementTypes ];
+ SMESHDS_Mesh* _meshDS;
+ /*!
+ * \brief Class used to access to protected data of SMDS_MeshInfo
+ */
+ struct TMeshInfo : public SMDS_MeshInfo
+ {
+ void Add(const SMDS_MeshElement* e) { SMDS_MeshInfo::addWithPoly( e ); }
+ };
+};
+
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a med file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToMED(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ CORBA::Boolean auto_groups,
+ ::SMESH::MED_VERSION version,
+ ::CORBA::Boolean overwrite)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ PrepareForWriting(file, overwrite);
+
+ string aMeshName = "Mesh";
+ SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
+ if ( !aStudy->_is_nil() ) {
+ SALOMEDS::SObject_var SO = _gen_i->ObjectToSObject( aStudy, meshPart );
+ if ( !SO->_is_nil() ) {
+ CORBA::String_var name = SO->GetName();
+ aMeshName = name;
+ }
+ }
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportMED( file, aMeshName.c_str(), auto_groups, version, &partDS );
+
+ TPythonDump() << _this() << ".ExportPartToMED( " << meshPart << ", r'" << file << "', "
+ << auto_groups << ", " << version << ", " << overwrite << " )";
+}
+
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a DAT file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToDAT(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ PrepareForWriting(file);
+
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportDAT(file,&partDS);
+
+ TPythonDump() << _this() << ".ExportPartToDAT( " << meshPart << ", r'" << file << "' )";
+}
+//================================================================================
+/*!
+ * \brief Export a part of mesh to an UNV file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToUNV(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ PrepareForWriting(file);
+
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportUNV(file, &partDS);
+
+ TPythonDump() << _this() << ".ExportPartToUNV( " << meshPart<< ", r'" << file << "' )";
+}
+//================================================================================
+/*!
+ * \brief Export a part of mesh to an STL file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportPartToSTL(::SMESH::SMESH_IDSource_ptr meshPart,
+ const char* file,
+ ::CORBA::Boolean isascii)
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+
+ PrepareForWriting(file);
+
+ SMESH_MeshPartDS partDS( meshPart );
+ _impl->ExportSTL(file, isascii, &partDS);
+
+ TPythonDump() << _this() << ".ExportPartToSTL( "
+ << meshPart<< ", r'" << file << "', " << isascii << ")";
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ SMESH_MEDMesh_i *aMedMesh = new SMESH_MEDMesh_i(this);
+ SALOME_MED::MESH_var aMesh = aMedMesh->_this();
+ return aMesh._retn();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbNodes()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbNodes();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbElements()throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return Nb0DElements() + NbEdges() + NbFaces() + NbVolumes();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::Nb0DElements()throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->Nb0DElements();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbEdges()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbEdges();
+}
+
+CORBA::Long SMESH_Mesh_i::NbEdgesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbEdges( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbFaces()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbFaces();
+}
+
+CORBA::Long SMESH_Mesh_i::NbTriangles()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbTriangles();
+}
+
+CORBA::Long SMESH_Mesh_i::NbQuadrangles()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbQuadrangles();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPolygons()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPolygons();
+}
+
+CORBA::Long SMESH_Mesh_i::NbFacesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbFaces( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbTrianglesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbTriangles( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbQuadranglesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbQuadrangles( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbVolumes()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbVolumes();
+}
+
+CORBA::Long SMESH_Mesh_i::NbTetras()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbTetras();
+}
+
+CORBA::Long SMESH_Mesh_i::NbHexas()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbHexas();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPyramids()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPyramids();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPrisms()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPrisms();
+}
+
+CORBA::Long SMESH_Mesh_i::NbPolyhedrons()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPolyhedrons();
+}
+
+CORBA::Long SMESH_Mesh_i::NbVolumesOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbVolumes( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbTetrasOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbTetras( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbHexasOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbHexas( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbPyramidsOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPyramids( (SMDSAbs_ElementOrder) order);
+}
+
+CORBA::Long SMESH_Mesh_i::NbPrismsOfOrder(SMESH::ElementOrder order)
+ throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _impl->NbPrisms( (SMDSAbs_ElementOrder) order);
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+CORBA::Long SMESH_Mesh_i::NbSubMesh()throw(SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ return _mapSubMesh_i.size();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+char* SMESH_Mesh_i::Dump()
+{
+ ostringstream os;
+ _impl->Dump( os );
+ return CORBA::string_dup( os.str().c_str() );
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+SMESH::long_array* SMESH_Mesh_i::GetIDs()
+{
+// SMESH::long_array_var aResult = new SMESH::long_array();
+// SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+// int aMinId = aSMESHDS_Mesh->MinElementID();
+// int aMaxId = aSMESHDS_Mesh->MaxElementID();
+
+// aResult->length(aMaxId - aMinId + 1);
+
+// for (int i = 0, id = aMinId; id <= aMaxId; id++ )
+// aResult[i++] = id;
+
+// return aResult._retn();
+ // PAL12398
+ return GetElementsId();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetElementsId()
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ MESSAGE("SMESH_Mesh_i::GetElementsId");
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ long nbElements = NbElements();
+ aResult->length( nbElements );
+ SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
+ for ( int i = 0, n = nbElements; i < n && anIt->more(); i++ )
+ aResult[i] = anIt->next()->GetID();
+
+ return aResult._retn();
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetElementsByType( SMESH::ElementType theElemType )
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ MESSAGE("SMESH_subMesh_i::GetElementsByType");
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ long nbElements = NbElements();
+
+ // No sense in returning ids of elements along with ids of nodes:
+ // when theElemType == SMESH::ALL, return node ids only if
+ // there are no elements
+ if ( theElemType == SMESH::NODE || (theElemType == SMESH::ALL && nbElements == 0) )
+ return GetNodesId();
+
+ aResult->length( nbElements );
+
+ int i = 0;
+
+ SMDS_ElemIteratorPtr anIt = aSMESHDS_Mesh->elementsIterator();
+ while ( i < nbElements && anIt->more() ) {
+ const SMDS_MeshElement* anElem = anIt->next();
+ if ( theElemType == SMESH::ALL || anElem->GetType() == (SMDSAbs_ElementType)theElemType )
+ aResult[i++] = anElem->GetID();
+ }
+
+ aResult->length( i );
+
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetNodesId()
+ throw (SALOME::SALOME_Exception)
+{
+ Unexpect aCatch(SALOME_SalomeException);
+ MESSAGE("SMESH_subMesh_i::GetNodesId");
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ long nbNodes = NbNodes();
+ aResult->length( nbNodes );
+ SMDS_NodeIteratorPtr anIt = aSMESHDS_Mesh->nodesIterator(/*idInceasingOrder=*/true);
+ for ( int i = 0, n = nbNodes; i < n && anIt->more(); i++ )
+ aResult[i] = anIt->next()->GetID();
+
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::ElementType SMESH_Mesh_i::GetElementType( const CORBA::Long id, const bool iselem )
+ throw (SALOME::SALOME_Exception)
+{
+ return ( SMESH::ElementType )_impl->GetElementType( id, iselem );
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH::EntityType SMESH_Mesh_i::GetElementGeomType( const CORBA::Long id )
+ throw (SALOME::SALOME_Exception)
+{
+ const SMDS_MeshElement* e = _impl->GetMeshDS()->FindElement(id);
+ if ( !e )
+ THROW_SALOME_CORBA_EXCEPTION( "invalid element id", SALOME::BAD_PARAM );
+
+ return ( SMESH::EntityType ) e->GetEntityType();
+}
+
+//=============================================================================
+/*!
+ * Returns ID of elements for given submesh
+ */
+//=============================================================================
+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_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
+ if(!SM) return aResult._retn();
+
+ SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
+ if(!SDSM) return aResult._retn();
+
+ aResult->length(SDSM->NbElements());
+
+ SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
+ int i = 0;
+ while ( eIt->more() ) {
+ aResult[i++] = eIt->next()->GetID();
+ }
+
+ return aResult._retn();
+}
+
+
+//=============================================================================
+/*!
+ * Returns ID of nodes for given submesh
+ * If param all==true - returns all nodes, else -
+ * returns only nodes on shapes.
+ */
+//=============================================================================
+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_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
+ if(!SM) return aResult._retn();
+
+ SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
+ if(!SDSM) return aResult._retn();
+
+ set<int> theElems;
+ if( !all || (SDSM->NbElements()==0) ) { // internal nodes or vertex submesh
+ SMDS_NodeIteratorPtr nIt = SDSM->GetNodes();
+ while ( nIt->more() ) {
+ const SMDS_MeshNode* elem = nIt->next();
+ theElems.insert( elem->GetID() );
+ }
+ }
+ else { // all nodes of submesh elements
+ SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
+ while ( eIt->more() ) {
+ const SMDS_MeshElement* anElem = eIt->next();
+ SMDS_ElemIteratorPtr nIt = anElem->nodesIterator();
+ while ( nIt->more() ) {
+ const SMDS_MeshElement* elem = nIt->next();
+ theElems.insert( elem->GetID() );
+ }
+ }
+ }
+
+ aResult->length(theElems.size());
+ set<int>::iterator itElem;
+ int i = 0;
+ for ( itElem = theElems.begin(); itElem != theElems.end(); itElem++ )
+ aResult[i++] = *itElem;
+
+ return aResult._retn();
+}
+
+
+//=============================================================================
+/*!
+ * Returns type of elements for given submesh
+ */
+//=============================================================================
+SMESH::ElementType SMESH_Mesh_i::GetSubMeshElementType(const CORBA::Long ShapeID)
+ throw (SALOME::SALOME_Exception)
+{
+ SMESH_subMesh* SM = _impl->GetSubMeshContaining(ShapeID);
+ if(!SM) return SMESH::ALL;
+
+ SMESHDS_SubMesh* SDSM = SM->GetSubMeshDS();
+ if(!SDSM) return SMESH::ALL;
+
+ if(SDSM->NbElements()==0)
+ return (SM->GetSubShape().ShapeType() == TopAbs_VERTEX) ? SMESH::NODE : SMESH::ALL;
+
+ SMDS_ElemIteratorPtr eIt = SDSM->GetElements();
+ const SMDS_MeshElement* anElem = eIt->next();
+ return ( SMESH::ElementType ) anElem->GetType();
+}
+
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+CORBA::LongLong SMESH_Mesh_i::GetMeshPtr()
+{
+ CORBA::LongLong pointeur = CORBA::LongLong(_impl);
+ if ( MYDEBUG )
+ MESSAGE("CORBA::LongLong SMESH_Mesh_i::GetMeshPtr() "<<pointeur);
+ return pointeur;
+}
+
+
+//=============================================================================
+/*!
+ * Get XYZ coordinates of node as list of double
+ * If there is not node for given ID - returns empty list
+ */
+//=============================================================================
+
+SMESH::double_array* SMESH_Mesh_i::GetNodeXYZ(const CORBA::Long id)
+{
+ SMESH::double_array_var aResult = new SMESH::double_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ // find node
+ const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
+ if(!aNode)
+ return aResult._retn();
+
+ // add coordinates
+ aResult->length(3);
+ aResult[0] = aNode->X();
+ aResult[1] = aNode->Y();
+ aResult[2] = aNode->Z();
+ return aResult._retn();
+}
+
+
+//=============================================================================
+/*!
+ * For given node returns list of IDs of inverse elements
+ * If there is not node for given ID - returns empty list
+ */
+//=============================================================================
+
+SMESH::long_array* SMESH_Mesh_i::GetNodeInverseElements(const CORBA::Long id)
+{
+ SMESH::long_array_var aResult = new SMESH::long_array();
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL )
+ return aResult._retn();
+
+ // find node
+ const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
+ if(!aNode)
+ return aResult._retn();
+
+ // find inverse elements
+ SMDS_ElemIteratorPtr eIt = aNode->GetInverseElementIterator();
+ TColStd_SequenceOfInteger IDs;
+ while(eIt->more()) {
+ const SMDS_MeshElement* elem = eIt->next();
+ IDs.Append(elem->GetID());
+ }
+ if(IDs.Length()>0) {
+ aResult->length(IDs.Length());
+ int i = 1;
+ for(; i<=IDs.Length(); i++) {
+ aResult[i-1] = IDs.Value(i);
+ }
+ }
+ return aResult._retn();
+}
+
+//=============================================================================
+/*!
+ * \brief Return position of a node on shape
+ */
+//=============================================================================
+
+SMESH::NodePosition* SMESH_Mesh_i::GetNodePosition(CORBA::Long NodeID)
+{
+ SMESH::NodePosition* aNodePosition = new SMESH::NodePosition();
+ aNodePosition->shapeID = 0;
+ aNodePosition->shapeType = GEOM::SHAPE;
+
+ SMESHDS_Mesh* mesh = _impl->GetMeshDS();
+ if ( !mesh ) return aNodePosition;
+
+ if ( const SMDS_MeshNode* aNode = mesh->FindNode(NodeID) )
+ {
+ if ( SMDS_PositionPtr pos = aNode->GetPosition() )
+ {
+ aNodePosition->shapeID = aNode->getshapeId();
+ switch ( pos->GetTypeOfPosition() ) {
+ case SMDS_TOP_EDGE:
+ aNodePosition->shapeType = GEOM::EDGE;
+ aNodePosition->params.length(1);
+ aNodePosition->params[0] =
+ static_cast<SMDS_EdgePosition*>( pos )->GetUParameter();
+ break;
+ case SMDS_TOP_FACE:
+ aNodePosition->shapeType = GEOM::FACE;
+ aNodePosition->params.length(2);
+ aNodePosition->params[0] =
+ static_cast<SMDS_FacePosition*>( pos )->GetUParameter();
+ aNodePosition->params[1] =
+ static_cast<SMDS_FacePosition*>( pos )->GetVParameter();
+ break;
+ case SMDS_TOP_VERTEX:
+ aNodePosition->shapeType = GEOM::VERTEX;
+ break;
+ case SMDS_TOP_3DSPACE:
+ if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SOLID).More() )
+ aNodePosition->shapeType = GEOM::SOLID;
+ else if ( TopExp_Explorer(_impl->GetShapeToMesh(), TopAbs_SHELL).More() )
+ aNodePosition->shapeType = GEOM::SHELL;
+ break;
+ default:;
+ }
+ }
+ }
+ return aNodePosition;
+}
+
+//=============================================================================
+/*!
+ * If given element is node returns IDs of shape from position
+ * If there is not node for given ID - returns -1
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetShapeID(const CORBA::Long id)
+{
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL )
+ return -1;
+
+ // try to find node
+ const SMDS_MeshNode* aNode = aSMESHDS_Mesh->FindNode(id);
+ if(aNode) {
+ return aNode->getshapeId();
+ }
+
+ return -1;
+}
+
+
+//=============================================================================
+/*!
+ * For given element returns ID of result shape after
+ * ::FindShape() from SMESH_MeshEditor
+ * If there is not element for given ID - returns -1
+ */
+//=============================================================================
+
+CORBA::Long SMESH_Mesh_i::GetShapeIDForElem(const CORBA::Long id)
+{
+ SMESHDS_Mesh* aSMESHDS_Mesh = _impl->GetMeshDS();
+ if ( aSMESHDS_Mesh == NULL )
+ return -1;
+
+ // try to find element
+ const SMDS_MeshElement* elem = aSMESHDS_Mesh->FindElement(id);
+ if(!elem)
+ return -1;
+
+ //SMESH::SMESH_MeshEditor_var aMeshEditor = SMESH_Mesh_i::GetMeshEditor();
+ ::SMESH_MeshEditor aMeshEditor(_impl);
+ int index = aMeshEditor.FindShape( elem );
+ if(index>0)
+ return index;
+
+ return -1;
+}
+
+
+//=============================================================================
+/*!
+ * Returns number of nodes for given element
+ * If there is not element for given ID - returns -1
+ */
+//=============================================================================