/// <summary>
        /// Copies from another instance.
        /// </summary>
        /// <param name="obj">The object to copy from.</param>
        /// <returns><c>True</c> if anything could be copied from the object, otherwise <c>false</c>.</returns>
        public bool CopyFrom(object obj)
        {
            if (object.ReferenceEquals(this, obj))
            {
                return(true);
            }

            var from = obj as DecomposeByColumnContentDataSource;

            if (null != from)
            {
                using (var token = SuspendGetToken())
                {
                    DecomposeByColumnContentOptions dataSourceOptions = null;
                    DataTableMultipleColumnProxy    inputData         = null;
                    IDataSourceImportOptions        importOptions     = null;

                    CopyHelper.Copy(ref importOptions, from._importOptions);
                    CopyHelper.Copy(ref dataSourceOptions, from._processOptions);
                    CopyHelper.Copy(ref inputData, from._processData);

                    DecomposeByColumnContentOptions = dataSourceOptions;
                    ImportOptions = importOptions;
                    InputData     = inputData;

                    return(true);
                }
            }
            return(false);
        }
        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.IProjectService.ShowDocumentView(destTable);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DecomposeByColumnContentDataSource"/> class.
        /// </summary>
        /// <param name="inputData">The input data designates the original source of data (used then for the processing).</param>
        /// <param name="dataSourceOptions">The Fourier transformation options.</param>
        /// <param name="importOptions">The data source import options.</param>
        /// <exception cref="System.ArgumentNullException">
        /// inputData
        /// or
        /// transformationOptions
        /// or
        /// importOptions
        /// </exception>
        public DecomposeByColumnContentDataSource(DataTableMultipleColumnProxy inputData, DecomposeByColumnContentOptions dataSourceOptions, IDataSourceImportOptions importOptions)
        {
            if (null == inputData)
            {
                throw new ArgumentNullException("inputData");
            }
            if (null == dataSourceOptions)
            {
                throw new ArgumentNullException("dataSourceOptions");
            }
            if (null == importOptions)
            {
                throw new ArgumentNullException("importOptions");
            }

            using (var token = SuspendGetToken())
            {
                DecomposeByColumnContentOptions = dataSourceOptions;
                ImportOptions = importOptions;
                InputData     = inputData;
            }
        }
