示例#1
0
        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);
            }
        }
示例#2
0
 /// <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);
     }
 }
示例#3
0
        public override void Paint(Graphics dc, Rectangle cellRectangle, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            PaintBackground(dc, cellRectangle, bSelected);

            var    dataColCol   = (Altaxo.Data.DataColumnCollection)Main.AbsoluteDocumentPath.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));

            var gdiTextFont = GdiFontManager.ToGdi(_textFont);

            var       fontheight    = gdiTextFont.GetHeight(dc);
            Rectangle nameRectangle = cellRectangle;

            nameRectangle.Height = (int)Math.Max(fontheight, cellRectangle.Height - fontheight);
            Rectangle numRectangle = cellRectangle;

            numRectangle.Height = (int)fontheight;
            numRectangle.Y      = (int)Math.Max(cellRectangle.Y + cellRectangle.Height - fontheight, cellRectangle.Y);

            if (bSelected)
            {
                dc.DrawString(columnnumber, gdiTextFont, _defaultSelectedTextBrush, numRectangle, _leftUpperTextFormat);
                dc.DrawString(kindandgroup, gdiTextFont, _defaultSelectedTextBrush, numRectangle, _rightUpperTextFormat);
                dc.DrawString(data.Name, gdiTextFont, _defaultSelectedTextBrush, nameRectangle, _textFormat);
            }
            else
            {
                dc.DrawString(columnnumber, gdiTextFont, TextBrush, numRectangle, _leftUpperTextFormat);
                dc.DrawString(kindandgroup, gdiTextFont, TextBrush, numRectangle, _rightUpperTextFormat);
                dc.DrawString(data.Name, gdiTextFont, TextBrush, nameRectangle, _textFormat);
            }
        }
示例#4
0
 /// <summary>
 /// Copies data to the data column with the provided index if both columns are of the same type. If they are not of the same type, the column is replaced by the provided column. If the index is beyoind the limit, the provided column is added.
 /// </summary>
 /// <param name="idx">The index of the column where to copy to, or replace.</param>
 /// <param name="datac">The column to copy.</param>
 /// <param name="name">The name of the column in the case the column is added or replaced.</param>
 public virtual void CopyOrReplaceOrAdd(int idx, Altaxo.Data.DataColumn datac, string name)
 {
     Suspend();
     _dataColumns.CopyOrReplaceOrAdd(idx, datac, name); // add the column to the collection
     // no need to insert a property row here (only when inserting)
     Resume();
 }
示例#5
0
        public override void Run(Altaxo.Worksheet.GUI.WorksheetController ctrl)
        {
            Altaxo.Data.DataTable dataTable = ctrl.DataTable;
            if (ctrl.SelectedPropertyColumns.Count == 0)
            {
                return;
            }
            m_Column = dataTable.PropertyColumns[ctrl.SelectedPropertyColumns[0]];

            IScriptText script = (IScriptText)dataTable.PropertyColumns.ColumnScripts[m_Column];

            if (script == null)
            {
                script = new PropertyColumnScript();
            }

            object[] args = new object[] { script, new ScriptExecutionHandler(this.EhScriptExecution) };
            if (Current.Gui.ShowDialog(args, "PropertyColumnScript of " + m_Column.Name))
            {
                if (null != dataTable.PropertyColumns.ColumnScripts[m_Column])
                {
                    dataTable.PropertyColumns.ColumnScripts[m_Column] = (IColumnScriptText)args[0];
                }
                else
                {
                    dataTable.PropertyColumns.ColumnScripts.Add(m_Column, args[0]);
                }
            }

            this.m_Column = null;
        }
示例#6
0
        public override void CopyDataFrom(Altaxo.Data.DataColumn v)
        {
            if (v.GetType() != typeof(Altaxo.Data.TextColumn))
            {
                throw new ArgumentException("Try to copy " + v.GetType() + " to " + this.GetType(), "v"); // throw exception
            }
            Altaxo.Data.TextColumn vd = (Altaxo.Data.TextColumn)v;

            // suggestion, but __not__ implemented:
            // if v is a standalone column, then simply take the dataarray
            // otherwise: copy the data by value
            int oldCount = this.m_Count;

            if (null == vd.m_Array || vd.m_Count == 0)
            {
                m_Array    = null;
                m_Capacity = 0;
                m_Count    = 0;
            }
            else
            {
                m_Array    = (string[])vd.m_Array.Clone();
                m_Capacity = m_Array.Length;
                m_Count    = ((Altaxo.Data.TextColumn)v).m_Count;
            }
            if (oldCount > 0 || m_Count > 0) // message only if really was a change
            {
                NotifyDataChanged(0, oldCount > m_Count? (oldCount):(m_Count), m_Count < oldCount);
            }
        }
