]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx
Salome HOME
Copyrights update
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfInteger.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_AttributeTableOfInteger.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDS_AttributeTableOfInteger.hxx"
25
26 #include <TCollection_AsciiString.hxx>
27 #include <TCollection_ExtendedString.hxx>
28 #include <TColStd_HSequenceOfInteger.hxx>
29 #include <TColStd_HSequenceOfExtendedString.hxx>
30
31
32 SALOMEDS_AttributeTableOfInteger
33 ::SALOMEDS_AttributeTableOfInteger(const Handle(SALOMEDSImpl_AttributeTableOfInteger)& theAttr)
34 :SALOMEDS_GenericAttribute(theAttr)
35 {}
36
37 SALOMEDS_AttributeTableOfInteger::SALOMEDS_AttributeTableOfInteger(SALOMEDS::AttributeTableOfInteger_ptr theAttr)
38 :SALOMEDS_GenericAttribute(theAttr)
39 {}
40
41 SALOMEDS_AttributeTableOfInteger::~SALOMEDS_AttributeTableOfInteger()
42 {}
43
44
45 void SALOMEDS_AttributeTableOfInteger::SetTitle(const std::string& theTitle)
46 {
47   CheckLocked();
48   if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetTitle((char*)theTitle.c_str());
49   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetTitle(theTitle.c_str());
50 }
51
52 std::string SALOMEDS_AttributeTableOfInteger::GetTitle()
53 {
54   std::string aStr;
55   if(_isLocal) 
56     aStr = TCollection_AsciiString(Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetTitle()).ToCString();
57   else aStr = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetTitle();
58   return aStr;
59 }
60
61 void SALOMEDS_AttributeTableOfInteger::SetRowTitle(int theIndex, const std::string& theTitle)
62 {
63   CheckLocked();
64   if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetRowTitle(theIndex, 
65                                                                                                 (char*)theTitle.c_str());
66   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str());
67 }
68
69 void SALOMEDS_AttributeTableOfInteger::SetRowTitles(const std::vector<std::string>& theTitles)
70 {
71   CheckLocked();
72   int aLength = theTitles.size(), i;
73   if(_isLocal) {
74     Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
75     for(i = 0; i < aLength; i++) aSeq->Append((char*)theTitles[i].c_str());
76     Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetRowTitles(aSeq);
77   }
78   else {
79     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
80     aSeq->length(aLength);
81     for(i = 0; i < aLength; i++) aSeq[i] = theTitles[i].c_str();
82     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowTitles(aSeq);
83   }
84   
85 }
86
87 std::vector<std::string> SALOMEDS_AttributeTableOfInteger::GetRowTitles()
88 {
89   std::vector<std::string> aVector;
90   int aLength, i;
91   if(_isLocal) {
92     Handle(TColStd_HSequenceOfExtendedString) aSeq;
93     aSeq = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetRowTitles();
94     aLength = aSeq->Length();
95     for(i = 1; i<= aLength; i++) aVector.push_back(TCollection_AsciiString((aSeq->Value(i))).ToCString());
96   }
97   else {
98     SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetRowTitles();
99     aLength = aSeq->length();
100     for(i = 0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
101   }
102   return aVector;
103 }
104
105 void SALOMEDS_AttributeTableOfInteger::SetColumnTitle(int theIndex, const std::string& theTitle)
106 {
107   CheckLocked();
108   if(_isLocal) 
109     Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetColumnTitle(theIndex, 
110                                                                                         (char*)theTitle.c_str());
111   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str());
112 }
113
114 void SALOMEDS_AttributeTableOfInteger::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_AttributeTableOfInteger)::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] = theTitles[i].c_str();
127     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetColumnTitles(aSeq);
128   }
129 }
130
131 std::vector<std::string> SALOMEDS_AttributeTableOfInteger::GetColumnTitles()
132 {
133   std::vector<std::string> aVector;
134   int aLength, i;
135   if(_isLocal) {
136     Handle(TColStd_HSequenceOfExtendedString) aSeq;
137     aSeq = Handle(SALOMEDSImpl_AttributeTableOfInteger)::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::AttributeTableOfInteger::_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_AttributeTableOfInteger::SetRowUnit(int theIndex, const std::string& theUnit)
150 {
151   CheckLocked();
152   if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetRowUnit(theIndex, 
153                                                                                                (char*)theUnit.c_str()); 
154   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str());
155 }
156
157 void SALOMEDS_AttributeTableOfInteger::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_AttributeTableOfInteger)::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::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowUnits(aSeq);
171   }
172 }
173
174 std::vector<std::string> SALOMEDS_AttributeTableOfInteger::GetRowUnits()
175 {
176   std::vector<std::string> aVector;
177   int aLength, i;
178   if(_isLocal) {
179     Handle(TColStd_HSequenceOfExtendedString) aSeq;
180     aSeq = Handle(SALOMEDSImpl_AttributeTableOfInteger)::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::AttributeTableOfInteger::_narrow(_corba_impl)->GetRowUnits();
186     aLength = aSeq->length();
187     for(i = 0; i<aLength; i++) aVector.push_back((char*)aSeq[i].in());
188   }
189   return aVector;
190 }
191
192 int SALOMEDS_AttributeTableOfInteger::GetNbRows()
193 {
194   int aNb;
195   if(_isLocal) aNb = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetNbRows();
196   else aNb = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetNbRows();
197   return aNb;
198 }
199
200 int SALOMEDS_AttributeTableOfInteger::GetNbColumns()
201 {  
202   int aNb;
203   if(_isLocal) aNb = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetNbColumns();
204   else aNb = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetNbColumns();
205   return aNb;
206   
207 }
208
209 void SALOMEDS_AttributeTableOfInteger::AddRow(const std::vector<int>& theData)
210 {
211   CheckLocked();
212   int aLength = theData.size(), i;
213   if(_isLocal) {
214     Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable;
215     aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl);
216     Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
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::AttributeTableOfInteger::IncorrectArgumentLength();
223     }
224   }
225   else {
226     SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq();
227     aSeq->length(aLength);
228     for(i = 0; i < aLength; i++) aSeq[i] = theData[i];
229     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->AddRow(aSeq);
230   }
231 }
232
233 void SALOMEDS_AttributeTableOfInteger::SetRow(int theRow, const std::vector<int>& theData)
234 {
235   CheckLocked();
236   int aLength = theData.size(), i;
237   if(_isLocal) {
238     Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable;
239     aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl);
240     Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
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::AttributeTableOfInteger::IncorrectArgumentLength();
247     }
248   }
249   else {
250     SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq();
251     aSeq->length(aLength);
252     for(i = 0; i < aLength; i++) aSeq[i] = theData[i];
253     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRow(theRow, aSeq);
254   }
255 }
256
257 std::vector<int> SALOMEDS_AttributeTableOfInteger::GetRow(int theRow)
258 {
259   std::vector<int> aVector;
260   int aLength, i;
261   if(_isLocal) {
262     Handle(TColStd_HSequenceOfInteger) aRow; 
263     aRow = Handle(SALOMEDSImpl_AttributeTableOfInteger)::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::LongSeq_var aRow = SALOMEDS::AttributeTableOfInteger::_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_AttributeTableOfInteger::AddColumn(const std::vector<int>& theData)
276 {
277   CheckLocked();
278   int aLength = theData.size(), i;
279   if(_isLocal) {
280     Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable;
281     aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl);
282     Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
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::AttributeTableOfInteger::IncorrectArgumentLength();
289     }
290   }
291   else {
292     SALOMEDS::LongSeq_var aColumn = new SALOMEDS::LongSeq();
293     aColumn->length(aLength);
294     for(i = 0; i < aLength; i++) aColumn[i] = theData[i];
295     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->AddColumn(aColumn);
296   }
297 }
298
299 void SALOMEDS_AttributeTableOfInteger::SetColumn(int theColumn, const std::vector<int>& theData)
300 {
301   CheckLocked();
302   int aLength = theData.size(), i;
303   if(_isLocal) {
304     Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable;
305     aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl);
306     Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
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::AttributeTableOfInteger::IncorrectArgumentLength();
313     }
314   }
315   else {
316     SALOMEDS::LongSeq_var aColumn = new SALOMEDS::LongSeq();
317     aColumn->length(aLength);
318     for(i = 0; i < aLength; i++) aColumn[i] = theData[i];
319     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRow(theColumn, aColumn);
320   }
321 }
322
323 std::vector<int> SALOMEDS_AttributeTableOfInteger::GetColumn(int theColumn)
324 {
325   std::vector<int> aVector;
326   int aLength, i;
327   if(_isLocal) {
328     Handle(TColStd_HSequenceOfInteger) aColumn; 
329     aColumn = Handle(SALOMEDSImpl_AttributeTableOfInteger)::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::LongSeq_var aColumn = SALOMEDS::AttributeTableOfInteger::_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_AttributeTableOfInteger::PutValue(int theValue, int theRow, int theColumn)
341 {
342   CheckLocked();
343   if(_isLocal) {
344     try {
345       Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->PutValue(theValue, theRow, theColumn);
346     }   
347     catch(...) {
348       throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
349     }
350   }
351   else {
352     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->PutValue(theValue, theRow, theColumn);
353   }
354 }
355
356 bool SALOMEDS_AttributeTableOfInteger::HasValue(int theRow, int theColumn)
357 {
358   bool ret;
359   if(_isLocal) ret = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->HasValue(theRow, theColumn);
360   else ret = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->HasValue(theRow, theColumn);
361   return ret;
362 }
363
364 int SALOMEDS_AttributeTableOfInteger::GetValue(int theRow, int theColumn)
365 {
366   int aValue;
367   if(_isLocal) {
368     try {
369       aValue = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetValue(theRow, theColumn);
370     }   
371     catch(...) {
372       throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
373     }
374   }
375   else {
376     aValue = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetValue(theRow, theColumn);
377   }
378   return aValue;
379 }
380
381 std::vector<int> SALOMEDS_AttributeTableOfInteger::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_AttributeTableOfInteger)::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::AttributeTableOfInteger::_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_AttributeTableOfInteger::SetNbColumns(int theNbColumns)
399 {
400   if(_isLocal) Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetNbColumns(theNbColumns);
401   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetNbColumns(theNbColumns);
402 }