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