예제 #1
0
        //for custom barcodes
        //-------------------------------------------------------------------------
        private void VerifyBarCode(BarCodeItem item)
        {
            if (String.IsNullOrEmpty(item.Value))
            {
                item.Verify = false;
                MouseEnterBarCode(item);
                return;
            }
            int i = 0;
            bool isNumeric = true;
            if (item.TextType == "numbersText")
                isNumeric = utils.IsNumeric(item.Value, out i);
            //else
            //    isNumeric = utils.IsNumeric(item.Value);
            if (item.TextType == "numbersText" && !isNumeric)
            {
                item.Verify = false;
                UpdateUI("Exception", "Invalid value in " + item.Name + "!");
                return;
            }
            else
                item.Verify = true;
            if (errList.Contains("Error in " + item.Name))
            {
                errList.Remove("Error in " + item.Name);
                VerifyErrList();
            }
            if (Status == StatusMessage.Verify || Status == StatusMessage.Delete)
                return;
            item.Value = item.Value.Trim();
            if (item.Name.StartsWith("question_number"))
            {
                string number = item.Name;
                number = number.Remove(0, number.LastIndexOf("_") + 1);
                int index = Convert.ToInt32(number);
                index--;
                rec.questionNumbers[index] = Convert.ToInt32(item.Value);
                //BarCodeListItemControl b = barCodeList.ControlList[index] as BarCodeListItemControl;
                //rec.lineNumbers[index]=
                if (bac != null)
                    bac.indexOfFirstQuestion = 1;
                //BarCodeListItemControl b = barCodeList.ControlList[item.Name] as BarCodeListItemControl;
            }
            switch (item.Name)
            {
                case "district_id":
                    lastDistrictId = item.Value;
                    break;
                case "amout_of_questions":
                    bool largerValue = false;
                    //if (regions == null || rec.maxAmoutOfQuestions == 0)
                    //    regions = rec.regions;
                    if (i > rec.MaxAmoutOfQuestions)
                    {
                        UpdateUI("Exception", "Value is larger than allowed!");//MessageBoxIcon.Error
                        largerValue = true;
                        item.Value = rec.MaxAmoutOfQuestions.ToString();
                        amoutOfQuestions = rec.MaxAmoutOfQuestions.ToString();
                        rec.AmoutOfQuestions = rec.MaxAmoutOfQuestions;
                    }
                    else
                    {
                        rec.AmoutOfQuestions = i;
                        rec.allBarCodeValues[amout_of_questionsIndex] = i.ToString();
                        amoutOfQuestions = i.ToString();
                    }
                    if (linsForm == null)
                        CreateLinsForm();
                    else
                        InitLinsForm(false);
                    if (rec.AmoutOfQuestions <= factLinesPerArea[0])
                    {//пока только для 2 - х полей
                        if (factLinesPerArea.Length > 1)
                            factLinesPerArea[1] = 0;
                    }
                    else if (factLinesPerArea.Length > 1)
                    {
                        factLinesPerArea[1] = rec.AmoutOfQuestions - factLinesPerArea[0];
                    }
                    if (bac.CheckBoxArr.Length == 0)
                    {
                        GetAreasSettings();
                        //if (rec.areas.Length == 0)
                        //{
                        rec.areas = bubblesRegions.areas;
                        //}
                        maxCountRectangles = rec.AddMaxCountRectangles();
                        rec.FillBubbleItems(maxCountRectangles);//
                        if (rec.factRectangle.Length > 0)
                        {
                            rec.FillBubbleItemsRectangle(rec.allContourMultiLine, rec.factRectangle);
                            rec.FindBubble(rec.factRectangle, rec.allContourMultiLine, true);
                        }
                        //rec.BubbleItems = rec.rec.BubbleItems;
                        bac = CreateNewBubblesAreaControl(rec.areas, rec.AmoutOfQuestions);
                        bac.lockReport = true;
                        DrawBubbleItems();
                        bac.lockReport = false;
                        VerifyButton.Enabled = true;
                    }
                    else
                    {
                        if (rec.AmoutOfQuestions.ToString() != item.Value)
                        {
                            GetAreasSettings();
                            InitLinsForm(false);
                        }
                    }
                    if (rec.Status == RecognizeAction.SearchBublesFinished || rec.Status == RecognizeAction.Cancelled)//
                    {
                        if (rec.Status == RecognizeAction.Cancelled && bac == new BubblesAreaControl())
                            bac = CreateNewBubblesAreaControl(rec.areas, rec.AmoutOfQuestions);
                        if (rec.AmoutOfQuestions > i)
                        {
                            if (Status != StatusMessage.Verify && Status != StatusMessage.Delete)
                            {
                                ShowImage(false);
                                rec.AmoutOfQuestions = i;
                                bac.AmoutOfQuestions = i;
                                DrawBubbleItems();
                                pictureBox1.Refresh();
                            }
                        }
                        else
                        {
                            if (rec.AmoutOfQuestions == i || rec.allBarCodeValues[amout_of_questionsIndex] == i.ToString())
                            {
                                if (bac != null && bac != new BubblesAreaControl() && bac.labelArr.Length == i)
                                    return;
                            }
                            rec.AmoutOfQuestions = i;
                            if (linsForm != null)
                                if (linsForm.Visible)
                                    return;
                            rec.Status = RecognizeAction.SearchBubles;
                            RecognizeBubblesButton.Enabled = true;
                            RecognizeBubblesButton.PerformClick();
                        }
                        if (largerValue) return;
                    }
                    else
                    {
                        Status = StatusMessage.ChangeAmoutOfQuestions;
                        return;
                    }
                    break;
                case "question_number_1":
                case "index_of_first_question":
                    rec.IndexOfFirstQuestion = i;
                    bac.indexOfFirstQuestion = i;
                    break;
                //if (rec.Status == RecognizeAction.SearchBublesFinished)
                //{
                //rec.IndexOfFirstQuestion = i;
                //bac.indexOfFirstQuestion = i;
                //}
                //else
                //{
                //    Status = StatusMessage.ChangeIndexOfFirstQuestion;
                //    return;
                //}
                //break;
                default:
                    break;
            }

            rec.SetValueManual(item);   //f.btnExport.Focus();
        }
