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