Beispiel #1
0
        /// <summary>
        /// Sets the column kind of the first selected column to the specified column kind
        /// </summary>
        public static void SetSelectedColumnAsKind(IWorksheetController ctrl, Altaxo.Data.ColumnKind kind)
        {
            bool bChanged = false;

            if (ctrl.SelectedDataColumns.Count > 0)
            {
                for (int i = 0; i < ctrl.SelectedDataColumns.Count; i++)
                {
                    ctrl.DataTable.DataColumns.SetColumnKind(ctrl.SelectedDataColumns[i], kind);
                }
                bChanged = true;
            }
            if (ctrl.SelectedPropertyColumns.Count > 0)
            {
                for (int i = 0; i < ctrl.SelectedPropertyColumns.Count; i++)
                {
                    ctrl.DataTable.PropertyColumns.SetColumnKind(ctrl.SelectedPropertyColumns[i], kind);
                }
                bChanged = true;
            }
            if (bChanged)
            {
                ctrl.TableAreaInvalidate(); // draw new because
            }
        }
Beispiel #2
0
        /// <summary>
        /// Maps each data column of the source table to a corresponding data columns of the destination table.
        /// The matching is based on the index (order) and on the currently selected columns of the destination table.
        /// Attention: The match here does <b>not</b> mean that the two columns are data compatible to each other!
        /// </summary>
        /// <param name="desttable">The destination table.</param>
        /// <param name="selectedDestColumns">The currently selected columns of the destination table.</param>
        /// <param name="sourcetable">The source table.</param>
        /// <returns>An array of columns. Each column of the array is a data column in the destination table, which
        /// matches (by index) the data column in the source table.</returns>
        /// <remarks>
        /// 1.) Since the returned columns are part of the DataColumns collection of the destination table, you must not
        /// use these for inserting i.e. in other tables.
        /// 2.) The match is based on the index and the selected columns of the destination table. The rules are as follows: if there is
        /// no selection, the first column of the destination table matches the first column of the source table, and so forth.
        /// If there is a column selection, the first selected column of the destination table matches the first column of the source table,
        /// the second selected column of the destination table matches the second column of the source table. If more source columns than selected columns in the destination
        /// table exists, the match is done 1:1 after the last selected column of the destination table. If there is no further column in the destination
        /// table to match, new columns are created in the destination table.
        /// </remarks>
        static protected Altaxo.Data.DataColumn[] MapOrCreateDataColumns(Altaxo.Data.DataTable desttable, IAscendingIntegerCollection selectedDestColumns, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataColumn[] columnmap = new Altaxo.Data.DataColumn[sourcetable.DataColumns.ColumnCount];
            int nDestCol = -1;

            for (int nCol = 0; nCol < sourcetable.DataColumns.ColumnCount; nCol++)
            {
                nDestCol = nCol < selectedDestColumns.Count ? selectedDestColumns[nCol] : nDestCol + 1;

                string name  = sourcetable.DataColumns.GetColumnName(nCol);
                int    group = sourcetable.DataColumns.GetColumnGroup(nCol);
                Altaxo.Data.ColumnKind kind = sourcetable.DataColumns.GetColumnKind(nCol);

                if (nDestCol < desttable.DataColumns.ColumnCount)
                {
                    columnmap[nCol] = desttable.DataColumns[nDestCol];
                }
                else
                {
                    columnmap[nCol] = (DataColumn)Activator.CreateInstance(sourcetable.DataColumns[nCol].GetType());
                    desttable.DataColumns.Add(columnmap[nCol], name, kind, group);
                }
            }
            return(columnmap);
        }
Beispiel #3
0
        public static Origin.COLTYPES AltaxoToOriginColumnType(Altaxo.Data.ColumnKind altaxoType)
        {
            COLTYPES originType;

            switch (altaxoType)
            {
            case ColumnKind.V:
                originType = COLTYPES.COLTYPE_Y;
                break;

            case ColumnKind.X:
                originType = COLTYPES.COLTYPE_X;
                break;

            case ColumnKind.Y:
                originType = COLTYPES.COLTYPE_Z;
                break;

            case ColumnKind.Z:
                originType = COLTYPES.COLTYPE_Z;
                break;

            case ColumnKind.Err:
                originType = COLTYPES.COLTYPE_ERROR;
                break;

            case ColumnKind.pErr:
                originType = COLTYPES.COLTYPE_ERROR;
                break;

            case ColumnKind.mErr:
                originType = COLTYPES.COLTYPE_ERROR;
                break;

            case ColumnKind.Label:
                originType = COLTYPES.COLTYPE_LABEL;
                break;

            case ColumnKind.Condition:
                originType = COLTYPES.COLTYPE_NONE;
                break;

            default:
                originType = COLTYPES.COLTYPE_NO_CHANGE;
                break;
            }

            return(originType);
        }
