Salome HOME
merging the main trunk with the BrForComp branch to build a pre V3_0_1
[modules/med.git] / src / MedClient / src / SUPPORTClient.cxx
1 #include "Utils_CorbaException.hxx"
2 #include "UtilClient.hxx"
3 #include "SUPPORTClient.hxx"
4 #include "MESHClient.hxx"
5 #include "ReceiverFactory.hxx"
6
7 using namespace MEDMEM;
8 using namespace MED_EN;
9
10 //=============================================================================
11 /*!
12  * Constructeur
13  */
14 //=============================================================================
15
16 SUPPORTClient::SUPPORTClient(const SALOME_MED::SUPPORT_ptr S,
17                              MESH * M) : 
18   SUPPORT(), 
19   IOR_Support(SALOME_MED::SUPPORT::_duplicate(S)),_refCounter(1)
20 {
21   BEGIN_OF("SUPPORTClient::SUPPORTClient(SALOME_MED::SUPPORT_ptr m)");
22
23   SCRUTE(S);
24   SCRUTE(M);
25   if(M)
26     _mesh=M;
27   else
28     {
29       _mesh=new MESHClient(IOR_Support->getMesh());
30     }
31   blankCopy();
32
33   END_OF("SUPPORTClient::SUPPORTClient(SALOME_MED::SUPPORT_ptr m)");
34 }
35 //=============================================================================
36 /*!
37  * Remplit les informations générales
38  */
39 //=============================================================================
40 void SUPPORTClient::blankCopy()
41 {
42   BEGIN_OF("SUPPORTClient::blankCopy");
43
44  try
45   {
46         SALOME_MED::SUPPORT::supportInfos_var all = IOR_Support->getSupportGlobal();
47
48         _name = all->name;
49         _description = all->description;
50         setAll(all->isOnAllElements);
51         setEntity(all->entity);
52 // modifs PN 
53         setNumberOfGeometricType(all->numberOfGeometricType);
54         convertCorbaArray(_geometricType, _numberOfGeometricType,
55                            &all->types);
56
57         //_name = IOR_Support->getName();
58         //_description = IOR_Support->getDescription();
59         //setAll(IOR_Support->isOnAllElements());
60         //setEntity(IOR_Support->getEntity());
61
62         SCRUTE(_name);
63         SCRUTE(_description);
64         //convertCorbaArray(_geometricType, _numberOfGeometricType,
65         //          IOR_Support->getTypes());
66
67         int *nE = new int[_numberOfGeometricType];
68         int i;
69         for (i=0; i<_numberOfGeometricType; i++)
70         {
71                 nE[i] = all->nbEltTypes[i];
72         }
73         setNumberOfElements(nE);
74
75         delete [] nE;
76
77         SCRUTE(_totalNumberOfElements);
78         _complete_support = false;
79         //Gauss points settings
80         _numberOfGaussPoint = new int[_numberOfGeometricType];
81         for (int i=0;i<_numberOfGeometricType;i++)
82           _numberOfGaussPoint[i] = 1 ;
83   }
84   catch( const CORBA::Exception &ex )
85   {
86          MESSAGE("Erreur CORBA dans la communication" ) ;
87          THROW_SALOME_CORBA_EXCEPTION("No associated Support", \
88                                        SALOME::INTERNAL_ERROR);
89   }
90
91   END_OF("SUPPORTClient::blankCopy");
92
93 }
94 //=============================================================================
95 /*!
96  *  
97  */
98 //=============================================================================
99 void SUPPORTClient::fillCopy()
100 {
101   BEGIN_OF("SUPPORTClient::fillCopy");
102
103   if (!_complete_support) {
104
105     const int * index, * value;
106     long n_index, n_value;
107     
108     SALOME::SenderInt_var senderForValue=IOR_Support->getSenderForNumber(MED_ALL_ELEMENTS);
109     value=(const int *)ReceiverFactory::getValue(senderForValue,n_value);
110     SALOME::SenderInt_var senderForIndex=IOR_Support->getSenderForNumberIndex();
111     index=(const int *)ReceiverFactory::getValue(senderForIndex,n_index);
112     
113     SCRUTE(n_index);
114     SCRUTE(n_value);
115     setNumber(index, value,true);
116
117     _complete_support = true;
118   }
119
120   END_OF("SUPPORTClient::fillCopy");
121 }
122 //=============================================================================
123 /*!
124  * Destructeur
125  */
126 //=============================================================================
127 SUPPORTClient::~SUPPORTClient()
128 {
129   BEGIN_OF("SUPPORTClient::~SUPPORTClient");
130   IOR_Support->release();
131   if(_mesh)
132     _mesh->removeReference();
133   END_OF("SUPPORTClient::~SUPPORTClient");
134 }
135
136 //=============================================================================
137 /*!
138  * Destructeur
139  */
140 //=============================================================================
141 MEDSKYLINEARRAY *  SUPPORTClient::getnumber() const throw (MEDEXCEPTION)
142 {
143   BEGIN_OF("SUPPORTClient::getnumber()");
144
145   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
146   MEDSKYLINEARRAY *m = SUPPORT::getnumber();
147
148   END_OF("SUPPORTClient::getnumber()");
149   return m;
150 }
151
152 //=============================================================================
153 /*!
154  * 
155  */
156 //=============================================================================
157 const int *  SUPPORTClient::getNumber(medGeometryElement GeometricType) 
158     const throw (MEDEXCEPTION)
159 {
160   BEGIN_OF("SUPPORTClient::getnumber(medGeometryElement)");
161
162   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
163   const int *n = SUPPORT::getNumber(GeometricType);
164
165   END_OF("SUPPORTClient::getnumber(medGeometryElement)");
166   return n;
167 }
168
169 //=============================================================================
170 /*!
171  * 
172  */
173 //=============================================================================
174 const int *  SUPPORTClient::getNumberIndex() const throw (MEDEXCEPTION) 
175 {
176   BEGIN_OF("SUPPORTClient::getnumberIndex()");
177
178   if (!_complete_support) (const_cast<SUPPORTClient *>(this))->fillCopy();
179   const int * n = SUPPORT::getNumberIndex();
180
181   END_OF("SUPPORTClient::getnumberIndex()");
182   return n;
183 }
184
185 //=============================================================================
186 /*!
187  * 
188  */
189 //=============================================================================
190 void SUPPORTClient::addReference() const
191 {
192   _refCounter++;
193 }
194
195 //=============================================================================
196 /*!
197  * 
198  */
199 //=============================================================================
200 void SUPPORTClient::removeReference() const
201 {
202   if (--_refCounter <= 0)
203     {
204       delete this;
205     }
206 }