Salome HOME
PR: synchro V7_main tag mergefrom_V6_main_28Feb13
[modules/smesh.git] / src / StdMeshers / StdMeshers_Import_1D.cxx
index 1fcd7d56005734a87b5bc40cc50601a08a198020..760a14a8ca40c3aee99531e032f4110e0dc07c63 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -134,7 +134,7 @@ namespace // INTERNAL STUFF
     _ListenerData(const StdMeshers_ImportSource1D* h, _ListenerDataType type=SRC_HYP):
       SMESH_subMeshEventListenerData(/*isDeletable=*/true), _srcHyp(h)
     {
-      myType = type; 
+      myType = type;
     }
   };
   //================================================================================
@@ -246,7 +246,8 @@ namespace // INTERNAL STUFF
     typedef map< SMESH_Mesh*, list< _ImportData > > TMesh2ImpData;
     TMesh2ImpData _tgtMesh2ImportData;
 
-    _Listener():SMESH_subMeshEventListener(/*isDeletable=*/false){}
+    _Listener():SMESH_subMeshEventListener(/*isDeletable=*/false,
+                                           "StdMeshers_Import_1D::_Listener") {}
 
   public:
     // return poiter to a static listener
@@ -303,14 +304,16 @@ namespace // INTERNAL STUFF
     // set listener to hear events of the submesh computed by "Import" algo
     importSub->SetEventListener( get(), new _ListenerData(srcHyp), importSub );
 
-    // set a listener to hear events of the source mesh
+    // set listeners to hear events of the source mesh
     SMESH_subMesh* smToNotify = importSub;
-    SMESH_subMesh* smToListen = srcMesh->GetSubMeshContaining(1);
-    SMESH_subMeshEventListenerData* data = new _ListenerData(srcHyp, LISTEN_SRC_MESH);
-    data->mySubMeshes.push_back( smToNotify );
-    importSub->SetEventListener( get(), data, smToListen );
-
-    // remeber the submesh importSub and its sub-submeshes
+    vector<SMESH_subMesh*> smToListen = srcHyp->GetSourceSubMeshes( srcMesh );
+    for ( size_t i = 0; i < smToListen.size(); ++i )
+    {
+      SMESH_subMeshEventListenerData* data = new _ListenerData(srcHyp, LISTEN_SRC_MESH);
+      data->mySubMeshes.push_back( smToNotify );
+      importSub->SetEventListener( get(), data, smToListen[i] );
+    }
+    // remember the submesh importSub and its sub-submeshes
     _ImportData* iData = _Listener::getImportData( srcMesh, importSub->GetFather());
     iData->trackHypParams( importSub, srcHyp );
     iData->addComputed( importSub );
