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"
34 #include "Utils_ExceptHandlers.hxx"
35 UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex);
36 UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength);
38 void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle)
40 SALOMEDS::Locker lock;
42 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
43 CORBA::String_var aStr = CORBA::string_dup(theTitle);
44 aTable->SetTitle(string(aStr));
47 char* SALOMEDS_AttributeTableOfReal_i::GetTitle()
49 SALOMEDS::Locker lock;
50 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
51 CORBA::String_var c_s = CORBA::string_dup(aTable->GetTitle().c_str());
55 void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle)
56 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
58 SALOMEDS::Locker lock;
59 Unexpect aCatch (ATR_IncorrectIndex);
61 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
62 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
63 aTable->SetRowTitle(theIndex, string(theTitle));
66 void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles)
67 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
69 SALOMEDS::Locker lock;
70 Unexpect aCatch (ATR_IncorrectArgumentLength);
72 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
73 if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
74 for (int i = 0; i < theTitles.length(); i++) {
75 aTable->SetRowTitle(i + 1, (char*)theTitles[i].in());
79 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles()
81 SALOMEDS::Locker lock;
82 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
83 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
84 aTitles->length(aTable->GetNbRows());
85 for(int i = 0; i < aTitles->length(); i++)
86 aTitles[i] = CORBA::string_dup(aTable->GetRowTitle(i + 1).c_str());
87 return aTitles._retn();
90 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle)
91 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
93 SALOMEDS::Locker lock;
94 Unexpect aCatch (ATR_IncorrectIndex);
96 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
97 if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
98 CORBA::String_var aStr = CORBA::string_dup(theTitle);
99 aTable->SetColumnTitle(theIndex, string(aStr));
102 void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles)
103 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
105 SALOMEDS::Locker lock;
106 Unexpect aCatch(ATR_IncorrectArgumentLength);
108 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
109 if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
110 for (int i = 0; i < theTitles.length(); i++) {
111 aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in());
115 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles()
117 SALOMEDS::Locker lock;
118 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
119 SALOMEDS::StringSeq_var aTitles = new SALOMEDS::StringSeq;
120 aTitles->length(aTable->GetNbColumns());
121 for(int i = 0; i < aTitles->length(); i++)
122 aTitles[i] = CORBA::string_dup(aTable->GetColumnTitle(i + 1).c_str());
123 return aTitles._retn();
127 void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit)
128 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
130 SALOMEDS::Locker lock;
131 Unexpect aCatch (ATR_IncorrectIndex);
133 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
134 if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
135 aTable->SetRowUnit(theIndex, string(theUnit));
138 void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits)
139 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
141 SALOMEDS::Locker lock;
142 Unexpect aCatch (ATR_IncorrectArgumentLength);
144 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
145 if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength();
146 for (int i = 0; i < theUnits.length(); i++) {
147 aTable->SetRowUnit(i + 1, (char*)theUnits[i].in());
151 SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowUnits()
153 SALOMEDS::Locker lock;
154 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
155 SALOMEDS::StringSeq_var aUnits = new SALOMEDS::StringSeq;
156 aUnits->length(aTable->GetNbRows());
157 for(int i = 0; i < aUnits->length(); i++)
158 aUnits[i] = CORBA::string_dup(aTable->GetRowUnit(i + 1).c_str());
159 return aUnits._retn();
163 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbRows()
165 SALOMEDS::Locker lock;
166 return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->GetNbRows();
169 CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns()
171 SALOMEDS::Locker lock;
172 return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->GetNbColumns();
175 void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData)
176 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
178 SALOMEDS::Locker lock;
179 Unexpect aCatch(ATR_IncorrectArgumentLength);
181 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
184 for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
185 aTable->SetRowData(aTable->GetNbRows() + 1, aRow);
188 void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData)
189 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
191 SALOMEDS::Locker lock;
192 Unexpect aCatch(ATR_IncorrectArgumentLength);
194 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
197 for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]);
198 aTable->SetRowData(theRow, aRow);
201 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow)
202 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
204 SALOMEDS::Locker lock;
205 Unexpect aCatch(ATR_IncorrectIndex);
206 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
207 if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
209 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
210 vector<double> aRow = aTable->GetRowData(theRow);
211 CorbaSeq->length(aRow.size());
212 for (int i = 0; i < aRow.size(); i++) {
213 CorbaSeq[i] = aRow[i];
215 return CorbaSeq._retn();
218 void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData)
219 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength)
221 SALOMEDS::Locker lock;
222 Unexpect aCatch(ATR_IncorrectArgumentLength);
224 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
226 vector<double> aColumn;
227 for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
228 aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn);
231 void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData)
232 throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex)
234 SALOMEDS::Locker lock;
235 Unexpect aCatch(ATR_IncorrectArgumentLength);
237 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
239 vector<double> aColumn;
240 for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]);
241 aTable->SetColumnData(theColumn, aColumn);
244 SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn)
245 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
247 SALOMEDS::Locker lock;
248 Unexpect aCatch(ATR_IncorrectIndex);
249 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
250 if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
252 SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq;
253 vector<double> aColumn = aTable->GetColumnData(theColumn);
254 CorbaSeq->length(aColumn.size());
255 for (int i = 0; i < aColumn.size(); i++) {
256 CorbaSeq[i] = aColumn[i];
258 return CorbaSeq._retn();
261 void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn)
262 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
264 SALOMEDS::Locker lock;
265 Unexpect aCatch(ATR_IncorrectIndex);
267 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
269 aTable->PutValue(theValue, theRow, theColumn);
272 CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, CORBA::Long theColumn)
274 SALOMEDS::Locker lock;
275 return dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl)->HasValue(theRow, theColumn);
278 CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn)
279 throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex)
281 SALOMEDS::Locker lock;
282 Unexpect aCatch(ATR_IncorrectIndex);
283 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
284 if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
286 CORBA::Double aValue;
289 aValue = aTable->GetValue(theRow, theColumn);
292 throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
299 SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow)
301 SALOMEDS::Locker lock;
302 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
304 if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex();
306 SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq;
307 vector<int> aSeq = aTable->GetSetRowIndices(theRow);
308 int len = aSeq.size();
309 CorbaSeq->length(len);
310 for (int i = 0; i < len; i++) {
311 CorbaSeq[i] = aSeq[i];
313 return CorbaSeq._retn();
317 void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns)
319 SALOMEDS::Locker lock;
320 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
321 aTable->SetNbColumns(theNbColumns);
324 bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theStream)
326 SALOMEDS::Locker lock;
327 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
329 string aStream((char*)&theStream[0], theStream.length());
330 aTable->Load(aStream);
334 SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile()
336 SALOMEDS::Locker lock;
337 SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast<SALOMEDSImpl_AttributeTableOfReal*>(_impl);
339 string aString = aTable->Save();
340 char* aBuffer = (char*)CORBA::string_dup(aString.c_str());
341 int aBufferSize = strlen((char*)aBuffer);
343 CORBA::Octet* anOctetBuf = (CORBA::Octet*)aBuffer;
345 SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(aBufferSize, aBufferSize, anOctetBuf, 1);
347 return aStreamFile._retn();