From c32c9e451406650ad48aca2b240c55c459c8a7d6 Mon Sep 17 00:00:00 2001 From: vsr Date: Fri, 14 May 2010 13:12:41 +0000 Subject: [PATCH] Merge results of improvement 0020465: CEA 335] sort tables in visualisation mode from V5_1_main branch --- idl/SALOMEDS_Attributes.idl | 1009 ++++++++++------- .../SALOMEDS_AttributeTableOfInteger.cxx | 243 +++- .../SALOMEDS_AttributeTableOfInteger.hxx | 14 +- .../SALOMEDS_AttributeTableOfInteger_i.cxx | 315 ++++- .../SALOMEDS_AttributeTableOfInteger_i.hxx | 62 +- .../SALOMEDS_AttributeTableOfReal.cxx | 241 +++- .../SALOMEDS_AttributeTableOfReal.hxx | 14 +- .../SALOMEDS_AttributeTableOfReal_i.cxx | 303 ++++- .../SALOMEDS_AttributeTableOfReal_i.hxx | 75 +- .../SALOMEDS_AttributeTableOfString.cxx | 239 +++- .../SALOMEDS_AttributeTableOfString.hxx | 14 +- .../SALOMEDS_AttributeTableOfString_i.cxx | 318 +++++- .../SALOMEDS_AttributeTableOfString_i.hxx | 61 +- src/SALOMEDSClient/Makefile.am | 1 + .../SALOMEDSClient_AttributeTable.hxx | 79 ++ ...SALOMEDSClient_AttributeTableOfInteger.hxx | 31 +- .../SALOMEDSClient_AttributeTableOfReal.hxx | 30 +- .../SALOMEDSClient_AttributeTableOfString.hxx | 30 +- src/SALOMEDSImpl/Makefile.am | 2 + .../SALOMEDSImpl_AttributeTable.hxx | 106 ++ .../SALOMEDSImpl_AttributeTableOfInteger.cxx | 318 +++++- .../SALOMEDSImpl_AttributeTableOfInteger.hxx | 91 +- .../SALOMEDSImpl_AttributeTableOfReal.cxx | 322 +++++- .../SALOMEDSImpl_AttributeTableOfReal.hxx | 90 +- .../SALOMEDSImpl_AttributeTableOfString.cxx | 313 ++++- .../SALOMEDSImpl_AttributeTableOfString.hxx | 92 +- 26 files changed, 3432 insertions(+), 981 deletions(-) create mode 100644 src/SALOMEDSClient/SALOMEDSClient_AttributeTable.hxx create mode 100644 src/SALOMEDSImpl/SALOMEDSImpl_AttributeTable.hxx diff --git a/idl/SALOMEDS_Attributes.idl b/idl/SALOMEDS_Attributes.idl index dd49ef584..37033d74a 100644 --- a/idl/SALOMEDS_Attributes.idl +++ b/idl/SALOMEDS_Attributes.idl @@ -779,453 +779,646 @@ Sets the item to be selectable */ void Remove(in SObject anObject); }; - //========================================================================== - /*! \brief %AttributeTableOfInteger interface - This attribute allows to store a table of integers (indexing from 1 like in CASCADE) - and string titles of this table, of each row, of each column. + //========================================================================== + /*! + \brief Generic table attribute. -See \ref example21 for an example of usage of these methods in batchmode of %SALOME application. + Used as base interface for the AttributeTableOfInteger, AttributeTableOfReal + and AttributeTableOfString. Provides functions which are common for all table + attributes. -*/ + \note The indices of rows and columns in the table start from 1. + \sa AttributeTableOfInteger, AttributeTableOfReal, AttributeTableOfString + */ //========================================================================== - interface AttributeTableOfInteger : GenericAttribute + interface AttributeTable : GenericAttribute { -//! This exception is raised when an incorrect index is passed as parameter. + //! This exception is raised when an invalid (out of range) index is passed as parameter. exception IncorrectIndex {}; -//! This exception is raised when an incorrect length of the argument is passed as parameter. + //! This exception is raised when sequence of incorrect length is passed as parameter. exception IncorrectArgumentLength {}; - // titles: for table, for each row, for each column -/*! - Sets the title of the table. -*/ - void SetTitle(in string theTitle); -/*! - Returns the title of the table. -*/ + //! 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 + \sa GetTitle() + */ + void SetTitle(in string title); + /*! + \brief Returns the title of the table. + \return table title (empty string if not set) + \sa SetTitle() + */ string GetTitle(); -/*! - Sets the title of a row with a definite index. -*/ - void SetRowTitle(in long theIndex, in string theTitle) raises(IncorrectIndex); -/*! - Sets the titles for all rows of the table. -*/ - void SetRowTitles(in StringSeq theTitles) raises(IncorrectArgumentLength); -/*! - Returns the titles of all rows of the table. -*/ + /*! + \brief Sets the title of a row with specified index. + + Raises an exception if \a row is out of range. + + \param row row index + \param title title being set to the row + \sa GetRowTitle() + */ + void SetRowTitle(in long row, in string title) raises(IncorrectIndex); + /*! + \brief Returns the title of a row with specified index. + + Raises an exception if \a row is out of range. + + \param row row index + \return row title (empty string if not set) + \sa SetRowTitle() + */ + string GetRowTitle(in long row) raises(IncorrectIndex); + /*! + \brief Sets the titles for all rows in the table. + + Raises an exception if length of the \a titles parameter is not equal + to the number of rows in the table. + + \param titles titles being set to the table rows + \sa GetRowTitles() + */ + void SetRowTitles(in StringSeq titles) raises(IncorrectArgumentLength); + /*! + \brief Returns the titles of all rows of the table. + \return list of all rows titles + \sa SetRowTitles() + */ StringSeq GetRowTitles(); -/*! - Sets the title of a column with a definite index. -*/ - void SetColumnTitle(in long theIndex, in string theTitle) raises(IncorrectIndex); -/*! - Sets the titles for all columns of the table. -*/ - void SetColumnTitles(in StringSeq theTitles) raises(IncorrectArgumentLength); -/*! - Returns the titles of all columns of the table. -*/ + /*! + \brief Sets the title of a column with specified index. + + Raises an exception if \a column is out of range. + + \param column column index + \param title title being set to the column + \sa GetColumnTitle() + */ + void SetColumnTitle(in long column, in string title) raises(IncorrectIndex); + /*! + \brief Returns the title of a column with specified index. + + Raises an exception if \a column is out of range. + + \param column column index + \return column title (empty string if not set) + \sa SetColumnTitle() + */ + string GetColumnTitle(in long column) raises(IncorrectIndex); + /*! + \brief Sets the titles for all columns in the table. + + Raises an exception if length of the \a titles parameter is not equal + to the number of columns in the table. + + \param titles titles being set to the table columns + \sa GetColumnTitles() + */ + void SetColumnTitles(in StringSeq titles) raises(IncorrectArgumentLength); + /*! + \brief Returns the titles of all columns of the table. + \return list of all columns titles + \sa SetColumnTitles() + */ StringSeq GetColumnTitles(); - - //Rows units -/*! - Sets the unit of a row with a definite index. -*/ - void SetRowUnit(in long theIndex, in string theUnit) raises(IncorrectIndex); -/*! - Sets the units for all rows of the table. -*/ - void SetRowUnits(in StringSeq theUnits) raises(IncorrectArgumentLength); -/*! - Returns the units of all rows of the table. -*/ + /*! + \brief Assigns the unit label to the row with specified index. + + Raises an exception if \a row is out of range. + + \param row row index + \param unit unit label being set to the row + \sa GetRowUnit() + */ + void SetRowUnit(in long row, in string unit) raises(IncorrectIndex); + /*! + \brief Returns the unit label of a row with specified index. + + Raises an exception if \a row is out of range. + + \param row row index + \return row unit label (empty string if not set) + \sa SetRowUnit() + */ + string GetRowUnit(in long row) raises(IncorrectIndex); + /*! + \brief Sets the unit labels for all rows in the table. + + Raises an exception if length of the \a units parameter is not equal + to the number of rows in the table. + + \param units unit labels being set to the table rows + \sa GetRowUnits() + */ + void SetRowUnits(in StringSeq units) raises(IncorrectArgumentLength); + /*! + \brief Returns the unit labels of all rows of the table. + \return list of all rows unit labels + \sa SetRowUnits() + */ StringSeq GetRowUnits(); - - // table information -/*! - Returns the number of rows of the table. -*/ + /*! + \brief Returns the number of rows of the table. + \return rows count + \sa GetNbColumns() + */ long GetNbRows(); -/*! - Returns the number of columns of the table. -*/ + /*! + \brief Returns the number of columns of the table. + \return columns count + \sa GetNbRows(), SetNbColumns() + */ long GetNbColumns(); - - // operations with rows -/*! - Adds a row to the end of the table. - \param theData A sequence of long values which will be set as elements of the added row. -*/ - void AddRow(in LongSeq theData) raises(IncorrectArgumentLength); -/*! - Sets the elements of a definite row. - \param theRow The number of the row. - \param theData A sequence of long values which will be set as elements of this row. - -*/ - void SetRow(in long theRow, in LongSeq theData) raises(IncorrectArgumentLength, IncorrectIndex); -/*! - Gets the row of the table. - - \param theRow The number of the row. - \return A sequence of long values which are set as elements of this row. -*/ - LongSeq GetRow(in long theRow) raises(IncorrectIndex); - - // operations with columns -/*! - Adds a column to the end of the table. - - \param theData A sequence of long values which will be set as elements of this column. -*/ - void AddColumn(in LongSeq theData) raises(IncorrectArgumentLength); -/*! - Sets the values of all elements of the column. - - \param theData A sequence of long values which will be set as elements of this column. -*/ - void SetColumn(in long theColumn, in LongSeq theData) raises(IncorrectArgumentLength, IncorrectIndex); -/*! - Returns the column of the table. -*/ - LongSeq GetColumn(in long theColumn) raises(IncorrectIndex); - - // operations with elements -/*! - Puts a value in the table. - \param theRow The row, where the value will be placed. - \param theColumn The column, where the value will be placed. -*/ - void PutValue(in long theValue, in long theRow, in long theColumn) raises(IncorrectIndex); -/*! - Returns True if there is a value in the table. - \param theRow The row containing the value - \param theColumn The column containing the value -*/ - boolean HasValue(in long theRow, in long theColumn); -/*! - Returns the value from the table. - \param theRow The row containing the value - \param theColumn The column containing the value -*/ - long GetValue(in long theRow, in long theColumn) raises(IncorrectIndex); - -/*! - Sets the max number of colums in the table. - \note It'd better to set it before filling the table. -*/ - void SetNbColumns(in long theNbColumns); - -/*! - Returns the indices of the row where the values are defined. -*/ - LongSeq GetRowSetIndices(in long theRow) raises(IncorrectIndex); - // operations with files -/*! - Reads a table from a file. -*/ - boolean ReadFromFile(in SALOMEDS::TMPFile theStream); -/*! - Saves a table into a file. -*/ + /*! + \brief Check if the value is set for the cell with specified \a row and \a column indices. + \param row row index + \param column column index + \return \c true if value is set for the specified cell or \c false otherwise + (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 + \sa GetNbColumns() + */ + void SetNbColumns(in long columns); + /*! + \brief Returns the indices of the columns in the specified \a row for which + values are set. + + Raises an exception if \a row is out of range. + + \param row row index + \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) + \return list of mixed column indices + */ + LongSeq 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) + \return list of mixed row indices + */ + LongSeq 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) + \return list of mixed column indices + */ + LongSeq 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) + \return list of mixed row indices + */ + LongSeq 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 + \return \c true if table is successfully read or \c false otherwise + \sa SaveToFile() + */ + boolean ReadFromFile(in SALOMEDS::TMPFile fileStream); + /*! + \brief Saves a table into a byte stream. + \return byte stream with table representation + \sa ReadFromFile() + */ SALOMEDS::TMPFile SaveToFile(); }; //========================================================================== -/*! \brief %AttributeTableOfReal interface + /*! + \brief Table of %integer values - This attribute allows to store a table of reals (indexing from 1 like in CASCADE) - and string titles of this table, of each row, of each column. -See \ref example21 for an example of usage of these methods in batchmode of %SALOME application. + This attribute allows to store a table of %integer values. It is possible + to specify titles for rows and columns. In addition, the unis labels can be + assigned to the rows. And finally, the table iself can have title. -*/ - //========================================================================== + \note The indices of rows and columns in the table start from 1. - interface AttributeTableOfReal : GenericAttribute - { -//! This exception is raised when an incorrect index is passed as parameter. - exception IncorrectIndex {}; -//! This exception is raised when an incorrect length of the argument is passed as parameter. - exception IncorrectArgumentLength {}; + See \ref example21 for an example of usage of this attribute in batchmode of %SALOME application. - // titles: for table, for each row, for each column -/*! - Sets the title of the table. -*/ - void SetTitle(in string theTitle); -/*! - Returns the title of the table. -*/ - string GetTitle(); -/*! - Sets the title of a row with a definite index. -*/ - void SetRowTitle(in long theIndex, in string theTitle) raises(IncorrectIndex); -/*! - Sets the titles for all rows of the table. -*/ - void SetRowTitles(in StringSeq theTitles) raises(IncorrectArgumentLength); -/*! - Returns the titles of all rows of the table. -*/ - StringSeq GetRowTitles(); -/*! - Sets the title of a column with a definite index. -*/ - void SetColumnTitle(in long theIndex, in string theTitle) raises(IncorrectIndex); -/*! - Sets the titles for all columns of the table. -*/ - void SetColumnTitles(in StringSeq theTitles) raises(IncorrectArgumentLength); -/*! - Returns the titles of all columns of the table. -*/ - StringSeq GetColumnTitles(); + \sa AttributeTable, AttributeTableOfReal, AttributeTableOfString + */ + //========================================================================== - //Rows units -/*! - Sets the unit of a row with a definite index. -*/ - void SetRowUnit(in long theIndex, in string theUnit) raises(IncorrectIndex); -/*! - Sets the units for all rows of the table. -*/ - void SetRowUnits(in StringSeq theUnits) raises(IncorrectArgumentLength); -/*! - Returns the units of all rows of the table. -*/ - StringSeq GetRowUnits(); + interface AttributeTableOfInteger : AttributeTable + { + /*! + \brief Appends new row to the table. + + If the length of the \a data parameter is greater than current number of columns + in the table, the table is automatically resized. + + \param data sequence of values which will be set as elements of the added row + \sa SetRow(), GetRow(), AddColumn() + */ + void AddRow(in LongSeq data) raises(IncorrectArgumentLength); + /*! + \brief Replaces all the elements of the specified \a row with new values. + + Raises an exception if \a row is out of range or if the length of the + \a data parameter is not equal to the number of columns in the table. + + \param row row index + \param data sequence of values being set as values of the row + \sa GetRow(), AddRow(), SetColumn() + */ + void SetRow(in long row, in LongSeq data) raises(IncorrectArgumentLength, IncorrectIndex); + /*! + \brief Returns all the values of the specified row in the table. + + Raises an exception if \a row is out of range. + + \note For empty cells 0 value is returned. + + \param row row index + \return sequence of values which are set as elements of the row. + \sa SetRow(), AddRow() + */ + LongSeq GetRow(in long row) raises(IncorrectIndex); + /*! + \brief Appends new column to the table. + + If the length of the \a data parameter is greater than current number of rows + in the table, the table is automatically resized. + + \param data sequence of values which will be set as elements of the added column + \sa SetColumn(), GetColumn(), AddRow() + */ + void AddColumn(in LongSeq data) raises(IncorrectArgumentLength); + /*! + \brief Replaces all the elements of the specified column with new values. + + Raises an exception if \a column is out of range or if the length of the + \a data parameter is not equal to the number of rows in the table. + + \param column column index + \param data sequence of values being set as values of the column + \sa GetColumn(), AddColumn(), SetRow() + */ + void SetColumn(in long column, in LongSeq data) raises(IncorrectArgumentLength, IncorrectIndex); + /*! + \brief Returns all the values of the specified column in the table. + + Raises an exception if \a column is out of range. + + \note For empty cells 0 value is returned. + + \param column column index + \return sequence of values which are set as elements of the column. + \sa SetColumn(), AddColumn() + */ + LongSeq GetColumn(in long column) raises(IncorrectIndex); + /*! + \brief Puts a value to the table cell specified by \a row and \a column indices. + + If the \a row and/or \a column parameter(s) are greater than current number of rows/columns + in the table, the table is automatically resized. + + \param value value being set to the table cell + \param row row index + \param column column index + \sa GetValue(), HasValue() + */ + void PutValue(in long value, in long row, in long column) raises(IncorrectIndex); + /*! + \brief Returns the value from the cell table. + + Raises an exception if \a row or \a column is out of range or + if value is not set for the specified table cell. + + \param row row index + \param column column index + \return value assigned to the table cell + \sa PutValue(), HasValue() + */ + long GetValue(in long row, in long column) raises(IncorrectIndex); + }; - // table information -/*! - Returns the number of rows of the table. -*/ - long GetNbRows(); -/*! - Returns the number of columns of the table. -*/ - long GetNbColumns(); + //========================================================================== + /*! + \brief Table of real values - // operations with rows -/*! - Adds a row to the end of the table. -*/ - void AddRow(in DoubleSeq theData) raises(IncorrectArgumentLength); -/*! - Sets the values of all elements of the row. -*/ - void SetRow(in long theRow, in DoubleSeq theData) raises(IncorrectArgumentLength, IncorrectIndex); -/*! - Returns the row of the table. -*/ - DoubleSeq GetRow(in long theRow) raises(IncorrectIndex); + This attribute allows to store a table of real values. It is possible + to specify titles for rows and columns. In addition, the unis labels can be + assigned to the rows. And finally, the table iself can have title. - // operations with columns -/*! - Adds a column to the end of the table. -*/ - void AddColumn(in DoubleSeq theData) raises(IncorrectArgumentLength); -/*! - Sets the values of all elements of the column. -*/ - void SetColumn(in long theColumn, in DoubleSeq theData) raises(IncorrectArgumentLength, IncorrectIndex); -/*! - Returns the column of the table. -*/ - DoubleSeq GetColumn(in long theColumn) raises(IncorrectIndex); + \note The indices of rows and columns in the table start from 1. - // operations with elements -/*! - Puts a value in the table. - \param theRow The row, where the value will be placed. - \param theColumn The column, where the value will be placed. -*/ - void PutValue(in double theValue, in long theRow, in long theColumn) raises(IncorrectIndex); -/*! - Returns True if there is a value in the table. - \param theRow The row containing the value - \param theColumn The column containing the value -*/ - boolean HasValue(in long theRow, in long theColumn); -/*! - Returns the value from the table. - \param theRow The row containing the value - \param theColumn The column containing the value -*/ - double GetValue(in long theRow, in long theColumn) raises(IncorrectIndex); + See \ref example22 for an example of usage of this attribute in batchmode of %SALOME application. -/*! - Sets the max number of colums in the table. - \note It'd better to set it before filling the table. -*/ - void SetNbColumns(in long theNbColumns); + \sa AttributeTable, AttributeTableOfInteger, AttributeTableOfString + */ + //========================================================================== -/*! - Returns the indices of the row where the values are defined. -*/ - LongSeq GetRowSetIndices(in long theRow) raises(IncorrectIndex); - // operations with files -/*! - Reads a table from a file. -*/ - boolean ReadFromFile(in SALOMEDS::TMPFile theStream); -/*! - Saves a table into a file. -*/ - SALOMEDS::TMPFile SaveToFile(); + interface AttributeTableOfReal : AttributeTable + { + /*! + \brief Appends new row to the table. + + If the length of the \a data parameter is greater than current number of columns + in the table, the table is automatically resized. + + \param data sequence of values which will be set as elements of the added row + \sa SetRow(), GetRow(), AddColumn() + */ + void AddRow(in DoubleSeq data) raises(IncorrectArgumentLength); + /*! + \brief Replaces all the elements of the specified \a row with new values. + + Raises an exception if \a row is out of range or if the length of the + \a data parameter is not equal to the number of columns in the table. + + \param row row index + \param data sequence of values being set as values of the row + \sa GetRow(), AddRow(), SetColumn() + */ + void SetRow(in long row, in DoubleSeq data) raises(IncorrectArgumentLength, IncorrectIndex); + /*! + \brief Returns all the values of the specified row in the table. + + Raises an exception if \a row is out of range. + + \note For empty cells 0.0 value is returned. + + \param row row index + \return sequence of values which are set as elements of the row. + \sa SetRow(), AddRow() + */ + DoubleSeq GetRow(in long row) raises(IncorrectIndex); + /*! + \brief Appends new column to the table. + + If the length of the \a data parameter is greater than current number of rows + in the table, the table is automatically resized. + + \param data sequence of values which will be set as elements of the added column + \sa SetColumn(), GetColumn(), AddRow() + */ + void AddColumn(in DoubleSeq data) raises(IncorrectArgumentLength); + /*! + \brief Replaces all the elements of the specified column with new values. + + Raises an exception if \a column is out of range or if the length of the + \a data parameter is not equal to the number of rows in the table. + + \param column column index + \param data sequence of values being set as values of the column + \sa GetColumn(), AddColumn(), SetRow() + */ + void SetColumn(in long column, in DoubleSeq data) raises(IncorrectArgumentLength, IncorrectIndex); + /*! + \brief Returns all the values of the specified column in the table. + + Raises an exception if \a column is out of range. + + \note For empty cells 0.0 value is returned. + + \param column column index + \return sequence of values which are set as elements of the column. + \sa SetColumn(), AddColumn() + */ + DoubleSeq GetColumn(in long column) raises(IncorrectIndex); + /*! + \brief Puts a value to the table cell specified by \a row and \a column indices. + + If the \a row and/or \a column parameter(s) are greater than current number of rows/columns + in the table, the table is automatically resized. + + \param value value being set to the table cell + \param row row index + \param column column index + \sa GetValue(), HasValue() + */ + void PutValue(in double value, in long row, in long volumn) raises(IncorrectIndex); + /*! + \brief Returns the value from the cell table. + + Raises an exception if \a row or \a column is out of range or + if value is not set for the specified table cell. + + \param row row index + \param column column index + \return value assigned to the table cell + \sa PutValue(), HasValue() + */ + double GetValue(in long row, in long column) raises(IncorrectIndex); }; - - //========================================================================== -/*! \brief %AttributeTableOfString interface + /*! + \brief Table of string values - This attribute allows to store a table of strings (indexing from 1 like in CASCADE) - and string titles of this table, of each row, of each column. -See \ref example21 for an example of usage of these methods in batchmode of %SALOME application. + This attribute allows to store a table of string values. It is possible + to specify titles for rows and columns. In addition, the unis labels can be + assigned to the rows. And finally, the table iself can have title. -*/ + \note The indices of rows and columns in the table start from 1. + \sa AttributeTable, AttributeTableOfInteger, AttributeTableOfReal + */ //========================================================================== - - interface AttributeTableOfString : GenericAttribute + interface AttributeTableOfString : AttributeTable { -//! This exception is raised when an incorrect index is passed as parameter. - exception IncorrectIndex {}; -//! This exception is raised when an incorrect length of the argument is passed as parameter. - exception IncorrectArgumentLength {}; - - // titles: for table, for each row, for each column -/*! - Sets the title of the table. -*/ - void SetTitle(in string theTitle); -/*! - Returns the title of the table. -*/ - string GetTitle(); -/*! - Sets the title of a row with a definite index. -*/ - void SetRowTitle(in long theIndex, in string theTitle) raises(IncorrectIndex); -/*! - Sets the titles for all rows of the table. -*/ - void SetRowTitles(in StringSeq theTitles) raises(IncorrectArgumentLength); -/*! - Returns the titles of all rows of the table. -*/ - StringSeq GetRowTitles(); -/*! - Sets the title of a column with a definite index. -*/ - void SetColumnTitle(in long theIndex, in string theTitle) raises(IncorrectIndex); -/*! - Sets the titles for all columns of the table. -*/ - void SetColumnTitles(in StringSeq theTitles) raises(IncorrectArgumentLength); -/*! - Returns the titles of all columns of the table. -*/ - StringSeq GetColumnTitles(); - - //Rows units -/*! - Sets the unit of a row with a definite index. -*/ - void SetRowUnit(in long theIndex, in string theUnit) raises(IncorrectIndex); -/*! - Sets the units for all rows of the table. -*/ - void SetRowUnits(in StringSeq theUnits) raises(IncorrectArgumentLength); -/*! - Returns the units of all rows of the table. -*/ - StringSeq GetRowUnits(); - - // table information -/*! - Returns the number of rows of the table. -*/ - long GetNbRows(); -/*! - Returns the number of columns of the table. -*/ - long GetNbColumns(); - - // operations with rows -/*! - Adds a row to the end of the table. -*/ - void AddRow(in StringSeq theData) raises(IncorrectArgumentLength); -/*! - Sets the values of all elements of the row. -*/ - void SetRow(in long theRow, in StringSeq theData) raises(IncorrectArgumentLength, IncorrectIndex); -/*! - Returns the row of the table. -*/ - StringSeq GetRow(in long theRow) raises(IncorrectIndex); - - // operations with columns -/*! - Adds a column to the end of the table. -*/ - void AddColumn(in StringSeq theData) raises(IncorrectArgumentLength); -/*! - Sets the values of all elements of the column. -*/ - void SetColumn(in long theColumn, in StringSeq theData) raises(IncorrectArgumentLength, IncorrectIndex); -/*! - Returns the column of the table. -*/ - StringSeq GetColumn(in long theColumn) raises(IncorrectIndex); - - // operations with elements -/*! - Puts a value in the table. - \param theRow The row, where the value will be placed. - \param theColumn The column, where the value will be placed. -*/ - void PutValue(in string theValue, in long theRow, in long theColumn) raises(IncorrectIndex); -/*! - Returns True if there is a value in the table. - \param theRow The row containing the value - \param theColumn The column containing the value -*/ - boolean HasValue(in long theRow, in long theColumn); -/*! - Returns the value from the table. - \param theRow The row containing the value - \param theColumn The column containing the value -*/ - string GetValue(in long theRow, in long theColumn) raises(IncorrectIndex); - -/*! - Sets the max number of colums in the table. - \note It'd better to set it before filling the table. -*/ - void SetNbColumns(in long theNbColumns); - -/*! - Returns the indices of the row where the values are defined. -*/ - LongSeq GetRowSetIndices(in long theRow) raises(IncorrectIndex); - // operations with files -/*! - Reads a table from a file. -*/ - boolean ReadFromFile(in SALOMEDS::TMPFile theStream); -/*! - Saves a table into a file. -*/ - SALOMEDS::TMPFile SaveToFile(); + /*! + \brief Appends new row to the table. + + If the length of the \a data parameter is greater than current number of columns + in the table, the table is automatically resized. + + \param data sequence of values which will be set as elements of the added row + \sa SetRow(), GetRow(), AddColumn() + */ + void AddRow(in StringSeq data) raises(IncorrectArgumentLength); + /*! + \brief Replaces all the elements of the specified \a row with new values. + + Raises an exception if \a row is out of range or if the length of the + \a data parameter is not equal to the number of columns in the table. + + \param row row index + \param data sequence of values being set as values of the row + \sa GetRow(), AddRow(), SetColumn() + */ + void SetRow(in long row, in StringSeq data) raises(IncorrectArgumentLength, IncorrectIndex); + /*! + \brief Returns all the values of the specified row in the table. + + Raises an exception if \a row is out of range. + + \note For empty cells empty string is returned. + + \param row row index + \return sequence of values which are set as elements of the row. + \sa SetRow(), AddRow() + */ + StringSeq GetRow(in long row) raises(IncorrectIndex); + /*! + \brief Appends new column to the table. + + If the length of the \a data parameter is greater than current number of rows + in the table, the table is automatically resized. + + \param data sequence of values which will be set as elements of the added column + \sa SetColumn(), GetColumn(), AddRow() + */ + void AddColumn(in StringSeq data) raises(IncorrectArgumentLength); + /*! + \brief Replaces all the elements of the specified column with new values. + + Raises an exception if \a column is out of range or if the length of the + \a data parameter is not equal to the number of rows in the table. + + \param column column index + \param data sequence of values being set as values of the column + \sa GetColumn(), AddColumn(), SetRow() + */ + void SetColumn(in long column, in StringSeq data) raises(IncorrectArgumentLength, IncorrectIndex); + /*! + \brief Returns all the values of the specified column in the table. + + Raises an exception if \a column is out of range. + + \note For empty cells empty string is returned. + + \param column column index + \return sequence of values which are set as elements of the column. + \sa SetColumn(), AddColumn() + */ + StringSeq GetColumn(in long column) raises(IncorrectIndex); + /*! + \brief Puts a value to the table cell specified by \a row and \a column indices. + + If the \a row and/or \a column parameter(s) are greater than current number of rows/columns + in the table, the table is automatically resized. + + \param value value being set to the table cell + \param row row index + \param column column index + \sa GetValue(), HasValue() + */ + void PutValue(in string value, in long row, in long column) raises(IncorrectIndex); + /*! + \brief Returns the value from the cell table. + + Raises an exception if \a row or \a column is out of range or + if value is not set for the specified table cell. + + \param row row index + \param column column index + \return value assigned to the table cell + \sa PutValue(), HasValue() + */ + string GetValue(in long row, in long column) raises(IncorrectIndex); }; - //========================================================================== /*! \brief %AttributeStudyProperties interface diff --git a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx index 522377918..10e37953b 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfInteger.cxx // Author : Sergey RUIN // Module : SALOME @@ -26,8 +27,6 @@ #include "SALOMEDS_AttributeTableOfInteger.hxx" #include "SALOMEDS.hxx" -using namespace std; - SALOMEDS_AttributeTableOfInteger::SALOMEDS_AttributeTableOfInteger (SALOMEDSImpl_AttributeTableOfInteger* theAttr) :SALOMEDS_GenericAttribute(theAttr) @@ -73,13 +72,31 @@ void SALOMEDS_AttributeTableOfInteger::SetRowTitle(int theIndex, const std::stri else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str()); } +std::string SALOMEDS_AttributeTableOfInteger::GetRowTitle(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetRowTitle(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetRowTitle(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfInteger::SetRowTitles(const std::vector& theTitles) { int aLength = theTitles.size(), i; if (_isLocal) { CheckLocked(); SALOMEDS::Locker lock; - vector aSeq; + std::vector aSeq; for (i = 0; i < aLength; i++) aSeq.push_back(theTitles[i]); dynamic_cast(_local_impl)->SetRowTitles(aSeq); } @@ -118,13 +135,31 @@ void SALOMEDS_AttributeTableOfInteger::SetColumnTitle(int theIndex, const std::s else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str()); } +std::string SALOMEDS_AttributeTableOfInteger::GetColumnTitle(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetColumnTitle(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetColumnTitle(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfInteger::SetColumnTitles(const std::vector& theTitles) { int aLength = theTitles.size(), i; if (_isLocal) { CheckLocked(); SALOMEDS::Locker lock; - vector aSeq; + std::vector aSeq; for (i = 0; i < aLength; i++) aSeq.push_back(theTitles[i]); dynamic_cast(_local_impl)->SetColumnTitles(aSeq); } @@ -162,6 +197,24 @@ void SALOMEDS_AttributeTableOfInteger::SetRowUnit(int theIndex, const std::strin else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str()); } +std::string SALOMEDS_AttributeTableOfInteger::GetRowUnit(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetRowUnit(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->GetRowUnit(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfInteger::SetRowUnits(const std::vector& theUnits) { int aLength = theUnits.size(), i; @@ -228,7 +281,7 @@ void SALOMEDS_AttributeTableOfInteger::AddRow(const std::vector& theData) aTable->SetRowData(aTable->GetNbRows() + 1, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -250,7 +303,7 @@ void SALOMEDS_AttributeTableOfInteger::SetRow(int theRow, const std::vector aTable->SetRowData(theRow, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -289,7 +342,7 @@ void SALOMEDS_AttributeTableOfInteger::AddColumn(const std::vector& theData aTable->SetColumnData(aTable->GetNbColumns() + 1, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -311,7 +364,7 @@ void SALOMEDS_AttributeTableOfInteger::SetColumn(int theColumn, const std::vecto aTable->SetColumnData(theColumn, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -347,7 +400,7 @@ void SALOMEDS_AttributeTableOfInteger::PutValue(int theValue, int theRow, int th dynamic_cast(_local_impl)->PutValue(theValue, theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } } else { @@ -375,7 +428,7 @@ int SALOMEDS_AttributeTableOfInteger::GetValue(int theRow, int theColumn) aValue = dynamic_cast(_local_impl)->GetValue(theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } } else { @@ -384,6 +437,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; @@ -409,3 +478,155 @@ void SALOMEDS_AttributeTableOfInteger::SetNbColumns(int theNbColumns) } else SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SetNbColumns(theNbColumns); } + +std::vector SALOMEDS_AttributeTableOfInteger::SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SortRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfInteger::SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SortColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfInteger::SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortByRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SortByRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfInteger::SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortByColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfInteger::_narrow(_corba_impl)->SortByColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +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 c585ef2b5..ba25d90c8 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfInteger.hxx // Author : Sergey RUIN // Module : SALOME @@ -47,13 +48,16 @@ public: virtual void SetTitle(const std::string& theTitle); virtual std::string GetTitle(); virtual void SetRowTitle(int theIndex, const std::string& theTitle); + virtual std::string GetRowTitle(int theIndex); virtual void SetRowTitles(const std::vector& theTitles); virtual std::vector GetRowTitles(); virtual void SetColumnTitle(int theIndex, const std::string& theTitle); + virtual std::string GetColumnTitle(int theIndex); virtual void SetColumnTitles(const std::vector& theTitles); virtual std::vector GetColumnTitles(); virtual void SetRowUnit(int theIndex, const std::string& theUnit); + virtual std::string GetRowUnit(int theIndex); virtual void SetRowUnits(const std::vector& theUnits); virtual std::vector GetRowUnits(); @@ -68,10 +72,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 std::vector SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector 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 01a3f03bd..08147016c 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfInteger_i.cxx // Author : Sergey RUIN // Module : SALOME @@ -33,17 +34,15 @@ #include #include -using namespace std; - -UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTableOfInteger::IncorrectIndex); -UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength); +UNEXPECT_CATCH(ATI_IncorrectIndex, SALOMEDS::AttributeTable::IncorrectIndex); +UNEXPECT_CATCH(ATI_IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectArgumentLength); 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() @@ -55,24 +54,36 @@ char* SALOMEDS_AttributeTableOfInteger_i::GetTitle() } void SALOMEDS_AttributeTableOfInteger_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + if (theIndex < 1 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + aTable->SetRowTitle(theIndex, std::string(theTitle)); +} + +char* SALOMEDS_AttributeTableOfInteger_i::GetRowTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex(); - aTable->SetRowTitle(theIndex, string(theTitle)); + 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(); } void SALOMEDS_AttributeTableOfInteger_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch (ATI_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theTitles.length(); i++) { SetRowTitle(i + 1, theTitles[i]); } @@ -90,25 +101,37 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowTitles() } void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::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) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + 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(); } void SALOMEDS_AttributeTableOfInteger_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theTitles.length(); i++) { aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in()); } @@ -127,24 +150,36 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumnTitles() //Units support void SALOMEDS_AttributeTableOfInteger_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch (ATI_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::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) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATI_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); + 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(); } void SALOMEDS_AttributeTableOfInteger_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch (ATI_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theUnits.length(); i++) { aTable->SetRowUnit(i + 1, (char*)theUnits[i].in()); } @@ -174,51 +209,51 @@ CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetNbColumns() } void SALOMEDS_AttributeTableOfInteger_i::AddRow(const SALOMEDS::LongSeq& theData) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectArgumentLength); 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); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } void SALOMEDS_AttributeTableOfInteger_i::SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectArgumentLength); 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); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectIndex); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::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]; @@ -227,51 +262,51 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRow(CORBA::Long theRow } void SALOMEDS_AttributeTableOfInteger_i::AddColumn(const SALOMEDS::LongSeq& theData) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectArgumentLength); 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); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } void SALOMEDS_AttributeTableOfInteger_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectArgumentLength); 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); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectIndex); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfInteger::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]; @@ -280,7 +315,7 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetColumn(CORBA::Long the } void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectIndex); @@ -291,7 +326,7 @@ void SALOMEDS_AttributeTableOfInteger_i::PutValue(CORBA::Long theValue, CORBA::L aTable->PutValue(theValue, theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } } @@ -302,32 +337,50 @@ CORBA::Boolean SALOMEDS_AttributeTableOfInteger_i::HasValue(CORBA::Long theRow, } CORBA::Long SALOMEDS_AttributeTableOfInteger_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATI_IncorrectIndex); SALOMEDSImpl_AttributeTableOfInteger* aTable = dynamic_cast(_impl); - if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfInteger::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 { aValue = aTable->GetValue(theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfInteger::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } 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::AttributeTableOfInteger::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]; @@ -335,7 +388,6 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfInteger_i::GetRowSetIndices(CORBA::L return CorbaSeq._retn(); } - void SALOMEDS_AttributeTableOfInteger_i::SetNbColumns(CORBA::Long theNbColumns) { SALOMEDS::Locker lock; @@ -348,17 +400,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); @@ -370,4 +422,167 @@ SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfInteger_i::SaveToFile() return aStreamFile._retn(); } +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortByRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortByColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +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 861543371..1c3daff5c 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfInteger_i.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfInteger_i.hxx // Author : Sergey RUIN // Module : SALOME @@ -36,9 +37,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) {}; @@ -47,45 +46,74 @@ public: virtual void SetTitle(const char* theTitle); virtual char* GetTitle(); virtual void SetRowTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetRowTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetRowTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetRowTitles(); virtual void SetColumnTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetColumnTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetColumnTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetColumnTitles(); virtual void SetRowUnit(CORBA::Long theIndex, const char* theUnit) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetRowUnit(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetRowUnits(const SALOMEDS::StringSeq& theUnits) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetRowUnits(); virtual CORBA::Long GetNbRows(); virtual CORBA::Long GetNbColumns(); virtual void AddRow(const SALOMEDS::LongSeq& theData) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual void SetRow(CORBA::Long theRow, const SALOMEDS::LongSeq& theData) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::LongSeq* GetRow(CORBA::Long theRow) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void AddColumn(const SALOMEDS::LongSeq& theData) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual void SetColumn(CORBA::Long theColumn, const SALOMEDS::LongSeq& theData) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectArgumentLength, SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::LongSeq* GetColumn(CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void PutValue(CORBA::Long theValue, CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual CORBA::Boolean HasValue(CORBA::Long theRow, CORBA::Long theColumn); virtual CORBA::Long GetValue(CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfInteger::IncorrectIndex); + 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 SALOMEDS::LongSeq* SortRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* SortColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* SortByRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* 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 8efbaaec5..de81d2a47 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfReal.cxx // Author : Sergey RUIN // Module : SALOME @@ -26,8 +27,6 @@ #include "SALOMEDS_AttributeTableOfReal.hxx" #include "SALOMEDS.hxx" -using namespace std; - SALOMEDS_AttributeTableOfReal::SALOMEDS_AttributeTableOfReal (SALOMEDSImpl_AttributeTableOfReal* theAttr) :SALOMEDS_GenericAttribute(theAttr) @@ -72,6 +71,24 @@ void SALOMEDS_AttributeTableOfReal::SetRowTitle(int theIndex, const std::string& else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str()); } +std::string SALOMEDS_AttributeTableOfReal::GetRowTitle(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetRowTitle(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowTitle(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfReal::SetRowTitles(const std::vector& theTitles) { CheckLocked(); @@ -115,6 +132,24 @@ void SALOMEDS_AttributeTableOfReal::SetColumnTitle(int theIndex, const std::stri else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str()); } +std::string SALOMEDS_AttributeTableOfReal::GetColumnTitle(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetColumnTitle(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetColumnTitle(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfReal::SetColumnTitles(const std::vector& theTitles) { int aLength = theTitles.size(), i; @@ -157,6 +192,24 @@ void SALOMEDS_AttributeTableOfReal::SetRowUnit(int theIndex, const std::string& else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str()); } +std::string SALOMEDS_AttributeTableOfReal::GetRowUnit(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetRowUnit(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowUnit(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfReal::SetRowUnits(const std::vector& theUnits) { int aLength = theUnits.size(), i; @@ -184,7 +237,7 @@ std::vector SALOMEDS_AttributeTableOfReal::GetRowUnits() else { SALOMEDS::StringSeq_var aSeq = SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->GetRowUnits(); aLength = aSeq->length(); - for (i = 0; i < aLength; i++) aVector.push_back(string(aSeq[i].in())); + for (i = 0; i < aLength; i++) aVector.push_back(std::string(aSeq[i].in())); } return aVector; } @@ -222,7 +275,7 @@ void SALOMEDS_AttributeTableOfReal::AddRow(const std::vector& theData) aTable->SetRowData(aTable->GetNbRows() + 1, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -244,7 +297,7 @@ void SALOMEDS_AttributeTableOfReal::SetRow(int theRow, const std::vector aTable->SetRowData(theRow, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -283,7 +336,7 @@ void SALOMEDS_AttributeTableOfReal::AddColumn(const std::vector& theData aTable->SetColumnData(aTable->GetNbColumns() + 1, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -305,7 +358,7 @@ void SALOMEDS_AttributeTableOfReal::SetColumn(int theColumn, const std::vectorSetColumnData(theColumn, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -341,7 +394,7 @@ void SALOMEDS_AttributeTableOfReal::PutValue(double theValue, int theRow, int th dynamic_cast(_local_impl)->PutValue(theValue, theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } } else { @@ -369,7 +422,7 @@ double SALOMEDS_AttributeTableOfReal::GetValue(int theRow, int theColumn) aValue = dynamic_cast(_local_impl)->GetValue(theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } } else { @@ -378,6 +431,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; @@ -402,3 +471,155 @@ void SALOMEDS_AttributeTableOfReal::SetNbColumns(int theNbColumns) } else SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SetNbColumns(theNbColumns); } + +std::vector SALOMEDS_AttributeTableOfReal::SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SortRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfReal::SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SortColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfReal::SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortByRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SortByRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfReal::SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortByColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfReal::_narrow(_corba_impl)->SortByColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +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 f58219ce3..82adcc341 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfReal.hxx // Author : Sergey RUIN // Module : SALOME @@ -47,13 +48,16 @@ public: virtual void SetTitle(const std::string& theTitle); virtual std::string GetTitle(); virtual void SetRowTitle(int theIndex, const std::string& theTitle); + virtual std::string GetRowTitle(int theIndex); virtual void SetRowTitles(const std::vector& theTitles); virtual std::vector GetRowTitles(); virtual void SetColumnTitle(int theIndex, const std::string& theTitle); + virtual std::string GetColumnTitle(int theIndex); virtual void SetColumnTitles(const std::vector& theTitles); virtual std::vector GetColumnTitles(); virtual void SetRowUnit(int theIndex, const std::string& theUnit); + virtual std::string GetRowUnit(int theIndex); virtual void SetRowUnits(const std::vector& theUnits); virtual std::vector GetRowUnits(); @@ -68,10 +72,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 std::vector SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector 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 30ee7075b..59bdda74f 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfReal_i.cxx // Author : Sergey RUIN // Module : SALOME @@ -30,11 +31,9 @@ #include #include -using namespace std; - #include "Utils_ExceptHandlers.hxx" -UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTableOfReal::IncorrectIndex); -UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength); +UNEXPECT_CATCH(ATR_IncorrectIndex, SALOMEDS::AttributeTable::IncorrectIndex); +UNEXPECT_CATCH(ATR_IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectArgumentLength); void SALOMEDS_AttributeTableOfReal_i::SetTitle(const char* theTitle) { @@ -42,7 +41,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() @@ -54,24 +53,36 @@ char* SALOMEDS_AttributeTableOfReal_i::GetTitle() } void SALOMEDS_AttributeTableOfReal_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch (ATR_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); - aTable->SetRowTitle(theIndex, string(theTitle)); + if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + aTable->SetRowTitle(theIndex, std::string(theTitle)); +} + +char* SALOMEDS_AttributeTableOfReal_i::GetRowTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + CORBA::String_var c_s = CORBA::string_dup(aTable->GetRowTitle(theIndex).c_str()); + return c_s._retn(); } void SALOMEDS_AttributeTableOfReal_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch (ATR_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength(); + if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theTitles.length(); i++) { aTable->SetRowTitle(i + 1, (char*)theTitles[i].in()); } @@ -89,25 +100,37 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetRowTitles() } void SALOMEDS_AttributeTableOfReal_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch (ATR_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); + 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) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + CORBA::String_var c_s = CORBA::string_dup(aTable->GetColumnTitle(theIndex).c_str()); + return c_s._retn(); } void SALOMEDS_AttributeTableOfReal_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength(); + if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theTitles.length(); i++) { aTable->SetColumnTitle(i + 1, (char*)theTitles[i].in()); } @@ -126,24 +149,36 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfReal_i::GetColumnTitles() //Units support void SALOMEDS_AttributeTableOfReal_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch (ATR_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); - aTable->SetRowUnit(theIndex, string(theUnit)); + if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + aTable->SetRowUnit(theIndex, std::string(theUnit)); +} + +char* SALOMEDS_AttributeTableOfReal_i::GetRowUnit(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATR_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); + if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + CORBA::String_var c_s = CORBA::string_dup(aTable->GetRowUnit(theIndex).c_str()); + return c_s._retn(); } void SALOMEDS_AttributeTableOfReal_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch (ATR_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength(); + if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); for (int i = 0; i < theUnits.length(); i++) { aTable->SetRowUnit(i + 1, (char*)theUnits[i].in()); } @@ -174,41 +209,41 @@ CORBA::Long SALOMEDS_AttributeTableOfReal_i::GetNbColumns() } void SALOMEDS_AttributeTableOfReal_i::AddRow(const SALOMEDS::DoubleSeq& theData) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectArgumentLength); 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); } void SALOMEDS_AttributeTableOfReal_i::SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectArgumentLength); 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); } SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectIndex); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); + 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]; @@ -217,41 +252,41 @@ SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetRow(CORBA::Long theRow) } void SALOMEDS_AttributeTableOfReal_i::AddColumn(const SALOMEDS::DoubleSeq& theData) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectArgumentLength); 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); } void SALOMEDS_AttributeTableOfReal_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectArgumentLength); 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); } SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectIndex); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); + 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]; @@ -260,7 +295,7 @@ SALOMEDS::DoubleSeq* SALOMEDS_AttributeTableOfReal_i::GetColumn(CORBA::Long theC } void SALOMEDS_AttributeTableOfReal_i::PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectIndex); @@ -277,12 +312,12 @@ CORBA::Boolean SALOMEDS_AttributeTableOfReal_i::HasValue(CORBA::Long theRow, COR } CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATR_IncorrectIndex); SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); + if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); CORBA::Double aValue; @@ -290,22 +325,38 @@ CORBA::Double SALOMEDS_AttributeTableOfReal_i::GetValue(CORBA::Long theRow, CORB aValue = aTable->GetValue(theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } 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) { SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfReal* aTable = dynamic_cast(_impl); - if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfReal::IncorrectIndex(); + 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++) { @@ -314,7 +365,6 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfReal_i::GetRowSetIndices(CORBA::Long return CorbaSeq._retn(); } - void SALOMEDS_AttributeTableOfReal_i::SetNbColumns(CORBA::Long theNbColumns) { SALOMEDS::Locker lock; @@ -327,7 +377,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; } @@ -337,7 +387,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); @@ -347,3 +397,168 @@ SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfReal_i::SaveToFile() return aStreamFile._retn(); } + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortByRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortByColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +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 e77ee0420..5e0ee60b4 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfReal_i.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfReal_i.hxx // Author : Michael Ponikarov // Module : SALOME @@ -33,58 +34,86 @@ #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::AttributeTableOfReal::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetRowTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetRowTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetRowTitles(); virtual void SetColumnTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetColumnTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetColumnTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetColumnTitles(); virtual void SetRowUnit(CORBA::Long theIndex, const char* theUnit) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetRowUnit(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetRowUnits(const SALOMEDS::StringSeq& theUnits) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetRowUnits(); virtual CORBA::Long GetNbRows(); virtual CORBA::Long GetNbColumns(); virtual void AddRow(const SALOMEDS::DoubleSeq& theData) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual void SetRow(CORBA::Long theRow, const SALOMEDS::DoubleSeq& theData) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::DoubleSeq* GetRow(CORBA::Long theRow) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void AddColumn(const SALOMEDS::DoubleSeq& theData) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual void SetColumn(CORBA::Long theColumn, const SALOMEDS::DoubleSeq& theData) - throw (SALOMEDS::AttributeTableOfReal::IncorrectArgumentLength, SALOMEDS::AttributeTableOfReal::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::DoubleSeq* GetColumn(CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void PutValue(CORBA::Double theValue, CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual CORBA::Boolean HasValue(CORBA::Long theRow, CORBA::Long theColumn); virtual CORBA::Double GetValue(CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfReal::IncorrectIndex); + 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 SALOMEDS::LongSeq* SortRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* SortColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* SortByRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* 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 227ebd4f4..d8fb0493b 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfString.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfString.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfString.cxx // Author : Sergey RUIN // Module : SALOME @@ -28,8 +29,6 @@ #include -using namespace std; - SALOMEDS_AttributeTableOfString::SALOMEDS_AttributeTableOfString (SALOMEDSImpl_AttributeTableOfString* theAttr) :SALOMEDS_GenericAttribute(theAttr) @@ -75,6 +74,24 @@ void SALOMEDS_AttributeTableOfString::SetRowTitle(int theIndex, const std::strin else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowTitle(theIndex, theTitle.c_str()); } +std::string SALOMEDS_AttributeTableOfString::GetRowTitle(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetRowTitle(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowTitle(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfString::SetRowTitles(const std::vector& theTitles) { int aLength = theTitles.size(), i; @@ -117,6 +134,24 @@ void SALOMEDS_AttributeTableOfString::SetColumnTitle(int theIndex, const std::st else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetColumnTitle(theIndex, theTitle.c_str()); } +std::string SALOMEDS_AttributeTableOfString::GetColumnTitle(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetColumnTitle(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetColumnTitle(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfString::SetColumnTitles(const std::vector& theTitles) { int aLength = theTitles.size(), i; @@ -159,6 +194,24 @@ void SALOMEDS_AttributeTableOfString::SetRowUnit(int theIndex, const std::string else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetRowUnit(theIndex, theUnit.c_str()); } +std::string SALOMEDS_AttributeTableOfString::GetRowUnit(int theIndex) +{ + std::string aTitle; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aTitle = dynamic_cast(_local_impl)->GetRowUnit(theIndex); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + aTitle = SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->GetRowUnit(theIndex); + } + return aTitle; +} + void SALOMEDS_AttributeTableOfString::SetRowUnits(const std::vector& theUnits) { int aLength = theUnits.size(), i; @@ -224,7 +277,7 @@ void SALOMEDS_AttributeTableOfString::AddRow(const std::vector& the aTable->SetRowData(aTable->GetNbRows() + 1, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -246,7 +299,7 @@ void SALOMEDS_AttributeTableOfString::SetRow(int theRow, const std::vectorSetRowData(theRow, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -285,7 +338,7 @@ void SALOMEDS_AttributeTableOfString::AddColumn(const std::vector& aTable->SetColumnData(aTable->GetNbColumns() + 1, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -307,7 +360,7 @@ void SALOMEDS_AttributeTableOfString::SetColumn(int theColumn, const std::vector aTable->SetColumnData(theColumn, theData); } catch(...) { - throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength(); + throw SALOMEDS::AttributeTable::IncorrectArgumentLength(); } } else { @@ -344,7 +397,7 @@ void SALOMEDS_AttributeTableOfString::PutValue(const std::string& theValue, int dynamic_cast(_local_impl)->PutValue(theValue, theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } } else { @@ -372,7 +425,7 @@ std::string SALOMEDS_AttributeTableOfString::GetValue(int theRow, int theColumn) aValue = dynamic_cast(_local_impl)->GetValue(theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } } else { @@ -381,6 +434,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; @@ -406,3 +475,155 @@ void SALOMEDS_AttributeTableOfString::SetNbColumns(int theNbColumns) } else SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SetNbColumns(theNbColumns); } + +std::vector SALOMEDS_AttributeTableOfString::SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SortRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfString::SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SortColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfString::SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortByRow(theRow, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SortByRow(theRow, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +std::vector SALOMEDS_AttributeTableOfString::SortByColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) +{ + std::vector aVector; + int aLength, i; + if (_isLocal) { + SALOMEDS::Locker lock; + try { + aVector = dynamic_cast(_local_impl)->SortByColumn(theColumn, + (SALOMEDSImpl_AttributeTable::SortOrder)theOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)thePolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + } + else { + SALOMEDS::LongSeq_var aSet = + SALOMEDS::AttributeTableOfString::_narrow(_corba_impl)->SortByColumn(theColumn, + (SALOMEDS::AttributeTable::SortOrder)theOrder, + (SALOMEDS::AttributeTable::SortPolicy)thePolicy); + aLength = aSet->length(); + for (i = 0; i < aLength; i++) aVector.push_back(aSet[i]); + } + return aVector; +} + +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 f7e2207ee..77670bcf6 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfString.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfString.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfString.hxx // Author : Sergey RUIN // Module : SALOME @@ -47,13 +48,16 @@ public: virtual void SetTitle(const std::string& theTitle); virtual std::string GetTitle(); virtual void SetRowTitle(int theIndex, const std::string& theTitle); + virtual std::string GetRowTitle(int theIndex); virtual void SetRowTitles(const std::vector& theTitles); virtual std::vector GetRowTitles(); virtual void SetColumnTitle(int theIndex, const std::string& theTitle); + virtual std::string GetColumnTitle(int theIndex); virtual void SetColumnTitles(const std::vector& theTitles); virtual std::vector GetColumnTitles(); virtual void SetRowUnit(int theIndex, const std::string& theUnit); + virtual std::string GetRowUnit(int theIndex); virtual void SetRowUnits(const std::vector& theUnits); virtual std::vector GetRowUnits(); @@ -68,10 +72,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 std::vector SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy); + virtual std::vector 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 ebc8ebd76..d33a39b73 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.cxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfString_i.cxx // Author : Sergey RUIN // Module : SALOME @@ -32,10 +33,8 @@ #include "Utils_ExceptHandlers.hxx" -using namespace std; - -UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTableOfString::IncorrectIndex); -UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectArgumentLength); +UNEXPECT_CATCH(ATS_IncorrectIndex, SALOMEDS::AttributeTable::IncorrectIndex); +UNEXPECT_CATCH(ATS_IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectArgumentLength); void SALOMEDS_AttributeTableOfString_i::SetTitle(const char* theTitle) { @@ -43,7 +42,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() @@ -55,27 +54,39 @@ char* SALOMEDS_AttributeTableOfString_i::GetTitle() } void SALOMEDS_AttributeTableOfString_i::SetRowTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); + 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) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + CORBA::String_var c_s = CORBA::string_dup(aTable->GetRowTitle(theIndex).c_str()); + return c_s._retn(); } void SALOMEDS_AttributeTableOfString_i::SetRowTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theTitles.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength(); + 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())); } } @@ -91,26 +102,38 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRowTitles() } void SALOMEDS_AttributeTableOfString_i::SetColumnTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); - aTable->SetColumnTitle(theIndex, string((char*)theTitle)); + if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + aTable->SetColumnTitle(theIndex, std::string((char*)theTitle)); +} + +char* SALOMEDS_AttributeTableOfString_i::GetColumnTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theIndex <= 0 || theIndex > aTable->GetNbColumns()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + CORBA::String_var c_s = CORBA::string_dup(aTable->GetColumnTitle(theIndex).c_str()); + return c_s._retn(); } void SALOMEDS_AttributeTableOfString_i::SetColumnTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theTitles.length() != aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength(); + 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())); } } @@ -127,26 +150,38 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumnTitles() //Units support void SALOMEDS_AttributeTableOfString_i::SetRowUnit(CORBA::Long theIndex, const char* theUnit) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectIndex); CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); - aTable->SetRowUnit(theIndex, string((char*)theUnit)); + if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + aTable->SetRowUnit(theIndex, std::string((char*)theUnit)); +} + +char* SALOMEDS_AttributeTableOfString_i::GetRowUnit(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) +{ + SALOMEDS::Locker lock; + Unexpect aCatch (ATS_IncorrectIndex); + CheckLocked(); + SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); + if (theIndex <= 0 || theIndex > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); + CORBA::String_var c_s = CORBA::string_dup(aTable->GetRowUnit(theIndex).c_str()); + return c_s._retn(); } void SALOMEDS_AttributeTableOfString_i::SetRowUnits(const SALOMEDS::StringSeq& theUnits) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectArgumentLength); CheckLocked(); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theUnits.length() != aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectArgumentLength(); + 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())); } } @@ -175,41 +210,41 @@ CORBA::Long SALOMEDS_AttributeTableOfString_i::GetNbColumns() } void SALOMEDS_AttributeTableOfString_i::AddRow(const SALOMEDS::StringSeq& theData) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectArgumentLength); 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); } void SALOMEDS_AttributeTableOfString_i::SetRow(CORBA::Long theRow, const SALOMEDS::StringSeq& theData) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectArgumentLength); 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); } SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRow) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectIndex); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); + 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()); @@ -218,41 +253,41 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetRow(CORBA::Long theRo } void SALOMEDS_AttributeTableOfString_i::AddColumn(const SALOMEDS::StringSeq& theData) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectArgumentLength); 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); } void SALOMEDS_AttributeTableOfString_i::SetColumn(CORBA::Long theColumn, const SALOMEDS::StringSeq& theData) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectArgumentLength); 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); } SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectIndex); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theColumn <= 0 || theColumn > aTable->GetNbColumns()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); + 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()); @@ -261,7 +296,7 @@ SALOMEDS::StringSeq* SALOMEDS_AttributeTableOfString_i::GetColumn(CORBA::Long th } void SALOMEDS_AttributeTableOfString_i::PutValue(const char* theValue, CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectIndex); @@ -279,34 +314,50 @@ CORBA::Boolean SALOMEDS_AttributeTableOfString_i::HasValue(CORBA::Long theRow, C } char* SALOMEDS_AttributeTableOfString_i::GetValue(CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex) { SALOMEDS::Locker lock; Unexpect aCatch(ATS_IncorrectIndex); SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); + if (theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTable::IncorrectIndex(); - string aValue; + std::string aValue; try { aValue = aTable->GetValue(theRow, theColumn); } catch(...) { - throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); + throw SALOMEDS::AttributeTable::IncorrectIndex(); } 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) { SALOMEDS::Locker lock; SALOMEDSImpl_AttributeTableOfString* aTable = dynamic_cast(_impl); - if(theRow <= 0 || theRow > aTable->GetNbRows()) throw SALOMEDS::AttributeTableOfString::IncorrectIndex(); + 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]; @@ -314,7 +365,6 @@ SALOMEDS::LongSeq* SALOMEDS_AttributeTableOfString_i::GetRowSetIndices(CORBA::Lo return CorbaSeq._retn(); } - void SALOMEDS_AttributeTableOfString_i::SetNbColumns(CORBA::Long theNbColumns) { SALOMEDS::Locker lock; @@ -327,7 +377,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; } @@ -337,7 +387,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); @@ -348,3 +398,167 @@ SALOMEDS::TMPFile* SALOMEDS_AttributeTableOfString_i::SaveToFile() return aStreamFile._retn(); } +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortByRow(theRow, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +SALOMEDS::LongSeq* 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(); + + std::vector aSeq; + SALOMEDS::LongSeq_var CorbaSeq = new SALOMEDS::LongSeq; + try { + aSeq = aTable->SortByColumn(theColumn, (SALOMEDSImpl_AttributeTable::SortOrder)sortOrder, + (SALOMEDSImpl_AttributeTable::SortPolicy)sortPolicy); + } + catch(...) { + throw SALOMEDS::AttributeTable::IncorrectIndex(); + } + CorbaSeq->length(aSeq.size()); + for (int i = 0; i < aSeq.size(); i++) { + CorbaSeq[i] = aSeq[i]; + } + return CorbaSeq._retn(); +} + +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 d4743e437..abd2232a0 100644 --- a/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.hxx +++ b/src/SALOMEDS/SALOMEDS_AttributeTableOfString_i.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDS_AttributeTableOfString_i.hxx // Author : Sergey RUIN // Module : SALOME @@ -46,48 +47,76 @@ public: virtual void SetTitle(const char* theTitle); virtual char* GetTitle(); virtual void SetRowTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetRowTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetRowTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetRowTitles(); virtual void SetColumnTitle(CORBA::Long theIndex, const char* theTitle) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetColumnTitle(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetColumnTitles(const SALOMEDS::StringSeq& theTitles) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetColumnTitles(); virtual void SetRowUnit(CORBA::Long theIndex, const char* theUnit) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual char* GetRowUnit(CORBA::Long theIndex) + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void SetRowUnits(const SALOMEDS::StringSeq& theUnits) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual SALOMEDS::StringSeq* GetRowUnits(); virtual CORBA::Long GetNbRows(); virtual CORBA::Long GetNbColumns(); virtual void AddRow(const SALOMEDS::StringSeq& theData) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual void SetRow(CORBA::Long theRow, const SALOMEDS::StringSeq& theData) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::StringSeq* GetRow(CORBA::Long theRow) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void AddColumn(const SALOMEDS::StringSeq& theData) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength); virtual void SetColumn(CORBA::Long theColumn, const SALOMEDS::StringSeq& theData) - throw (SALOMEDS::AttributeTableOfString::IncorrectArgumentLength, SALOMEDS::AttributeTableOfString::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectArgumentLength, SALOMEDS::AttributeTable::IncorrectIndex); virtual SALOMEDS::StringSeq* GetColumn(CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual void PutValue(const char* theValue, CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex); + throw (SALOMEDS::AttributeTable::IncorrectIndex); virtual CORBA::Boolean HasValue(CORBA::Long theRow, CORBA::Long theColumn); virtual char* GetValue(CORBA::Long theRow, CORBA::Long theColumn) - throw (SALOMEDS::AttributeTableOfString::IncorrectIndex); + 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 SALOMEDS::LongSeq* SortRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* SortColumn(CORBA::Long theColumn, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* SortByRow(CORBA::Long theRow, SALOMEDS::AttributeTable::SortOrder sortOrder, + SALOMEDS::AttributeTable::SortPolicy sortPolicy) + throw (SALOMEDS::AttributeTable::IncorrectIndex); + virtual SALOMEDS::LongSeq* 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..1bc425a5b --- /dev/null +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTable.hxx @@ -0,0 +1,79 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 std::vector SortRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) = 0; + virtual std::vector SortColumn(int theColumn, SortOrder theOrder, SortPolicy thePolicy) = 0; + virtual std::vector SortByRow(int theRow, SortOrder theOrder, SortPolicy thePolicy) = 0; + virtual std::vector 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 1f3bff0ff..ddd263451 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfInteger.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDSClient_AttributeTableOfInteger.hxx // Author : Sergey RUIN // Module : SALOME @@ -29,28 +30,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 void SetRowTitles(const std::vector& theTitles) = 0; - virtual std::vector GetRowTitles() = 0; - virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 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 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; @@ -58,12 +42,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 22b614de1..fee299f92 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfReal.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDSClient_AttributeTableOfReal.hxx // Author : Michael Ponikarov // Module : SALOME @@ -29,27 +30,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 void SetRowTitles(const std::vector& theTitles) = 0; - virtual std::vector GetRowTitles() = 0; - virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 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 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; @@ -57,12 +42,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 5bed53cd9..3851faa1b 100644 --- a/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx +++ b/src/SALOMEDSClient/SALOMEDSClient_AttributeTableOfString.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDSClient_AttributeTableOfString.hxx // Author : Sergey RUIN // Module : SALOME @@ -29,27 +30,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 void SetRowTitles(const std::vector& theTitles) = 0; - virtual std::vector GetRowTitles() = 0; - virtual void SetColumnTitle(int theIndex, const std::string& theTitle) = 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 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; @@ -57,12 +42,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 731cf625a..57d7e26d4 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 \ @@ -187,6 +188,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..aeed32ffe --- /dev/null +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTable.hxx @@ -0,0 +1,106 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// 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 24a21d772..c5a123ebb 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,17 +19,18 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDSImpl_AttributeTableOfInteger.cxx // 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()) @@ -151,11 +150,11 @@ vector SALOMEDSImpl_AttributeTableOfInteger::GetRowData(const int theRow) } void SALOMEDSImpl_AttributeTableOfInteger::SetRowTitle(const int theRow, - const std::string& theTitle) + const std::string& theTitle) { CheckLocked(); Backup(); - string aTitle(theTitle), aUnit = GetRowUnit(theRow); + std::string aTitle(theTitle), aUnit = GetRowUnit(theRow); if(aUnit.size()>0) { aTitle += SEPARATOR; aTitle += aUnit; @@ -166,7 +165,7 @@ void SALOMEDSImpl_AttributeTableOfInteger::SetRowTitle(const int theRow, } void SALOMEDSImpl_AttributeTableOfInteger::SetRowUnit(const int theRow, - const std::string& theUnit) + const std::string& theUnit) { CheckLocked(); Backup(); @@ -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,9 +262,9 @@ vector SALOMEDSImpl_AttributeTableOfInteger::GetColumnData(const int theCol } void SALOMEDSImpl_AttributeTableOfInteger::SetColumnTitle(const int theColumn, - const std::string& theTitle) + const std::string& theTitle) { - CheckLocked(); + CheckLocked(); Backup(); while(myCols.size() < theColumn) myCols.push_back(std::string("")); myCols[theColumn-1] = theTitle; @@ -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; @@ -331,7 +328,7 @@ void SALOMEDSImpl_AttributeTableOfInteger::PutValue(const int theValue, } bool SALOMEDSImpl_AttributeTableOfInteger::HasValue(const int theRow, - const int theColumn) + const int theColumn) { if(theRow > myNbRows || theRow < 1) return false; if(theColumn > myNbColumns || theColumn < 1) return false; @@ -340,10 +337,10 @@ bool SALOMEDSImpl_AttributeTableOfInteger::HasValue(const int theRow, } int SALOMEDSImpl_AttributeTableOfInteger::GetValue(const int theRow, - const int theColumn) + 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 SALOMEDSImpl_AttributeTableOfInteger::SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfInteger::SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfInteger::SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfInteger::SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +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); + // swap row titles + std::string tmp = myRows[theRow1-1]; + myRows[theRow1-1] = myRows[theRow2-1]; + myRows[theRow2-1] = tmp; + // 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); + // swap column titles + std::string tmp = myCols[theColumn1-1]; + myCols[theColumn1-1] = myCols[theColumn2-1]; + myCols[theColumn2-1] = tmp; + // 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..9c4948180 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfInteger.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SALOME SALOMEDSImpl : data structure of SALOME and sources of Salome data server // File : SALOMEDSImpl_AttributeTableOfInteger.hxx // Author : Michael Ponikarov @@ -31,6 +32,7 @@ #include "DF_Attribute.hxx" #include "DF_Label.hxx" #include "SALOMEDSImpl_GenericAttribute.hxx" +#include "SALOMEDSImpl_AttributeTable.hxx" #include #include @@ -38,59 +40,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); - 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); + std::vector GetSetRowIndices(const int theRow); + std::vector GetSetColumnIndices(const int theColumn); - std::vector GetSetRowIndices(const int theRow); - std::vector GetSetColumnIndices(const int theColumn); + std::vector SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector 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_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 af1baaacd..6036e27c1 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,35 +19,31 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDSImpl_AttributeTableOfReal.cxx // Author : Michael Ponikarov // Module : SALOME // #include "SALOMEDSImpl_AttributeTableOfReal.hxx" -#include -#include -using namespace std; +#include +#include #define SEPARATOR '\1' +typedef std::map::const_iterator MI; -typedef map::const_iterator MI; - -static std::string getUnit(std::string theString) +static std::string getUnit(const std::string& theString) { std::string aString(theString); int aPos = aString.find(SEPARATOR); - if(aPos <= 0 || aPos == aString.size() ) return std::string(); - return aString.substr(aPos+1, aString.size()); + return aPos < 0 || aPos == aString.size()-1 ? std::string() : aString.substr(aPos+1, aString.size()); } -static std::string getTitle(std::string theString) +static std::string getTitle(const std::string& theString) { std::string aString(theString); int aPos = aString.find(SEPARATOR); - if(aPos < 0) return aString; - if(aPos == 0) return std::string(); - return aString.substr(0, aPos); + return aPos < 0 ? aString :aString.substr(0, aPos); } const std::string& SALOMEDSImpl_AttributeTableOfReal::GetID() @@ -78,7 +74,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetNbColumns(const int theNbColumns) CheckLocked(); Backup(); - map aMap; + std::map aMap; aMap = myTable; myTable.clear(); @@ -94,7 +90,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetNbColumns(const int theNbColumns) myNbColumns = theNbColumns; while (myCols.size() < myNbColumns) { // append empty columns titles - myCols.push_back(string("")); + myCols.push_back(std::string("")); } SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved @@ -115,7 +111,7 @@ std::string SALOMEDSImpl_AttributeTableOfReal::GetTitle() const } void SALOMEDSImpl_AttributeTableOfReal::SetRowData(const int theRow, - const vector& theData) + const std::vector& theData) { CheckLocked(); if(theData.size() > myNbColumns) SetNbColumns(theData.size()); @@ -136,9 +132,9 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowData(const int theRow, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfReal::GetRowData(const int theRow) +std::vector SALOMEDSImpl_AttributeTableOfReal::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()) @@ -150,9 +146,8 @@ vector SALOMEDSImpl_AttributeTableOfReal::GetRowData(const int theRow) return aSeq; } - void SALOMEDSImpl_AttributeTableOfReal::SetRowTitle(const int theRow, - const std::string& theTitle) + const std::string& theTitle) { CheckLocked(); Backup(); @@ -167,7 +162,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowTitle(const int theRow, } void SALOMEDSImpl_AttributeTableOfReal::SetRowUnit(const int theRow, - const std::string& theUnit) + const std::string& theUnit) { CheckLocked(); Backup(); @@ -180,7 +175,7 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowUnit(const int theRow, SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const vector& theUnits) +void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const std::vector& theUnits) { if (theUnits.size() != GetNbRows()) throw DFexception("Invalid number of rows"); int aLength = theUnits.size(), i; @@ -189,15 +184,15 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowUnits(const vector& theUni SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfReal::GetRowUnits() +std::vector SALOMEDSImpl_AttributeTableOfReal::GetRowUnits() { - vector aSeq; + std::vector aSeq; int aLength = myRows.size(), i; for(i=0; i& theTitles) +void SALOMEDSImpl_AttributeTableOfReal::SetRowTitles(const std::vector& theTitles) { if (theTitles.size() != GetNbRows()) throw DFexception("Invalid number of rows"); int aLength = theTitles.size(), i; @@ -206,15 +201,14 @@ void SALOMEDSImpl_AttributeTableOfReal::SetRowTitles(const vector& theTi SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfReal::GetRowTitles() +std::vector SALOMEDSImpl_AttributeTableOfReal::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); @@ -242,17 +236,16 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnData(const int theColumn, if(aLength > myNbRows) { myNbRows = aLength; while (myRows.size() < myNbRows) { // append empty row titles - myRows.push_back(string("")); + myRows.push_back(std::string("")); } } SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } - -vector SALOMEDSImpl_AttributeTableOfReal::GetColumnData(const int theColumn) +std::vector SALOMEDSImpl_AttributeTableOfReal::GetColumnData(const int theColumn) { - vector aSeq; + std::vector aSeq; int i, anIndex; for(i = 1; i <= myNbRows; i++) { @@ -267,7 +260,7 @@ vector SALOMEDSImpl_AttributeTableOfReal::GetColumnData(const int theCol } void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitle(const int theColumn, - const std::string& theTitle) + const std::string& theTitle) { CheckLocked(); Backup(); @@ -284,7 +277,7 @@ std::string SALOMEDSImpl_AttributeTableOfReal::GetColumnTitle(const int theColum return myCols[theColumn-1]; } -void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const vector& theTitles) +void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const std::vector& theTitles) { if (theTitles.size() != myNbColumns) throw DFexception("Invalid number of columns"); int aLength = theTitles.size(), i; @@ -293,9 +286,9 @@ void SALOMEDSImpl_AttributeTableOfReal::SetColumnTitles(const vector& th SetModifyFlag(); //SRN: Mark the study as being modified, so it could be saved } -vector SALOMEDSImpl_AttributeTableOfReal::GetColumnTitles() +std::vector SALOMEDSImpl_AttributeTableOfReal::GetColumnTitles() { - vector aSeq; + std::vector aSeq; int aLength = myCols.size(), i; for(i=0; i myNbColumns) SetNbColumns(theColumn); int anIndex = (theRow-1)*myNbColumns + theColumn; @@ -332,7 +326,7 @@ void SALOMEDSImpl_AttributeTableOfReal::PutValue(const double& theValue, } bool SALOMEDSImpl_AttributeTableOfReal::HasValue(const int theRow, - const int theColumn) + const int theColumn) { if(theRow > myNbRows || theRow < 1) return false; if(theColumn > myNbColumns || theColumn < 1) return false; @@ -341,7 +335,7 @@ bool SALOMEDSImpl_AttributeTableOfReal::HasValue(const int theRow, } double SALOMEDSImpl_AttributeTableOfReal::GetValue(const int theRow, - const int theColumn) + const int theColumn) { if(theRow > myNbRows || theRow < 1) throw DFexception("Invalid cell index"); if(theColumn > myNbColumns || theColumn < 1) throw DFexception("Invalid cell index"); @@ -353,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(); @@ -406,10 +414,9 @@ void SALOMEDSImpl_AttributeTableOfReal::Paste(DF_Attribute* into) aTable->myCols.push_back(GetColumnTitle(anIndex)); } - -vector SALOMEDSImpl_AttributeTableOfReal::GetSetRowIndices(const int theRow) +std::vector SALOMEDSImpl_AttributeTableOfReal::GetSetRowIndices(const int theRow) { - vector aSeq; + std::vector aSeq; int i, aShift = myNbColumns*(theRow-1); for(i = 1; i <= myNbColumns; i++) { @@ -419,9 +426,9 @@ vector SALOMEDSImpl_AttributeTableOfReal::GetSetRowIndices(const int theRow return aSeq; } -vector SALOMEDSImpl_AttributeTableOfReal::GetSetColumnIndices(const int theColumn) +std::vector SALOMEDSImpl_AttributeTableOfReal::GetSetColumnIndices(const int theColumn) { - vector aSeq; + std::vector aSeq; int i, anIndex; for(i = 1; i <= myNbRows; i++) { @@ -432,9 +439,9 @@ vector SALOMEDSImpl_AttributeTableOfReal::GetSetColumnIndices(const int the return aSeq; } -string SALOMEDSImpl_AttributeTableOfReal::Save() +std::string SALOMEDSImpl_AttributeTableOfReal::Save() { - string aString; + std::string aString; char* buffer = new char[1024]; int i, j, l; @@ -490,9 +497,9 @@ string SALOMEDSImpl_AttributeTableOfReal::Save() return aString; } -void SALOMEDSImpl_AttributeTableOfReal::Load(const string& value) +void SALOMEDSImpl_AttributeTableOfReal::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 SALOMEDSImpl_AttributeTableOfReal::SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfReal::SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfReal::SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfReal::SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +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); + // swap row titles + std::string tmp = myRows[theRow1-1]; + myRows[theRow1-1] = myRows[theRow2-1]; + myRows[theRow2-1] = tmp; + // 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); + // swap column titles + std::string tmp = myCols[theColumn1-1]; + myCols[theColumn1-1] = myCols[theColumn2-1]; + myCols[theColumn2-1] = tmp; + // 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..e9fbc024e 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfReal.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SALOME SALOMEDSImpl : data structure of SALOME and sources of Salome data server // File : SALOMEDSImpl_AttributeTableOfReal.hxx // Author : Michael Ponikarov @@ -31,64 +32,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); + + std::vector SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector 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 c73f7c730..80e6b8892 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.cxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,20 +19,18 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // File : SALOMEDSImpl_AttributeTableOfString.cxx // 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(); @@ -102,7 +100,7 @@ void SALOMEDSImpl_AttributeTableOfString::SetNbColumns(const int theNbColumns) } void SALOMEDSImpl_AttributeTableOfString::SetRowTitle(const int theRow, - const std::string& theTitle) + const std::string& theTitle) { CheckLocked(); Backup(); @@ -117,7 +115,7 @@ void SALOMEDSImpl_AttributeTableOfString::SetRowTitle(const int theRow, } void SALOMEDSImpl_AttributeTableOfString::SetRowUnit(const int theRow, - const std::string& theUnit) + const std::string& theUnit) { CheckLocked(); Backup(); @@ -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++) { @@ -265,7 +260,7 @@ vector SALOMEDSImpl_AttributeTableOfString::GetColumnData(const int theC } void SALOMEDSImpl_AttributeTableOfString::SetColumnTitle(const int theColumn, - const std::string& theTitle) + const std::string& theTitle) { CheckLocked(); Backup(); @@ -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; @@ -332,7 +326,7 @@ void SALOMEDSImpl_AttributeTableOfString::PutValue(const std::string& theValue, } bool SALOMEDSImpl_AttributeTableOfString::HasValue(const int theRow, - const int theColumn) + const int theColumn) { if(theRow > myNbRows || theRow < 1) return false; if(theColumn > myNbColumns || theColumn < 1) return false; @@ -342,7 +336,7 @@ bool SALOMEDSImpl_AttributeTableOfString::HasValue(const int theRow, } std::string SALOMEDSImpl_AttributeTableOfString::GetValue(const int theRow, - const int theColumn) + const int theColumn) { if(theRow > myNbRows || theRow < 1) throw DFexception("Invalid cell index"); if(theColumn > myNbColumns || theColumn < 1) throw DFexception("Invalid cell index"); @@ -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 SALOMEDSImpl_AttributeTableOfString::SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfString::SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfString::SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +std::vector SALOMEDSImpl_AttributeTableOfString::SortByColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy ) +{ + CheckLocked(); + std::vector result; + 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; + } + result = indices; + + 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() + } + return result; +} + +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); + // swap row titles + std::string tmp = myRows[theRow1-1]; + myRows[theRow1-1] = myRows[theRow2-1]; + myRows[theRow2-1] = tmp; + // 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); + // swap column titles + std::string tmp = myCols[theColumn1-1]; + myCols[theColumn1-1] = myCols[theColumn2-1]; + myCols[theColumn2-1] = tmp; + // 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..e91718e7d 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeTableOfString.hxx @@ -1,4 +1,4 @@ -// Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2010 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 @@ -19,6 +19,7 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // + // SALOME SALOMEDSImpl : data structure of SALOME and sources of Salome data server // File : SALOMEDSImpl_AttributeTableOfString.hxx // Author : Sergey Ruin @@ -31,65 +32,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); + std::vector SortRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector SortColumn(const int theColumn, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector SortByRow(const int theRow, SortOrder sortOrder, SortPolicy sortPolicy); + std::vector 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 -- 2.39.2