]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.cxx
Salome HOME
sources v1.2
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_AttributeTableOfInteger_i.cxx
1 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
2 //
3 //  Copyright (C) 2003  CEA/DEN, EDF R&D
4 //
5 //
6 //
7 //  File   : SALOMEDS_AttributeTableOfInteger_i.cxx
8 //  Author : Michael Ponikarov
9 //  Module : SALOME
10 //  $Header$
11
12 using namespace std;
13 #include "SALOMEDS_AttributeTableOfInteger_i.hxx"
14 #include "SALOMEDS_SObject_i.hxx"
15 #include <TColStd_HSequenceOfInteger.hxx>
16 #include <Standard_Failure.hxx>
17 #include <Standard_ErrorHandler.hxx>
18
19 #include <strstream>
20 #include <string>
21
22 #define SEPARATOR '\1'
23
24 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
25 {
26   TCollection_ExtendedString aString(theString);
27   int aPos = aString.Search(SEPARATOR);
28   if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
29   return aString.Split(aPos);
30 }
31
32 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
33 {
34   TCollection_ExtendedString aString(theString);
35   int aPos = aString.Search(SEPARATOR);
36   if(aPos < 1) return aString;
37   if(aPos == 1) return TCollection_ExtendedString();
38   aString.Split(aPos-1);
39   return aString;
40 }
41
42
43
44 void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) {
45   CheckLocked();
46   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
47   CORBA::String_var aStr = CORBA::string_dup(theTitle);
48   aTable->SetTitle(TCollection_ExtendedString(aStr));
49 }
50
51 char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() {
52   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
53   CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
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   CheckLocked();
61   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
62   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
63   CORBA::String_var aStr = CORBA::string_dup(theTitle);
64   TCollection_ExtendedString aTitle(aStr);
65   TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
66   if(aUnit.Length() > 0) {
67     aTitle += SEPARATOR;
68     aTitle += aUnit;
69   }
70
71   aTable->SetRowTitle(theIndex, aTitle);
72 }
73
74 void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
75      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
76 {
77   CheckLocked();
78   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
79   if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
80   for (int i = 0; i < theTitles.length(); i++) {
81     SetRowTitle(i + 1, theTitles[i]);
82   }
83 }
84
85 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() {
86   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
87   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
88   aTitles->length(aTable->GetNbRows());
89   for(int i = 0; i < aTitles->length(); i++)
90     aTitles[i] = CORBA::string_dup(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
91   return aTitles._retn();
92 }
93
94 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
95      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
96 {
97   CheckLocked();
98   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
99   if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
100   CORBA::String_var aStr = CORBA::string_dup(theTitle);
101   aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
102 }
103
104 void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
105      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
106 {
107   CheckLocked();
108   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
109   if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
110   for (int i = 0; i < theTitles.length(); i++) {
111     SetColumnTitle(i + 1, theTitles[i]);
112   }
113 }
114
115 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() {
116   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
117   SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
118   aTitles->length(aTable->GetNbColumns());
119   for(int i = 0; i < aTitles->length(); i++)
120     aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
121   return aTitles._retn();
122 }
123
124 //Units support
125 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
126      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
127 {
128   CheckLocked();
129   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
130   if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
131   CORBA::String_var aStr = CORBA::string_dup(theUnit);
132   TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
133   TCollection_ExtendedString aUnit(aStr);
134   aTitle += SEPARATOR;
135   aTitle += aUnit;
136   aTable->SetRowTitle(theIndex, aTitle);
137 }
138
139 void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
141 {
142   CheckLocked();
143   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
144   if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
145   for (int i = 0; i < theUnits.length(); i++) {
146     SetRowUnit(i + 1, theUnits[i]);
147   }
148 }
149
150 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowUnits() {
151   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
152   SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
153   aUnits->length(aTable->GetNbRows());
154   for(int i = 0; i < aUnits->length(); i++)
155     aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
156   return aUnits._retn();
157 }
158
159 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbRows() {
160   return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbRows();
161 }
162 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() {
163   return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->GetNbColumns();
164 }
165
166 void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData)
167      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
168 {
169   CheckLocked();
170   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
171   
172   Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
173   for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
174   try {
175     aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
176   }
177   catch(Standard_Failure) {
178     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
179   }
180 }
181
182 void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData)
183      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
184 {
185   CheckLocked();
186   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
187   
188   Handle(TColStd_HSequenceOfInteger) aRow = new TColStd_HSequenceOfInteger;
189   for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
190   try {
191     aTable->SetRowData(theRow, aRow);
192   }
193   catch(Standard_Failure) {
194     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
195   }  
196 }
197
198 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow)
199      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
200 {
201   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
202   if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
203
204   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
205   Handle(TColStd_HSequenceOfInteger) aRow = aTable->GetRowData(theRow);
206   CorbaSeq->length(aRow->Length());
207   for (int i = 0; i < aRow->Length(); i++) {
208     CorbaSeq[i] = aRow->Value(i + 1);
209   }
210   return CorbaSeq._retn();
211 }
212
213 void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData)
214      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength)
215 {
216   CheckLocked();
217   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
218   
219   Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
220   for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
221   try {
222     aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
223   }
224   catch(Standard_Failure) {
225     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
226   }  
227 }
228
229 void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData)
230      throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
231 {
232   CheckLocked();
233   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
234   
235   Handle(TColStd_HSequenceOfInteger) aColumn = new TColStd_HSequenceOfInteger;
236   for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
237   try {
238     aTable->SetColumnData(theColumn, aColumn);
239   }
240   catch(Standard_Failure) {
241     throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength();
242   }
243 }
244
245 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn)
246      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
247 {
248   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
249   if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
250
251   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
252   Handle(TColStd_HSequenceOfInteger) aColumn = aTable->GetColumnData(theColumn);
253   CorbaSeq->length(aColumn->Length());
254   for (int i = 0; i < aColumn->Length(); i++) {
255     CorbaSeq[i] = aColumn->Value(i + 1);
256   }
257   return CorbaSeq._retn();
258 }
259
260 void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn)
261      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
262 {
263   CheckLocked();
264   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
265
266   try {
267     aTable->PutValue(theValue, theRow, theColumn);
268   }
269   catch(Standard_Failure) {
270     throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
271   }
272 }
273
274 CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
275   return Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
276 }
277
278 CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
279      throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex)
280 {
281   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
282   if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
283
284   CORBA::Long aValue;
285   try {
286     aValue = aTable->GetValue(theRow, theColumn);
287   }
288   catch(Standard_Failure) {
289     throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
290   }
291   return aValue;
292 }
293
294 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow) 
295 {
296   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
297
298   if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex();
299
300   SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
301   Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
302   CorbaSeq->length(aSeq->Length());
303   for (int i = 0; i < aSeq->Length(); i++) {
304     CorbaSeq[i] = aSeq->Value(i + 1);
305   }
306   return CorbaSeq._retn(); 
307 }
308
309
310 void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns)
311 {
312   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
313   aTable->SetNbColumns(theNbColumns);
314 }
315
316 bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& theStream) 
317 {
318   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
319
320   istrstream aStream((char*)&theStream[0], theStream.length());
321   return aTable->RestoreFromString(aStream);
322 }
323
324 SALOMEDS::TMPFile*  SALOMEDS_AttributeTableOfInteger_i::SaveToFile()
325 {
326   Handle(SALOMEDS_TableOfIntegerAttribute) aTable = Handle(SALOMEDS_TableOfIntegerAttribute)::DownCast(_myAttr);
327
328   ostrstream ostr;
329   string aString;
330   aTable->ConvertToString(ostr);
331
332   aString = ostr.rdbuf()->str();
333
334   char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
335   int aBufferSize = strlen((char*)aBuffer);
336
337   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
338
339   SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
340
341   return aStreamFile._retn();
342 }
343