@@ -370,11 +373,11 @@ namespace // INTERNAL STUFF
           // clear the rest submeshes
           if ( !d->_computedSubM.empty() )
           {
-            set< SMESH_subMesh*, _SubLess> subs;
-            subs.swap( d->_computedSubM ); // avoid recursion via events
-            while ( !subs.empty() )
+            d->_computedSubM.clear();
+            set< SMESH_subMesh*, _SubLess>::iterator sub = d->_subM.begin();
+            for ( ; sub != d->_subM.end(); ++sub )
             {
-              SMESH_subMesh* subM = *subs.begin(); subs.erase( subs.begin() );
+              SMESH_subMesh* subM = *sub;
               _ListenerData* hypData = (_ListenerData*) subM->GetEventListenerData( get() );
               if ( hypData )
                 d->removeGroups( sm, hypData->_srcHyp );
@@ -507,7 +510,7 @@ namespace // INTERNAL STUFF
   {
     // To get SMESH_subMesh corresponding to srcMeshDS we need to have a shape
     // for which SMESHDS_Mesh::IsGroupOfSubShapes() returns true.
-    // And this shape must be different from subshapes of the main shape.
+    // And this shape must be different from sub-shapes of the main shape.
     // So we create a compound containing
     // 1) some sub-shapes of SMESH_Mesh::PseudoShape() corresponding to
     //    srcMeshDS->GetPersistentId()
@@ -518,7 +521,7 @@ namespace // INTERNAL STUFF
     TopExp::MapShapes( SMESH_Mesh::PseudoShape(), pseudoSubShapes );
 
     // index of pseudoSubShapes corresponding to srcMeshDS
-    int subIndex = srcMeshDS->GetPersistentId() % pseudoSubShapes.Extent();
+    int    subIndex = 1 + srcMeshDS->GetPersistentId() % pseudoSubShapes.Extent();
     int nbSubShapes = 1 + srcMeshDS->GetPersistentId() / pseudoSubShapes.Extent();
 
     // try to find already present shapeForSrcMesh
@@ -610,7 +613,7 @@ namespace // INTERNAL STUFF
 
 //=============================================================================
 /*!
- * Import elements from the other mesh 
+ * Import elements from the other mesh
  */
 //=============================================================================
 
@@ -634,8 +637,8 @@ bool StdMeshers_Import_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & th
   subShapeIDs.insert( shapeID );
 
   // get nodes on vertices
-  list < SMESH_TNodeXYZ > vertexNodes; 
- list < SMESH_TNodeXYZ >::iterator vNIt;
+  list < SMESH_TNodeXYZ > vertexNodes;
 list < SMESH_TNodeXYZ >::iterator vNIt;
   TopExp_Explorer vExp( theShape, TopAbs_VERTEX );
   for ( ; vExp.More(); vExp.Next() )
   {
@@ -667,7 +670,7 @@ bool StdMeshers_Import_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & th
     SMDS_ElemIteratorPtr srcElems = srcGroup->GetElements();
     vector<const SMDS_MeshNode*> newNodes;
     SMDS_MeshNode *tmpNode = helper.AddNode(0,0,0);
-    double u;
+    double u = 0;
     while ( srcElems->more() ) // loop on group contents
     {
       const SMDS_MeshElement* edge = srcElems->next();
@@ -675,6 +678,10 @@ bool StdMeshers_Import_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & th
       newNodes.resize( edge->NbNodes() );
       newNodes.back() = 0;
       SMDS_MeshElement::iterator node = edge->begin_nodes();
+      SMESH_TNodeXYZ a(edge->GetNode(0));
+      // --- define a tolerance relative to the length of an edge
+      double mytol = a.Distance(edge->GetNode(edge->NbNodes()-1))/25;
+      //MESSAGE("mytol = " << mytol);
       for ( unsigned i = 0; i < newNodes.size(); ++i, ++node )
       {
         TNodeNodeMap::iterator n2nIt = n2n->insert( make_pair( *node, (SMDS_MeshNode*)0 )).first;
@@ -698,7 +705,7 @@ bool StdMeshers_Import_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & th
         {
           // find out if node lies on theShape
           tmpNode->setXYZ( (*node)->X(), (*node)->Y(), (*node)->Z());
-          if ( helper.CheckNodeU( geomEdge, tmpNode, u, 10 * edgeTol, /*force=*/true ))
+          if ( helper.CheckNodeU( geomEdge, tmpNode, u, mytol, /*force=*/true ))
           {
             SMDS_MeshNode* newNode = tgtMesh->AddNode( (*node)->X(), (*node)->Y(), (*node)->Z());
             n2nIt->second = newNode;
@@ -903,7 +910,7 @@ void StdMeshers_Import_1D::importMesh(const SMESH_Mesh*          srcMesh,
  */
 //=============================================================================
 
-void StdMeshers_Import_1D::setEventListener(SMESH_subMesh*             subMesh, 
+void StdMeshers_Import_1D::setEventListener(SMESH_subMesh*             subMesh,
                                             StdMeshers_ImportSource1D* sourceHyp)
 {
   if ( sourceHyp )