Salome HOME
e013551244d3b8e9bb2c834248e987917167c14d
[modules/med.git] / src / MedClient / src / CONNECTIVITYClient.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/
19 //
20 #include "MEDMEM_convert.hxx"
21 #include "Utils_CorbaException.hxx"
22 #include "UtilClient.hxx"
23 #include "CONNECTIVITYClient.hxx"
24
25 #include "ReceiverFactory.hxx"
26 using namespace MEDMEM;
27 //=============================================================================
28 /*!
29  * Constructeur
30  */
31 //=============================================================================
32
33 CONNECTIVITYClient::CONNECTIVITYClient(const SALOME_MED::MESH_ptr m,
34                                        medEntityMesh Entity) :
35   CONNECTIVITY(m->getNumberOfTypes(Entity), Entity),
36   IOR_Mesh(SALOME_MED::MESH::_duplicate(m)),
37   _numberOfElements_client(0),
38   _complete(false)
39 {
40   BEGIN_OF("CONNECTIVITYClient::CONNECTIVITYClient()");
41
42   ASSERT(m);
43
44   blankCopy();
45   
46   END_OF("CONNECTIVITYClient::CONNECTIVITYClient()");
47 }
48
49 //=============================================================================
50 /*!
51  * Destructeur
52  */
53 //=============================================================================
54 CONNECTIVITYClient::~CONNECTIVITYClient()
55 {
56   BEGIN_OF("CONNECTIVITYClient::~CONNECTIVITYClient()");
57
58   if (_numberOfElements_client)
59     delete [] _numberOfElements_client;
60
61   END_OF("CONNECTIVITYClient::~CONNECTIVITYClient()");
62 }
63
64 //=============================================================================
65 /*!
66  * Remplit les informations nĂ©cessaires
67  * 1 seul appel Corba
68  */
69 //=============================================================================
70 void CONNECTIVITYClient::blankCopy()
71 {
72   BEGIN_OF("CONNECTIVITYClient::blankCopy()");
73    SALOME_MED::MESH::connectivityInfos_var all;
74    medEntityMesh Entity = getEntity();
75    try
76    {
77         all= IOR_Mesh->getConnectGlobal(Entity);
78    }
79    catch (const exception & ex)
80    {
81         MESSAGE("Unable to acces Global information");
82         THROW_SALOME_CORBA_EXCEPTION(ex.what() ,SALOME::INTERNAL_ERROR);
83    }
84
85   _numberOfNodes = all->numberOfNodes;
86   _entityDimension = all->entityDimension;
87   medGeometryElement * Types;
88
89   long iT, nTwithPoly, nT=getNumberOfTypes(Entity);
90   convertCorbaArray<MED_EN::medGeometryElement,SALOME_MED::medGeometryElement_array *, long>
91     (Types, nTwithPoly, &all->meshTypes);
92
93   //ASSERT(nT == (int) getNumberOfTypes(Entity)); FALSE with POLY
94   SCRUTE(nT);
95   
96   setGeometricTypes(Types, Entity);
97
98   _totalNumberOfElements_client = 0L;
99   _numberOfElements_client = new long[nTwithPoly];
100   for (iT=0; iT<nT; iT++) 
101    {
102     _numberOfElements_client[iT] =  all->numberOfElements[iT];
103     _totalNumberOfElements_client += _numberOfElements_client[iT];
104     SCRUTE(iT);
105     SCRUTE(_numberOfElements_client[iT]);
106   }
107
108   if ( nT != nTwithPoly )
109   {
110     _numberOfElements_client[iT] = all->numberOfElements[iT];
111     _polyType_client = Types[iT];
112   }
113   else
114   {
115     _polyType_client = MED_EN::MED_NONE;
116   }
117
118   _complete = false;
119
120   END_OF("CONNECTIVITYClient::blankCopy()");
121 }
122
123 //=============================================================================
124 /*!
125  */
126 //=============================================================================
127 // template< class T>
128 // void dumpArray(const T* array, int size, const char* msg)
129 // {
130 //   if ( msg )
131 //     std::cout << msg << " " << std::endl;
132 //   std::cout << "Size: " << size << std::endl;
133 //   for ( int i = 0; i < size; i++ )
134 //     std::cout << " " << array[ i ];
135 //   std::cout << endl;
136 // }
137
138 void CONNECTIVITYClient::fillCopy()
139 {
140   BEGIN_OF("void CONNECTIVITYClient::fillCopy()");
141
142
143   if (!_complete) {
144
145     int *pC;
146     long nC;
147     
148     medEntityMesh Entity = getEntity();
149     int iT, nT = getNumberOfTypes(Entity);
150     SCRUTE(nT);
151     const medGeometryElement * T = getGeometricTypes(Entity);
152     
153     int * Count = new int[nT+1] ;
154     Count[0]=1 ;
155     SCRUTE(Count[0]);
156     for (iT=0; iT<nT; iT++) {
157       Count[iT+1]=Count[iT] + _numberOfElements_client[iT];
158       SCRUTE(Count[iT+1]);
159     }
160     setCount(Count, Entity) ;
161     
162     for (iT=0; iT<nT; iT++) {
163       
164       SCRUTE(iT);
165       int kT = Count[iT+1]-Count[iT];
166       SCRUTE(kT);
167       
168       SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForConnectivity(MED_FULL_INTERLACE, MED_NODAL, Entity, T[iT]);
169       pC=ReceiverFactory::getValue(senderForConnectivity,nC);
170       SCRUTE(nC);
171       ASSERT(nC == (T[iT]%100) * kT);
172       
173       setNodal(pC, Entity, T[iT]);
174       delete [] pC;
175     }
176
177     if ( _polyType_client == MED_POLYGON )
178     {
179       const medConnectivity ConType = MED_NODAL;
180       SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForPolygonsConnectivity (ConType, Entity);
181       SALOME::SenderInt_var senderForConnectivityIndex=IOR_Mesh->getSenderForPolygonsConnectivityIndex (ConType, Entity);
182
183       pC=ReceiverFactory::getValue(senderForConnectivity,nC);
184       long nP;
185       int * pCI=ReceiverFactory::getValue(senderForConnectivityIndex,nP);
186 //       dumpArray( pC, nC, "POLYGON Connectivity: ");
187 //       dumpArray( pCI, nP, "POLYGON ConnectivityIndex: ");
188
189       setPolygonsConnectivity(ConType, Entity, pC, pCI, nC, nP-1);
190       delete [] pC;
191       delete [] pCI;
192     }
193
194     if ( _polyType_client == MED_POLYHEDRA )
195     {
196       const medConnectivity ConType = MED_NODAL;
197       SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForPolyhedronConnectivity (ConType);
198       SALOME::SenderInt_var senderForPolyhedronIndex=IOR_Mesh->getSenderForPolyhedronIndex (ConType);
199       SALOME::SenderInt_var senderForPolyhedronFacesIndex=IOR_Mesh->getSenderForPolyhedronFacesIndex ();
200
201       pC=ReceiverFactory::getValue(senderForConnectivity,nC);
202       long nP, nF;
203       int * pPI=ReceiverFactory::getValue(senderForPolyhedronIndex,nP);
204       int * pFI=ReceiverFactory::getValue(senderForPolyhedronFacesIndex,nF);
205
206 //       dumpArray( pC, nC, "POLYHedron Connectivity: ");
207 //       dumpArray( pFI, nF, "POLYHedron Face Index: ");
208 //       dumpArray( pPI, nP, "POLYHedron Index: ");
209
210       setPolyhedronConnectivity(ConType, pC, pPI, nC, nP-1, pFI, nF-1);
211       delete [] pC;
212       delete [] pPI;
213       delete [] pFI;
214     }
215
216     delete[] Count;
217     
218     _complete = true;
219   }
220
221   END_OF("void CONNECTIVITYClient::fillCopy()");
222 }
223
224 //=============================================================================
225 /*!
226  */
227 //=============================================================================
228 int CONNECTIVITYClient::getNumberOf(medEntityMesh Entity, 
229                                     medGeometryElement Type) const
230 {
231   BEGIN_OF("void CONNECTIVITYClient::getNumberOf()");
232
233   int n = 0;
234
235   SCRUTE(Type);
236   SCRUTE(Entity);
237   
238   if (!_complete) {
239     
240     if (Entity == _entity) {
241       
242       if (Type==MED_ALL_ELEMENTS)
243         n = _totalNumberOfElements_client;
244       
245       for (int i=0; i<_numberOfTypes; i++) {
246         SCRUTE(_geometricTypes[i]);
247         if (_geometricTypes[i] == Type) {
248           n = _numberOfElements_client[i];
249           break;
250         }
251       }
252     } 
253     else if (_constituent != NULL)
254       n = _constituent->getNumberOf(Entity,Type);
255     
256   }
257   else
258     n = CONNECTIVITY::getNumberOf(Entity, Type);
259
260   SCRUTE(n);
261   END_OF("void CONNECTIVITYClient::getNumberOf()");
262   return n;
263 }
264
265 //=============================================================================
266 /*!
267  */
268 //=============================================================================
269 const int * CONNECTIVITYClient::getConnectivity
270                       (medConnectivity ConnectivityType, 
271                        medEntityMesh Entity,
272                        medGeometryElement Type)
273 {
274   BEGIN_OF("void CONNECTIVITYClient::getConnectivity()");
275
276   if (!_complete)
277     fillCopy();
278
279   const int * c = CONNECTIVITY::getConnectivity
280     (ConnectivityType, Entity, Type);
281
282   END_OF("void CONNECTIVITYClient::getConnectivity()");
283   return c;
284 }
285
286 //=============================================================================
287 /*!
288  */
289 //=============================================================================
290 const int * CONNECTIVITYClient::getConnectivityIndex
291                       (medConnectivity ConnectivityType,
292                        medEntityMesh Entity)
293 {
294   BEGIN_OF("void CONNECTIVITYClient::getConnectivityIndex()");
295
296   if (!_complete)
297     fillCopy();
298
299   const int *c = CONNECTIVITY::getConnectivityIndex
300     (ConnectivityType, Entity);
301
302   END_OF("void CONNECTIVITYClient::getConnectivityIndex()");
303   return c;
304 }
305
306 //=============================================================================
307 /*!
308  */
309 //=============================================================================
310 void CONNECTIVITYClient::calculateConnectivity
311                       (medConnectivity connectivityType, 
312                        medEntityMesh Entity)
313 {
314   BEGIN_OF("void CONNECTIVITYClient::calculateConnectivity()");
315
316   if (!_complete)
317     fillCopy();
318
319   CONNECTIVITY::calculateConnectivity(connectivityType, Entity);
320
321   END_OF("void CONNECTIVITYClient::calculateConnectivity()");
322 }
323
324 //=============================================================================
325 /*!
326  */
327 //=============================================================================
328 void  CONNECTIVITYClient::updateFamily (vector<FAMILY*> myFamilies)
329 {
330   BEGIN_OF("void CONNECTIVITYClient::updateFamily()");
331
332   if (!_complete)
333     fillCopy();
334
335   CONNECTIVITY::updateFamily(myFamilies);
336
337   END_OF("void CONNECTIVITYClient::updateFamily()");
338 }
339
340 //=============================================================================
341 /*!
342  */
343 //=============================================================================
344 const int * CONNECTIVITYClient::getGlobalNumberingIndex 
345                       (medEntityMesh Entity) const throw (MEDEXCEPTION)
346 {
347   BEGIN_OF("void CONNECTIVITYClient::getGlobalNumberingIndex()");
348
349   if (!_complete)
350     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
351
352   const int * c = CONNECTIVITY::getGlobalNumberingIndex(Entity);
353
354   END_OF("void CONNECTIVITYClient::getGlobalNumberingIndex()");
355
356   return c;
357 }
358
359 //=============================================================================
360 /*!
361  */
362 //=============================================================================
363 bool CONNECTIVITYClient::existConnectivity(medConnectivity ConnectivityType, 
364                                            medEntityMesh Entity) const
365
366   BEGIN_OF("void CONNECTIVITYClient::existConnectivity()");
367
368   if (!_complete)
369     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
370
371   bool b = CONNECTIVITY::existConnectivity(ConnectivityType, Entity);
372
373   END_OF("void CONNECTIVITYClient::existConnectivity()");
374
375   return b;
376 }
377
378 //=============================================================================
379 /*!
380  */
381 //=============================================================================
382 const int * CONNECTIVITYClient::getReverseConnectivity
383                       (medConnectivity ConnectivityType, 
384                        medEntityMesh Entity) throw (MEDEXCEPTION)
385 {
386   BEGIN_OF("void CONNECTIVITYClient::getReverseConnectivity()");
387   
388   if (!_complete)
389     fillCopy();
390
391   const int *c = CONNECTIVITY::getReverseConnectivity
392     (ConnectivityType, Entity);
393
394   END_OF("void CONNECTIVITYClient::getReverseConnectivity()");
395
396   return c;
397 }
398
399 //=============================================================================
400 /*!
401  */
402 //=============================================================================
403 const int * CONNECTIVITYClient::getReverseConnectivityIndex
404                       (medConnectivity ConnectivityType,
405                        medEntityMesh Entity) throw (MEDEXCEPTION)
406 {
407   BEGIN_OF("void CONNECTIVITYClient::getReverseConnectivityIndex()");
408   
409   if (!_complete)
410     fillCopy();
411
412   const int *c =  CONNECTIVITY::getReverseConnectivityIndex
413     (ConnectivityType, Entity);
414
415   END_OF("void CONNECTIVITYClient::getReverseConnectivityIndex()");
416
417   return c;
418 }
419
420 //=============================================================================
421 /*!
422  */
423 //=============================================================================
424 const int* CONNECTIVITYClient::getValue(medConnectivity TypeConnectivity, 
425                         medGeometryElement Type)
426 {
427   BEGIN_OF("void CONNECTIVITYClient::getValue()");
428
429   if (!_complete)
430     fillCopy();
431
432   const int * c =  CONNECTIVITY::getValue(TypeConnectivity, Type);
433
434   END_OF("void CONNECTIVITYClient::()");
435
436   return c;
437 }
438
439 //=============================================================================
440 /*!
441  */
442 //=============================================================================
443 const int* CONNECTIVITYClient::getValueIndex(medConnectivity TypeConnectivity)
444 {
445   BEGIN_OF("void CONNECTIVITYClient::getValueIndex()");
446
447   if (!_complete)
448     fillCopy();
449
450   const int * c =  CONNECTIVITY::getValueIndex(TypeConnectivity);
451
452   END_OF("void CONNECTIVITYClient::getValueIndex()");
453
454   return c;
455 }
456
457 //=============================================================================
458 /*!
459  */
460 //=============================================================================
461 const int* CONNECTIVITYClient::getNeighbourhood() const
462 {
463   BEGIN_OF("void CONNECTIVITYClient::getNeighbourhood()");
464
465   if (!_complete)
466     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
467
468   const int * c =  CONNECTIVITY::getNeighbourhood();
469
470   END_OF("void CONNECTIVITYClient::getNeighbourhood()");
471
472   return c;
473 }
474
475 //=======================================================================
476 //function : existPolygonsConnectivity
477 //purpose  : 
478 //=======================================================================
479
480 bool CONNECTIVITYClient::existPolygonsConnectivity(medConnectivity connectivityType,
481                                                    medEntityMesh   Entity) const
482 {
483   BEGIN_OF("void CONNECTIVITYClient::existPolygonsConnectivity()");
484
485   if (!_complete)
486     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
487
488   bool b = CONNECTIVITY::existPolygonsConnectivity( connectivityType, Entity );
489
490   END_OF("void CONNECTIVITYClient::existPolygonsConnectivity(connectivityType, Entity)");
491
492   return b;
493 }
494
495 //=======================================================================
496 //function : existPolyhedronConnectivity
497 //purpose  : 
498 //=======================================================================
499
500 bool CONNECTIVITYClient::existPolyhedronConnectivity(medConnectivity connectivityType,
501                                                      medEntityMesh   Entity) const
502 {
503   BEGIN_OF("void CONNECTIVITYClient::existPolyhedronConnectivity()");
504
505   if (!_complete)
506     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
507
508   bool b = CONNECTIVITY::existPolyhedronConnectivity( connectivityType, Entity );
509
510   END_OF("void CONNECTIVITYClient::existPolyhedronConnectivity(connectivityType, Entity)");
511
512   return b;
513 }
514
515 //=======================================================================
516 //function : getPolygonsConnectivity
517 //purpose  : 
518 //=======================================================================
519
520 const int* CONNECTIVITYClient::getPolygonsConnectivity(medConnectivity ConnectivityType,
521                                                        medEntityMesh Entity)
522 {
523   BEGIN_OF("void CONNECTIVITYClient::getPolygonsConnectivity()");
524
525   if (!_complete)
526     fillCopy();
527
528   const int * c = CONNECTIVITY::getPolygonsConnectivity (ConnectivityType, Entity);
529
530   END_OF("void CONNECTIVITYClient::getPolygonsConnectivity()");
531   return c;
532 }
533
534 //=======================================================================
535 //function : getPolygonsConnectivityIndex
536 //purpose  : 
537 //=======================================================================
538
539 const int* CONNECTIVITYClient::getPolygonsConnectivityIndex(medConnectivity ConnectivityType,
540                                                             medEntityMesh Entity)
541 {
542   BEGIN_OF("void CONNECTIVITYClient::getPolygonsConnectivityIndex()");
543
544   if (!_complete)
545     fillCopy();
546
547   const int * c = CONNECTIVITY::getPolygonsConnectivityIndex (ConnectivityType, Entity);
548
549   END_OF("void CONNECTIVITYClient::getPolygonsConnectivityIndex()");
550   return c;
551 }
552
553 //=======================================================================
554 //function : getPolyhedronConnectivity
555 //purpose  : 
556 //=======================================================================
557
558 const int* CONNECTIVITYClient::getPolyhedronConnectivity(medConnectivity ConnectivityType) const
559 {
560   BEGIN_OF("void CONNECTIVITYClient::getPolyhedronConnectivity()");
561
562   if (!_complete)
563     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
564
565   const int * c = CONNECTIVITY::getPolyhedronConnectivity (ConnectivityType);
566
567   END_OF("void CONNECTIVITYClient::getPolyhedronConnectivity()");
568   return c;
569 }
570
571 //=======================================================================
572 //function : getPolyhedronFacesIndex
573 //purpose  : 
574 //=======================================================================
575
576 const int* CONNECTIVITYClient::getPolyhedronFacesIndex() const
577 {
578   BEGIN_OF("void CONNECTIVITYClient::getPolyhedronFacesIndex()");
579
580   if (!_complete)
581     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
582
583   const int * c = CONNECTIVITY::getPolyhedronFacesIndex();
584
585   END_OF("void CONNECTIVITYClient::getPolyhedronFacesIndex()");
586   return c;
587 }
588
589 //=======================================================================
590 //function : getPolyhedronIndex
591 //purpose  : 
592 //=======================================================================
593
594 const int* CONNECTIVITYClient::getPolyhedronIndex(medConnectivity ConnectivityType) const
595 {
596   BEGIN_OF("void CONNECTIVITYClient::getPolyhedronIndex()");
597
598   if (!_complete)
599     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
600
601   const int * c = CONNECTIVITY::getPolyhedronIndex (ConnectivityType);
602
603   END_OF("void CONNECTIVITYClient::getPolyhedronIndex()");
604   return c;
605 }
606
607 //=======================================================================
608 //function : getNumberOfPolygons
609 //purpose  : 
610 //=======================================================================
611
612 int CONNECTIVITYClient::getNumberOfPolygons() const
613 {
614   BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolygons()");
615
616   int n = 0;
617
618   if (!_complete) {
619     if ( _polyType_client == MED_POLYGON )
620       n = _numberOfElements_client[ getNumberOfTypes( _entity )];
621   }
622   else
623     n = CONNECTIVITY::getNumberOfPolygons();
624
625   SCRUTE(n);
626
627   END_OF("void CONNECTIVITYClient::getNumberOfPolygons()");
628   return n;
629 }
630
631 //=======================================================================
632 //function : getNumberOfPolyhedronFaces
633 //purpose  : 
634 //=======================================================================
635
636 int CONNECTIVITYClient::getNumberOfPolyhedronFaces() const
637 {
638   BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolyhedronFaces()");
639
640   if (!_complete)
641     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
642
643   int n = CONNECTIVITY::getNumberOfPolyhedronFaces ();
644
645   SCRUTE(n);
646
647   END_OF("void CONNECTIVITYClient::getNumberOfPolyhedronFaces()");
648   return n;
649 }
650
651 //=======================================================================
652 //function : getNumberOfPolyhedron
653 //purpose  : 
654 //=======================================================================
655
656 int CONNECTIVITYClient::getNumberOfPolyhedron() const
657 {
658   BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolyhedron()");
659
660   int n = 0;
661
662   if (!_complete) {
663     if ( _polyType_client == MED_POLYHEDRA )
664       n = _numberOfElements_client[ getNumberOfTypes( _entity )];
665   }
666   else
667     n = CONNECTIVITY::getNumberOfPolyhedron();
668
669   SCRUTE(n);
670
671   END_OF("void CONNECTIVITYClient::getNumberOfPolyhedron()");
672   return n;
673 }
674