Example #1
0
        /// <summary>
        /// Asks for file name(s) and imports the file(s) into one or multiple worksheets. After the user chooses one or multiple files, one of the chosen files is used for analysis.
        /// The result of the structure analysis of this file is then presented to the user. The user may change some of the options and starts a re-analysis. Finally, the import options
        /// are confirmed by the user and the import process can start.
        /// </summary>
        /// <param name="dataTable">The data table to import to. Can be null if <paramref name="toMultipleWorksheets"/> is set to <c>true</c>.</param>
        /// <param name="toMultipleWorksheets">If true, multiple files are imported into multiple worksheets. New worksheets were then created automatically.</param>
        /// <param name="vertically">If <c>toMultipleWorksheets</c> is false, and this option is true, the data will be exported vertically (in the same columns) instead of horizontally.</param>
        public static void ShowImportAsciiDialogAndOptions(this DataTable dataTable, bool toMultipleWorksheets, bool vertically)
        {
            var options = new Altaxo.Gui.OpenFileOptions();

            options.AddFilter("*.csv;*.dat;*.txt", "Text files (*.csv;*.dat;*.txt)");
            options.AddFilter("*.*", "All files (*.*)");
            options.FilterIndex      = 0;
            options.RestoreDirectory = true;
            options.Multiselect      = true;

            if (Current.Gui.ShowOpenFileDialog(options) && options.FileNames.Length > 0)
            {
                var analysisOptions = dataTable.GetPropertyValue(AsciiDocumentAnalysisOptions.PropertyKeyAsciiDocumentAnalysisOptions, null);
                if (!ShowAsciiImportOptionsDialog(options.FileName, analysisOptions, out var importOptions))
                {
                    return;
                }

                if (toMultipleWorksheets)
                {
                    AsciiImporter.ImportFilesIntoSeparateNewTables(Main.ProjectFolder.RootFolder, options.FileNames, true, importOptions);
                }
                else
                {
                    if (vertically)
                    {
                        AsciiImporter.ImportFromMultipleAsciiFilesVertically(dataTable, options.FileNames, true, importOptions);
                    }
                    else
                    {
                        AsciiImporter.ImportFromMultipleAsciiFilesHorizontally(dataTable, options.FileNames, true, importOptions);
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// Asks for a file name of an image file, and imports the image data into a data table.
        /// </summary>
        /// <param name="table">The table to import to.</param>
        public static void ShowImportImageDialog(this DataTable table)
        {
            ColorAmplitudeFunction colorfunc;
            var options = new Altaxo.Gui.OpenFileOptions();

            options.AddFilter("*.bmp;*.jpg;*.png,*.tif", "Image files (*.bmp;*.jpg;*.png,*.tif)");
            options.AddFilter("*.*", "All files (*.*)");
            options.FilterIndex      = 0;
            options.RestoreDirectory = true;

            if (Current.Gui.ShowOpenFileDialog(options))
            {
                using (Stream myStream = new FileStream(options.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    var bmp = new System.Drawing.Bitmap(myStream);

                    int sizex = bmp.Width;
                    int sizey = bmp.Height;
                    //if(Format16bppGrayScale==bmp.PixelFormat)

                    colorfunc = new ColorAmplitudeFunction(ColorToBrightness);
                    // add here other function or the result of a dialog box

                    // now add new columns to the worksheet,
                    // the name of the columns should preferabbly simply
                    // the index in x direction

                    using (var suspendToken = table.SuspendGetToken())
                    {
                        for (int i = 0; i < sizex; i++)
                        {
                            var dblcol = new Altaxo.Data.DoubleColumn();
                            for (int j = sizey - 1; j >= 0; j--)
                            {
                                dblcol[j] = colorfunc(bmp.GetPixel(i, j));
                            }

                            table.DataColumns.Add(dblcol, table.DataColumns.FindUniqueColumnName(i.ToString())); // Spalte hinzufügen
                        } // end for all x coordinaates

                        suspendToken.Dispose();
                    }
                    myStream.Close();
                } // end using myStream
            }
        }
Example #3
0
        /// <summary>
        /// Shows the SPC file import dialog, and imports the files to the table if the user clicked on "OK".
        /// </summary>
        /// <param name="table">The table to import the SPC files to.</param>
        public static void ShowDialog(Altaxo.Data.DataTable table)
        {
            var options = new Altaxo.Gui.OpenFileOptions();

            options.AddFilter("*.dx", "JCamp-DX files (*.dx)");
            options.AddFilter("*.*", "All files (*.*)");
            options.FilterIndex = 0;
            options.Multiselect = true; // allow selecting more than one file

            if (Current.Gui.ShowOpenFileDialog(options))
            {
                // if user has clicked ok, import all selected files into Altaxo
                string[] filenames = options.FileNames;
                Array.Sort(filenames); // Windows seems to store the filenames reverse to the clicking order or in arbitrary order

                string errors = ImportJcampFiles(filenames, table);

                if (errors != null)
                {
                    Current.Gui.ErrorMessageBox(errors, "Some errors occured during import!");
                }
            }
        }
Example #4
0
        /// <summary>
        /// Asks for file name(s) and imports the file(s) into one or multiple worksheets.
        /// </summary>
        /// <param name="dataTable">The data table to import to. Can be null if <paramref name="toMultipleWorksheets"/> is set to <c>true</c>.</param>
        /// <param name="toMultipleWorksheets">If true, multiple files are imported into multiple worksheets. New worksheets were then created automatically.</param>
        /// <param name="vertically">If <c>toMultipleWorksheets</c> is false, and this option is true, the data will be exported vertically (in the same columns) instead of horizontally.</param>
        public static void ShowImportAsciiDialog(this DataTable dataTable, bool toMultipleWorksheets, bool vertically)
        {
            var options = new Altaxo.Gui.OpenFileOptions();

            options.AddFilter("*.csv;*.dat;*.txt", "Text files (*.csv;*.dat;*.txt)");
            options.AddFilter("*.*", "All files (*.*)");
            options.FilterIndex      = 0;
            options.RestoreDirectory = true;
            options.Multiselect      = true;

            if (Current.Gui.ShowOpenFileDialog(options) && options.FileNames.Length > 0)
            {
                if (toMultipleWorksheets)
                {
                    if (options.FileNames.Length == 1 && null != dataTable)
                    {
                        AsciiImporter.ImportFromAsciiFile(dataTable, options.FileName);
                    }
                    else
                    {
                        AsciiImporter.ImportFilesIntoSeparateNewTables(Main.ProjectFolder.RootFolder, options.FileNames, true, false);
                    }
                }
                else
                {
                    if (vertically)
                    {
                        AsciiImporter.ImportFromMultipleAsciiFilesVertically(dataTable, options.FileNames, true, false);
                    }
                    else
                    {
                        AsciiImporter.ImportFromMultipleAsciiFilesHorizontally(dataTable, options.FileNames, true, false);
                    }
                }
            }
        }
Example #5
0
		/// <summary>
		/// Asks for a file name of an image file, and imports the image data into a data table.
		/// </summary>
		/// <param name="table">The table to import to.</param>
		public static void ShowImportImageDialog(this DataTable table)
		{
			ColorAmplitudeFunction colorfunc;
			var options = new Altaxo.Gui.OpenFileOptions();
			options.AddFilter("*.bmp;*.jpg;*.png,*.tif", "Image files (*.bmp;*.jpg;*.png,*.tif)");
			options.AddFilter("*.*", "All files (*.*)");
			options.FilterIndex = 0;
			options.RestoreDirectory = true;

			if (Current.Gui.ShowOpenFileDialog(options))
			{
				using (Stream myStream = new FileStream(options.FileName, FileMode.Open, FileAccess.Read, FileShare.Read))
				{
					System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(myStream);

					int sizex = bmp.Width;
					int sizey = bmp.Height;
					//if(Format16bppGrayScale==bmp.PixelFormat)

					colorfunc = new ColorAmplitudeFunction(ColorToBrightness);
					// add here other function or the result of a dialog box

					// now add new columns to the worksheet,
					// the name of the columns should preferabbly simply
					// the index in x direction

					using (var suspendToken = table.SuspendGetToken())
					{
						for (int i = 0; i < sizex; i++)
						{
							Altaxo.Data.DoubleColumn dblcol = new Altaxo.Data.DoubleColumn();
							for (int j = sizey - 1; j >= 0; j--)
								dblcol[j] = colorfunc(bmp.GetPixel(i, j));

							table.DataColumns.Add(dblcol, table.DataColumns.FindUniqueColumnName(i.ToString())); // Spalte hinzufügen
						} // end for all x coordinaates

						suspendToken.Dispose();
					}
					myStream.Close();
				} // end using myStream
			}
		}
Example #6
0
		/// <summary>
		/// Asks for file name(s) and imports the file(s) into one or multiple worksheets. After the user chooses one or multiple files, one of the chosen files is used for analysis.
		/// The result of the structure analysis of this file is then presented to the user. The user may change some of the options and starts a re-analysis. Finally, the import options
		/// are confirmed by the user and the import process can start.
		/// </summary>
		/// <param name="dataTable">The data table to import to. Can be null if <paramref name="toMultipleWorksheets"/> is set to <c>true</c>.</param>
		/// <param name="toMultipleWorksheets">If true, multiple files are imported into multiple worksheets. New worksheets were then created automatically.</param>
		/// <param name="vertically">If <c>toMultipleWorksheets</c> is false, and this option is true, the data will be exported vertically (in the same columns) instead of horizontally.</param>
		public static void ShowImportAsciiDialogAndOptions(this DataTable dataTable, bool toMultipleWorksheets, bool vertically)
		{
			var options = new Altaxo.Gui.OpenFileOptions();
			options.AddFilter("*.csv;*.dat;*.txt", "Text files (*.csv;*.dat;*.txt)");
			options.AddFilter("*.*", "All files (*.*)");
			options.FilterIndex = 0;
			options.RestoreDirectory = true;
			options.Multiselect = true;

			if (Current.Gui.ShowOpenFileDialog(options) && options.FileNames.Length > 0)
			{
				AsciiImportOptions importOptions;
				var analysisOptions = dataTable.GetPropertyValue(AsciiDocumentAnalysisOptions.PropertyKeyAsciiDocumentAnalysisOptions, null);
				if (!ShowAsciiImportOptionsDialog(options.FileName, analysisOptions, out importOptions))
					return;

				if (toMultipleWorksheets)
				{
					AsciiImporter.ImportFilesIntoSeparateNewTables(Main.ProjectFolder.RootFolder, options.FileNames, true, importOptions);
				}
				else
				{
					if (vertically)
					{
						AsciiImporter.ImportFromMultipleAsciiFilesVertically(dataTable, options.FileNames, true, importOptions);
					}
					else
					{
						AsciiImporter.ImportFromMultipleAsciiFilesHorizontally(dataTable, options.FileNames, true, importOptions);
					}
				}
			}
		}
Example #7
0
		/// <summary>
		/// Asks for file name(s) and imports the file(s) into one or multiple worksheets.
		/// </summary>
		/// <param name="dataTable">The data table to import to. Can be null if <paramref name="toMultipleWorksheets"/> is set to <c>true</c>.</param>
		/// <param name="toMultipleWorksheets">If true, multiple files are imported into multiple worksheets. New worksheets were then created automatically.</param>
		/// <param name="vertically">If <c>toMultipleWorksheets</c> is false, and this option is true, the data will be exported vertically (in the same columns) instead of horizontally.</param>
		public static void ShowImportAsciiDialog(this DataTable dataTable, bool toMultipleWorksheets, bool vertically)
		{
			var options = new Altaxo.Gui.OpenFileOptions();
			options.AddFilter("*.csv;*.dat;*.txt", "Text files (*.csv;*.dat;*.txt)");
			options.AddFilter("*.*", "All files (*.*)");
			options.FilterIndex = 0;
			options.RestoreDirectory = true;
			options.Multiselect = true;

			if (Current.Gui.ShowOpenFileDialog(options) && options.FileNames.Length > 0)
			{
				if (toMultipleWorksheets)
				{
					if (options.FileNames.Length == 1 && null != dataTable)
					{
						AsciiImporter.ImportFromAsciiFile(dataTable, options.FileName);
					}
					else
					{
						AsciiImporter.ImportFilesIntoSeparateNewTables(Main.ProjectFolder.RootFolder, options.FileNames, true, false);
					}
				}
				else
				{
					if (vertically)
					{
						AsciiImporter.ImportFromMultipleAsciiFilesVertically(dataTable, options.FileNames, true, false);
					}
					else
					{
						AsciiImporter.ImportFromMultipleAsciiFilesHorizontally(dataTable, options.FileNames, true, false);
					}
				}
			}
		}
Example #8
0
		public override void Run()
		{
			Altaxo.Scripting.IScriptText script = null; // or load it from somewhere

			if (script == null)
				script = new Altaxo.Scripting.ProgramInstanceScript();
			var options = new Altaxo.Gui.OpenFileOptions();
			options.Title = "Open a script or press Cancel to create a new script";
			options.AddFilter("*.cs", "C# files (*.cs)");
			options.AddFilter("*.*", "All files (*.*)");
			options.FilterIndex = 0;
			if (Current.Gui.ShowOpenFileDialog(options))
			{
				string scripttext;
				string err = OpenScriptText(options.FileName, out scripttext);
				if (null != err)
					Current.Gui.ErrorMessageBox(err);
				else
					script.ScriptText = scripttext;
			}

			object[] args = new object[] { script, new Altaxo.Gui.Scripting.ScriptExecutionHandler(this.EhScriptExecution) };
			if (Current.Gui.ShowDialog(args, "New instance script"))
			{
				string errors = null;
				do
				{
					errors = null;
					// store the script somewhere m_Table.TableScript = (TableScript)args[0];
					var saveOptions = new Altaxo.Gui.SaveFileOptions();
					saveOptions.Title = "Save your script";
					saveOptions.AddFilter("*.cs", "C# files (*.cs)");
					saveOptions.AddFilter("*.*", "All files (*.*)");
					saveOptions.FilterIndex = 0;
					if (Current.Gui.ShowSaveFileDialog(saveOptions))
					{
						errors = SaveScriptText(saveOptions.FileName, script.ScriptText);
						if (null != errors)
							Current.Gui.ErrorMessageBox(errors);
					}
				} while (null != errors);
			}
		}
Example #9
0
		/// <summary>
		/// Shows the SPC file import dialog, and imports the files to the table if the user clicked on "OK".
		/// </summary>
		/// <param name="table">The table to import the SPC files to.</param>
		public static void ShowDialog(Altaxo.Data.DataTable table)
		{
			var options = new Altaxo.Gui.OpenFileOptions();
			options.AddFilter("*.dx", "JCamp-DX files (*.dx)");
			options.AddFilter("*.*", "All files (*.*)");
			options.FilterIndex = 0;
			options.Multiselect = true; // allow selecting more than one file

			if (Current.Gui.ShowOpenFileDialog(options))
			{
				// if user has clicked ok, import all selected files into Altaxo
				string[] filenames = options.FileNames;
				Array.Sort(filenames); // Windows seems to store the filenames reverse to the clicking order or in arbitrary order

				string errors = ImportJcampFiles(filenames, table);

				if (errors != null)
				{
					Current.Gui.ErrorMessageBox(errors, "Some errors occured during import!");
				}
			}
		}