+
+//=======================================================================
+//function : IsNotConformAllowed
+//purpose : check if a hypothesis alowing notconform mesh is present
+//=======================================================================
+
+bool SMESH_Mesh::IsNotConformAllowed() const
+{
+ if(MYDEBUG) MESSAGE("SMESH_Mesh::IsNotConformAllowed");
+
+ static SMESH_HypoFilter filter( SMESH_HypoFilter::HasName( "NotConformAllowed" ));
+ return GetHypothesis( _myMeshDS->ShapeToMesh(), filter, false );
+}
+
+//=======================================================================
+//function : IsMainShape
+//purpose :
+//=======================================================================
+
+bool SMESH_Mesh::IsMainShape(const TopoDS_Shape& theShape) const
+{
+ return theShape.IsSame(_myMeshDS->ShapeToMesh() );
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+SMESH_Group* SMESH_Mesh::AddGroup (const SMDSAbs_ElementType theType,
+ const char* theName,
+ int& theId,
+ const TopoDS_Shape& theShape,
+ const SMESH_PredicatePtr& thePredicate)
+{
+ if (_mapGroup.count(_groupId))
+ return NULL;
+ theId = _groupId;
+ SMESH_Group* aGroup = new SMESH_Group (theId, this, theType, theName, theShape, thePredicate);
+ GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
+ _mapGroup[_groupId++] = aGroup;
+ return aGroup;
+}
+
+//================================================================================
+/*!
+ * \brief Creates a group based on an existing SMESHDS group. Group ID should be unique
+ */
+//================================================================================
+
+SMESH_Group* SMESH_Mesh::AddGroup (SMESHDS_GroupBase* groupDS) throw(SALOME_Exception)
+{
+ if ( !groupDS )
+ throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup(): NULL SMESHDS_GroupBase"));
+
+ map <int, SMESH_Group*>::iterator i_g = _mapGroup.find( groupDS->GetID() );
+ if ( i_g != _mapGroup.end() && i_g->second )
+ {
+ if ( i_g->second->GetGroupDS() == groupDS )
+ return i_g->second;
+ else
+ throw SALOME_Exception(LOCALIZED ("SMESH_Mesh::AddGroup() wrong ID of SMESHDS_GroupBase"));
+ }
+ SMESH_Group* aGroup = new SMESH_Group (groupDS);
+ _mapGroup[ groupDS->GetID() ] = aGroup;
+ GetMeshDS()->AddGroup( aGroup->GetGroupDS() );
+
+ _groupId = 1 + _mapGroup.rbegin()->first;
+
+ return aGroup;
+}
+
+
+//================================================================================
+/*!
+ * \brief Creates SMESH_Groups for not wrapped SMESHDS_Groups
+ * \retval bool - true if new SMESH_Groups have been created
+ *
+ */
+//================================================================================
+
+bool SMESH_Mesh::SynchronizeGroups()
+{
+ int nbGroups = _mapGroup.size();
+ const set<SMESHDS_GroupBase*>& groups = _myMeshDS->GetGroups();
+ set<SMESHDS_GroupBase*>::const_iterator gIt = groups.begin();
+ for ( ; gIt != groups.end(); ++gIt )
+ {
+ SMESHDS_GroupBase* groupDS = (SMESHDS_GroupBase*) *gIt;
+ _groupId = groupDS->GetID();
+ if ( !_mapGroup.count( _groupId ))
+ _mapGroup[_groupId] = new SMESH_Group( groupDS );
+ }
+ if ( !_mapGroup.empty() )
+ _groupId = _mapGroup.rbegin()->first + 1;
+
+ return nbGroups < _mapGroup.size();
+}
+
+//================================================================================
+/*!
+ * \brief Return iterator on all existing groups
+ */
+//================================================================================
+
+SMESH_Mesh::GroupIteratorPtr SMESH_Mesh::GetGroups() const
+{
+ typedef map <int, SMESH_Group *> TMap;
+ return GroupIteratorPtr( new SMDS_mapIterator<TMap>( _mapGroup ));
+}
+
+//=============================================================================
+/*!
+ * \brief Return a group by ID
+ */
+//=============================================================================
+
+SMESH_Group* SMESH_Mesh::GetGroup (const int theGroupID)
+{
+ if (_mapGroup.find(theGroupID) == _mapGroup.end())
+ return NULL;
+ return _mapGroup[theGroupID];
+}
+
+
+//=============================================================================
+/*!
+ * \brief Return IDs of all groups
+ */
+//=============================================================================
+
+list<int> SMESH_Mesh::GetGroupIds() const
+{
+ list<int> anIds;
+ for ( map<int, SMESH_Group*>::const_iterator it = _mapGroup.begin(); it != _mapGroup.end(); it++ )
+ anIds.push_back( it->first );
+
+ return anIds;
+}
+
+//================================================================================
+/*!
+ * \brief Set a caller of methods at level of CORBA API implementation.
+ * The set upCaller will be deleted by SMESH_Mesh
+ */
+//================================================================================
+
+void SMESH_Mesh::SetCallUp( TCallUp* upCaller )
+{
+ if ( _callUp ) delete _callUp;
+ _callUp = upCaller;
+}
+
+//=============================================================================
+/*!
+ *
+ */
+//=============================================================================
+
+bool SMESH_Mesh::RemoveGroup (const int theGroupID)
+{
+ if (_mapGroup.find(theGroupID) == _mapGroup.end())
+ return false;
+ GetMeshDS()->RemoveGroup( _mapGroup[theGroupID]->GetGroupDS() );
+ delete _mapGroup[theGroupID];
+ _mapGroup.erase (theGroupID);
+ if (_callUp)
+ _callUp->RemoveGroup( theGroupID );
+ return true;
+}
+
+//=======================================================================
+//function : GetAncestors
+//purpose : return list of ancestors of theSubShape in the order
+// that lower dimention shapes come first.
+//=======================================================================
+
+const TopTools_ListOfShape& SMESH_Mesh::GetAncestors(const TopoDS_Shape& theS) const
+{
+ if ( _mapAncestors.Contains( theS ) )
+ return _mapAncestors.FindFromKey( theS );
+
+ static TopTools_ListOfShape emptyList;
+ return emptyList;
+}
+
+//=======================================================================
+//function : Dump
+//purpose : dumps contents of mesh to stream [ debug purposes ]
+//=======================================================================
+
+ostream& SMESH_Mesh::Dump(ostream& save)
+{
+ int clause = 0;
+ save << "========================== Dump contents of mesh ==========================" << endl << endl;
+ save << ++clause << ") Total number of nodes: \t" << NbNodes() << endl;
+ save << ++clause << ") Total number of edges: \t" << NbEdges() << endl;
+ save << ++clause << ") Total number of faces: \t" << NbFaces() << endl;
+ save << ++clause << ") Total number of polygons:\t" << NbPolygons() << endl;
+ save << ++clause << ") Total number of volumes:\t" << NbVolumes() << endl;
+ save << ++clause << ") Total number of polyhedrons:\t" << NbPolyhedrons() << endl << endl;
+ for ( int isQuadratic = 0; isQuadratic < 2; ++isQuadratic )
+ {
+ string orderStr = isQuadratic ? "quadratic" : "linear";
+ SMDSAbs_ElementOrder order = isQuadratic ? ORDER_QUADRATIC : ORDER_LINEAR;
+
+ save << ++clause << ") Total number of " << orderStr << " edges:\t" << NbEdges(order) << endl;
+ save << ++clause << ") Total number of " << orderStr << " faces:\t" << NbFaces(order) << endl;
+ if ( NbFaces(order) > 0 ) {
+ int nb3 = NbTriangles(order);
+ int nb4 = NbQuadrangles(order);
+ save << clause << ".1) Number of " << orderStr << " triangles: \t" << nb3 << endl;
+ save << clause << ".2) Number of " << orderStr << " quadrangles:\t" << nb4 << endl;
+ if ( nb3 + nb4 != NbFaces(order) ) {
+ map<int,int> myFaceMap;
+ SMDS_FaceIteratorPtr itFaces=_myMeshDS->facesIterator();
+ while( itFaces->more( ) ) {
+ int nbNodes = itFaces->next()->NbNodes();
+ if ( myFaceMap.find( nbNodes ) == myFaceMap.end() )
+ myFaceMap[ nbNodes ] = 0;
+ myFaceMap[ nbNodes ] = myFaceMap[ nbNodes ] + 1;
+ }
+ save << clause << ".3) Faces in detail: " << endl;
+ map <int,int>::iterator itF;
+ for (itF = myFaceMap.begin(); itF != myFaceMap.end(); itF++)
+ save << "--> nb nodes: " << itF->first << " - nb elemens:\t" << itF->second << endl;
+ }
+ }
+ save << ++clause << ") Total number of " << orderStr << " volumes:\t" << NbVolumes(order) << endl;
+ if ( NbVolumes(order) > 0 ) {
+ int nb8 = NbHexas(order);
+ int nb4 = NbTetras(order);
+ int nb5 = NbPyramids(order);
+ int nb6 = NbPrisms(order);
+ save << clause << ".1) Number of " << orderStr << " hexahedrons:\t" << nb8 << endl;
+ save << clause << ".2) Number of " << orderStr << " tetrahedrons:\t" << nb4 << endl;
+ save << clause << ".3) Number of " << orderStr << " prisms: \t" << nb6 << endl;
+ save << clause << ".4) Number of " << orderStr << " pyramids:\t" << nb5 << endl;
+ if ( nb8 + nb4 + nb5 + nb6 != NbVolumes(order) ) {
+ map<int,int> myVolumesMap;
+ SMDS_VolumeIteratorPtr itVolumes=_myMeshDS->volumesIterator();
+ while( itVolumes->more( ) ) {
+ int nbNodes = itVolumes->next()->NbNodes();
+ if ( myVolumesMap.find( nbNodes ) == myVolumesMap.end() )
+ myVolumesMap[ nbNodes ] = 0;
+ myVolumesMap[ nbNodes ] = myVolumesMap[ nbNodes ] + 1;
+ }
+ save << clause << ".5) Volumes in detail: " << endl;
+ map <int,int>::iterator itV;
+ for (itV = myVolumesMap.begin(); itV != myVolumesMap.end(); itV++)
+ save << "--> nb nodes: " << itV->first << " - nb elemens:\t" << itV->second << endl;
+ }
+ }
+ save << endl;
+ }
+ save << "===========================================================================" << endl;
+ return save;
+}
+
+//=======================================================================
+//function : GetElementType
+//purpose : Returns type of mesh element with certain id
+//=======================================================================
+
+SMDSAbs_ElementType SMESH_Mesh::GetElementType( const int id, const bool iselem )
+{
+ return _myMeshDS->GetElementType( id, iselem );
+}
+
+//=============================================================================
+/*!
+ * \brief Convert group on geometry into standalone group
+ */
+//=============================================================================
+
+SMESH_Group* SMESH_Mesh::ConvertToStandalone ( int theGroupID )
+{
+ SMESH_Group* aGroup = 0;
+ map < int, SMESH_Group * >::iterator itg = _mapGroup.find( theGroupID );
+ if ( itg == _mapGroup.end() )
+ return aGroup;
+
+ SMESH_Group* anOldGrp = (*itg).second;
+ SMESHDS_GroupBase* anOldGrpDS = anOldGrp->GetGroupDS();
+ if ( !anOldGrp || !anOldGrpDS )
+ return aGroup;
+
+ // create new standalone group
+ aGroup = new SMESH_Group (theGroupID, this, anOldGrpDS->GetType(), anOldGrp->GetName() );
+ _mapGroup[theGroupID] = aGroup;
+
+ SMESHDS_Group* aNewGrpDS = dynamic_cast<SMESHDS_Group*>( aGroup->GetGroupDS() );
+ GetMeshDS()->RemoveGroup( anOldGrpDS );
+ GetMeshDS()->AddGroup( aNewGrpDS );
+
+ // add elements (or nodes) into new created group
+ SMDS_ElemIteratorPtr anItr = anOldGrpDS->GetElements();
+ while ( anItr->more() )
+ aNewGrpDS->Add( (anItr->next())->GetID() );
+
+ // set color
+ aNewGrpDS->SetColor( anOldGrpDS->GetColor() );
+
+ // remove old group
+ delete anOldGrp;
+
+ return aGroup;
+}
+
+//=============================================================================
+/*!
+ * \brief remove submesh order from Mesh
+ */
+//=============================================================================
+
+void SMESH_Mesh::ClearMeshOrder()
+{
+ _mySubMeshOrder.clear();
+}
+
+//=============================================================================
+/*!
+ * \brief remove submesh order from Mesh
+ */
+//=============================================================================
+
+void SMESH_Mesh::SetMeshOrder(const TListOfListOfInt& theOrder )
+{
+ _mySubMeshOrder = theOrder;
+}
+
+//=============================================================================
+/*!
+ * \brief return submesh order if any
+ */
+//=============================================================================
+
+const TListOfListOfInt& SMESH_Mesh::GetMeshOrder() const
+{
+ return _mySubMeshOrder;
+}
+
+//=============================================================================
+/*!
+ * \brief fill _mapAncestors
+ */
+//=============================================================================
+
+void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
+{
+
+ int desType, ancType;
+ if ( !theShape.IsSame( GetShapeToMesh()) && theShape.ShapeType() == TopAbs_COMPOUND )
+ {
+ // a geom group is added. Insert it into lists of ancestors before
+ // the first ancestor more complex than group members
+ TopoDS_Iterator subIt( theShape );
+ if ( !subIt.More() ) return;
+ int memberType = subIt.Value().ShapeType();
+ for ( desType = TopAbs_VERTEX; desType >= memberType; desType-- )
+ for (TopExp_Explorer des( theShape, TopAbs_ShapeEnum( desType )); des.More(); des.Next())
+ {
+ if ( !_mapAncestors.Contains( des.Current() )) continue;// issue 0020982
+ TopTools_ListOfShape& ancList = _mapAncestors.ChangeFromKey( des.Current() );
+ TopTools_ListIteratorOfListOfShape ancIt (ancList);
+ while ( ancIt.More() && ancIt.Value().ShapeType() >= memberType )
+ ancIt.Next();
+ if ( ancIt.More() )
+ ancList.InsertBefore( theShape, ancIt );
+ }
+ }
+ {
+ for ( desType = TopAbs_VERTEX; desType > TopAbs_COMPOUND; desType-- )
+ for ( ancType = desType - 1; ancType >= TopAbs_COMPOUND; ancType-- )
+ TopExp::MapShapesAndAncestors ( theShape,
+ (TopAbs_ShapeEnum) desType,
+ (TopAbs_ShapeEnum) ancType,
+ _mapAncestors );
+ }
+ // visit COMPOUNDs inside a COMPOUND that are not reachable by TopExp_Explorer
+ if ( theShape.ShapeType() == TopAbs_COMPOUND )
+ {
+ for ( TopoDS_Iterator sIt(theShape); sIt.More(); sIt.Next() )
+ if ( sIt.Value().ShapeType() == TopAbs_COMPOUND )
+ fillAncestorsMap( sIt.Value() );
+ }
+}
+
+//=============================================================================
+/*!
+ * \brief sort submeshes according to stored mesh order
+ * \param theListToSort in out list to be sorted
+ * \return FALSE if nothing sorted
+ */
+//=============================================================================
+
+bool SMESH_Mesh::SortByMeshOrder(list<SMESH_subMesh*>& theListToSort) const
+{
+ if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
+ return true;
+
+ bool res = false;
+ list<SMESH_subMesh*> onlyOrderedList;
+ // collect all ordered submeshes in one list as pointers
+ // and get their positions within theListToSort
+ typedef list<SMESH_subMesh*>::iterator TPosInList;
+ map< int, TPosInList > sortedPos;
+ TPosInList smBeg = theListToSort.begin(), smEnd = theListToSort.end();
+ TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
+ for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++) {
+ const TListOfInt& listOfId = *listIdsIt;
+ TListOfInt::const_iterator idIt = listOfId.begin();
+ for ( ; idIt != listOfId.end(); idIt++ ) {
+ if ( SMESH_subMesh * sm = GetSubMeshContaining( *idIt )) {
+ TPosInList smPos = find( smBeg, smEnd, sm );
+ if ( smPos != smEnd ) {
+ onlyOrderedList.push_back( sm );
+ sortedPos[ distance( smBeg, smPos )] = smPos;
+ }
+ }
+ }
+ }
+ if (onlyOrderedList.size() < 2)
+ return res;
+ res = true;
+
+ list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
+ list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
+
+ // iterate on ordered submeshes and insert them in detected positions
+ map< int, TPosInList >::iterator i_pos = sortedPos.begin();
+ for ( ; onlyBIt != onlyEIt; ++onlyBIt, ++i_pos )
+ *(i_pos->second) = *onlyBIt;
+
+ return res;
+}
+
+//================================================================================
+/*!
+ * \brief Return true if given order of sub-meshes is OK
+ */
+//================================================================================
+
+bool SMESH_Mesh::IsOrderOK( const SMESH_subMesh* smBefore,
+ const SMESH_subMesh* smAfter ) const
+{
+ TListOfListOfInt::const_iterator listIdsIt = _mySubMeshOrder.begin();
+ TListOfInt::const_iterator idBef, idAft;
+ for( ; listIdsIt != _mySubMeshOrder.end(); listIdsIt++)
+ {
+ const TListOfInt& listOfId = *listIdsIt;
+ idBef = std::find( listOfId.begin(), listOfId.end(), smBefore->GetId() );
+ if ( idBef != listOfId.end() )
+ idAft = std::find( listOfId.begin(), listOfId.end(), smAfter->GetId() );
+ if ( idAft != listOfId.end () )
+ return ( std::distance( listOfId.begin(), idBef ) <
+ std::distance( listOfId.begin(), idAft ) );
+ }
+ return true; // no order imposed to given submeshes
+}
+
+//=============================================================================
+/*!
+ * \brief sort submeshes according to stored mesh order
+ * \param theListToSort in out list to be sorted
+ * \return FALSE if nothing sorted
+ */
+//=============================================================================
+
+list<SMESH_subMesh*>
+SMESH_Mesh::getAncestorsSubMeshes (const TopoDS_Shape& theSubShape) const
+{
+ list<SMESH_subMesh*> listOfSubMesh;
+ TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
+ for (; it.More(); it.Next() )
+ if ( SMESH_subMesh* sm = GetSubMeshContaining( it.Value() ))
+ listOfSubMesh.push_back(sm);
+
+ // sort submeshes according to stored mesh order
+ SortByMeshOrder( listOfSubMesh );
+
+ return listOfSubMesh;
+}