+ StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
+
+ // create a new SMESH_mesh object
+ SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
+ theStudyId,
+ this,
+ theIsEmbeddedMode,
+ aStudyContext->myDocument);
+ aStudyContext->mapMesh[_localId-1] = aMesh;
+
+ return aMesh;
+}
+
+//=============================================================================
+/*
+ * Compute a mesh
+ */
+//=============================================================================
+
+bool SMESH_Gen::Compute(SMESH_Mesh & aMesh,
+ const TopoDS_Shape & aShape,
+ const bool aShapeOnly /*=false*/,
+ const bool anUpward /*=false*/,
+ const ::MeshDimension aDim /*=::MeshDim_3D*/,
+ TSetOfInt* aShapesId /*=0*/)
+{
+ MEMOSTAT;
+
+ bool ret = true;
+
+ SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
+
+ const bool includeSelf = true;
+ const bool complexShapeFirst = true;
+ const int globalAlgoDim = 100;
+
+ SMESH_subMeshIteratorPtr smIt;
+
+ // Fix of Issue 22150. Due to !BLSURF->OnlyUnaryInput(), BLSURF computes edges
+ // that must be computed by Projection 1D-2D when Projection asks to compute
+ // one face only.
+ SMESH_subMesh::compute_event computeEvent =
+ aShapeOnly ? SMESH_subMesh::COMPUTE_SUBMESH : SMESH_subMesh::COMPUTE;
+
+ if ( anUpward ) // is called from the below code in this method
+ {
+ // ===============================================
+ // 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 TopoDS_Shape& shape = smToCompute->GetSubShape();
+ const TopAbs_ShapeEnum shapeType = shape.ShapeType();
+ if ( !aMesh.HasShapeToMesh() && shapeType == TopAbs_VERTEX )
+ continue;
+
+ // check for preview dimension limitations
+ if ( aShapesId && GetShapeDim( shapeType ) > (int)aDim )
+ {
+ // clear compute state not to show previous compute errors
+ // if preview invoked less dimension less than previous
+ smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
+ continue;
+ }
+
+ if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
+ {
+ if (_compute_canceled)
+ return false;
+ setCurrentSubMesh( smToCompute );
+ smToCompute->ComputeStateEngine( computeEvent );
+ setCurrentSubMesh( NULL );
+ }
+
+ // we check all the sub-meshes here and detect if any of them failed to compute
+ if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE &&
+ ( shapeType != TopAbs_EDGE || !SMESH_Algo::isDegenerated( TopoDS::Edge( shape ))))
+ ret = false;
+ else if ( aShapesId )
+ aShapesId->insert( smToCompute->GetId() );
+ }
+ //aMesh.GetMeshDS()->Modified();
+ return ret;
+ }
+ else
+ {
+ // ================================================================
+ // Apply algos that do NOT require discreteized boundaries
+ // ("all-dimensional") 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[4]; // for each dim
+
+ // map to sort sm with same dim algos according to dim of
+ // the shape the algo assigned to (issue 0021217).
+ // Other issues influenced the algo applying order:
+ // 21406, 21556, 21893, 20206
+ multimap< int, SMESH_subMesh* > shDim2sm;
+ multimap< int, SMESH_subMesh* >::reverse_iterator shDim2smIt;
+ TopoDS_Shape algoShape;
+ int prevShapeDim = -1, aShapeDim;
+
+ 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();
+ aShapeDim = GetShapeDim( aSubShape );
+ if ( aShapeDim < 1 ) break;
+
+ // check for preview dimension limitations
+ if ( aShapesId && aShapeDim > (int)aDim )
+ continue;
+
+ SMESH_Algo* algo = GetAlgo( smToCompute, &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[ aShapeDim ].push_back( shDim2smIt->second );
+ else
+ smWithAlgoSupportingSubmeshes[ aShapeDim ].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 // Compute w/o support of sub-meshes
+ {
+ if (_compute_canceled)
+ return false;
+ setCurrentSubMesh( smToCompute );
+ smToCompute->ComputeStateEngine( computeEvent );
+ setCurrentSubMesh( NULL );
+ 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[3].push_back( shDim2smIt->second );
+ else
+ smWithAlgoSupportingSubmeshes[0].push_front( shDim2smIt->second );
+
+ // ======================================================
+ // Apply all-dimensional algorithms supporing sub-meshes
+ // ======================================================
+
+ std::vector< SMESH_subMesh* > smVec;
+ for ( aShapeDim = 0; aShapeDim < 4; ++aShapeDim )
+ {
+ // ------------------------------------------------
+ // sort list of sub-meshes according to mesh order
+ // ------------------------------------------------
+ smVec.assign( smWithAlgoSupportingSubmeshes[ aShapeDim ].begin(),
+ smWithAlgoSupportingSubmeshes[ aShapeDim ].end() );
+ aMesh.SortByMeshOrder( smVec );
+
+ // ------------------------------------------------------------
+ // compute sub-meshes with local uni-dimensional algos under
+ // sub-meshes with all-dimensional algos
+ // ------------------------------------------------------------
+ // start from lower shapes
+ for ( size_t i = 0; i < smVec.size(); ++i )
+ {
+ sm = smVec[i];
+
+ // get a shape the algo is assigned to
+ if ( !GetAlgo( sm, & 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;