예제 #2
0
        //-------------------------------------------------------------------------
        private void PrevRecognizeBubbles(bool clear = true)
        {
            ShowImage(false);
            SetCancelSource();

            VerifyButton.Enabled = false;
            //btnGrid.Enabled = true;
            RecognizeAllButton.Enabled = false;
            RecognizeBubblesButton.Enabled = false;
            StopRecognizeButton.Enabled = true;
            if (clear)
            {
                rec.BubbleItems.Clear();
                pnlBubbles.Controls.Clear(); //BubblesAC.Clear();
                bac = new BubblesAreaControl();
                rec.factRectangle = new Rectangle[0];
            }
            animatedTimer.SetActiveValue(null);
            //AnimatedBubbleClear();
            UpdateUI("StatusLabel", "Bubbles recognition, please wait ...");
            Refresh();

            if (!DarknessManualySet.Checked)
            {
                UpdateUI("nudPerCentEmptyBubble", (decimal)rec.DarknessPercent);
                UpdateUI("nudPerCentBestBubble", (decimal)rec.DarknessDifferenceLevel);
            }
            rec.SetDarkness((double)nudPerCentEmptyBubble.Value, (double)nudPerCentBestBubble.Value);
        }
예제 #3
0
        //-------------------------------------------------------------------------
        private void RecognizeAll(bool alignmentOnly)
        {
            if (backgroundWorker.IsBusy)
                return;
            SetCancelSource();
            if (!isRotate && rec.Bitmap.Width > rec.Bitmap.Height)
                rec.Bitmap.RotateFlip(RotateFlipType.Rotate270FlipNone);
            animatedTimer = new AnimatedTimer();
            animatedTimer.Tick += animatedTimer_Tick;
            rec.BubbleItems.Clear();
            BarCodeItems.Clear();
            //BubblesAC.Clear();
            pnlBubbles.Controls.Clear(); //
            bac = new BubblesAreaControl();
            rec.factRectangle = new Rectangle[0];
            VerifyButton.Enabled = false;
            rbtnGrid.Enabled = true;
            RecognizeAllButton.Enabled = false;
            RecognizeBubblesButton.Enabled = false;
            StopRecognizeButton.Enabled = true;

            UpdateUI("StatusLabel", "Search markers, please wait ...");
            ShowImage(false);

            var value = (BoxSheet.SelectedIndex == -1) ? "" : BoxSheet.SelectedItem.ToString();
            var text = (alignmentOnly) ? "RecAllAlignmentOnly" : "RecAll";
            backgroundWorker.RunWorkerAsync(new string[] { text, value });
            if (rec.BarCodesPrompt != "Rotate180")// && rpf != null
                ShowProcessingForm();
            else
                rec.BarCodesPrompt = "";
        }
