Salome HOME
correct previous integration (Porting to Python 2.6)
[modules/smesh.git] / src / StdMeshers / StdMeshers_Projection_3D.cxx
index af93f888de2313eacc45570822effb1785534564..d8939feadf14986318733aff833ab9e3297622be 100644 (file)
@@ -1,50 +1,47 @@
-//  SMESH SMESH : implementaion of SMESH idl descriptions
+//  Copyright (C) 2007-2008  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
+//
+//  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.
 //
-//  Copyright (C) 2003  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 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 
-// 
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  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
 //
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+//  SMESH SMESH : implementaion of SMESH idl descriptions
 // File      : StdMeshers_Projection_3D.cxx
 // Module    : SMESH
 // Created   : Fri Oct 20 11:37:07 2006
 // Author    : Edward AGAPOV (eap)
-
-
+//
 #include "StdMeshers_Projection_3D.hxx"
 #include "StdMeshers_ProjectionSource3D.hxx"
 
 #include "StdMeshers_ProjectionUtils.hxx"
 
+#include "SMDS_PolyhedralVolumeOfNodes.hxx"
+#include "SMDS_VolumeTool.hxx"
 #include "SMESHDS_Hypothesis.hxx"
 #include "SMESHDS_SubMesh.hxx"
 #include "SMESH_Block.hxx"
+#include "SMESH_Comment.hxx"
 #include "SMESH_Gen.hxx"
 #include "SMESH_Mesh.hxx"
-#include "SMESH_MeshEditor.hxx"
+#include "SMESH_MesherHelper.hxx"
 #include "SMESH_Pattern.hxx"
 #include "SMESH_subMesh.hxx"
 #include "SMESH_subMeshEventListener.hxx"
-#include "SMESH_MesherHelper.hxx"
-#include "SMESH_Comment.hxx"
-#include "SMDS_VolumeTool.hxx"
-#include "SMDS_PolyhedralVolumeOfNodes.hxx"
 
 #include "utilities.h"
 
