Beispiel #1
0
        private void ChangeMainYAxisButton_Click(object sender, EventArgs e)
        {
            ScaleForm scaleForm;

            if (MainGridView.ColumnCount > 0)
            {
                List <double> existingAxis = new List <double>();
                foreach (DataGridViewRow row in MainGridView.Rows)
                {
                    if (row.HeaderCell != null)
                    {
                        if (row.HeaderCell.Value != null)
                        {
                            if (!String.IsNullOrEmpty(row.HeaderCell.Value.ToString()))
                            {
                                double val;
                                if (Double.TryParse(row.HeaderCell.Value.ToString(), out val))
                                {
                                    existingAxis.Add(val);
                                }
                            }
                        }
                    }
                }
                double[] existingDoubles = existingAxis.ToArray();
                scaleForm = new ScaleForm(UpdateMainYAxisAndRegenerate, existingDoubles);
            }
            else
            {
                scaleForm = new ScaleForm(UpdateMainYAxisAndRegenerate);
            }

            scaleForm.Show();
        }
Beispiel #2
0
        private void SecondaryGridView_RowHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            ScaleForm scaleForm = new ScaleForm(UpdateSecondaryYAxisAndRegenerate);

            scaleForm.Show();
        }
Beispiel #3
0
        private void MainGridView_ColumnHeaderMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            ScaleForm scaleForm = new ScaleForm(UpdateMainYAxisAndRegenerate);

            scaleForm.Show();
        }
Beispiel #4
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);
        }