Salome HOME
clear computation status if Compute invoked with dimension less than previous
[modules/smesh.git] / src / SMESH / SMESH_Gen.cxx
1 //  SMESH SMESH : implementaion of SMESH idl descriptions
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //
23 //
24 //  File   : SMESH_Gen.cxx
25 //  Author : Paul RASCLE, EDF
26 //  Module : SMESH
27 //  $Header$
28
29 #include "SMESH_Gen.hxx"
30 #include "SMESH_subMesh.hxx"
31 #include "SMESH_HypoFilter.hxx"
32 #include "SMESHDS_Document.hxx"
33 #include "SMDS_MeshElement.hxx"
34 #include "SMDS_MeshNode.hxx"
35
36 #include "utilities.h"
37 #include "OpUtil.hxx"
38 #include "Utils_ExceptHandlers.hxx"
39
40 #include <gp_Pnt.hxx>
41 #include <BRep_Tool.hxx>
42 #include <TopTools_ListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44
45 using namespace std;
46
47 //=============================================================================
48 /*!
49  *  default constructor:
50  */
51 //=============================================================================
52
53 SMESH_Gen::SMESH_Gen()
54 {
55         MESSAGE("SMESH_Gen::SMESH_Gen");
56         _localId = 0;
57         _hypId = 0;
58 }
59
60 //=============================================================================
61 /*!
62  *
63  */
64 //=============================================================================
65
66 SMESH_Gen::~SMESH_Gen()
67 {
68         MESSAGE("SMESH_Gen::~SMESH_Gen");
69 }
70
71 //=============================================================================
72 /*!
73  *
74  */
75 //=============================================================================
76
77 /*SMESH_Hypothesis *SMESH_Gen::CreateHypothesis(const char *anHyp, int studyId)
78         throw(SALOME_Exception)
79 {
80
81         MESSAGE("CreateHypothesis("<<anHyp<<","<<studyId<<")");
82         // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
83
84         StudyContextStruct *myStudyContext = GetStudyContext(studyId);
85
86         // create a new hypothesis object, store its ref. in studyContext
87
88         SMESH_Hypothesis *myHypothesis = _hypothesisFactory.Create(anHyp, studyId);
89         int hypId = myHypothesis->GetID();
90         myStudyContext->mapHypothesis[hypId] = myHypothesis;
91         SCRUTE(studyId);
92         SCRUTE(hypId);
93
94         // store hypothesis in SMESHDS document
95
96         myStudyContext->myDocument->AddHypothesis(myHypothesis);
97         return myHypothesis;
98 }*/
99
100 //=============================================================================
101 /*!
102  *
103  */
104 //=============================================================================
105
106 SMESH_Mesh* SMESH_Gen::CreateMesh(int theStudyId, bool theIsEmbeddedMode)
107   throw(SALOME_Exception)
108 {
109   Unexpect aCatch(SalomeException);
110   MESSAGE("SMESH_Gen::CreateMesh");
111
112   // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
113   StudyContextStruct *aStudyContext = GetStudyContext(theStudyId);
114
115   // create a new SMESH_mesh object
116   SMESH_Mesh *aMesh = new SMESH_Mesh(_localId++,
117                                      theStudyId,
118                                      this,
119                                      theIsEmbeddedMode,
120                                      aStudyContext->myDocument);
121   aStudyContext->mapMesh[_localId] = aMesh;
122
123   return aMesh;
124 }
125
126 //=============================================================================
127 /*!
128  * Compute a mesh
129  */
130 //=============================================================================
131
132 bool SMESH_Gen::Compute(SMESH_Mesh &          aMesh,
133                         const TopoDS_Shape &  aShape,
134                         const bool            anUpward,
135                         const ::MeshDimension aDim,
136                         TSetOfInt*            aShapesId)
137 {
138   MESSAGE("SMESH_Gen::Compute");
139
140   bool ret = true;
141
142   SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
143
144   const bool includeSelf = true;
145   const bool complexShapeFirst = true;
146
147   SMESH_subMeshIteratorPtr smIt;
148
149   if ( anUpward ) // is called from below code here
150   {
151     // -----------------------------------------------
152     // mesh all the subshapes starting from vertices
153     // -----------------------------------------------
154     smIt = sm->getDependsOnIterator(includeSelf, !complexShapeFirst);
155     while ( smIt->more() )
156     {
157       SMESH_subMesh* smToCompute = smIt->next();
158
159       // do not mesh vertices of a pseudo shape
160       const TopAbs_ShapeEnum aShType = smToCompute->GetSubShape().ShapeType();
161       if ( !aMesh.HasShapeToMesh() && aShType == TopAbs_VERTEX )
162         continue;
163
164       // check for preview dimension limitations
165       if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
166       {
167         // clear compute state to not show previous compute errors
168         //  if preview invoked less dimension less than previous
169         smToCompute->ComputeStateEngine( SMESH_subMesh::CHECK_COMPUTE_STATE );
170         continue;
171       }
172
173       if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
174         smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
175
176       // we check all the submeshes here and detect if any of them failed to compute
177       if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
178         ret = false;
179       else if ( aShapesId )
180         aShapesId->insert( smToCompute->GetId() );
181     }
182     return ret;
183   }
184   else
185   {
186     // -----------------------------------------------------------------
187     // apply algos that DO NOT require descretized boundaries and DO NOT
188     // support submeshes, starting from the most complex shapes
189     // and collect submeshes with algos that DO support submeshes
190     // -----------------------------------------------------------------
191     list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
192     smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
193     while ( smIt->more() )
194     {
195       SMESH_subMesh* smToCompute = smIt->next();
196       if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
197         continue;
198
199       const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
200       const int aShapeDim = GetShapeDim( aSubShape );
201       if ( aShapeDim < 1 ) break;
202       
203       // check for preview dimension limitations
204       if ( aShapesId && aShapeDim > (int)aDim )
205         continue;
206
207       SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
208       if ( algo && !algo->NeedDescretBoundary() )
209       {
210         if ( algo->SupportSubmeshes() )
211           smWithAlgoSupportingSubmeshes.push_back( smToCompute );
212         else
213         {
214           smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
215           if ( aShapesId )
216             aShapesId->insert( smToCompute->GetId() );
217         }
218       }
219     }
220     // ------------------------------------------------------------
221     // compute submeshes under shapes with algos that DO NOT require
222     // descretized boundaries and DO support submeshes
223     // ------------------------------------------------------------
224     list< SMESH_subMesh* >::reverse_iterator subIt, subEnd;
225     subIt  = smWithAlgoSupportingSubmeshes.rbegin();
226     subEnd = smWithAlgoSupportingSubmeshes.rend();
227     // start from lower shapes
228     for ( ; subIt != subEnd; ++subIt )
229     {
230       sm = *subIt;
231
232       // get a shape the algo is assigned to
233       TopoDS_Shape algoShape;
234       if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
235         continue; // strange...
236
237       // look for more local algos
238       smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
239       while ( smIt->more() )
240       {
241         SMESH_subMesh* smToCompute = smIt->next();
242
243         const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
244         const int aShapeDim = GetShapeDim( aSubShape );
245         //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
246         if ( aShapeDim < 1 ) continue;
247
248         // check for preview dimension limitations
249         if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
250           continue;
251         
252         SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
253         filter
254           .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
255           .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
256
257         if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
258           SMESH_Hypothesis::Hypothesis_Status status;
259           if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
260             // mesh a lower smToCompute starting from vertices
261             Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
262         }
263       }
264     }
265     // ----------------------------------------------------------
266     // apply the algos that do not require descretized boundaries
267     // ----------------------------------------------------------
268     for ( subIt = smWithAlgoSupportingSubmeshes.rbegin(); subIt != subEnd; ++subIt )
269       if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
270       {
271         const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
272         // check for preview dimension limitations
273         if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
274           continue;
275
276         sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
277         if ( aShapesId )
278           aShapesId->insert( sm->GetId() );
279       }
280
281     // -----------------------------------------------
282     // mesh the rest subshapes starting from vertices
283     // -----------------------------------------------
284     ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
285   }
286
287   MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
288   return ret;
289 }
290
291 //=======================================================================
292 //function : checkConformIgnoredAlgos
293 //purpose  :
294 //=======================================================================
295
296 static bool checkConformIgnoredAlgos(SMESH_Mesh&               aMesh,
297                                      SMESH_subMesh*            aSubMesh,
298                                      const SMESH_Algo*         aGlobIgnoAlgo,
299                                      const SMESH_Algo*         aLocIgnoAlgo,
300                                      bool &                    checkConform,
301                                      map<int, SMESH_subMesh*>& aCheckedMap,
302                                      list< SMESH_Gen::TAlgoStateError > & theErrors)
303 {
304   ASSERT( aSubMesh );
305   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
306     return true;
307
308
309   bool ret = true;
310
311   const list<const SMESHDS_Hypothesis*>& listHyp =
312     aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
313   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
314   for ( ; it != listHyp.end(); it++)
315   {
316     const SMESHDS_Hypothesis * aHyp = *it;
317     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
318       continue;
319
320     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
321     ASSERT ( algo );
322
323     if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
324     {
325       INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
326             << aLocIgnoAlgo->GetName() << ">");
327     }
328     else
329     {
330       bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
331       int dim = algo->GetDim();
332       int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
333
334       if ( dim < aMaxGlobIgnoDim )
335       {
336         // algo is hidden by a global algo
337         INFOS( ( isGlobal ? "Global" : "Local" )
338               << " <" << algo->GetName() << "> is hidden by global <"
339               << aGlobIgnoAlgo->GetName() << ">");
340       }
341       else if ( !algo->NeedDescretBoundary() && !isGlobal)
342       {
343         // local algo is not hidden and hides algos on sub-shapes
344         if (checkConform && !aSubMesh->IsConform( algo ))
345         {
346           ret = false;
347           checkConform = false; // no more check conformity
348           INFOS( "ERROR: Local <" << algo->GetName() <<
349                 "> would produce not conform mesh: "
350                 "<Not Conform Mesh Allowed> hypotesis is missing");
351           theErrors.push_back( SMESH_Gen::TAlgoStateError() );
352           theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
353         }
354
355         // sub-algos will be hidden by a local <algo>
356         const map<int, SMESH_subMesh*>& smMap = aSubMesh->DependsOn();
357         map<int, SMESH_subMesh*>::const_reverse_iterator revItSub;
358         bool checkConform2 = false;
359         for ( revItSub = smMap.rbegin(); revItSub != smMap.rend(); revItSub++)
360         {
361           checkConformIgnoredAlgos (aMesh, (*revItSub).second, aGlobIgnoAlgo,
362                                     algo, checkConform2, aCheckedMap, theErrors);
363           int key = (*revItSub).first;
364           SMESH_subMesh* sm = (*revItSub).second;
365           if ( aCheckedMap.find( key ) == aCheckedMap.end() )
366           {
367             aCheckedMap[ key ] = sm;
368           }
369         }
370       }
371     }
372   }
373
374   return ret;
375 }
376
377 //=======================================================================
378 //function : checkMissing
379 //purpose  : notify on missing hypothesis
380 //           Return false if algo or hipothesis is missing
381 //=======================================================================
382
383 static bool checkMissing(SMESH_Gen*                aGen,
384                          SMESH_Mesh&               aMesh,
385                          SMESH_subMesh*            aSubMesh,
386                          const int                 aTopAlgoDim,
387                          bool*                     globalChecked,
388                          const bool                checkNoAlgo,
389                          map<int, SMESH_subMesh*>& aCheckedMap,
390                          list< SMESH_Gen::TAlgoStateError > & theErrors)
391 {
392   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
393     return true;
394
395   //MESSAGE("=====checkMissing");
396
397   int ret = true;
398   SMESH_Algo* algo = 0;
399
400   switch (aSubMesh->GetAlgoState())
401   {
402   case SMESH_subMesh::NO_ALGO: {
403     if (checkNoAlgo)
404     {
405       // should there be any algo?
406       int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
407       if (aTopAlgoDim > shapeDim)
408       {
409         MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
410         ret = false;
411         theErrors.push_back( SMESH_Gen::TAlgoStateError() );
412         theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
413       }
414     }
415     return ret;
416   }
417   case SMESH_subMesh::MISSING_HYP: {
418     // notify if an algo missing hyp is attached to aSubMesh
419     algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
420     ASSERT( algo );
421     bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
422     if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
423     {
424       TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
425       SMESH_Hypothesis::Hypothesis_Status status;
426       algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
427       if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
428         MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
429                  << "<" << algo->GetName() << "> has a bad parameter value");
430         errName = status;
431       } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
432         MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
433                  << "<" << algo->GetName() << "> assigned to mismatching geometry");
434         errName = status;
435       } else {
436         MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
437                  << "<" << algo->GetName() << "> misses some hypothesis");
438       }
439       if (IsGlobalHypothesis)
440         globalChecked[ algo->GetDim() ] = true;
441       theErrors.push_back( SMESH_Gen::TAlgoStateError() );
442       theErrors.back().Set( errName, algo, IsGlobalHypothesis );
443     }
444     ret = false;
445     break;
446   }
447   case SMESH_subMesh::HYP_OK:
448     algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
449     ret = true;
450     break;
451   default: ASSERT(0);
452   }
453
454   // do not check under algo that hides sub-algos or
455   // re-start checking NO_ALGO state
456   ASSERT (algo);
457   bool isTopLocalAlgo =
458     ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
459   if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
460   {
461     bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
462     const map<int, SMESH_subMesh*>& subMeshes = aSubMesh->DependsOn();
463     map<int, SMESH_subMesh*>::const_iterator itsub;
464     for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
465     {
466       // sub-meshes should not be checked further more
467       int key = (*itsub).first;
468       SMESH_subMesh* sm = (*itsub).second;
469       if ( aCheckedMap.find( key ) == aCheckedMap.end() )
470         aCheckedMap[ key ] = sm;
471
472       if (isTopLocalAlgo)
473       {
474         //check algo on sub-meshes
475         int aTopAlgoDim2 = algo->GetDim();
476         if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
477                            globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
478         {
479           ret = false;
480           if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
481             checkNoAlgo2 = false;
482         }
483       }
484     }
485   }
486   return ret;
487 }
488
489 //=======================================================================
490 //function : CheckAlgoState
491 //purpose  : notify on bad state of attached algos, return false
492 //           if Compute() would fail because of some algo bad state
493 //=======================================================================
494
495 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
496 {
497   list< TAlgoStateError > errors;
498   return GetAlgoState( aMesh, aShape, errors );
499 }
500
501 //=======================================================================
502 //function : GetAlgoState
503 //purpose  : notify on bad state of attached algos, return false
504 //           if Compute() would fail because of some algo bad state
505 //           theErrors list contains problems description
506 //=======================================================================
507
508 bool SMESH_Gen::GetAlgoState(SMESH_Mesh&               theMesh,
509                              const TopoDS_Shape&       theShape,
510                              list< TAlgoStateError > & theErrors)
511 {
512   //MESSAGE("SMESH_Gen::CheckAlgoState");
513
514   bool ret = true;
515   bool hasAlgo = false;
516
517   SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
518   const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
519   TopoDS_Shape mainShape = meshDS->ShapeToMesh();
520
521   // -----------------
522   // get global algos
523   // -----------------
524
525   const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
526
527   const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
528   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
529   for ( ; it != listHyp.end(); it++)
530   {
531     const SMESHDS_Hypothesis * aHyp = *it;
532     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
533       continue;
534
535     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
536     ASSERT ( algo );
537
538     int dim = algo->GetDim();
539     aGlobAlgoArr[ dim ] = algo;
540
541     hasAlgo = true;
542   }
543
544   // --------------------------------------------------------
545   // info on algos that will be ignored because of ones that
546   // don't NeedDescretBoundary() attached to super-shapes,
547   // check that a conform mesh will be produced
548   // --------------------------------------------------------
549
550
551   // find a global algo possibly hiding sub-algos
552   int dim;
553   const SMESH_Algo* aGlobIgnoAlgo = 0;
554   for (dim = 3; dim > 0; dim--)
555   {
556     if (aGlobAlgoArr[ dim ] &&
557         !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
558     {
559       aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
560       break;
561     }
562   }
563
564   const map<int, SMESH_subMesh*>& smMap = sm->DependsOn();
565   map<int, SMESH_subMesh*>::const_reverse_iterator revItSub = smMap.rbegin();
566   map<int, SMESH_subMesh*> aCheckedMap;
567   bool checkConform = ( !theMesh.IsNotConformAllowed() );
568   int aKey = 1;
569   SMESH_subMesh* smToCheck = sm;
570
571   // loop on theShape and its sub-shapes
572   while ( smToCheck )
573   {
574     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
575       break;
576
577     if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
578       if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
579                                      0, checkConform, aCheckedMap, theErrors))
580         ret = false;
581
582     if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
583       hasAlgo = true;
584
585     // next subMesh
586     if (revItSub != smMap.rend())
587     {
588       aKey = (*revItSub).first;
589       smToCheck = (*revItSub).second;
590       revItSub++;
591     }
592     else
593     {
594       smToCheck = 0;
595     }
596
597   }
598
599   // ----------------------------------------------------------------
600   // info on missing hypothesis and find out if all needed algos are
601   // well defined
602   // ----------------------------------------------------------------
603
604   //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
605
606   // find max dim of global algo
607   int aTopAlgoDim = 0;
608   for (dim = 3; dim > 0; dim--)
609   {
610     if (aGlobAlgoArr[ dim ])
611     {
612       aTopAlgoDim = dim;
613       break;
614     }
615   }
616   aCheckedMap.clear();
617   smToCheck = sm;
618   revItSub = smMap.rbegin();
619   bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
620   bool globalChecked[] = { false, false, false, false };
621
622   // loop on theShape and its sub-shapes
623   while ( smToCheck )
624   {
625     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
626       break;
627
628     if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
629       if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
630                          globalChecked, checkNoAlgo, aCheckedMap, theErrors))
631       {
632         ret = false;
633         if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
634           checkNoAlgo = false;
635       }
636
637     // next subMesh
638     if (revItSub != smMap.rend())
639     {
640       aKey = (*revItSub).first;
641       smToCheck = (*revItSub).second;
642       revItSub++;
643     }
644     else
645       smToCheck = 0;
646   }
647
648   if ( !hasAlgo ) {
649     ret = false;
650     INFOS( "None algorithm attached" );
651     theErrors.push_back( TAlgoStateError() );
652     theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
653   }
654
655   return ret;
656 }
657
658 //=======================================================================
659 //function : IsGlobalHypothesis
660 //purpose  : check if theAlgo is attached to the main shape
661 //=======================================================================
662
663 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
664 {
665   SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
666   return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
667 }
668
669 //=============================================================================
670 /*!
671  *
672  */
673 //=============================================================================
674
675 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh &         aMesh,
676                                const TopoDS_Shape & aShape,
677                                TopoDS_Shape*        assignedTo)
678 {
679
680   SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
681   filter.And( filter.IsApplicableTo( aShape ));
682
683   return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
684 }
685
686 //=============================================================================
687 /*!
688  *
689  */
690 //=============================================================================
691
692 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
693 {
694         // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
695
696         if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
697         {
698                 _mapStudyContext[studyId] = new StudyContextStruct;
699                 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
700         }
701         StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
702 //   ASSERT(_mapStudyContext.find(studyId) != _mapStudyContext.end());
703         return myStudyContext;
704 }
705
706 //=============================================================================
707 /*!
708  *
709  */
710 //=============================================================================
711
712 void SMESH_Gen::Save(int studyId, const char *aUrlOfFile)
713 {
714 }
715
716 //=============================================================================
717 /*!
718  *
719  */
720 //=============================================================================
721
722 void SMESH_Gen::Load(int studyId, const char *aUrlOfFile)
723 {
724 }
725
726 //=============================================================================
727 /*!
728  *
729  */
730 //=============================================================================
731
732 void SMESH_Gen::Close(int studyId)
733 {
734 }
735
736 //=============================================================================
737 /*!
738  *
739  */
740 //=============================================================================
741
742 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
743 {
744   static vector<int> dim;
745   if ( dim.empty() )
746   {
747     dim.resize( TopAbs_SHAPE, -1 );
748     dim[ TopAbs_COMPOUND ]  = MeshDim_3D;
749     dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
750     dim[ TopAbs_SOLID ]     = MeshDim_3D;
751     dim[ TopAbs_SHELL ]     = MeshDim_3D;
752     dim[ TopAbs_FACE  ]     = MeshDim_2D;
753     dim[ TopAbs_WIRE ]      = MeshDim_1D;
754     dim[ TopAbs_EDGE ]      = MeshDim_1D;
755     dim[ TopAbs_VERTEX ]    = MeshDim_0D;
756   }
757   return dim[ aShapeType ];
758 }
759
760 //=============================================================================
761 /*!
762  *
763  */
764 //=============================================================================
765
766 int SMESH_Gen::GetANewId()
767 {
768         //MESSAGE("SMESH_Gen::GetANewId");
769         return _hypId++;
770 }