/// <summary> /// Exports the property columns into Ascii. Each property column is exported into one row (line). /// </summary> /// <param name="strwr">A stream writer to write the ascii data to.</param> /// <param name="columnCollection">The column collection to export.</param> /// <param name="nDataColumns">The number of data columns of the table -> is the number of elements in each property column that must be exported.</param> /// <param name="options">The Ascii export options.</param> protected static void ExportPropertyColumns(StreamWriter strwr, Altaxo.Data.DataColumnCollection columnCollection, int nDataColumns, AsciiExportOptions options) { int nPropColumns = columnCollection.ColumnCount; for (int i = 0; i < nPropColumns; i++) { string columnName = options.ConvertToSaveString(columnCollection.GetColumnName(i)); columnName += "="; bool isTextColumn = columnCollection[i] is Data.TextColumn; for (int j = 0; j < nDataColumns; j++) { if (!columnCollection[i].IsElementEmpty(j)) { string data = options.DataItemToString(columnCollection[i], j); if (options.ExportPropertiesWithName && !isTextColumn && !data.Contains("=")) { strwr.Write(columnName); } strwr.Write(data); } if ((j + 1) < nDataColumns) { strwr.Write(options.SeparatorChar); } else { strwr.WriteLine(); } } } }
public override void Paint(Graphics dc, Rectangle cellRectangle, int nRow, Altaxo.Data.DataColumn data, bool bSelected) { PaintBackground(dc, cellRectangle, bSelected); Altaxo.Data.DataColumnCollection dataColCol = (Altaxo.Data.DataColumnCollection)Main.DocumentPath.GetRootNodeImplementing(data, typeof(Altaxo.Data.DataColumnCollection)); string columnnumber = dataColCol.GetColumnNumber(data).ToString(); string kindandgroup = string.Format("({0}{1})", dataColCol.GetColumnKind(data).ToString(), dataColCol.GetColumnGroup(data)); int fontheight = m_TextFont.Height; Rectangle nameRectangle = cellRectangle; nameRectangle.Height = Math.Max(fontheight, cellRectangle.Height - fontheight); Rectangle numRectangle = cellRectangle; numRectangle.Height = fontheight; numRectangle.Y = Math.Max(cellRectangle.Y + cellRectangle.Height - fontheight, cellRectangle.Y); if (bSelected) { dc.DrawString(columnnumber, m_TextFont, _defaultSelectedTextBrush, numRectangle, m_LeftUpperFormat); dc.DrawString(kindandgroup, m_TextFont, _defaultSelectedTextBrush, numRectangle, m_RightUpperFormat); dc.DrawString(data.Name, m_TextFont, _defaultSelectedTextBrush, nameRectangle, m_TextFormat); } else { dc.DrawString(columnnumber, m_TextFont, m_TextBrush, numRectangle, m_LeftUpperFormat); dc.DrawString(kindandgroup, m_TextFont, m_TextBrush, numRectangle, m_RightUpperFormat); dc.DrawString(data.Name, m_TextFont, m_TextBrush, nameRectangle, m_TextFormat); } }
/// <summary> /// Exports the data columns into Ascii. Each data row is exported into one row (line). /// </summary> /// <param name="strwr">A stream writer to write the ascii data to.</param> /// <param name="columnCollection">The column collection to export.</param> /// <param name="options">The options used for exporting the data.</param> protected static void ExportDataColumns( StreamWriter strwr, Altaxo.Data.DataColumnCollection columnCollection, AsciiExportOptions options ) { int nRows = columnCollection.RowCount; int nColumns = columnCollection.ColumnCount; for (int i = 0; i < nRows; i++) { for (int j = 0; j < nColumns; j++) { strwr.Write(options.DataItemToString(columnCollection[j], i)); if ((j + 1) < nColumns) { strwr.Write(options.SeparatorChar); } else { strwr.WriteLine(); } } } }
/// <summary> /// This function searches for patterns like aaa=bbb in the items of the text column. If it finds such a item, it creates a column named aaa /// and stores the value bbb at the same position in it as in the text column. /// </summary> /// <param name="col">The column where to search for the patterns described above.</param> /// <param name="store">The column collection where to store the newly created columns of properties.</param> public static void ExtractPropertiesFromColumn(Altaxo.Data.DataColumn col, Altaxo.Data.DataColumnCollection store) { for (int nRow = 0; nRow < col.Count; nRow++) { ExtractPropertiesFromString(col[nRow].ToString(), store, nRow); } }
/// <summary> /// Constructor /// </summary> /// <param name="collection">Collection of <see>DataColumns</see>.</param> /// <param name="selectedColumns">Set set of indices into the collection that are part of the matrix.</param> /// <param name="nRows">The number of rows that are part of the matrix. (Starting from index 0).</param> public DataColumnToColumnMatrixWrapper(Altaxo.Data.DataColumnCollection collection, Altaxo.Collections.IAscendingIntegerCollection selectedColumns, int nRows) { _columns = new Altaxo.Data.INumericColumn[selectedColumns.Count]; for (int i = selectedColumns.Count - 1; i >= 0; i--) { _columns[i] = (Altaxo.Data.INumericColumn)collection[selectedColumns[i]]; } _rows = nRows; }
/// <summary> /// This function searches for patterns like aaa=bbb in the provided string. If it finds such a item, it creates a column named aaa /// and stores the value bbb at the same position in it as in the text column. /// </summary> /// <param name="strg">The string where to search for the patterns described above.</param> /// <param name="store">The column collection where to store the newly created columns of properties.</param> /// <param name="index">The index into the column where to store the property value.</param> public static void ExtractPropertiesFromString(string strg, Altaxo.Data.DataColumnCollection store, int index) { string pat; pat = @"(\S+)=(\S+)"; Regex r = new Regex(pat, RegexOptions.Compiled | RegexOptions.IgnoreCase); for (Match m = r.Match(strg); m.Success; m = m.NextMatch()) { string propname = m.Groups[1].ToString(); string propvalue = m.Groups[2].ToString(); // System.Diagnostics.Trace.WriteLine("Found the pair " + propname + " : " + propvalue); if (!store.ContainsColumn(propname)) { Altaxo.Data.DataColumn col; if (Altaxo.Serialization.DateTimeParsing.IsDateTime(propvalue)) { col = new Altaxo.Data.DateTimeColumn(); } else if (Altaxo.Serialization.NumberConversion.IsNumeric(propvalue)) { col = new Altaxo.Data.DoubleColumn(); } else { col = new Altaxo.Data.TextColumn(); } store.Add(col, propname); // add the column to the collection } // now the column is present we can store the value in it. store[propname][index] = new Altaxo.Data.AltaxoVariant(propvalue); } }
/// <summary> /// Exports the property columns into Ascii. Each property column is exported into one row (line). /// </summary> /// <param name="strwr">A stream writer to write the ascii data to.</param> /// <param name="columnCollection">The column collection to export.</param> /// <param name="nDataColumns">The number of data columns of the table -> is the number of elements in each property column that must be exported.</param> /// <param name="separator">The separator char. If the text to export contains the separator char, it is replaced by a space.</param> static protected void ExportPropertyColumns(StreamWriter strwr, Altaxo.Data.DataColumnCollection columnCollection, int nDataColumns, char separator) { int nPropColumns = columnCollection.ColumnCount; for (int i = 0; i < nPropColumns; i++) { for (int j = 0; j < nDataColumns; j++) { if (!columnCollection[i].IsElementEmpty(j)) { strwr.Write(columnCollection[i][j].ToString().Replace(separator, ' ')); } if ((j + 1) < nDataColumns) { strwr.Write(separator); } else { strwr.WriteLine(); } } } }
public ColumnRenameValidator(Altaxo.Data.DataColumn col, Altaxo.Data.DataColumnCollection parent) : base("The column name must not be empty! Please enter a valid name.") { _col = col; _parent = parent; }
/// <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="myColumn">The property column 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.DataColumn myColumn) { 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); } Altaxo.Data.DataColumnCollection myColumnCollection = Altaxo.Data.DataColumnCollection.GetParentDataColumnCollectionOf(myColumn); Altaxo.Data.DataTable myTable = Altaxo.Data.DataTable.GetParentDataTableOf(myColumnCollection); myDataSet = Altaxo.Data.DataTableCollection.GetParentDataTableCollectionOf(myTable); if (null != myDataSet) { myDataSet.Suspend(); } else if (null != myTable) { myTable.Suspend(); } else if (null != myColumnCollection) { myColumnCollection.Suspend(); } else if (null != myColumn) { myColumn.Suspend(); } try { ((Altaxo.Calc.ColScriptExeBase)m_ScriptObject).Execute(myColumn); } 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(); } else if (null != myColumnCollection) { myColumnCollection.Resume(); } else if (null != myColumn) { myColumn.Resume(); } } return(bSucceeded); }
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
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
public ColumnRenameValidator(Altaxo.Data.DataColumn col, Altaxo.Data.DataColumnCollection parent) : base("The column name must not be empty! Please enter a valid name.") { _col = col; _parent = parent; }