Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / StdMeshers / StdMeshers_Import_1D.cxx
index 9f4759a596a6bdb55067c9305f56b9c6ce27b6e8..b8a5076b8c10c2eb8fcd9a62a17aba6438245088 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  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
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  This library is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU Lesser General Public
-//  License as published by the Free Software Foundation; either
-//  version 2.1 of the License.
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License.
 //
-//  This library is distributed in the hope that it will be useful,
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-//  Lesser General Public License for more details.
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
-//  You should have received a copy of the GNU Lesser General Public
-//  License along with this library; if not, write to the Free Software
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 //  SMESH SMESH : implementaion of SMESH idl descriptions
@@ -168,7 +168,7 @@ namespace // INTERNAL STUFF
 
     set< SMESH_subMesh*, _SubLess > _subM; // submeshes relating to this srcMesh
     set< SMESH_subMesh*, _SubLess > _copyMeshSubM; // submeshes requesting mesh copying
-    set< SMESH_subMesh*, _SubLess > _copyGroupSubM; // submeshes requesting mesh copying
+    set< SMESH_subMesh*, _SubLess > _copyGroupSubM; // submeshes requesting group copying
     set< SMESH_subMesh*, _SubLess > _computedSubM;
 
     SMESHDS_SubMesh*     _importMeshSubDS; // submesh storing a copy of _srcMesh
@@ -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 );
@@ -413,8 +416,7 @@ namespace // INTERNAL STUFF
       {
         // re-call SetEventListener() to take into account valid parameters
         // of ImportSource hypothesis
-        SMESH_Gen* gen = subMesh->GetFather()->GetGen();
-        if ( SMESH_Algo* algo = gen->GetAlgo(*subMesh->GetFather(), subMesh->GetSubShape()))
+        if ( SMESH_Algo* algo = subMesh->GetAlgo() )
           algo->SetEventListener( subMesh );
       }
     }
@@ -457,11 +459,11 @@ namespace // INTERNAL STUFF
       {
         removeImport = true;
       }
-      else if ( SMESH_subMesh::REMOVE_ALGO == event ||
-                SMESH_subMesh::REMOVE_FATHER_ALGO == event )
+      else if (( SMESH_subMesh::REMOVE_ALGO == event ||
+                 SMESH_subMesh::REMOVE_FATHER_ALGO == event ) &&
+               SMESH_subMesh::ALGO_EVENT == eventType )
       {
-        SMESH_Gen* gen = subMesh->GetFather()->GetGen();
-        SMESH_Algo* algo = gen->GetAlgo(*subMesh->GetFather(),subMesh->GetSubShape() );
+        SMESH_Algo* algo = subMesh->GetAlgo();
         removeImport = ( strncmp( "Import", algo->GetName(), 6 ) != 0 );
       }
 
@@ -470,7 +472,9 @@ namespace // INTERNAL STUFF
         // treate removal of Import algo from subMesh
         removeSubmesh( subMesh, (_ListenerData*) data );
       }
-      else if ( modifHyp )
+      else if ( modifHyp ||
+                ( SMESH_subMesh::CLEAN         == event &&
+                  SMESH_subMesh::COMPUTE_EVENT == eventType))
       {
         // treate modification of ImportSource hypothesis
         clearSubmesh( subMesh, (_ListenerData*) data, /*all=*/false );
@@ -486,7 +490,7 @@ namespace // INTERNAL STUFF
         for ( ; d != dList.end(); ++d )
           if ( d->_subM.count( subMesh ))
           {
-            set<SMESH_subMesh*>::iterator smIt = d->_subM.begin();
+            set<SMESH_subMesh*,_SubLess>::iterator smIt = d->_subM.begin();
             for( ; smIt != d->_subM.end(); ++smIt )
               if ( (*smIt)->IsMeshComputed() )
                 d->_computedSubM.insert( *smIt);
@@ -506,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()
@@ -633,8 +637,8 @@ bool StdMeshers_Import_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & th
   subShapeIDs.insert( shapeID );
 
   // get nodes on vertices
-  list < SMESH_MeshEditor::TNodeXYZ > vertexNodes; 
- list < SMESH_MeshEditor::TNodeXYZ >::iterator vNIt;
+  list < SMESH_TNodeXYZ > vertexNodes; 
+ list < SMESH_TNodeXYZ >::iterator vNIt;
   TopExp_Explorer vExp( theShape, TopAbs_VERTEX );
   for ( ; vExp.More(); vExp.Next() )
   {
@@ -648,7 +652,7 @@ bool StdMeshers_Import_1D::Compute(SMESH_Mesh & theMesh, const TopoDS_Shape & th
       n = SMESH_Algo::VertexNode( v, tgtMesh );
       if ( !n ) return false; // very strange
     }
-    vertexNodes.push_back( SMESH_MeshEditor::TNodeXYZ( n ));
+    vertexNodes.push_back( SMESH_TNodeXYZ( n ));
   }
 
   // import edges from groups
@@ -889,8 +893,8 @@ void StdMeshers_Import_1D::importMesh(const SMESH_Mesh*          srcMesh,
   e2e->clear();
 
   // Remember created groups in order to remove them as soon as the srcHyp is
-  // modified or something other similar happens. Store them in a hypothesis
-  // as it stores its values anyway
+  // modified or something other similar happens. This imformation must be persistent,
+  // for that store them in a hypothesis as it stores its values in the file anyway
   srcHyp->StoreResultGroups( resultGroups, *srcMeshDS, *tgtMeshDS );
 }
 
@@ -989,8 +993,8 @@ bool StdMeshers_Import_1D::Evaluate(SMESH_Mesh &         theMesh,
         const SMDS_MeshElement* edge = srcElems->next();
         // find out if edge is located on geomEdge by projecting
         // a middle of edge to geomEdge
-        SMESH_MeshEditor::TNodeXYZ p1( edge->GetNode(0));
-        SMESH_MeshEditor::TNodeXYZ p2( edge->GetNode(1));
+        SMESH_TNodeXYZ p1( edge->GetNode(0));
+        SMESH_TNodeXYZ p2( edge->GetNode(1));
         gp_XYZ middle = ( p1 + p2 ) / 2.;
         tmpNode->setXYZ( middle.X(), middle.Y(), middle.Z());
         double u = 0;