private void button1_Click(object sender, EventArgs e)
        {
            GraphProcessing.resetGraph(mainForm);
            mainForm.readingInOneSession   = null;
            mainForm.startBuilding.Enabled = true;
            mainForm.stopBuilding.Enabled  = false;
            List <Form> openForms = new List <Form>();

            foreach (Form f in Application.OpenForms)
            {
                openForms.Add(f);
            }

            foreach (Form f in openForms)
            {
                if (f.Name != mainForm.Name && f.Name != this.Name)
                {
                    f.Close();
                }
            }
            try { mainForm.Port.Close(); }
            catch (Exception ex) { }
            mainForm.showWindow.Enabled = false;
            mainForm.Port         = null;
            mainForm.ReadingInput = null;
        }
Exemple #2
0
        private void planeGraph_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
        {
            double stepX = Math.Log10(Math.Abs(planeGraph.ScrollMaxX - planeGraph.ScrollMinX));
            double stepY = Math.Log10(Math.Abs(planeGraph.ScrollMaxY - planeGraph.ScrollMinY));

            if (e.KeyCode == Keys.Up)
            {
                MinYValue += stepY;
                MaxYValue += stepY;
            }


            if (e.KeyCode == Keys.Down)
            {
                MinYValue -= stepY;
                MaxYValue -= stepY;
            }

            if (e.KeyCode == Keys.Left)
            {
                MinXValue -= stepX;
                MaxXValue -= stepX;
            }

            if (e.KeyCode == Keys.Right)
            {
                MinXValue += stepX;
                MaxXValue += stepX;
            }


            GraphProcessing.UpdateGraph(planeGraph);
        }
Exemple #3
0
 /// <summary>
 /// Loading the main form
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void MainMenu_Load(object sender, EventArgs e)
 {
     GraphProcessing.CreateGraph(planeGraph, GraphName, XAxisData, YAxisData, 100, 100); //Создать график
     string[] test = SerialPort.GetPortNames();                                          // Получить список доступных имен ком-портов
     for (int i = 0; i < test.Length; i++)
     {
         comPortStatusB.Items.Add(test[i]);
     }
     base.Closing += OnClosing;
     FileOperations.GetVariables(this);
 }
Exemple #4
0
        public static void calculateSize(ZedGraphControl ZGCInstance)
        {
            double maxY = double.MinValue;
            double maxX = double.MinValue;

            maxY = ZGCInstance.GraphPane.YAxis.Scale.Max;
            maxX = ZGCInstance.GraphPane.XAxis.Scale.Max;
            ZGCInstance.GraphPane.YAxis.Scale.MinorStep = Math.Abs(maxY / 10);
            ZGCInstance.GraphPane.YAxis.Scale.MajorStep = Math.Abs(maxY / 5);
            ZGCInstance.GraphPane.XAxis.Scale.MinorStep = Math.Abs(maxX / 10);
            ZGCInstance.GraphPane.XAxis.Scale.MajorStep = Math.Abs(maxX / 5);
            GraphProcessing.UpdateGraph(ZGCInstance);
        }
Exemple #5
0
        internal void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            if (curve == null)
            {
                buttons.Add(GraphProcessing.CreateCurve(ref curve, curvesDropDownBtn, planeGraph, "Основной График", Color.Red, 2, SymbolType.Circle, Color.Red));
                ZGCInstance.GraphPane.YAxis.Title.Text = "F, условных единиц";
                ZGCInstance.GraphPane.XAxis.Title.Text = "N, оборотов";
                curve.Tag = 3;
            }
            // Логика за этим? Зачем таймер.
            drawGraphMethod print = new drawGraphMethod(GraphProcessing.AddInRealTime); //Инициализация переменных для ком-порта
            // Show all the incoming data in the port's buffer
            string comPortData = ((SerialPort)sender).ReadExisting().ToString();        //Чтение данных из текущего ком порта.

            comPortData = comPortData.Replace("0\r#0", " ");                            //Удаление символов перехода строки
            comPortData = comPortData.Replace("\t", " ");
            int lengthOfOneReading = Parsing.GetLengthOfOneReading(comPortData);

            counterTimer  = 0;
            saveTimerTick = 0;
            while (lengthOfOneReading > 0 && comPortData.Length > lengthOfOneReading) //Перебираем все пары усилий и поворотов в полученной строке
            {
                if (everySecond == null)
                {
                    СreateTimer();
                }

                atLeastOnePointPassed = true;
                lengthOfOneReading    = Parsing.GetLengthOfOneReading(comPortData);
                string tempStr = comPortData.Substring(0, lengthOfOneReading); //Если в полученной строке несколько показаний, отделяем одно
                comPortData = comPortData.Substring(lengthOfOneReading);       // Вся остальная строка
                TwoCordLinkedList.Node temp = Parsing.ProcessDataMK2(tempStr, coefficient);
                listOfPoints.addLast(temp);
                if (!firstValue && temp != null)
                {
                    xMin = temp.X; firstValue = true;
                }

                if (temp != null) // Отрисовка добавленной в список точки
                {
                    try
                    {
                        planeGraph.Invoke((Action)(() => print(curve, (double)temp.X - xMin, temp.Y)));
                        planeGraph.Invoke((Action)(() => GraphProcessing.UpdateGraph(planeGraph)));
                        planeGraph.Invoke((Action)(() => GraphProcessing.calculateSize(ZGCInstance)));
                    }
                    catch (Exception ex) { }
                }
            }
        }
