Salome HOME
Imp 19925 - Mesh preview
[modules/smesh.git] / src / SMESH / SMESH_Gen.cxx
index e8d57f86c14672303afd0e64f873f44687137226..c86699a2a01eba19438caaba567ad4a06a0b6c03 100644 (file)
@@ -129,9 +129,11 @@ SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
  */
 //=============================================================================
 
-bool SMESH_Gen::Compute(SMESH_Mesh &         aMesh,
-                        const TopoDS_Shape & aShape,
-                        const bool           anUpward)
+bool SMESH_Gen::Compute(SMESH_Mesh &          aMesh,
+                        const TopoDS_Shape &  aShape,
+                        const bool            anUpward,
+                       const ::MeshDimension aDim,
+                       TSetOfInt*            aShapesId)
 {
   MESSAGE("SMESH_Gen::Compute");
 
@@ -155,16 +157,22 @@ bool SMESH_Gen::Compute(SMESH_Mesh &         aMesh,
       SMESH_subMesh* smToCompute = smIt->next();
 
       // do not mesh vertices of a pseudo shape
-      if ( !aMesh.HasShapeToMesh() &&
-           smToCompute->GetSubShape().ShapeType() == TopAbs_VERTEX )
+      const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
+      if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
         continue;
 
+      // check for preview dimension limitations
+      if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
+       continue;
+
       if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
         smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
 
       // we check all the submeshes here and detect if any of them failed to compute
       if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
         ret = false;
+      else if ( aShapesId )
+       aShapesId->insert( smToCompute->GetId() );
     }
     return ret;
   }
@@ -184,7 +192,12 @@ bool SMESH_Gen::Compute(SMESH_Mesh &         aMesh,
         continue;
 
       const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
-      if ( GetShapeDim( aSubShape ) < 1 ) break;
+      const int aShapeDim = GetShapeDim( aSubShape );
+      if ( aShapeDim < 1 ) break;
+      
+      // check for preview dimension limitations
+      if ( aShapesId && aShapeDim > (int)aDim )
+       continue;
 
       SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
       if ( algo && !algo->NeedDescretBoundary() )
@@ -192,7 +205,11 @@ bool SMESH_Gen::Compute(SMESH_Mesh &         aMesh,
         if ( algo->SupportSubmeshes() )
           smWithAlgoSupportingSubmeshes.push_back( smToCompute );
         else
+       {
           smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+         if ( aShapesId )
+           aShapesId->insert( smToCompute->GetId() );
+       }
       }
     }
     // ------------------------------------------------------------
@@ -219,8 +236,14 @@ bool SMESH_Gen::Compute(SMESH_Mesh &         aMesh,
         SMESH_subMesh* smToCompute = smIt->next();
 
         const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
-        if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
-
+       const int aShapeDim = GetShapeDim( aSubShape );
+        //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
+       if ( aShapeDim < 1 ) continue;
+
+       // check for preview dimension limitations
+       if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
+         continue;
+       
         SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
         filter
           .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
@@ -230,7 +253,7 @@ bool SMESH_Gen::Compute(SMESH_Mesh &         aMesh,
           SMESH_Hypothesis::Hypothesis_Status status;
           if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
             // mesh a lower smToCompute starting from vertices
-            Compute( aMesh, aSubShape, /*anUpward=*/true );
+            Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
         }
       }
     }
@@ -239,12 +262,21 @@ bool SMESH_Gen::Compute(SMESH_Mesh &         aMesh,
     // ----------------------------------------------------------
     for ( subIt = smWithAlgoSupportingSubmeshes.rbegin(); subIt != subEnd; ++subIt )
       if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
+      {
+       const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
+       // check for preview dimension limitations
+       if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
+         continue;
+
         sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+       if ( aShapesId )
+         aShapesId->insert( sm->GetId() );
+      }
 
     // -----------------------------------------------
     // mesh the rest subshapes starting from vertices
     // -----------------------------------------------
-    ret = Compute( aMesh, aShape, /*anUpward=*/true );
+    ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
   }
 
   MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
@@ -708,14 +740,14 @@ int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
   if ( dim.empty() )
   {
     dim.resize( TopAbs_SHAPE, -1 );
-    dim[ TopAbs_COMPOUND ]  = 3;
-    dim[ TopAbs_COMPSOLID ] = 3;
-    dim[ TopAbs_SOLID ]     = 3;
-    dim[ TopAbs_SHELL ]     = 3;
-    dim[ TopAbs_FACE  ]     = 2;
-    dim[ TopAbs_WIRE ]      = 1;
-    dim[ TopAbs_EDGE ]      = 1;
-    dim[ TopAbs_VERTEX ]    = 0;
+    dim[ TopAbs_COMPOUND ]  = MeshDim_3D;
+    dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
+    dim[ TopAbs_SOLID ]     = MeshDim_3D;
+    dim[ TopAbs_SHELL ]     = MeshDim_3D;
+    dim[ TopAbs_FACE  ]     = MeshDim_2D;
+    dim[ TopAbs_WIRE ]      = MeshDim_1D;
+    dim[ TopAbs_EDGE ]      = MeshDim_1D;
+    dim[ TopAbs_VERTEX ]    = MeshDim_0D;
   }
   return dim[ aShapeType ];
 }