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