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