Beispiel #4
0
        /// <summary>
        /// Pastes data from a table (usually deserialized table from the clipboard) into a worksheet, which has
        /// currently selected columns. The number of selected columns has to match the number of columns of the source table.
        /// </summary>
        /// <param name="dg">The worksheet to paste into.</param>
        /// <param name="sourcetable">The table which contains the data to paste into the worksheet.</param>
        /// <remarks>The operation is defined as follows: if the is no ro selection, the data are inserted beginning at row[0] of the destination table.
        /// If there is a row selection, the data are inserted in the selected rows, and then in the rows after the last selected rows.
        /// No exception is thrown if a column type does not match the corresponding source column type.
        /// The columns to paste into do not change their name, kind or group number. But property columns in the source table
        /// are pasted into the destination table.</remarks>
        protected static void PasteFromTableColumnsToSelectedColumns(GUI.WorksheetController dg, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataTable desttable = dg.DataTable;

            Altaxo.Data.DataColumn[] propertycolumnmap = MapOrCreatePropertyColumns(desttable, sourcetable);

            // use the selected columns, then use the following columns, then add columns
            int nDestCol = -1;

            for (int nSrcCol = 0; nSrcCol < sourcetable.DataColumns.ColumnCount; nSrcCol++)
            {
                nDestCol = nSrcCol < dg.SelectedDataColumns.Count ? dg.SelectedDataColumns[nSrcCol] : nDestCol + 1;
                Altaxo.Data.DataColumn destcolumn;
                if (nDestCol < desttable.DataColumns.ColumnCount)
                {
                    destcolumn = desttable.DataColumns[nDestCol];
                }
                else
                {
                    string name  = sourcetable.DataColumns.GetColumnName(nSrcCol);
                    int    group = sourcetable.DataColumns.GetColumnGroup(nSrcCol);
                    Altaxo.Data.ColumnKind kind = sourcetable.DataColumns.GetColumnKind(nSrcCol);
                    destcolumn = (Altaxo.Data.DataColumn)Activator.CreateInstance(sourcetable.DataColumns[nSrcCol].GetType());
                    desttable.DataColumns.Add(destcolumn, name, kind, group);
                }

                // now fill the data into that column
                Altaxo.Data.DataColumn sourcecolumn = sourcetable.DataColumns[nSrcCol];

                try
                {
                    int nDestRow = -1;
                    for (int nSrcRow = 0; nSrcRow < sourcetable.DataColumns.RowCount; nSrcRow++)
                    {
                        nDestRow             = nSrcRow < dg.SelectedDataRows.Count ? dg.SelectedDataRows[nSrcRow] : nDestRow + 1;
                        destcolumn[nDestRow] = sourcecolumn[nSrcRow];
                    }
                }
                catch (Exception)
                {
                }


                // also fill in the property values
                int nDestColumnIndex = desttable.DataColumns.GetColumnNumber(destcolumn);
                FillRow(propertycolumnmap, nDestColumnIndex, sourcetable.PropCols, nSrcCol);
            } // for all data columns
        }
Beispiel #5
0
        /// <summary>
        /// Pastes data from a table (usually deserialized table from the clipboard) into a worksheet, which has
        /// no current selections. This means that the data are appended to the end of the worksheet.
        /// </summary>
        /// <param name="dg">The worksheet to paste into.</param>
        /// <param name="sourcetable">The table which contains the data to paste into the worksheet.</param>
        protected static void PasteFromTableToUnselected(GUI.WorksheetController dg, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataTable    desttable         = dg.DataTable;
            Altaxo.Data.DataColumn[] propertycolumnmap = MapOrCreatePropertyColumns(desttable, sourcetable);

            // add first the data columns to the end of the table
            for (int nCol = 0; nCol < sourcetable.DataColumns.ColumnCount; nCol++)
            {
                string name  = sourcetable.DataColumns.GetColumnName(nCol);
                int    group = sourcetable.DataColumns.GetColumnGroup(nCol);
                Altaxo.Data.ColumnKind kind       = sourcetable.DataColumns.GetColumnKind(nCol);
                Altaxo.Data.DataColumn destcolumn = (Altaxo.Data.DataColumn)sourcetable.DataColumns[nCol].Clone();
                desttable.DataColumns.Add(destcolumn, name, kind, group);

                // also fill in the property values
                int nDestColumnIndex = desttable.DataColumns.GetColumnNumber(destcolumn);
                FillRow(propertycolumnmap, nDestColumnIndex, sourcetable.PropCols, nCol);
            } // for all data columns
        }
