Salome HOME
Merge from V6_main (04/10/2012)
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
index 2e4d1772c2a1bd5c01ea74c750e27528eda85aeb..3bcdb181ca7898578e1983fe74f1630f9bbd912d 100644 (file)
@@ -43,6 +43,7 @@
 #include "SMESH_MEDMesh_i.hxx"
 #include "SMESH_MeshEditor.hxx"
 #include "SMESH_MeshEditor_i.hxx"
+#include "SMESH_MeshPartDS.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_PreMeshInfo.hxx"
 #include "SMESH_PythonDump.hxx"
 #include <OSD_File.hxx>
 #include <OSD_Path.hxx>
 #include <OSD_Protection.hxx>
+#include <Standard_OutOfMemory.hxx>
 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
 #include <TColStd_MapOfInteger.hxx>
 #include <TColStd_SequenceOfInteger.hxx>
 #include <TCollection_AsciiString.hxx>
 #include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
-#include <TopoDS_Compound.hxx>
-#include <TopTools_MapOfShape.hxx>
 #include <TopTools_MapIteratorOfMapOfShape.hxx>
+#include <TopTools_MapOfShape.hxx>
+#include <TopoDS_Compound.hxx>
 
 // STL Includes
 #include <algorithm>
@@ -304,7 +306,7 @@ void SMESH_Mesh_i::ClearSubMesh(CORBA::Long ShapeID)
 
 //=============================================================================
 /*!
- *
+ * Convert enum Driver_Mesh::Status to SMESH::DriverMED_ReadStatus
  */
 //=============================================================================
 
@@ -328,6 +330,30 @@ static SMESH::DriverMED_ReadStatus ConvertDriverMEDReadStatus (int theStatus)
   return res;
 }
 
+//=============================================================================
+/*!
+ * Convert ::SMESH_ComputeError to SMESH::ComputeError
+ */
+//=============================================================================
+
+static SMESH::ComputeError* ConvertComputeError( SMESH_ComputeErrorPtr errorPtr )
+{
+  SMESH::ComputeError_var errVar = new SMESH::ComputeError();
+  errVar->subShapeID = -1;
+  errVar->hasBadMesh = false;
+
+  if ( !errorPtr || errorPtr->IsOK() )
+  {
+    errVar->code = SMESH::COMPERR_OK;
+  }
+  else
+  {
+    errVar->code = ConvertDriverMEDReadStatus( errorPtr->myName );
+    errVar->comment = errorPtr->myComment.c_str();
+  }
+  return errVar._retn();
+}
+
 //=============================================================================
 /*!
  *  ImportMEDFile
@@ -451,6 +477,45 @@ int SMESH_Mesh_i::ImportSTLFile( const char* theFileName )
   return 1;
 }
 
+//================================================================================
+/*!
+ * \brief Imports data from a GMF file and returns an error description
+ */
+//================================================================================
+
+SMESH::ComputeError* SMESH_Mesh_i::ImportGMFFile( const char* theFileName )
+  throw (SALOME::SALOME_Exception)
+{
+  SMESH_ComputeErrorPtr error;
+  try {
+    error = _impl->GMFToMesh( theFileName );
+  }
+  catch ( std::bad_alloc& exc ) {
+    error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "std::bad_alloc raised" );
+  }
+  catch ( Standard_OutOfMemory& exc ) {
+    error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "Standard_OutOfMemory raised" );
+  }
+  catch (Standard_Failure& ex) {
+    error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, ex.DynamicType()->Name() );
+    if ( ex.GetMessageString() && strlen( ex.GetMessageString() ))
+      error->myComment += string(": ") + ex.GetMessageString();
+  }
+  catch ( SALOME_Exception& S_ex ) {
+    error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, S_ex.what() );
+  }
+  catch ( std::exception& exc ) {
+    error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, exc.what() );
+  }
+  catch (...) {
+    error = SMESH_ComputeError::New( Driver_Mesh::DRS_FAIL, "Unknown exception" );
+  }
+
+  CreateGroupServants();
+
+  return ConvertComputeError( error );
+}
+
 //=============================================================================
 /*!
  *
@@ -2838,37 +2903,6 @@ void SMESH_Mesh_i::ExportSTL (const char *file, const bool isascii)
   _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_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;
-  virtual SMDS_ElemIteratorPtr elementGeomIterator(SMDSAbs_GeometryType type) const;
-  virtual SMDS_ElemIteratorPtr elementEntityIterator(SMDSAbs_EntityType type) 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
@@ -2991,13 +3025,36 @@ void SMESH_Mesh_i::ExportCGNS(::SMESH::SMESH_IDSource_ptr meshPart,
   SMESH_MeshPartDS partDS( meshPart );
   _impl->ExportCGNS(file, &partDS);
 
-  TPythonDump() << _this() << ".ExportCGNS( "
-                << meshPart<< ", r'" << file << "', " << overwrite << ")";
+  TPythonDump() << _this() << ".ExportCGNS( r'"
+                << file << "', " << overwrite << ", "<< meshPart<< ")";
 #else
   THROW_SALOME_CORBA_EXCEPTION("CGNS library is unavailable", SALOME::INTERNAL_ERROR);
 #endif
 }
 
+//================================================================================
+/*!
+ * \brief Export a part of mesh to a GMF file
+ */
+//================================================================================
+
+void SMESH_Mesh_i::ExportGMF(::SMESH::SMESH_IDSource_ptr meshPart,
+                             const char*                 file)
+  throw (SALOME::SALOME_Exception)
+{
+  Unexpect aCatch(SALOME_SalomeException);
+  if ( _preMeshInfo )
+    _preMeshInfo->FullLoadFromFile();
+
+  PrepareForWriting(file,/*overwrite=*/true);
+
+  SMESH_MeshPartDS partDS( meshPart );
+  _impl->ExportGMF(file, &partDS);
+
+  TPythonDump() << _this() << ".ExportGMF( r'"
+                << file << "', "<< meshPart<< ")";
+}
+
 //=============================================================================
 /*!
  * Return implementation of SALOME_MED::MESH interfaces
@@ -4083,7 +4140,7 @@ SMESH::double_array* SMESH_Mesh_i::BaryCenter(const CORBA::Long id)
  */
 //=============================================================================
 