예제 #4
0
        //все кнопки к первоначальным значениям
        //-------------------------------------------------------------------------
        private void InitButtonsAndControls()
        {
            pictureBox1.Size = new System.Drawing.Size
                (ImagePanel.DisplayRectangle.Width, ImagePanel.DisplayRectangle.Height);
            RotateLeftButton.Enabled = false;
            RotateRightButton.Enabled = false;
            SizeFitButton.Enabled = false;
            SizeFullButton.Enabled = false;
            SizePlusButton.Enabled = false;
            SizeMinusButton.Enabled = false;

            OpenFilesDirButton.Enabled = false;
            button1.Enabled = false;

            RecognizeAllButton.Enabled = false;
            RecognizeBubblesButton.Enabled = false;
            StopRecognizeButton.Enabled = false;

            VerifyButton.Enabled = false;

            // BoxSheet.SelectedIndex = -1;
            if (rec != null)
                rec.BubbleItems.Clear();
            BarCodeItems.Clear();
            pnlBubbles.Controls.Clear();//BubblesAC.Clear();
            bac = new BubblesAreaControl();
            Refresh();
        }
예제 #5
0
        //-------------------------------------------------------------------------
        private void DoWork(object sender, DoWorkEventArgs e)
        {
            if (e.Argument != null)
            {
                var obj = e.Argument as string[];
                if (obj != null)
                {
                    string key = obj.First();
                    string qrCodeText;
                    if (obj.Length == 2)
                        qrCodeText = obj[1];
                    else
                        qrCodeText = "";
                    if (ShetIdManualySet && key == "RecAll")
                    {
                        key = "RecAllAlignmentOnly";
                    }

                    switch (key)
                    {
                        case "new Recognize":
                            Status = StatusMessage.NULL;
                            isInvert = false;
                            isRotate = false;
                            isCut = false;
                            isClear = false;
                            usedPrevTool = false;
                            ShetIdManualySet = false;
                            string fileName = obj.Last();
                            rec = new Recognize(fileName, defaults, cancelSource.Token);
                            rec.BubbleItems = new ObservableCollection<BubbleItem>();
                            errList.Clear();
                            if (rec != null && rec.Audit != null && !string.IsNullOrEmpty(rec.Audit.error))
                            {
                                Invoke(new MethodInvoker(delegate
                                {
                                    lblErr.Text = rec.Audit.error;
                                    errList.Add(rec.Audit.error);
                                    lblErr.Visible = true;
                                }));
                            }
                            recBitmap = (Bitmap)rec.Bitmap.Clone();
                            Invoke(new MethodInvoker(delegate
                                {
                                    BoxSheet.SelectedIndex = -1;
                                }));
                            break;

                        case "RecAll":
                            //Invoke(new MethodInvoker(delegate
                            //    {
                            //        BoxSheet.SelectedIndex = -1;
                            //    }));

                            if (string.IsNullOrEmpty(obj.Last()) && !string.IsNullOrEmpty(lastSheetId))
                            {
                                rec.RecAll(lastSheetId, false, ref qrCodeText, isRotate, isCut, ShetIdManualySet);
                            }
                            else
                            {
                                rec.RecAll(obj.Last(), false, ref qrCodeText, isRotate);
                            }
                            if (rec.cancellationToken.IsCancellationRequested)
                                Invoke(new MethodInvoker(delegate
                                    {
                                        if (!isRotate)
                                            btnRestore_Click(null, null);
                                    }));
                            break;
                        case "RecAllAlignmentOnly":
                            rec.RecAll(obj.Last(), true, ref qrCodeText, isRotate, isCut, ShetIdManualySet);
                            break;
                        case "SelectedSheetIdentifier":
                            rec.SelectedSheetIdentifier(obj.Last(), ref qrCodeText, isRotate, isCut, ShetIdManualySet);
                            break;
                        case "BarcodesRecognition":
                            rec.BarcodesRecognition(qrCodeText);
                            break;
                        case "BubblesRecognition":
                            CreateEtalonAreas();
                            GetAreasSettings();
                            if (!string.IsNullOrEmpty(rec.Audit.error) && rec.Audit.error.StartsWith("Calibration"))
                            {
                                //if (rpf != null && rpf.Disposing)
                                //CloseProcessingForm();
                                rec.Audit.error = "";
                                Invoke(new MethodInvoker(delegate
                                {
                                    rbtnGrid.PerformClick();
                                }));
                                break;
                            }
                            if (rec.bubbles_per_lineErr)
                            {
                                if (rpf != null && rpf.Disposing)
                                    CloseProcessingForm();
                                MessageBox.Show("Please, specify correctly the bubbles per line"
                                , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                                break;
                            }
                            else// (!rec.bubbles_per_lineErr)
                                rec.RecAndFindBubble();
                            break;
                        case "BubblesRecognition2":
                            rec.Exception = null;
                            rec.BarCodesPrompt = "";
                            //rec.Status = RecognizeAction.SearchBublesFinished;
                            //var maxCountRectangles = rec.AddMaxCountRectangles();
                            //rec.BubblesRecognition();
                            int deltaX = 0;
                            //if (rec.bubbles_per_lineFLEX != 5)
                            //{
                            //    deltaX = 0;
                            //}

                            recTools.BubblesRecognize
                            (
                              ref rec.allContourMultiLine
                            , ref rec.factRectangle
                            , rec.Bitmap
                            , ref barCodesPrompt
                            , rec.filterType
                            , rec.defaults.SmartResize
                            , rec.bubblesRegions
                            , rec.bubblesOfRegion
                            , rec.bubblesSubLinesCount
                            , rec.bubblesSubLinesStep
                            , rec.bubblesPerLine
                            , rec.lineHeight
                            , rec.linesPerArea
                            , rec.answersPosition
                            , rec.indexAnswersPosition
                            , rec.totalOutput
                            , rec.bubbleLines
                            , rec.regions
                            , rec.areas
                            , 0, 0, 0, 0//x1, x2, y1, y2
                            , rec.kx, rec.ky
                            , rec.curRect
                            , rec.etRect
                            , 0//deltaY
                            , rec.AmoutOfQuestions
                            , rec.IndexOfFirstQuestion
                            , maxCountRectangles
                            , rec.darknessPercent
                            , rec.darknessDifferenceLevel
                            , rec.lastBannerBottom
                            , deltaX
                            );
                            rec.FillBubbleItems(maxCountRectangles);//
                            rec.FillBubbleItemsRectangle(rec.allContourMultiLine, rec.factRectangle);
                            if (rec.Exception != null)
                            {
                                //MessageBox.Show
                                //            ("Please check that you have the correct number of columns and sub rows"
                                //            , Text, MessageBoxButtons.OK
                                //            , MessageBoxIcon.Exclamation
                                //            );
                                //Invoke(new MethodInvoker(delegate
                                //{
                                //    CloseProcessingForm();
                                //}));
                                return;
                            }
                            rec.FindBubble(rec.factRectangle, rec.allContourMultiLine, true);
                            if (rec.Exception != null)
                                return;
                            if (bac.CheckBoxArr.Length == 0)
                            {
                                //AddBubblesAreaControl(new BubbleEventArgs(false, rec.BubbleItems, rec.areas, rec.AmoutOfQuestions, rec.maxAmoutOfQuestions, rec.IndexOfFirstQuestion, rec.linesPerArea, rec.bubblesPerLine));
                                GetAreasSettings();
                                Invoke(new MethodInvoker(delegate
                                {
                                    bac = CreateNewBubblesAreaControl(rec.areas, rec.AmoutOfQuestions);
                                    bac.lockReport = true;
                                    DrawBubbleItems();
                                    bac.lockReport = false;
                                }));
                            }

                            Invoke(new MethodInvoker(delegate
                                        {
                                            if (!string.IsNullOrEmpty(barCodesPrompt))
                                            {
                                                rec.BarCodesPrompt = barCodesPrompt;
                                                if (!errList.Contains(rec.BarCodesPrompt))
                                                    errList.Add(rec.BarCodesPrompt);
                                                lblErr.Visible = true;
                                            }
                                            pictureBox1.Refresh();
                                            VerifyButton.Enabled = true;
                                            //Status = StatusMessage.NULL;
                                            rec.Status = RecognizeAction.NULL;
                                        }));
                            //rec.UpdateGui();
                            break;
                        case "RemoveNoise":
                            //cancelSource = new System.Threading.CancellationTokenSource();
                            rec.Bitmap = recTools.RemoveNoise(rec.Bitmap);
                            pictureBox1.Image = (Bitmap)rec.Bitmap.Clone();
                            break;
                    }
                    //if (qrCodeText == "")
                    //    e.Result = key;
                    //else
                    e.Result = new string[2] { key, qrCodeText };
                }
            }
        }
예제 #6
0
 //Rectangle barCode= Rectangle.Empty;
 //-------------------------------------------------------------------------
 public BubblesAreaControl CreateNewBubblesAreaControl(RegionsArea[] areas, int amoutOfQuestions)
 {
     //int[] bubblesPerLine,
     maxAmoutOfQuestions = rec.maxAmoutOfQuestions;
     maxCountRectangles = rec.AddMaxCountRectangles();
     if (bubblesPerLine.Length != 0 && areas.Length != bubblesPerLine.Length)
     {
         GetAreasSettings();
         areas = (RegionsArea[])rec.areas.Clone();
     }
     BubblesAreaControl bac = new BubblesAreaControl()
     {
         Name = "bac",
         //Enabled = false,
         Areas = areas,
         bubblesPerLine = areas[0].bubblesPerLine,// bubblesPerLine[0],
         indexOfFirstQuestion = rec.IndexOfFirstQuestion,// IndexOfFirstQuestion,
         AmoutOfQuestions = amoutOfQuestions
     };
     pnlBubbles.Controls.Clear();
     pnlBubbles.Width = bac.Width;
     pnlBubbles.Height = bac.Height;
     pnlBubbles.Controls.Add(bac);
     //bac.Visible = true;
     VerifyButton.Enabled = true;
     return bac;
 }
예제 #7
0
        //-------------------------------------------------------------------------
        private void barCodeList_OkButtonClick(object sender, EventArgs e)
        {
            var obj = sender as BarCodeListItemControl;
            if (obj == null) return;
            VerifyBarCode(obj.Item);
            if (obj.Item.Verify)
                obj.comboBox1.ForeColor = Color.Black;
            if (obj.Item.Name == "amout_of_questions" && utils.IsNumeric(obj.Item.Value))
                SetAmoutOfQuestions(Convert.ToInt32(obj.Item.Value));
            else if (obj.Item.Name == "test_id" && utils.IsNumeric(obj.Item.Value))
                testId = obj.Item.Value;
            else if (obj.Item.Name == "district_id" && utils.IsNumeric(obj.Item.Value))
                districtId = obj.Item.Value;

            else if ((obj.Item.Name == "question_number_1"
                || obj.Item.Name == "index_of_first_question") && utils.IsNumeric(obj.Item.Value))
                indexOfQuestion = obj.Item.Value;
            else if (obj.Item.Name == "bubbles_per_line" && utils.IsNumeric(obj.Item.Value))
            {
                if (Status == StatusMessage.Verify || Status == StatusMessage.Delete)
                    return;
                switch (obj.Item.Value)
                {
                    case "5":
                    case "6":
                        rec.bubbles_per_lineFLEX = Convert.ToInt32(obj.Item.Value);
                        rec.bubbles_per_lineErr = false;
                        switch (rec.bubbles_per_lineFLEX)
                        {
                            case 5:
                            case 6:
                                foreach (var item in rec.regionsListFLEX)
                                {
                                    if (item.regions[item.regions.Length - 1].areas[0].bubblesPerLine == rec.bubbles_per_lineFLEX)
                                    {
                                        rec.regions = item;
                                        break;
                                    }
                                }
                                break;
                                //default:
                                //    bItem.Value = "";
                                //    break;
                        }
                        rec.bubblesPerLine[0] = Convert.ToInt32(obj.Item.Value);
                        rec.areas[0].bubblesPerLine = rec.bubblesPerLine[0];
                        bac = CreateNewBubblesAreaControl(rec.areas, rec.AmoutOfQuestions);
                        break;
                    default:
                        rec.bubbles_per_lineErr = true;
                        obj.comboBox1.ForeColor = Color.Red;
                        MessageBox.Show("Invalid value in " + obj.Item.Name, Text, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        break;
                }
            }
            //if (obj.Item.Name.StartsWith("question_number"))
            //{

            //}
            if (obj.Item.Name == "amout_of_questions"
                || obj.Item.Name == "test_id"
                || obj.Item.Name == "index_of_first_question"
                || obj.Item.Name == "question_number_1")
            {
                SetFactAreasSetting();
            }
        }
예제 #8
0
 //-------------------------------------------------------------------------
 private void AddBubblesAreaControl(BubbleEventArgs e)
 {
     if (Status == StatusMessage.ChangeAmoutOfQuestions)
         return;
     //linesPerArea = new int[rec.areas.Length];
     //bubblesPerLine = new int[rec.areas.Length];
     linesPerArea = new int[rec.linesPerArea.Length];
     bubblesPerLine = new int[rec.linesPerArea.Length];
     for (int j = 0; j < rec.linesPerArea.Length; j++)
     {
         if (j > rec.bubblesPerLine.Length - 1)
             break;
         linesPerArea[j] = rec.linesPerArea[j];
         bubblesPerLine[j] = rec.bubblesPerLine[j];
     }
     rec.areas = (RegionsArea[])e.Areas.Clone();
     bac = CreateNewBubblesAreaControl(rec.areas, rec.AmoutOfQuestions);
     DrawBubbleItems();
     VerifyButton.Enabled = true;
 }