Salome HOME
Implemented method Modified() for SALOMEDS_Study that marks the Study as being modified.
[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/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDS_AttributeTableOfInteger.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24 #include "SALOMEDS_AttributeTableOfInteger.hxx"
25 #include "SALOMEDS.hxx"
26
27 #include <TCollection_AsciiString.hxx>
28 #include <TCollection_ExtendedString.hxx>
29 #include <TColStd_HSequenceOfInteger.hxx>
30 #include <TColStd_HSequenceOfExtendedString.hxx>
31
32
33 SALOMEDS_AttributeTableOfInteger::SALOMEDS_AttributeTableOfInteger
34                   (const Handle(SALOMEDSImpl_AttributeTableOfInteger)& theAttr)
35 :SALOMEDS_GenericAttribute(theAttr)
36 {}
37
38 SALOMEDS_AttributeTableOfInteger::SALOMEDS_AttributeTableOfInteger
39                   (SALOMEDS::AttributeTableOfInteger_ptr theAttr)
40 :SALOMEDS_GenericAttribute(theAttr)
41 {}
42
43 SALOMEDS_AttributeTableOfInteger::~SALOMEDS_AttributeTableOfInteger()
44 {}
45
46
47 void SALOMEDS_AttributeTableOfInteger::SetTitle(const std::string& theTitle)
48 {
49   if (_isLocal) {
50     CheckLocked();
51     SALOMEDS::Locker lock;
52     Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetTitle((char*)theTitle.c_str());
53   }
54   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetTitle(theTitle.c_str());
55 }
56
57 std::string SALOMEDS_AttributeTableOfInteger::GetTitle()
58 {
59   std::string aStr;
60   if (_isLocal) {
61     SALOMEDS::Locker lock;
62     aStr = TCollection_AsciiString(Handle(SALOMEDSImpl_AttributeTableOfInteger)::
63                                    DownCast(_local_impl)->GetTitle()).ToCString();
64   }
65   else aStr = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetTitle();
66   return aStr;
67 }
68
69 void SALOMEDS_AttributeTableOfInteger::SetRowTitle(int theIndex, const std::string& theTitle)
70 {
71   if (_isLocal) {
72     CheckLocked();
73     SALOMEDS::Locker lock;
74     Handle(SALOMEDSImpl_AttributeTableOfInteger)::
75       DownCast(_local_impl)->SetRowTitle(theIndex, (char*)theTitle.c_str());
76   }
77   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str());
78 }
79
80 void SALOMEDS_AttributeTableOfInteger::SetRowTitles(const std::vector<std::string>& theTitles)
81 {
82   int aLength = theTitles.size(), i;
83   if (_isLocal) {
84     CheckLocked();
85     SALOMEDS::Locker lock;
86     Handle(TColStd_HSequenceOfExtendedString) aSeq = new TColStd_HSequenceOfExtendedString;
87     for (i = 0; i < aLength; i++) aSeq->Append((char*)theTitles[i].c_str());
88     Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetRowTitles(aSeq);
89   }
90   else {
91     SALOMEDS::StringSeq_var aSeq = new SALOMEDS::StringSeq();
92     aSeq->length(aLength);
93     for(i = 0; i < aLength; i++) aSeq[i] = theTitles[i].c_str();
94     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowTitles(aSeq);
95   }
96   
97 }
98
99 std::vector<std::string> SALOMEDS_AttributeTableOfInteger::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_AttributeTableOfInteger)::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::AttributeTableOfInteger::_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_AttributeTableOfInteger::SetColumnTitle(int theIndex, const std::string& theTitle)
119 {
120   if (_isLocal) {
121     CheckLocked();
122     SALOMEDS::Locker lock;
123     Handle(SALOMEDSImpl_AttributeTableOfInteger)::
124       DownCast(_local_impl)->SetColumnTitle(theIndex, (char*)theTitle.c_str());
125   }
126   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str());
127 }
128
129 void SALOMEDS_AttributeTableOfInteger::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_AttributeTableOfInteger)::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] = theTitles[i].c_str();
143     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetColumnTitles(aSeq);
144   }
145 }
146
147 std::vector<std::string> SALOMEDS_AttributeTableOfInteger::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_AttributeTableOfInteger)::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::AttributeTableOfInteger::_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_AttributeTableOfInteger::SetRowUnit(int theIndex, const std::string& theUnit)
167 {
168   if (_isLocal) {
169     CheckLocked();
170     SALOMEDS::Locker lock;
171     Handle(SALOMEDSImpl_AttributeTableOfInteger)::
172       DownCast(_local_impl)->SetRowUnit(theIndex, (char*)theUnit.c_str());
173   }
174   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str());
175 }
176
177 void SALOMEDS_AttributeTableOfInteger::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_AttributeTableOfInteger)::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::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowUnits(aSeq);
192   }
193 }
194
195 std::vector<std::string> SALOMEDS_AttributeTableOfInteger::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_AttributeTableOfInteger)::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::AttributeTableOfInteger::_narrow(_corba_impl)->GetRowUnits();
208     aLength = aSeq->length();
209     for (i = 0; i < aLength; i++) aVector.push_back((char*)aSeq[i].in());
210   }
211   return aVector;
212 }
213
214 int SALOMEDS_AttributeTableOfInteger::GetNbRows()
215 {
216   int aNb;
217   if (_isLocal) {
218     SALOMEDS::Locker lock;
219     aNb = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetNbRows();
220   }
221   else aNb = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetNbRows();
222   return aNb;
223 }
224
225 int SALOMEDS_AttributeTableOfInteger::GetNbColumns()
226 {  
227   int aNb;
228   if (_isLocal) {
229     SALOMEDS::Locker lock;
230     aNb = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetNbColumns();
231   }
232   else aNb = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetNbColumns();
233   return aNb;
234   
235 }
236
237 void SALOMEDS_AttributeTableOfInteger::AddRow(const std::vector<int>& theData)
238 {
239   int aLength = theData.size(), i;
240   if (_isLocal) {
241     CheckLocked();
242     SALOMEDS::Locker lock;
243     Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable;
244     aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl);
245     Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
246     for (int i = 0; i < aLength; i++) aRow->Append(theData[i]);
247     try {
248       aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
249     }   
250     catch(...) {
251       throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
252     }
253   }
254   else {
255     SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq();
256     aSeq->length(aLength);
257     for(i = 0; i < aLength; i++) aSeq[i] = theData[i];
258     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->AddRow(aSeq);
259   }
260 }
261
262 void SALOMEDS_AttributeTableOfInteger::SetRow(int theRow, const std::vector<int>& theData)
263 {
264   int aLength = theData.size(), i;
265   if (_isLocal) {
266     CheckLocked();
267     SALOMEDS::Locker lock;
268     Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable;
269     aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl);
270     Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
271     for (int i = 0; i < aLength; i++) aRow->Append(theData[i]);
272     try {
273       aTable->SetRowData(theRow, aRow);
274     }   
275     catch(...) {
276       throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
277     }
278   }
279   else {
280     SALOMEDS::LongSeq_var aSeq = new SALOMEDS::LongSeq();
281     aSeq->length(aLength);
282     for (i = 0; i < aLength; i++) aSeq[i] = theData[i];
283     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRow(theRow, aSeq);
284   }
285 }
286
287 std::vector<int> SALOMEDS_AttributeTableOfInteger::GetRow(int theRow)
288 {
289   std::vector<int> aVector;
290   int aLength, i;
291   if (_isLocal) {
292     SALOMEDS::Locker lock;
293     Handle(TColStd_HSequenceOfInteger) aRow; 
294     aRow = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetRowData(theRow);
295     aLength = aRow->Length();
296     for (i = 1; i <= aLength; i++) aVector.push_back(aRow->Value(i));
297   }
298   else {
299     SALOMEDS::LongSeq_var aRow = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetRow(theRow);
300     aLength = aRow->length();
301     for (i = 0; i < aLength; i++) aVector.push_back(aRow[i]);
302   }
303
304   return aVector;
305 }
306
307 void SALOMEDS_AttributeTableOfInteger::AddColumn(const std::vector<int>& theData)
308 {
309   int aLength = theData.size(), i;
310   if (_isLocal) {
311     CheckLocked();
312     SALOMEDS::Locker lock;
313     Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable;
314     aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl);
315     Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
316     for (int i = 0; i < aLength; i++) aColumn->Append(theData[i]);
317     try {
318       aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
319     }   
320     catch(...) {
321       throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
322     }
323   }
324   else {
325     SALOMEDS::LongSeq_var aColumn = new SALOMEDS::LongSeq();
326     aColumn->length(aLength);
327     for(i = 0; i < aLength; i++) aColumn[i] = theData[i];
328     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->AddColumn(aColumn);
329   }
330 }
331
332 void SALOMEDS_AttributeTableOfInteger::SetColumn(int theColumn, const std::vector<int>& theData)
333 {
334   int aLength = theData.size(), i;
335   if (_isLocal) {
336     CheckLocked();
337     SALOMEDS::Locker lock;
338     Handle(SALOMEDSImpl_AttributeTableOfInteger) aTable;
339     aTable = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl);
340     Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
341     for (int i = 0; i < aLength; i++) aColumn->Append(theData[i]);
342     try {
343       aTable->SetColumnData(theColumn, aColumn);
344     }   
345     catch(...) {
346       throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
347     }
348   }
349   else {
350     SALOMEDS::LongSeq_var aColumn = new SALOMEDS::LongSeq();
351     aColumn->length(aLength);
352     for (i = 0; i < aLength; i++) aColumn[i] = theData[i];
353     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetColumn(theColumn, aColumn);
354   }
355 }
356
357 std::vector<int> SALOMEDS_AttributeTableOfInteger::GetColumn(int theColumn)
358 {
359   std::vector<int> aVector;
360   int aLength, i;
361   if (_isLocal) {
362     SALOMEDS::Locker lock;
363     Handle(TColStd_HSequenceOfInteger) aColumn; 
364     aColumn = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetColumnData(theColumn);
365     aLength = aColumn->Length();
366     for (i = 1; i <= aLength; i++) aVector.push_back(aColumn->Value(i));
367   }
368   else {
369     SALOMEDS::LongSeq_var aColumn = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetColumn(theColumn);
370     aLength = aColumn->length();
371     for (i = 0; i < aLength; i++) aVector.push_back(aColumn[i]);
372   }
373   return aVector;
374 }
375
376 void SALOMEDS_AttributeTableOfInteger::PutValue(int theValue, int theRow, int theColumn)
377 {
378   if (_isLocal) {
379     CheckLocked();
380     SALOMEDS::Locker lock;
381     try {
382       Handle(SALOMEDSImpl_AttributeTableOfInteger)::
383         DownCast(_local_impl)->PutValue(theValue, theRow, theColumn);
384     }
385     catch(...) {
386       throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
387     }
388   }
389   else {
390     SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->PutValue(theValue, theRow, theColumn);
391   }
392 }
393
394 bool SALOMEDS_AttributeTableOfInteger::HasValue(int theRow, int theColumn)
395 {
396   bool ret;
397   if (_isLocal) {
398     SALOMEDS::Locker lock;
399     ret = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->HasValue(theRow, theColumn);
400   }
401   else ret = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->HasValue(theRow, theColumn);
402   return ret;
403 }
404
405 int SALOMEDS_AttributeTableOfInteger::GetValue(int theRow, int theColumn)
406 {
407   int aValue;
408   if (_isLocal) {
409     SALOMEDS::Locker lock;
410     try {
411       aValue = Handle(SALOMEDSImpl_AttributeTableOfInteger)::
412         DownCast(_local_impl)->GetValue(theRow, theColumn);
413     }   
414     catch(...) {
415       throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
416     }
417   }
418   else {
419     aValue = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetValue(theRow, theColumn);
420   }
421   return aValue;
422 }
423
424 std::vector<int> SALOMEDS_AttributeTableOfInteger::GetRowSetIndices(int theRow)
425 {
426   std::vector<int> aVector;
427   int aLength, i;
428   if (_isLocal) {
429     SALOMEDS::Locker lock;
430     Handle(TColStd_HSequenceOfInteger) aSet; 
431     aSet = Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->GetSetRowIndices(theRow);
432     aLength = aSet->Length();
433     for (i = 1; i <= aLength; i++) aVector.push_back(aSet->Value(i));
434   }
435   else {
436     SALOMEDS::LongSeq_var aSet =
437       SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetRowSetIndices(theRow);
438     aLength = aSet->length();  
439     for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]);
440   }
441   return aVector;
442 }
443
444 void SALOMEDS_AttributeTableOfInteger::SetNbColumns(int theNbColumns)
445 {
446   if (_isLocal) {
447     SALOMEDS::Locker lock;
448     Handle(SALOMEDSImpl_AttributeTableOfInteger)::DownCast(_local_impl)->SetNbColumns(theNbColumns);
449   }
450   else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetNbColumns(theNbColumns);
451 }