Exemple #6
0
 private void startBuilding_Click(object sender, EventArgs e)
 {
     if (port == null)
     {
         MessageBox.Show("Порт не открыт");
     }
     if (port != null && !port.IsOpen & readingInput == null)
     {
         try
         {
             if (readingInOneSession == null)
             {
                 readingInOneSession = new List <ExperimentReading>();
             }
             showWindow.Enabled    = true;
             stopBuilding.Enabled  = true;
             startBuilding.Enabled = false;
             readingInput          = new FirstInput(this);
             readingInput.Show();
         }
         catch (Exception ex)
         {
             if (ex is UnauthorizedAccessException || ex is InvalidOperationException)
             {
                 ErrorMessage form = new ErrorMessage("Невозможно открыть порт, так как порт уже открыт!");
                 form.Show();
             }
         }
     }
     else
     {
         if (port != null)
         {
             ErrorMessage form = new ErrorMessage("Невозможно открыть порт, так как порт уже открыт!");
         }
     }
     GraphProcessing.UpdateGraph(planeGraph);
 }
Exemple #7
0
        private bool planeGraph_DoubleClickEvent(ZedGraphControl sender, MouseEventArgs e)
        {
            object nearestObject;
            int    index;

            this.planeGraph.GraphPane.FindNearestObject(new PointF(e.X, e.Y), this.CreateGraphics(), out nearestObject, out index);
            if (nearestObject != null && nearestObject.GetType() == typeof(LineItem))
            {
                LineItem      nearestLineItemObject = (LineItem)nearestObject;
                PointPair     clickedPoint          = nearestLineItemObject.Points[index];
                int           i = 0;
                bool          pointBelongToCurve = false;
                PointPairList temp = (PointPairList)curve.Points;
                if (temp.Contains(clickedPoint))
                {
                    if (selectionCurveBegin == null)
                    {
                        setCurve("Точка 1", ref selectionCurveBegin);
                        selectionCurveBegin.AddPoint(clickedPoint);
                        selectionCurveBegin.Label.IsVisible = false;
                        selectionCurveBegin.Tag             = 0;
                    }
                    else if (selectionCurveEnd == null)
                    {
                        setCurve("Точка 2", ref selectionCurveEnd);
                        selectionCurveEnd.AddPoint(clickedPoint);
                        selectionCurveEnd.Label.IsVisible = false;
                        selectionCurveEnd.Tag             = 0;
                    }
                    else
                    {
                        string curveName = ComputeClosestPoint(clickedPoint.X, clickedPoint.Y);
                        int    pos       = planeGraph.GraphPane.CurveList.IndexOf(curveName);
                        if (pos >= 0)
                        {
                            planeGraph.GraphPane.CurveList.RemoveAt(pos);
                        }
                        LineItem curve = null;
                        setCurve(curveName, ref curve);
                        curve.AddPoint(clickedPoint);
                        curve.Label.IsVisible = false;
                        curve.Tag             = 0;
                        if (curveName == "Точка 1")
                        {
                            selectionCurveBegin = curve;
                        }
                        else if (curveName == "Точка 2")
                        {
                            selectionCurveEnd = curve;
                        }
                    }
                }
                else
                {
                    int posBegin = planeGraph.GraphPane.CurveList.IndexOf("Точка 1");

                    if (posBegin >= 0)
                    {
                        planeGraph.GraphPane.CurveList.RemoveAt(posBegin);
                        selectionCurveBegin = null;
                    }
                    int posEnd = planeGraph.GraphPane.CurveList.IndexOf("Точка 2");
                    if (posEnd >= 0)
                    {
                        planeGraph.GraphPane.CurveList.RemoveAt(posEnd);
                        selectionCurveEnd = null;
                    }
                }
            }
            else
            {
                int posBegin = planeGraph.GraphPane.CurveList.IndexOf("Точка 1");

                if (posBegin >= 0)
                {
                    planeGraph.GraphPane.CurveList.RemoveAt(posBegin);
                    selectionCurveBegin = null;
                }
                int posEnd = planeGraph.GraphPane.CurveList.IndexOf("Точка 2");
                if (posEnd >= 0)
                {
                    planeGraph.GraphPane.CurveList.RemoveAt(posEnd);
                    selectionCurveEnd = null;
                }
            }
            GraphProcessing.UpdateGraph(planeGraph);

            return(false);
        }
