/// <summary>
 /// Copies the data stored in this object in another object.
 /// </summary>
 /// <remarks>
 /// Anything stored in the other object is overwritten.
 /// </remarks>
 /// <param name="other">The object where to copy this object to.</param>
 internal void CopyTo(PFunction2D other)
 {
     other.SetSizes(this.coordinatesX.Length, this.coordinatesY.Length);
     other.coordinatesX             = (IRightValue[])this.coordinatesX.Clone();
     other.coordinatesY             = (IRightValue[])this.coordinatesY.Clone();
     other.values                   = (IRightValue[, ]) this.values.Clone();
     other.extrapolationType        = this.extrapolationType;
     other.interpolationType        = this.interpolationType;
     other.leastSquaresCoefficients = this.leastSquaresCoefficients;
 }
示例#2
0
 /// <summary>
 /// Copies the data stored in this object in another object.
 /// </summary>
 /// <remarks>
 /// Anything stored in the other object is overwritten.
 /// </remarks>
 /// <param name="other">The object where to copy this object to.</param>
 internal void CopyTo(PFunction2D other)
 {
     other.SetSizes(this.coordinatesX.Length, this.coordinatesY.Length);
     other.coordinatesX = (IRightValue[])this.coordinatesX.Clone();
     other.coordinatesY = (IRightValue[])this.coordinatesY.Clone();
     other.values = (IRightValue[,])this.values.Clone();
     other.extrapolationType = this.extrapolationType;
     other.interpolationType = this.interpolationType;
     other.leastSquaresCoefficients = this.leastSquaresCoefficients;
 }
        /// <summary>
        /// Gets the data from the Data Grid and puts it back in the function.
        /// </summary>
        /// <param name="destination">
        /// The <see cref="PFunction2D"/> object where
        /// the data will be stored if it succeeds validation.
        /// </param>
        /// <returns>True if the operation was successful, False otherwise.</returns>
        private bool DataGridToPointFunctionData(PFunction2D destination)
        {
            PFunction2D tempFunction = new PFunction2D(null);

            // Check if bind was executed. Is it still needed?
            if (m_Project != null)
            {
                m_Project.ResetExpressionParser();
                m_Project.CreateSymbols();

            #if MONO
                // If it's running on Mono the event EditingControlShowing doesn't work, so
                // convert the decimal separators in the data grid before calculating the points.
                if (Engine.RunningOnMono)
                    fairmatDataGridViewPointData.ConvertDecimalSeparators();
            #endif

                DataGridViewRowCollection rows = fairmatDataGridViewPointData.Rows;
                DataGridViewColumnCollection columns = fairmatDataGridViewPointData.Columns;

                // Sets the sizes of the function. Additionally check if the row.Count is zero,
                // in that case it means there are no columns and rows and so must be handled
                // separately
                tempFunction.SetSizes(columns.Count, rows.Count > 0 ? rows.Count - 1 : 0);

                // First load the column headers values
                for (int x = columns.Count - 1; x >= 0; x--)
                {
                    // DataGridView in case the header cell is edited to an empty string replaces
                    // its value with DBNull (non existent value).
                    // So, substitute the cell value explicitly with the empty string.
                    if (columns[x].HeaderCell.Value is DBNull ||
                        columns[x].HeaderCell.Value == null)
                    {
                        columns[x].HeaderCell.Value = string.Empty;
                    }

                    try
                    {
                        tempFunction[x, -1] = RightValue.ConvertFrom(columns[x].HeaderText, true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("The string " + columns[x].HeaderText + " (position " +
                                        (x + 1) + ") is invalid due to: " + e.Message,
                                        DataExchange.ApplicationName);
                        return false;
                    }
                }

                // Then the rows and the cells.
                for (int y = rows.Count - 2; y >= 0; y--)
                {
                    // DataGridView in case the header cell is edited to an empty string replaces
                    // its value with DBNull (non existent value).
                    // So, substitute the cell value explicitly with the empty string.
                    if (rows[y].HeaderCell.Value is DBNull || rows[y].HeaderCell.Value == null)
                    {
                        rows[y].HeaderCell.Value = string.Empty;
                    }

                    try
                    {
                        tempFunction[-1, y] = RightValue.ConvertFrom(rows[y].HeaderCell.Value, true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("The string " + rows[y].HeaderCell.Value + " (position " +
                                        (y + 1) + ") is invalid due to: " + e.Message,
                                        DataExchange.ApplicationName);
                        return false;
                    }

                    for (int x = 0; x < columns.Count; x++)
                    {
                        // DataGridView in case the cell is edited to an empty string replaces
                        // its value with DBNull (non existent value).
                        // So, substitute the cell value explicitly with the empty string.
                        if (rows[y].Cells[x].Value is DBNull)
                        {
                            rows[y].Cells[x].Value = string.Empty;
                        }

                        try
                        {
                            tempFunction[x, y] = RightValue.ConvertFrom(rows[y].Cells[x].Value, true);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("The string " + rows[y].Cells[x].Value +
                                            " is invalid due to: " + e.Message,
                                            DataExchange.ApplicationName);
                            return false;
                        }
                    }
                }
            }

            try
            {
                // Save the information about the interpolation/extrapolation
                tempFunction.Interpolation = this.interpolationExtrapolationControlPF.GetInterpolationType();
                tempFunction.LeastSquaresCoefficients = this.interpolationExtrapolationControlPF.LeastSquareCoefficients;
                tempFunction.Extrapolation = this.interpolationExtrapolationControlPF.GetExtrapolationType();
            }
            catch (Exception e)
            {
                MessageBox.Show("The selected functionality is currently not usable: " + e.Message,
                                DataExchange.ApplicationName);
                return false;
            }

            tempFunction.CopyTo(destination);
            return true;
        }
        /// <summary>
        /// Gets the data from the Data Grid and puts it back in the function.
        /// </summary>
        /// <param name="destination">
        /// The <see cref="PFunction2D"/> object where
        /// the data will be stored if it succeeds validation.
        /// </param>
        /// <returns>True if the operation was successful, False otherwise.</returns>
        private bool DataGridToPointFunctionData(PFunction2D destination)
        {
            PFunction2D tempFunction = new PFunction2D();

            // Check if bind was executed. Is it still needed?
            if (base.m_Project != null)
            {
                base.m_Project.ResetExpressionParser();
                base.m_Project.CreateSymbols();

#if MONO
                // If it's running on Mono the event EditingControlShowing doesn't work, so
                // convert the decimal separators in the data grid before calculating the points.
                if (Engine.RunningOnMono)
                {
                    fairmatDataGridViewPointData.ConvertDecimalSeparators();
                }
#endif

                DataGridViewRowCollection    rows    = fairmatDataGridViewPointData.Rows;
                DataGridViewColumnCollection columns = fairmatDataGridViewPointData.Columns;

                // Sets the sizes of the function. Additionally check if the row.Count is zero,
                // in that case it means there are no columns and rows and so must be handled
                // separately
                tempFunction.SetSizes(columns.Count, rows.Count > 0 ? rows.Count - 1 : 0);

                // First load the column headers values
                for (int x = columns.Count - 1; x >= 0; x--)
                {
                    // DataGridView in case the header cell is edited to an empty string replaces
                    // its value with DBNull (non existent value).
                    // So, substitute the cell value explicitly with the empty string.
                    if (columns[x].HeaderCell.Value is DBNull ||
                        columns[x].HeaderCell.Value == null)
                    {
                        columns[x].HeaderCell.Value = string.Empty;
                    }

                    try
                    {
                        tempFunction[x, -1] = RightValue.ConvertFrom(columns[x].HeaderText, true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("The string " + columns[x].HeaderText + " (column " +
                                        "position " + (x + 1) + ") is invalid due to: " +
                                        e.Message, DataExchange.ApplicationName);
                        return(false);
                    }
                }

                // Then the rows and the cells.
                for (int y = rows.Count - 2; y >= 0; y--)
                {
                    // DataGridView in case the header cell is edited to an empty string replaces
                    // its value with DBNull (non existent value).
                    // So, substitute the cell value explicitly with the empty string.
                    if (rows[y].HeaderCell.Value is DBNull || rows[y].HeaderCell.Value == null)
                    {
                        rows[y].HeaderCell.Value = string.Empty;
                    }

                    try
                    {
                        tempFunction[-1, y] = RightValue.ConvertFrom(rows[y].HeaderCell.Value, true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show("The string " + rows[y].HeaderCell.Value + " (row " +
                                        "position " + (y + 1) + ") is invalid due to: " +
                                        e.Message, DataExchange.ApplicationName);
                        return(false);
                    }

                    for (int x = 0; x < columns.Count; x++)
                    {
                        // DataGridView in case the cell is edited to an empty string replaces
                        // its value with DBNull (non existent value).
                        // So, substitute the cell value explicitly with the empty string.
                        if (rows[y].Cells[x].Value is DBNull)
                        {
                            rows[y].Cells[x].Value = string.Empty;
                        }

                        try
                        {
                            tempFunction[x, y] = RightValue.ConvertFrom(rows[y].Cells[x].Value, true);
                        }
                        catch (Exception e)
                        {
                            MessageBox.Show("The string " + rows[y].Cells[x].Value +
                                            " (position " + (x + 1) + ", " + (y + 1) + ") " +
                                            "is invalid due to: " + e.Message,
                                            DataExchange.ApplicationName);
                            return(false);
                        }
                    }
                }
            }

            try
            {
                // Save the information about the interpolation/extrapolation
                tempFunction.Interpolation            = this.interpolationExtrapolationControlPF.GetInterpolationType();
                tempFunction.LeastSquaresCoefficients = this.interpolationExtrapolationControlPF.LeastSquareCoefficients;
                tempFunction.Extrapolation            = this.interpolationExtrapolationControlPF.GetExtrapolationType();
            }
            catch (Exception e)
            {
                MessageBox.Show("The selected functionality is currently not usable: " + e.Message,
                                DataExchange.ApplicationName);
                return(false);
            }

            tempFunction.CopyTo(destination);
            return(true);
        }