2 // File : SALOMEDS_AttributeTableOfReal_i.cxx
3 // Created : Tue Oct 8 10:13:30 2002
4 // Author : Michael Ponikarov
7 // Copyright : Open CASCADE
11 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
12 #include "SALOMEDS_SObject_i.hxx"
13 #include <TColStd_HSequenceOfReal.hxx>
14 #include <Standard_Failure.hxx>
15 #include <Standard_ErrorHandler.hxx>
20 #define SEPARATOR '\1'
22 static TCollection_ExtendedString getUnit(TCollection_ExtendedString theString)
24 TCollection_ExtendedString aString(theString);
25 int aPos = aString.Search(SEPARATOR);
26 if(aPos <= 0 || aPos == aString.Length() ) return TCollection_ExtendedString();
27 return aString.Split(aPos);
30 static TCollection_ExtendedString getTitle(TCollection_ExtendedString theString)
32 TCollection_ExtendedString aString(theString);
33 int aPos = aString.Search(SEPARATOR);
34 if(aPos < 1) return aString;
35 if(aPos == 1) return TCollection_ExtendedString();
36 aString.Split(aPos-1);
42 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle) {
44 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
45 CORBA::String_var aStr = CORBA::string_dup(theTitle);
46 aTable->SetTitle(TCollection_ExtendedString(aStr));
49 char* SALOMEDS_AttributeTableOfReal_i::GetTitle() {
50 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
51 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
55 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
56 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
59 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
60 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
61 CORBA::String_var aStr = CORBA::string_dup(theTitle);
62 TCollection_ExtendedString aTitle(aStr);
63 TCollection_ExtendedString aUnit = getUnit(aTable->GetRowTitle(theIndex));
64 if(aUnit.Length() > 0) {
69 aTable->SetRowTitle(theIndex, aTitle);
72 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
73 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
76 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
77 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
78 for (int i = 0; i < theTitles.length(); i++) {
79 SetRowTitle(i + 1, theTitles[i]);
83 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles() {
84 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
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(TCollection_AsciiString(getTitle(aTable->GetRowTitle(i + 1))).ToCString());
89 return aTitles._retn();
92 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
93 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
96 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
97 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
98 CORBA::String_var aStr = CORBA::string_dup(theTitle);
99 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
102 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
103 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
106 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
107 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
108 for (int i = 0; i < theTitles.length(); i++) {
109 SetColumnTitle(i + 1, theTitles[i]);
113 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles() {
114 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
115 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
116 aTitles->length(aTable->GetNbColumns());
117 for(int i = 0; i < aTitles->length(); i++)
118 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
119 return aTitles._retn();
123 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
124 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
127 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
128 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
129 CORBA::String_var aStr = CORBA::string_dup(theUnit);
130 TCollection_ExtendedString aTitle = getTitle(aTable->GetRowTitle(theIndex));
131 TCollection_ExtendedString aUnit(aStr);
134 aTable->SetRowTitle(theIndex, aTitle);
137 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
138 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
141 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
142 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
143 for (int i = 0; i < theUnits.length(); i++) {
144 SetRowUnit(i + 1, theUnits[i]);
148 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits() {
149 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
150 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
151 aUnits->length(aTable->GetNbRows());
152 for(int i = 0; i < aUnits->length(); i++)
153 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(getUnit(aTable->GetRowTitle(i + 1))).ToCString());
154 return aUnits._retn();
158 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows() {
159 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->GetNbRows();
161 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns() {
162 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->GetNbColumns();
165 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
166 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
169 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
171 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
172 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
173 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
176 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
177 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
180 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
182 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
183 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
184 aTable->SetRowData(theRow, aRow);
187 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
188 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
190 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
191 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
193 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
194 Handle(TColStd_HSequenceOfReal) aRow = aTable->GetRowData(theRow);
195 CorbaSeq->length(aRow->Length());
196 for (int i = 0; i < aRow->Length(); i++) {
197 CorbaSeq[i] = aRow->Value(i + 1);
199 return CorbaSeq._retn();
202 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
203 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
206 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
208 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
209 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
210 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
213 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
214 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
217 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
219 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
220 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
221 aTable->SetColumnData(theColumn, aColumn);
224 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
225 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
227 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
228 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
230 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
231 Handle(TColStd_HSequenceOfReal) aColumn = aTable->GetColumnData(theColumn);
232 CorbaSeq->length(aColumn->Length());
233 for (int i = 0; i < aColumn->Length(); i++) {
234 CorbaSeq[i] = aColumn->Value(i + 1);
236 return CorbaSeq._retn();
239 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
240 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
243 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
245 aTable->PutValue(theValue, theRow, theColumn);
248 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn) {
249 return Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr)->HasValue(theRow, theColumn);
252 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
253 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
255 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
256 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
258 CORBA::Double aValue;
261 aValue = aTable->GetValue(theRow, theColumn);
263 catch(Standard_Failure) {
264 throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
271 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow)
273 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
275 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
277 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
278 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
279 CorbaSeq->length(aSeq->Length());
280 for (int i = 0; i < aSeq->Length(); i++) {
281 CorbaSeq[i] = aSeq->Value(i + 1);
283 return CorbaSeq._retn();
287 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
289 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
290 aTable->SetNbColumns(theNbColumns);
293 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
295 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
297 istrstream aStream((char*)&theStream[0], theStream.length());
298 return aTable->RestoreFromString(aStream);
301 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile()
303 Handle(SALOMEDS_TableOfRealAttribute) aTable = Handle(SALOMEDS_TableOfRealAttribute)::DownCast(_myAttr);
307 aTable->ConvertToString(ostr);
309 aString = ostr.rdbuf()->str();
311 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
312 int aBufferSize = strlen((char*)aBuffer);
314 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
316 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
318 return aStreamFile._retn();