]> SALOME platform Git repositories - modules/med.git/blob - src/MedClient/src/CONNECTIVITYClient.cxx
Salome HOME
Join modifications from branch CEAFor_V3_2_0
[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   // create a constituent (PAL10556)
119   if ( Entity == MED_CELL ) {
120     Entity = ( IOR_Mesh->getMeshDimension() == 3 ? MED_FACE : MED_EDGE );
121     _constituent = new CONNECTIVITYClient( IOR_Mesh, Entity );
122   }
123
124   _complete = false;
125
126   END_OF("CONNECTIVITYClient::blankCopy()");
127 }
128
129 //=============================================================================
130 /*!
131  */
132 //=============================================================================
133 // template< class T>
134 // void dumpArray(const T* array, int size, const char* msg)
135 // {
136 //   if ( msg )
137 //     std::cout << msg << " " << std::endl;
138 //   std::cout << "Size: " << size << std::endl;
139 //   for ( int i = 0; i < size; i++ )
140 //     std::cout << " " << array[ i ];
141 //   std::cout << endl;
142 // }
143
144 void CONNECTIVITYClient::fillCopy()
145 {
146   BEGIN_OF("void CONNECTIVITYClient::fillCopy()");
147
148
149   if (!_complete) {
150
151     int *pC;
152     long nC;
153     
154     medEntityMesh Entity = getEntity();
155     int iT, nT = getNumberOfTypes(Entity);
156     SCRUTE(nT);
157     const medGeometryElement * T = getGeometricTypes(Entity);
158     
159     int * Count = new int[nT+1] ;
160     Count[0]=1 ;
161     SCRUTE(Count[0]);
162     for (iT=0; iT<nT; iT++) {
163       Count[iT+1]=Count[iT] + _numberOfElements_client[iT];
164       SCRUTE(Count[iT+1]);
165     }
166     setCount(Count, Entity) ;
167     
168     for (iT=0; iT<nT; iT++) {
169       
170       SCRUTE(iT);
171       int kT = Count[iT+1]-Count[iT];
172       SCRUTE(kT);
173       
174       SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForConnectivity(MED_FULL_INTERLACE, MED_NODAL, Entity, T[iT]);
175       pC=ReceiverFactory::getValue(senderForConnectivity,nC);
176       SCRUTE(nC);
177       ASSERT(nC == (T[iT]%100) * kT);
178       
179       setNodal(pC, Entity, T[iT]);
180       delete [] pC;
181     }
182
183     if ( _polyType_client == MED_POLYGON )
184     {
185       const medConnectivity ConType = MED_NODAL;
186       SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForPolygonsConnectivity (ConType, Entity);
187       SALOME::SenderInt_var senderForConnectivityIndex=IOR_Mesh->getSenderForPolygonsConnectivityIndex (ConType, Entity);
188
189       pC=ReceiverFactory::getValue(senderForConnectivity,nC);
190       long nP;
191       int * pCI=ReceiverFactory::getValue(senderForConnectivityIndex,nP);
192 //       dumpArray( pC, nC, "POLYGON Connectivity: ");
193 //       dumpArray( pCI, nP, "POLYGON ConnectivityIndex: ");
194
195       setPolygonsConnectivity(ConType, Entity, pC, pCI, nC, nP-1);
196       delete [] pC;
197       delete [] pCI;
198     }
199
200     if ( _polyType_client == MED_POLYHEDRA )
201     {
202       const medConnectivity ConType = MED_NODAL;
203       SALOME::SenderInt_var senderForConnectivity=IOR_Mesh->getSenderForPolyhedronConnectivity (ConType);
204       SALOME::SenderInt_var senderForPolyhedronIndex=IOR_Mesh->getSenderForPolyhedronIndex (ConType);
205       SALOME::SenderInt_var senderForPolyhedronFacesIndex=IOR_Mesh->getSenderForPolyhedronFacesIndex ();
206
207       pC=ReceiverFactory::getValue(senderForConnectivity,nC);
208       long nP, nF;
209       int * pPI=ReceiverFactory::getValue(senderForPolyhedronIndex,nP);
210       int * pFI=ReceiverFactory::getValue(senderForPolyhedronFacesIndex,nF);
211
212 //       dumpArray( pC, nC, "POLYHedron Connectivity: ");
213 //       dumpArray( pFI, nF, "POLYHedron Face Index: ");
214 //       dumpArray( pPI, nP, "POLYHedron Index: ");
215
216       setPolyhedronConnectivity(ConType, pC, pPI, nC, nP-1, pFI, nF-1);
217       delete [] pC;
218       delete [] pPI;
219       delete [] pFI;
220     }
221
222     delete[] Count;
223     
224     _complete = true;
225   }
226
227   END_OF("void CONNECTIVITYClient::fillCopy()");
228 }
229
230 //=============================================================================
231 /*!
232  */
233 //=============================================================================
234 int CONNECTIVITYClient::getNumberOf(medEntityMesh Entity, 
235                                     medGeometryElement Type) const
236 {
237   BEGIN_OF("void CONNECTIVITYClient::getNumberOf()");
238
239   int n = 0;
240
241   SCRUTE(Type);
242   SCRUTE(Entity);
243   
244   if (!_complete) {
245     
246     if (Entity == _entity) {
247       
248       if (Type==MED_ALL_ELEMENTS)
249         n = _totalNumberOfElements_client;
250       
251       for (int i=0; i<_numberOfTypes; i++) {
252         SCRUTE(_geometricTypes[i]);
253         if (_geometricTypes[i] == Type) {
254           n = _numberOfElements_client[i];
255           break;
256         }
257       }
258     } 
259     else if (_constituent != NULL)
260       n = _constituent->getNumberOf(Entity,Type);
261     
262   }
263   else
264     n = CONNECTIVITY::getNumberOf(Entity, Type);
265
266   SCRUTE(n);
267   END_OF("void CONNECTIVITYClient::getNumberOf()");
268   return n;
269 }
270
271 //=============================================================================
272 /*!
273  */
274 //=============================================================================
275 const int * CONNECTIVITYClient::getConnectivity
276                       (medConnectivity ConnectivityType, 
277                        medEntityMesh Entity,
278                        medGeometryElement Type)
279 {
280   BEGIN_OF("void CONNECTIVITYClient::getConnectivity()");
281
282   if (!_complete)
283     fillCopy();
284
285   const int * c = CONNECTIVITY::getConnectivity
286     (ConnectivityType, Entity, Type);
287
288   END_OF("void CONNECTIVITYClient::getConnectivity()");
289   return c;
290 }
291
292 //=============================================================================
293 /*!
294  */
295 //=============================================================================
296 const int * CONNECTIVITYClient::getConnectivityIndex
297                       (medConnectivity ConnectivityType,
298                        medEntityMesh Entity)
299 {
300   BEGIN_OF("void CONNECTIVITYClient::getConnectivityIndex()");
301
302   if (!_complete)
303     fillCopy();
304
305   const int *c = CONNECTIVITY::getConnectivityIndex
306     (ConnectivityType, Entity);
307
308   END_OF("void CONNECTIVITYClient::getConnectivityIndex()");
309   return c;
310 }
311
312 //=============================================================================
313 /*!
314  */
315 //=============================================================================
316 void CONNECTIVITYClient::calculateConnectivity
317                       (medConnectivity connectivityType, 
318                        medEntityMesh Entity)
319 {
320   BEGIN_OF("void CONNECTIVITYClient::calculateConnectivity()");
321
322   if (!_complete)
323     fillCopy();
324
325   CONNECTIVITY::calculateConnectivity(connectivityType, Entity);
326
327   END_OF("void CONNECTIVITYClient::calculateConnectivity()");
328 }
329
330 //=============================================================================
331 /*!
332  */
333 //=============================================================================
334 void  CONNECTIVITYClient::updateFamily (vector<FAMILY*> myFamilies)
335 {
336   BEGIN_OF("void CONNECTIVITYClient::updateFamily()");
337
338   if (!_complete)
339     fillCopy();
340
341   CONNECTIVITY::updateFamily(myFamilies);
342
343   END_OF("void CONNECTIVITYClient::updateFamily()");
344 }
345
346 //=============================================================================
347 /*!
348  */
349 //=============================================================================
350 const int * CONNECTIVITYClient::getGlobalNumberingIndex 
351                       (medEntityMesh Entity) const throw (MEDEXCEPTION)
352 {
353   BEGIN_OF("void CONNECTIVITYClient::getGlobalNumberingIndex()");
354
355   if (!_complete)
356     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
357
358   const int * index = CONNECTIVITY::getGlobalNumberingIndex(Entity);
359
360   END_OF("void CONNECTIVITYClient::getGlobalNumberingIndex()");
361
362   return index;
363 }
364
365 //=============================================================================
366 /*!
367  */
368 //=============================================================================
369 bool CONNECTIVITYClient::existConnectivity(medConnectivity ConnectivityType, 
370                                            medEntityMesh Entity) const
371
372   BEGIN_OF("void CONNECTIVITYClient::existConnectivity()");
373
374   if (!_complete)
375     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
376
377   bool b = CONNECTIVITY::existConnectivity(ConnectivityType, Entity);
378
379   END_OF("void CONNECTIVITYClient::existConnectivity()");
380
381   return b;
382 }
383
384 //=============================================================================
385 /*!
386  */
387 //=============================================================================
388 const int * CONNECTIVITYClient::getReverseConnectivity
389                       (medConnectivity ConnectivityType, 
390                        medEntityMesh Entity) throw (MEDEXCEPTION)
391 {
392   BEGIN_OF("void CONNECTIVITYClient::getReverseConnectivity()");
393   
394   if (!_complete)
395     fillCopy();
396
397   const int *c = CONNECTIVITY::getReverseConnectivity
398     (ConnectivityType, Entity);
399
400   END_OF("void CONNECTIVITYClient::getReverseConnectivity()");
401
402   return c;
403 }
404
405 //=============================================================================
406 /*!
407  */
408 //=============================================================================
409 const int * CONNECTIVITYClient::getReverseConnectivityIndex
410                       (medConnectivity ConnectivityType,
411                        medEntityMesh Entity) throw (MEDEXCEPTION)
412 {
413   BEGIN_OF("void CONNECTIVITYClient::getReverseConnectivityIndex()");
414   
415   if (!_complete)
416     fillCopy();
417
418   const int *c =  CONNECTIVITY::getReverseConnectivityIndex
419     (ConnectivityType, Entity);
420
421   END_OF("void CONNECTIVITYClient::getReverseConnectivityIndex()");
422
423   return c;
424 }
425
426 //=============================================================================
427 /*!
428  */
429 //=============================================================================
430 const int* CONNECTIVITYClient::getValue(medConnectivity TypeConnectivity, 
431                         medGeometryElement Type)
432 {
433   BEGIN_OF("void CONNECTIVITYClient::getValue()");
434
435   if (!_complete)
436     fillCopy();
437
438   const int * c =  CONNECTIVITY::getValue(TypeConnectivity, Type);
439
440   END_OF("void CONNECTIVITYClient::()");
441
442   return c;
443 }
444
445 //=============================================================================
446 /*!
447  */
448 //=============================================================================
449 const int* CONNECTIVITYClient::getValueIndex(medConnectivity TypeConnectivity)
450 {
451   BEGIN_OF("void CONNECTIVITYClient::getValueIndex()");
452
453   if (!_complete)
454     fillCopy();
455
456   const int * c =  CONNECTIVITY::getValueIndex(TypeConnectivity);
457
458   END_OF("void CONNECTIVITYClient::getValueIndex()");
459
460   return c;
461 }
462
463 //=============================================================================
464 /*!
465  */
466 //=============================================================================
467 const int* CONNECTIVITYClient::getNeighbourhood() const
468 {
469   BEGIN_OF("void CONNECTIVITYClient::getNeighbourhood()");
470
471   if (!_complete)
472     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
473
474   const int * c =  CONNECTIVITY::getNeighbourhood();
475
476   END_OF("void CONNECTIVITYClient::getNeighbourhood()");
477
478   return c;
479 }
480
481 //=======================================================================
482 //function : existPolygonsConnectivity
483 //purpose  : 
484 //=======================================================================
485
486 bool CONNECTIVITYClient::existPolygonsConnectivity(medConnectivity connectivityType,
487                                                    medEntityMesh   Entity) const
488 {
489   BEGIN_OF("void CONNECTIVITYClient::existPolygonsConnectivity()");
490
491   if (!_complete)
492     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
493
494   bool b = CONNECTIVITY::existPolygonsConnectivity( connectivityType, Entity );
495
496   END_OF("void CONNECTIVITYClient::existPolygonsConnectivity(connectivityType, Entity)");
497
498   return b;
499 }
500
501 //=======================================================================
502 //function : existPolyhedronConnectivity
503 //purpose  : 
504 //=======================================================================
505
506 bool CONNECTIVITYClient::existPolyhedronConnectivity(medConnectivity connectivityType,
507                                                      medEntityMesh   Entity) const
508 {
509   BEGIN_OF("void CONNECTIVITYClient::existPolyhedronConnectivity()");
510
511   if (!_complete)
512     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
513
514   bool b = CONNECTIVITY::existPolyhedronConnectivity( connectivityType, Entity );
515
516   END_OF("void CONNECTIVITYClient::existPolyhedronConnectivity(connectivityType, Entity)");
517
518   return b;
519 }
520
521 //=======================================================================
522 //function : getPolygonsConnectivity
523 //purpose  : 
524 //=======================================================================
525
526 const int* CONNECTIVITYClient::getPolygonsConnectivity(medConnectivity ConnectivityType,
527                                                        medEntityMesh Entity)
528 {
529   BEGIN_OF("void CONNECTIVITYClient::getPolygonsConnectivity()");
530
531   if (!_complete)
532     fillCopy();
533
534   const int * c = CONNECTIVITY::getPolygonsConnectivity (ConnectivityType, Entity);
535
536   END_OF("void CONNECTIVITYClient::getPolygonsConnectivity()");
537   return c;
538 }
539
540 //=======================================================================
541 //function : getPolygonsConnectivityIndex
542 //purpose  : 
543 //=======================================================================
544
545 const int* CONNECTIVITYClient::getPolygonsConnectivityIndex(medConnectivity ConnectivityType,
546                                                             medEntityMesh Entity)
547 {
548   BEGIN_OF("void CONNECTIVITYClient::getPolygonsConnectivityIndex()");
549
550   if (!_complete)
551     fillCopy();
552
553   const int * c = CONNECTIVITY::getPolygonsConnectivityIndex (ConnectivityType, Entity);
554
555   END_OF("void CONNECTIVITYClient::getPolygonsConnectivityIndex()");
556   return c;
557 }
558
559 //=======================================================================
560 //function : getPolyhedronConnectivity
561 //purpose  : 
562 //=======================================================================
563
564 const int* CONNECTIVITYClient::getPolyhedronConnectivity(medConnectivity ConnectivityType) const
565 {
566   BEGIN_OF("void CONNECTIVITYClient::getPolyhedronConnectivity()");
567
568   if (!_complete)
569     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
570
571   const int * c = CONNECTIVITY::getPolyhedronConnectivity (ConnectivityType);
572
573   END_OF("void CONNECTIVITYClient::getPolyhedronConnectivity()");
574   return c;
575 }
576
577 //=======================================================================
578 //function : getPolyhedronFacesIndex
579 //purpose  : 
580 //=======================================================================
581
582 const int* CONNECTIVITYClient::getPolyhedronFacesIndex() const
583 {
584   BEGIN_OF("void CONNECTIVITYClient::getPolyhedronFacesIndex()");
585
586   if (!_complete)
587     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
588
589   const int * c = CONNECTIVITY::getPolyhedronFacesIndex();
590
591   END_OF("void CONNECTIVITYClient::getPolyhedronFacesIndex()");
592   return c;
593 }
594
595 //=======================================================================
596 //function : getPolyhedronIndex
597 //purpose  : 
598 //=======================================================================
599
600 const int* CONNECTIVITYClient::getPolyhedronIndex(medConnectivity ConnectivityType) const
601 {
602   BEGIN_OF("void CONNECTIVITYClient::getPolyhedronIndex()");
603
604   if (!_complete)
605     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
606
607   const int * c = CONNECTIVITY::getPolyhedronIndex (ConnectivityType);
608
609   END_OF("void CONNECTIVITYClient::getPolyhedronIndex()");
610   return c;
611 }
612
613 //=======================================================================
614 //function : getNumberOfPolygons
615 //purpose  : 
616 //=======================================================================
617
618 int CONNECTIVITYClient::getNumberOfPolygons() const
619 {
620   BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolygons()");
621
622   int n = 0;
623
624   if (!_complete) {
625     if ( _polyType_client == MED_POLYGON )
626       n = _numberOfElements_client[ getNumberOfTypes( _entity )];
627   }
628   else
629     n = CONNECTIVITY::getNumberOfPolygons();
630
631   SCRUTE(n);
632
633   END_OF("void CONNECTIVITYClient::getNumberOfPolygons()");
634   return n;
635 }
636
637 //=======================================================================
638 //function : getNumberOfPolyhedronFaces
639 //purpose  : 
640 //=======================================================================
641
642 int CONNECTIVITYClient::getNumberOfPolyhedronFaces() const
643 {
644   BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolyhedronFaces()");
645
646   if (!_complete)
647     (const_cast<CONNECTIVITYClient *>(this))->fillCopy();
648
649   int n = CONNECTIVITY::getNumberOfPolyhedronFaces ();
650
651   SCRUTE(n);
652
653   END_OF("void CONNECTIVITYClient::getNumberOfPolyhedronFaces()");
654   return n;
655 }
656
657 //=======================================================================
658 //function : getNumberOfPolyhedron
659 //purpose  : 
660 //=======================================================================
661
662 int CONNECTIVITYClient::getNumberOfPolyhedron() const
663 {
664   BEGIN_OF("void CONNECTIVITYClient::getNumberOfPolyhedron()");
665
666   int n = 0;
667
668   if (!_complete) {
669     if ( _polyType_client == MED_POLYHEDRA )
670       n = _numberOfElements_client[ getNumberOfTypes( _entity )];
671   }
672   else
673     n = CONNECTIVITY::getNumberOfPolyhedron();
674
675   SCRUTE(n);
676
677   END_OF("void CONNECTIVITYClient::getNumberOfPolyhedron()");
678   return n;
679 }
680