示例#7
0
 public override void SetColumnValueAtRow(string s, int nRow, Altaxo.Data.DataColumn data)
 {
     try
     {
         ((Altaxo.Data.TextColumn)data)[nRow] = s;
     }
     catch (Exception) { }
 }
示例#8
0
        /// <summary>
        /// Executes the script in the background with showing the background dialog. 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 ExecuteWithBackgroundDialogAndSuspendNotifications(Altaxo.Data.DataColumn myColumn)
        {
            var reporter = new Altaxo.Main.Services.ExternalDrivenBackgroundMonitor();
            var t        = new System.Threading.Thread(() => ExecuteWithSuspendedNotifications(myColumn, reporter));

            t.Start();
            return(Current.Gui.ShowBackgroundCancelDialog(1000, t, reporter));
        }
示例#9
0
 public override void SetColumnValueAtRow(string s, int nRow, Altaxo.Data.DataColumn data)
 {
     if (!double.TryParse(s, System.Globalization.NumberStyles.Float, Altaxo.Settings.GuiCulture.Instance, out var result))
     {
         result = double.NaN;
     }
     ((Altaxo.Data.DoubleColumn)data)[nRow] = result;
 }
示例#10
0
 /// <summary>
 /// Extracts the property values of the selected property columns.
 /// </summary>
 /// <param name="ctrl">The controller that controls the table.</param>
 public static void ExtractPropertyValues(WorksheetController ctrl)
 {
     for (int i = 0; i < ctrl.SelectedPropertyColumns.Count; i++)
     {
         Altaxo.Data.DataColumn col = ctrl.DataTable.PropCols[ctrl.SelectedPropertyColumns[i]];
         ExtractPropertiesFromColumn(col, ctrl.DataTable.PropCols);
     }
     ctrl.ClearAllSelections();
 }
示例#11
0
        public override void SetColumnValueAtRow(string s, int nRow, Altaxo.Data.DataColumn data)
        {
            if (!DateTime.TryParse(s, Altaxo.Settings.GuiCulture.Instance, System.Globalization.DateTimeStyles.RoundtripKind, out var newval))
            {
                newval = Altaxo.Data.DateTimeColumn.NullValue;
            }

            ((Altaxo.Data.DateTimeColumn)data)[nRow] = newval;
        }
示例#12
0
        /// <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>
        /// <param name="reporter">Progress reporter that can be used by the script to report the progress of its work.</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, IProgressReporter reporter)
        {
            bool bSucceeded = true;

            Altaxo.Data.DataTableCollection myDataSet = null;

            // first, test some preconditions
            if (null == _scriptObject)
            {
                _errors = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, "Script Object is null"));
                return(false);
            }

            var myColumnCollection = Altaxo.Data.DataColumnCollection.GetParentDataColumnCollectionOf(myColumn);

            var myTable = Altaxo.Data.DataTable.GetParentDataTableOf(myColumnCollection);

            myDataSet = Altaxo.Data.DataTableCollection.GetParentDataTableCollectionOf(myTable);

            IDisposable suspendToken = null;

            if (null != myDataSet)
            {
                suspendToken = myDataSet.SuspendGetToken();
            }
            else if (null != myTable)
            {
                suspendToken = myTable.SuspendGetToken();
            }
            else if (null != myColumnCollection)
            {
                suspendToken = myColumnCollection.SuspendGetToken();
            }
            else if (null != myColumn)
            {
                suspendToken = myColumn.SuspendGetToken();
            }

            try
            {
                ((Altaxo.Calc.ColScriptExeBase)_scriptObject).Execute(myColumn, reporter);
            }
            catch (Exception ex)
            {
                bSucceeded = false;
                _errors    = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, ex.ToString()));
            }
            finally
            {
                if (null != suspendToken)
                {
                    suspendToken.Dispose();
                }
            }

            return(bSucceeded);
        }
示例#13
0
        public override void SetColumnValueAtRow(string s, int nRow, Altaxo.Data.DataColumn data)
        {
            double newval;

            try
            {
                newval = s.Length == 0 ? Double.NaN : System.Convert.ToDouble(s);
                ((Altaxo.Data.DoubleColumn)data)[nRow] = newval;
            }
            catch (Exception) {}
        }
