/// <summary> /// Executes the script. If no instance of the script object exists, a error message will be stored and the return value is false. /// If the script object exists, the data change notifications will be switched of (for all tables). /// Then the Execute function of this script object is called. Afterwards, the data changed notifications are switched on again. /// </summary> /// <param name="myTable">The data table this script is working on.</param> /// <returns>True if executed without exceptions, otherwise false.</returns> /// <remarks>If exceptions were thrown during execution, the exception messages are stored /// inside the column script and can be recalled by the Errors property.</remarks> public bool ExecuteWithSuspendedNotifications(Altaxo.Data.DataTable myTable) { bool bSucceeded = true; Altaxo.Data.DataTableCollection myDataSet = null; // first, test some preconditions if (null == m_ScriptObject) { m_Errors = new string[1] { "Script Object is null" }; return(false); } myDataSet = Altaxo.Data.DataTableCollection.GetParentDataTableCollectionOf(myTable); if (null != myDataSet) { myDataSet.Suspend(); } else if (null != myTable) { myTable.Suspend(); } try { ((Altaxo.Calc.TableScriptExeBase)m_ScriptObject).Execute(myTable); } catch (Exception ex) { bSucceeded = false; m_Errors = new string[1]; m_Errors[0] = ex.ToString(); } finally { if (null != myDataSet) { myDataSet.Resume(); } else if (null != myTable) { myTable.Resume(); } } return(bSucceeded); }
public static string TwoDimCenteredFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg) { int rows = dg.Doc.DataColumns.RowCount; int cols = dg.Doc.DataColumns.ColumnCount; // reserve two arrays (one for real part, which is filled with the table contents) // and the imaginary part - which is left zero here) double[] rePart; double[] imPart; string stringresult = TwoDimFFT(mainDocument, dg, out rePart, out imPart); if (stringresult != null) { return(stringresult); } Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name); // Fill the Table so that the zero frequency point is in the middle // this means for the point order: // for even number of points, i.e. 8 points, the frequencies are -3, -2, -1, 0, 1, 2, 3, 4 (the frequency 4 is the nyquist part) // for odd number of points, i.e. 9 points, the frequencies are -4, -3, -2, -1, 0, 1, 2, 3, 4 (for odd number of points there is no nyquist part) table.Suspend(); int colsNegative = (cols - 1) / 2; // number of negative frequency points int colsPositive = cols - colsNegative; // number of positive (or null) frequency points int rowsNegative = (rows - 1) / 2; int rowsPositive = rows - rowsNegative; for (int i = 0; i < cols; i++) { int sc = i < colsNegative ? i + colsPositive : i - colsNegative;// source column index centered Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < rows; j++) { int sr = j < rowsNegative ? j + rowsPositive : j - rowsNegative; // source row index centered col[j] = rePart[sc * rows + sr]; } table.DataColumns.Add(col); } table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return(null); }
public static void ImportImage(Altaxo.Data.DataTable table) { ColorAmplitudeFunction colorfunc; System.IO.Stream myStream; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = "c:\\"; openFileDialog1.Filter = "Image files (*.bmp;*.jpg;*.png,*.tif)|*.bmp;*.jpg;*.png,*.tif|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 1; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { if ((myStream = openFileDialog1.OpenFile()) != null) { 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 table.Suspend(); 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 table.Resume(); myStream.Close(); myStream = null; } // end if myStream was != null } }
public static string TwoDimFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg) { int rows = dg.Doc.DataColumns.RowCount; int cols = dg.Doc.DataColumns.ColumnCount; // reserve two arrays (one for real part, which is filled with the table contents) // and the imaginary part - which is left zero here) double[] rePart; double[] imPart; string stringresult = TwoDimFFT(mainDocument, dg, out rePart, out imPart); if (stringresult != null) { return(stringresult); } Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name); // Fill the Table table.Suspend(); for (int i = 0; i < cols; i++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for (int j = 0; j < rows; j++) { col[j] = rePart[i * rows + j]; } table.DataColumns.Add(col); } table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return(null); }
/// <summary> /// Shows a dialog to add columns to a table. /// </summary> /// <param name="table">The table where to add the columns.</param> /// <param name="bAddToPropertyColumns">If true, the columns are added to the property columns instead of the data columns collection.</param> public static void ShowAddColumnsDialog(Altaxo.Data.DataTable table, bool bAddToPropertyColumns) { Altaxo.Collections.SelectableListNodeList lbitems = new Altaxo.Collections.SelectableListNodeList(); lbitems.Add(new Altaxo.Collections.SelectableListNode("Numeric", typeof(Altaxo.Data.DoubleColumn), true)); lbitems.Add(new Altaxo.Collections.SelectableListNode("Date/Time", typeof(Altaxo.Data.DateTimeColumn), false)); lbitems.Add(new Altaxo.Collections.SelectableListNode("Text", typeof(Altaxo.Data.TextColumn), false)); IntegerAndComboBoxController ct = new IntegerAndComboBoxController( "Number of colums to add:", 1, int.MaxValue, 1, "Type of columns to add:", lbitems, 0); SpinAndComboBoxControl panel = new SpinAndComboBoxControl(); ct.View = panel; if (true == Current.Gui.ShowDialog(ct, "Add new column(s)", false)) { System.Type columntype = (System.Type)ct.SelectedItem.Item; table.Suspend(); if (bAddToPropertyColumns) { for (int i = 0; i < ct.IntegerValue; i++) { table.PropCols.Add((Altaxo.Data.DataColumn)System.Activator.CreateInstance(columntype)); } } else { for (int i = 0; i < ct.IntegerValue; i++) { table.DataColumns.Add((Altaxo.Data.DataColumn)System.Activator.CreateInstance(columntype)); } } table.Resume(); } }
public static string TwoDimCenteredFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg) { int rows = dg.Doc.DataColumns.RowCount; int cols = dg.Doc.DataColumns.ColumnCount; // reserve two arrays (one for real part, which is filled with the table contents) // and the imaginary part - which is left zero here) double[] rePart; double[] imPart; string stringresult = TwoDimFFT(mainDocument,dg,out rePart, out imPart); if(stringresult!=null) return stringresult; Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name); // Fill the Table so that the zero frequency point is in the middle // this means for the point order: // for even number of points, i.e. 8 points, the frequencies are -3, -2, -1, 0, 1, 2, 3, 4 (the frequency 4 is the nyquist part) // for odd number of points, i.e. 9 points, the frequencies are -4, -3, -2, -1, 0, 1, 2, 3, 4 (for odd number of points there is no nyquist part) table.Suspend(); int colsNegative = (cols-1)/2; // number of negative frequency points int colsPositive = cols - colsNegative; // number of positive (or null) frequency points int rowsNegative= (rows-1)/2; int rowsPositive = rows - rowsNegative; for(int i=0;i<cols;i++) { int sc = i<colsNegative ? i + colsPositive : i - colsNegative; // source column index centered Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for(int j=0;j<rows;j++) { int sr = j<rowsNegative ? j + rowsPositive : j - rowsNegative; // source row index centered col[j] = rePart[sc*rows+sr]; } table.DataColumns.Add(col); } table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return null; }
public static string TwoDimFFT(Altaxo.AltaxoDocument mainDocument, GUI.WorksheetController dg) { int rows = dg.Doc.DataColumns.RowCount; int cols = dg.Doc.DataColumns.ColumnCount; // reserve two arrays (one for real part, which is filled with the table contents) // and the imaginary part - which is left zero here) double[] rePart; double[] imPart; string stringresult = TwoDimFFT(mainDocument,dg,out rePart, out imPart); if(stringresult!=null) return stringresult; Altaxo.Data.DataTable table = new Altaxo.Data.DataTable("Fourieramplitude of " + dg.Doc.Name); // Fill the Table table.Suspend(); for(int i=0;i<cols;i++) { Altaxo.Data.DoubleColumn col = new Altaxo.Data.DoubleColumn(); for(int j=0;j<rows;j++) col[j] = rePart[i*rows+j]; table.DataColumns.Add(col); } table.Resume(); mainDocument.DataTableCollection.Add(table); // create a new worksheet without any columns Current.ProjectService.CreateNewWorksheet(table); return null; }
public void ImportAscii(AsciiImportOptions impopt, Altaxo.Data.DataTable table) { string sLine; stream.Position = 0; // rewind the stream to the beginning System.IO.StreamReader sr = new System.IO.StreamReader(stream, System.Text.Encoding.Default, true); Altaxo.Data.DataColumnCollection newcols = new Altaxo.Data.DataColumnCollection(); Altaxo.Data.DataColumnCollection newpropcols = new Altaxo.Data.DataColumnCollection(); // in case a structure is provided, allocate already the columsn if (null != impopt.recognizedStructure) { for (int i = 0; i < impopt.recognizedStructure.Count; i++) { if (impopt.recognizedStructure[i] == typeof(Double)) { newcols.Add(new Altaxo.Data.DoubleColumn()); } else if (impopt.recognizedStructure[i] == typeof(DateTime)) { newcols.Add(new Altaxo.Data.DateTimeColumn()); } else if (impopt.recognizedStructure[i] == typeof(string)) { newcols.Add(new Altaxo.Data.TextColumn()); } else { newcols.Add(new Altaxo.Data.DBNullColumn()); }; } } // add also additional property columns if not enough there if (impopt.nMainHeaderLines > 1) // if there are more than one header line, allocate also property columns { int toAdd = impopt.nMainHeaderLines - 1; for (int i = 0; i < toAdd; i++) { newpropcols.Add(new Data.TextColumn()); } } // if decimal separator statistics is provided by impopt, create a number format info object System.Globalization.NumberFormatInfo numberFormatInfo = null; if (impopt.m_DecimalSeparatorCommaCount > 0 || impopt.m_DecimalSeparatorDotCount > 0) { numberFormatInfo = (System.Globalization.NumberFormatInfo)System.Globalization.NumberFormatInfo.CurrentInfo.Clone(); // analyse the statistics if (impopt.m_DecimalSeparatorCommaCount > impopt.m_DecimalSeparatorDotCount) // the comma is the decimal separator { numberFormatInfo.NumberDecimalSeparator = ","; if (numberFormatInfo.NumberGroupSeparator == numberFormatInfo.NumberDecimalSeparator) { numberFormatInfo.NumberGroupSeparator = ""; // in case now the group separator is also comma, remove the group separator } } else if (impopt.m_DecimalSeparatorCommaCount < impopt.m_DecimalSeparatorDotCount) // the comma is the decimal separator { numberFormatInfo.NumberDecimalSeparator = "."; if (numberFormatInfo.NumberGroupSeparator == numberFormatInfo.NumberDecimalSeparator) { numberFormatInfo.NumberGroupSeparator = ""; // in case now the group separator is also comma, remove the group separator } } } else // no decimal separator statistics is provided, so retrieve the numberFormatInfo object from the program options or from the current thread { numberFormatInfo = System.Globalization.NumberFormatInfo.CurrentInfo; } char [] splitchar = new char[] { impopt.cDelimiter }; // first of all, read the header if existent for (int i = 0; i < impopt.nMainHeaderLines; i++) { sLine = sr.ReadLine(); if (null == sLine) { break; } string[] substr = sLine.Split(splitchar); int cnt = substr.Length; for (int k = 0; k < cnt; k++) { if (substr[k].Length == 0) { continue; } if (k >= newcols.ColumnCount) { continue; } if (i == 0) // is it the column name line { newcols.SetColumnName(k, substr[k]); } else // this are threated as additional properties { ((Data.DataColumn)newpropcols[i - 1])[k] = substr[k]; // set the properties } } } for (int i = 0; true; i++) { sLine = sr.ReadLine(); if (null == sLine) { break; } string[] substr = sLine.Split(splitchar); int cnt = Math.Min(substr.Length, newcols.ColumnCount); for (int k = 0; k < cnt; k++) { if (substr[k].Length == 0) { continue; } if (newcols[k] is Altaxo.Data.DoubleColumn) { try { ((Altaxo.Data.DoubleColumn)newcols[k])[i] = System.Convert.ToDouble(substr[k], numberFormatInfo); } catch {} } else if (newcols[k] is Altaxo.Data.DateTimeColumn) { try { ((Altaxo.Data.DateTimeColumn)newcols[k])[i] = System.Convert.ToDateTime(substr[k]); } catch {} } else if (newcols[k] is Altaxo.Data.TextColumn) { ((Altaxo.Data.TextColumn)newcols[k])[i] = substr[k]; } else if (null == newcols[k] || newcols[k] is Altaxo.Data.DBNullColumn) { bool bConverted = false; double val = Double.NaN; DateTime valDateTime = DateTime.MinValue; try { val = System.Convert.ToDouble(substr[k]); bConverted = true; } catch { } if (bConverted) { Altaxo.Data.DoubleColumn newc = new Altaxo.Data.DoubleColumn(); newc[i] = val; newcols.Replace(k, newc); } else { try { valDateTime = System.Convert.ToDateTime(substr[k]); bConverted = true; } catch { } if (bConverted) { Altaxo.Data.DateTimeColumn newc = new Altaxo.Data.DateTimeColumn(); newc[i] = valDateTime; newcols.Replace(k, newc); } else { Altaxo.Data.TextColumn newc = new Altaxo.Data.TextColumn(); newc[i] = substr[k]; newcols.Replace(k, newc); } } // end outer if null==newcol } } // end of for all cols } // end of for all lines // insert the new columns or replace the old ones table.Suspend(); bool tableWasEmptyBefore = table.DataColumns.ColumnCount == 0; for (int i = 0; i < newcols.ColumnCount; i++) { if (newcols[i] is Altaxo.Data.DBNullColumn) // if the type is undefined, use a new DoubleColumn { table.DataColumns.CopyOrReplaceOrAdd(i, new Altaxo.Data.DoubleColumn(), newcols.GetColumnName(i)); } else { table.DataColumns.CopyOrReplaceOrAdd(i, newcols[i], newcols.GetColumnName(i)); } // set the first column as x-column if the table was empty before, and there are more than one column if (i == 0 && tableWasEmptyBefore && newcols.ColumnCount > 1) { table.DataColumns.SetColumnKind(0, Altaxo.Data.ColumnKind.X); } } // end for loop // add the property columns for (int i = 0; i < newpropcols.ColumnCount; i++) { table.PropCols.CopyOrReplaceOrAdd(i, newpropcols[i], newpropcols.GetColumnName(i)); } table.Resume(); } // end of function ImportAscii