Salome HOME
This commit was generated by cvs2git to create branch 'WPdev'.
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfReal_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/
19 //
20 //  File   : SALOMEDS_AttributeTableOfReal_i.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24
25 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
26 #include "SALOMEDS.hxx"
27
28 #include <TColStd_HSequenceOfReal.hxx>
29 #include <Standard_Failure.hxx>
30 #include <Standard_ErrorHandler.hxx>
31
32 #include <strstream>
33 #include <string>
34
35 using namespace std;
36
37 #include "Utils_ExceptHandlers.hxx"
38 UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex);
39 UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength);
40
41 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle) 
42 {
43   SALOMEDS::Locker lock;     
44   CheckLocked();
45   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
46   CORBA::String_var aStr = CORBA::string_dup(theTitle);
47   aTable->SetTitle(TCollection_ExtendedString(aStr));
48 }
49
50 char* SALOMEDS_AttributeTableOfReal_i::GetTitle() 
51 {
52   SALOMEDS::Locker lock; 
53   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::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_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
59      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
60 {
61   SALOMEDS::Locker lock; 
62   Unexpect aCatch (ATR_IncorrectIndex);
63   CheckLocked();
64   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
65   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
66   aTable->SetRowTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
67 }
68
69 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
70      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
71 {
72   SALOMEDS::Locker lock; 
73   Unexpect aCatch (ATR_IncorrectArgumentLength);
74   CheckLocked();
75   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
76   if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
77   for (int i = 0; i < theTitles.length(); i++) {
78     aTable->SetRowTitle(i + 1, (char*)theTitles[i].in());
79   }
80 }
81
82 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles() 
83 {
84   SALOMEDS::Locker lock; 
85   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::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_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
94      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
95 {
96   SALOMEDS::Locker lock; 
97   Unexpect aCatch (ATR_IncorrectIndex);
98   CheckLocked();
99   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
100   if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
101   CORBA::String_var aStr = CORBA::string_dup(theTitle);
102   aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
103 }
104
105 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
106      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
107 {
108   SALOMEDS::Locker lock; 
109   Unexpect aCatch(ATR_IncorrectArgumentLength);
110   CheckLocked();
111   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
112   if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::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_AttributeTableOfReal_i::GetColumnTitles() 
119 {
120   SALOMEDS::Locker lock; 
121   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::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_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
131      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
132 {
133   SALOMEDS::Locker lock; 
134   Unexpect aCatch (ATR_IncorrectIndex);
135   CheckLocked();
136   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
137   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
138   aTable->SetRowUnit(theIndex, TCollection_ExtendedString((char*)theUnit));
139 }
140
141 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
142      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
143 {
144   SALOMEDS::Locker lock; 
145   Unexpect aCatch (ATR_IncorrectArgumentLength);
146   CheckLocked();
147   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
148   if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::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_AttributeTableOfReal_i::GetRowUnits() 
155 {
156   SALOMEDS::Locker lock; 
157   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::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
166 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows() 
167 {
168   SALOMEDS::Locker lock; 
169   return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->GetNbRows();
170 }
171
172 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns() 
173 {
174   SALOMEDS::Locker lock; 
175   return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->GetNbColumns();
176 }
177
178 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
179      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
180 {
181   SALOMEDS::Locker lock; 
182   Unexpect aCatch(ATR_IncorrectArgumentLength);
183   CheckLocked();
184   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
185   
186   Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
187   for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
188   aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
189 }
190
191 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
192      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
193 {
194   SALOMEDS::Locker lock; 
195   Unexpect aCatch(ATR_IncorrectArgumentLength);
196   CheckLocked();
197   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
198   
199   Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
200   for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
201   aTable->SetRowData(theRow, aRow);
202 }
203
204 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
205      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
206 {
207   SALOMEDS::Locker lock; 
208   Unexpect aCatch(ATR_IncorrectIndex);
209   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
210   if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
211
212   SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
213   Handle(TColStd_HSequenceOfReal) aRow = aTable->GetRowData(theRow);
214   CorbaSeq->length(aRow->Length());
215   for (int i = 0; i < aRow->Length(); i++) {
216     CorbaSeq[i] = aRow->Value(i + 1);
217   }
218   return CorbaSeq._retn();
219 }
220
221 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
222      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
223 {
224   SALOMEDS::Locker lock; 
225   Unexpect aCatch(ATR_IncorrectArgumentLength);
226   CheckLocked();
227   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
228   
229   Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
230   for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
231   aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
232 }
233
234 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
235      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
236 {
237   SALOMEDS::Locker lock; 
238   Unexpect aCatch(ATR_IncorrectArgumentLength);
239   CheckLocked();
240   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
241   
242   Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
243   for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
244   aTable->SetColumnData(theColumn, aColumn);
245 }
246
247 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
248      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
249 {
250   SALOMEDS::Locker lock; 
251   Unexpect aCatch(ATR_IncorrectIndex);
252   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
253   if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
254
255   SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
256   Handle(TColStd_HSequenceOfReal) aColumn = aTable->GetColumnData(theColumn);
257   CorbaSeq->length(aColumn->Length());
258   for (int i = 0; i < aColumn->Length(); i++) {
259     CorbaSeq[i] = aColumn->Value(i + 1);
260   }
261   return CorbaSeq._retn();
262 }
263
264 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
265      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
266 {
267   SALOMEDS::Locker lock; 
268   Unexpect aCatch(ATR_IncorrectIndex);
269   CheckLocked();
270   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
271
272   aTable->PutValue(theValue, theRow, theColumn);
273 }
274
275 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) 
276 {
277   SALOMEDS::Locker lock; 
278   return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->HasValue(theRow, theColumn);
279 }
280
281 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
282      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
283 {
284   SALOMEDS::Locker lock; 
285   Unexpect aCatch(ATR_IncorrectIndex);
286   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
287   if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
288
289   CORBA::Double aValue;
290
291   try {
292     aValue = aTable->GetValue(theRow, theColumn);
293   }
294   catch(Standard_Failure) {
295     throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
296   }
297
298   return aValue;
299 }
300
301
302 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow) 
303 {
304   SALOMEDS::Locker lock; 
305   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
306
307   if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
308
309   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
310   Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
311   CorbaSeq->length(aSeq->Length());
312   for (int i = 0; i < aSeq->Length(); i++) {
313     CorbaSeq[i] = aSeq->Value(i + 1);
314   }
315   return CorbaSeq._retn(); 
316 }
317
318
319 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
320 {
321   SALOMEDS::Locker lock; 
322   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
323   aTable->SetNbColumns(theNbColumns);
324 }
325
326 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream) 
327 {
328   SALOMEDS::Locker lock; 
329   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
330
331   istrstream aStream((char*)&theStream[0], theStream.length());
332   return aTable->RestoreFromString(aStream);
333 }
334
335 SALOMEDS::TMPFile*  SALOMEDS_AttributeTableOfReal_i::SaveToFile()
336 {
337   SALOMEDS::Locker lock; 
338   Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
339
340   ostrstream ostr;
341   string aString;
342   aTable->ConvertToString(ostr);
343
344   aString = ostr.rdbuf()->str();
345
346   char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
347   int aBufferSize = strlen((char*)aBuffer);
348
349   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
350
351   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
352
353   return aStreamFile._retn();
354 }