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