From: vsr Date: Mon, 12 Apr 2010 06:21:55 +0000 (+0000) Subject: 0020465: [CEA 335] sort tables in visualisation mode X-Git-Tag: V5_1_4a1~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=3afeb10c10a3515c333e60d80e434718d7ade794;p=modules%2Fkernel.git 0020465: [CEA 335] sort tables in visualisation mode Implement Sort() and Swap() functions for table attributes --- diff --git a/idl/SALOMEDS_Attributes.idl b/idl/SALOMEDS_Attributes.idl index 31000a5a4..c7a78f367 100644 --- a/idl/SALOMEDS_Attributes.idl +++ b/idl/SALOMEDS_Attributes.idl @@ -895,6 +895,21 @@ module SALOMEDS //! This exception is raised when sequence of incorrect length is passed as parameter. exception IncorrectArgumentLength {}; + //! Sort order + enum SortOrder { + AscendingOrder, //!< The items are sorted ascending + DescendingOrder //!< The items are sorted descending + }; + + //! Sort policy (specifies how empty cells are taken into account when sorting) + enum SortPolicy { + EmptyLowest, //!< Empty cells are considered as lowest values + EmptyHighest, //!< Empty cells are considered as highest values + EmptyFirst, //!< Empty cells are always first + EmptyLast, //!< Empty cells are always last + EmptyIgnore //!< Empty cells are ignored (stay at initial positions) + }; + /*! \brief Sets the main title of the table. \param title title being set to the table @@ -1035,12 +1050,22 @@ module SALOMEDS (or if row/column index is/are out of range) */ boolean HasValue(in long row, in long column); + /*! + \brief Clear value in the specified table cell. + + Raises an exception if \a row or \a column is out of range. + + \param row row index + \param column column index + \sa HasValue() + */ + void RemoveValue(in long row, in long column) raises(IncorrectIndex); /*! \brief Sets the maximum number of colums in the table. If new number of columns is less than the current one, the table is truncated (extra columns are removed). - + \note It is recommended to set number of columns before assigning data to the table. \param columns total number of columns being set for the table @@ -1057,6 +1082,93 @@ module SALOMEDS \return list of column indices */ LongSeq GetRowSetIndices(in long row) raises(IncorrectIndex); + /*! + \brief Sort values in the specified table row. + + Sort order is specified by the \a order parameter. The \a policy + specifies how to process empty cells (put to the first place, ignore, etc). + + Raises an exception if \a row is out of range. + + \note Other table rows are not affected. + + \param row row index + \param order sort order (ascending/descending) + \param policy sort policy (specifies how to process empty cells) + */ + void SortRow(in long row, in SortOrder order, in SortPolicy policy) raises(IncorrectIndex); + /*! + \brief Sort values in the specified table column. + + Sort order is specified by the \a order parameter. The \a policy + specifies how to process empty cells (put to the first place, ignore, etc). + + Raises an exception if \a column is out of range. + + \note Other table columns are not affected. + + \param column column index + \param order sort order (ascending/descending) + \param policy sort policy (specifies how to process empty cells) + */ + void SortColumn(in long column, in SortOrder order, in SortPolicy policy) raises(IncorrectIndex); + /*! + \brief Sort table columns by the specified row. + + All the table columns are sorted according to the values in the specified + row. Sort order is specified by the \a order parameter. The \a policy + specifies how to process empty cells (put to the first place, ignore, etc). + + Raises an exception if \a row is out of range. + + \param row row index + \param order sort order (ascending/descending) + \param policy sort policy (specifies how to process empty cells) + */ + void SortByRow(in long row, in SortOrder order, in SortPolicy policy) raises(IncorrectIndex); + /*! + \brief Sort table rows by the specified column. + + All the table rows are sorted according to the values in the specified + column. Sort order is specified by the \a order parameter. The \a policy + specifies how to process empty cells (put to the first place, ignore, etc). + + Raises an exception if \a column is out of range. + + \param column column index + \param order sort order (ascending/descending) + \param policy sort policy (specifies how to process empty cells) + */ + void SortByColumn(in long column, in SortOrder order, in SortPolicy policy) raises(IncorrectIndex); + /*! + \brief Swap values in two table cells. + + Raises an exception if any specified index is out of range. + + \param row1 first cell's row index + \param column1 first cell's column index + \param row2 second cell's row index + \param column2 second cell's column index + */ + void SwapCells(in long row1, in long column1, in long row2, in long column2) raises(IncorrectIndex); + /*! + \brief Swap two table rows. + + Raises an exception if any \a row1 or \a row2 is out of range. + + \param row1 first row's index + \param row2 second row's index + */ + void SwapRows(in long row1, in long row2) raises(IncorrectIndex); + /*! + \brief Swap two table columns. + + Raises an exception if any \a column1 or \a column2 is out of range. + + \param column1 first column's index + \param column2 second column's index + */ + void SwapColumns(in long column1, in long column2) raises(IncorrectIndex); /*! \brief Reads a table from a byte stream. \param fileStream byte stream diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx index ce82749a4..4dc6657e5 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx @@ -26,8 +26,6 @@ #include "SALOMEDS_AttributeTableOfInteger.hxx" #include "SALOMEDS.hxx" -using namespace std; - SALOMEDS_AttributeTableOfInteger::SALOMEDS_AttributeTableOfInteger (SALOMEDSImpl_AttributeTableOfInteger* theAttr) :SALOMEDS_GenericAttribute(theAttr) @@ -97,7 +95,7 @@ void SALOMEDS_AttributeTableOfInteger::SetRowTitles(const std::vector aSeq; + std::vector aSeq; for (i = 0; i < aLength; i++) aSeq.push_back(theTitles[i]); dynamic_cast(_local_impl)->SetRowTitles(aSeq); } @@ -160,7 +158,7 @@ void SALOMEDS_AttributeTableOfInteger::SetColumnTitles(const std::vector aSeq; + std::vector aSeq; for (i = 0; i < aLength; i++) aSeq.push_back(theTitles[i]); dynamic_cast(_local_impl)->SetColumnTitles(aSeq); } @@ -438,6 +436,22 @@ int SALOMEDS_AttributeTableOfInteger::GetValue(int theRow, int theColumn) return aValue; } +void SALOMEDS_AttributeTableOfInteger::RemoveValue(int theRow, int theColumn) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->RemoveValue(theRow, theColumn); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->RemoveValue(theRow, theColumn); + } +} + std::vector SALOMEDS_AttributeTableOfInteger::GetRowSetIndices(int theRow) { std::vector aVector; @@ -463,3 +477,131 @@ void SALOMEDS_AttributeTableOfInteger::SetNbColumns(int theNbColumns) } else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetNbColumns(theNbColumns); } + +void SALOMEDS_AttributeTableOfInteger::SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SortRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfInteger::SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SortColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfInteger::SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortByRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SortByRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfInteger::SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortByColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SortByColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfInteger::SwapCells(int theRow1, int theColumn1, int theRow2, int theColumn2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } +} + +void SALOMEDS_AttributeTableOfInteger::SwapRows(int theRow1, int theRow2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapRows(theRow1, theRow2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SwapRows(theRow1, theRow2); + } +} + +void SALOMEDS_AttributeTableOfInteger::SwapColumns(int theColumn1, int theColumn2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapColumns(theColumn1, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SwapColumns(theColumn1, theColumn2); + } +} diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.hxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.hxx index 391360fa6..930c69490 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.hxx @@ -71,10 +71,18 @@ public: virtual void PutValue(int theValue, int theRow, int theColumn); virtual bool HasValue(int theRow, int theColumn); virtual int GetValue(int theRow, int theColumn); + virtual void RemoveValue(int theRow, int theColumn); virtual std::vector GetRowSetIndices(int theRow); virtual void SetNbColumns(int theNbColumns); + virtual void SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual void SwapCells(int theRow1, int theColumn1, int theRow2, int theColumn2); + virtual void SwapRows(int theRow1, int theRow2); + virtual void SwapColumns(int theColumn1, int theColumn2); }; #endif diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.cxx index 63035941c..7e22f6eaf 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.cxx @@ -33,8 +33,6 @@ #include #include -using namespace std; - UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTable::IncorrectIndex); UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectArgumentLength); @@ -43,7 +41,7 @@ void SALOMEDS_AttributeTableOfInteger_i::SetTitle(const char* theTitle) SALOMEDS::Locker lock; CheckLocked(); CORBA::String_var aStr = CORBA::string_dup(theTitle); - dynamic_cast(_impl)->SetTitle(string(aStr)); + dynamic_cast(_impl)->SetTitle(std::string(aStr)); } char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() @@ -61,8 +59,8 @@ void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - aTable->SetRowTitle(theIndex, string(theTitle)); + if (theIndex < 1 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + aTable->SetRowTitle(theIndex, std::string(theTitle)); } char* SALOMEDS_AttributeTableOfInteger_i::GetRowTitle(CORBA::Long theIndex) @@ -72,7 +70,7 @@ char* SALOMEDS_AttributeTableOfInteger_i::GetRowTitle(CORBA::Long theIndex) Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theIndex < 1 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); CORBA::String_var c_s = CORBA::string_dup(aTable->GetRowTitle(theIndex).c_str()); return c_s._retn(); } @@ -108,9 +106,9 @@ void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, co Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theIndex < 1 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); CORBA::String_var aStr = CORBA::string_dup(theTitle); - aTable->SetColumnTitle(theIndex, string(aStr)); + aTable->SetColumnTitle(theIndex, std::string(aStr)); } char* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitle(CORBA::Long theIndex) @@ -120,7 +118,7 @@ char* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitle(CORBA::Long theIndex) Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theIndex < 1 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); CORBA::String_var c_s = CORBA::string_dup(aTable->GetColumnTitle(theIndex).c_str()); return c_s._retn(); } @@ -157,8 +155,8 @@ void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - aTable->SetRowUnit(theIndex, string(theUnit)); + if (theIndex < 1 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + aTable->SetRowUnit(theIndex, std::string(theUnit)); } char* SALOMEDS_AttributeTableOfInteger_i::GetRowUnit(CORBA::Long theIndex) @@ -168,7 +166,7 @@ char* SALOMEDS_AttributeTableOfInteger_i::GetRowUnit(CORBA::Long theIndex) Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theIndex < 1 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); CORBA::String_var c_s = CORBA::string_dup(aTable->GetRowUnit(theIndex).c_str()); return c_s._retn(); } @@ -217,7 +215,7 @@ void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - vector aRow; + std::vector aRow; for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]); try { aTable->SetRowData(aTable->GetNbRows() + 1, aRow); @@ -235,7 +233,7 @@ void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOME CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - vector aRow; + std::vector aRow; for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]); try { aTable->SetRowData(theRow, aRow); @@ -251,10 +249,10 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectIndex); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; - vector aRow = aTable->GetRowData(theRow); + std::vector aRow = aTable->GetRowData(theRow); CorbaSeq->length(aRow.size()); for (int i = 0; i < aRow.size(); i++) { CorbaSeq[i] = aRow[i]; @@ -270,7 +268,7 @@ void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theD CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - vector aColumn; + std::vector aColumn; for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]); try { aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn); @@ -288,7 +286,7 @@ void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - vector aColumn; + std::vector aColumn; for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]); try { aTable->SetColumnData(theColumn, aColumn); @@ -304,10 +302,10 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long the SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectIndex); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; - vector aColumn = aTable->GetColumnData(theColumn); + std::vector aColumn = aTable->GetColumnData(theColumn); CorbaSeq->length(aColumn.size()); for (int i = 0; i < aColumn.size(); i++) { CorbaSeq[i] = aColumn[i]; @@ -343,7 +341,8 @@ CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, COR SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectIndex); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); CORBA::Long aValue; try { @@ -355,15 +354,32 @@ CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, COR return aValue; } +void SALOMEDS_AttributeTableOfInteger_i::RemoveValue(CORBA::Long theRow, CORBA::Long theColumn) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATI_IncorrectIndex); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->RemoveValue(theRow, theColumn); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::Long theRow) { SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if(theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; - vector aSeq = aTable->GetSetRowIndices(theRow); + std::vector aSeq = aTable->GetSetRowIndices(theRow); CorbaSeq->length(aSeq.size()); for (int i = 0; i < aSeq.size(); i++) { CorbaSeq[i] = aSeq[i]; @@ -371,7 +387,6 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::L return CorbaSeq._retn(); } - void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns) { SALOMEDS::Locker lock; @@ -384,17 +399,17 @@ bool SALOMEDS_AttributeTableOfInteger_i::ReadFromFile(const SALOMEDS::TMPFile& t SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - string aStream((char*)&theStream[0], theStream.length()); + std::string aStream((char*)&theStream[0], theStream.length()); aTable->Load(aStream); return true; } -SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile() +SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile() { SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - string aString = aTable->Save(); + std::string aString = aTable->Save(); char* aBuffer = (char*)CORBA::string_dup(aString.c_str()); int aBufferSize = strlen((char*)aBuffer); @@ -406,4 +421,139 @@ SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile() return aStreamFile._retn(); } +void SALOMEDS_AttributeTableOfInteger_i::SortRow(CORBA::Long theRow, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfInteger_i::SortColumn(CORBA::Long theColumn, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfInteger_i::SortByRow(CORBA::Long theRow, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortByRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} +void SALOMEDS_AttributeTableOfInteger_i::SortByColumn(CORBA::Long theColumn, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortByColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfInteger_i::SwapCells(CORBA::Long theRow1, CORBA::Long theColumn1, + CORBA::Long theRow2, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theRow1 < 1 || theRow1 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn1 < 1 || theColumn1 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theRow2 < 1 || theRow2 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn2 < 1 || theColumn2 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfInteger_i::SwapRows(CORBA::Long theRow1, CORBA::Long theRow2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theRow1 < 1 || theRow1 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theRow2 < 1 || theRow2 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapRows(theRow1, theRow2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfInteger_i::SwapColumns(CORBA::Long theColumn1, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theColumn1 < 1 || theColumn1 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn2 < 1 || theColumn2 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapColumns(theColumn1, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.hxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.hxx index 371db5e48..edf10c5c7 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.hxx @@ -36,9 +36,7 @@ class SALOMEDS_AttributeTableOfInteger_i: public virtual POA_SALOMEDS::AttributeTableOfInteger, public virtual SALOMEDS_GenericAttribute_i { - public: - SALOMEDS_AttributeTableOfInteger_i(SALOMEDSImpl_AttributeTableOfInteger* theAttr, CORBA::ORB_ptr orb) :SALOMEDS_GenericAttribute_i(theAttr, orb) {}; @@ -88,10 +86,33 @@ public: virtual CORBA::Boolean HasValue(CORBA::Long theRow, CORBA::Long theColumn); virtual CORBA::Long GetValue(CORBA::Long theRow, CORBA::Long theColumn) throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void RemoveValue(CORBA::Long theRow, CORBA::Long theColumn) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::LongSeq* GetRowSetIndices(CORBA::Long theRow); virtual void SetNbColumns(CORBA::Long theNbColumns); + virtual void SortRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortByRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortByColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + + virtual void SwapCells(CORBA::Long theRow1, CORBA::Long theColumn1, + CORBA::Long theRow2, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SwapRows(CORBA::Long theRow1, CORBA::Long theRow2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SwapColumns(CORBA::Long theColumn1, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual bool ReadFromFile(const SALOMEDS::TMPFile& theStream); virtual SALOMEDS::TMPFile* SaveToFile(); }; diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.cxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.cxx index 9a3924634..fc3c3e261 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.cxx @@ -432,6 +432,22 @@ double SALOMEDS_AttributeTableOfReal::GetValue(int theRow, int theColumn) return aValue; } +void SALOMEDS_AttributeTableOfReal::RemoveValue(int theRow, int theColumn) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->RemoveValue(theRow, theColumn); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->RemoveValue(theRow, theColumn); + } +} + std::vector SALOMEDS_AttributeTableOfReal::GetRowSetIndices(int theRow) { std::vector aVector; @@ -456,3 +472,131 @@ void SALOMEDS_AttributeTableOfReal::SetNbColumns(int theNbColumns) } else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetNbColumns(theNbColumns); } + +void SALOMEDS_AttributeTableOfReal::SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SortRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfReal::SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SortColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfReal::SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortByRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SortByRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfReal::SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortByColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SortByColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfReal::SwapCells(int theRow1, int theColumn1, int theRow2, int theColumn2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } +} + +void SALOMEDS_AttributeTableOfReal::SwapRows(int theRow1, int theRow2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapRows(theRow1, theRow2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SwapRows(theRow1, theRow2); + } +} + +void SALOMEDS_AttributeTableOfReal::SwapColumns(int theColumn1, int theColumn2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapColumns(theColumn1, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SwapColumns(theColumn1, theColumn2); + } +} diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.hxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.hxx index 884fc0ccf..3655427f9 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.hxx @@ -71,10 +71,18 @@ public: virtual void PutValue(double theValue, int theRow, int theColumn); virtual bool HasValue(int theRow, int theColumn); virtual double GetValue(int theRow, int theColumn); + virtual void RemoveValue(int theRow, int theColumn); virtual std::vector GetRowSetIndices(int theRow); virtual void SetNbColumns(int theNbColumns); + virtual void SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual void SwapCells(int theRow1, int theColumn1, int theRow2, int theColumn2); + virtual void SwapRows(int theRow1, int theRow2); + virtual void SwapColumns(int theColumn1, int theColumn2); }; #endif diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.cxx index e3a4c4026..60e2d330a 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.cxx @@ -30,8 +30,6 @@ #include #include -using namespace std; - #include "Utils_ExceptHandlers.hxx" UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTable::IncorrectIndex); UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectArgumentLength); @@ -42,7 +40,7 @@ void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle) CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); CORBA::String_var aStr = CORBA::string_dup(theTitle); - aTable->SetTitle(string(aStr)); + aTable->SetTitle(std::string(aStr)); } char* SALOMEDS_AttributeTableOfReal_i::GetTitle() @@ -61,7 +59,7 @@ void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const ch CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - aTable->SetRowTitle(theIndex, string(theTitle)); + aTable->SetRowTitle(theIndex, std::string(theTitle)); } char* SALOMEDS_AttributeTableOfReal_i::GetRowTitle(CORBA::Long theIndex) @@ -109,7 +107,7 @@ void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); CORBA::String_var aStr = CORBA::string_dup(theTitle); - aTable->SetColumnTitle(theIndex, string(aStr)); + aTable->SetColumnTitle(theIndex, std::string(aStr)); } char* SALOMEDS_AttributeTableOfReal_i::GetColumnTitle(CORBA::Long theIndex) @@ -157,7 +155,7 @@ void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const cha CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - aTable->SetRowUnit(theIndex, string(theUnit)); + aTable->SetRowUnit(theIndex, std::string(theUnit)); } char* SALOMEDS_AttributeTableOfReal_i::GetRowUnit(CORBA::Long theIndex) @@ -217,7 +215,7 @@ void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData) CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - vector aRow; + std::vector aRow; for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]); aTable->SetRowData(aTable->GetNbRows() + 1, aRow); } @@ -230,7 +228,7 @@ void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS: CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - vector aRow; + std::vector aRow; for (int i = 0; i < theData.length(); i++) aRow.push_back(theData[i]); aTable->SetRowData(theRow, aRow); } @@ -244,7 +242,7 @@ SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow) if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq; - vector aRow = aTable->GetRowData(theRow); + std::vector aRow = aTable->GetRowData(theRow); CorbaSeq->length(aRow.size()); for (int i = 0; i < aRow.size(); i++) { CorbaSeq[i] = aRow[i]; @@ -260,7 +258,7 @@ void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theDa CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - vector aColumn; + std::vector aColumn; for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]); aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn); } @@ -273,7 +271,7 @@ void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SAL CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - vector aColumn; + std::vector aColumn; for (int i = 0; i < theData.length(); i++) aColumn.push_back(theData[i]); aTable->SetColumnData(theColumn, aColumn); } @@ -287,7 +285,7 @@ SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theC if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::DoubleSeq_var CorbaSeq = new SALOMEDS::DoubleSeq; - vector aColumn = aTable->GetColumnData(theColumn); + std::vector aColumn = aTable->GetColumnData(theColumn); CorbaSeq->length(aColumn.size()); for (int i = 0; i < aColumn.size(); i++) { CorbaSeq[i] = aColumn[i]; @@ -332,6 +330,22 @@ CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORB return aValue; } +void SALOMEDS_AttributeTableOfReal_i::RemoveValue(CORBA::Long theRow, CORBA::Long theColumn) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATR_IncorrectIndex); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->RemoveValue(theRow, theColumn); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long theRow) { @@ -341,7 +355,7 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; - vector aSeq = aTable->GetSetRowIndices(theRow); + std::vector aSeq = aTable->GetSetRowIndices(theRow); int len = aSeq.size(); CorbaSeq->length(len); for (int i = 0; i < len; i++) { @@ -350,7 +364,6 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long return CorbaSeq._retn(); } - void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns) { SALOMEDS::Locker lock; @@ -363,7 +376,7 @@ bool SALOMEDS_AttributeTableOfReal_i::ReadFromFile(const SALOMEDS::TMPFile& theS SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - string aStream((char*)&theStream[0], theStream.length()); + std::string aStream((char*)&theStream[0], theStream.length()); aTable->Load(aStream); return true; } @@ -373,7 +386,7 @@ SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile() SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - string aString = aTable->Save(); + std::string aString = aTable->Save(); char* aBuffer = (char*)CORBA::string_dup(aString.c_str()); int aBufferSize = strlen((char*)aBuffer); @@ -383,3 +396,140 @@ SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile() return aStreamFile._retn(); } + +void SALOMEDS_AttributeTableOfReal_i::SortRow(CORBA::Long theRow, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfReal_i::SortColumn(CORBA::Long theColumn, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfReal_i::SortByRow(CORBA::Long theRow, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortByRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfReal_i::SortByColumn(CORBA::Long theColumn, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortByColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfReal_i::SwapCells(CORBA::Long theRow1, CORBA::Long theColumn1, + CORBA::Long theRow2, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theRow1 < 1 || theRow1 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn1 < 1 || theColumn1 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theRow2 < 1 || theRow2 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn2 < 1 || theColumn2 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfReal_i::SwapRows(CORBA::Long theRow1, CORBA::Long theRow2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theRow1 < 1 || theRow1 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theRow2 < 1 || theRow2 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapRows(theRow1, theRow2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfReal_i::SwapColumns(CORBA::Long theColumn1, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theColumn1 < 1 || theColumn1 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn2 < 1 || theColumn2 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapColumns(theColumn1, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.hxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.hxx index ae7410223..9aeee88e8 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.hxx @@ -33,17 +33,16 @@ #include "SALOMEDS_GenericAttribute_i.hxx" #include "SALOMEDSImpl_AttributeTableOfReal.hxx" -class SALOMEDS_AttributeTableOfReal_i: public virtual POA_SALOMEDS::AttributeTableOfReal, - public virtual SALOMEDS_GenericAttribute_i { - +class SALOMEDS_AttributeTableOfReal_i : public virtual POA_SALOMEDS::AttributeTableOfReal, + public virtual SALOMEDS_GenericAttribute_i +{ public: - SALOMEDS_AttributeTableOfReal_i(SALOMEDSImpl_AttributeTableOfReal* theAttr, CORBA::ORB_ptr orb) - :SALOMEDS_GenericAttribute_i(theAttr, orb) {}; - + : SALOMEDS_GenericAttribute_i(theAttr, orb) {}; + ~SALOMEDS_AttributeTableOfReal_i() {}; - - virtual void SetTitle(const char* theTitle); + + virtual void SetTitle(const char* theTitle); virtual char* GetTitle(); virtual void SetRowTitle(CORBA::Long theIndex, const char* theTitle) throw (SALOMEDS::AttributeTable::IncorrectIndex); @@ -87,10 +86,33 @@ public: virtual CORBA::Boolean HasValue(CORBA::Long theRow, CORBA::Long theColumn); virtual CORBA::Double GetValue(CORBA::Long theRow, CORBA::Long theColumn) throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void RemoveValue(CORBA::Long theRow, CORBA::Long theColumn) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::LongSeq* GetRowSetIndices(CORBA::Long theRow); virtual void SetNbColumns(CORBA::Long theNbColumns); + virtual void SortRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortByRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortByColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + + virtual void SwapCells(CORBA::Long theRow1, CORBA::Long theColumn1, + CORBA::Long theRow2, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SwapRows(CORBA::Long theRow1, CORBA::Long theRow2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SwapColumns(CORBA::Long theColumn1, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual bool ReadFromFile(const SALOMEDS::TMPFile& theStream); virtual SALOMEDS::TMPFile* SaveToFile(); diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfString.cxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfString.cxx index 324ee8707..af7218536 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfString.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfString.cxx @@ -435,6 +435,22 @@ std::string SALOMEDS_AttributeTableOfString::GetValue(int theRow, int theColumn) return aValue; } +void SALOMEDS_AttributeTableOfString::RemoveValue(int theRow, int theColumn) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->RemoveValue(theRow, theColumn); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->RemoveValue(theRow, theColumn); + } +} + std::vector SALOMEDS_AttributeTableOfString::GetRowSetIndices(int theRow) { std::vector aVector; @@ -460,3 +476,131 @@ void SALOMEDS_AttributeTableOfString::SetNbColumns(int theNbColumns) } else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetNbColumns(theNbColumns); } + +void SALOMEDS_AttributeTableOfString::SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SortRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfString::SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SortColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfString::SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortByRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SortByRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfString::SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SortByColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SortByColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + } +} + +void SALOMEDS_AttributeTableOfString::SwapCells(int theRow1, int theColumn1, int theRow2, int theColumn2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } +} + +void SALOMEDS_AttributeTableOfString::SwapRows(int theRow1, int theRow2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapRows(theRow1, theRow2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SwapRows(theRow1, theRow2); + } +} + +void SALOMEDS_AttributeTableOfString::SwapColumns(int theColumn1, int theColumn2) +{ + if (_isLocal) { + SALOMEDS::Locker lock; + try { + dynamic_cast(_local_impl)->SwapColumns(theColumn1, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SwapColumns(theColumn1, theColumn2); + } +} diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfString.hxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfString.hxx index a79b790cb..c4572bf4e 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfString.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfString.hxx @@ -71,10 +71,18 @@ public: virtual void PutValue(const std::string& theValue, int theRow, int theColumn); virtual bool HasValue(int theRow, int theColumn); virtual std::string GetValue(int theRow, int theColumn); + virtual void RemoveValue(int theRow, int theColumn); virtual std::vector GetRowSetIndices(int theRow); virtual void SetNbColumns(int theNbColumns); + virtual void SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual void SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual void SwapCells(int theRow1, int theColumn1, int theRow2, int theColumn2); + virtual void SwapRows(int theRow1, int theRow2); + virtual void SwapColumns(int theColumn1, int theColumn2); }; #endif diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.cxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.cxx index 9f47aa425..267569a28 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.cxx @@ -32,8 +32,6 @@ #include "Utils_ExceptHandlers.hxx" -using namespace std; - UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTable::IncorrectIndex); UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectArgumentLength); @@ -43,7 +41,7 @@ void SALOMEDS_AttributeTableOfString_i::SetTitle(const char* theTitle) CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); CORBA::String_var aStr = CORBA::string_dup(theTitle); - aTable->SetTitle(string(aStr)); + aTable->SetTitle(std::string(aStr)); } char* SALOMEDS_AttributeTableOfString_i::GetTitle() @@ -63,7 +61,7 @@ void SALOMEDS_AttributeTableOfString_i::SetRowTitle(CORBA::Long theIndex, const SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - aTable->SetRowTitle(theIndex, string(theTitle)); + aTable->SetRowTitle(theIndex, std::string(theTitle)); } char* SALOMEDS_AttributeTableOfString_i::GetRowTitle(CORBA::Long theIndex) @@ -87,7 +85,7 @@ void SALOMEDS_AttributeTableOfString_i::SetRowTitles(const SALOMEDS::StringSeq& SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theTitles.length(); i++) { - aTable->SetRowTitle(i + 1, string((char*)theTitles[i].in())); + aTable->SetRowTitle(i + 1, std::string((char*)theTitles[i].in())); } } @@ -110,7 +108,7 @@ void SALOMEDS_AttributeTableOfString_i::SetColumnTitle(CORBA::Long theIndex, con CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - aTable->SetColumnTitle(theIndex, string((char*)theTitle)); + aTable->SetColumnTitle(theIndex, std::string((char*)theTitle)); } char* SALOMEDS_AttributeTableOfString_i::GetColumnTitle(CORBA::Long theIndex) @@ -134,7 +132,7 @@ void SALOMEDS_AttributeTableOfString_i::SetColumnTitles(const SALOMEDS::StringSe SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theTitles.length(); i++) { - aTable->SetColumnTitle(i + 1, string((char*)theTitles[i].in())); + aTable->SetColumnTitle(i + 1, std::string((char*)theTitles[i].in())); } } @@ -158,7 +156,7 @@ void SALOMEDS_AttributeTableOfString_i::SetRowUnit(CORBA::Long theIndex, const c CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - aTable->SetRowUnit(theIndex, string((char*)theUnit)); + aTable->SetRowUnit(theIndex, std::string((char*)theUnit)); } char* SALOMEDS_AttributeTableOfString_i::GetRowUnit(CORBA::Long theIndex) @@ -182,7 +180,7 @@ void SALOMEDS_AttributeTableOfString_i::SetRowUnits(const SALOMEDS::StringSeq& t SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theUnits.length(); i++) { - aTable->SetRowUnit(i + 1, string((char*)theUnits[i].in())); + aTable->SetRowUnit(i + 1, std::string((char*)theUnits[i].in())); } } @@ -218,8 +216,8 @@ void SALOMEDS_AttributeTableOfString_i::AddRow(const SALOMEDS::StringSeq& theDat CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - vector aRow; - for (int i = 0; i < theData.length(); i++) aRow.push_back(string(CORBA::string_dup(theData[i]))); + std::vector aRow; + for (int i = 0; i < theData.length(); i++) aRow.push_back(std::string(CORBA::string_dup(theData[i]))); aTable->SetRowData(aTable->GetNbRows() + 1, aRow); } @@ -231,8 +229,8 @@ void SALOMEDS_AttributeTableOfString_i::SetRow(CORBA::Long theRow, const SALOMED CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - vector aRow; - for (int i = 0; i < theData.length(); i++) aRow.push_back(string(CORBA::string_dup(theData[i].in()))); + std::vector aRow; + for (int i = 0; i < theData.length(); i++) aRow.push_back(std::string(CORBA::string_dup(theData[i].in()))); aTable->SetRowData(theRow, aRow); } @@ -245,7 +243,7 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRo if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq; - vector aRow = aTable->GetRowData(theRow); + std::vector aRow = aTable->GetRowData(theRow); CorbaSeq->length(aRow.size()); for (int i = 0; i < aRow.size(); i++) { CorbaSeq[i] = CORBA::string_dup(aRow[i].c_str()); @@ -261,8 +259,8 @@ void SALOMEDS_AttributeTableOfString_i::AddColumn(const SALOMEDS::StringSeq& the CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - vector aColumn; - for (int i = 0; i < theData.length(); i++) aColumn.push_back(string(CORBA::string_dup(theData[i]))); + std::vector aColumn; + for (int i = 0; i < theData.length(); i++) aColumn.push_back(std::string(CORBA::string_dup(theData[i]))); aTable->SetColumnData(aTable->GetNbColumns() + 1, aColumn); } @@ -274,8 +272,8 @@ void SALOMEDS_AttributeTableOfString_i::SetColumn(CORBA::Long theColumn, const S CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - vector aColumn; - for (int i = 0; i < theData.length(); i++) aColumn.push_back(string(CORBA::string_dup(theData[i]))); + std::vector aColumn; + for (int i = 0; i < theData.length(); i++) aColumn.push_back(std::string(CORBA::string_dup(theData[i]))); aTable->SetColumnData(theColumn, aColumn); } @@ -288,7 +286,7 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long th if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::StringSeq_var CorbaSeq = new SALOMEDS::StringSeq; - vector aColumn = aTable->GetColumnData(theColumn); + std::vector aColumn = aTable->GetColumnData(theColumn); CorbaSeq->length(aColumn.size()); for (int i = 0; i < aColumn.size(); i++) { CorbaSeq[i] = CORBA::string_dup(aColumn[i].c_str()); @@ -322,7 +320,7 @@ char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Lon SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - string aValue; + std::string aValue; try { aValue = aTable->GetValue(theRow, theColumn); } @@ -333,6 +331,22 @@ char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Lon return CORBA::string_dup(aValue.c_str()); } +void SALOMEDS_AttributeTableOfString_i::RemoveValue(CORBA::Long theRow, CORBA::Long theColumn) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATS_IncorrectIndex); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->RemoveValue(theRow, theColumn); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Long theRow) { @@ -342,7 +356,7 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Lo if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; - vector aSeq = aTable->GetSetRowIndices(theRow); + std::vector aSeq = aTable->GetSetRowIndices(theRow); CorbaSeq->length(aSeq.size()); for (int i = 0; i < aSeq.size(); i++) { CorbaSeq[i] = aSeq[i]; @@ -350,7 +364,6 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Lo return CorbaSeq._retn(); } - void SALOMEDS_AttributeTableOfString_i::SetNbColumns(CORBA::Long theNbColumns) { SALOMEDS::Locker lock; @@ -363,7 +376,7 @@ bool SALOMEDS_AttributeTableOfString_i::ReadFromFile(const SALOMEDS::TMPFile& th SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - string aStream((char*)&theStream[0], theStream.length()); + std::string aStream((char*)&theStream[0], theStream.length()); aTable->Load(aStream); return true; } @@ -373,7 +386,7 @@ SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfString_i::SaveToFile() SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - string aString = aTable->Save(); + std::string aString = aTable->Save(); char* aBuffer = (char*)CORBA::string_dup(aString.c_str()); int aBufferSize = strlen((char*)aBuffer); @@ -384,3 +397,139 @@ SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfString_i::SaveToFile() return aStreamFile._retn(); } +void SALOMEDS_AttributeTableOfString_i::SortRow(CORBA::Long theRow, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfString_i::SortColumn(CORBA::Long theColumn, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfString_i::SortByRow(CORBA::Long theRow, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theRow < 1 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortByRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfString_i::SortByColumn(CORBA::Long theColumn, + SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theColumn < 1 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SortByColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfString_i::SwapCells(CORBA::Long theRow1, CORBA::Long theColumn1, + CORBA::Long theRow2, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theRow1 < 1 || theRow1 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn1 < 1 || theColumn1 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theRow2 < 1 || theRow2 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn2 < 1 || theColumn2 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapCells(theRow1, theColumn1, theRow2, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfString_i::SwapRows(CORBA::Long theRow1, CORBA::Long theRow2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theRow1 < 1 || theRow1 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theRow2 < 1 || theRow2 > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapRows(theRow1, theRow2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} + +void SALOMEDS_AttributeTableOfString_i::SwapColumns(CORBA::Long theColumn1, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theColumn1 < 1 || theColumn1 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + if (theColumn2 < 1 || theColumn2 > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + + try { + aTable->SwapColumns(theColumn1, theColumn2); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } +} diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.hxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.hxx index f40b76f86..eedb388ab 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.hxx @@ -87,13 +87,35 @@ public: virtual CORBA::Boolean HasValue(CORBA::Long theRow, CORBA::Long theColumn); virtual char* GetValue(CORBA::Long theRow, CORBA::Long theColumn) throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void RemoveValue(CORBA::Long theRow, CORBA::Long theColumn) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::LongSeq* GetRowSetIndices(CORBA::Long theRow); virtual void SetNbColumns(CORBA::Long theNbColumns); + virtual void SortRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortByRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SortByColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + + virtual void SwapCells(CORBA::Long theRow1, CORBA::Long theColumn1, + CORBA::Long theRow2, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SwapRows(CORBA::Long theRow1, CORBA::Long theRow2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual void SwapColumns(CORBA::Long theColumn1, CORBA::Long theColumn2) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual bool ReadFromFile(const SALOMEDS::TMPFile& theStream); virtual SALOMEDS::TMPFile* SaveToFile(); - }; #endif diff --git a/src/SALOMEDSClient/Makefile.am b/src/SALOMEDSClient/Makefile.am index d9736b141..00d937f5b 100644 --- a/src/SALOMEDSClient/Makefile.am +++ b/src/SALOMEDSClient/Makefile.am @@ -48,6 +48,7 @@ salomeinclude_HEADERS=\ SALOMEDSClient_AttributeSequenceOfInteger.hxx \ SALOMEDSClient_AttributeSequenceOfReal.hxx \ SALOMEDSClient_AttributeStudyProperties.hxx \ + SALOMEDSClient_AttributeTable.hxx \ SALOMEDSClient_AttributeTableOfInteger.hxx \ SALOMEDSClient_AttributeTableOfReal.hxx \ SALOMEDSClient_AttributeTableOfString.hxx \ diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTable.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTable.hxx new file mode 100644 index 000000000..9560085ac --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTable.hxx @@ -0,0 +1,82 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SALOMEDSClient_AttributeTable.hxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#ifndef SALOMEDSClient_AttributeTable_HeaderFile +#define SALOMEDSClient_AttributeTable_HeaderFile + +#include +#include +#include "SALOMEDSClient_definitions.hxx" +#include "SALOMEDSClient_GenericAttribute.hxx" + +class SALOMEDSClient_AttributeTable: public virtual SALOMEDSClient_GenericAttribute +{ +public: + typedef enum { + AscendingOrder, + DescendingOrder, + } SortOrder; + + typedef enum { + EmptyLowest, + EmptyHighest, + EmptyFirst, + EmptyLast, + EmptyIgnore, + } SortPolicy; + + virtual void SetTitle(const std::string& theTitle) = 0; + virtual std::string GetTitle() = 0; + virtual void SetRowTitle(int theIndex, const std::string& theTitle) = 0; + virtual std::string GetRowTitle(int theIndex) = 0; + virtual void SetRowTitles(const std::vector& theTitles) = 0; + virtual std::vector GetRowTitles() = 0; + virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 0; + virtual std::string GetColumnTitle(int theIndex) = 0; + virtual void SetColumnTitles(const std::vector& theTitles) = 0; + virtual std::vector GetColumnTitles() = 0; + virtual void SetRowUnit(int theIndex, const std::string& theUnit) = 0; + virtual std::string GetRowUnit(int theIndex) = 0; + virtual void SetRowUnits(const std::vector& theUnits) = 0; + virtual std::vector GetRowUnits() = 0; + + virtual int GetNbRows() = 0; + virtual int GetNbColumns() = 0; + virtual bool HasValue(int theRow, int theColumn) = 0; + virtual void RemoveValue(int theRow, int theColumn) = 0; + + virtual std::vector GetRowSetIndices(int theRow) = 0; + virtual void SetNbColumns(int theNbColumns) = 0; + + virtual void SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) = 0; + virtual void SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) = 0; + virtual void SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) = 0; + virtual void SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) = 0; + virtual void SwapCells(int theRow1, int theColumn1, int theRow2, int theColumn2) = 0; + virtual void SwapRows(int theRow1, int theRow2) = 0; + virtual void SwapColumns(int theColumn1, int theColumn2) = 0; +}; + +#endif // SALOMEDSClient_AttributeTable_HeaderFile diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx index 045e37f7d..5a023e6b3 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx @@ -29,30 +29,11 @@ #include #include #include "SALOMEDSClient_definitions.hxx" -#include "SALOMEDSClient_GenericAttribute.hxx" +#include "SALOMEDSClient_AttributeTable.hxx" -class SALOMEDSClient_AttributeTableOfInteger: public virtual SALOMEDSClient_GenericAttribute +class SALOMEDSClient_AttributeTableOfInteger: public SALOMEDSClient_AttributeTable { - public: - - virtual void SetTitle(const std::string& theTitle) = 0; - virtual std::string GetTitle() = 0; - virtual void SetRowTitle(int theIndex, const std::string& theTitle) = 0; - virtual std::string GetRowTitle(int theIndex) = 0; - virtual void SetRowTitles(const std::vector& theTitles) = 0; - virtual std::vector GetRowTitles() = 0; - virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 0; - virtual std::string GetColumnTitle(int theIndex) = 0; - virtual void SetColumnTitles(const std::vector& theTitles) = 0; - virtual std::vector GetColumnTitles() = 0; - virtual void SetRowUnit(int theIndex, const std::string& theUnit) = 0; - virtual std::string GetRowUnit(int theIndex) = 0; - virtual void SetRowUnits(const std::vector& theUnits) = 0; - virtual std::vector GetRowUnits() = 0; - - virtual int GetNbRows() = 0; - virtual int GetNbColumns() = 0; virtual void AddRow(const std::vector& theData) = 0; virtual void SetRow(int theRow, const std::vector& theData) = 0; virtual std::vector GetRow(int theRow) = 0; @@ -60,12 +41,7 @@ public: virtual void SetColumn(int theColumn, const std::vector& theData) = 0; virtual std::vector GetColumn(int theColumn) = 0; virtual void PutValue(int theValue, int theRow, int theColumn) = 0; - virtual bool HasValue(int theRow, int theColumn) = 0; virtual int GetValue(int theRow, int theColumn) = 0; - - virtual std::vector GetRowSetIndices(int theRow) = 0; - virtual void SetNbColumns(int theNbColumns) = 0; - }; -#endif +#endif // SALOMEDSClient_AttributeTableOfInteger_HeaderFile diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx index 257d56a02..c4d22a524 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx @@ -29,30 +29,11 @@ #include #include #include "SALOMEDSClient_definitions.hxx" -#include "SALOMEDSClient_GenericAttribute.hxx" +#include "SALOMEDSClient_AttributeTable.hxx" -class SALOMEDSClient_AttributeTableOfReal: public virtual SALOMEDSClient_GenericAttribute +class SALOMEDSClient_AttributeTableOfReal: public SALOMEDSClient_AttributeTable { - public: - - virtual void SetTitle(const std::string& theTitle) = 0; - virtual std::string GetTitle() = 0; - virtual void SetRowTitle(int theIndex, const std::string& theTitle) = 0; - virtual std::string GetRowTitle(int theIndex) = 0; - virtual void SetRowTitles(const std::vector& theTitles) = 0; - virtual std::vector GetRowTitles() = 0; - virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 0; - virtual std::string GetColumnTitle(int theIndex) = 0; - virtual void SetColumnTitles(const std::vector& theTitles) = 0; - virtual std::vector GetColumnTitles() = 0; - virtual void SetRowUnit(int theIndex, const std::string& theUnit) = 0; - virtual std::string GetRowUnit(int theIndex) = 0; - virtual void SetRowUnits(const std::vector& theUnits) = 0; - virtual std::vector GetRowUnits() = 0; - - virtual int GetNbRows() = 0; - virtual int GetNbColumns() = 0; virtual void AddRow(const std::vector& theData) = 0; virtual void SetRow(int theRow, const std::vector& theData) = 0; virtual std::vector GetRow(int theRow) = 0; @@ -60,12 +41,7 @@ public: virtual void SetColumn(int theColumn, const std::vector& theData) = 0; virtual std::vector GetColumn(int theColumn) = 0; virtual void PutValue(double theValue, int theRow, int theColumn) = 0; - virtual bool HasValue(int theRow, int theColumn) = 0; virtual double GetValue(int theRow, int theColumn) = 0; - - virtual std::vector GetRowSetIndices(int theRow) = 0; - virtual void SetNbColumns(int theNbColumns) = 0; - }; -#endif +#endif // SALOMEDSClient_AttributeTableOfReal_HeaderFile diff --git a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx index 93b75c024..60b1d233f 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx @@ -29,29 +29,11 @@ #include #include #include "SALOMEDSClient_definitions.hxx" -#include "SALOMEDSClient_GenericAttribute.hxx" +#include "SALOMEDSClient_AttributeTable.hxx" -class SALOMEDSClient_AttributeTableOfString: public virtual SALOMEDSClient_GenericAttribute +class SALOMEDSClient_AttributeTableOfString: public SALOMEDSClient_AttributeTable { public: - - virtual void SetTitle(const std::string& theTitle) = 0; - virtual std::string GetTitle() = 0; - virtual void SetRowTitle(int theIndex, const std::string& theTitle) = 0; - virtual std::string GetRowTitle(int theIndex) = 0; - virtual void SetRowTitles(const std::vector& theTitles) = 0; - virtual std::vector GetRowTitles() = 0; - virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 0; - virtual std::string GetColumnTitle(int theIndex) = 0; - virtual void SetColumnTitles(const std::vector& theTitles) = 0; - virtual std::vector GetColumnTitles() = 0; - virtual void SetRowUnit(int theIndex, const std::string& theUnit) = 0; - virtual std::string GetRowUnit(int theIndex) = 0; - virtual void SetRowUnits(const std::vector& theUnits) = 0; - virtual std::vector GetRowUnits() = 0; - - virtual int GetNbRows() = 0; - virtual int GetNbColumns() = 0; virtual void AddRow(const std::vector& theData) = 0; virtual void SetRow(int theRow, const std::vector& theData) = 0; virtual std::vector GetRow(int theRow) = 0; @@ -59,12 +41,7 @@ public: virtual void SetColumn(int theColumn, const std::vector& theData) = 0; virtual std::vector GetColumn(int theColumn) = 0; virtual void PutValue(const std::string& theValue, int theRow, int theColumn) = 0; - virtual bool HasValue(int theRow, int theColumn) = 0; virtual std::string GetValue(int theRow, int theColumn) = 0; - - virtual std::vector GetRowSetIndices(int theRow) = 0; - virtual void SetNbColumns(int theNbColumns) = 0; - }; -#endif +#endif // SALOMEDSClient_AttributeTableOfString_HeaderFile diff --git a/src/SALOMEDSImpl/Makefile.am b/src/SALOMEDSImpl/Makefile.am index c7c3a2f60..07d8aebee 100644 --- a/src/SALOMEDSImpl/Makefile.am +++ b/src/SALOMEDSImpl/Makefile.am @@ -56,6 +56,7 @@ salomeinclude_HEADERS= \ SALOMEDSImpl_AttributePixMap.hxx \ SALOMEDSImpl_AttributeLocalID.hxx \ SALOMEDSImpl_AttributeTarget.hxx \ + SALOMEDSImpl_AttributeTable.hxx \ SALOMEDSImpl_AttributeTableOfInteger.hxx \ SALOMEDSImpl_AttributeTableOfReal.hxx \ SALOMEDSImpl_AttributeTableOfString.hxx \ @@ -189,6 +190,7 @@ libSalomeDSImpl_la_SOURCES =\ SALOMEDSImpl_AttributeSequenceOfReal.hxx \ SALOMEDSImpl_Attributes.hxx \ SALOMEDSImpl_AttributeStudyProperties.hxx \ + SALOMEDSImpl_AttributeTable.hxx \ SALOMEDSImpl_AttributeTableOfInteger.hxx \ SALOMEDSImpl_AttributeTableOfReal.hxx \ SALOMEDSImpl_AttributeTableOfString.hxx \ diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTable.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTable.hxx new file mode 100644 index 000000000..68b9ec7aa --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTable.hxx @@ -0,0 +1,109 @@ +// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// File : SALOMEDSImpl_AttributeTable.hxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) +// + +#ifndef _SALOMEDSImpl_AttributeTable_HeaderFile +#define _SALOMEDSImpl_AttributeTable_HeaderFile + +#include "SALOMEDSImpl_Defines.hxx" + +class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AttributeTable +{ +public: + //! Sort order + typedef enum { + AscendingOrder, //!< The items are sorted ascending + DescendingOrder, //!< The items are sorted descending + } SortOrder; + + //! Sort policy (specifies how empty cells are taken into account when sorting) + typedef enum { + EmptyLowest, //!< Empty cells are considered as lowest values + EmptyHighest, //!< Empty cells are considered as highest values + EmptyFirst, //!< Empty cells are always first + EmptyLast, //!< Empty cells are always last + EmptyIgnore, //!< Empty cells are ignored (stay at initial positions) + } SortPolicy; +}; + +template class TableSorter +{ + TTable* myTable; + SALOMEDSImpl_AttributeTable::SortOrder mySortOrder; + SALOMEDSImpl_AttributeTable::SortPolicy mySortPolicy; + int myIndex; + bool myIsRow; + +public: + TableSorter( TTable* table, + SALOMEDSImpl_AttributeTable::SortOrder so, + SALOMEDSImpl_AttributeTable::SortPolicy sp, + int index, + bool sortRow) + : myTable( table ), mySortOrder( so ), mySortPolicy( sp ), + myIndex( index ), myIsRow( sortRow ) {} + + bool operator() ( int idx1, int idx2 ) + { + bool hasValue1 = myIsRow ? myTable->HasValue( myIndex, idx1 ) : myTable->HasValue( idx1, myIndex ); + bool hasValue2 = myIsRow ? myTable->HasValue( myIndex, idx2 ) : myTable->HasValue( idx2, myIndex ); + if ( !hasValue1 && !hasValue2 ) { + return false; + } + else if ( !hasValue1 || !hasValue2 ) { + switch ( mySortPolicy ) { + case SALOMEDSImpl_AttributeTable::EmptyLowest: + return (!hasValue1) ? + (mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder) : + (mySortOrder == SALOMEDSImpl_AttributeTable::DescendingOrder); + case SALOMEDSImpl_AttributeTable::EmptyHighest: + return (!hasValue1) ? + (mySortOrder != SALOMEDSImpl_AttributeTable::AscendingOrder) : + (mySortOrder != SALOMEDSImpl_AttributeTable::DescendingOrder); + case SALOMEDSImpl_AttributeTable::EmptyFirst: + return (!hasValue1); + case SALOMEDSImpl_AttributeTable::EmptyLast: + return hasValue1; + case SALOMEDSImpl_AttributeTable::EmptyIgnore: + default: + // should not go here + return false; + } + } + else { + if ( myIsRow ) { + return mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder ? + myTable->GetValue( myIndex, idx1 ) < myTable->GetValue( myIndex, idx2 ) : + myTable->GetValue( myIndex, idx2 ) < myTable->GetValue( myIndex, idx1 ); + } + else { + return mySortOrder == SALOMEDSImpl_AttributeTable::AscendingOrder ? + myTable->GetValue( idx1, myIndex ) < myTable->GetValue( idx2, myIndex ) : + myTable->GetValue( idx2, myIndex ) < myTable->GetValue( idx1, myIndex ); + } + } + } +}; + +#endif // _SALOMEDSImpl_AttributeTable_HeaderFile diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx index 422c84e08..a9eabad01 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx @@ -23,13 +23,14 @@ // Author : Michael Ponikarov // Module : SALOME // + #include "SALOMEDSImpl_AttributeTableOfInteger.hxx" -#include -using namespace std; +#include +#include #define SEPARATOR '\1' -typedef map::const_iterator MI; +typedef std::map::const_iterator MI; static std::string getUnit(std::string theString) { @@ -76,11 +77,10 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetNbColumns(const int theNbColumns) CheckLocked(); Backup(); - map aMap; + std::map aMap; aMap = myTable; myTable.clear(); - for(MI p = aMap.begin(); p != aMap.end(); p++) { int aRow = (int)(p->first/myNbColumns) + 1; int aCol = (int)(p->first - myNbColumns*(aRow-1)); @@ -97,7 +97,6 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetNbColumns(const int theNbColumns) } SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved - } void SALOMEDSImpl_AttributeTableOfInteger::SetTitle(const std::string& theTitle) @@ -105,7 +104,7 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetTitle(const std::string& theTitle) CheckLocked(); Backup(); myTitle = theTitle; - + SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } @@ -115,7 +114,7 @@ std::string SALOMEDSImpl_AttributeTableOfInteger::GetTitle() const } void SALOMEDSImpl_AttributeTableOfInteger::SetRowData(const int theRow, - const vector& theData) + const std::vector& theData) { CheckLocked(); if(theData.size() > myNbColumns) SetNbColumns(theData.size()); @@ -136,9 +135,9 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetRowData(const int theRow, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfInteger::GetRowData(const int theRow) +std::vector SALOMEDSImpl_AttributeTableOfInteger::GetRowData(const int theRow) { - vector aSeq; + std::vector aSeq; int i, aShift = (theRow-1)*myNbColumns; for(i = 1; i <= myNbColumns; i++) { if(myTable.find(aShift+i) != myTable.end()) @@ -155,7 +154,7 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetRowTitle(const int theRow, { CheckLocked(); Backup(); - string aTitle(theTitle), aUnit = GetRowUnit(theRow); + std::string aTitle(theTitle), aUnit = GetRowUnit(theRow); if(aUnit.size()>0) { aTitle += SEPARATOR; aTitle += aUnit; @@ -179,7 +178,7 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetRowUnit(const int theRow, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -void SALOMEDSImpl_AttributeTableOfInteger::SetRowUnits(const vector& theUnits) +void SALOMEDSImpl_AttributeTableOfInteger::SetRowUnits(const std::vector& theUnits) { if (theUnits.size() != GetNbRows()) throw DFexception("Invalid number of rows"); int aLength = theUnits.size(), i; @@ -188,15 +187,15 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetRowUnits(const vector& the SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfInteger::GetRowUnits() +std::vector SALOMEDSImpl_AttributeTableOfInteger::GetRowUnits() { - vector aSeq; + std::vector aSeq; int aLength = myRows.size(), i; for(i=0; i& theTitles) +void SALOMEDSImpl_AttributeTableOfInteger::SetRowTitles(const std::vector& theTitles) { if (theTitles.size() != GetNbRows()) throw DFexception("Invalid number of rows"); int aLength = theTitles.size(), i; @@ -205,29 +204,26 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetRowTitles(const vector& th SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfInteger::GetRowTitles() +std::vector SALOMEDSImpl_AttributeTableOfInteger::GetRowTitles() { - vector aSeq; + std::vector aSeq; int aLength = myRows.size(), i; for(i=0; i& theData) + const std::vector& theData) { CheckLocked(); if(theColumn > myNbColumns) SetNbColumns(theColumn); @@ -250,9 +246,9 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetColumnData(const int theColumn, } -vector SALOMEDSImpl_AttributeTableOfInteger::GetColumnData(const int theColumn) +std::vector SALOMEDSImpl_AttributeTableOfInteger::GetColumnData(const int theColumn) { - vector aSeq; + std::vector aSeq; int i, anIndex; for(i = 1; i <= myNbRows; i++) { anIndex = myNbColumns*(i-1) + theColumn; @@ -266,7 +262,7 @@ vector SALOMEDSImpl_AttributeTableOfInteger::GetColumnData(const int theCol } void SALOMEDSImpl_AttributeTableOfInteger::SetColumnTitle(const int theColumn, - const std::string& theTitle) + const std::string& theTitle) { CheckLocked(); Backup(); @@ -283,7 +279,7 @@ std::string SALOMEDSImpl_AttributeTableOfInteger::GetColumnTitle(const int theCo return myCols[theColumn-1]; } -void SALOMEDSImpl_AttributeTableOfInteger::SetColumnTitles(const vector& theTitles) +void SALOMEDSImpl_AttributeTableOfInteger::SetColumnTitles(const std::vector& theTitles) { if (theTitles.size() != myNbColumns) throw DFexception("Invalid number of columns"); int aLength = theTitles.size(), i; @@ -292,9 +288,9 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetColumnTitles(const vector& SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfInteger::GetColumnTitles() +std::vector SALOMEDSImpl_AttributeTableOfInteger::GetColumnTitles() { - vector aSeq; + std::vector aSeq; int aLength = myCols.size(), i; for(i=0; i myNbColumns) SetNbColumns(theColumn); int anIndex = (theRow-1)*myNbColumns + theColumn; @@ -343,7 +340,7 @@ int SALOMEDSImpl_AttributeTableOfInteger::GetValue(const int theRow, const int theColumn) { if(theRow > myNbRows || theRow < 1) throw DFexception("Invalid cell index"); - if(theColumn > myNbColumns || theColumn < 1) DFexception("Invalid cell index"); + if(theColumn > myNbColumns || theColumn < 1) throw DFexception("Invalid cell index"); int anIndex = (theRow-1)*myNbColumns + theColumn; if(myTable.find(anIndex) != myTable.end()) return myTable[anIndex]; @@ -352,6 +349,20 @@ int SALOMEDSImpl_AttributeTableOfInteger::GetValue(const int theRow, return 0; } +void SALOMEDSImpl_AttributeTableOfInteger::RemoveValue(const int theRow, const int theColumn) +{ + CheckLocked(); + if(theRow > myNbRows || theRow < 1) throw DFexception("Invalid cell index"); + if(theColumn > myNbColumns || theColumn < 1) throw DFexception("Invalid cell index"); + + int anIndex = (theRow-1)*myNbColumns + theColumn; + if (myTable.find(anIndex) != myTable.end()) { + //Backup(); + myTable.erase(anIndex); + SetModifyFlag(); // table is modified + } +} + const std::string& SALOMEDSImpl_AttributeTableOfInteger::ID() const { return GetID(); @@ -405,10 +416,9 @@ void SALOMEDSImpl_AttributeTableOfInteger::Paste(DF_Attribute* into) aTable->myCols.push_back(GetColumnTitle(anIndex)); } - -vector SALOMEDSImpl_AttributeTableOfInteger::GetSetRowIndices(const int theRow) +std::vector SALOMEDSImpl_AttributeTableOfInteger::GetSetRowIndices(const int theRow) { - vector aSeq; + std::vector aSeq; int i, aShift = myNbColumns*(theRow-1); for(i = 1; i <= myNbColumns; i++) { @@ -418,9 +428,9 @@ vector SALOMEDSImpl_AttributeTableOfInteger::GetSetRowIndices(const int the return aSeq; } -vector SALOMEDSImpl_AttributeTableOfInteger::GetSetColumnIndices(const int theColumn) +std::vector SALOMEDSImpl_AttributeTableOfInteger::GetSetColumnIndices(const int theColumn) { - vector aSeq; + std::vector aSeq; int i, anIndex; for(i = 1; i <= myNbRows; i++) { @@ -431,10 +441,9 @@ vector SALOMEDSImpl_AttributeTableOfInteger::GetSetColumnIndices(const int return aSeq; } - -string SALOMEDSImpl_AttributeTableOfInteger::Save() +std::string SALOMEDSImpl_AttributeTableOfInteger::Save() { - string aString; + std::string aString; char* buffer = new char[1024]; int i, j, l; @@ -490,11 +499,9 @@ string SALOMEDSImpl_AttributeTableOfInteger::Save() return aString; } - - -void SALOMEDSImpl_AttributeTableOfInteger::Load(const string& value) +void SALOMEDSImpl_AttributeTableOfInteger::Load(const std::string& value) { - vector v; + std::vector v; int i, j, l, pos, aSize = (int)value.size(); for(i = 0, pos = 0; i 0 && theRow <= myNbRows ) { + std::vector indices( myNbColumns ); + int cnt = 0; + for ( int i = 0; i < myNbColumns; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(theRow, i+1) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theRow, true ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbColumns ); + cnt = 0; + for( int i = 0; i < myNbColumns; i++ ) + other[i] = HasValue(theRow, i+1) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int col = 0; col < indices.size(); col++ ) { + int idx = indices[col]; + if ( col+1 == idx ) continue; + SwapCells(theRow, col+1, theRow, idx); + int idx1 = 0; + for ( int i = col+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == col+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapCells() + } +} + +void SALOMEDSImpl_AttributeTableOfInteger::SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theColumn > 0 && theColumn <= myNbColumns ) { + std::vector indices( myNbRows ); + int cnt = 0; + for ( int i = 0; i < myNbRows; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(i+1, theColumn) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theColumn, false ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbRows ); + cnt = 0; + for( int i = 0; i < myNbRows; i++ ) + other[i] = HasValue(i+1, theColumn) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int row = 0; row < indices.size(); row++ ) { + int idx = indices[row]; + if ( row+1 == idx ) continue; + SwapCells(row+1, theColumn, idx, theColumn); + int idx1 = 0; + for ( int i = row+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == row+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapCells() + } +} + +void SALOMEDSImpl_AttributeTableOfInteger::SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theRow > 0 && theRow <= myNbRows ) { + std::vector indices( myNbColumns ); + int cnt = 0; + for ( int i = 0; i < myNbColumns; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(theRow, i+1) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theRow, true ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbColumns ); + cnt = 0; + for( int i = 0; i < myNbColumns; i++ ) + other[i] = HasValue(theRow, i+1) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int col = 0; col < indices.size(); col++ ) { + int idx = indices[col]; + if ( col+1 == idx ) continue; + SwapColumns(col+1, idx); + int idx1 = 0; + for ( int i = col+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == col+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapColumns() + } +} + +void SALOMEDSImpl_AttributeTableOfInteger::SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theColumn > 0 && theColumn <= myNbColumns ) { + std::vector indices( myNbRows ); + int cnt = 0; + for ( int i = 0; i < myNbRows; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(i+1, theColumn) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theColumn, false ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbRows ); + cnt = 0; + for( int i = 0; i < myNbRows; i++ ) + other[i] = HasValue(i+1, theColumn) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int row = 0; row < indices.size(); row++ ) { + int idx = indices[row]; + if ( row+1 == idx ) continue; + SwapRows(row+1, idx); + int idx1 = 0; + for ( int i = row+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == row+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapRows() + } +} + +void SALOMEDSImpl_AttributeTableOfInteger::SwapCells(const int theRow1, const int theColumn1, + const int theRow2, const int theColumn2) +{ + CheckLocked(); + if (theRow1 > myNbRows || theRow1 < 1) throw DFexception("Invalid cell index"); + if (theRow2 > myNbRows || theRow2 < 1) throw DFexception("Invalid cell index"); + if (theColumn1 > myNbColumns || theColumn1 < 1) throw DFexception("Invalid cell index"); + if (theColumn2 > myNbColumns || theColumn2 < 1) throw DFexception("Invalid cell index"); + + int anIndex1 = (theRow1-1)*myNbColumns + theColumn1; + int anIndex2 = (theRow2-1)*myNbColumns + theColumn2; + + bool hasValue1 = myTable.find(anIndex1) != myTable.end(); + bool hasValue2 = myTable.find(anIndex2) != myTable.end(); + + if (!hasValue1 && !hasValue2) return; // nothing changed + + int value1 = hasValue1 ? myTable[anIndex1] : 0; + int value2 = hasValue2 ? myTable[anIndex2] : 0; + + if (hasValue1 && hasValue2 && value1 == value2) return; // nothing changed + + if (hasValue1) myTable[anIndex2] = value1; + else myTable.erase(anIndex2); + if (hasValue2) myTable[anIndex1] = value2; + else myTable.erase(anIndex1); + + SetModifyFlag(); // table is modified +} + +void SALOMEDSImpl_AttributeTableOfInteger::SwapRows(const int theRow1, const int theRow2) +{ + CheckLocked(); + for (int i = 1; i <= myNbColumns; i++) + SwapCells(theRow1, i, theRow2, i); + // no need for SetModifyFlag(), since it is done by SwapCells() +} + +void SALOMEDSImpl_AttributeTableOfInteger::SwapColumns(const int theColumn1, const int theColumn2) +{ + CheckLocked(); + for (int i = 1; i <= myNbRows; i++) + SwapCells(i, theColumn1, i, theColumn2); + // no need for SetModifyFlag(), since it is done by SwapCells() +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx index dd80b1ba9..c423c2ae4 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx @@ -31,6 +31,7 @@ #include "DF_Attribute.hxx" #include "DF_Label.hxx" #include "SALOMEDSImpl_GenericAttribute.hxx" +#include "SALOMEDSImpl_AttributeTable.hxx" #include #include @@ -38,59 +39,70 @@ class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AttributeTableOfInteger : - public SALOMEDSImpl_GenericAttribute + public SALOMEDSImpl_GenericAttribute, public SALOMEDSImpl_AttributeTable { public: - virtual std::string Save(); - virtual void Load(const std::string&); - static const std::string& GetID() ; - static SALOMEDSImpl_AttributeTableOfInteger* Set(const DF_Label& label) ; + virtual std::string Save(); + virtual void Load(const std::string&); + + static const std::string& GetID(); + static SALOMEDSImpl_AttributeTableOfInteger* Set(const DF_Label& label); + SALOMEDSImpl_AttributeTableOfInteger(); - void SetNbColumns(const int theNbColumns); - void SetTitle(const std::string& theTitle) ; - std::string GetTitle() const; - void SetRowData(const int theRow,const std::vector& theData) ; - std::vector GetRowData(const int theRow) ; - void SetRowTitle(const int theRow,const std::string& theTitle) ; - void SetRowUnit(const int theRow,const std::string& theUnit) ; - std::string GetRowUnit(const int theRow) const; - void SetRowUnits(const std::vector& theUnits) ; + + void SetNbColumns(const int theNbColumns); + void SetTitle(const std::string& theTitle); + std::string GetTitle() const; + void SetRowData(const int theRow, const std::vector& theData); + std::vector GetRowData(const int theRow); + void SetRowTitle(const int theRow, const std::string& theTitle); + void SetRowUnit(const int theRow, const std::string& theUnit); + std::string GetRowUnit(const int theRow) const; + void SetRowUnits(const std::vector& theUnits); std::vector GetRowUnits(); - void SetRowTitles(const std::vector& theTitles) ; + void SetRowTitles(const std::vector& theTitles); std::vector GetRowTitles(); - std::string GetRowTitle(const int theRow) const; - void SetColumnData(const int theColumn,const std::vector& theData) ; - std::vector GetColumnData(const int theColumn) ; - void SetColumnTitle(const int theColumn,const std::string& theTitle) ; - std::string GetColumnTitle(const int theColumn) const; - void SetColumnTitles(const std::vector& theTitles); + std::string GetRowTitle(const int theRow) const; + void SetColumnData(const int theColumn, const std::vector& theData); + std::vector GetColumnData(const int theColumn); + void SetColumnTitle(const int theColumn, const std::string& theTitle); + std::string GetColumnTitle(const int theColumn) const; + void SetColumnTitles(const std::vector& theTitles); std::vector GetColumnTitles(); - int GetNbRows() const; - int GetNbColumns() const; + int GetNbRows() const; + int GetNbColumns() const; + + void PutValue(const int theValue, const int theRow, const int theColumn); + bool HasValue(const int theRow, const int theColumn); + int GetValue(const int theRow, const int theColumn); + void RemoveValue(const int theRow, const int theColumn); + const std::string& ID() const; + void Restore(DF_Attribute* with); + DF_Attribute* NewEmpty() const; + void Paste(DF_Attribute* into); + + std::vector GetSetRowIndices(const int theRow); + std::vector GetSetColumnIndices(const int theColumn); - void PutValue(const int theValue,const int theRow,const int theColumn) ; - bool HasValue(const int theRow,const int theColumn) ; - int GetValue(const int theRow,const int theColumn) ; - const std::string& ID() const; - void Restore(DF_Attribute* with) ; - DF_Attribute* NewEmpty() const; - void Paste(DF_Attribute* into); + void SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + void SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); + void SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + void SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); - std::vector GetSetRowIndices(const int theRow); - std::vector GetSetColumnIndices(const int theColumn); + void SwapCells(const int theRow1, const int theColumn1, const int theRow2, const int theColumn2); + void SwapRows(const int theRow1, const int theRow2); + void SwapColumns(const int theColumn1, const int theColumn2); ~SALOMEDSImpl_AttributeTableOfInteger() {} private: - - std::map myTable; - std::string myTitle; + std::map myTable; + std::string myTitle; std::vector myRows; std::vector myCols; - int myNbRows; - int myNbColumns; - + int myNbRows; + int myNbColumns; }; #endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx index 081dcad36..e2bf63fdc 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx @@ -23,12 +23,13 @@ // Author : Michael Ponikarov // Module : SALOME // + #include "SALOMEDSImpl_AttributeTableOfReal.hxx" -#include + #include +#include #define SEPARATOR '\1' - typedef std::map::const_iterator MI; static std::string getUnit(const std::string& theString) @@ -145,7 +146,6 @@ std::vector SALOMEDSImpl_AttributeTableOfReal::GetRowData(const int theR return aSeq; } - void SALOMEDSImpl_AttributeTableOfReal::SetRowTitle(const int theRow, const std::string& theTitle) { @@ -209,7 +209,6 @@ std::vector SALOMEDSImpl_AttributeTableOfReal::GetRowTitles() return aSeq; } - std::string SALOMEDSImpl_AttributeTableOfReal::GetRowTitle(const int theRow) const { return getTitle(myRows[theRow-1]); @@ -244,7 +243,6 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnData(const int theColumn, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } - std::vector SALOMEDSImpl_AttributeTableOfReal::GetColumnData(const int theColumn) { std::vector aSeq; @@ -311,6 +309,7 @@ void SALOMEDSImpl_AttributeTableOfReal::PutValue(const double& theValue, const int theColumn) { CheckLocked(); + //Backup(); if(theColumn > myNbColumns) SetNbColumns(theColumn); int anIndex = (theRow-1)*myNbColumns + theColumn; @@ -348,6 +347,20 @@ double SALOMEDSImpl_AttributeTableOfReal::GetValue(const int theRow, return 0.; } +void SALOMEDSImpl_AttributeTableOfReal::RemoveValue(const int theRow, const int theColumn) +{ + CheckLocked(); + if(theRow > myNbRows || theRow < 1) throw DFexception("Invalid cell index"); + if(theColumn > myNbColumns || theColumn < 1) throw DFexception("Invalid cell index"); + + int anIndex = (theRow-1)*myNbColumns + theColumn; + if (myTable.find(anIndex) != myTable.end()) { + //Backup(); + myTable.erase(anIndex); + SetModifyFlag(); // table is modified + } +} + const std::string& SALOMEDSImpl_AttributeTableOfReal::ID() const { return GetID(); @@ -401,7 +414,6 @@ void SALOMEDSImpl_AttributeTableOfReal::Paste(DF_Attribute* into) aTable->myCols.push_back(GetColumnTitle(anIndex)); } - std::vector SALOMEDSImpl_AttributeTableOfReal::GetSetRowIndices(const int theRow) { std::vector aSeq; @@ -547,3 +559,198 @@ void SALOMEDSImpl_AttributeTableOfReal::Load(const std::string& value) } } + +void SALOMEDSImpl_AttributeTableOfReal::SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theRow > 0 && theRow <= myNbRows ) { + std::vector indices( myNbColumns ); + int cnt = 0; + for ( int i = 0; i < myNbColumns; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(theRow, i+1) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theRow, true ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbColumns ); + cnt = 0; + for( int i = 0; i < myNbColumns; i++ ) + other[i] = HasValue(theRow, i+1) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int col = 0; col < indices.size(); col++ ) { + int idx = indices[col]; + if ( col+1 == idx ) continue; + SwapCells(theRow, col+1, theRow, idx); + int idx1 = 0; + for ( int i = col+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == col+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapCells() + } +} + +void SALOMEDSImpl_AttributeTableOfReal::SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theColumn > 0 && theColumn <= myNbColumns ) { + std::vector indices( myNbRows ); + int cnt = 0; + for ( int i = 0; i < myNbRows; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(i+1, theColumn) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theColumn, false ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbRows ); + cnt = 0; + for( int i = 0; i < myNbRows; i++ ) + other[i] = HasValue(i+1, theColumn) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int row = 0; row < indices.size(); row++ ) { + int idx = indices[row]; + if ( row+1 == idx ) continue; + SwapCells(row+1, theColumn, idx, theColumn); + int idx1 = 0; + for ( int i = row+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == row+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapCells() + } +} + +void SALOMEDSImpl_AttributeTableOfReal::SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theRow > 0 && theRow <= myNbRows ) { + std::vector indices( myNbColumns ); + int cnt = 0; + for ( int i = 0; i < myNbColumns; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(theRow, i+1) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theRow, true ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbColumns ); + cnt = 0; + for( int i = 0; i < myNbColumns; i++ ) + other[i] = HasValue(theRow, i+1) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int col = 0; col < indices.size(); col++ ) { + int idx = indices[col]; + if ( col+1 == idx ) continue; + SwapColumns(col+1, idx); + int idx1 = 0; + for ( int i = col+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == col+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapColumns() + } +} + +void SALOMEDSImpl_AttributeTableOfReal::SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theColumn > 0 && theColumn <= myNbColumns ) { + std::vector indices( myNbRows ); + int cnt = 0; + for ( int i = 0; i < myNbRows; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(i+1, theColumn) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theColumn, false ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbRows ); + cnt = 0; + for( int i = 0; i < myNbRows; i++ ) + other[i] = HasValue(i+1, theColumn) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int row = 0; row < indices.size(); row++ ) { + int idx = indices[row]; + if ( row+1 == idx ) continue; + SwapRows(row+1, idx); + int idx1 = 0; + for ( int i = row+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == row+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapRows() + } +} + +void SALOMEDSImpl_AttributeTableOfReal::SwapCells(const int theRow1, const int theColumn1, + const int theRow2, const int theColumn2) +{ + CheckLocked(); + if (theRow1 > myNbRows || theRow1 < 1) throw DFexception("Invalid cell index"); + if (theRow2 > myNbRows || theRow2 < 1) throw DFexception("Invalid cell index"); + if (theColumn1 > myNbColumns || theColumn1 < 1) throw DFexception("Invalid cell index"); + if (theColumn2 > myNbColumns || theColumn2 < 1) throw DFexception("Invalid cell index"); + + int anIndex1 = (theRow1-1)*myNbColumns + theColumn1; + int anIndex2 = (theRow2-1)*myNbColumns + theColumn2; + + bool hasValue1 = myTable.find(anIndex1) != myTable.end(); + bool hasValue2 = myTable.find(anIndex2) != myTable.end(); + + if (!hasValue1 && !hasValue2) return; // nothing changed + + double value1 = hasValue1 ? myTable[anIndex1] : 0; + double value2 = hasValue2 ? myTable[anIndex2] : 0; + + if (hasValue1 && hasValue2 && value1 == value2) return; // nothing changed + + if (hasValue1) myTable[anIndex2] = value1; + else myTable.erase(anIndex2); + if (hasValue2) myTable[anIndex1] = value2; + else myTable.erase(anIndex1); + + SetModifyFlag(); // table is modified +} + +void SALOMEDSImpl_AttributeTableOfReal::SwapRows(const int theRow1, const int theRow2) +{ + CheckLocked(); + for (int i = 1; i <= myNbColumns; i++) + SwapCells(theRow1, i, theRow2, i); + // no need for SetModifyFlag(), since it is done by SwapCells() +} + +void SALOMEDSImpl_AttributeTableOfReal::SwapColumns(const int theColumn1, const int theColumn2) +{ + CheckLocked(); + for (int i = 1; i <= myNbRows; i++) + SwapCells(i, theColumn1, i, theColumn2); + // no need for SetModifyFlag(), since it is done by SwapCells() +} + diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx index 17838b39c..9c38bdbd5 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx @@ -31,64 +31,77 @@ #include "DF_Attribute.hxx" #include "DF_Label.hxx" #include "SALOMEDSImpl_GenericAttribute.hxx" +#include "SALOMEDSImpl_AttributeTable.hxx" #include #include #include class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AttributeTableOfReal : - public SALOMEDSImpl_GenericAttribute + public SALOMEDSImpl_GenericAttribute, public SALOMEDSImpl_AttributeTable { public: - virtual std::string Save(); - virtual void Load(const std::string&); - static const std::string& GetID() ; - static SALOMEDSImpl_AttributeTableOfReal* Set(const DF_Label& label) ; + virtual std::string Save(); + virtual void Load(const std::string&); + + static const std::string& GetID(); + static SALOMEDSImpl_AttributeTableOfReal* Set(const DF_Label& label); + SALOMEDSImpl_AttributeTableOfReal(); - void SetNbColumns(const int theNbColumns); - void SetTitle(const std::string& theTitle) ; - std::string GetTitle() const; - void SetRowData(const int theRow,const std::vector& theData) ; - std::vector GetRowData(const int theRow) ; - void SetRowTitle(const int theRow,const std::string& theTitle) ; - void SetRowUnit(const int theRow,const std::string& theUnit) ; - std::string GetRowUnit(const int theRow) const; - void SetRowUnits(const std::vector& theUnits) ; + + void SetNbColumns(const int theNbColumns); + void SetTitle(const std::string& theTitle); + std::string GetTitle() const; + void SetRowData(const int theRow, const std::vector& theData); + std::vector GetRowData(const int theRow); + void SetRowTitle(const int theRow, const std::string& theTitle); + void SetRowUnit(const int theRow, const std::string& theUnit); + std::string GetRowUnit(const int theRow) const; + void SetRowUnits(const std::vector& theUnits); std::vector GetRowUnits(); - void SetRowTitles(const std::vector& theTitles) ; + void SetRowTitles(const std::vector& theTitles); std::vector GetRowTitles(); - std::string GetRowTitle(const int theRow) const; - void SetColumnData(const int theColumn,const std::vector& theData) ; - std::vector GetColumnData(const int theColumn) ; - void SetColumnTitle(const int theColumn,const std::string& theTitle) ; - void SetColumnTitles(const std::vector& theTitles); + std::string GetRowTitle(const int theRow) const; + void SetColumnData(const int theColumn, const std::vector& theData); + std::vector GetColumnData(const int theColumn); + void SetColumnTitle(const int theColumn, const std::string& theTitle); + void SetColumnTitles(const std::vector& theTitles); std::vector GetColumnTitles(); - std::string GetColumnTitle(const int theColumn) const; - int GetNbRows() const; - int GetNbColumns() const; + std::string GetColumnTitle(const int theColumn) const; + int GetNbRows() const; + int GetNbColumns() const; - void PutValue(const double& theValue,const int theRow,const int theColumn) ; - bool HasValue(const int theRow,const int theColumn) ; - double GetValue(const int theRow,const int theColumn) ; - const std::string& ID() const; - void Restore(DF_Attribute* with) ; - DF_Attribute* NewEmpty() const; - void Paste(DF_Attribute* into); + void PutValue(const double& theValue, const int theRow, const int theColumn); + bool HasValue(const int theRow, const int theColumn); + double GetValue(const int theRow, const int theColumn); + void RemoveValue(const int theRow, const int theColumn); + const std::string& ID() const; + void Restore(DF_Attribute* with); + DF_Attribute* NewEmpty() const; + void Paste(DF_Attribute* into); - std::vector GetSetRowIndices(const int theRow); - std::vector GetSetColumnIndices(const int theColumn); + std::vector GetSetRowIndices(const int theRow); + std::vector GetSetColumnIndices(const int theColumn); + + void SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + void SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); + void SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + void SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); + + void SwapCells(const int theRow1, const int theColumn1, const int theRow2, const int theColumn2); + void SwapRows(const int theRow1, const int theRow2); + void SwapColumns(const int theColumn1, const int theColumn2); ~SALOMEDSImpl_AttributeTableOfReal() {} private: - std::map myTable; - std::string myTitle; + std::map myTable; + std::string myTitle; std::vector myRows; std::vector myCols; - int myNbRows; - int myNbColumns; - + int myNbRows; + int myNbColumns; }; #endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx index 1644f41bc..a111d8e30 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx @@ -23,16 +23,14 @@ // Author : Sergey Ruin // Module : SALOME // + #include "SALOMEDSImpl_AttributeTableOfString.hxx" -#include -#include -#include -using namespace std; +#include +#include #define SEPARATOR '\1' - -typedef map::const_iterator MI; +typedef std::map::const_iterator MI; static std::string getUnit(std::string theString) { @@ -79,7 +77,7 @@ void SALOMEDSImpl_AttributeTableOfString::SetNbColumns(const int theNbColumns) CheckLocked(); Backup(); - map aMap; + std::map aMap; aMap = myTable; myTable.clear(); @@ -130,22 +128,22 @@ void SALOMEDSImpl_AttributeTableOfString::SetRowUnit(const int theRow, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -void SALOMEDSImpl_AttributeTableOfString::SetRowUnits(const vector& theUnits) +void SALOMEDSImpl_AttributeTableOfString::SetRowUnits(const std::vector& theUnits) { if (theUnits.size() != GetNbRows()) throw DFexception("Invalid number of rows"); int aLength = theUnits.size(), i; for(i = 1; i <= aLength; i++) SetRowUnit(i, theUnits[i-1]); } -vector SALOMEDSImpl_AttributeTableOfString::GetRowUnits() +std::vector SALOMEDSImpl_AttributeTableOfString::GetRowUnits() { - vector aSeq; + std::vector aSeq; int aLength = myRows.size(), i; for(i=0; i& theTitles) +void SALOMEDSImpl_AttributeTableOfString::SetRowTitles(const std::vector& theTitles) { if (theTitles.size() != GetNbRows()) throw DFexception("Invalid number of rows"); int aLength = theTitles.size(), i; @@ -154,28 +152,26 @@ void SALOMEDSImpl_AttributeTableOfString::SetRowTitles(const vector& the SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfString::GetRowTitles() +std::vector SALOMEDSImpl_AttributeTableOfString::GetRowTitles() { - vector aSeq; + std::vector aSeq; int aLength = myRows.size(), i; for(i=0; i& theData) + const std::vector& theData) { CheckLocked(); if(theData.size() > myNbColumns) SetNbColumns(theData.size()); @@ -210,9 +206,9 @@ std::string SALOMEDSImpl_AttributeTableOfString::GetTitle() const return myTitle; } -vector SALOMEDSImpl_AttributeTableOfString::GetRowData(const int theRow) +std::vector SALOMEDSImpl_AttributeTableOfString::GetRowData(const int theRow) { - vector aSeq; + std::vector aSeq; int i, aShift = (theRow-1)*myNbColumns; for(i = 1; i <= myNbColumns; i++) { if(myTable.find(aShift+i) != myTable.end()) @@ -225,7 +221,7 @@ vector SALOMEDSImpl_AttributeTableOfString::GetRowData(const int theRow) } void SALOMEDSImpl_AttributeTableOfString::SetColumnData(const int theColumn, - const vector& theData) + const std::vector& theData) { CheckLocked(); if(theColumn > myNbColumns) SetNbColumns(theColumn); @@ -247,10 +243,9 @@ void SALOMEDSImpl_AttributeTableOfString::SetColumnData(const int theColumn, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } - -vector SALOMEDSImpl_AttributeTableOfString::GetColumnData(const int theColumn) +std::vector SALOMEDSImpl_AttributeTableOfString::GetColumnData(const int theColumn) { - vector aSeq; + std::vector aSeq; int i, anIndex; for(i = 1; i <= myNbRows; i++) { @@ -282,8 +277,7 @@ std::string SALOMEDSImpl_AttributeTableOfString::GetColumnTitle(const int theCol return myCols[theColumn-1]; } - -void SALOMEDSImpl_AttributeTableOfString::SetColumnTitles(const vector& theTitles) +void SALOMEDSImpl_AttributeTableOfString::SetColumnTitles(const std::vector& theTitles) { if (theTitles.size() != myNbColumns) throw DFexception("Invalid number of columns"); int aLength = theTitles.size(), i; @@ -292,15 +286,14 @@ void SALOMEDSImpl_AttributeTableOfString::SetColumnTitles(const vector& SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfString::GetColumnTitles() +std::vector SALOMEDSImpl_AttributeTableOfString::GetColumnTitles() { - vector aSeq; + std::vector aSeq; int aLength = myCols.size(), i; for(i=0; i myNbColumns) SetNbColumns(theColumn); int anIndex = (theRow-1)*myNbColumns + theColumn; @@ -354,6 +348,20 @@ std::string SALOMEDSImpl_AttributeTableOfString::GetValue(const int theRow, return ""; } +void SALOMEDSImpl_AttributeTableOfString::RemoveValue(const int theRow, const int theColumn) +{ + CheckLocked(); + if(theRow > myNbRows || theRow < 1) throw DFexception("Invalid cell index"); + if(theColumn > myNbColumns || theColumn < 1) throw DFexception("Invalid cell index"); + + int anIndex = (theRow-1)*myNbColumns + theColumn; + if (myTable.find(anIndex) != myTable.end()) { + //Backup(); + myTable.erase(anIndex); + SetModifyFlag(); // table is modified + } +} + const std::string& SALOMEDSImpl_AttributeTableOfString::ID() const { return GetID(); @@ -405,10 +413,9 @@ void SALOMEDSImpl_AttributeTableOfString::Paste(DF_Attribute* into) aTable->myCols.push_back(GetColumnTitle(anIndex)); } - -vector SALOMEDSImpl_AttributeTableOfString::GetSetRowIndices(const int theRow) +std::vector SALOMEDSImpl_AttributeTableOfString::GetSetRowIndices(const int theRow) { - vector aSeq; + std::vector aSeq; int i, aShift = myNbColumns*(theRow-1); for(i = 1; i <= myNbColumns; i++) { @@ -418,9 +425,9 @@ vector SALOMEDSImpl_AttributeTableOfString::GetSetRowIndices(const int theR return aSeq; } -vector SALOMEDSImpl_AttributeTableOfString::GetSetColumnIndices(const int theColumn) +std::vector SALOMEDSImpl_AttributeTableOfString::GetSetColumnIndices(const int theColumn) { - vector aSeq; + std::vector aSeq; int i, anIndex; for(i = 1; i <= myNbRows; i++) { @@ -431,11 +438,9 @@ vector SALOMEDSImpl_AttributeTableOfString::GetSetColumnIndices(const int t return aSeq; } - - -string SALOMEDSImpl_AttributeTableOfString::Save() +std::string SALOMEDSImpl_AttributeTableOfString::Save() { - string aString; + std::string aString; char* buffer = new char[1024]; int i, j, l; @@ -501,9 +506,9 @@ string SALOMEDSImpl_AttributeTableOfString::Save() return aString; } -void SALOMEDSImpl_AttributeTableOfString::Load(const string& value) +void SALOMEDSImpl_AttributeTableOfString::Load(const std::string& value) { - vector v; + std::vector v; int i, j, l, pos, aSize = (int)value.size(); for(i = 0, pos = 0; i 0 && theRow <= myNbRows ) { + std::vector indices( myNbColumns ); + int cnt = 0; + for ( int i = 0; i < myNbColumns; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(theRow, i+1) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theRow, true ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbColumns ); + cnt = 0; + for( int i = 0; i < myNbColumns; i++ ) + other[i] = HasValue(theRow, i+1) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int col = 0; col < indices.size(); col++ ) { + int idx = indices[col]; + if ( col+1 == idx ) continue; + SwapCells(theRow, col+1, theRow, idx); + int idx1 = 0; + for ( int i = col+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == col+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapCells() + } +} + +void SALOMEDSImpl_AttributeTableOfString::SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theColumn > 0 && theColumn <= myNbColumns ) { + std::vector indices( myNbRows ); + int cnt = 0; + for ( int i = 0; i < myNbRows; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(i+1, theColumn) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theColumn, false ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbRows ); + cnt = 0; + for( int i = 0; i < myNbRows; i++ ) + other[i] = HasValue(i+1, theColumn) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int row = 0; row < indices.size(); row++ ) { + int idx = indices[row]; + if ( row+1 == idx ) continue; + SwapCells(row+1, theColumn, idx, theColumn); + int idx1 = 0; + for ( int i = row+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == row+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapCells() + } +} + +void SALOMEDSImpl_AttributeTableOfString::SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theRow > 0 && theRow <= myNbRows ) { + std::vector indices( myNbColumns ); + int cnt = 0; + for ( int i = 0; i < myNbColumns; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(theRow, i+1) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theRow, true ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbColumns ); + cnt = 0; + for( int i = 0; i < myNbColumns; i++ ) + other[i] = HasValue(theRow, i+1) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int col = 0; col < indices.size(); col++ ) { + int idx = indices[col]; + if ( col+1 == idx ) continue; + SwapColumns(col+1, idx); + int idx1 = 0; + for ( int i = col+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == col+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapColumns() + } +} + +void SALOMEDSImpl_AttributeTableOfString::SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + if ( theColumn > 0 && theColumn <= myNbColumns ) { + std::vector indices( myNbRows ); + int cnt = 0; + for ( int i = 0; i < myNbRows; i++ ) { + if ( sortPolicy != EmptyIgnore || HasValue(i+1, theColumn) ) { + indices[cnt++] = i+1; + } + } + indices.resize(cnt); + + TableSorter sorter( this, sortOrder, sortPolicy, theColumn, false ); + std::stable_sort( indices.begin(), indices.end(), sorter ); + + if ( sortPolicy == EmptyIgnore ) { + std::vector other( myNbRows ); + cnt = 0; + for( int i = 0; i < myNbRows; i++ ) + other[i] = HasValue(i+1, theColumn) ? indices[cnt++] : i+1; + indices = other; + } + + for ( int row = 0; row < indices.size(); row++ ) { + int idx = indices[row]; + if ( row+1 == idx ) continue; + SwapRows(row+1, idx); + int idx1 = 0; + for ( int i = row+1; i < indices.size() && idx1 == 0; i++) + if ( indices[i] == row+1 ) idx1 = i; + indices[idx1] = idx; + } + // no need for SetModifyFlag(), since it is done by SwapRows() + } +} + +void SALOMEDSImpl_AttributeTableOfString::SwapCells(const int theRow1, const int theColumn1, + const int theRow2, const int theColumn2) +{ + CheckLocked(); + if (theRow1 > myNbRows || theRow1 < 1) throw DFexception("Invalid cell index"); + if (theRow2 > myNbRows || theRow2 < 1) throw DFexception("Invalid cell index"); + if (theColumn1 > myNbColumns || theColumn1 < 1) throw DFexception("Invalid cell index"); + if (theColumn2 > myNbColumns || theColumn2 < 1) throw DFexception("Invalid cell index"); + + int anIndex1 = (theRow1-1)*myNbColumns + theColumn1; + int anIndex2 = (theRow2-1)*myNbColumns + theColumn2; + + bool hasValue1 = myTable.find(anIndex1) != myTable.end(); + bool hasValue2 = myTable.find(anIndex2) != myTable.end(); + + if (!hasValue1 && !hasValue2) return; // nothing changed + + std::string value1 = hasValue1 ? myTable[anIndex1] : 0; + std::string value2 = hasValue2 ? myTable[anIndex2] : 0; + + if (hasValue1 && hasValue2 && value1 == value2) return; // nothing changed + + if (hasValue1) myTable[anIndex2] = value1; + else myTable.erase(anIndex2); + if (hasValue2) myTable[anIndex1] = value2; + else myTable.erase(anIndex1); + + SetModifyFlag(); // table is modified +} + +void SALOMEDSImpl_AttributeTableOfString::SwapRows(const int theRow1, const int theRow2) +{ + CheckLocked(); + for (int i = 1; i <= myNbColumns; i++) + SwapCells(theRow1, i, theRow2, i); + // no need for SetModifyFlag(), since it is done by SwapCells() +} + +void SALOMEDSImpl_AttributeTableOfString::SwapColumns(const int theColumn1, const int theColumn2) +{ + CheckLocked(); + for (int i = 1; i <= myNbRows; i++) + SwapCells(i, theColumn1, i, theColumn2); + // no need for SetModifyFlag(), since it is done by SwapCells() +} diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx index 121ee4fee..db46dc38e 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx @@ -31,65 +31,76 @@ #include "DF_Label.hxx" #include "DF_Attribute.hxx" #include "SALOMEDSImpl_GenericAttribute.hxx" +#include "SALOMEDSImpl_AttributeTable.hxx" #include #include #include class SALOMEDSIMPL_EXPORT SALOMEDSImpl_AttributeTableOfString : - public SALOMEDSImpl_GenericAttribute + public SALOMEDSImpl_GenericAttribute, public SALOMEDSImpl_AttributeTable { public: - virtual std::string Save(); - virtual void Load(const std::string&); - static const std::string& GetID() ; - static SALOMEDSImpl_AttributeTableOfString* Set(const DF_Label& label) ; + virtual std::string Save(); + virtual void Load(const std::string&); + + static const std::string& GetID(); + static SALOMEDSImpl_AttributeTableOfString* Set(const DF_Label& label); + SALOMEDSImpl_AttributeTableOfString(); - void SetNbColumns(const int theNbColumns); - void SetTitle(const std::string& theTitle) ; - std::string GetTitle() const; - void SetRowData(const int theRow,const std::vector& theData) ; - std::vector GetRowData(const int theRow) ; - void SetRowTitle(const int theRow,const std::string& theTitle) ; - void SetRowUnit(const int theRow,const std::string& theUnit) ; - std::string GetRowUnit(const int theRow) const; - void SetRowUnits(const std::vector& theUnits) ; + void SetNbColumns(const int theNbColumns); + void SetTitle(const std::string& theTitle); + std::string GetTitle() const; + void SetRowData(const int theRow, const std::vector& theData); + std::vector GetRowData(const int theRow); + void SetRowTitle(const int theRow, const std::string& theTitle); + void SetRowUnit(const int theRow, const std::string& theUnit); + std::string GetRowUnit(const int theRow) const; + void SetRowUnits(const std::vector& theUnits); std::vector GetRowUnits(); - void SetRowTitles(const std::vector& theTitles) ; + void SetRowTitles(const std::vector& theTitles); std::vector GetRowTitles(); - std::string GetRowTitle(const int theRow) const; - void SetColumnData(const int theColumn,const std::vector& theData) ; - std::vector GetColumnData(const int theColumn) ; - void SetColumnTitle(const int theColumn,const std::string& theTitle) ; - std::string GetColumnTitle(const int theColumn) const; - void SetColumnTitles(const std::vector& theTitles); + std::string GetRowTitle(const int theRow) const; + void SetColumnData(const int theColumn, const std::vector& theData); + std::vector GetColumnData(const int theColumn); + void SetColumnTitle(const int theColumn, const std::string& theTitle); + std::string GetColumnTitle(const int theColumn) const; + void SetColumnTitles(const std::vector& theTitles); std::vector GetColumnTitles(); - int GetNbRows() const; - int GetNbColumns() const; + int GetNbRows() const; + int GetNbColumns() const; + + void PutValue(const std::string& theValue, const int theRow, const int theColumn); + bool HasValue(const int theRow, const int theColumn); + std::string GetValue(const int theRow, const int theColumn); + void RemoveValue(const int theRow, const int theColumn); + const std::string& ID() const; + void Restore(DF_Attribute* with); + DF_Attribute* NewEmpty() const; + void Paste(DF_Attribute* into); - void PutValue(const std::string& theValue,const int theRow,const int theColumn) ; - bool HasValue(const int theRow,const int theColumn) ; - std::string GetValue(const int theRow,const int theColumn) ; - const std::string& ID() const; - void Restore(DF_Attribute* with) ; - DF_Attribute* NewEmpty() const; - void Paste(DF_Attribute* into); + std::vector GetSetRowIndices(const int theRow); + std::vector GetSetColumnIndices(const int theColumn); - std::vector GetSetRowIndices(const int theRow); - std::vector GetSetColumnIndices(const int theColumn); + void SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + void SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); + void SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + void SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); + + void SwapCells(const int theRow1, const int theColumn1, const int theRow2, const int theColumn2); + void SwapRows(const int theRow1, const int theRow2); + void SwapColumns(const int theColumn1, const int theColumn2); ~SALOMEDSImpl_AttributeTableOfString() {} private: - std::map myTable; - std::string myTitle; - std::vector myRows; - std::vector myCols; - int myNbRows; - int myNbColumns; - + std::string myTitle; + std::vector myRows; + std::vector myCols; + int myNbRows; + int myNbColumns; }; #endif