+//================================================================================
+/*!
+ * \brief Return a ratio of "compute cost" of computed sub-meshes to the whole
+ * "compute cost".
+ */
+//================================================================================
+
+double SMESH_Mesh::GetComputeProgress() const
+{
+ double totalCost = 1e-100, computedCost = 0;
+ const SMESH_subMesh* curSM = _gen->GetCurrentSubMesh();
+
+ // get cost of already treated sub-meshes
+ if ( SMESH_subMesh* mainSM = GetSubMeshContaining( 1 ))
+ {
+ SMESH_subMeshIteratorPtr smIt = mainSM->getDependsOnIterator(/*includeSelf=*/true);
+ while ( smIt->more() )
+ {
+ SMESH_subMesh* sm = smIt->next();
+ if ( sm->GetComputeState() != SMESH_subMesh::NOT_READY )
+ {
+ const int smCost = sm->GetComputeCost();
+ totalCost += smCost;
+ if ( sm != curSM &&
+ ( !sm->IsEmpty() ||
+ sm->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE ))
+ {
+ computedCost += smCost;
+ }
+ }
+ }
+ }
+ // get progress of a current algo
+ if ( curSM )
+ if ( SMESH_Algo* algo = curSM->GetAlgo() )
+ {
+ double rate = algo->GetProgress();
+ if ( 0. < rate && rate < 1.001 )
+ {
+ //cout << " rate: " << rate << " cost " << algo->GetComputeCost() << endl;
+ computedCost += rate * algo->GetComputeCost();
+ }
+ else if ( curSM->IsEmpty() )
+ {
+ computedCost += algo->GetProgressByTic() * algo->GetComputeCost();
+ }
+ else
+ {
+ computedCost += 0.99 * algo->GetComputeCost();
+ }
+ }
+ //cout << "Total: " << totalCost << " progress: " << computedCost / totalCost << endl;
+ return computedCost / totalCost;
+}
+