示例#1
0
        /// <summary>
        /// Tests if the data in <paramref name="data"/> can be used for the DecomposeByColumnContent action.
        /// </summary>
        /// <param name="data">The data to test.</param>
        /// <param name="throwIfNonCoherent">If true, an exception is thrown if any problems are detected. If false, it is tried to rectify the problem by making some assumtions.</param>
        public static void EnsureCoherence(DataTableMultipleColumnProxy data, bool throwIfNonCoherent)
        {
            if (null == data.DataTable) // this is mandatory, thus an exception is always thrown
            {
                throw new ArgumentNullException("SourceTable is null, it must be set before");
            }

            data.EnsureExistenceOfIdentifier(ColumnsParticipatingIdentifier);
            data.EnsureExistenceOfIdentifier(ColumnWithCyclingVariableIdentifier, 1);

            if (data.GetDataColumns(ColumnsParticipatingIdentifier).Count == 0)
            {
                if (throwIfNonCoherent)
                {
                    throw new ArgumentException(!data.ContainsIdentifier(ColumnsParticipatingIdentifier) ? "ColumnsToProcess is not set" : "ColumnsToProcess is empty");
                }
            }

            if (data.GetDataColumnOrNull(ColumnWithCyclingVariableIdentifier) == null)
            {
                if (throwIfNonCoherent)
                {
                    throw new ArgumentException("Column with cycling variable was not included in columnsToProcess");
                }
                else
                {
                    var col = data.GetDataColumns(ColumnsParticipatingIdentifier).FirstOrDefault();
                    if (null != col)
                    {
                        data.SetDataColumn(ColumnWithCyclingVariableIdentifier, col);
                    }
                }
            }
        }
        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);
            }
        }
示例#3
0
        public static void ShowExpandCyclingVariableColumnDialog(this DataTable srcTable, IAscendingIntegerCollection selectedDataRows, IAscendingIntegerCollection selectedDataColumns)
        {
            DataTableMultipleColumnProxy       proxy   = null;
            ExpandCyclingVariableColumnOptions options = null;

            try
            {
                proxy = new DataTableMultipleColumnProxy(ExpandCyclingVariableColumnDataAndOptions.ColumnsParticipatingIdentifier, srcTable, selectedDataRows, selectedDataColumns);
                proxy.EnsureExistenceOfIdentifier(ExpandCyclingVariableColumnDataAndOptions.ColumnWithCyclingVariableIdentifier, 1);
                proxy.EnsureExistenceOfIdentifier(ExpandCyclingVariableColumnDataAndOptions.ColumnsToAverageIdentifier);

                options = new ExpandCyclingVariableColumnOptions();
            }
            catch (Exception ex)
            {
                Current.Gui.ErrorMessageBox(string.Format("{0}\r\nDetails:\r\n{1}", ex.Message, ex.ToString()), "Error in preparation of 'Expand Cycling Variable'");
                return;
            }

            var dataAndOptions = new ExpandCyclingVariableColumnDataAndOptions(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 = ExpandCyclingVariableColumn(dataAndOptions.Data, dataAndOptions.Options, destTable);
                }
                catch (Exception ex)
                {
                    error = ex.ToString();
                }
                if (null != error)
                {
                    Current.Gui.ErrorMessageBox(error);
                }

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

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

                Current.Project.DataTableCollection.Add(destTable);
                Current.IProjectService.ShowDocumentView(destTable);
            }
        }
示例#4
0
		public static void ShowDecomposeByColumnContentDialog(this DataTable srcTable, IAscendingIntegerCollection selectedDataRows, IAscendingIntegerCollection selectedDataColumns)
		{
			DataTableMultipleColumnProxy proxy = null;
			DecomposeByColumnContentOptions options = null;

			try
			{
				proxy = new DataTableMultipleColumnProxy(DecomposeByColumnContentDataAndOptions.ColumnsParticipatingIdentifier, srcTable, selectedDataRows, selectedDataColumns);
				proxy.EnsureExistenceOfIdentifier(DecomposeByColumnContentDataAndOptions.ColumnWithCyclingVariableIdentifier, 1);

				options = new DecomposeByColumnContentOptions();
			}
			catch (Exception ex)
			{
				Current.Gui.ErrorMessageBox(string.Format("{0}\r\nDetails:\r\n{1}", ex.Message, ex.ToString()), "Error in preparation of 'Decompose by column content'");
				return;
			}

			var dataAndOptions = new DecomposeByColumnContentDataAndOptions(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 = DecomposeByColumnContent(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 DecomposeByColumnContentDataSource(proxy, options, new Altaxo.Data.DataSourceImportOptions());
				destTable.DataSource = dataSource;

				Current.Project.DataTableCollection.Add(destTable);
				Current.ProjectService.ShowDocumentView(destTable);
			}
		}
示例#5
0
		/// <summary>
		/// Tests if the data in <paramref name="data"/> can be used for the DecomposeByColumnContent action.
		/// </summary>
		/// <param name="data">The data to test.</param>
		/// <param name="throwIfNonCoherent">If true, an exception is thrown if any problems are detected. If false, it is tried to rectify the problem by making some assumtions.</param>
		public static void EnsureCoherence(DataTableMultipleColumnProxy data, bool throwIfNonCoherent)
		{
			if (null == data.DataTable) // this is mandatory, thus an exception is always thrown
			{
				throw new ArgumentNullException("SourceTable is null, it must be set before");
			}

			data.EnsureExistenceOfIdentifier(ColumnsParticipatingIdentifier);
			data.EnsureExistenceOfIdentifier(ColumnWithCyclingVariableIdentifier, 1);

			if (data.GetDataColumns(ColumnsParticipatingIdentifier).Count == 0)
			{
				if (throwIfNonCoherent)
					throw new ArgumentException(!data.ContainsIdentifier(ColumnsParticipatingIdentifier) ? "ColumnsToProcess is not set" : "ColumnsToProcess is empty");
			}

			if (data.GetDataColumnOrNull(ColumnWithCyclingVariableIdentifier) == null)
			{
				if (throwIfNonCoherent)
					throw new ArgumentException("Column with cycling variable was not included in columnsToProcess");
				else
				{
					var col = data.GetDataColumns(ColumnsParticipatingIdentifier).FirstOrDefault();
					if (null != col)
						data.SetDataColumn(ColumnWithCyclingVariableIdentifier, col);
				}
			}
		}
        /// <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);
        }