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
13 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
14 #include "SALOMEDS_SObject_i.hxx"
15 #include <TColStd_HSequenceOfReal.hxx>
16 #include <Standard_Failure.hxx>
17 #include <Standard_ErrorHandler.hxx>
22 #define SEPARATOR '\1'
24 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
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);
32 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
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);
44 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle) {
46 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
47 CORBA::String_var aStr = CORBA::string_dup(theTitle);
48 aTable->SetTitle(TCollection_ExtendedString(aStr));
51 char* SALOMEDS_AttributeTableOfReal_i::GetTitle() {
52 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
53 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
57 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
58 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
61 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
62 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::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) {
71 aTable->SetRowTitle(theIndex, aTitle);
74 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
75 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
78 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
79 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
80 for (int i = 0; i < theTitles.length(); i++) {
81 SetRowTitle(i + 1, theTitles[i]);
85 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles() {
86 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::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();
94 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
95 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
98 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
99 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
100 CORBA::String_var aStr = CORBA::string_dup(theTitle);
101 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
104 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
105 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
108 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
109 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
110 for (int i = 0; i < theTitles.length(); i++) {
111 SetColumnTitle(i + 1, theTitles[i]);
115 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles() {
116 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::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();
125 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
126 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
129 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
130 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
131 CORBA::String_var aStr = CORBA::string_dup(theUnit);
132 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
133 TCollection_ExtendedString aUnit(aStr);
136 aTable->SetRowTitle(theIndex, aTitle);
139 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
143 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
144 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
145 for (int i = 0; i < theUnits.length(); i++) {
146 SetRowUnit(i + 1, theUnits[i]);
150 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits() {
151 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::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();
160 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows() {
161 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->GetNbRows();
163 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns() {
164 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->GetNbColumns();
167 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
168 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
171 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
173 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
174 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
175 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
178 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
179 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
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(theRow, aRow);
189 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
190 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
192 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
193 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
195 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
196 Handle(TColStd_HSequenceOfReal) aRow = aTable->GetRowData(theRow);
197 CorbaSeq->length(aRow->Length());
198 for (int i = 0; i < aRow->Length(); i++) {
199 CorbaSeq[i] = aRow->Value(i + 1);
201 return CorbaSeq._retn();
204 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
205 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
208 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
210 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
211 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
212 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
215 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
216 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
219 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
221 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
222 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
223 aTable->SetColumnData(theColumn, aColumn);
226 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
227 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
229 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
230 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
232 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
233 Handle(TColStd_HSequenceOfReal) aColumn = aTable->GetColumnData(theColumn);
234 CorbaSeq->length(aColumn->Length());
235 for (int i = 0; i < aColumn->Length(); i++) {
236 CorbaSeq[i] = aColumn->Value(i + 1);
238 return CorbaSeq._retn();
241 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
242 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
245 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
247 aTable->PutValue(theValue, theRow, theColumn);
250 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
251 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
254 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
255 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
257 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
258 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
260 CORBA::Double aValue;
263 aValue = aTable->GetValue(theRow, theColumn);
265 catch(Standard_Failure) {
266 throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
273 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow)
275 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
277 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
279 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
280 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
281 CorbaSeq->length(aSeq->Length());
282 for (int i = 0; i < aSeq->Length(); i++) {
283 CorbaSeq[i] = aSeq->Value(i + 1);
285 return CorbaSeq._retn();
289 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
291 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
292 aTable->SetNbColumns(theNbColumns);
295 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
297 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
299 istrstream aStream((char*)&theStream[0], theStream.length());
300 return aTable->RestoreFromString(aStream);
303 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile()
305 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
309 aTable->ConvertToString(ostr);
311 aString = ostr.rdbuf()->str();
313 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
314 int aBufferSize = strlen((char*)aBuffer);
316 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
318 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
320 return aStreamFile._retn();