1 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
3 // Copyright (C) 2003 CEA/DEN, EDF R&D
7 // File : SALOMEDS_AttributeTableOfReal_i.cxx
8 // Author : Michael Ponikarov
12 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
13 #include "SALOMEDS.hxx"
15 #include <TColStd_HSequenceOfReal.hxx>
16 #include <TCollection_AsciiString.hxx>
17 #include <Standard_Failure.hxx>
22 #include "Utils_ExceptHandlers.hxx"
23 UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex);
24 UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength);
26 #define SEPARATOR '\1'
30 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
32 TCollection_ExtendedString aString(theString);
33 int aPos = aString.Search(SEPARATOR);
34 if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
35 return aString.Split(aPos);
38 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
40 TCollection_ExtendedString aString(theString);
41 int aPos = aString.Search(SEPARATOR);
42 if(aPos < 1) return aString;
43 if(aPos == 1) return TCollection_ExtendedString();
44 aString.Split(aPos-1);
48 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle) {
49 SALOMEDS::Locker lock;
52 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
53 CORBA::String_var aStr = CORBA::string_dup(theTitle);
54 aTable->SetTitle(TCollection_ExtendedString(aStr));
57 char* SALOMEDS_AttributeTableOfReal_i::GetTitle() {
58 SALOMEDS::Locker lock;
60 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
61 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
65 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
66 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
68 SALOMEDS::Locker lock;
70 Unexpect aCatch (ATR_IncorrectIndex);
72 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
73 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
74 CORBA::String_var aStr = CORBA::string_dup(theTitle);
75 TCollection_ExtendedString aTitle(aStr);
76 TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
77 if(aUnit.Length() > 0) {
82 aTable->SetRowTitle(theIndex, aTitle);
85 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
86 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
88 SALOMEDS::Locker lock;
90 Unexpect aCatch (ATR_IncorrectArgumentLength);
92 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
93 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
94 for (int i = 0; i < theTitles.length(); i++) {
95 SetRowTitle(i + 1, theTitles[i]);
99 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles() {
100 SALOMEDS::Locker lock;
102 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
103 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
104 aTitles->length(aTable->GetNbRows());
105 for(int i = 0; i < aTitles->length(); i++)
106 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
107 return aTitles._retn();
110 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
111 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
113 SALOMEDS::Locker lock;
115 Unexpect aCatch (ATR_IncorrectIndex);
117 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
118 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
119 CORBA::String_var aStr = CORBA::string_dup(theTitle);
120 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
123 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
124 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
126 SALOMEDS::Locker lock;
128 Unexpect aCatch(ATR_IncorrectArgumentLength);
130 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
131 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
132 for (int i = 0; i < theTitles.length(); i++) {
133 SetColumnTitle(i + 1, theTitles[i]);
137 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles() {
138 SALOMEDS::Locker lock;
140 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
141 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
142 aTitles->length(aTable->GetNbColumns());
143 for(int i = 0; i < aTitles->length(); i++)
144 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
145 return aTitles._retn();
149 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
150 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
152 SALOMEDS::Locker lock;
154 Unexpect aCatch (ATR_IncorrectIndex);
156 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
157 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
158 CORBA::String_var aStr = CORBA::string_dup(theUnit);
159 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
160 TCollection_ExtendedString aUnit(aStr);
163 aTable->SetRowTitle(theIndex, aTitle);
166 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
167 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
169 SALOMEDS::Locker lock;
171 Unexpect aCatch (ATR_IncorrectArgumentLength);
173 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
174 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
175 for (int i = 0; i < theUnits.length(); i++) {
176 SetRowUnit(i + 1, theUnits[i]);
180 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits() {
181 SALOMEDS::Locker lock;
183 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
184 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
185 aUnits->length(aTable->GetNbRows());
186 for(int i = 0; i < aUnits->length(); i++)
187 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
188 return aUnits._retn();
192 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows() {
193 SALOMEDS::Locker lock;
195 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->GetNbRows();
197 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns() {
198 SALOMEDS::Locker lock;
200 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->GetNbColumns();
203 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
204 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
206 SALOMEDS::Locker lock;
208 Unexpect aCatch(ATR_IncorrectArgumentLength);
210 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
212 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
213 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
214 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
217 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
218 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
220 SALOMEDS::Locker lock;
222 Unexpect aCatch(ATR_IncorrectArgumentLength);
224 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
226 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
227 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
228 aTable->SetRowData(theRow, aRow);
231 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
232 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
234 SALOMEDS::Locker lock;
236 Unexpect aCatch(ATR_IncorrectIndex);
237 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
238 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
240 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
241 Handle(TColStd_HSequenceOfReal) aRow = aTable->GetRowData(theRow);
242 CorbaSeq->length(aRow->Length());
243 for (int i = 0; i < aRow->Length(); i++) {
244 CorbaSeq[i] = aRow->Value(i + 1);
246 return CorbaSeq._retn();
249 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
250 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
252 SALOMEDS::Locker lock;
254 Unexpect aCatch(ATR_IncorrectArgumentLength);
256 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
258 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
259 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
260 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
263 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
264 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
266 SALOMEDS::Locker lock;
268 Unexpect aCatch(ATR_IncorrectArgumentLength);
270 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
272 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
273 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
274 aTable->SetColumnData(theColumn, aColumn);
277 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
278 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
280 SALOMEDS::Locker lock;
282 Unexpect aCatch(ATR_IncorrectIndex);
283 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
284 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
286 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
287 Handle(TColStd_HSequenceOfReal) aColumn = aTable->GetColumnData(theColumn);
288 CorbaSeq->length(aColumn->Length());
289 for (int i = 0; i < aColumn->Length(); i++) {
290 CorbaSeq[i] = aColumn->Value(i + 1);
292 return CorbaSeq._retn();
295 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
296 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
298 SALOMEDS::Locker lock;
300 Unexpect aCatch(ATR_IncorrectIndex);
302 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
304 aTable->PutValue(theValue, theRow, theColumn);
307 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
308 SALOMEDS::Locker lock;
310 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
313 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
314 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
316 SALOMEDS::Locker lock;
318 Unexpect aCatch(ATR_IncorrectIndex);
319 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
320 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
322 CORBA::Double aValue;
325 aValue = aTable->GetValue(theRow, theColumn);
327 catch(Standard_Failure) {
328 throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
335 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow)
337 SALOMEDS::Locker lock;
339 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
341 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
343 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
344 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
345 CorbaSeq->length(aSeq->Length());
346 for (int i = 0; i < aSeq->Length(); i++) {
347 CorbaSeq[i] = aSeq->Value(i + 1);
349 return CorbaSeq._retn();
353 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
355 SALOMEDS::Locker lock;
357 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
358 aTable->SetNbColumns(theNbColumns);
361 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
363 SALOMEDS::Locker lock;
365 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
367 istrstream aStream((char*)&theStream[0], theStream.length());
368 return aTable->RestoreFromString(aStream);
371 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile()
373 SALOMEDS::Locker lock;
375 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
379 aTable->ConvertToString(ostr);
381 aString = ostr.rdbuf()->str();
383 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
384 int aBufferSize = strlen((char*)aBuffer);
386 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
388 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
390 return aStreamFile._retn();
393 char* SALOMEDS_AttributeTableOfReal_i::Store() {
394 SALOMEDS::Locker lock;
396 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
399 aTable->ConvertToString(ostr);
400 string aString = ostr.rdbuf()->str();
402 CORBA::String_var aBuffer = CORBA::string_dup(aString.c_str());
403 return aBuffer._retn();
406 void SALOMEDS_AttributeTableOfReal_i::Restore(const char* value) {
407 SALOMEDS::Locker lock;
409 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
411 istrstream aStream(value, strlen(value));
412 aTable->RestoreFromString(aStream);