Exemple #8
0
        public void DrawLinearPart()
        {
            if (curve != null)
            {
                if (lineCurve != null)
                {
                    planeGraph.GraphPane.CurveList.Remove(lineCurve);
                    curvesDropDownBtn.DropDownItems.Remove(linearPart.button);
                    buttons.Remove(linearPart);
                    linearPart = null;
                    lineCurve  = null;
                }
                linearPart = GraphProcessing.CreateCurve(ref lineCurve, curvesDropDownBtn, planeGraph, "Линейный участок", Color.Blue, 8, SymbolType.Circle, Color.Blue);
                buttons.Add(linearPart);
                lineCurve.Label.IsVisible = false;
                LineItem firstDerivativeCurve = new LineItem("d1");
                firstDerivativeCurve.Tag = 5;
                LineItem firstMovingAverageCurve = new LineItem("mad1");
                firstMovingAverageCurve.Tag = 5;
                processedCurve = new LineItem("movingAverage1");

                processedCurve.Tag  = 5;
                processedCurve2     = new LineItem("movingAverage2");
                processedCurve2.Tag = 5;
                double[] data = GraphProcessing.CurveToArray(curve, false);

                double[] movingAverage1 = GraphProcessing.MovingAverage(data, sensitivy);
                for (int i = 0; i < movingAverage1.Length - 1; i++)
                {
                    processedCurve2.AddPoint(curve.Points[i].X, movingAverage1[i]);
                }
                linearPart.curve.IsVisible = false;
                processedCurve             = processedCurve2.Clone();

                GraphProcessing.DerivativeGraph(curve, ref firstDerivativeCurve);

                GraphProcessing.SecondDerivativeGraph(firstDerivativeCurve, ref secondDerivativeCurve);
                GraphProcessing.DerivativeGraph(processedCurve, ref firstMovingAverageCurve);
                LineItem tempCurve = new LineItem("temp");
                tempCurve.Tag = 5;
                LineItem secondMovingAverageCurve = new LineItem("sMAC");
                secondMovingAverageCurve.Tag = 5;
                GraphProcessing.DerivativeGraph(processedCurve2, ref tempCurve);
                GraphProcessing.DerivativeGraph(tempCurve, ref secondMovingAverageCurve);
                int[] bounds = GraphProcessing.CalculatePointsForLinear(curve, secondMovingAverageCurve, firstMovingAverageCurve);
                for (int i = bounds[0]; i < bounds[1]; i++)
                {
                    lineCurve.AddPoint(curve[i]);
                }

                aproximateLinearCurve = null;
                int begin = (int)bounds[0];
                int end   = (int)bounds[1];
                buttons.Add(GraphProcessing.CreateCurve(ref aproximateLinearCurve, curvesDropDownBtn, planeGraph, "Линейный участок МНК", Color.Green, 2, SymbolType.Circle, Color.Green));
                //(int) curve.Points[begin].X (int) curve.Points[end].X
                // y= y1+(x-x1) (y2 - y1) / (x2-x1) ; y = k*(x-x1) + y1 = kx - (kx1 + y1)
                MyMath.leastSquaresBuild((int)curve.Points[begin].X, (int)curve.Points[end].X, lineCurve, ref aproximateLinearCurve, this);
                aproximateLinearCurve.Tag             = 2;
                form.AproximateLinearCurve            = aproximateLinearCurve;
                aproximateLinearCurve.IsVisible       = false;
                aproximateLinearCurve.Label.IsVisible = false;
                lineCurve.Tag = 5;
                planeGraph.Refresh();
                GraphProcessing.UpdateGraph(planeGraph);
            }
            else
            {
                ErrorMessage form = new ErrorMessage("Нет графика на котором нужно найти линейный участок");
            }



            Task.Delay(1500);
            var customLineForm = new CustomLine(this);

            customLineForm.Show();
            customLineForm.Activate();
            customLineForm.Focus();
            customLineForm.BringToFront();
        }