示例#1
0
        public void PopulateMainGridView(string xHeader, string yHeader, string zHeader, string vHeader, bool exactMatch = false)
        {
            SecondaryGridView.Rows.Clear();
            SecondaryGridView.Columns.Clear();
            MainGridView.Rows.Clear();

            if (MainXValuesAreNullOrEmpty())
            {
                UpdateMainXAxis(ScaleForm.GenerateAxis(250.0, 6000.0, 250.0));
            }
            if (MainYValuesAreNullOrEmpty())
            {
                UpdateMainYAxis(ScaleForm.GenerateAxis(-10.0, 45.0, 10.0));
            }

            int i = 0;

            int xIndex          = -1;
            int yIndex          = -1;
            int zIndex          = -1;
            int uIndex          = -1;
            int numberOfHeaders = csvData[0].Length;

            for (i = 0; i < numberOfHeaders; i++)
            {
                if (exactMatch)
                {
                    if (csvHeaders[i].Equals(xHeader))
                    {
                        xIndex = i;
                    }
                    if (csvHeaders[i].Equals(yHeader))
                    {
                        yIndex = i;
                    }
                    if (csvHeaders[i].Equals(zHeader))
                    {
                        zIndex = i;
                    }
                    if (csvHeaders[i].Equals(vHeader))
                    {
                        uIndex = i;
                    }
                }
                else
                {
                    if (csvHeaders[i].Contains(xHeader))
                    {
                        xIndex = i;
                    }
                    if (csvHeaders[i].Contains(yHeader))
                    {
                        yIndex = i;
                    }
                    if (csvHeaders[i].Contains(zHeader))
                    {
                        zIndex = i;
                    }
                    if (csvHeaders[i].Contains(vHeader))
                    {
                        uIndex = i;
                    }
                }
                if (yIndex != -1 && xIndex != -1 && zIndex != -1 && uIndex != -1)
                {
                    break;
                }
            }

            //We couldn't find the indexs
            if (yIndex == -1 || xIndex == -1 || zIndex == -1 || uIndex == -1)
            {
                MessageBox.Show("Error: Couldn't find X/Y/Z index in file", "Error");
                return;
            }

            int height = csvData[0].Length;

            MainGridViewData = new List <double[]> [MainGridViewxValues.Length, MainGridViewyValues.Length];
            for (i = 0; i < MainGridView.Columns.Count; i++)
            {
                for (int j = 0; j < MainGridViewyValues.Length; j++)
                {
                    MainGridViewData[i, j] = new List <double[]>();
                }
            }

            double uMult = 1.0;
            double yMult = 1.0;
            double xMult = 1.0;
            double zMult = 1.0;

            if (!double.TryParse(UAxisMultiplierTextBox.Text, out uMult))
            {
                uMult = 1.0;
            }
            if (!double.TryParse(YAxisMultiplierTextBox.Text, out yMult))
            {
                yMult = 1.0;
            }
            if (!double.TryParse(XAxisMultiplierTextBox.Text, out xMult))
            {
                xMult = 1.0;
            }
            if (!double.TryParse(ZAxisMultiplierTextBox.Text, out zMult))
            {
                zMult = 1.0;
            }

            double[][] csvDataCopy = csvData.Select(a => a.ToArray()).ToArray();

            double xsdignore, ysdignore, zsdignore, usdignore;

            if (sdFiltercheckBox.Checked == true)
            {
                if (double.TryParse(xsd.Text, out xsdignore))
                {
                    RemoveOutliers(ref csvDataCopy, xIndex, xsdignore);
                }
                if (double.TryParse(ysd.Text, out ysdignore))
                {
                    RemoveOutliers(ref csvDataCopy, xIndex, ysdignore);
                }
                if (double.TryParse(zsd.Text, out zsdignore))
                {
                    RemoveOutliers(ref csvDataCopy, zIndex, zsdignore);
                }
                if (double.TryParse(usd.Text, out usdignore))
                {
                    RemoveOutliers(ref csvDataCopy, uIndex, usdignore);
                }
            }

            //Iterate each time sample and add it to the appropriate x,y list
            int    numberOfSamples = csvDataCopy.Length;
            double minZ            = double.MaxValue;
            double range           = 0.0;

            for (i = 0; i < numberOfSamples; i++)
            {
                double x = csvDataCopy[i][xIndex] * xMult;
                double y = csvDataCopy[i][yIndex] * yMult;
                double z = csvDataCopy[i][zIndex] * zMult;
                double u = csvDataCopy[i][uIndex] * uMult;

                //Skip the entry if it is invalid
                if (!HelperMethods.IsValidDouble(x) || !HelperMethods.IsValidDouble(y) || !HelperMethods.IsValidDouble(z))
                {
                    continue;
                }

                int[]    coordinates = GetNearestCoordinate(x, y, MainGridViewxValues, MainGridViewyValues);
                double[] cell        = new double[2];
                cell[0] = z;
                cell[1] = u;
                MainGridViewData[coordinates[0], coordinates[1]].Add(cell);
            }

            //Do not display cells with a count below this level
            double ignoreLowerLimitValue;

            if (!double.TryParse(ignoreLowerLimit.Text, out ignoreLowerLimitValue))
            {
                ignoreLowerLimitValue = Double.MinValue;
            }

            double ignoreUpperLimitValue;

            if (!double.TryParse(ignoreUpperLimit.Text, out ignoreUpperLimitValue))
            {
                ignoreUpperLimitValue = Double.MaxValue;
            }

            double ignoreCellCount;

            if (!double.TryParse(cellCountIgnoreTextBox.Text, out ignoreCellCount))
            {
                ignoreCellCount = 0.0;
            }

            for (i = 0; i < MainGridViewyValues.Length; i++)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.HeaderCell       = new DataGridViewRowHeaderCell();
                row.HeaderCell.Value = MainGridViewyValues[i].ToString();
                for (int j = 0; j < MainGridViewxValues.Length; j++)
                {
                    double[] primaryArray   = new double[MainGridViewData[j, i].Count];
                    double[] secondaryArray = new double[MainGridViewData[j, i].Count];

                    for (int k = 0; k < primaryArray.Length; k++)
                    {
                        primaryArray[k]   = MainGridViewData[j, i][k][0];
                        secondaryArray[k] = MainGridViewData[j, i][k][1];
                    }

                    if (primaryArray.Length < ignoreCellCount)
                    {
                        primaryArray = new double[0];
                    }

                    DataGridViewTuningCell cell = new DataGridViewTuningCell(secondaryArray, primaryArray, range, minZ, MainGridView.currentMode, ignoreLowerLimitValue, ignoreUpperLimitValue);

                    row.Cells.Add(cell);
                }


                MainGridView.Rows.Add(row);
            }
            MainGridView.RowHeadersWidth = 60;

            MainGridView.SetFormat(MainGridView.currentMode, true);
        }
