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