Salome HOME
PAL7933. Add static IsApplicableHypothesis()
[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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
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 "SMDS_MeshElement.hxx"
32 #include "SMDS_MeshNode.hxx"
33
34 #include "utilities.h"
35 #include "OpUtil.hxx"
36 #include "Utils_ExceptHandlers.hxx"
37
38 #include <gp_Pnt.hxx>
39 #include <BRep_Tool.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_ListIteratorOfListOfShape.hxx>
42
43 using namespace std;
44
45 //=============================================================================
46 /*!
47  *  default constructor:
48  */
49 //=============================================================================
50
51 SMESH_Gen::SMESH_Gen()
52 {
53         MESSAGE("SMESH_Gen::SMESH_Gen");
54         _localId = 0;
55         _hypId = 0;
56 }
57
58 //=============================================================================
59 /*!
60  *
61  */
62 //=============================================================================
63
64 SMESH_Gen::~SMESH_Gen()
65 {
66         MESSAGE("SMESH_Gen::~SMESH_Gen");
67 }
68
69 //=============================================================================
70 /*!
71  *
72  */
73 //=============================================================================
74
75 /*SMESH_Hypothesis *SMESH_Gen::CreateHypothesis(const char *anHyp, int studyId)
76         throw(SALOME_Exception)
77 {
78
79         MESSAGE("CreateHypothesis("<<anHyp<<","<<studyId<<")");
80         // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
81
82         StudyContextStruct *myStudyContext = GetStudyContext(studyId);
83
84         // create a new hypothesis object, store its ref. in studyContext
85
86         SMESH_Hypothesis *myHypothesis = _hypothesisFactory.Create(anHyp, studyId);
87         int hypId = myHypothesis->GetID();
88         myStudyContext->mapHypothesis[hypId] = myHypothesis;
89         SCRUTE(studyId);
90         SCRUTE(hypId);
91
92         // store hypothesis in SMESHDS document
93
94         myStudyContext->myDocument->AddHypothesis(myHypothesis);
95         return myHypothesis;
96 }*/
97
98 //=============================================================================
99 /*!
100  *
101  */
102 //=============================================================================
103
104 SMESH_Mesh* SMESH_Gen::CreateMesh(int studyId)
105 throw(SALOME_Exception)
106 {
107         Unexpect aCatch(SalomeException);
108         MESSAGE("SMESH_Gen::CreateMesh");
109 //   if (aShape.ShapeType() == TopAbs_COMPOUND)
110 //     {
111 //       INFOS("Mesh Compound not yet implemented!");
112 //       throw(SALOME_Exception(LOCALIZED("Mesh Compound not yet implemented!")));
113 //     }
114
115         // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
116
117         StudyContextStruct *myStudyContext = GetStudyContext(studyId);
118
119         // create a new SMESH_mesh object
120
121         SMESH_Mesh *mesh = new SMESH_Mesh(_localId++,
122                 studyId,
123                 this,
124                 myStudyContext->myDocument);
125         myStudyContext->mapMesh[_localId] = mesh;
126
127         // associate a TopoDS_Shape to the mesh
128
129 //mesh->ShapeToMesh(aShape);
130         return mesh;
131 }
132
133 //=============================================================================
134 /*!
135  *
136  */
137 //=============================================================================
138
139 bool SMESH_Gen::Compute(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
140 {
141   MESSAGE("SMESH_Gen::Compute");
142   //   bool isDone = false;
143   /*
144      Algo : s'appuie ou non sur une geometrie
145      Si geometrie:
146      Vertex : rien à faire (range le point)
147      Edge, Wire, collection d'edge et wire : 1D
148      Face, Shell, collection de Face et Shells : 2D
149      Solid, Collection de Solid : 3D
150      */
151   // *** corriger commentaires
152   // check hypothesis associated to the mesh :
153   // - only one algo : type compatible with the type of the shape
154   // - hypothesis = compatible with algo
155   //    - check if hypothesis are applicable to this algo
156   //    - check contradictions within hypothesis
157   //    (test if enough hypothesis is done further)
158
159   bool ret = true;
160
161 //   if ( !CheckAlgoState( aMesh, aShape ))
162 //   {
163 //     INFOS( "ABORT MESHING: some algos or hypothesis are missing");
164 //     return false;
165 //   }
166
167   SMESH_subMesh *sm = aMesh.GetSubMesh(aShape);
168
169   if ( sm->GetComputeState() == SMESH_subMesh::COMPUTE_OK )
170     return true; // already computed
171
172   // -----------------------------------------------------------------
173   // apply algos that do not require descretized boundaries, starting
174   // from the most complex shapes
175   // -----------------------------------------------------------------
176
177   // map containing all subshapes in the order: vertices, edges, faces...
178   const map<int, SMESH_subMesh*>& smMap = sm->DependsOn();
179   map<int, SMESH_subMesh*>::const_reverse_iterator revItSub = smMap.rbegin();
180
181   SMESH_subMesh* smToCompute = sm;
182   while ( smToCompute )
183   {
184     const TopoDS_Shape& aSubShape = smToCompute->GetSubShape();
185     if ( GetShapeDim( aSubShape ) < 1 ) break;
186
187     SMESH_Algo* algo = GetAlgo( aMesh, aSubShape );
188     if (algo && !algo->NeedDescretBoundary()) {
189       if (smToCompute->GetComputeState() == SMESH_subMesh::READY_TO_COMPUTE) {
190         ret = smToCompute->ComputeStateEngine( SMESH_subMesh::COMPUTE );
191       } else if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE) {
192         // JFA for PAL6524
193         ret = false;
194       } else {
195       }
196     }
197     if (!ret)
198       return false;
199
200     // next subMesh
201     if (revItSub != smMap.rend())
202     {
203       smToCompute = (*revItSub).second;
204       revItSub++;
205     }
206     else
207       smToCompute = 0;
208   }
209
210   // -----------------------------------------------
211   // mesh the rest subshapes starting from vertices
212   // -----------------------------------------------
213
214   int i, nbSub = smMap.size();
215   map<int, SMESH_subMesh*>::const_iterator itSub = smMap.begin();
216   for ( i = 0; i <= nbSub; ++i ) // loop on the whole map plus <sm>
217   {
218     if ( itSub == smMap.end() )
219       smToCompute = sm;
220     else
221       smToCompute = (itSub++)->second;
222     if (smToCompute->GetComputeState() != SMESH_subMesh::READY_TO_COMPUTE) {
223       if (smToCompute->GetComputeState() == SMESH_subMesh::FAILED_TO_COMPUTE)
224         ret = false;
225       continue;
226     }
227     TopoDS_Shape subShape = smToCompute->GetSubShape();
228     if ( subShape.ShapeType() != TopAbs_VERTEX )
229     {
230       if ( !smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE) )
231         ret = false;
232     }
233     else
234     {
235       TopoDS_Vertex V1 = TopoDS::Vertex(subShape);
236       gp_Pnt P1 = BRep_Tool::Pnt(V1);
237       SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
238       SMDS_MeshNode * node = meshDS->AddNode(P1.X(), P1.Y(), P1.Z());
239       if ( node ) {  // san - increase robustness
240         meshDS->SetNodeOnVertex(node, V1);
241         smToCompute->ComputeStateEngine(SMESH_subMesh::COMPUTE);
242       }
243     }
244   }
245
246   MESSAGE( "VSR - SMESH_Gen::Compute() finished, OK = " << ret);
247   return ret;
248 }
249
250
251 //=======================================================================
252 //function : checkConformIgnoredAlgos
253 //purpose  :
254 //=======================================================================
255
256 static bool checkConformIgnoredAlgos(SMESH_Mesh&               aMesh,
257                                      SMESH_subMesh*            aSubMesh,
258                                      const SMESH_Algo*         aGlobIgnoAlgo,
259                                      const SMESH_Algo*         aLocIgnoAlgo,
260                                      bool &                    checkConform,
261                                      map<int, SMESH_subMesh*>& aCheckedMap)
262 {
263   ASSERT( aSubMesh );
264   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
265     return true;
266
267
268   bool ret = true;
269
270   const list<const SMESHDS_Hypothesis*>& listHyp =
271     aMesh.GetMeshDS()->GetHypothesis( aSubMesh->GetSubShape() );
272   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
273   for ( ; it != listHyp.end(); it++)
274   {
275     const SMESHDS_Hypothesis * aHyp = *it;
276     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
277       continue;
278
279     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
280     ASSERT ( algo );
281
282     if ( aLocIgnoAlgo ) // algo is hidden by a local algo of upper dim
283     {
284       INFOS( "Local <" << algo->GetName() << "> is hidden by local <"
285             << aLocIgnoAlgo->GetName() << ">");
286     }
287     else
288     {
289       bool isGlobal = (aMesh.IsMainShape( aSubMesh->GetSubShape() ));
290       int dim = algo->GetDim();
291       int aMaxGlobIgnoDim = ( aGlobIgnoAlgo ? aGlobIgnoAlgo->GetDim() : -1 );
292
293       if ( dim < aMaxGlobIgnoDim )
294       {
295         // algo is hidden by a global algo
296         INFOS( ( isGlobal ? "Global" : "Local" )
297               << " <" << algo->GetName() << "> is hidden by global <"
298               << aGlobIgnoAlgo->GetName() << ">");
299       }
300       else if ( !algo->NeedDescretBoundary() && !isGlobal)
301       {
302         // local algo is not hidden and hides algos on sub-shapes
303         if (checkConform && !aSubMesh->IsConform( algo ))
304         {
305           ret = false;
306           checkConform = false; // no more check conformity
307           INFOS( "ERROR: Local <" << algo->GetName() <<
308                 "> would produce not conform mesh: "
309                 "<Not Conform Mesh Allowed> hypotesis is missing");
310         }
311
312         // sub-algos will be hidden by a local <algo>
313         const map<int, SMESH_subMesh*>& smMap = aSubMesh->DependsOn();
314         map<int, SMESH_subMesh*>::const_reverse_iterator revItSub;
315         bool checkConform2 = false;
316           for ( revItSub = smMap.rbegin(); revItSub != smMap.rend(); revItSub++)
317         {
318           checkConformIgnoredAlgos (aMesh, (*revItSub).second, aGlobIgnoAlgo,
319                                     algo, checkConform2, aCheckedMap);
320           int key = (*revItSub).first;
321           SMESH_subMesh* sm = (*revItSub).second;
322           if ( aCheckedMap.find( key ) == aCheckedMap.end() )
323           {
324             aCheckedMap[ key ] = sm;
325           }
326         }
327       }
328     }
329   }
330
331   return ret;
332 }
333
334 //=======================================================================
335 //function : checkMissing
336 //purpose  : notify on missing hypothesis
337 //           Return false if algo or hipothesis is missing
338 //=======================================================================
339
340 static bool checkMissing(SMESH_Gen*                aGen,
341                          SMESH_Mesh&               aMesh,
342                          SMESH_subMesh*            aSubMesh,
343                          const int                 aTopAlgoDim,
344                          bool*                     globalChecked,
345                          const bool                checkNoAlgo,
346                          map<int, SMESH_subMesh*>& aCheckedMap)
347 {
348   if ( aSubMesh->GetSubShape().ShapeType() == TopAbs_VERTEX)
349     return true;
350
351   //MESSAGE("=====checkMissing");
352
353   int ret = true;
354   SMESH_Algo* algo = 0;
355
356   switch (aSubMesh->GetAlgoState())
357   {
358   case SMESH_subMesh::NO_ALGO: {
359     if (checkNoAlgo)
360     {
361       // should there be any algo?
362       int shapeDim = SMESH_Gen::GetShapeDim( aSubMesh->GetSubShape() );
363       if (aTopAlgoDim > shapeDim)
364       {
365         INFOS( "ERROR: " << shapeDim << "D algorithm is missing" );
366         ret = false;
367       }
368     }
369     return ret;
370   }
371   case SMESH_subMesh::MISSING_HYP: {
372     // notify if an algo missing hyp is attached to aSubMesh
373     algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
374     ASSERT( algo );
375     bool isGlobalAlgo = aGen->IsGlobalAlgo( algo, aMesh );
376     if (!isGlobalAlgo || !globalChecked[ algo->GetDim() ])
377     {
378       INFOS( "ERROR: " << (isGlobalAlgo ? "Global " : "Local ")
379             << "<" << algo->GetName() << "> misses some hypothesis");
380       if (isGlobalAlgo)
381         globalChecked[ algo->GetDim() ] = true;
382     }
383     ret = false;
384     break;
385   }
386   case SMESH_subMesh::HYP_OK:
387     algo = aGen->GetAlgo( aMesh, aSubMesh->GetSubShape() );
388     ret = true;
389     break;
390   default: ASSERT(0);
391   }
392
393   // do not check under algo that hides sub-algos or
394   // re-start checking NO_ALGO state
395   ASSERT (algo);
396   bool isTopLocalAlgo =
397     ( aTopAlgoDim <= algo->GetDim() && !aGen->IsGlobalAlgo( algo, aMesh ));
398   if (!algo->NeedDescretBoundary() || isTopLocalAlgo)
399   {
400     bool checkNoAlgo2 = ( algo->NeedDescretBoundary() );
401     const map<int, SMESH_subMesh*>& subMeshes = aSubMesh->DependsOn();
402     map<int, SMESH_subMesh*>::const_iterator itsub;
403     for (itsub = subMeshes.begin(); itsub != subMeshes.end(); itsub++)
404     {
405       // sub-meshes should not be checked further more
406       int key = (*itsub).first;
407       SMESH_subMesh* sm = (*itsub).second;
408       if ( aCheckedMap.find( key ) == aCheckedMap.end() )
409         aCheckedMap[ key ] = sm;
410
411       if (isTopLocalAlgo)
412       {
413         //check algo on sub-meshes
414         int aTopAlgoDim2 = algo->GetDim();
415         if (!checkMissing (aGen, aMesh, sm, aTopAlgoDim2,
416                            globalChecked, checkNoAlgo2, aCheckedMap))
417         {
418           ret = false;
419           if (sm->GetAlgoState() == SMESH_subMesh::NO_ALGO )
420             checkNoAlgo2 = false;
421         }
422       }
423     }
424   }
425   return ret;
426 }
427
428 //=======================================================================
429 //function : CheckAlgoState
430 //purpose  : notify on bad state of attached algos, return false
431 //           if Compute() would fail because of some algo bad state
432 //=======================================================================
433
434 bool SMESH_Gen::CheckAlgoState(SMESH_Mesh& aMesh, const TopoDS_Shape& aShape)
435 {
436   //MESSAGE("SMESH_Gen::CheckAlgoState");
437
438   bool ret = true;
439   bool hasAlgo = false;
440
441   SMESH_subMesh* sm = aMesh.GetSubMesh(aShape);
442   const SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
443   TopoDS_Shape mainShape = meshDS->ShapeToMesh();
444
445   // -----------------
446   // get global algos
447   // -----------------
448
449   const SMESH_Algo* aGlobAlgoArr[] = {0,0,0,0};
450
451   const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
452   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
453   for ( ; it != listHyp.end(); it++)
454   {
455     const SMESHDS_Hypothesis * aHyp = *it;
456     if (aHyp->GetType() == SMESHDS_Hypothesis::PARAM_ALGO)
457       continue;
458
459     const SMESH_Algo* algo = dynamic_cast<const SMESH_Algo*> (aHyp);
460     ASSERT ( algo );
461
462     int dim = algo->GetDim();
463     aGlobAlgoArr[ dim ] = algo;
464
465     hasAlgo = true;
466   }
467
468   // --------------------------------------------------------
469   // info on algos that will be ignored because of ones that
470   // don't NeedDescretBoundary() attached to super-shapes,
471   // check that a conform mesh will be produced
472   // --------------------------------------------------------
473
474
475   // find a global algo possibly hidding sub-algos
476   int dim;
477   const SMESH_Algo* aGlobIgnoAlgo = 0;
478   for (dim = 3; dim > 0; dim--)
479   {
480     if (aGlobAlgoArr[ dim ] &&
481         !aGlobAlgoArr[ dim ]->NeedDescretBoundary())
482     {
483       aGlobIgnoAlgo = aGlobAlgoArr[ dim ];
484       break;
485     }
486   }
487
488   const map<int, SMESH_subMesh*>& smMap = sm->DependsOn();
489   map<int, SMESH_subMesh*>::const_reverse_iterator revItSub = smMap.rbegin();
490   map<int, SMESH_subMesh*> aCheckedMap;
491   bool checkConform = ( !aMesh.IsNotConformAllowed() );
492   int aKey = 1;
493   SMESH_subMesh* smToCheck = sm;
494
495   // loop on aShape and its sub-shapes
496   while ( smToCheck )
497   {
498     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
499       break;
500
501     if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
502       if (!checkConformIgnoredAlgos (aMesh, smToCheck, aGlobIgnoAlgo,
503                                      0, checkConform, aCheckedMap))
504         ret = false;
505
506     if ( smToCheck->GetAlgoState() != SMESH_subMesh::NO_ALGO )
507       hasAlgo = true;
508
509     // next subMesh
510     if (revItSub != smMap.rend())
511     {
512       aKey = (*revItSub).first;
513       smToCheck = (*revItSub).second;
514       revItSub++;
515     }
516     else
517     {
518       smToCheck = 0;
519     }
520
521   }
522
523   // ----------------------------------------------------------------
524   // info on missing hypothesis and find out if all needed algos are
525   // well defined
526   // ----------------------------------------------------------------
527
528   //MESSAGE( "---info on missing hypothesis and find out if all needed algos are");
529
530   // find max dim of global algo
531   int aTopAlgoDim = 0;
532   for (dim = 3; dim > 0; dim--)
533   {
534     if (aGlobAlgoArr[ dim ])
535     {
536       aTopAlgoDim = dim;
537       break;
538     }
539   }
540   aCheckedMap.clear();
541   smToCheck = sm;
542   revItSub = smMap.rbegin();
543   bool checkNoAlgo = (bool) aTopAlgoDim;
544   bool globalChecked[] = { false, false, false, false };
545
546   // loop on aShape and its sub-shapes
547   while ( smToCheck )
548   {
549     if ( smToCheck->GetSubShape().ShapeType() == TopAbs_VERTEX)
550       break;
551
552     if ( aCheckedMap.find( aKey ) == aCheckedMap.end() )
553       if (!checkMissing (this, aMesh, smToCheck, aTopAlgoDim,
554                          globalChecked, checkNoAlgo, aCheckedMap))
555       {
556         ret = false;
557         if (smToCheck->GetAlgoState() == SMESH_subMesh::NO_ALGO )
558           checkNoAlgo = false;
559       }
560
561     // next subMesh
562     if (revItSub != smMap.rend())
563     {
564       aKey = (*revItSub).first;
565       smToCheck = (*revItSub).second;
566       revItSub++;
567     }
568     else
569       smToCheck = 0;
570   }
571
572   if ( !hasAlgo )
573     INFOS( "None algorithm attached" );
574
575   return ( ret && hasAlgo );
576 }
577
578 //=======================================================================
579 //function : IsGlobalAlgo
580 //purpose  : check if theAlgo is attached to the main shape
581 //=======================================================================
582
583 bool SMESH_Gen::IsGlobalAlgo(const SMESH_Algo* theAlgo, SMESH_Mesh& aMesh)
584 {
585   const SMESHDS_Mesh* meshDS = aMesh.GetMeshDS();
586   TopoDS_Shape mainShape = meshDS->ShapeToMesh();
587   const list<const SMESHDS_Hypothesis*>& listHyp = meshDS->GetHypothesis( mainShape );
588   list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
589   for ( ; it != listHyp.end(); it++)
590     if ( *it == theAlgo )
591       return true;
592
593   return false;
594 }
595
596
597 //=======================================================================
598 //function : getAlgoId
599 //purpose  : return algo ID or -1 if not found
600 //=======================================================================
601
602 static int getAlgo(const list<const SMESHDS_Hypothesis*>& theHypList,
603                    const int                              theAlgoDim,
604                    const int                              theAlgoShapeType)
605 {
606   list<const SMESHDS_Hypothesis*>::const_iterator it = theHypList.begin();
607
608   int nb_algo = 0;
609   int algo_id = -1;
610
611   while (it!=theHypList.end())
612   {
613     const SMESH_Hypothesis *anHyp = static_cast< const SMESH_Hypothesis *>( *it );
614     if (anHyp->GetType() > SMESHDS_Hypothesis::PARAM_ALGO &&
615         anHyp->GetDim() == theAlgoDim &&
616         ((anHyp->GetShapeType()) & (1 << theAlgoShapeType)))
617     {
618       nb_algo++;
619       algo_id = anHyp->GetID();
620       break;
621     }
622
623     //if (nb_algo > 1) return -1;       // more than one algo
624     it++;
625   }
626
627   return algo_id;
628 }
629
630 //=============================================================================
631 /*!
632  *
633  */
634 //=============================================================================
635
636 SMESH_Algo *SMESH_Gen::GetAlgo(SMESH_Mesh & aMesh, const TopoDS_Shape & aShape)
637 {
638 //  MESSAGE("SMESH_Gen::GetAlgo");
639
640   const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
641   int dim = GetShapeDim( aShape );
642   int shape_type = aShape.ShapeType();
643   int algo_id = -1;
644
645   algo_id = getAlgo( meshDS->GetHypothesis( aShape ), dim, shape_type );
646
647   if (algo_id < 0)
648   {
649     // try ansestors
650     TopTools_ListIteratorOfListOfShape ancIt( aMesh.GetAncestors( aShape ));
651     for (; ancIt.More(); ancIt.Next())
652     {
653       const TopoDS_Shape& ancestor = ancIt.Value();
654       algo_id = getAlgo( meshDS->GetHypothesis( ancestor ), dim, shape_type );
655       if ( algo_id >= 0 )
656         break;
657     }
658     if (algo_id < 0) return NULL;
659   }
660
661   ASSERT(_mapAlgo.find(algo_id) != _mapAlgo.end());
662
663   return _mapAlgo[algo_id];
664
665 //      const SMESHDS_Hypothesis *theHyp = NULL;
666 //      SMESH_Algo *algo = NULL;
667 //      const SMESHDS_Mesh * meshDS = aMesh.GetMeshDS();
668 //      int hypType;
669 //      int hypId;
670 //      int algoDim;
671
672 //      // try shape first, then main shape
673
674 //      TopoDS_Shape mainShape = meshDS->ShapeToMesh();
675 //      const TopoDS_Shape *shapeToTry[2] = { &aShape, &mainShape };
676
677 //      for (int iShape = 0; iShape < 2; iShape++)
678 //      {
679 //              TopoDS_Shape tryShape = (*shapeToTry[iShape]);
680
681 //              const list<const SMESHDS_Hypothesis*>& listHyp =
682 //                      meshDS->GetHypothesis(tryShape);
683 //              list<const SMESHDS_Hypothesis*>::const_iterator it=listHyp.begin();
684
685 //              int nb_algo = 0;
686 //              int shapeDim = GetShapeDim(aShape);
687 //              int typeOfShape = aShape.ShapeType();
688
689 //              while (it!=listHyp.end())
690 //              {
691 //                      const SMESHDS_Hypothesis *anHyp = *it;
692 //                      hypType = anHyp->GetType();
693 //                      //SCRUTE(hypType);
694 //                      if (hypType > SMESHDS_Hypothesis::PARAM_ALGO)
695 //                      {
696 //                              switch (hypType)
697 //                              {
698 //                              case SMESHDS_Hypothesis::ALGO_1D:
699 //                                      algoDim = 1;
700 //                                      break;
701 //                              case SMESHDS_Hypothesis::ALGO_2D:
702 //                                      algoDim = 2;
703 //                                      break;
704 //                              case SMESHDS_Hypothesis::ALGO_3D:
705 //                                      algoDim = 3;
706 //                                      break;
707 //                              default:
708 //                                      algoDim = 0;
709 //                                      break;
710 //                              }
711 //                              //SCRUTE(algoDim);
712 //                              //SCRUTE(shapeDim);
713 //                              //SCRUTE(typeOfShape);
714 //                              if (shapeDim == algoDim)        // count only algos of shape dim.
715 //                              {                               // discard algos for subshapes
716 //                                      hypId = anHyp->GetID(); // (of lower dim.)
717 //                                      ASSERT(_mapAlgo.find(hypId) != _mapAlgo.end());
718 //                                      SMESH_Algo *anAlgo = _mapAlgo[hypId];
719 //                                      //SCRUTE(anAlgo->GetShapeType());
720 //                                      //if (anAlgo->GetShapeType() == typeOfShape)
721 //                                      if ((anAlgo->GetShapeType()) & (1 << typeOfShape))
722 //                                      {                       // only specific TopoDS_Shape
723 //                                              nb_algo++;
724 //                                              theHyp = anHyp;
725 //                                      }
726 //                              }
727 //                      }
728 //                      if (nb_algo > 1) return NULL;   // more than one algo
729 //                      it++;
730 //              }
731 //              if (nb_algo == 1)               // one algo found : OK
732 //                      break;                          // do not try a parent shape
733 //      }
734
735 //      if (!theHyp)
736 //              return NULL;                    // no algo found
737
738 //      hypType = theHyp->GetType();
739 //      hypId = theHyp->GetID();
740
741 //      ASSERT(_mapAlgo.find(hypId) != _mapAlgo.end());
742 //      algo = _mapAlgo[hypId];
743 //      //MESSAGE("Algo found " << algo->GetName() << " Id " << hypId);
744 //      return algo;
745 }
746
747 //=============================================================================
748 /*!
749  *
750  */
751 //=============================================================================
752
753 StudyContextStruct *SMESH_Gen::GetStudyContext(int studyId)
754 {
755         // Get studyContext, create it if it does'nt exist, with a SMESHDS_Document
756
757         if (_mapStudyContext.find(studyId) == _mapStudyContext.end())
758         {
759                 _mapStudyContext[studyId] = new StudyContextStruct;
760                 _mapStudyContext[studyId]->myDocument = new SMESHDS_Document(studyId);
761         }
762         StudyContextStruct *myStudyContext = _mapStudyContext[studyId];
763 //   ASSERT(_mapStudyContext.find(studyId) != _mapStudyContext.end());
764         return myStudyContext;
765 }
766
767 //=============================================================================
768 /*!
769  *
770  */
771 //=============================================================================
772
773 void SMESH_Gen::Save(int studyId, const char *aUrlOfFile)
774 {
775 }
776
777 //=============================================================================
778 /*!
779  *
780  */
781 //=============================================================================
782
783 void SMESH_Gen::Load(int studyId, const char *aUrlOfFile)
784 {
785 }
786
787 //=============================================================================
788 /*!
789  *
790  */
791 //=============================================================================
792
793 void SMESH_Gen::Close(int studyId)
794 {
795 }
796
797 //=============================================================================
798 /*!
799  *
800  */
801 //=============================================================================
802
803 int SMESH_Gen::GetShapeDim(const TopAbs_ShapeEnum & aShapeType)
804 {
805         int shapeDim = -1;                      // Shape dimension: 0D, 1D, 2D, 3D
806         int type = aShapeType;//.ShapeType();
807         switch (type)
808         {
809         case TopAbs_COMPOUND:
810         case TopAbs_COMPSOLID:
811         case TopAbs_SOLID:
812         case TopAbs_SHELL:
813         {
814                 shapeDim = 3;
815                 break;
816         }
817                 //    case TopAbs_SHELL:
818         case TopAbs_FACE:
819         {
820                 shapeDim = 2;
821                 break;
822         }
823         case TopAbs_WIRE:
824         case TopAbs_EDGE:
825         {
826                 shapeDim = 1;
827                 break;
828         }
829         case TopAbs_VERTEX:
830         {
831                 shapeDim = 0;
832                 break;
833         }
834         }
835         return shapeDim;
836 }
837
838 //=============================================================================
839 /*!
840  *
841  */
842 //=============================================================================
843
844 int SMESH_Gen::GetANewId()
845 {
846         //MESSAGE("SMESH_Gen::GetANewId");
847         return _hypId++;
848 }