+bool SMESH_Gen::GetAlgoState(SMESH_Mesh& theMesh,
+ const TopoDS_Shape& theShape,
+ list< TAlgoStateError > & theErrors)
+{
+ //MESSAGE("SMESH_Gen::CheckAlgoState");
+
+ bool ret = true;
+ bool hasAlgo = false;
+
+ SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
+ const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
+ TopoDS_Shape mainShape = meshDS->ShapeToMesh();
+
+ // -----------------
+ // get global algos
+ // -----------------
+
+ const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
+
+ const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
+ list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
+ for ( ; it != listHyp.end(); it++)
+ {
+ const SMESHDS_Hypothesis * aHyp = *it;
+ if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
+ continue;
+
+ const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
+ ASSERT ( algo );
+
+ int dim = algo->GetDim();
+ aGlobAlgoArr[ dim ] = algo;
+
+ hasAlgo = true;
+ }
+
+ // --------------------------------------------------------
+ // info on algos that will be ignored because of ones that
+ // don't NeedDescretBoundary() attached to super-shapes,
+ // check that a conform mesh will be produced
+ // --------------------------------------------------------
+
+
+ // find a global algo possibly hiding sub-algos
+ int dim;
+ const SMESH_Algo* aGlobIgnoAlgo = 0;
+ for (dim = 3; dim > 0; dim--)
+ {
+ if (aGlobAlgoArr[ dim ] &&
+ !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
+ {
+ aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
+ break;
+ }
+ }
+
+ const map<int, SMESH_subMesh*>& smMap = sm->DependsOn();
+ map<int, SMESH_subMesh*>::const_reverse_iterator revItSub = smMap.rbegin();
+ map<int, SMESH_subMesh*> aCheckedMap;
+ bool checkConform = ( !theMesh.IsNotConformAllowed() );
+ int aKey = 1;
+ SMESH_subMesh* smToCheck = sm;
+
+ // loop on theShape and its sub-shapes
+ while ( smToCheck )
+ {
+ if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
+ break;
+
+ if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
+ if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
+ 0, checkConform, aCheckedMap, theErrors))
+ ret = false;
+
+ if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
+ hasAlgo = true;
+
+ // next subMesh
+ if (revItSub != smMap.rend())
+ {
+ aKey = (*revItSub).first;
+ smToCheck = (*revItSub).second;
+ revItSub++;
+ }
+ else
+ {
+ smToCheck = 0;
+ }
+
+ }
+
+ // ----------------------------------------------------------------
+ // info on missing hypothesis and find out if all needed algos are
+ // well defined
+ // ----------------------------------------------------------------
+
+ //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
+
+ // find max dim of global algo
+ int aTopAlgoDim = 0;
+ for (dim = 3; dim > 0; dim--)
+ {
+ if (aGlobAlgoArr[ dim ])
+ {
+ aTopAlgoDim = dim;
+ break;
+ }
+ }
+ aCheckedMap.clear();
+ smToCheck = sm;
+ revItSub = smMap.rbegin();
+ bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
+ bool globalChecked[] = { false, false, false, false };
+
+ // loop on theShape and its sub-shapes
+ while ( smToCheck )
+ {
+ if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
+ break;
+
+ if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
+ if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
+ globalChecked, checkNoAlgo, aCheckedMap, theErrors))
+ {
+ ret = false;
+ if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
+ checkNoAlgo = false;
+ }
+
+ // next subMesh
+ if (revItSub != smMap.rend())
+ {
+ aKey = (*revItSub).first;
+ smToCheck = (*revItSub).second;
+ revItSub++;
+ }
+ else
+ smToCheck = 0;
+ }
+
+ if ( !hasAlgo ) {
+ ret = false;
+ INFOS( "None algorithm attached" );
+ theErrors.push_back( TAlgoStateError() );
+ theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
+ }
+
+ return ret;
+}