-void SMESH_Mesh_i::CreateGroupServants() 
+void SMESH_Mesh_i::CreateGroupServants()
 {
   SALOMEDS::Study_ptr aStudy = _gen_i->GetCurrentStudy();
 
@@ -4352,12 +4409,14 @@ void SMESH_Mesh_i::CollectMeshInfo(const SMDS_ElemIteratorPtr theItr,
 }
 
 //=============================================================================
+namespace // Finding concurrent hypotheses
+//=============================================================================
+{
+
 /*!
  * \brief mapping of mesh dimension into shape type
  */
-//=============================================================================
-
-static TopAbs_ShapeEnum shapeTypeByDim(const int theDim)
+TopAbs_ShapeEnum shapeTypeByDim(const int theDim)
 {
   TopAbs_ShapeEnum aType = TopAbs_SOLID;
   switch ( theDim ) {
@@ -4370,7 +4429,7 @@ static TopAbs_ShapeEnum shapeTypeByDim(const int theDim)
   return aType;
 }
 
-//=============================================================================
+//-----------------------------------------------------------------------------
 /*!
  * \brief Internal structure used to find concurent submeshes
  *
@@ -4379,8 +4438,6 @@ static TopAbs_ShapeEnum shapeTypeByDim(const int theDim)
  *  with another submesh. In other words, it is dimension of a hypothesis assigned
  *  to submesh.
  */
-//=============================================================================
-
 class SMESH_DimHyp
 {
  public:
@@ -4389,8 +4446,14 @@ class SMESH_DimHyp
   int _ownDim; //!< dimension of shape of _subMesh (>=_dim)
   TopTools_MapOfShape _shapeMap;
   SMESH_subMesh*      _subMesh;
-  list<const SMESHDS_Hypothesis*> _hypothesises; //!< algo is first, then its parameters
+  list<const SMESHDS_Hypothesis*> _hypotheses; //!< algo is first, then its parameters
+
+  //-----------------------------------------------------------------------------
+  // Return the algorithm
+  const SMESH_Algo* GetAlgo() const
+  { return _hypotheses.empty() ? 0 : dynamic_cast<const SMESH_Algo*>( _hypotheses.front() ); }
 
+  //-----------------------------------------------------------------------------
   //! Constructors
   SMESH_DimHyp(const SMESH_subMesh*  theSubMesh,
                const int             theDim,
@@ -4400,6 +4463,7 @@ class SMESH_DimHyp
     SetShape( theDim, theShape );
   }
 
+  //-----------------------------------------------------------------------------
   //! set shape
   void SetShape(const int           theDim,
                 const TopoDS_Shape& theShape)
@@ -4415,6 +4479,7 @@ class SMESH_DimHyp
     }
   }
 
+  //-----------------------------------------------------------------------------
   //! Check sharing of sub-shapes
   static bool isShareSubShapes(const TopTools_MapOfShape& theToCheck,
                                const TopTools_MapOfShape& theToFind,
@@ -4435,11 +4500,13 @@ class SMESH_DimHyp
     return isShared;
   }
   
+  //-----------------------------------------------------------------------------
   //! check algorithms
   static bool checkAlgo(const SMESHDS_Hypothesis* theA1,
                         const SMESHDS_Hypothesis* theA2)
   {
-    if ( theA1->GetType() == SMESHDS_Hypothesis::PARAM_ALGO ||
+    if ( !theA1 || !theA2 ||
+         theA1->GetType() == SMESHDS_Hypothesis::PARAM_ALGO ||
          theA2->GetType() == SMESHDS_Hypothesis::PARAM_ALGO )
       return false; // one of the hypothesis is not algorithm
     // check algorithm names (should be equal)
@@ -4447,6 +4514,7 @@ class SMESH_DimHyp
   }
 
   
+  //-----------------------------------------------------------------------------
   //! Check if sub-shape hypotheses are concurrent
   bool IsConcurrent(const SMESH_DimHyp* theOther) const
   {
@@ -4456,8 +4524,10 @@ class SMESH_DimHyp
     // if ( <own dim of either of submeshes> == <concurrent dim> &&
     //      any of the two submeshes is not on COMPOUND shape )
     //  -> no concurrency
-    bool meIsCompound = (_subMesh->GetSubMeshDS() && _subMesh->GetSubMeshDS()->IsComplexSubmesh());
-    bool otherIsCompound = (theOther->_subMesh->GetSubMeshDS() && theOther->_subMesh->GetSubMeshDS()->IsComplexSubmesh());
+    bool meIsCompound    = (_subMesh->GetSubMeshDS() &&
+                            _subMesh->GetSubMeshDS()->IsComplexSubmesh());
+    bool otherIsCompound = (theOther->_subMesh->GetSubMeshDS() &&
+                            theOther->_subMesh->GetSubMeshDS()->IsComplexSubmesh());
     if ( (_ownDim == _dim  || theOther->_ownDim == _dim ) && (!meIsCompound || !otherIsCompound))
       return false;
 
@@ -4469,65 +4539,102 @@ class SMESH_DimHyp
         return false;
 
     // check algorithms to be same
-    if (!checkAlgo( _hypothesises.front(), theOther->_hypothesises.front() ))
-      return true; // different algorithms
-    
+    if ( !checkAlgo( this->GetAlgo(), theOther->GetAlgo() ))
+      return true; // different algorithms -> concurrency !
+
     // check hypothesises for concurrence (skip first as algorithm)
     int nbSame = 0;
-    // pointers should be same, becase it is referenes from mesh hypothesis partition
-    list <const SMESHDS_Hypothesis*>::const_iterator hypIt = _hypothesises.begin();
-    list <const SMESHDS_Hypothesis*>::const_iterator otheEndIt = theOther->_hypothesises.end();
-    for ( hypIt++ /*skip first as algo*/; hypIt != _hypothesises.end(); hypIt++ )
-      if ( find( theOther->_hypothesises.begin(), otheEndIt, *hypIt ) != otheEndIt )
+    // pointers should be same, because it is referened from mesh hypothesis partition
+    list <const SMESHDS_Hypothesis*>::const_iterator hypIt = _hypotheses.begin();
+    list <const SMESHDS_Hypothesis*>::const_iterator otheEndIt = theOther->_hypotheses.end();
+    for ( hypIt++ /*skip first as algo*/; hypIt != _hypotheses.end(); hypIt++ )
+      if ( find( theOther->_hypotheses.begin(), otheEndIt, *hypIt ) != otheEndIt )
         nbSame++;
     // the submeshes are concurrent if their algorithms has different parameters
-    return nbSame != theOther->_hypothesises.size() - 1;
+    return nbSame != theOther->_hypotheses.size() - 1;
+  }
+
+  // Return true if algorithm of this SMESH_DimHyp is used if no
+  // sub-mesh order is imposed by the user
+  bool IsHigherPriorityThan( const SMESH_DimHyp* theOther ) const
+  {
+    // NeedDiscreteBoundary() algo has a higher priority
+    if ( this    ->GetAlgo()->NeedDiscreteBoundary() !=
+         theOther->GetAlgo()->NeedDiscreteBoundary() )
+      return !this->GetAlgo()->NeedDiscreteBoundary();
+
+    return ( this->_subMesh->GetId() < theOther->_subMesh->GetId() );
   }
   
 }; // end of SMESH_DimHyp
+//-----------------------------------------------------------------------------
+
+typedef list<const SMESH_DimHyp*> TDimHypList;
 
-typedef list<SMESH_DimHyp*> TDimHypList;
+//-----------------------------------------------------------------------------
 
-static void addDimHypInstance(const int               theDim, 
-                              const TopoDS_Shape&     theShape,
-                              const SMESH_Algo*       theAlgo,
-                              const SMESH_subMesh*    theSubMesh,
-                              const list <const SMESHDS_Hypothesis*>& theHypList,
-                              TDimHypList*            theDimHypListArr )
+void addDimHypInstance(const int                               theDim, 
+                       const TopoDS_Shape&                     theShape,
+                       const SMESH_Algo*                       theAlgo,
+                       const SMESH_subMesh*                    theSubMesh,
+                       const list <const SMESHDS_Hypothesis*>& theHypList,
+                       TDimHypList*                            theDimHypListArr )
 {
   TDimHypList& listOfdimHyp = theDimHypListArr[theDim];
   if ( listOfdimHyp.empty() || listOfdimHyp.back()->_subMesh != theSubMesh ) {
     SMESH_DimHyp* dimHyp = new SMESH_DimHyp( theSubMesh, theDim, theShape );
+    dimHyp->_hypotheses.push_front(theAlgo);
     listOfdimHyp.push_back( dimHyp );
   }
   
-  SMESH_DimHyp* dimHyp = listOfdimHyp.back();
-  dimHyp->_hypothesises.push_front(theAlgo);
-  list <const SMESHDS_Hypothesis*>::const_iterator hypIt = theHypList.begin();
-  for( ; hypIt != theHypList.end(); hypIt++ )
-    dimHyp->_hypothesises.push_back( *hypIt );
+  SMESH_DimHyp* dimHyp = const_cast<SMESH_DimHyp*>( listOfdimHyp.back() );
+  dimHyp->_hypotheses.insert( dimHyp->_hypotheses.end(),
+                              theHypList.begin(), theHypList.end() );
 }
 
-static void findConcurrents(const SMESH_DimHyp* theDimHyp,
-                            const TDimHypList&  theListOfDimHyp,
-                            TListOfInt&         theListOfConcurr )
+//-----------------------------------------------------------------------------
+void addInOrderOfPriority( const SMESH_DimHyp* theDimHyp,
+                           TDimHypList&        theListOfConcurr)
+{
+  if ( theListOfConcurr.empty() )
+  {
+    theListOfConcurr.push_back( theDimHyp );
+  }
+  else
+  {
+    TDimHypList::iterator hypIt = theListOfConcurr.begin();
+    while ( hypIt != theListOfConcurr.end() &&
+            !theDimHyp->IsHigherPriorityThan( *hypIt ))
+      ++hypIt;
+    theListOfConcurr.insert( hypIt, theDimHyp );
+  }
+}
+
+//-----------------------------------------------------------------------------
+void findConcurrents(const SMESH_DimHyp* theDimHyp,
+                     const TDimHypList&  theListOfDimHyp,
+                     TDimHypList&        theListOfConcurrHyp,
+                     set<int>&           theSetOfConcurrId )
 {
   TDimHypList::const_reverse_iterator rIt = theListOfDimHyp.rbegin();
-  for ( ; rIt != theListOfDimHyp.rend(); rIt++ ) {
+  for ( ; rIt != theListOfDimHyp.rend(); rIt++ )
+  {
     const SMESH_DimHyp* curDimHyp = *rIt;
     if ( curDimHyp == theDimHyp )
       break; // meet own dimHyp pointer in same dimension
-    else if ( theDimHyp->IsConcurrent( curDimHyp ) )
-      if ( find( theListOfConcurr.begin(),
-                 theListOfConcurr.end(),
-                 curDimHyp->_subMesh->GetId() ) == theListOfConcurr.end() )
-        theListOfConcurr.push_back( curDimHyp->_subMesh->GetId() );
+
+    if ( theDimHyp->IsConcurrent( curDimHyp ) &&
+         theSetOfConcurrId.insert( curDimHyp->_subMesh->GetId() ).second )
+    {
+      addInOrderOfPriority( curDimHyp, theListOfConcurrHyp );
+    }
   }
 }
 
-static void unionLists(TListOfInt&       theListOfId,
-                       TListOfListOfInt& theListOfListOfId,
-                       const int         theIndx )
+//-----------------------------------------------------------------------------
+void unionLists(TListOfInt&       theListOfId,
+                TListOfListOfInt& theListOfListOfId,
+                const int         theIndx )
 {
   TListOfListOfInt::iterator it = theListOfListOfId.begin();
   for ( int i = 0; it != theListOfListOfId.end(); it++, i++ ) {
@@ -4549,9 +4656,10 @@ static void unionLists(TListOfInt&       theListOfId,
     otherListOfId.clear();
   }
 }
+//-----------------------------------------------------------------------------
 
 //! free memory allocated for dimension-hypothesis objects
-static void removeDimHyps( TDimHypList* theArrOfList )
+void removeDimHyps( TDimHypList* theArrOfList )
 {
   for (int i = 0; i < 4; i++ ) {
     TDimHypList& listOfdimHyp = theArrOfList[i];
@@ -4561,6 +4669,28 @@ static void removeDimHyps( TDimHypList* theArrOfList )
   }
 }
 
+//-----------------------------------------------------------------------------
+/*!
+ * \brief find common submeshes with given submesh
+ * \param theSubMeshList list of already collected submesh to check
+ * \param theSubMesh given submesh to intersect with other
+ * \param theCommonSubMeshes collected common submeshes
+ */
+void findCommonSubMesh (list<const SMESH_subMesh*>& theSubMeshList,
+                        const SMESH_subMesh*        theSubMesh,
+                        set<const SMESH_subMesh*>&  theCommon )
+{
+  if ( !theSubMesh )
+    return;
+  list<const SMESH_subMesh*>::const_iterator it = theSubMeshList.begin();
+  for ( ; it != theSubMeshList.end(); it++ )
+    theSubMesh->FindIntersection( *it, theCommon );
+  theSubMeshList.push_back( theSubMesh );
+  //theCommon.insert( theSubMesh );
+}
+
+} // namespace
+
 //=============================================================================
 /*!
  * \brief Return submesh objects list in meshing order
@@ -4579,7 +4709,7 @@ SMESH::submesh_array_array* SMESH_Mesh_i::GetMeshOrder()
   TListOfListOfInt anOrder = mesh.GetMeshOrder(); // is there already defined order?
   if ( !anOrder.size() ) {
 
-    // collect submeshes detecting concurrent algorithms and hypothesises
+    // collect submeshes and detect concurrent algorithms and hypothesises
     TDimHypList dimHypListArr[4]; // dimHyp list for each shape dimension
     
     map<int, ::SMESH_subMesh*>::iterator i_sm = _mapSubMesh.begin();
@@ -4587,7 +4717,7 @@ SMESH::submesh_array_array* SMESH_Mesh_i::GetMeshOrder()
       ::SMESH_subMesh* sm = (*i_sm).second;
       // shape of submesh
       const TopoDS_Shape& aSubMeshShape = sm->GetSubShape();
-      
+
       // list of assigned hypothesises
       const list <const SMESHDS_Hypothesis*>& hypList = mesh.GetHypothesisList(aSubMeshShape);
       // Find out dimensions where the submesh can be concurrent.
@@ -4606,7 +4736,7 @@ SMESH::submesh_array_array* SMESH_Mesh_i::GetMeshOrder()
             anAlgo = mesh.GetGen()->GetAlgo( mesh, anExp.Current() );
         }
         if (!anAlgo)
-          continue; // no assigned algorithm to current submesh
+          continue; // no algorithm assigned to a current submesh
 
         int dim = anAlgo->GetDim(); // top concurrent dimension (see comment to SMESH_DimHyp)
         // the submesh can concurrent at <dim> (or lower dims if !anAlgo->NeedDiscreteBoundary())
@@ -4619,20 +4749,25 @@ SMESH::submesh_array_array* SMESH_Mesh_i::GetMeshOrder()
     
     // iterate on created dimension-hypotheses and check for concurrents
     for ( int i = 0; i < 4; i++ ) {
-      const list<SMESH_DimHyp*>& listOfDimHyp = dimHypListArr[i];
+      const TDimHypList& listOfDimHyp = dimHypListArr[i];
       // check for concurrents in own and other dimensions (step-by-step)
       TDimHypList::const_iterator dhIt = listOfDimHyp.begin();
       for ( ; dhIt != listOfDimHyp.end(); dhIt++ ) {
         const SMESH_DimHyp* dimHyp = *dhIt;
-        TListOfInt listOfConcurr;
+        TDimHypList listOfConcurr;
+        set<int>    setOfConcurrIds;
         // looking for concurrents and collect into own list
         for ( int j = i; j < 4; j++ )
-          findConcurrents( dimHyp, dimHypListArr[j], listOfConcurr );
+          findConcurrents( dimHyp, dimHypListArr[j], listOfConcurr, setOfConcurrIds );
         // check if any concurrents found
         if ( listOfConcurr.size() > 0 ) {
           // add own submesh to list of concurrent
-          listOfConcurr.push_front( dimHyp->_subMesh->GetId() );
-          anOrder.push_back( listOfConcurr );
+          addInOrderOfPriority( dimHyp, listOfConcurr );
+          list<int> listOfConcurrIds;
+          TDimHypList::iterator hypIt = listOfConcurr.begin();
+          for ( ; hypIt != listOfConcurr.end(); ++hypIt )
+            listOfConcurrIds.push_back( (*hypIt)->_subMesh->GetId() );
+          anOrder.push_back( listOfConcurrIds );
         }
       }
     }
@@ -4655,28 +4790,6 @@ SMESH::submesh_array_array* SMESH_Mesh_i::GetMeshOrder()
   return aResult._retn();
 }
 
-//=============================================================================
-/*!
- * \brief find common submeshes with given submesh
- * \param theSubMeshList list of already collected submesh to check
- * \param theSubMesh given submesh to intersect with other
- * \param theCommonSubMeshes collected common submeshes
- */
-//=============================================================================
-
-static void findCommonSubMesh (list<const SMESH_subMesh*>& theSubMeshList,
-                               const SMESH_subMesh*        theSubMesh,
-                               set<const SMESH_subMesh*>&  theCommon )
-{
-  if ( !theSubMesh )
-    return;
-  list<const SMESH_subMesh*>::const_iterator it = theSubMeshList.begin();
-  for ( ; it != theSubMeshList.end(); it++ )
-    theSubMesh->FindIntersection( *it, theCommon );
-  theSubMeshList.push_back( theSubMesh );
-  //theCommon.insert( theSubMesh );
-}
-
 //=============================================================================
 /*!
  * \brief Set submesh object order
@@ -4845,6 +4958,27 @@ SMESH_MeshPartDS::SMESH_MeshPartDS(SMESH::SMESH_IDSource_ptr meshPart):
   }
 }
 // -------------------------------------------------------------------------------------
+SMESH_MeshPartDS::SMESH_MeshPartDS(const std::list< const SMDS_MeshElement* > & meshPart):
+  SMESHDS_Mesh( /*meshID=*/-1, /*isEmbeddedMode=*/true), _meshDS(0)
+{
+  TMeshInfo tmpInfo;
+  list< const SMDS_MeshElement* >::const_iterator partIt = meshPart.begin();
+  for ( ; partIt != meshPart.end(); ++partIt )
+    if ( const SMDS_MeshElement * e = *partIt )
+      if ( _elements[ e->GetType() ].insert( e ).second )
+      {
+        tmpInfo.Add( e );
+        SMDS_ElemIteratorPtr nIt = e->nodesIterator();
+        while ( nIt->more() )
+        {
+          const SMDS_MeshNode * n = (const SMDS_MeshNode*) nIt->next();
+          if ( _elements[ SMDSAbs_Node ].insert( n ).second )
+            tmpInfo.Add( n );
+        }
+      }
+  myInfo = tmpInfo;
+}
+// -------------------------------------------------------------------------------------
 SMDS_ElemIteratorPtr SMESH_MeshPartDS::elementGeomIterator(SMDSAbs_GeometryType geomType) const
 {
   if ( _meshDS ) return _meshDS->elementGeomIterator( geomType );