Salome HOME
This commit was generated by cvs2git to create branch 'IMPORT'.
[modules/smesh.git] / src / SMESH_I / SMESH_Mesh_i.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : SMESH_Mesh_i.cxx
4 // Created   : lun mai  6 13:41:55 CEST 2002
5 // Author    : Paul RASCLE, EDF
6 // Project   : SALOME
7 // Copyright : EDF 2002
8 // $Header$
9 //=============================================================================
10 using namespace std;
11
12 #include "SMESH_Mesh_i.hxx"
13 #include "SMESH_subMesh_i.hxx"
14 #include "SMESH_MEDMesh_i.hxx"
15
16 #include "Utils_CorbaException.hxx"
17 #include "utilities.h"
18
19 #include "SALOME_NamingService.hxx"
20 #include "Utils_SINGLETON.hxx"
21 #include "OpUtil.hxx"
22
23 #include "TCollection_AsciiString.hxx"
24 // #include "SMESHDS_ListOfAsciiString.hxx"
25 // #include "SMESHDS_ListIteratorOfListOfAsciiString.hxx"
26 #include "TColStd_ListOfInteger.hxx"
27 #include "TColStd_ListOfReal.hxx"
28 #include "TColStd_ListIteratorOfListOfInteger.hxx"
29 #include "TColStd_ListIteratorOfListOfReal.hxx"
30 #include "SMESHDS_Command.hxx"
31 #include "SMESHDS_CommandType.hxx"
32 #include "SMESHDS_ListOfCommand.hxx"
33 #include "SMESHDS_ListIteratorOfListOfCommand.hxx"
34 #include "Handle_SMESHDS_Command.hxx"
35
36 #include "SMESH_MeshEditor_i.hxx"
37 #include <string>
38 #include <iostream>
39 //#include <sstream>
40
41 //**** SMESHDS en champ
42
43 //=============================================================================
44 /*!
45  *  
46  */
47 //=============================================================================
48
49 SMESH_Mesh_i::SMESH_Mesh_i()
50 {
51   MESSAGE("SMESH_Mesh_i: default constructor, not for use");
52   ASSERT(0);
53 };
54
55 //=============================================================================
56 /*!
57  *  Constructor
58  */
59 //=============================================================================
60
61 SMESH_Mesh_i::SMESH_Mesh_i(SMESH_Gen_i* gen_i,
62                            GEOM::GEOM_Gen_ptr geomEngine,
63                            CORBA::Long studyId,
64                            int localId)
65 {
66   MESSAGE("SMESH_Mesh_i");
67   _gen_i = gen_i;
68   _id = localId;
69   _geom = GEOM::GEOM_Gen::_narrow(geomEngine);
70   _studyId = studyId;
71 }
72
73 //=============================================================================
74 /*!
75  *  Destructor
76  */
77 //=============================================================================
78
79 SMESH_Mesh_i::~SMESH_Mesh_i()
80 {
81   MESSAGE("~SMESH_Mesh_i");
82   // ****
83 };
84
85
86 //=============================================================================
87 /*!
88  *  
89  */
90 //=============================================================================
91
92 CORBA::Boolean SMESH_Mesh_i::AddHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
93                                            SMESH::SMESH_Hypothesis_ptr anHyp)
94   throw (SALOME::SALOME_Exception)
95 {
96   MESSAGE("AddHypothesis");
97   // **** proposer liste de subShape (selection multiple)
98
99   GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
100   if (CORBA::is_nil(mySubShape))
101     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
102                                  SALOME::BAD_PARAM);
103
104   SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
105   if (CORBA::is_nil(myHyp))
106     THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", \
107                                  SALOME::BAD_PARAM);
108   bool ret = false;
109   try
110     {
111       TopoDS_Shape myLocSubShape=
112         _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
113       int hypId = myHyp->GetId();
114       ret = _impl->AddHypothesis(myLocSubShape, hypId);
115     }
116   catch (SALOME_Exception& S_ex)
117     {
118       THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), \
119                                    SALOME::BAD_PARAM);
120     }
121   return ret;
122 };
123
124 //=============================================================================
125 /*!
126  *  
127  */
128 //=============================================================================
129
130 CORBA::Boolean 
131 SMESH_Mesh_i::RemoveHypothesis(GEOM::GEOM_Shape_ptr aSubShape,
132                                SMESH::SMESH_Hypothesis_ptr anHyp)
133   throw (SALOME::SALOME_Exception)
134 {
135   MESSAGE("RemoveHypothesis");
136   // **** proposer liste de subShape (selection multiple)
137
138   GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
139   if (CORBA::is_nil(mySubShape))
140     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
141                                  SALOME::BAD_PARAM);
142
143   SMESH::SMESH_Hypothesis_var myHyp = SMESH::SMESH_Hypothesis::_narrow(anHyp);
144   if (CORBA::is_nil(myHyp))
145     THROW_SALOME_CORBA_EXCEPTION("bad hypothesis reference", \
146                                  SALOME::BAD_PARAM);
147
148   bool ret = false;
149   try
150     {
151       TopoDS_Shape myLocSubShape=
152         _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
153       int hypId = myHyp->GetId();
154       ret = _impl->RemoveHypothesis(myLocSubShape, hypId);
155     }
156   catch (SALOME_Exception& S_ex)
157     {
158       THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), \
159                                    SALOME::BAD_PARAM);
160     }
161   return ret;
162 };
163
164 //=============================================================================
165 /*!
166  *  
167  */
168 //=============================================================================
169
170 SMESH::ListOfHypothesis*
171 SMESH_Mesh_i::GetHypothesisList(GEOM::GEOM_Shape_ptr aSubShape)
172   throw (SALOME::SALOME_Exception)
173 {
174   MESSAGE("GetHypothesisList");
175   // ****
176 };
177
178 //=============================================================================
179 /*!
180  *  
181  */
182 //=============================================================================
183 SMESH::SMESH_subMesh_ptr SMESH_Mesh_i::GetElementsOnShape(GEOM::GEOM_Shape_ptr aSubShape)
184   throw (SALOME::SALOME_Exception)
185 {
186   MESSAGE("SMESH_Mesh_i::GetElementsOnShape");
187   GEOM::GEOM_Shape_var mySubShape = GEOM::GEOM_Shape::_narrow(aSubShape);
188   if (CORBA::is_nil(mySubShape))
189     THROW_SALOME_CORBA_EXCEPTION("bad subShape reference", \
190                                  SALOME::BAD_PARAM);
191
192   int subMeshId = 0;
193   try
194     {
195       SMESH_subMesh_i* subMeshServant;
196       TopoDS_Shape myLocSubShape
197         = _gen_i->_ShapeReader->GetShape(_geom,mySubShape);
198
199       //Get or Create the SMESH_subMesh object implementation
200       
201       ::SMESH_subMesh * mySubMesh
202           = _impl->GetSubMesh(myLocSubShape);
203       subMeshId = mySubMesh->GetId();
204
205       // create a new subMesh object servant if there is none for the shape
206
207       if (_mapSubMesh.find(subMeshId) != _mapSubMesh.end())
208         {
209           ASSERT(_mapSubMesh_i.find(subMeshId) != _mapSubMesh_i.end());
210           subMeshServant = _mapSubMesh_i[subMeshId];
211         }
212       else
213         {
214           // create and activate the CORBA servant of Mesh
215           subMeshServant = new SMESH_subMesh_i(_gen_i, this, subMeshId);
216           SMESH::SMESH_subMesh_var subMesh
217             = SMESH::SMESH_subMesh::_narrow(subMeshServant->_this());
218           _mapSubMesh[subMeshId] = mySubMesh;
219           _mapSubMesh_i[subMeshId] = subMeshServant;
220           _mapSubMeshIor[subMeshId]
221             = SMESH::SMESH_subMesh::_duplicate(subMesh);
222         }
223     }
224   catch (SALOME_Exception& S_ex)
225     {
226       THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
227     }
228
229   ASSERT(_mapSubMeshIor.find(subMeshId) != _mapSubMeshIor.end());
230   return SMESH::SMESH_subMesh::_duplicate(_mapSubMeshIor[subMeshId]);
231 }
232
233 //=============================================================================
234 /*!
235  *  
236  */
237 //=============================================================================
238
239 SMESH::log_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
240  throw (SALOME::SALOME_Exception)
241 {
242  MESSAGE("SMESH_Mesh_i::GetLog");
243
244  SMESH::log_array_var aLog;
245  try
246    {
247      const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
248      aLog = new SMESH::log_array;
249      int indexLog = 0;
250      int lg = logDS.Extent();
251      SCRUTE(lg);
252      aLog->length(lg);
253      SMESHDS_ListIteratorOfListOfCommand its(logDS);
254      while(its.More())
255      {
256         Handle(SMESHDS_Command) com = its.Value();
257         int comType = com->GetType();
258         //SCRUTE(comType);
259         int lgcom = com->GetNumber();
260         //SCRUTE(lgcom);
261         const TColStd_ListOfInteger& intList = com->GetIndexes();
262         int inum = intList.Extent();
263         //SCRUTE(inum);
264         TColStd_ListIteratorOfListOfInteger ii(intList);
265         const TColStd_ListOfReal& coordList = com->GetCoords();
266         int rnum = coordList.Extent();
267         //SCRUTE(rnum);
268         TColStd_ListIteratorOfListOfReal ir(coordList);
269         aLog[indexLog].commandType = comType;
270         aLog[indexLog].number = lgcom;
271         aLog[indexLog].coords.length(rnum);
272         aLog[indexLog].indexes.length(inum);
273         for (int i=0; i<rnum; i++)
274           {
275             aLog[indexLog].coords[i] = ir.Value();
276             //MESSAGE(" "<<i<<" "<<ir.Value());
277             ir.Next();
278           }
279         for (int i=0; i<inum; i++)
280           {
281             aLog[indexLog].indexes[i] = ii.Value();
282             //MESSAGE(" "<<i<<" "<<ii.Value());
283             ii.Next();
284           }
285         indexLog++;
286         its.Next();
287      }
288      if (clearAfterGet) _impl->ClearLog();
289    }
290  catch (SALOME_Exception& S_ex)
291    {
292      THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
293    }
294  return aLog._retn();
295 }
296
297 //  SMESH::string_array* SMESH_Mesh_i::GetLog(CORBA::Boolean clearAfterGet)
298 //    throw (SALOME::SALOME_Exception)
299 //  {
300 //    MESSAGE("SMESH_Mesh_i::GetLog");
301
302 //    SMESH::string_array_var aLog;
303 //    try
304 //      {
305 //        const SMESHDS_ListOfCommand& logDS =_impl->GetLog();
306 //        aLog = new SMESH::string_array;
307 //        int logSize = 0;
308 //        int indexLog = 0;
309 //        int lg = logDS.Extent();
310 //        SCRUTE(lg);
311 //        SMESHDS_ListIteratorOfListOfCommand its(logDS);
312 //        while(its.More())
313 //        {
314 //      Handle(SMESHDS_Command) com = its.Value();
315 //      int comType = com->GetType();
316 //      SCRUTE(comType);
317 //      int lgcom = com->GetNumber();
318 //      SCRUTE(lgcom);
319 //      logSize += lgcom;
320 //      aLog->length(logSize);
321 //      SCRUTE(logSize);
322 //      const TColStd_ListOfInteger& intList = com->GetIndexes();
323 //      TColStd_ListIteratorOfListOfInteger ii(intList);
324 //      const TColStd_ListOfReal& coordList = com->GetCoords();
325 //      TColStd_ListIteratorOfListOfReal ir(coordList);
326 //      for (int icom = 1; icom <= lgcom; icom++)
327 //        {
328 //          ostringstream S;
329 //          switch (comType)
330 //            {
331 //            case SMESHDS_AddNode:
332 //              S << "AddNode " << ii.Value(); ii.Next();
333 //              S << " " << ir.Value(); ir.Next(); 
334 //              S << " " << ir.Value(); ir.Next();
335 //              S << " " << ir.Value(); ir.Next();
336 //              break;
337 //            case SMESHDS_AddEdge:
338 //              S << "AddEdge " << ii.Value(); ii.Next();
339 //              S << " " << ii.Value(); ii.Next();
340 //              S << " " << ii.Value(); ii.Next();
341 //              break;
342 //            case SMESHDS_AddTriangle:
343 //              S << "AddFace " << ii.Value(); ii.Next();
344 //              S << " " << ii.Value(); ii.Next();
345 //              S << " " << ii.Value(); ii.Next();
346 //              S << " " << ii.Value(); ii.Next();
347 //              break;
348 //            case SMESHDS_AddQuadrangle:
349 //              S << "AddFace " << ii.Value(); ii.Next();
350 //              S << " " << ii.Value(); ii.Next();
351 //              S << " " << ii.Value(); ii.Next();
352 //              S << " " << ii.Value(); ii.Next();
353 //              S << " " << ii.Value(); ii.Next();
354 //              break;
355 //            case SMESHDS_AddTetrahedron:
356 //              S << "AddVolume " << ii.Value(); ii.Next();
357 //              S << " " << ii.Value(); ii.Next();
358 //              S << " " << ii.Value(); ii.Next();
359 //              S << " " << ii.Value(); ii.Next();
360 //              S << " " << ii.Value(); ii.Next();
361 //              break;
362 //            case SMESHDS_AddPyramid:
363 //              S << "AddVolume " << ii.Value(); ii.Next();
364 //              S << " " << ii.Value(); ii.Next();
365 //              S << " " << ii.Value(); ii.Next();
366 //              S << " " << ii.Value(); ii.Next();
367 //              S << " " << ii.Value(); ii.Next();
368 //              S << " " << ii.Value(); ii.Next();
369 //              break;
370 //            case SMESHDS_AddPrism:
371 //              S << "AddVolume " << ii.Value(); ii.Next();
372 //              S << " " << ii.Value(); ii.Next();
373 //              S << " " << ii.Value(); ii.Next();
374 //              S << " " << ii.Value(); ii.Next();
375 //              S << " " << ii.Value(); ii.Next();
376 //              S << " " << ii.Value(); ii.Next();
377 //              S << " " << ii.Value(); ii.Next();
378 //              break;
379 //            case SMESHDS_AddHexahedron:
380 //              S << "AddVolume " << ii.Value(); ii.Next();
381 //              S << " " << ii.Value(); ii.Next();
382 //              S << " " << ii.Value(); ii.Next();
383 //              S << " " << ii.Value(); ii.Next();
384 //              S << " " << ii.Value(); ii.Next();
385 //              S << " " << ii.Value(); ii.Next();
386 //              S << " " << ii.Value(); ii.Next();
387 //              S << " " << ii.Value(); ii.Next();
388 //              S << " " << ii.Value(); ii.Next();
389 //              break;
390 //            case SMESHDS_RemoveNode:
391 //              S << "RemoveNode " << ii.Value(); ii.Next();
392 //              break;
393 //            case SMESHDS_RemoveElement:
394 //              S << "RemoveElement " << ii.Value(); ii.Next();
395 //              break;
396 //            default:
397 //              ASSERT(0);
398 //              break;
399 //            }
400 //          string ch = S.str();
401 //          SCRUTE(ch);
402 //          aLog[indexLog++] = CORBA::string_dup(ch.c_str());
403 //        }
404 //      its.Next();
405 //        }
406 //        if (clearAfterGet) _impl->ClearLog();
407 //      }
408 //    catch (SALOME_Exception& S_ex)
409 //      {
410 //        THROW_SALOME_CORBA_EXCEPTION(S_ex.what(), SALOME::BAD_PARAM);
411 //      }
412 //    return aLog._retn();
413 //  }
414
415 //=============================================================================
416 /*!
417  *  
418  */
419 //=============================================================================
420
421 void SMESH_Mesh_i::ClearLog()
422   throw (SALOME::SALOME_Exception)
423 {
424   MESSAGE("SMESH_Mesh_i::ClearLog");
425   // ****
426 }
427
428 //=============================================================================
429 /*!
430  *  
431  */
432 //=============================================================================
433
434 CORBA::Long SMESH_Mesh_i::GetId()
435   throw (SALOME::SALOME_Exception)
436 {
437   MESSAGE("SMESH_Mesh_i::GetId");
438   return _id;
439 }
440
441 //=============================================================================
442 /*!
443  *  
444  */
445 //=============================================================================
446
447 CORBA::Long SMESH_Mesh_i::GetStudyId()
448   throw (SALOME::SALOME_Exception)
449 {
450   return _studyId;
451 }
452 //=============================================================================
453 /*!
454  *  
455  */
456 //=============================================================================
457
458 void SMESH_Mesh_i::SetImpl(::SMESH_Mesh* impl)
459 {
460   MESSAGE("SMESH_Mesh_i::SetImpl");
461   _impl = impl;
462 }
463
464 //=============================================================================
465 /*!
466  *  
467  */
468 //=============================================================================
469
470 ::SMESH_Mesh& SMESH_Mesh_i::GetImpl()
471 {
472   MESSAGE("SMESH_Mesh_i::GetImpl()");
473   return  *_impl;
474 }
475
476 //=============================================================================
477 /*!
478  *  
479  */
480 //=============================================================================
481
482 GEOM::GEOM_Gen_ptr SMESH_Mesh_i::GetGeomEngine()
483 {
484   MESSAGE("SMESH_Mesh_i::GetGeomEngine");
485   return GEOM::GEOM_Gen::_duplicate(_geom);
486 }
487
488 //=============================================================================
489 /*!
490  *  
491  */
492 //=============================================================================
493
494 void SMESH_Mesh_i::SetIor(SMESH::SMESH_Mesh_ptr myIor)
495 {
496   MESSAGE("SMESH_Mesh_i::SetIor");
497   _myIor = SMESH::SMESH_Mesh::_duplicate(myIor);
498   ASSERT(! CORBA::is_nil(_myIor));
499 }
500
501 //=============================================================================
502 /*!
503  *  
504  */
505 //=============================================================================
506
507 SMESH::SMESH_Mesh_ptr SMESH_Mesh_i::GetIor()
508 {
509   MESSAGE("SMESH_Mesh_i::GetIor");
510   ASSERT(! CORBA::is_nil(_myIor));
511   return SMESH::SMESH_Mesh::_duplicate(_myIor);
512 }
513 //=============================================================================
514 /*!
515  *  
516  */
517 //=============================================================================
518
519 SMESH::SMESH_MeshEditor_ptr SMESH_Mesh_i::GetMeshEditor()
520 {
521   SMESH_MeshEditor_i* aMeshEditor =  new  SMESH_MeshEditor_i(_impl->GetMeshDS());
522   SMESH::SMESH_MeshEditor_var aMesh = aMeshEditor->_this();
523   return aMesh._retn();
524 }
525
526 //=============================================================================
527 /*!
528  *  
529  */
530 //=============================================================================
531
532 void SMESH_Mesh_i::ExportMED( const char* file )
533   throw (SALOME::SALOME_Exception)
534 {
535   _impl->ExportMED( file );
536 }
537 void SMESH_Mesh_i::ExportDAT( const char* file )
538   throw (SALOME::SALOME_Exception)
539 {
540   _impl->ExportDAT( file );
541 }
542 void SMESH_Mesh_i::ExportUNV( const char* file )
543   throw (SALOME::SALOME_Exception)
544 {
545   _impl->ExportUNV( file );
546 }
547
548
549 //=============================================================================
550 /*!
551  *  
552  */
553 //=============================================================================
554
555 SALOME_MED::MESH_ptr SMESH_Mesh_i::GetMEDMesh()
556   throw (SALOME::SALOME_Exception)
557 {
558   SMESH_MEDMesh_i* aMedMesh =  new  SMESH_MEDMesh_i( this );
559   SALOME_MED::MESH_var aMesh = aMedMesh->_this();
560   return aMesh._retn();
561 }
562
563 //=============================================================================
564 /*!
565  *  
566  */
567 //=============================================================================
568 CORBA::Long SMESH_Mesh_i::NbNodes()
569   throw (SALOME::SALOME_Exception)
570 {
571   return _impl->NbNodes();
572 }
573
574 //=============================================================================
575 /*!
576  *  
577  */
578 //=============================================================================
579 CORBA::Long SMESH_Mesh_i::NbEdges()
580   throw (SALOME::SALOME_Exception)
581 {
582   return _impl->NbEdges();
583 }
584
585 //=============================================================================
586 /*!
587  *  
588  */
589 //=============================================================================
590 CORBA::Long SMESH_Mesh_i::NbFaces()
591     throw (SALOME::SALOME_Exception)
592 {
593   return _impl->NbFaces();
594 }
595 CORBA::Long SMESH_Mesh_i::NbTriangles()
596     throw (SALOME::SALOME_Exception)
597 {
598   return _impl->NbTriangles();
599 }
600 CORBA::Long SMESH_Mesh_i::NbQuadrangles()
601     throw (SALOME::SALOME_Exception)
602 {
603   return _impl->NbQuadrangles();
604 }
605
606 //=============================================================================
607 /*!
608  *  
609  */
610 //=============================================================================
611 CORBA::Long SMESH_Mesh_i::NbVolumes()
612   throw (SALOME::SALOME_Exception)
613 {
614   return _impl->NbVolumes();
615 }
616 CORBA::Long SMESH_Mesh_i::NbTetras()
617   throw (SALOME::SALOME_Exception)
618 {
619   return _impl->NbTetras();
620 }
621 CORBA::Long SMESH_Mesh_i::NbHexas()
622   throw (SALOME::SALOME_Exception)
623 {
624   return _impl->NbHexas();
625 }
626
627 //=============================================================================
628 /*!
629  *  
630  */
631 //=============================================================================
632 CORBA::Long SMESH_Mesh_i::NbSubMesh()
633   throw (SALOME::SALOME_Exception)
634 {
635   return _impl->NbSubMesh();
636 }