Exemple #4
0
 public DecomposeByColumnContentOptions(DecomposeByColumnContentOptions from)
 {
     CopyFrom(from);
 }
		/// <summary>
		/// Decompose the source columns according to the provided options. The source table and the settings are provided in the <paramref name="options"/> variable.
		/// The provided destination table is cleared from all data and property values before.
		/// </summary>
		/// <param name="inputData">The data containing the source table, the participating columns and the column with the cycling variable.</param>
		/// <param name="options">The settings for decomposing.</param>
		/// <param name="destTable">The destination table. Any data will be removed before filling with the new data.</param>
		/// <returns>Null if the method finishes successfully, or an error information.</returns>
		public static string DecomposeByColumnContent(DataTableMultipleColumnProxy inputData, DecomposeByColumnContentOptions options, DataTable destTable)
		{
			var srcTable = inputData.DataTable;

			try
			{
				DecomposeByColumnContentDataAndOptions.EnsureCoherence(inputData, true);
			}
			catch (Exception ex)
			{
				return ex.Message;
			}

			destTable.DataColumns.RemoveColumnsAll();
			destTable.PropCols.RemoveColumnsAll();

			DataColumn srcCycCol = inputData.GetDataColumnOrNull(DecomposeByColumnContentDataAndOptions.ColumnWithCyclingVariableIdentifier);
			var decomposedValues = Decompose(srcCycCol);
			// the decomposedValues are not sorted yes

			if (options.DestinationColumnSorting == DecomposeByColumnContentOptions.OutputSorting.Ascending)
			{
				decomposedValues.Sort();
			}
			else if (options.DestinationColumnSorting == DecomposeByColumnContentOptions.OutputSorting.Descending)
			{
				decomposedValues.Sort();
				decomposedValues.Reverse();
			}
			// get the other columns to process

			var srcColumnsToProcess = new List<DataColumn>(inputData.GetDataColumns(DecomposeByColumnContentDataAndOptions.ColumnsParticipatingIdentifier));
			// subtract the column containing the decompose values
			srcColumnsToProcess.Remove(srcCycCol);

			// the only property column that is now usefull is that with the repeated values
			var destPropCol = destTable.PropCols.EnsureExistence(srcTable.DataColumns.GetColumnName(srcCycCol), srcCycCol.GetType(), srcTable.DataColumns.GetColumnKind(srcCycCol), srcTable.DataColumns.GetColumnGroup(srcCycCol));

			if (options.DestinationOutput == DecomposeByColumnContentOptions.OutputFormat.GroupOneColumn)
			{
				// columns originating from the same column but with different property are grouped together, but they will get different group numbers
				foreach (var srcCol in srcColumnsToProcess)
				{
					int nCreatedCol = -1;
					int nCreatedProp = 0;
					foreach (var prop in decomposedValues)
					{
						++nCreatedCol;
						++nCreatedProp;
						var destCol = destTable.DataColumns.EnsureExistence(srcTable.DataColumns.GetColumnName(srcCol) + "." + nCreatedCol.ToString(), srcCol.GetType(), srcTable.DataColumns.GetColumnKind(srcCol), nCreatedProp);
						var nDestCol = destTable.DataColumns.GetColumnNumber(destCol);
						for (int i = 0, j = 0; i < srcCycCol.Count; ++i)
						{
							if (prop == srcCycCol[i])
							{
								destCol[j] = srcCol[i];
								++j;
							}
						}
						// fill also property column
						destPropCol[nDestCol] = prop;
					}
				}
			}
			else if (options.DestinationOutput == DecomposeByColumnContentOptions.OutputFormat.GroupAllColumns)
			{
				// all columns with the same property are grouped together, and those columns will share the same group number
				int nCreatedCol = -1; // running number of processed range for column creation (Naming)
				int nCreatedProp = -1;
				foreach (var prop in decomposedValues)
				{
					++nCreatedProp;
					++nCreatedCol;

					foreach (var srcCol in srcColumnsToProcess)
					{
						var destCol = destTable.DataColumns.EnsureExistence(srcTable.DataColumns.GetColumnName(srcCol) + "." + nCreatedCol.ToString(), srcCol.GetType(), srcTable.DataColumns.GetColumnKind(srcCol), nCreatedProp);
						var nDestCol = destTable.DataColumns.GetColumnNumber(destCol);
						for (int i = 0, j = 0; i < srcCycCol.Count; ++i)
						{
							if (prop == srcCycCol[i])
							{
								destCol[j] = srcCol[i];
								++j;
							}
						}
						// fill also property column
						destPropCol[nDestCol] = prop;
					}
				}
			}
			else
			{
				throw new NotImplementedException("The option for destination output is unknown: " + options.DestinationOutput.ToString());
			}

			return null;
		}
		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);
			}
		}
		public DecomposeByColumnContentDataAndOptions(DataTableMultipleColumnProxy data, DecomposeByColumnContentOptions options)
		{
			Data = data;
			Options = options;
		}
		public DecomposeByColumnContentOptions(DecomposeByColumnContentOptions from)
		{
			CopyFrom(from);
		}
        /// <summary>
        /// Decompose the source columns according to the provided options. The source table and the settings are provided in the <paramref name="options"/> variable.
        /// The provided destination table is cleared from all data and property values before.
        /// </summary>
        /// <param name="inputData">The data containing the source table, the participating columns and the column with the cycling variable.</param>
        /// <param name="options">The settings for decomposing.</param>
        /// <param name="destTable">The destination table. Any data will be removed before filling with the new data.</param>
        /// <returns>Null if the method finishes successfully, or an error information.</returns>
        public static string DecomposeByColumnContent(DataTableMultipleColumnProxy inputData, DecomposeByColumnContentOptions options, DataTable destTable)
        {
            var srcTable = inputData.DataTable;

            try
            {
                DecomposeByColumnContentDataAndOptions.EnsureCoherence(inputData, true);
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }

            destTable.DataColumns.RemoveColumnsAll();
            destTable.PropCols.RemoveColumnsAll();

            DataColumn srcCycCol        = inputData.GetDataColumnOrNull(DecomposeByColumnContentDataAndOptions.ColumnWithCyclingVariableIdentifier);
            var        decomposedValues = Decompose(srcCycCol);

            // the decomposedValues are not sorted yes

            if (options.DestinationColumnSorting == DecomposeByColumnContentOptions.OutputSorting.Ascending)
            {
                decomposedValues.Sort();
            }
            else if (options.DestinationColumnSorting == DecomposeByColumnContentOptions.OutputSorting.Descending)
            {
                decomposedValues.Sort();
                decomposedValues.Reverse();
            }
            // get the other columns to process

            var srcColumnsToProcess = new List <DataColumn>(inputData.GetDataColumns(DecomposeByColumnContentDataAndOptions.ColumnsParticipatingIdentifier));

            // subtract the column containing the decompose values
            srcColumnsToProcess.Remove(srcCycCol);

            // the only property column that is now usefull is that with the repeated values
            var destPropCol = destTable.PropCols.EnsureExistence(srcTable.DataColumns.GetColumnName(srcCycCol), srcCycCol.GetType(), srcTable.DataColumns.GetColumnKind(srcCycCol), srcTable.DataColumns.GetColumnGroup(srcCycCol));

            if (options.DestinationOutput == DecomposeByColumnContentOptions.OutputFormat.GroupOneColumn)
            {
                // columns originating from the same column but with different property are grouped together, but they will get different group numbers
                foreach (var srcCol in srcColumnsToProcess)
                {
                    int nCreatedCol  = -1;
                    int nCreatedProp = 0;
                    foreach (var prop in decomposedValues)
                    {
                        ++nCreatedCol;
                        ++nCreatedProp;
                        var destCol  = destTable.DataColumns.EnsureExistence(srcTable.DataColumns.GetColumnName(srcCol) + "." + nCreatedCol.ToString(), srcCol.GetType(), srcTable.DataColumns.GetColumnKind(srcCol), nCreatedProp);
                        var nDestCol = destTable.DataColumns.GetColumnNumber(destCol);
                        for (int i = 0, j = 0; i < srcCycCol.Count; ++i)
                        {
                            if (prop == srcCycCol[i])
                            {
                                destCol[j] = srcCol[i];
                                ++j;
                            }
                        }
                        // fill also property column
                        destPropCol[nDestCol] = prop;
                    }
                }
            }
            else if (options.DestinationOutput == DecomposeByColumnContentOptions.OutputFormat.GroupAllColumns)
            {
                // all columns with the same property are grouped together, and those columns will share the same group number
                int nCreatedCol  = -1; // running number of processed range for column creation (Naming)
                int nCreatedProp = -1;
                foreach (var prop in decomposedValues)
                {
                    ++nCreatedProp;
                    ++nCreatedCol;

                    foreach (var srcCol in srcColumnsToProcess)
                    {
                        var destCol  = destTable.DataColumns.EnsureExistence(srcTable.DataColumns.GetColumnName(srcCol) + "." + nCreatedCol.ToString(), srcCol.GetType(), srcTable.DataColumns.GetColumnKind(srcCol), nCreatedProp);
                        var nDestCol = destTable.DataColumns.GetColumnNumber(destCol);
                        for (int i = 0, j = 0; i < srcCycCol.Count; ++i)
                        {
                            if (prop == srcCycCol[i])
                            {
                                destCol[j] = srcCol[i];
                                ++j;
                            }
                        }
                        // fill also property column
                        destPropCol[nDestCol] = prop;
                    }
                }
            }
            else
            {
                throw new NotImplementedException("The option for destination output is unknown: " + options.DestinationOutput.ToString());
            }

            return(null);
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="DecomposeByColumnContentDataSource"/> class.
		/// </summary>
		/// <param name="inputData">The input data designates the original source of data (used then for the processing).</param>
		/// <param name="dataSourceOptions">The Fourier transformation options.</param>
		/// <param name="importOptions">The data source import options.</param>
		/// <exception cref="System.ArgumentNullException">
		/// inputData
		/// or
		/// transformationOptions
		/// or
		/// importOptions
		/// </exception>
		public DecomposeByColumnContentDataSource(DataTableMultipleColumnProxy inputData, DecomposeByColumnContentOptions dataSourceOptions, IDataSourceImportOptions importOptions)
		{
			if (null == inputData)
				throw new ArgumentNullException("inputData");
			if (null == dataSourceOptions)
				throw new ArgumentNullException("dataSourceOptions");
			if (null == importOptions)
				throw new ArgumentNullException("importOptions");

			using (var token = SuspendGetToken())
			{
				this.DecomposeByColumnContentOptions = dataSourceOptions;
				this.ImportOptions = importOptions;
				this.InputData = inputData;
			}
		}
Exemple #11
0
 public DecomposeByColumnContentDataAndOptions(DataTableMultipleColumnProxy data, DecomposeByColumnContentOptions options)
 {
     Data    = data;
     Options = options;
 }