Beispiel #6
0
        /// <summary>
        /// Pastes data from a table (usually deserialized table from the clipboard) into a worksheet, which has
        /// currently selected property columns. The sourceTable is transposed before pasting, i.e. the number of selected property columns has to match the number of data (!) rows of the source table.
        /// </summary>
        /// <param name="dg">The worksheet to paste into.</param>
        /// <param name="sourceTable">The table which contains the data to paste into the worksheet.</param>
        /// <remarks>The operation is defined as follows: if the is no ro selection, the data are inserted beginning at row[0] of the destination table.
        /// If there is a row selection, the data are inserted in the selected rows, and then in the rows after the last selected rows.
        /// No exception is thrown if a column type does not match the corresponding source column type.
        /// The columns to paste into do not change their name, kind or group number. But property columns in the source table
        /// are pasted into the destination table.</remarks>
        protected static void PasteFromTableColumnsTransposedToSelectedPropertyColumns(IWorksheetController dg, Altaxo.Data.DataTable sourceTable)
        {
            Altaxo.Data.DataTable destinationTable = dg.DataTable;

            // use the selected columns, then use the following columns, then add columns
            int destinationColumnIndex = -1;

            for (int sourceRowIndex = 0; sourceRowIndex < sourceTable.DataColumns.RowCount; sourceRowIndex++)
            {
                destinationColumnIndex = sourceRowIndex < dg.SelectedPropertyColumns.Count ? dg.SelectedPropertyColumns[sourceRowIndex] : destinationColumnIndex + 1;
                Altaxo.Data.DataColumn destinationPropertyColumn;
                if (destinationColumnIndex < destinationTable.PropertyColumns.ColumnCount)
                {
                    destinationPropertyColumn = destinationTable.PropertyColumns[destinationColumnIndex];
                }
                else
                {
                    string name  = sourceTable.DataColumns.GetColumnName(0);
                    int    group = sourceTable.DataColumns.GetColumnGroup(0);
                    Altaxo.Data.ColumnKind kind = sourceTable.DataColumns.GetColumnKind(0);
                    destinationPropertyColumn = (Altaxo.Data.DataColumn)Activator.CreateInstance(sourceTable.DataColumns[0].GetType());
                    destinationTable.PropertyColumns.Add(destinationPropertyColumn, name, kind, group);
                }

                // now fill the data into that column
                try
                {
                    int destinationRowIndex = -1;
                    for (int sourceColumnIndex = 0; sourceColumnIndex < sourceTable.DataColumns.ColumnCount; sourceColumnIndex++)
                    {
                        destinationRowIndex = sourceColumnIndex < dg.SelectedPropertyRows.Count ? dg.SelectedPropertyRows[sourceColumnIndex] : destinationRowIndex + 1;
                        destinationPropertyColumn[destinationRowIndex] = sourceTable.DataColumns[sourceColumnIndex][sourceRowIndex];
                    }
                }
                catch (Exception)
                {
                }
            } // for all data columns
        }
Beispiel #7
0
        /// <summary>
        /// Maps each property column of the source table to a corresponding property columns of the destination table. If no matching property
        /// column can be found in the destination table, a new matching property column is added to the destination table.
        /// </summary>
        /// <param name="desttable">The destination table.</param>
        /// <param name="sourcetable">The source table.</param>
        /// <returns>An array of columns. Each column of the array is a property column in the destination table, which
        /// matches the property column in the source table by index.</returns>
        /// <remarks>
        /// 1.) Since the returned columns are part of the PropCols collection of the destination table, you must not
        /// use these for inserting i.e. in other tables.
        /// 2.) The match is based on the names _and_ the types of the property columns. If there is no match,
        /// a new property column of the same type as in the source table and with a reasonable name is created.
        /// Therefore each mapped property column has the same type as its counterpart in the source table.
        /// </remarks>
        static protected Altaxo.Data.DataColumn[] MapOrCreatePropertyColumns(Altaxo.Data.DataTable desttable, Altaxo.Data.DataTable sourcetable)
        {
            Altaxo.Data.DataColumn[] columnmap = new Altaxo.Data.DataColumn[sourcetable.PropCols.ColumnCount];
            for (int nCol = 0; nCol < sourcetable.PropCols.ColumnCount; nCol++)
            {
                string name  = sourcetable.PropCols.GetColumnName(nCol);
                int    group = sourcetable.PropCols.GetColumnGroup(nCol);
                Altaxo.Data.ColumnKind kind = sourcetable.PropCols.GetColumnKind(nCol);

                // if a property column with the same name and kind exist - use that one - else create a new one
                if (desttable.PropCols.ContainsColumn(name) && desttable.PropCols[name].GetType() == sourcetable.PropCols[nCol].GetType())
                {
                    columnmap[nCol] = desttable.PropCols[name];
                }
                else
                {
                    // the prop col must be empty - we will add the data later
                    columnmap[nCol] = (DataColumn)Activator.CreateInstance(sourcetable.PropCols[nCol].GetType());
                    desttable.PropCols.Add(columnmap[nCol], name, kind, group);
                }
            }
            return(columnmap);
        }