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