+//=============================================================================
+/*!
+ * \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 fillAncestorsMap
+ */
+//=============================================================================
+
+void SMESH_Mesh::fillAncestorsMap(const TopoDS_Shape& theShape)
+{
+ // fill _mapAncestors
+ int desType, ancType;
+ 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 );
+}
+
+//=============================================================================
+/*!
+ * \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(std::list<SMESH_subMesh*>& theListToSort) const
+{
+ if ( !_mySubMeshOrder.size() || theListToSort.size() < 2)
+ return true;
+
+ bool res = false;
+ std::list<SMESH_subMesh*> onlyOrderedList;
+ // collect all ordered submeshes in one list as pointers
+ TListOfListOfInt::const_iterator listIddIt = _mySubMeshOrder.begin();
+ for( ; listIddIt != _mySubMeshOrder.end(); listIddIt++) {
+ const TListOfInt& listOfId = *listIddIt;
+ TListOfInt::const_iterator idIt = listOfId.begin();
+ for ( ; idIt != listOfId.end(); idIt++ ) {
+ map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(*idIt);
+ if ( i_sm != _mapSubMesh.end() )
+ onlyOrderedList.push_back(i_sm->second);
+ }
+ }
+ if (!onlyOrderedList.size())
+ return res;
+
+ std::list<SMESH_subMesh*>::iterator onlyBIt = onlyOrderedList.begin();
+ std::list<SMESH_subMesh*>::iterator onlyEIt = onlyOrderedList.end();
+
+ // check positions where ordered submeshes should be in result list
+ std::set<int> setOfPos; // remember positions of in set
+ std::list<SMESH_subMesh*>::const_iterator smIt = theListToSort.begin();
+ int i = 0;
+ for( ; smIt != theListToSort.end(); i++, smIt++ )
+ if ( find( onlyBIt, onlyEIt, *smIt ) != onlyEIt )
+ setOfPos.insert(i);
+
+ if ( !setOfPos.size() )
+ return res;
+
+ // new list of all submeshes to be sorted
+ std::list<SMESH_subMesh*> aNewList;
+ // iterates on submeshes and insert ordered in detected positions
+ for ( i = 0, smIt = theListToSort.begin(); smIt != theListToSort.end(); i++, smIt++ )
+ if ( setOfPos.find( i ) != setOfPos.end() &&
+ onlyBIt != onlyEIt ) { // position of ordered submesh detected
+ aNewList.push_back( *onlyBIt ); // ordered submesh
+ onlyBIt++;
+ }
+ else
+ aNewList.push_back( *smIt ); // other submesh from list
+
+ theListToSort = aNewList;
+ return res;
+}
+
+//=============================================================================
+/*!
+ * \brief sort submeshes according to stored mesh order
+ * \param theListToSort in out list to be sorted
+ * \return FALSE if nothing sorted
+ */
+//=============================================================================
+
+std::list<SMESH_subMesh*> SMESH_Mesh::getAncestorsSubMeshes
+ (const TopoDS_Shape& theSubShape) const
+{
+ std::list<SMESH_subMesh*> listOfSubMesh;
+ TopTools_ListIteratorOfListOfShape it( GetAncestors( theSubShape ));
+ for (; it.More(); it.Next() ) {
+ int index = _myMeshDS->ShapeToIndex(it.Value());
+ map <int, SMESH_subMesh *>::const_iterator i_sm = _mapSubMesh.find(index);
+ if (i_sm != _mapSubMesh.end())
+ listOfSubMesh.push_back(i_sm->second);
+ }
+
+ // sort submeshes according to stored mesh order
+ SortByMeshOrder( listOfSubMesh );
+
+ return listOfSubMesh;
+}