+ // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
+ for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
+ if ( shDim2smIt->first == globalAlgoDim )
+ smWithAlgoSupportingSubmeshes[3].push_back( shDim2smIt->second );
+ else
+ smWithAlgoSupportingSubmeshes[0].push_front( shDim2smIt->second );
+
+ // ======================================================
+ // Apply all-dimensional algorithms supporing sub-meshes
+ // ======================================================
+
+ for ( aShapeDim = 0; aShapeDim < 4; ++aShapeDim )
+ {
+ // ------------------------------------------------
+ // sort list of sub-meshes according to mesh order
+ // ------------------------------------------------
+ aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes[ aShapeDim ] );
+
+ // ------------------------------------------------------------
+ // compute sub-meshes with local uni-dimensional algos under
+ // sub-meshes with all-dimensional algos
+ // ------------------------------------------------------------
+ list< SMESH_subMesh* >::iterator subIt, subEnd;
+ subIt = smWithAlgoSupportingSubmeshes[ aShapeDim ].begin();
+ subEnd = smWithAlgoSupportingSubmeshes[ aShapeDim ].end();
+ // start from lower shapes
+ for ( ; subIt != subEnd; ++subIt )
+ {
+ sm = *subIt;
+
+ // get a shape the algo is assigned to
+ if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
+ continue; // strange...
+
+ // look for more local algos
+ smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
+ while ( smIt->more() )
+ {
+ SMESH_subMesh* smToCompute = smIt->next();
+
+ const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
+ 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 ))
+ .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape, aMesh ));
+
+ if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
+ if ( ! subAlgo->NeedDiscreteBoundary() ) continue;
+ SMESH_Hypothesis::Hypothesis_Status status;
+ if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
+ // mesh a lower smToCompute starting from vertices
+ Compute( aMesh, aSubShape, aShapeOnly, /*anUpward=*/true, aDim, aShapesId );
+ }
+ }
+ }
+ // --------------------------------
+ // apply the all-dimensional algos
+ // --------------------------------
+ subIt = smWithAlgoSupportingSubmeshes[ aShapeDim ].begin();
+ for ( ; subIt != subEnd; ++subIt )
+ {
+ sm = *subIt;
+ if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
+ {
+ const TopAbs_ShapeEnum shapeType = sm->GetSubShape().ShapeType();
+ // check for preview dimension limitations
+ if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
+ continue;
+
+ if (_compute_canceled)
+ return false;
+ _sm_current = sm;
+ sm->ComputeStateEngine( computeEvent );
+ _sm_current = NULL;
+ if ( aShapesId )
+ aShapesId->insert( sm->GetId() );
+ }
+ }
+ } // loop on shape dimensions
+
+ // -----------------------------------------------
+ // mesh the rest sub-shapes starting from vertices
+ // -----------------------------------------------
+ ret = Compute( aMesh, aShape, aShapeOnly, /*anUpward=*/true, aDim, aShapesId );
+ }
+
+ MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
+ MEMOSTAT;
+
+ SMESHDS_Mesh *myMesh = aMesh.GetMeshDS();
+ MESSAGE("*** compactMesh after compute");
+ myMesh->compactMesh();
+
+ // fix quadratic mesh by bending iternal links near concave boundary
+ if ( aShape.IsSame( aMesh.GetShapeToMesh() ) &&
+ !aShapesId && // not preview
+ ret ) // everything is OK
+ {
+ SMESH_MesherHelper aHelper( aMesh );
+ if ( aHelper.IsQuadraticMesh() != SMESH_MesherHelper::LINEAR )
+ {
+ aHelper.FixQuadraticElements( sm->GetComputeError() );
+ }
+ }
+ return ret;
+}
+
+
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+//=============================================================================
+/*!
+ * Prepare Compute a mesh
+ */
+//=============================================================================
+void SMESH_Gen::PrepareCompute(SMESH_Mesh & aMesh,
+ const TopoDS_Shape & aShape)
+{
+ _compute_canceled = false;
+ _sm_current = NULL;
+}
+//=============================================================================
+/*!
+ * Cancel Compute a mesh
+ */
+//=============================================================================
+void SMESH_Gen::CancelCompute(SMESH_Mesh & aMesh,
+ const TopoDS_Shape & aShape)
+{
+ _compute_canceled = true;
+ if(_sm_current)
+ {
+ _sm_current->ComputeStateEngine( SMESH_subMesh::COMPUTE_CANCELED );
+ }
+}
+#endif
+
+//=============================================================================
+/*!
+ * Evaluate a mesh
+ */
+//=============================================================================
+
+bool SMESH_Gen::Evaluate(SMESH_Mesh & aMesh,
+ const TopoDS_Shape & aShape,
+ MapShapeNbElems& aResMap,
+ const bool anUpward,
+ TSetOfInt* aShapesId)
+{
+ MESSAGE("SMESH_Gen::Evaluate");
+
+ bool ret = true;
+
+ SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
+
+ const bool includeSelf = true;
+ const bool complexShapeFirst = true;
+ SMESH_subMeshIteratorPtr smIt;
+
+ if ( anUpward ) { // is called from below code here
+ // -----------------------------------------------
+ // mesh all the sub-shapes starting from vertices
+ // -----------------------------------------------
+ smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
+ while ( smIt->more() ) {
+ SMESH_subMesh* smToCompute = smIt->next();
+
+ // do not mesh vertices of a pseudo shape
+ const TopAbs_ShapeEnum shapeType = smToCompute->GetSubShape().ShapeType();
+ //if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
+ // continue;
+ if ( !aMesh.HasShapeToMesh() ) {
+ if( shapeType == TopAbs_VERTEX || shapeType == TopAbs_WIRE ||
+ shapeType == TopAbs_SHELL )
+ continue;
+ }
+
+ smToCompute->Evaluate(aResMap);
+ if( aShapesId )
+ aShapesId->insert( smToCompute->GetId() );
+ }
+ return ret;
+ }
+ else {
+ // -----------------------------------------------------------------
+ // apply algos that DO NOT require Discreteized boundaries and DO NOT
+ // support sub-meshes, starting from the most complex shapes
+ // and collect sub-meshes with algos that DO support sub-meshes
+ // -----------------------------------------------------------------
+ list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
+ smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
+ while ( smIt->more() ) {
+ SMESH_subMesh* smToCompute = smIt->next();
+ const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
+ const int aShapeDim = GetShapeDim( aSubShape );
+ if ( aShapeDim < 1 ) break;
+
+ SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
+ if ( algo && !algo->NeedDiscreteBoundary() ) {
+ if ( algo->SupportSubmeshes() ) {
+ smWithAlgoSupportingSubmeshes.push_front( smToCompute );
+ }
+ else {
+ smToCompute->Evaluate(aResMap);
+ if ( aShapesId )
+ aShapesId->insert( smToCompute->GetId() );
+ }
+ }
+ }
+