示例#2
0
        public void PopulateFilteredCellGridView(DataGridViewTuningCell data)
        {
            SecondaryGridView.Rows.Clear();
            SecondaryGridView.Columns.Clear();

            List <String> columns       = new List <string>();
            double        val           = data.data.Min();
            double        range         = data.data.Max() - val;
            int           numberOfCells = Math.Min(10, data.data.Length);

            for (int x = 0; x < numberOfCells; x++)
            {
                columns.Add(String.Format("{0:0.00}", val));
                val += range / (double)numberOfCells;
            }
            secondaryXValues = new double[numberOfCells];


            int i = 0;

            SecondaryGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            foreach (string column in columns)
            {
                secondaryXValues[i] = Convert.ToDouble(column);

                DataGridViewTextBoxColumn cell = new DataGridViewTextBoxColumn();
                cell.HeaderText = column;
                cell.Name       = column;
                cell.Width      = 45;
                cell.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                SecondaryGridView.Columns.Add(cell);
                i++;
            }

            double minY = data.secondaryData.Min();

            minY = double.MaxValue;
            for (int index = 0; index < data.secondaryData.Length; index++)
            {
                if (data.secondaryData[index] < minY)
                {
                    minY = data.secondaryData[index];
                }
            }

            double maxY = data.secondaryData.Max();

            double        Range = maxY - minY;
            List <String> rows  = new List <string>();

            val           = minY;
            numberOfCells = Math.Min(10, data.secondaryData.Length);

            List <Double> rowDoubles = new List <Double>();

            for (int y = 0; y < numberOfCells; y++)
            {
                rows.Add(String.Format("{0:0.00}", val));
                rowDoubles.Add(val);
                val += Range / (double)numberOfCells;
            }

            secondaryYValues = new double[rows.Count];
            i = 0;
            foreach (double row in rowDoubles)
            {
                secondaryYValues[i] = row;
                i++;
            }
            SecondaryGridView.RowHeadersWidth = 60;

            SecondaryGridViewData = new int[data.secondaryData.Length, secondaryYValues.Length];
            for (i = 0; i < SecondaryGridView.Columns.Count; i++)
            {
                for (int j = 0; j < secondaryYValues.Length; j++)
                {
                    SecondaryGridViewData[i, j] = 0;
                }
            }

            //Iterate each time sample and add it to the appropriate x,y list
            int min = int.MaxValue;
            int max = int.MinValue;

            for (i = 0; i < data.secondaryData.Length; i++)
            {
                double x = data.data[i];
                double y = data.secondaryData[i];

                int[] coordinates = GetNearestCoordinate(x, y, secondaryXValues, secondaryYValues);

                SecondaryGridViewData[coordinates[0], coordinates[1]]++;
            }

            for (i = 0; i < secondaryXValues.Length; i++)
            {
                for (int j = 0; j < secondaryYValues.Length; j++)
                {
                    if (SecondaryGridViewData[j, i] != 0)
                    {
                        if (SecondaryGridViewData[j, i] < min)
                        {
                            min = SecondaryGridViewData[j, i];
                        }
                        if (SecondaryGridViewData[j, i] > max)
                        {
                            max = SecondaryGridViewData[j, i];
                        }
                    }
                }
            }


            //Create a series of sums per x,y reference
            SecondaryGridView.RowHeadersWidth = 4;
            for (i = 0; i < secondaryYValues.Length; i++)
            {
                DataGridViewRow row = new DataGridViewRow();
                row.HeaderCell       = new DataGridViewRowHeaderCell();
                row.HeaderCell.Value = secondaryYValues[i].ToString();
                int widthTemp = (row.HeaderCell.Value.ToString().Length + 3) * 10;
                if (widthTemp > SecondaryGridView.RowHeadersWidth)
                {
                    SecondaryGridView.RowHeadersWidth = widthTemp;
                }

                for (int j = 0; j < secondaryXValues.Length; j++)
                {
                    DataGridViewTextBoxCell cell = new DataGridViewTextBoxCell();
                    if (SecondaryGridViewData[j, i] != 0)
                    {
                        cell.Value = SecondaryGridViewData[j, i].ToString();
                        double scalar = 360.0 / (max - min);
                        double value  = scalar * (SecondaryGridViewData[j, i] - min);

                        double H = (0.4 * (360.0 - value)) - 10.0;
                        double S = 0.9;
                        double B = 0.92;

                        cell.Style.BackColor = HelperMethods.HSVtoRGB(H, S, B);;
                    }
                    else
                    {
                        cell.Value = "";
                    }



                    row.Cells.Add(cell);
                }
                SecondaryGridView.Rows.Add(row);
            }
        }