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_SObject_i.hxx"
14 #include <TColStd_HSequenceOfReal.hxx>
15 #include <Standard_Failure.hxx>
16 #include <Standard_ErrorHandler.hxx>
21 #include "Utils_ExceptHandlers.hxx"
23 UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex);
24 UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength);
26 #define SEPARATOR '\1'
28 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
30 TCollection_ExtendedString aString(theString);
31 int aPos = aString.Search(SEPARATOR);
32 if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
33 return aString.Split(aPos);
36 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
38 TCollection_ExtendedString aString(theString);
39 int aPos = aString.Search(SEPARATOR);
40 if(aPos < 1) return aString;
41 if(aPos == 1) return TCollection_ExtendedString();
42 aString.Split(aPos-1);
48 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle) {
50 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
51 CORBA::String_var aStr = CORBA::string_dup(theTitle);
52 aTable->SetTitle(TCollection_ExtendedString(aStr));
55 char* SALOMEDS_AttributeTableOfReal_i::GetTitle() {
56 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
57 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
61 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
62 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
64 Unexpect aCatch (ATR_IncorrectIndex);
66 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
67 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
68 CORBA::String_var aStr = CORBA::string_dup(theTitle);
69 TCollection_ExtendedString aTitle(aStr);
70 TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
71 if(aUnit.Length() > 0) {
76 aTable->SetRowTitle(theIndex, aTitle);
79 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
80 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
82 Unexpect aCatch (ATR_IncorrectArgumentLength);
84 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
85 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
86 for (int i = 0; i < theTitles.length(); i++) {
87 SetRowTitle(i + 1, theTitles[i]);
91 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles() {
92 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
93 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
94 aTitles->length(aTable->GetNbRows());
95 for(int i = 0; i < aTitles->length(); i++)
96 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
97 return aTitles._retn();
100 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
101 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
103 Unexpect aCatch (ATR_IncorrectIndex);
105 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
106 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
107 CORBA::String_var aStr = CORBA::string_dup(theTitle);
108 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
111 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
112 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
114 Unexpect aCatch(ATR_IncorrectArgumentLength);
116 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
117 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
118 for (int i = 0; i < theTitles.length(); i++) {
119 SetColumnTitle(i + 1, theTitles[i]);
123 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles() {
124 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
125 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
126 aTitles->length(aTable->GetNbColumns());
127 for(int i = 0; i < aTitles->length(); i++)
128 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
129 return aTitles._retn();
133 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
134 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
136 Unexpect aCatch (ATR_IncorrectIndex);
138 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
139 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
140 CORBA::String_var aStr = CORBA::string_dup(theUnit);
141 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
142 TCollection_ExtendedString aUnit(aStr);
145 aTable->SetRowTitle(theIndex, aTitle);
148 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
149 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
151 Unexpect aCatch (ATR_IncorrectArgumentLength);
153 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
154 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
155 for (int i = 0; i < theUnits.length(); i++) {
156 SetRowUnit(i + 1, theUnits[i]);
160 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits() {
161 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
162 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
163 aUnits->length(aTable->GetNbRows());
164 for(int i = 0; i < aUnits->length(); i++)
165 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
166 return aUnits._retn();
170 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows() {
171 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->GetNbRows();
173 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns() {
174 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->GetNbColumns();
177 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
178 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
180 Unexpect aCatch(ATR_IncorrectArgumentLength);
182 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
184 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
185 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
186 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
189 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
190 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
192 Unexpect aCatch(ATR_IncorrectArgumentLength);
194 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
196 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
197 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
198 aTable->SetRowData(theRow, aRow);
201 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
202 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
204 Unexpect aCatch(ATR_IncorrectIndex);
205 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
206 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
208 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
209 Handle(TColStd_HSequenceOfReal) aRow = aTable->GetRowData(theRow);
210 CorbaSeq->length(aRow->Length());
211 for (int i = 0; i < aRow->Length(); i++) {
212 CorbaSeq[i] = aRow->Value(i + 1);
214 return CorbaSeq._retn();
217 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
218 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
220 Unexpect aCatch(ATR_IncorrectArgumentLength);
222 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
224 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
225 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
226 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
229 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
230 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
232 Unexpect aCatch(ATR_IncorrectArgumentLength);
234 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
236 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
237 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
238 aTable->SetColumnData(theColumn, aColumn);
241 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
242 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
244 Unexpect aCatch(ATR_IncorrectIndex);
245 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
246 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
248 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
249 Handle(TColStd_HSequenceOfReal) aColumn = aTable->GetColumnData(theColumn);
250 CorbaSeq->length(aColumn->Length());
251 for (int i = 0; i < aColumn->Length(); i++) {
252 CorbaSeq[i] = aColumn->Value(i + 1);
254 return CorbaSeq._retn();
257 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
258 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
260 Unexpect aCatch(ATR_IncorrectIndex);
262 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
264 aTable->PutValue(theValue, theRow, theColumn);
267 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
268 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
271 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
272 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
274 Unexpect aCatch(ATR_IncorrectIndex);
275 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
276 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
278 CORBA::Double aValue;
281 aValue = aTable->GetValue(theRow, theColumn);
283 catch(Standard_Failure) {
284 throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
291 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow)
293 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
295 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
297 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
298 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
299 CorbaSeq->length(aSeq->Length());
300 for (int i = 0; i < aSeq->Length(); i++) {
301 CorbaSeq[i] = aSeq->Value(i + 1);
303 return CorbaSeq._retn();
307 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
309 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
310 aTable->SetNbColumns(theNbColumns);
313 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
315 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
317 istrstream aStream((char*)&theStream[0], theStream.length());
318 return aTable->RestoreFromString(aStream);
321 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile()
323 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
327 aTable->ConvertToString(ostr);
329 aString = ostr.rdbuf()->str();
331 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
332 int aBufferSize = strlen((char*)aBuffer);
334 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
336 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
338 return aStreamFile._retn();
341 char* SALOMEDS_AttributeTableOfReal_i::Store() {
342 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
345 aTable->ConvertToString(ostr);
346 string aString = ostr.rdbuf()->str();
348 CORBA::String_var aBuffer = CORBA::string_dup(aString.c_str());
349 return aBuffer._retn();
352 void SALOMEDS_AttributeTableOfReal_i::Restore(const char* value) {
353 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
355 istrstream aStream(value, strlen(value));
356 aTable->RestoreFromString(aStream);