示例#14
0
        public override void SetColumnValueAtRow(string s, int nRow, Altaxo.Data.DataColumn data)
        {
            DateTime newval;

            try
            {
                newval = s.Length == 0 ? Altaxo.Data.DateTimeColumn.NullValue : System.Convert.ToDateTime(s);
                ((Altaxo.Data.DateTimeColumn)data)[nRow] = newval;
            }
            catch (Exception) {}
        }
示例#15
0
 public static Altaxo.Data.DoubleColumn Round(double x, Altaxo.Data.DataColumn y)
 {
     if (typeof(Altaxo.Data.DoubleColumn) == y.GetType())
     {
         return(Altaxo.Data.DoubleColumn.Round(x, (Altaxo.Data.DoubleColumn)y));
     }
     else
     {
         throw new ArgumentException("Error: Try to apply Round() to " + x.GetType() + " " + x.ToString() + " and " + y.TypeAndName, "x");
     }
 }
示例#16
0
 public static Altaxo.Data.DoubleColumn Pow(Altaxo.Data.DataColumn x, double y)
 {
     if (typeof(Altaxo.Data.DoubleColumn) == x.GetType())
     {
         return(Altaxo.Data.DoubleColumn.Pow((Altaxo.Data.DoubleColumn)x, y));
     }
     else
     {
         throw new ArgumentException("Error: Try to apply Pow() to " + x.TypeAndName + " and " + y.GetType() + " " + y.ToString(), "x");
     }
 }
示例#17
0
 public static Altaxo.Data.DoubleColumn Atan2(Altaxo.Data.DataColumn y, double x)
 {
     if (typeof(Altaxo.Data.DoubleColumn) == y.GetType())
     {
         return(Altaxo.Data.DoubleColumn.Atan2((Altaxo.Data.DoubleColumn)y, x));
     }
     else
     {
         throw new ArgumentException("Error: Try to apply Atan2() to " + y.TypeAndName + " and " + x.GetType(), "x");
     }
 }
示例#18
0
 public static Altaxo.Data.DoubleColumn Atan2(double y, Altaxo.Data.DataColumn x)
 {
     if (typeof(Altaxo.Data.DoubleColumn) == x.GetType())
     {
         return(Altaxo.Data.DoubleColumn.Atan2(y, (Altaxo.Data.DoubleColumn)x));
     }
     else
     {
         throw new ArgumentException("Error: Try to apply Atan2() to " + y.GetType() + " and " + x.TypeAndName, "x");
     }
 }
示例#19
0
 public static Altaxo.Data.DoubleColumn Min(Altaxo.Data.DataColumn x, Altaxo.Data.DataColumn y)
 {
     if (typeof(Altaxo.Data.DoubleColumn) == x.GetType() && typeof(Altaxo.Data.DoubleColumn) == y.GetType())
     {
         return(Altaxo.Data.DoubleColumn.Min((Altaxo.Data.DoubleColumn)x, (Altaxo.Data.DoubleColumn)y));
     }
     else
     {
         throw new ArgumentException("Error: Try to apply Min() to " + x.TypeAndName + " and " + y.TypeAndName, "x");
     }
 }
示例#20
0
 public static Altaxo.Data.DoubleColumn Tanh(Altaxo.Data.DataColumn x)
 {
     if (typeof(Altaxo.Data.DoubleColumn) == x.GetType())
     {
         return(Altaxo.Data.DoubleColumn.Tanh((Altaxo.Data.DoubleColumn)x));
     }
     else
     {
         throw new ArgumentException("Error: Try to apply Tanh() to " + x.TypeAndName, "x");
     }
 }
示例#21
0
        public override void Paint(Graphics dc, Rectangle cellRectangle, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            PaintBackground(dc, cellRectangle, bSelected);

            if (bSelected)
            {
                dc.DrawString("[" + nRow + "]", GdiFontManager.ToGdi(_textFont), _defaultSelectedTextBrush, cellRectangle, _textFormat);
            }
            else
            {
                dc.DrawString("[" + nRow + "]", GdiFontManager.ToGdi(_textFont), TextBrush, cellRectangle, _textFormat);
            }
        }