@@ -71,7 +68,7 @@ StdMeshers_Projection_3D::StdMeshers_Projection_3D(int hypId, int studyId, SMESH
   :SMESH_3D_Algo(hypId, studyId, gen)
 {
   _name = "Projection_3D";
-  _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);      // 1 bit per shape type
+  _shapeType = (1 << TopAbs_SHELL) | (1 << TopAbs_SOLID);  // 1 bit per shape type
 
   _compatibleHypothesis.push_back("ProjectionSource3D");
   _sourceHypo = 0;
@@ -311,9 +308,9 @@ bool StdMeshers_Projection_3D::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aS
     TNodeNodeMap faceMatchingNodes;
     if ( ! TAssocTool::FindMatchingNodesOnFaces( srcFace, srcMesh, tgtFace, tgtMesh, 
                                                  shape2ShapeMap, faceMatchingNodes ))
-    return error(COMPERR_BAD_INPUT_MESH,SMESH_Comment("Mesh on faces #")
-                 << srcMeshDS->ShapeToIndex( srcFace ) << " and "
-                 << tgtMeshDS->ShapeToIndex( tgtFace ) << " seems different" );
+      return error(COMPERR_BAD_INPUT_MESH,SMESH_Comment("Mesh on faces #")
+                   << srcMeshDS->ShapeToIndex( srcFace ) << " and "
+                   << tgtMeshDS->ShapeToIndex( tgtFace ) << " seems different" );
 
     // put found matching nodes of 2 faces to the global map
     src2tgtNodeMap.insert( faceMatchingNodes.begin(), faceMatchingNodes.end() );
@@ -423,6 +420,104 @@ bool StdMeshers_Projection_3D::Compute(SMESH_Mesh& aMesh, const TopoDS_Shape& aS
   return true;
 }
 
+
+//=======================================================================
+//function : Evaluate
+//purpose  : 
+//=======================================================================
+
+bool StdMeshers_Projection_3D::Evaluate(SMESH_Mesh& aMesh,
+                                        const TopoDS_Shape& aShape,
+                                        MapShapeNbElems& aResMap)
+{
+  if ( !_sourceHypo )
+    return false;
+
+  SMESH_Mesh * srcMesh = _sourceHypo->GetSourceMesh();
+  SMESH_Mesh * tgtMesh = & aMesh;
+  if ( !srcMesh )
+    srcMesh = tgtMesh;
+
+  // get shell from shape3D
+  TopoDS_Shell srcShell, tgtShell;
+  TopExp_Explorer exp( _sourceHypo->GetSource3DShape(), TopAbs_SHELL );
+  int nbShell;
+  for ( nbShell = 0; exp.More(); exp.Next(), ++nbShell )
+    srcShell = TopoDS::Shell( exp.Current() );
+  if ( nbShell != 1 )
+    return error(COMPERR_BAD_SHAPE,
+                 SMESH_Comment("Source shape must have 1 shell but not ") << nbShell);
+
+  exp.Init( aShape, TopAbs_SHELL );
+  for ( nbShell = 0; exp.More(); exp.Next(), ++nbShell )
+    tgtShell = TopoDS::Shell( exp.Current() );
+  if ( nbShell != 1 )
+    return error(COMPERR_BAD_SHAPE,
+                 SMESH_Comment("Target shape must have 1 shell but not ") << nbShell);
+
+  // Check that shapes are blocks
+  if ( TAssocTool::Count( tgtShell, TopAbs_FACE , 1 ) != 6 ||
+       TAssocTool::Count( tgtShell, TopAbs_EDGE , 1 ) != 12 ||
+       TAssocTool::Count( tgtShell, TopAbs_WIRE , 1 ) != 6 )
+    return error(COMPERR_BAD_SHAPE, "Target shape is not a block");
+  if ( TAssocTool::Count( srcShell, TopAbs_FACE , 1 ) != 6 ||
+       TAssocTool::Count( srcShell, TopAbs_EDGE , 1 ) != 12 ||
+       TAssocTool::Count( srcShell, TopAbs_WIRE , 1 ) != 6 )
+    return error(COMPERR_BAD_SHAPE, "Source shape is not a block");
+
+  // Assure that mesh on a source shape is computed
+
+  SMESH_subMesh* srcSubMesh = srcMesh->GetSubMesh( _sourceHypo->GetSource3DShape() );
+
+  if ( !srcSubMesh->IsMeshComputed() )
+    return error(COMPERR_BAD_INPUT_MESH,"Source mesh not computed");
+
+
+  std::vector<int> aVec(SMDSEntity_Last);
+  for(int i=SMDSEntity_Node; i<SMDSEntity_Last; i++) aVec[i] = 0;
+
+  aVec[SMDSEntity_Node] = srcSubMesh->GetSubMeshDS()->NbNodes();
+
+  //bool quadratic = false;
+  SMDS_ElemIteratorPtr elemIt = srcSubMesh->GetSubMeshDS()->GetElements();
+  while ( elemIt->more() ) {
+    const SMDS_MeshElement* E  = elemIt->next();
+    if( E->NbNodes()==4 ) {
+      aVec[SMDSEntity_Tetra]++;
+    }
+    else if( E->NbNodes()==5 ) {
+      aVec[SMDSEntity_Pyramid]++;
+    }
+    else if( E->NbNodes()==6 ) {
+      aVec[SMDSEntity_Penta]++;
+    }
+    else if( E->NbNodes()==8 ) {
+      aVec[SMDSEntity_Hexa]++;
+    }
+    else if( E->NbNodes()==10 && E->IsQuadratic() ) {
+      aVec[SMDSEntity_Quad_Tetra]++;
+    }
+    else if( E->NbNodes()==13 && E->IsQuadratic() ) {
+      aVec[SMDSEntity_Quad_Pyramid]++;
+    }
+    else if( E->NbNodes()==15 && E->IsQuadratic() ) {
+      aVec[SMDSEntity_Quad_Penta]++;
+    }
+    else if( E->NbNodes()==20 && E->IsQuadratic() ) {
+      aVec[SMDSEntity_Quad_Hexa]++;
+    }
+    else {
+      aVec[SMDSEntity_Polyhedra]++;
+    }
+  }
+
+  SMESH_subMesh * sm = aMesh.GetSubMesh(aShape);
+  aResMap.insert(std::make_pair(sm,aVec));
+
+  return true;
+}
+
+
 //=============================================================================
 /*!
  * \brief Sets a default event listener to submesh of the source shape