Salome HOME
0020523: String notebook support
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfReal_i.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SALOMEDS_AttributeTableOfReal_i.cxx
23 //  Author : Sergey RUIN
24 //  Module : SALOME
25 //
26 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
27 #include "SALOMEDS.hxx"
28
29 #include <sstream>
30 #include <string>
31 #include <vector>
32
33 using namespace std;
34
35 #include "Utils_ExceptHandlers.hxx"
36 UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex);
37 UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength);
38
39 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle) 
40 {
41   SALOMEDS::Locker lock;     
42   CheckLocked();
43   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
44   CORBA::String_var aStr = CORBA::string_dup(theTitle);
45   aTable->SetTitle(string(aStr));
46 }
47
48 char* SALOMEDS_AttributeTableOfReal_i::GetTitle() 
49 {
50   SALOMEDS::Locker lock; 
51   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
52   CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
53   return c_s._retn();
54 }
55
56 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
57      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
58 {
59   SALOMEDS::Locker lock; 
60   Unexpect aCatch (ATR_IncorrectIndex);
61   CheckLocked();
62   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
63   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
64   aTable->SetRowTitle(theIndex, string(theTitle));
65 }
66
67 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
68      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
69 {
70   SALOMEDS::Locker lock; 
71   Unexpect aCatch (ATR_IncorrectArgumentLength);
72   CheckLocked();
73   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
74   if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
75   for (int i = 0; i < theTitles.length(); i++) {
76     aTable->SetRowTitle(i + 1, (char*)theTitles[i].in());
77   }
78 }
79
80 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles() 
81 {
82   SALOMEDS::Locker lock; 
83   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
84   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
85   aTitles->length(aTable->GetNbRows());
86   for(int i = 0; i < aTitles->length(); i++)
87     aTitles[i] = CORBA::string_dup(aTable->GetRowTitle(i + 1).c_str());
88   return aTitles._retn();
89 }
90
91 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
92      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
93 {
94   SALOMEDS::Locker lock; 
95   Unexpect aCatch (ATR_IncorrectIndex);
96   CheckLocked();
97   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
98   if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
99   CORBA::String_var aStr = CORBA::string_dup(theTitle);
100   aTable->SetColumnTitle(theIndex, string(aStr));
101 }
102
103 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
104      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
105 {
106   SALOMEDS::Locker lock; 
107   Unexpect aCatch(ATR_IncorrectArgumentLength);
108   CheckLocked();
109   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
110   if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
111   for (int i = 0; i < theTitles.length(); i++) {
112     aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
113   }
114 }
115
116 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles() 
117 {
118   SALOMEDS::Locker lock; 
119   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
120   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
121   aTitles->length(aTable->GetNbColumns());
122   for(int i = 0; i < aTitles->length(); i++)
123     aTitles[i] = CORBA::string_dup(aTable->GetColumnTitle(i + 1).c_str());
124   return aTitles._retn();
125 }
126
127 //Units support
128 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
129      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
130 {
131   SALOMEDS::Locker lock; 
132   Unexpect aCatch (ATR_IncorrectIndex);
133   CheckLocked();
134   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
135   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
136   aTable->SetRowUnit(theIndex, string(theUnit));
137 }
138
139 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
141 {
142   SALOMEDS::Locker lock; 
143   Unexpect aCatch (ATR_IncorrectArgumentLength);
144   CheckLocked();
145   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
146   if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
147   for (int i = 0; i < theUnits.length(); i++) {
148     aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
149   }
150 }
151
152 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits() 
153 {
154   SALOMEDS::Locker lock; 
155   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
156   SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
157   aUnits->length(aTable->GetNbRows());
158   for(int i = 0; i < aUnits->length(); i++)
159     aUnits[i] = CORBA::string_dup(aTable->GetRowUnit(i + 1).c_str());
160   return aUnits._retn();
161 }
162
163
164 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows() 
165 {
166   SALOMEDS::Locker lock; 
167   return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->GetNbRows();
168 }
169
170 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns() 
171 {
172   SALOMEDS::Locker lock; 
173   return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->GetNbColumns();
174 }
175
176 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
177      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
178 {
179   SALOMEDS::Locker lock; 
180   Unexpect aCatch(ATR_IncorrectArgumentLength);
181   CheckLocked();
182   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
183   
184   vector<double> aRow;
185   for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
186   aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
187 }
188
189 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
190      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
191 {
192   SALOMEDS::Locker lock; 
193   Unexpect aCatch(ATR_IncorrectArgumentLength);
194   CheckLocked();
195   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
196   
197   vector<double> aRow;
198   for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
199   aTable->SetRowData(theRow, aRow);
200 }
201
202 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
203      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
204 {
205   SALOMEDS::Locker lock; 
206   Unexpect aCatch(ATR_IncorrectIndex);
207   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
208   if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
209
210   SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
211   vector<double> aRow = aTable->GetRowData(theRow);
212   CorbaSeq->length(aRow.size());
213   for (int i = 0; i < aRow.size(); i++) {
214     CorbaSeq[i] = aRow[i];
215   }
216   return CorbaSeq._retn();
217 }
218
219 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
220      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
221 {
222   SALOMEDS::Locker lock; 
223   Unexpect aCatch(ATR_IncorrectArgumentLength);
224   CheckLocked();
225   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
226   
227   vector<double> aColumn;
228   for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
229   aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
230 }
231
232 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
233      throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
234 {
235   SALOMEDS::Locker lock; 
236   Unexpect aCatch(ATR_IncorrectArgumentLength);
237   CheckLocked();
238   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
239   
240   vector<double> aColumn;
241   for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
242   aTable->SetColumnData(theColumn, aColumn);
243 }
244
245 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
246      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
247 {
248   SALOMEDS::Locker lock; 
249   Unexpect aCatch(ATR_IncorrectIndex);
250   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
251   if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
252
253   SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
254   vector<double> aColumn = aTable->GetColumnData(theColumn);
255   CorbaSeq->length(aColumn.size());
256   for (int i = 0; i < aColumn.size(); i++) {
257     CorbaSeq[i] = aColumn[i];
258   }
259   return CorbaSeq._retn();
260 }
261
262 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
263      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
264 {
265   SALOMEDS::Locker lock; 
266   Unexpect aCatch(ATR_IncorrectIndex);
267   CheckLocked();
268   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
269
270   aTable->PutValue(theValue, theRow, theColumn);
271 }
272
273 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) 
274 {
275   SALOMEDS::Locker lock; 
276   return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->HasValue(theRow, theColumn);
277 }
278
279 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
280      throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
281 {
282   SALOMEDS::Locker lock; 
283   Unexpect aCatch(ATR_IncorrectIndex);
284   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
285   if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
286
287   CORBA::Double aValue;
288
289   try {
290     aValue = aTable->GetValue(theRow, theColumn);
291   }
292   catch(...) {
293     throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
294   }
295
296   return aValue;
297 }
298
299
300 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow) 
301 {
302   SALOMEDS::Locker lock; 
303   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
304
305   if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
306
307   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
308   vector<int> aSeq = aTable->GetSetRowIndices(theRow);
309   int len = aSeq.size();
310   CorbaSeq->length(len);
311   for (int i = 0; i < len; i++) {
312     CorbaSeq[i] = aSeq[i];
313   }
314   return CorbaSeq._retn(); 
315 }
316
317
318 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
319 {
320   SALOMEDS::Locker lock; 
321   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
322   aTable->SetNbColumns(theNbColumns);
323 }
324
325 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream) 
326 {
327   SALOMEDS::Locker lock; 
328   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
329
330   string aStream((char*)&theStream[0], theStream.length());
331   aTable->Load(aStream);
332   return true;
333 }
334
335 SALOMEDS::TMPFile*  SALOMEDS_AttributeTableOfReal_i::SaveToFile()
336 {
337   SALOMEDS::Locker lock; 
338   SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
339
340   string aString = aTable->Save();
341   char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
342   int aBufferSize = strlen((char*)aBuffer);
343
344   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
345
346   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
347
348   return aStreamFile._retn();
349 }