示例#22
0
        public override void Paint(Graphics dc, Rectangle cellRectangle, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            PaintBackground(dc, cellRectangle, bSelected);

            string myString = ((Altaxo.Data.DateTimeColumn)data)[nRow].ToString();

            if (bSelected)
            {
                dc.DrawString(myString, m_TextFont, _defaultSelectedTextBrush, cellRectangle, m_TextFormat);
            }
            else
            {
                dc.DrawString(myString, m_TextFont, m_TextBrush, cellRectangle, m_TextFormat);
            }
        }
示例#23
0
        /// <summary>
        /// Compare the values in a double array with values in a double column and see if they match.
        /// </summary>
        /// <param name="values">An array of double values.</param>
        /// <param name="col">A double column to compare with the double array.</param>
        /// <returns>True if the length of the array is equal to the length of the <see cref="Altaxo.Data.DoubleColumn" /> and the values in
        /// both array match to each other, otherwise false.</returns>
        public static bool ValuesMatch(Altaxo.Data.DataColumn values, Altaxo.Data.DataColumn col)
        {
            if (values.Count != col.Count)
            {
                return(false);
            }

            for (int i = 0; i < values.Count; i++)
            {
                if (col[i] != values[i])
                {
                    return(false);
                }
            }

            return(true);
        }
示例#24
0
        /// <summary>
        /// Fits data provided as xcolumn and ycolumn with a polynomial base.
        /// </summary>
        /// <param name="order">The order of the fit (1:linear, 2:quadratic, etc.)</param>
        /// <param name="xcolumn">The column of x-values.</param>
        /// <param name="ycolumn">The column of y-values.</param>
        /// <returns>The fit.</returns>
        public static LinearFitBySvd Fit(int order, Altaxo.Data.DataColumn xcolumn, Altaxo.Data.DataColumn ycolumn)
        {
            if (!(xcolumn is Altaxo.Data.INumericColumn))
            {
                throw new ArgumentException("The x-column must be numeric", "xcolumn");
            }
            if (!(ycolumn is Altaxo.Data.INumericColumn))
            {
                throw new ArgumentException("The y-column must be numeric", "ycolumn");
            }

            int firstIndex = 0;
            int count      = Math.Min(xcolumn.Count, ycolumn.Count);

            double[] xarr = new double[count];
            double[] yarr = new double[count];
            double[] earr = new double[count];

            Altaxo.Data.INumericColumn xcol = (Altaxo.Data.INumericColumn)xcolumn;
            Altaxo.Data.INumericColumn ycol = (Altaxo.Data.INumericColumn)ycolumn;

            int numberOfDataPoints = 0;
            int endIndex           = firstIndex + count;

            for (int i = firstIndex; i < endIndex; i++)
            {
                double x = xcol[i];
                double y = ycol[i];
                if (double.IsNaN(x) || double.IsNaN(y))
                {
                    continue;
                }

                xarr[numberOfDataPoints] = x;
                yarr[numberOfDataPoints] = y;
                earr[numberOfDataPoints] = 1;
                numberOfDataPoints++;
            }

            LinearFitBySvd fit =
                new LinearFitBySvd(
                    xarr, yarr, earr, numberOfDataPoints, order + 1, new FunctionBaseEvaluator(EvaluatePolynomialBase), 1E-5);

            return(fit);
        }
示例#25
0
        /// <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 Execute function of this script object is called.
        /// </summary>
        /// <param name="myColumn">The data table this script is working on.</param>
        /// <param name="reporter">Progress reporter that can be used by the script to report the progress of its work.</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 Execute(Altaxo.Data.DataColumn myColumn, IProgressReporter reporter)
        {
            if (null == _scriptObject)
            {
                _errors = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, "Script Object is null"));
                return(false);
            }

            try
            {
                ((Altaxo.Calc.ColScriptExeBase)_scriptObject).Execute(myColumn, reporter);
            }
            catch (Exception ex)
            {
                _errors = ImmutableArray.Create(new CompilerDiagnostic(null, null, DiagnosticSeverity.Error, ex.ToString()));
                return(false);
            }
            return(true);
        }
        bool IsTransposePossible(int numMovedDataColumns, ref int indexDifferentColumn)
        {
            if (numMovedDataColumns >= _table.DataColumnCount)
            {
                return(true);
            }

            Altaxo.Data.DataColumn masterColumn = _table[numMovedDataColumns];

            for (int i = 0; i < _table.DataColumnCount; i++)
            {
                if (_table[i].GetType() != masterColumn.GetType())
                {
                    indexDifferentColumn = i;
                    return(false);
                }
            }
            return(true);
        }
