Salome HOME
Merge from V6_4_BR 05/12/2011
[modules/smesh.git] / src / StdMeshers / StdMeshers_ImportSource.cxx
index 1ba39eacf9ebb91b8316e88a7592f00947c7f668..5e963a02d96401edf200001bed5df2819f07ccd8 100644 (file)
@@ -1,23 +1,23 @@
-//  Copyright (C) 2007-2010  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2011  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 StdMeshers_ImportSource1D : implementaion of SMESH idl descriptions
@@ -26,7 +26,7 @@
 //
 #include "StdMeshers_ImportSource.hxx"
 
-#include "SMESHDS_GroupBase.hxx"
+#include "SMESHDS_GroupOnGeom.hxx"
 #include "SMESHDS_Mesh.hxx"
 #include "SMESH_Algo.hxx"
 #include "SMESH_Gen.hxx"
@@ -258,6 +258,51 @@ std::vector<SMESH_Mesh*> StdMeshers_ImportSource1D::GetSourceMeshes() const
   return meshes;
 }
 
+//================================================================================
+/*!
+ * \brief Return submeshes whose events affect the target mesh
+ */
+//================================================================================
+
+std::vector<SMESH_subMesh*>
+StdMeshers_ImportSource1D::GetSourceSubMeshes(const SMESH_Mesh* srcMesh) const
+{
+  if ( !srcMesh->HasShapeToMesh() )
+    return vector<SMESH_subMesh*>(1, srcMesh->GetSubMeshContaining(1));
+
+  set<int> shapeIDs;
+  const vector<SMESH_Group*>& groups = GetGroups();
+  const SMESHDS_Mesh * srcMeshDS = srcMesh->GetMeshDS();
+  for ( size_t i = 0; i < groups.size(); ++i )
+  {
+    SMESHDS_GroupBase * grDS = groups[i]->GetGroupDS();
+    if ( grDS->GetMesh() != srcMeshDS )
+      continue;
+    if ( SMESHDS_GroupOnGeom* gog = dynamic_cast<SMESHDS_GroupOnGeom*>( grDS ))
+    {
+      shapeIDs.insert( srcMeshDS->ShapeToIndex( gog->GetShape() ));
+    }
+    else
+    {
+      SMDS_ElemIteratorPtr elIt = grDS->GetElements();
+      while ( elIt->more() )
+        shapeIDs.insert( elIt->next()->getshapeId() );
+    }
+  }
+  if ( !shapeIDs.empty() && *shapeIDs.begin() < 1 )
+  {
+    shapeIDs.erase( shapeIDs.begin() );
+    shapeIDs.insert( 1 );
+  }
+
+  vector<SMESH_subMesh*> smVec( shapeIDs.size());
+  set<int>::iterator sID = shapeIDs.begin();
+  for ( int i = 0; sID != shapeIDs.end(); ++sID, ++i )
+    smVec[i] = srcMesh->GetSubMeshContaining( *sID );
+
+  return smVec;
+}
+
 //=============================================================================
 /*!
  * Save _toCopyMesh and _toCopyGroups to a stream