1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDS_AttributeTableOfReal_i.cxx
21 // Author : Sergey RUIN
25 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
26 #include "SALOMEDS.hxx"
28 #include <TColStd_HSequenceOfReal.hxx>
29 #include <Standard_Failure.hxx>
30 #include <Standard_ErrorHandler.hxx>
37 #include "Utils_ExceptHandlers.hxx"
38 UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex);
39 UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength);
41 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle)
43 SALOMEDS::Locker lock;
45 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
46 CORBA::String_var aStr = CORBA::string_dup(theTitle);
47 aTable->SetTitle(TCollection_ExtendedString(aStr));
50 char* SALOMEDS_AttributeTableOfReal_i::GetTitle()
52 SALOMEDS::Locker lock;
53 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
54 CORBA::String_var c_s = CORBA::string_dup(TCollection_AsciiString(aTable->GetTitle()).ToCString());
58 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
59 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
61 SALOMEDS::Locker lock;
62 Unexpect aCatch (ATR_IncorrectIndex);
64 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
65 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
66 aTable->SetRowTitle(theIndex, TCollection_ExtendedString((char*)theTitle));
69 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
70 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
72 SALOMEDS::Locker lock;
73 Unexpect aCatch (ATR_IncorrectArgumentLength);
75 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
76 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
77 for (int i = 0; i < theTitles.length(); i++) {
78 aTable->SetRowTitle(i + 1, (char*)theTitles[i].in());
82 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles()
84 SALOMEDS::Locker lock;
85 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
86 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
87 aTitles->length(aTable->GetNbRows());
88 for(int i = 0; i < aTitles->length(); i++)
89 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowTitle(i + 1)).ToCString());
90 return aTitles._retn();
93 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
94 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
96 SALOMEDS::Locker lock;
97 Unexpect aCatch (ATR_IncorrectIndex);
99 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
100 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
101 CORBA::String_var aStr = CORBA::string_dup(theTitle);
102 aTable->SetColumnTitle(theIndex, TCollection_ExtendedString(aStr));
105 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
106 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
108 SALOMEDS::Locker lock;
109 Unexpect aCatch(ATR_IncorrectArgumentLength);
111 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
112 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
113 for (int i = 0; i < theTitles.length(); i++) {
114 aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
118 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles()
120 SALOMEDS::Locker lock;
121 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
122 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
123 aTitles->length(aTable->GetNbColumns());
124 for(int i = 0; i < aTitles->length(); i++)
125 aTitles[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetColumnTitle(i + 1)).ToCString());
126 return aTitles._retn();
130 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
131 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
133 SALOMEDS::Locker lock;
134 Unexpect aCatch (ATR_IncorrectIndex);
136 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
137 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
138 aTable->SetRowUnit(theIndex, TCollection_ExtendedString((char*)theUnit));
141 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
142 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
144 SALOMEDS::Locker lock;
145 Unexpect aCatch (ATR_IncorrectArgumentLength);
147 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
148 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
149 for (int i = 0; i < theUnits.length(); i++) {
150 aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
154 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits()
156 SALOMEDS::Locker lock;
157 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
158 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
159 aUnits->length(aTable->GetNbRows());
160 for(int i = 0; i < aUnits->length(); i++)
161 aUnits[i] = CORBA::string_dup(TCollection_AsciiString(aTable->GetRowUnit(i + 1)).ToCString());
162 return aUnits._retn();
166 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows()
168 SALOMEDS::Locker lock;
169 return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->GetNbRows();
172 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns()
174 SALOMEDS::Locker lock;
175 return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->GetNbColumns();
178 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
179 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
181 SALOMEDS::Locker lock;
182 Unexpect aCatch(ATR_IncorrectArgumentLength);
184 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
186 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
187 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
188 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
191 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
192 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
194 SALOMEDS::Locker lock;
195 Unexpect aCatch(ATR_IncorrectArgumentLength);
197 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
199 Handle(TColStd_HSequenceOfReal) aRow = new TColStd_HSequenceOfReal;
200 for (int i = 0; i < theData.length(); i++) aRow->Append(theData[i]);
201 aTable->SetRowData(theRow, aRow);
204 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
205 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
207 SALOMEDS::Locker lock;
208 Unexpect aCatch(ATR_IncorrectIndex);
209 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
210 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
212 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
213 Handle(TColStd_HSequenceOfReal) aRow = aTable->GetRowData(theRow);
214 CorbaSeq->length(aRow->Length());
215 for (int i = 0; i < aRow->Length(); i++) {
216 CorbaSeq[i] = aRow->Value(i + 1);
218 return CorbaSeq._retn();
221 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
222 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
224 SALOMEDS::Locker lock;
225 Unexpect aCatch(ATR_IncorrectArgumentLength);
227 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
229 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
230 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
231 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
234 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
235 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
237 SALOMEDS::Locker lock;
238 Unexpect aCatch(ATR_IncorrectArgumentLength);
240 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
242 Handle(TColStd_HSequenceOfReal) aColumn = new TColStd_HSequenceOfReal;
243 for (int i = 0; i < theData.length(); i++) aColumn->Append(theData[i]);
244 aTable->SetColumnData(theColumn, aColumn);
247 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
248 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
250 SALOMEDS::Locker lock;
251 Unexpect aCatch(ATR_IncorrectIndex);
252 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
253 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
255 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
256 Handle(TColStd_HSequenceOfReal) aColumn = aTable->GetColumnData(theColumn);
257 CorbaSeq->length(aColumn->Length());
258 for (int i = 0; i < aColumn->Length(); i++) {
259 CorbaSeq[i] = aColumn->Value(i + 1);
261 return CorbaSeq._retn();
264 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
265 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
267 SALOMEDS::Locker lock;
268 Unexpect aCatch(ATR_IncorrectIndex);
270 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
272 aTable->PutValue(theValue, theRow, theColumn);
275 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
277 SALOMEDS::Locker lock;
278 return Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl)->HasValue(theRow, theColumn);
281 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
282 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
284 SALOMEDS::Locker lock;
285 Unexpect aCatch(ATR_IncorrectIndex);
286 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
287 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
289 CORBA::Double aValue;
292 aValue = aTable->GetValue(theRow, theColumn);
294 catch(Standard_Failure) {
295 throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
302 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow)
304 SALOMEDS::Locker lock;
305 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
307 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
309 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
310 Handle(TColStd_HSequenceOfInteger) aSeq = aTable->GetSetRowIndices(theRow);
311 CorbaSeq->length(aSeq->Length());
312 for (int i = 0; i < aSeq->Length(); i++) {
313 CorbaSeq[i] = aSeq->Value(i + 1);
315 return CorbaSeq._retn();
319 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
321 SALOMEDS::Locker lock;
322 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
323 aTable->SetNbColumns(theNbColumns);
326 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
328 SALOMEDS::Locker lock;
329 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
331 istrstream aStream((char*)&theStream[0], theStream.length());
332 return aTable->RestoreFromString(aStream);
335 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile()
337 SALOMEDS::Locker lock;
338 Handle(SALOMEDSImpl_AttributeTableOfReal) aTable = Handle(SALOMEDSImpl_AttributeTableOfReal)::DownCast(_impl);
342 aTable->ConvertToString(ostr);
344 aString = ostr.rdbuf()->str();
346 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
347 int aBufferSize = strlen((char*)aBuffer);
349 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
351 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
353 return aStreamFile._retn();