示例#27
0
        public override void Paint(Graphics dc, Rectangle cellRectangle, int nRow, Altaxo.Data.DataColumn data, bool bSelected)
        {
            PaintBackground(dc, cellRectangle, bSelected);

            DateTime t = ((Altaxo.Data.DateTimeColumn)data)[nRow];

            string myString = (t.Kind == DateTimeKind.Unspecified || t.Kind == DateTimeKind.Local) ?
                              t.ToString("yyyy-MM-dd HH:mm:ss.FFFFFFF") :
                              t.ToString("o");

            if (bSelected)
            {
                dc.DrawString(myString, GdiFontManager.ToGdi(_textFont), _defaultSelectedTextBrush, cellRectangle, _textFormat);
            }
            else
            {
                dc.DrawString(myString, GdiFontManager.ToGdi(_textFont), TextBrush, cellRectangle, _textFormat);
            }
        }
示例#28
0
        /// <summary>
        /// Fits data provided as xcolumn and ycolumn with a polynomial base.
        /// </summary>
        /// <param name="order">The order of the fit (1:linear, 2:quadratic, etc.)</param>
        /// <param name="xcolumn">The column of x-values.</param>
        /// <param name="ycolumn">The column of y-values.</param>
        /// <returns>The fit.</returns>
        public static LinearFitBySvd Fit(int order, Altaxo.Data.DataColumn xcolumn, Altaxo.Data.DataColumn ycolumn)
        {
            if (!(xcolumn is Altaxo.Data.INumericColumn))
            {
                throw new ArgumentException("The x-column must be numeric", "xcolumn");
            }
            if (!(ycolumn is Altaxo.Data.INumericColumn))
            {
                throw new ArgumentException("The y-column must be numeric", "ycolumn");
            }

            int firstIndex = 0;
            int count      = Math.Min(xcolumn.Count, ycolumn.Count);

            double[] xarr = new double[count];
            double[] yarr = new double[count];
            double[] earr = new double[count];

            var xcol = (Altaxo.Data.INumericColumn)xcolumn;
            var ycol = (Altaxo.Data.INumericColumn)ycolumn;

            int numberOfDataPoints = 0;
            int endIndex           = firstIndex + count;

            for (int i = firstIndex; i < endIndex; i++)
            {
                double x = xcol[i];
                double y = ycol[i];
                if (double.IsNaN(x) || double.IsNaN(y))
                {
                    continue;
                }

                xarr[numberOfDataPoints] = x;
                yarr[numberOfDataPoints] = y;
                earr[numberOfDataPoints] = 1;
                numberOfDataPoints++;
            }

            return(LinearFitBySvd.FitPolymomialDestructive(order, xarr, yarr, earr, numberOfDataPoints));
        }
示例#29
0
        /// <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 Execute function of this script object is called.
        /// </summary>
        /// <param name="myColumn">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 Execute(Altaxo.Data.DataColumn myColumn)
        {
            if (null == m_ScriptObject)
            {
                m_Errors = new string[1] {
                    "Script Object is null"
                };
                return(false);
            }

            try
            {
                ((Altaxo.Calc.ColScriptExeBase)m_ScriptObject).Execute(myColumn);
            }
            catch (Exception ex)
            {
                m_Errors    = new string[1];
                m_Errors[0] = ex.ToString();
                return(false);
            }
            return(true);
        }
