+ // 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() );
+ }
+ //aMesh.GetMeshDS()->Modified();
+ return ret;
+ }
+ else
+ {
+ // -----------------------------------------------------------------
+ // apply algos that DO NOT require Discreteized boundaries and DO NOT
+ // support submeshes, starting from the most complex shapes
+ // and collect submeshes with algos that DO support submeshes
+ // -----------------------------------------------------------------
+ list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
+
+ // map to sort sm with same dim algos according to dim of
+ // the shape the algo assigned to (issue 0021217)
+ multimap< int, SMESH_subMesh* > shDim2sm;
+ multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
+ TopoDS_Shape algoShape;
+ int prevShapeDim = -1;
+
+ smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
+ while ( smIt->more() )
+ {
+ SMESH_subMesh* smToCompute = smIt->next();
+ if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
+ continue;
+
+ const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
+ 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, &algoShape );
+ if ( algo && !algo->NeedDiscreteBoundary() )
+ {
+ if ( algo->SupportSubmeshes() )
+ {
+ // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
+ // so that more local algos to go first
+ if ( prevShapeDim != aShapeDim )
+ {
+ prevShapeDim = aShapeDim;
+ for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
+ if ( shDim2smIt->first == globalAlgoDim )
+ smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
+ else
+ smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
+ shDim2sm.clear();
+ }
+ // add smToCompute to shDim2sm map
+ if ( algoShape.IsSame( aMesh.GetShapeToMesh() ))
+ {
+ aShapeDim = globalAlgoDim; // to compute last
+ }
+ else
+ {
+ aShapeDim = GetShapeDim( algoShape );
+ if ( algoShape.ShapeType() == TopAbs_COMPOUND )
+ {
+ TopoDS_Iterator it( algoShape );
+ aShapeDim += GetShapeDim( it.Value() );
+ }
+ }
+ shDim2sm.insert( make_pair( aShapeDim, smToCompute ));
+ }
+ else
+ {
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ if (_compute_canceled)
+ return false;
+ _sm_current = smToCompute;
+#endif
+ smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
+#ifdef WITH_SMESH_CANCEL_COMPUTE
+ _sm_current = NULL;
+#endif
+ if ( aShapesId )
+ aShapesId->insert( smToCompute->GetId() );
+ }
+ }
+ }
+ // reload sub-meshes from shDim2sm into smWithAlgoSupportingSubmeshes
+ for ( shDim2smIt = shDim2sm.rbegin(); shDim2smIt != shDim2sm.rend(); ++shDim2smIt )
+ if ( shDim2smIt->first == globalAlgoDim )
+ smWithAlgoSupportingSubmeshes.push_back( shDim2smIt->second );
+ else
+ smWithAlgoSupportingSubmeshes.push_front( shDim2smIt->second );
+
+ // ------------------------------------------------------------
+ // sort list of submeshes according to mesh order
+ // ------------------------------------------------------------
+ aMesh.SortByMeshOrder( smWithAlgoSupportingSubmeshes );
+
+ // ------------------------------------------------------------
+ // compute submeshes under shapes with algos that DO NOT require
+ // Discreteized boundaries and DO support submeshes
+ // ------------------------------------------------------------
+ list< SMESH_subMesh* >::iterator subIt, subEnd;
+ subIt = smWithAlgoSupportingSubmeshes.begin();
+ subEnd = smWithAlgoSupportingSubmeshes.end();
+ // start from lower shapes
+ for ( ; subIt != subEnd; ++subIt )
+ {
+ sm = *subIt;