1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SALOMEDS_AttributeTableOfReal_i.cxx
23 // Author : Sergey RUIN
26 #include "SALOMEDS_AttributeTableOfReal_i.hxx"
27 #include "SALOMEDS.hxx"
35 #include "Utils_ExceptHandlers.hxx"
36 UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex);
37 UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength);
39 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle)
41 SALOMEDS::Locker lock;
43 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
44 CORBA::String_var aStr = CORBA::string_dup(theTitle);
45 aTable->SetTitle(string(aStr));
48 char* SALOMEDS_AttributeTableOfReal_i::GetTitle()
50 SALOMEDS::Locker lock;
51 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
52 CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
56 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
57 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
59 SALOMEDS::Locker lock;
60 Unexpect aCatch (ATR_IncorrectIndex);
62 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
63 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
64 aTable->SetRowTitle(theIndex, string(theTitle));
67 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
68 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
70 SALOMEDS::Locker lock;
71 Unexpect aCatch (ATR_IncorrectArgumentLength);
73 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
74 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
75 for (int i = 0; i < theTitles.length(); i++) {
76 aTable->SetRowTitle(i + 1, (char*)theTitles[i].in());
80 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles()
82 SALOMEDS::Locker lock;
83 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
84 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
85 aTitles->length(aTable->GetNbRows());
86 for(int i = 0; i < aTitles->length(); i++)
87 aTitles[i] = CORBA::string_dup(aTable->GetRowTitle(i + 1).c_str());
88 return aTitles._retn();
91 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
92 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
94 SALOMEDS::Locker lock;
95 Unexpect aCatch (ATR_IncorrectIndex);
97 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
98 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
99 CORBA::String_var aStr = CORBA::string_dup(theTitle);
100 aTable->SetColumnTitle(theIndex, string(aStr));
103 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
104 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
106 SALOMEDS::Locker lock;
107 Unexpect aCatch(ATR_IncorrectArgumentLength);
109 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
110 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
111 for (int i = 0; i < theTitles.length(); i++) {
112 aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
116 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles()
118 SALOMEDS::Locker lock;
119 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
120 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
121 aTitles->length(aTable->GetNbColumns());
122 for(int i = 0; i < aTitles->length(); i++)
123 aTitles[i] = CORBA::string_dup(aTable->GetColumnTitle(i + 1).c_str());
124 return aTitles._retn();
128 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
129 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
131 SALOMEDS::Locker lock;
132 Unexpect aCatch (ATR_IncorrectIndex);
134 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
135 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
136 aTable->SetRowUnit(theIndex, string(theUnit));
139 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
140 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
142 SALOMEDS::Locker lock;
143 Unexpect aCatch (ATR_IncorrectArgumentLength);
145 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
146 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
147 for (int i = 0; i < theUnits.length(); i++) {
148 aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
152 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits()
154 SALOMEDS::Locker lock;
155 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
156 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
157 aUnits->length(aTable->GetNbRows());
158 for(int i = 0; i < aUnits->length(); i++)
159 aUnits[i] = CORBA::string_dup(aTable->GetRowUnit(i + 1).c_str());
160 return aUnits._retn();
164 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows()
166 SALOMEDS::Locker lock;
167 return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->GetNbRows();
170 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns()
172 SALOMEDS::Locker lock;
173 return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->GetNbColumns();
176 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
177 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
179 SALOMEDS::Locker lock;
180 Unexpect aCatch(ATR_IncorrectArgumentLength);
182 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
185 for (int i = 0; i < theData.length(); i++) aRow.push_back(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 SALOMEDS::Locker lock;
193 Unexpect aCatch(ATR_IncorrectArgumentLength);
195 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
198 for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
199 aTable->SetRowData(theRow, aRow);
202 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
203 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
205 SALOMEDS::Locker lock;
206 Unexpect aCatch(ATR_IncorrectIndex);
207 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
208 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
210 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
211 vector<double> aRow = aTable->GetRowData(theRow);
212 CorbaSeq->length(aRow.size());
213 for (int i = 0; i < aRow.size(); i++) {
214 CorbaSeq[i] = aRow[i];
216 return CorbaSeq._retn();
219 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
220 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
222 SALOMEDS::Locker lock;
223 Unexpect aCatch(ATR_IncorrectArgumentLength);
225 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
227 vector<double> aColumn;
228 for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
229 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
232 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
233 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
235 SALOMEDS::Locker lock;
236 Unexpect aCatch(ATR_IncorrectArgumentLength);
238 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
240 vector<double> aColumn;
241 for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
242 aTable->SetColumnData(theColumn, aColumn);
245 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
246 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
248 SALOMEDS::Locker lock;
249 Unexpect aCatch(ATR_IncorrectIndex);
250 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
251 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
253 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
254 vector<double> aColumn = aTable->GetColumnData(theColumn);
255 CorbaSeq->length(aColumn.size());
256 for (int i = 0; i < aColumn.size(); i++) {
257 CorbaSeq[i] = aColumn[i];
259 return CorbaSeq._retn();
262 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
263 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
265 SALOMEDS::Locker lock;
266 Unexpect aCatch(ATR_IncorrectIndex);
268 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
270 aTable->PutValue(theValue, theRow, theColumn);
273 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
275 SALOMEDS::Locker lock;
276 return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->HasValue(theRow, theColumn);
279 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
280 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
282 SALOMEDS::Locker lock;
283 Unexpect aCatch(ATR_IncorrectIndex);
284 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
285 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
287 CORBA::Double aValue;
290 aValue = aTable->GetValue(theRow, theColumn);
293 throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
300 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow)
302 SALOMEDS::Locker lock;
303 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
305 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
307 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
308 vector<int> aSeq = aTable->GetSetRowIndices(theRow);
309 int len = aSeq.size();
310 CorbaSeq->length(len);
311 for (int i = 0; i < len; i++) {
312 CorbaSeq[i] = aSeq[i];
314 return CorbaSeq._retn();
318 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
320 SALOMEDS::Locker lock;
321 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
322 aTable->SetNbColumns(theNbColumns);
325 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
327 SALOMEDS::Locker lock;
328 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
330 string aStream((char*)&theStream[0], theStream.length());
331 aTable->Load(aStream);
335 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile()
337 SALOMEDS::Locker lock;
338 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
340 string aString = aTable->Save();
341 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
342 int aBufferSize = strlen((char*)aBuffer);
344 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
346 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
348 return aStreamFile._retn();