示例#30
0
 /// <summary>
 /// Renames the selected data column or property column.
 /// </summary>
 /// <param name="ctrl">The worksheet controller for the table.</param>
 public static void RenameSelectedColumn(WorksheetController ctrl)
 {
     if (ctrl.SelectedDataColumns.Count == 1 && ctrl.SelectedPropertyColumns.Count == 0)
     {
         Altaxo.Data.DataColumn   col    = ctrl.Doc.DataColumns[ctrl.SelectedDataColumns[0]];
         TextValueInputController tvctrl = new TextValueInputController(col.Name, "new column name:");
         tvctrl.Validator = new DataColumnRenameValidator(col, ctrl);
         if (Current.Gui.ShowDialog(tvctrl, "Rename column", false))
         {
             ctrl.Doc.DataColumns.SetColumnName(col, tvctrl.InputText);
         }
     }
     if (ctrl.SelectedDataColumns.Count == 0 && ctrl.SelectedPropertyColumns.Count == 1)
     {
         Altaxo.Data.DataColumn   col    = ctrl.Doc.PropCols[ctrl.SelectedPropertyColumns[0]];
         TextValueInputController tvctrl = new TextValueInputController(col.Name, "new property column name:");
         tvctrl.Validator = new PropertyColumnRenameValidator(col, ctrl);
         if (Current.Gui.ShowDialog(tvctrl, "Rename property column", false))
         {
             ctrl.Doc.PropCols.SetColumnName(col, tvctrl.InputText);
         }
     }
 }
    public override void Run(Altaxo.Worksheet.GUI.WorksheetController ctrl)
    {
      Altaxo.Data.DataTable dataTable = ctrl.DataTable;
      if(ctrl.SelectedPropertyColumns.Count==0)
        return;
      m_Column = dataTable.PropertyColumns[ctrl.SelectedPropertyColumns[0]];

      IScriptText script = (IScriptText)dataTable.PropertyColumns.ColumnScripts[m_Column];
      if(script==null)
        script = new PropertyColumnScript();

      object[] args = new object[]{script,new ScriptExecutionHandler(this.EhScriptExecution)};
      if(Current.Gui.ShowDialog(args, "PropertyColumnScript of " + m_Column.Name))
      {
        if(null != dataTable.PropertyColumns.ColumnScripts[m_Column])
          dataTable.PropertyColumns.ColumnScripts[m_Column] = (IColumnScriptText)args[0];
        else
          dataTable.PropertyColumns.ColumnScripts.Add(m_Column, args[0]);
      }

      this.m_Column = null;
    }
示例#32
0
			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>
    /// Moves one or more columns to a new position.
    /// </summary>
    /// <param name="selectedColumns">The indices of the columns to move to the new position.</param>
    /// <param name="newPosition">The new position where the columns are moved to.</param>
    /// <remarks>An exception is thrown if newPosition is negative or higher than possible.</remarks>
    public void ChangeColumnPosition(Altaxo.Collections.IAscendingIntegerCollection selectedColumns, int newPosition)
    {
      int numberSelected = selectedColumns.Count;
      if(numberSelected==0)
        return;

      int oldPosition = selectedColumns[0];
      if(oldPosition==newPosition)
        return;

      // check that the newPosition is ok
      if(newPosition<0)
        throw new ArgumentException("New column position is negative!");
      if(newPosition+numberSelected>ColumnCount)
        throw new ArgumentException(string.Format("New column position too high: ColsToMove({0})+NewPosition({1})>ColumnCount({2})",numberSelected,newPosition,ColumnCount));

      // Allocated tempory storage for the datacolumns
      Altaxo.Data.DataColumn[] columnsMoved = new Altaxo.Data.DataColumn[selectedColumns.Count];
      // fill temporary storage
      for(int i=0;i<selectedColumns.Count;i++)
        columnsMoved[i]=this[selectedColumns[i]];

      int firstAffectedColumn=0;
      int maxAffectedColumn = ColumnCount;
      if(newPosition<oldPosition) // move down to lower indices
      {
        firstAffectedColumn = newPosition;
        maxAffectedColumn  = Math.Max(newPosition+numberSelected,selectedColumns[numberSelected-1]+1);

        for(int i=selectedColumns[numberSelected-1],offset=0;i>=firstAffectedColumn;i--)
        {
          if(numberSelected>offset && i==selectedColumns[numberSelected-1-offset])
            offset++;
          else
            m_ColumnsByNumber[i+offset] = m_ColumnsByNumber[i];

        }
      }
      else // move up to higher
      {
        firstAffectedColumn = selectedColumns[0];
        maxAffectedColumn = newPosition+numberSelected;
        for(int i=selectedColumns[0],offset=0;i<maxAffectedColumn;i++)
        {
          if(offset<numberSelected && i==selectedColumns[offset])
            offset++;
          else
            m_ColumnsByNumber[i-offset] = m_ColumnsByNumber[i];

        }
      }

      // Fill in temporary stored columns on new position
      for(int i=0;i<numberSelected;i++)
        m_ColumnsByNumber[newPosition+i] = columnsMoved[i];
      
      RefreshColumnIndices();
      this.EhChildChanged(null,ChangeEventArgs.CreateColumnMoveArgs(firstAffectedColumn,maxAffectedColumn));
    }
示例#34
0
 public DataColumnRenameValidator(Altaxo.Data.DataColumn col, WorksheetController ctrl)
   : base("The column name must not be empty! Please enter a valid name.")
 {
   m_Col = col;
   m_Ctrl = ctrl;
 }