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