Salome HOME
3443b6b520a6d33ed171ec0f3a8e842257a7ed5d
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfReal.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 //  File   : SALOMEDS_AttributeTableOfReal.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDS_AttributeTableOfReal.hxx"
25 #include "SALOMEDS.hxx"
26
27 #include <TCollection_AsciiString.hxx>
28 #include <TCollection_ExtendedString.hxx>
29 #include <TColStd_HSequenceOfInteger.hxx>
30 #include <TColStd_HSequenceOfReal.hxx>
31 #include <TColStd_HSequenceOfExtendedString.hxx>
32
33
34 SALOMEDS_AttributeTableOfReal::SALOMEDS_AttributeTableOfReal
35                   (const Handle(SALOMEDSImpl_AttributeTableOfReal)& theAttr)
36 :SALOMEDS_GenericAttribute(theAttr)
37 {}
38
39 SALOMEDS_AttributeTableOfReal::SALOMEDS_AttributeTableOfReal(SALOMEDS::AttributeTableOfReal_ptr theAttr)
40 :SALOMEDS_GenericAttribute(theAttr)
41 {}
42
43 SALOMEDS_AttributeTableOfReal::~SALOMEDS_AttributeTableOfReal()
44 {}
45
46
47 void SALOMEDS_AttributeTableOfReal::SetTitle(const std::string& theTitle)
48 {
49   if (_isLocal) {
50     CheckLocked();
51     SALOMEDS::Locker lock;     
52     Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->SetTitle((char*)theTitle.c_str());
53   }
54   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetTitle(theTitle.c_str());
55 }
56
57 std::string SALOMEDS_AttributeTableOfReal::GetTitle()
58 {
59   std::string aStr;
60   if (_isLocal) {
61     SALOMEDS::Locker lock; 
62     aStr = TCollection_AsciiString(Handle(SALOMEDSImpl_AttributeTableOfReal)::
63                                    DownCast(_local_impl)->GetTitle()).ToCString();
64   }
65   else aStr = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetTitle();
66   return aStr;
67 }
68
69 void SALOMEDS_AttributeTableOfReal::SetRowTitle(int theIndex, const std::string& theTitle)
70 {
71   if (_isLocal) {
72     CheckLocked();
73     SALOMEDS::Locker lock;     
74     Handle(SALOMEDSImpl_AttributeTableOfReal)::
75       DownCast(_local_impl)->SetRowTitle(theIndex, (char*)theTitle.c_str());
76   }
77   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str());
78 }
79
80 void SALOMEDS_AttributeTableOfReal::SetRowTitles(const std::vector<std::string>& theTitles)
81 {
82   CheckLocked();
83   int aLength = theTitles.size(), i;
84   if (_isLocal) {
85     CheckLocked();
86     SALOMEDS::Locker lock;     
87     Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
88     for (i = 0; i < aLength; i++) aSeq->Append((char*)theTitles[i].c_str());
89     Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->SetRowTitles(aSeq);
90   }
91   else {
92     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
93     aSeq->length(aLength);
94     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theTitles[i].c_str();
95     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowTitles(aSeq);
96   }
97 }
98
99 std::vector<std::string> SALOMEDS_AttributeTableOfReal::GetRowTitles()
100 {
101   std::vector<std::string> aVector;
102   int aLength, i;
103   if (_isLocal) {
104     SALOMEDS::Locker lock; 
105     Handle(TColStd_HSequenceOfExtendedString) aSeq;
106     aSeq = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetRowTitles();
107     aLength = aSeq->Length();
108     for (i = 1; i <= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
109   }
110   else {
111     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowTitles();
112     aLength = aSeq->length();
113     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
114   }
115   return aVector;
116 }
117
118 void SALOMEDS_AttributeTableOfReal::SetColumnTitle(int theIndex, const std::string& theTitle)
119 {
120   if (_isLocal) {
121     CheckLocked();
122     SALOMEDS::Locker lock; 
123     Handle(SALOMEDSImpl_AttributeTableOfReal)::
124       DownCast(_local_impl)->SetColumnTitle(theIndex, (char*)theTitle.c_str());
125   }
126   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str());
127 }
128
129 void SALOMEDS_AttributeTableOfReal::SetColumnTitles(const std::vector<std::string>& theTitles)
130 {
131   int aLength = theTitles.size(), i;
132   if (_isLocal) {
133     CheckLocked();
134     SALOMEDS::Locker lock; 
135     Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
136     for (i = 0; i < aLength; i++) aSeq->Append((char*)theTitles[i].c_str());
137     Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->SetColumnTitles(aSeq);
138   }
139   else {
140     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
141     aSeq->length(aLength);
142     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theTitles[i].c_str();
143     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetColumnTitles(aSeq);
144   }
145 }
146
147 std::vector<std::string> SALOMEDS_AttributeTableOfReal::GetColumnTitles()
148 {
149   std::vector<std::string> aVector;
150   int aLength, i;
151   if (_isLocal) {
152     SALOMEDS::Locker lock; 
153     Handle(TColStd_HSequenceOfExtendedString) aSeq;
154     aSeq = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetColumnTitles();
155     aLength = aSeq->Length();
156     for (i = 1; i <= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
157   }
158   else {
159     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetColumnTitles();
160     aLength = aSeq->length();
161     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
162   }
163   return aVector;
164 }
165
166 void SALOMEDS_AttributeTableOfReal::SetRowUnit(int theIndex, const std::string& theUnit)
167 {
168   if (_isLocal) {
169     CheckLocked();
170     SALOMEDS::Locker lock; 
171     Handle(SALOMEDSImpl_AttributeTableOfReal)::
172       DownCast(_local_impl)->SetRowUnit(theIndex, (char*)theUnit.c_str());
173   }
174   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str());
175 }
176
177 void SALOMEDS_AttributeTableOfReal::SetRowUnits(const std::vector<std::string>& theUnits)
178 {
179   int aLength = theUnits.size(), i;
180   if (_isLocal) {
181     CheckLocked();
182     SALOMEDS::Locker lock; 
183     Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
184     for (i = 0; i < aLength; i++) aSeq->Append((char*)theUnits[i].c_str());
185     Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->SetRowUnits(aSeq);
186   }
187   else {
188     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
189     aSeq->length(aLength);
190     for (i = 0; i < aLength; i++) aSeq[i] = (char*)theUnits[i].c_str();
191     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowUnits(aSeq);
192   }
193 }
194
195 std::vector<std::string> SALOMEDS_AttributeTableOfReal::GetRowUnits()
196 {
197   std::vector<std::string> aVector;
198   int aLength, i;
199   if (_isLocal) {
200     SALOMEDS::Locker lock; 
201     Handle(TColStd_HSequenceOfExtendedString) aSeq;
202     aSeq = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetRowUnits();
203     aLength = aSeq->Length();
204     for (i = 1; i <= aLength; i++) aVector.push_back(TCollection_AsciiString(aSeq->Value(i)).ToCString());
205   }
206   else {
207     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowUnits();
208     aLength = aSeq->length();
209     for (i = 0; i < aLength; i++) aVector.push_back(TCollection_AsciiString((char*)aSeq[i].in()).ToCString());
210   }
211   return aVector;
212 }
213
214 int SALOMEDS_AttributeTableOfReal::GetNbRows()
215 {
216   int aNb;
217   if (_isLocal) {
218     SALOMEDS::Locker lock; 
219     aNb = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetNbRows();
220   }
221   else aNb = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetNbRows();
222   return aNb;
223 }
224
225 int SALOMEDS_AttributeTableOfReal::GetNbColumns()
226 {  
227   int aNb;
228   if (_isLocal) {
229     SALOMEDS::Locker lock; 
230     aNb = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetNbColumns();
231   }
232   else aNb = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetNbColumns();
233   return aNb;
234 }
235
236 void SALOMEDS_AttributeTableOfReal::AddRow(const std::vector<double>& theData)
237 {
238   int aLength = theData.size(), i;
239   if (_isLocal) {
240     CheckLocked();
241     SALOMEDS::Locker lock; 
242     Handle(SALOMEDSImpl_AttributeTableOfReal) aTable;
243     aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl);
244     Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
245     for (int i = 0; i < aLength; i++) aRow->Append(theData[i]);
246     try {
247       aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
248     }   
249     catch(...) {
250       throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
251     }
252   }
253   else {
254     SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq();
255     aSeq->length(aLength);
256     for (i = 0; i < aLength; i++) aSeq[i] = theData[i];
257     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->AddRow(aSeq);
258   }
259 }
260
261 void SALOMEDS_AttributeTableOfReal::SetRow(int theRow, const std::vector<double>& theData)
262 {
263   int aLength = theData.size(), i;
264   if (_isLocal) {
265     CheckLocked();
266     SALOMEDS::Locker lock; 
267     Handle(SALOMEDSImpl_AttributeTableOfReal) aTable;
268     aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl);
269     Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
270     for (int i = 0; i < aLength; i++) aRow->Append(theData[i]);
271     try {
272       aTable->SetRowData(theRow, aRow);
273     }   
274     catch(...) {
275       throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
276     }
277   }
278   else {
279     SALOMEDS::DoubleSeq_var aSeq = new SALOMEDS::DoubleSeq();
280     aSeq->length(aLength);
281     for (i = 0; i < aLength; i++) aSeq[i] = theData[i];
282     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRow(theRow, aSeq);
283   }
284 }
285
286 std::vector<double> SALOMEDS_AttributeTableOfReal::GetRow(int theRow)
287 {
288   std::vector<double> aVector;
289   int aLength, i;
290   if (_isLocal) {
291     SALOMEDS::Locker lock; 
292     Handle(TColStd_HSequenceOfReal) aRow; 
293     aRow = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetRowData(theRow);
294     aLength = aRow->Length();
295     for (i = 1; i <= aLength; i++) aVector.push_back(aRow->Value(i));
296   }
297   else {
298     SALOMEDS::DoubleSeq_var aRow = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRow(theRow);
299         aLength = aRow->length();
300     for (i = 0; i < aLength; i++) aVector.push_back(aRow[i]);
301   }
302
303   return aVector;
304 }
305
306 void SALOMEDS_AttributeTableOfReal::AddColumn(const std::vector<double>& theData)
307 {
308   int aLength = theData.size(), i;
309   if (_isLocal) {
310     CheckLocked();
311     SALOMEDS::Locker lock; 
312     Handle(SALOMEDSImpl_AttributeTableOfReal) aTable;
313     aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl);
314     Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
315     for (int i = 0; i < aLength; i++) aColumn->Append(theData[i]);
316     try {
317       aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
318     }   
319     catch(...) {
320       throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
321     }
322   }
323   else {
324     SALOMEDS::DoubleSeq_var aColumn = new SALOMEDS::DoubleSeq();
325     aColumn->length(aLength);
326     for (i = 0; i < aLength; i++) aColumn[i] = theData[i];
327     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->AddColumn(aColumn);
328   }
329 }
330
331 void SALOMEDS_AttributeTableOfReal::SetColumn(int theColumn, const std::vector<double>& theData)
332 {
333   int aLength = theData.size(), i;
334   if (_isLocal) {
335     CheckLocked();
336     SALOMEDS::Locker lock; 
337     Handle(SALOMEDSImpl_AttributeTableOfReal) aTable;
338     aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl);
339     Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
340     for (int i = 0; i < aLength; i++) aColumn->Append(theData[i]);
341     try {
342       aTable->SetRowData(theColumn, aColumn);
343     }   
344     catch(...) {
345       throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
346     }
347   }
348   else {
349     SALOMEDS::DoubleSeq_var aColumn = new SALOMEDS::DoubleSeq();
350     aColumn->length(aLength);
351     for (i = 0; i < aLength; i++) aColumn[i] = theData[i];
352     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRow(theColumn, aColumn);
353   }
354 }
355
356 std::vector<double> SALOMEDS_AttributeTableOfReal::GetColumn(int theColumn)
357 {
358   std::vector<double> aVector;
359   int aLength, i;
360   if (_isLocal) {
361     SALOMEDS::Locker lock; 
362     Handle(TColStd_HSequenceOfReal) aColumn; 
363     aColumn = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetColumnData(theColumn);
364     aLength = aColumn->Length();
365     for (i = 1; i <= aLength; i++) aVector.push_back(aColumn->Value(i));
366   }
367   else {
368     SALOMEDS::DoubleSeq_var aColumn = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetColumn(theColumn);
369         aLength = aColumn->length();
370     for (i = 0; i < aLength; i++) aVector.push_back(aColumn[i]);
371   }
372   return aVector;
373 }
374
375 void SALOMEDS_AttributeTableOfReal::PutValue(double theValue, int theRow, int theColumn)
376 {
377   if (_isLocal) {
378     CheckLocked();
379     SALOMEDS::Locker lock; 
380     try {
381       Handle(SALOMEDSImpl_AttributeTableOfReal)::
382         DownCast(_local_impl)->PutValue(theValue, theRow, theColumn);
383     }   
384     catch(...) {
385       throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
386     }
387   }
388   else {
389     SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->PutValue(theValue, theRow, theColumn);
390   }
391 }
392
393 bool SALOMEDS_AttributeTableOfReal::HasValue(int theRow, int theColumn)
394 {
395   bool ret;
396   if (_isLocal) {
397     SALOMEDS::Locker lock; 
398     ret = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->HasValue(theRow, theColumn);
399   }
400   else ret = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->HasValue(theRow, theColumn);
401   return ret;
402 }
403
404 double SALOMEDS_AttributeTableOfReal::GetValue(int theRow, int theColumn)
405 {
406   double aValue;
407   if (_isLocal) {
408     SALOMEDS::Locker lock; 
409     try {
410       aValue = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetValue(theRow, theColumn);
411     }   
412     catch(...) {
413       throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
414     }
415   }
416   else {
417     aValue = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetValue(theRow, theColumn);
418   }
419   return aValue;
420 }
421
422 std::vector<int> SALOMEDS_AttributeTableOfReal::GetRowSetIndices(int theRow)
423 {
424   std::vector<int> aVector;
425   int aLength, i;
426   if (_isLocal) {
427     SALOMEDS::Locker lock; 
428     Handle(TColStd_HSequenceOfInteger) aSet; 
429     aSet = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->GetSetRowIndices(theRow);
430     aLength = aSet->Length();
431     for (i = 1; i <= aLength; i++) aVector.push_back(aSet->Value(i));
432   }
433   else {
434     SALOMEDS::LongSeq_var aSet = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowSetIndices(theRow);
435         aLength = aSet->length();
436     for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]);
437   }
438   return aVector;
439 }
440
441 void SALOMEDS_AttributeTableOfReal::SetNbColumns(int theNbColumns)
442 {
443   if (_isLocal) {
444     SALOMEDS::Locker lock; 
445     Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_local_impl)->SetNbColumns(theNbColumns);
446   }
447   else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetNbColumns(theNbColumns);
448 }