Ejemplo n.º 1
0
        private void SearchThread()
        {
            try
            {
                Lines        = new List <SpectrFunctions.LineInfo>();
                Calibrations = new List <Calibrator>();

                panel1.Enabled  = false;
                btnStop.Enabled = true;

                MethodSimpleElementFormula msef = Method.GetElHeader(Element).Formula[Formula];
                msef.Formula.Founds.Clear();
                msef.Formula.Pairs.Clear();

                Cons = DataExtractor.getData(Method, Element, Formula);
                if (Th != null && Cons != null)
                {
                    Log("Загруженно " + Cons.Count + " прожигов.");
                    int sn_count = Cons[0].DataMinusNull.Length;

                    for (int sn = 0; sn < sn_count && Th != null; sn++)
                    {
                        SpectrFunctions.LineInfo candidat = new SpectrFunctions.LineInfo(sn, Cons);
                        Dispers disp = Cons[0].Disp;
                        int     l    = Cons[0].DataMinusNull[sn].Length;
                        for (int p = 10; p < l - 10 && Th != null; p++)
                        {
                            double ly      = disp.GetLyByLocalPixel(sn, p);
                            bool   found   = false;
                            double real_ly = 0;
                            for (int sp = 0; sp < Cons.Count && Th != null; sp++)
                            {
                                try
                                {
                                    int pixel = (int)Cons[sp].Disp.GetLocalPixelByLy(sn, ly);
                                    candidat.Values[sp] = SpectrFunctions.CheckLine(ref pixel, Cons[sp].DataMinusNull[sn],
                                                                                    (int)numSearchMax.Value, (int)numMaxValue.Value, (int)numMinWidth.Value, (int)numMinValue.Value,
                                                                                    ref candidat.Profile[sp]);
                                    if (candidat.Values[sp] <= 0)
                                    {
                                        found = false;
                                        break;
                                    }
                                    else
                                    {
                                        real_ly += Cons[sp].Disp.GetLyByLocalPixel(sn, pixel);
                                        found    = true;
                                    }
                                    candidat.DLy = Math.Abs(Cons[sp].Disp.GetLyByLocalPixel(sn, pixel + 1) - Cons[sp].Disp.GetLyByLocalPixel(sn, pixel));
                                }
                                catch (Exception ex)
                                {
                                    found = false;
                                }
                            }
                            if (found == true)
                            {
                                candidat.Ly = (float)(real_ly / Cons.Count);
                                Lines.Add(candidat);
                                candidat = new SpectrFunctions.LineInfo(sn, Cons);
                                p       += (int)numSearchMax.Value;
                            }
                        }
                    }
                    Log("Найдено " + Lines.Count + " линий.");

                    int analitic_count = 0;
                    //int element = Method.GetElHeader(Element).Element.Num-1;
                    String element_name = Method.GetElHeader(Element).Element.Name;
                    for (int l = 0; l < Lines.Count; l++)
                    {
                        if (chbAllLinesAnalize.Checked == false)
                        {
                            double ly = Lines[l].Ly;
                            for (int i = 0; i < Common.LDb.Data.Count; i++)
                            {
                                String name = Common.LDb.Data[i].ElementName;
                                if (name.Equals(element_name) && Math.Abs(Common.LDb.Data[i].Ly - ly) < Lines[l].DLy * 3)
                                {
                                    Lines[l].HasLine = true;
                                    analitic_count++;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            Lines[l].HasLine = true;
                        }
                    }
                    Log("Из них " + analitic_count + " могут быть аналитическими.");

                    cboxLyList.Items.Clear();
                    for (int i = 0; i < Lines.Count; i++)
                    {
                        String str = "" + Lines[i].Ly + ":" + Lines[i].Sn;
                        if (Lines[i].HasLine)
                        {
                            str += "   A";
                        }
                        cboxLyList.Items.Add(str);
                    }
                    long out_time = DateTime.Now.Ticks;
                    for (int l1 = 0; l1 < Lines.Count && Th != null; l1++)
                    {
                        if (Lines[l1].HasLine == false)
                        {
                            continue;
                        }
                        for (int l2 = 0; l2 < Lines.Count && Th != null; l2++)
                        {
                            if (l1 == l2 || chbAtTheSameSensor.Checked && Lines[l1].Sn != Lines[l2].Sn)
                            {
                                continue;
                            }

                            Calibrator cal = new Calibrator(Lines[l1], Lines[l2], Cons);
                            cal.ReCalc();
                            for (int i = 0; i < Calibrations.Count; i++)
                            {
                                if (cal.SKO < Calibrations[i].SKO)
                                {
                                    Calibrations.Insert(i, cal);
                                    cal = null;
                                    break;
                                }
                            }

                            if (cal != null)
                            {
                                Calibrations.Add(cal);
                            }

                            while (Calibrations.Count > 1000)
                            {
                                Calibrations.RemoveAt(Calibrations.Count - 1);
                            }

                            if (DateTime.Now.Ticks - out_time > 10000000)
                            {
                                LogTmp("Найлучшее СКО: " + Calibrations[0].SKO + "%.");
                                out_time = DateTime.Now.Ticks;
                            }
                        }
                    }
                    if (Calibrations.Count > 0)
                    {
                        Log("Найлучшее СКО: " + Calibrations[0].SKO + "%.");
                    }
                    else
                    {
                        Log("Не найдено отношений...");
                    }
                }
                else
                {
                    Log("Не найдено данных по прожигам...");
                }
                InitList();
                chbViewFilter.Items.Clear();
                chbViewFilter.Items.Add("");
                for (int i = 0; i < Calibrations.Count; i++)
                {
                    bool   already_in_list = false;
                    String ly = Calibrations[i].Ly1.ToString();
                    for (int j = 0; j < chbViewFilter.Items.Count; j++)
                    {
                        if (chbViewFilter.Items[j].Equals(ly))
                        {
                            already_in_list = true;
                            break;
                        }
                    }
                    if (already_in_list == false)
                    {
                        chbViewFilter.Items.Add(ly);
                    }
                }
            }
            catch (Exception ex)
            {
                Common.Log(ex);
            }
            btnStop.Enabled = false;
            panel1.Enabled  = true;
        }