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