コード例 #1
0
        public static void ShowActionDialog(this DataTable srcTable, IAscendingIntegerCollection selectedDataColumns)
        {
            DataTableMultipleColumnProxy proxy   = null;
            ConvertXYVToMatrixOptions    options = null;

            try
            {
                proxy = new DataTableMultipleColumnProxy(ConvertXYVToMatrixDataAndOptions.ColumnV, srcTable, null, selectedDataColumns);
                proxy.EnsureExistenceOfIdentifier(ConvertXYVToMatrixDataAndOptions.ColumnX, 1);
                proxy.EnsureExistenceOfIdentifier(ConvertXYVToMatrixDataAndOptions.ColumnY, 1);

                options = new ConvertXYVToMatrixOptions();
            }
            catch (Exception ex)
            {
                Current.Gui.ErrorMessageBox(string.Format("{0}\r\nDetails:\r\n{1}", ex.Message, ex.ToString()), "Error in preparation of 'Convert X-Y-V values to matrix'");
                return;
            }

            var dataAndOptions = new ConvertXYVToMatrixDataAndOptions(proxy, options);

            // in order to show the column names etc in the dialog, it is neccessary to set the source
            if (true == Current.Gui.ShowDialog(ref dataAndOptions, "Choose options", false))
            {
                var destTable = new DataTable();
                proxy   = dataAndOptions.Data;
                options = dataAndOptions.Options;

                string error = null;
                try
                {
                    error = ConvertXYVToMatrix(dataAndOptions.Data, dataAndOptions.Options, destTable);
                }
                catch (Exception ex)
                {
                    error = ex.ToString();
                }
                if (null != error)
                {
                    Current.Gui.ErrorMessageBox(error);
                }

                destTable.Name = srcTable.Name + "_Decomposed";

                // Create a DataSource
                var dataSource = new ConvertXYVToMatrixDataSource(proxy, options, new Altaxo.Data.DataSourceImportOptions());
                destTable.DataSource = dataSource;

                Current.Project.DataTableCollection.Add(destTable);
                Current.IProjectService.ShowDocumentView(destTable);
            }
        }
コード例 #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConvertXYVToMatrixDataSource"/> class.
 /// </summary>
 /// <param name="from">Another instance to copy from.</param>
 public ConvertXYVToMatrixDataSource(ConvertXYVToMatrixDataSource from)
 {
     CopyFrom(from);
 }
コード例 #3
0
        /// <summary>
        /// Creates a matrix from three selected columns. This must be a x-column, a y-column, and a value column.
        /// </summary>
        /// <param name="ctrl">Controller where the columns are selected in.</param>
        /// <returns>Null if no error occurs, or an error message.</returns>
        public static string DoMakeActionWithoutDialog(this DataTable srcTable, IAscendingIntegerCollection selectedDataColumns)
        {
            DataColumn xcol = null, ycol = null, vcol = null;

            // for this command to work, there must be exactly 3 data columns selected
            int nCols = selectedDataColumns.Count;

            if (nCols >= 3)
            {
                for (int i = 0; i < nCols; i++)
                {
                    if (srcTable.DataColumns.GetColumnKind(selectedDataColumns[i]) == ColumnKind.Y)
                    {
                        ycol = srcTable.DataColumns[selectedDataColumns[i]];
                        break;
                    }
                }
                for (int i = 0; i < nCols; i++)
                {
                    if (srcTable.DataColumns.GetColumnKind(selectedDataColumns[i]) == ColumnKind.X)
                    {
                        xcol = srcTable.DataColumns[selectedDataColumns[i]];
                        break;
                    }
                }

                if (xcol == null || ycol == null)
                {
                    return("The selected columns must be a x-column, a y-column, and one or more value columns");
                }
            }
            else
            {
                return("You must select exactly a x-column, a y-column, and one or more value column");
            }

            // use the last column that is a value column as v
            // and use the first column that is an x column as x
            for (int i = 0; i < nCols; i++)
            {
                vcol = srcTable.DataColumns[selectedDataColumns[i]];
                if (object.ReferenceEquals(vcol, xcol) || object.ReferenceEquals(vcol, ycol))
                {
                    continue;
                }


                var proxy = new DataTableMultipleColumnProxy(srcTable, srcTable.DataColumns.GetColumnGroup(vcol));
                proxy.EnsureExistenceOfIdentifier(ConvertXYVToMatrixDataAndOptions.ColumnX, 1);
                proxy.EnsureExistenceOfIdentifier(ConvertXYVToMatrixDataAndOptions.ColumnY, 1);
                proxy.EnsureExistenceOfIdentifier(ConvertXYVToMatrixDataAndOptions.ColumnV, 1);

                proxy.AddDataColumn(ConvertXYVToMatrixDataAndOptions.ColumnX, xcol);
                proxy.AddDataColumn(ConvertXYVToMatrixDataAndOptions.ColumnY, ycol);
                proxy.AddDataColumn(ConvertXYVToMatrixDataAndOptions.ColumnV, vcol);

                var newtablename = Current.Project.DataTableCollection.FindNewItemName(srcTable.Name + "-" + vcol.Name);
                var newTable     = new DataTable(newtablename);
                Current.Project.DataTableCollection.Add(newTable);
                var options = new ConvertXYVToMatrixOptions();
                ConvertXYVToMatrix(proxy, options, newTable);

                var dataSource = new ConvertXYVToMatrixDataSource(proxy, options, new Altaxo.Data.DataSourceImportOptions());
                newTable.DataSource = dataSource;

                Current.IProjectService.ShowDocumentView(newTable);
            }

            return(null);
        }