Salome HOME
Imp 19925 - Mesh preview
[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         continue;
167
168       if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
169         smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
170
171       // we check all the submeshes here and detect if any of them failed to compute
172       if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
173         ret = false;
174       else if ( aShapesId )
175         aShapesId->insert( smToCompute->GetId() );
176     }
177     return ret;
178   }
179   else
180   {
181     // -----------------------------------------------------------------
182     // apply algos that DO NOT require descretized boundaries and DO NOT
183     // support submeshes, starting from the most complex shapes
184     // and collect submeshes with algos that DO support submeshes
185     // -----------------------------------------------------------------
186     list< SMESH_subMesh* > smWithAlgoSupportingSubmeshes;
187     smIt = sm->getDependsOnIterator(includeSelf, complexShapeFirst);
188     while ( smIt->more() )
189     {
190       SMESH_subMesh* smToCompute = smIt->next();
191       if ( smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE )
192         continue;
193
194       const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
195       const int aShapeDim = GetShapeDim( aSubShape );
196       if ( aShapeDim < 1 ) break;
197       
198       // check for preview dimension limitations
199       if ( aShapesId && aShapeDim > (int)aDim )
200         continue;
201
202       SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
203       if ( algo && !algo->NeedDescretBoundary() )
204       {
205         if ( algo->SupportSubmeshes() )
206           smWithAlgoSupportingSubmeshes.push_back( smToCompute );
207         else
208         {
209           smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
210           if ( aShapesId )
211             aShapesId->insert( smToCompute->GetId() );
212         }
213       }
214     }
215     // ------------------------------------------------------------
216     // compute submeshes under shapes with algos that DO NOT require
217     // descretized boundaries and DO support submeshes
218     // ------------------------------------------------------------
219     list< SMESH_subMesh* >::reverse_iterator subIt, subEnd;
220     subIt  = smWithAlgoSupportingSubmeshes.rbegin();
221     subEnd = smWithAlgoSupportingSubmeshes.rend();
222     // start from lower shapes
223     for ( ; subIt != subEnd; ++subIt )
224     {
225       sm = *subIt;
226
227       // get a shape the algo is assigned to
228       TopoDS_Shape algoShape;
229       if ( !GetAlgo( aMesh, sm->GetSubShape(), & algoShape ))
230         continue; // strange...
231
232       // look for more local algos
233       smIt = sm->getDependsOnIterator(!includeSelf, !complexShapeFirst);
234       while ( smIt->more() )
235       {
236         SMESH_subMesh* smToCompute = smIt->next();
237
238         const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
239         const int aShapeDim = GetShapeDim( aSubShape );
240         //if ( aSubShape.ShapeType() == TopAbs_VERTEX ) continue;
241         if ( aShapeDim < 1 ) continue;
242
243         // check for preview dimension limitations
244         if ( aShapesId && GetShapeDim( aSubShape.ShapeType() ) > (int)aDim )
245           continue;
246         
247         SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
248         filter
249           .And( SMESH_HypoFilter::IsApplicableTo( aSubShape ))
250           .And( SMESH_HypoFilter::IsMoreLocalThan( algoShape ));
251
252         if ( SMESH_Algo* subAlgo = (SMESH_Algo*) aMesh.GetHypothesis( aSubShape, filter, true )) {
253           SMESH_Hypothesis::Hypothesis_Status status;
254           if ( subAlgo->CheckHypothesis( aMesh, aSubShape, status ))
255             // mesh a lower smToCompute starting from vertices
256             Compute( aMesh, aSubShape, /*anUpward=*/true, aDim, aShapesId );
257         }
258       }
259     }
260     // ----------------------------------------------------------
261     // apply the algos that do not require descretized boundaries
262     // ----------------------------------------------------------
263     for ( subIt = smWithAlgoSupportingSubmeshes.rbegin(); subIt != subEnd; ++subIt )
264       if ( sm->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE)
265       {
266         const TopAbs_ShapeEnum aShType = sm->GetSubShape().ShapeType();
267         // check for preview dimension limitations
268         if ( aShapesId && GetShapeDim( aShType ) > (int)aDim )
269           continue;
270
271         sm->ComputeStateEngine( SMESH_subMesh::COMPUTE );
272         if ( aShapesId )
273           aShapesId->insert( sm->GetId() );
274       }
275
276     // -----------------------------------------------
277     // mesh the rest subshapes starting from vertices
278     // -----------------------------------------------
279     ret = Compute( aMesh, aShape, /*anUpward=*/true, aDim, aShapesId );
280   }
281
282   MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
283   return ret;
284 }
285
286 //=======================================================================
287 //function : checkConformIgnoredAlgos
288 //purpose  :
289 //=======================================================================
290
291 static bool checkConformIgnoredAlgos(SMESH_Mesh&               aMesh,
292                                      SMESH_subMesh*            aSubMesh,
293                                      const SMESH_Algo*         aGlobIgnoAlgo,
294                                      const SMESH_Algo*         aLocIgnoAlgo,
295                                      bool &                    checkConform,
296                                      map<int, SMESH_subMesh*>& aCheckedMap,
297                                      list< SMESH_Gen::TAlgoStateError > & theErrors)
298 {
299   ASSERT( aSubMesh );
300   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
301     return true;
302
303
304   bool ret = true;
305
306   const list<const SMESHDS_Hypothesis*>& listHyp =
307     aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
308   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
309   for ( ; it != listHyp.end(); it++)
310   {
311     const SMESHDS_Hypothesis * aHyp = *it;
312     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
313       continue;
314
315     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
316     ASSERT ( algo );
317
318     if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
319     {
320       INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
321             << aLocIgnoAlgo->GetName() << ">");
322     }
323     else
324     {
325       bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
326       int dim = algo->GetDim();
327       int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
328
329       if ( dim < aMaxGlobIgnoDim )
330       {
331         // algo is hidden by a global algo
332         INFOS( ( isGlobal ? "Global" : "Local" )
333               << " <" << algo->GetName() << "> is hidden by global <"
334               << aGlobIgnoAlgo->GetName() << ">");
335       }
336       else if ( !algo->NeedDescretBoundary() && !isGlobal)
337       {
338         // local algo is not hidden and hides algos on sub-shapes
339         if (checkConform && !aSubMesh->IsConform( algo ))
340         {
341           ret = false;
342           checkConform = false; // no more check conformity
343           INFOS( "ERROR: Local <" << algo->GetName() <<
344                 "> would produce not conform mesh: "
345                 "<Not Conform Mesh Allowed> hypotesis is missing");
346           theErrors.push_back( SMESH_Gen::TAlgoStateError() );
347           theErrors.back().Set( SMESH_Hypothesis::HYP_NOTCONFORM, algo, false );
348         }
349
350         // sub-algos will be hidden by a local <algo>
351         const map<int, SMESH_subMesh*>& smMap = aSubMesh->DependsOn();
352         map<int, SMESH_subMesh*>::const_reverse_iterator revItSub;
353         bool checkConform2 = false;
354         for ( revItSub = smMap.rbegin(); revItSub != smMap.rend(); revItSub++)
355         {
356           checkConformIgnoredAlgos (aMesh, (*revItSub).second, aGlobIgnoAlgo,
357                                     algo, checkConform2, aCheckedMap, theErrors);
358           int key = (*revItSub).first;
359           SMESH_subMesh* sm = (*revItSub).second;
360           if ( aCheckedMap.find( key ) == aCheckedMap.end() )
361           {
362             aCheckedMap[ key ] = sm;
363           }
364         }
365       }
366     }
367   }
368
369   return ret;
370 }
371
372 //=======================================================================
373 //function : checkMissing
374 //purpose  : notify on missing hypothesis
375 //           Return false if algo or hipothesis is missing
376 //=======================================================================
377
378 static bool checkMissing(SMESH_Gen*                aGen,
379                          SMESH_Mesh&               aMesh,
380                          SMESH_subMesh*            aSubMesh,
381                          const int                 aTopAlgoDim,
382                          bool*                     globalChecked,
383                          const bool                checkNoAlgo,
384                          map<int, SMESH_subMesh*>& aCheckedMap,
385                          list< SMESH_Gen::TAlgoStateError > & theErrors)
386 {
387   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
388     return true;
389
390   //MESSAGE("=====checkMissing");
391
392   int ret = true;
393   SMESH_Algo* algo = 0;
394
395   switch (aSubMesh->GetAlgoState())
396   {
397   case SMESH_subMesh::NO_ALGO: {
398     if (checkNoAlgo)
399     {
400       // should there be any algo?
401       int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
402       if (aTopAlgoDim > shapeDim)
403       {
404         MESSAGE( "ERROR: " << shapeDim << "D algorithm is missing" );
405         ret = false;
406         theErrors.push_back( SMESH_Gen::TAlgoStateError() );
407         theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, shapeDim, true );
408       }
409     }
410     return ret;
411   }
412   case SMESH_subMesh::MISSING_HYP: {
413     // notify if an algo missing hyp is attached to aSubMesh
414     algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
415     ASSERT( algo );
416     bool IsGlobalHypothesis = aGen->IsGlobalHypothesis( algo, aMesh );
417     if (!IsGlobalHypothesis || !globalChecked[ algo->GetDim() ])
418     {
419       TAlgoStateErrorName errName = SMESH_Hypothesis::HYP_MISSING;
420       SMESH_Hypothesis::Hypothesis_Status status;
421       algo->CheckHypothesis( aMesh, aSubMesh->GetSubShape(), status );
422       if ( status == SMESH_Hypothesis::HYP_BAD_PARAMETER ) {
423         MESSAGE( "ERROR: hypothesis of " << (IsGlobalHypothesis ? "Global " : "Local ")
424                  << "<" << algo->GetName() << "> has a bad parameter value");
425         errName = status;
426       } else if ( status == SMESH_Hypothesis::HYP_BAD_GEOMETRY ) {
427         MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
428                  << "<" << algo->GetName() << "> assigned to mismatching geometry");
429         errName = status;
430       } else {
431         MESSAGE( "ERROR: " << (IsGlobalHypothesis ? "Global " : "Local ")
432                  << "<" << algo->GetName() << "> misses some hypothesis");
433       }
434       if (IsGlobalHypothesis)
435         globalChecked[ algo->GetDim() ] = true;
436       theErrors.push_back( SMESH_Gen::TAlgoStateError() );
437       theErrors.back().Set( errName, algo, IsGlobalHypothesis );
438     }
439     ret = false;
440     break;
441   }
442   case SMESH_subMesh::HYP_OK:
443     algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
444     ret = true;
445     break;
446   default: ASSERT(0);
447   }
448
449   // do not check under algo that hides sub-algos or
450   // re-start checking NO_ALGO state
451   ASSERT (algo);
452   bool isTopLocalAlgo =
453     ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalHypothesis( algo, aMesh ));
454   if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
455   {
456     bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
457     const map<int, SMESH_subMesh*>& subMeshes = aSubMesh->DependsOn();
458     map<int, SMESH_subMesh*>::const_iterator itsub;
459     for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
460     {
461       // sub-meshes should not be checked further more
462       int key = (*itsub).first;
463       SMESH_subMesh* sm = (*itsub).second;
464       if ( aCheckedMap.find( key ) == aCheckedMap.end() )
465         aCheckedMap[ key ] = sm;
466
467       if (isTopLocalAlgo)
468       {
469         //check algo on sub-meshes
470         int aTopAlgoDim2 = algo->GetDim();
471         if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
472                            globalChecked, checkNoAlgo2, aCheckedMap, theErrors))
473         {
474           ret = false;
475           if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
476             checkNoAlgo2 = false;
477         }
478       }
479     }
480   }
481   return ret;
482 }
483
484 //=======================================================================
485 //function : CheckAlgoState
486 //purpose  : notify on bad state of attached algos, return false
487 //           if Compute() would fail because of some algo bad state
488 //=======================================================================
489
490 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
491 {
492   list< TAlgoStateError > errors;
493   return GetAlgoState( aMesh, aShape, errors );
494 }
495
496 //=======================================================================
497 //function : GetAlgoState
498 //purpose  : notify on bad state of attached algos, return false
499 //           if Compute() would fail because of some algo bad state
500 //           theErrors list contains problems description
501 //=======================================================================
502
503 bool SMESH_Gen::GetAlgoState(SMESH_Mesh&               theMesh,
504                              const TopoDS_Shape&       theShape,
505                              list< TAlgoStateError > & theErrors)
506 {
507   //MESSAGE("SMESH_Gen::CheckAlgoState");
508
509   bool ret = true;
510   bool hasAlgo = false;
511
512   SMESH_subMesh* sm = theMesh.GetSubMesh(theShape);
513   const SMESHDS_Mesh* meshDS = theMesh.GetMeshDS();
514   TopoDS_Shape mainShape = meshDS->ShapeToMesh();
515
516   // -----------------
517   // get global algos
518   // -----------------
519
520   const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
521
522   const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
523   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
524   for ( ; it != listHyp.end(); it++)
525   {
526     const SMESHDS_Hypothesis * aHyp = *it;
527     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
528       continue;
529
530     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
531     ASSERT ( algo );
532
533     int dim = algo->GetDim();
534     aGlobAlgoArr[ dim ] = algo;
535
536     hasAlgo = true;
537   }
538
539   // --------------------------------------------------------
540   // info on algos that will be ignored because of ones that
541   // don't NeedDescretBoundary() attached to super-shapes,
542   // check that a conform mesh will be produced
543   // --------------------------------------------------------
544
545
546   // find a global algo possibly hiding sub-algos
547   int dim;
548   const SMESH_Algo* aGlobIgnoAlgo = 0;
549   for (dim = 3; dim > 0; dim--)
550   {
551     if (aGlobAlgoArr[ dim ] &&
552         !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
553     {
554       aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
555       break;
556     }
557   }
558
559   const map<int, SMESH_subMesh*>& smMap = sm->DependsOn();
560   map<int, SMESH_subMesh*>::const_reverse_iterator revItSub = smMap.rbegin();
561   map<int, SMESH_subMesh*> aCheckedMap;
562   bool checkConform = ( !theMesh.IsNotConformAllowed() );
563   int aKey = 1;
564   SMESH_subMesh* smToCheck = sm;
565
566   // loop on theShape and its sub-shapes
567   while ( smToCheck )
568   {
569     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
570       break;
571
572     if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
573       if (!checkConformIgnoredAlgos (theMesh, smToCheck, aGlobIgnoAlgo,
574                                      0, checkConform, aCheckedMap, theErrors))
575         ret = false;
576
577     if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
578       hasAlgo = true;
579
580     // next subMesh
581     if (revItSub != smMap.rend())
582     {
583       aKey = (*revItSub).first;
584       smToCheck = (*revItSub).second;
585       revItSub++;
586     }
587     else
588     {
589       smToCheck = 0;
590     }
591
592   }
593
594   // ----------------------------------------------------------------
595   // info on missing hypothesis and find out if all needed algos are
596   // well defined
597   // ----------------------------------------------------------------
598
599   //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
600
601   // find max dim of global algo
602   int aTopAlgoDim = 0;
603   for (dim = 3; dim > 0; dim--)
604   {
605     if (aGlobAlgoArr[ dim ])
606     {
607       aTopAlgoDim = dim;
608       break;
609     }
610   }
611   aCheckedMap.clear();
612   smToCheck = sm;
613   revItSub = smMap.rbegin();
614   bool checkNoAlgo = theMesh.HasShapeToMesh() ? bool( aTopAlgoDim ) : false;
615   bool globalChecked[] = { false, false, false, false };
616
617   // loop on theShape and its sub-shapes
618   while ( smToCheck )
619   {
620     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
621       break;
622
623     if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
624       if (!checkMissing (this, theMesh, smToCheck, aTopAlgoDim,
625                          globalChecked, checkNoAlgo, aCheckedMap, theErrors))
626       {
627         ret = false;
628         if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
629           checkNoAlgo = false;
630       }
631
632     // next subMesh
633     if (revItSub != smMap.rend())
634     {
635       aKey = (*revItSub).first;
636       smToCheck = (*revItSub).second;
637       revItSub++;
638     }
639     else
640       smToCheck = 0;
641   }
642
643   if ( !hasAlgo ) {
644     ret = false;
645     INFOS( "None algorithm attached" );
646     theErrors.push_back( TAlgoStateError() );
647     theErrors.back().Set( SMESH_Hypothesis::HYP_MISSING, 1, true );
648   }
649
650   return ret;
651 }
652
653 //=======================================================================
654 //function : IsGlobalHypothesis
655 //purpose  : check if theAlgo is attached to the main shape
656 //=======================================================================
657
658 bool SMESH_Gen::IsGlobalHypothesis(const SMESH_Hypothesis* theHyp, SMESH_Mesh& aMesh)
659 {
660   SMESH_HypoFilter filter( SMESH_HypoFilter::Is( theHyp ));
661   return aMesh.GetHypothesis( aMesh.GetMeshDS()->ShapeToMesh(), filter, false );
662 }
663
664 //=============================================================================
665 /*!
666  *
667  */
668 //=============================================================================
669
670 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh &         aMesh,
671                                const TopoDS_Shape & aShape,
672                                TopoDS_Shape*        assignedTo)
673 {
674
675   SMESH_HypoFilter filter( SMESH_HypoFilter::IsAlgo() );
676   filter.And( filter.IsApplicableTo( aShape ));
677
678   return (SMESH_Algo*) aMesh.GetHypothesis( aShape, filter, true, assignedTo );
679 }
680
681 //=============================================================================
682 /*!
683  *
684  */
685 //=============================================================================
686
687 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
688 {
689         // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
690
691         if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
692         {
693                 _mapStudyContext[studyId] = new StudyContextStruct;
694                 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
695         }
696         StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
697 //   ASSERT(_mapStudyContext.find(studyId) != _mapStudyContext.end());
698         return myStudyContext;
699 }
700
701 //=============================================================================
702 /*!
703  *
704  */
705 //=============================================================================
706
707 void SMESH_Gen::Save(int studyId, const char *aUrlOfFile)
708 {
709 }
710
711 //=============================================================================
712 /*!
713  *
714  */
715 //=============================================================================
716
717 void SMESH_Gen::Load(int studyId, const char *aUrlOfFile)
718 {
719 }
720
721 //=============================================================================
722 /*!
723  *
724  */
725 //=============================================================================
726
727 void SMESH_Gen::Close(int studyId)
728 {
729 }
730
731 //=============================================================================
732 /*!
733  *
734  */
735 //=============================================================================
736
737 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
738 {
739   static vector<int> dim;
740   if ( dim.empty() )
741   {
742     dim.resize( TopAbs_SHAPE, -1 );
743     dim[ TopAbs_COMPOUND ]  = MeshDim_3D;
744     dim[ TopAbs_COMPSOLID ] = MeshDim_3D;
745     dim[ TopAbs_SOLID ]     = MeshDim_3D;
746     dim[ TopAbs_SHELL ]     = MeshDim_3D;
747     dim[ TopAbs_FACE  ]     = MeshDim_2D;
748     dim[ TopAbs_WIRE ]      = MeshDim_1D;
749     dim[ TopAbs_EDGE ]      = MeshDim_1D;
750     dim[ TopAbs_VERTEX ]    = MeshDim_0D;
751   }
752   return dim[ aShapeType ];
753 }
754
755 //=============================================================================
756 /*!
757  *
758  */
759 //=============================================================================
760
761 int SMESH_Gen::GetANewId()
762 {
763         //MESSAGE("SMESH_Gen::GetANewId");
764         return _hypId++;
765 }