private void ShowProcessingForm() { if (rpf != null && !rpf.IsDisposed && rpf.Visible && rpf.IsHandleCreated) return; //rpf = null; //Application.DoEvents(); //if (backgroundWorker == null || backgroundWorker.workerThread == null) // return; //if (rpf == null || rpf.IsDisposed) //{ rpf = new RecognizeProcessingForm(); rpf.FormClosing += rpf_FormClosed; rpf.Owner = this; rpf.LabelTextBox.Text = StatusLabel.Text; //} //if (!rpf.IsHandleCreated) //{ rpf.ShowDialog(); //} //} //else //{ // rpf.Visible = true; //} }
//------------------------------------------------------------------------- private void CloseProcessingForm() { if (rpf != null)// && !rpf.IsDisposed { //this.Focus(); rpf.Close(); //SetUsePrevTool(); if (!string.IsNullOrEmpty(rec.BarCodesPrompt) && appSettings.Fields.UsePrevTool) { foreach (var item in editorTools) { if (item.BackColor == Color.Cyan) { toolTip2.ToolTipIcon = ToolTipIcon.Info; toolTip2.IsBalloon = true; toolTip2.SetToolTip(item, "Used this tool"); toolTip2.ToolTipTitle = "Warning"; //toolTip2.Show("Used this tool", item // , new Point (item.Bounds.X,item.Bounds.Y), 2000); toolTip2.Show("Used this tool", item, 2000); if (item.Name == "btnRemoveNoise") continue; //toolTip2.Hide(item); Button b = item as Button; if (b != null) { b.PerformClick(); return; } RadioButton r = item as RadioButton; if (r != null) { r.Checked = true; return; } } } } if (rbtnGrid.Enabled) { if (BoxSheet.SelectedIndex == -1) { rec.SheetIdentifier = ""; } else { if (rec.Status == RecognizeAction.Cancelled || rec.BarCodesPrompt.StartsWith("A") || rec.BarCodesPrompt.StartsWith("M")) { Status = StatusMessage.NULL; etalonAreas = new RegionsArea[0]; rbtnGrid.Checked = true; btnGrid_Click(null, null); } //rpf.Dispose(); //rpf = null; if (animatedTimer != null) animatedTimer.StartAnimation(); comboBoxFocused = false; } } else { if (!ShetIdManualySet && appSettings.Fields.ChbSheetId && lastSheetId != "") { rec.SheetIdentifier = lastSheetId; var selectedItem = MiniatureItems.First(x => x.Name == rec.SheetIdentifier); if (selectedItem != null) { BoxSheet.SelectedItem = selectedItem; miniatureList.SelectedItem = selectedItem; } //regions = recTools.GetRegions(lastSheetId, rec.regionsList); //rec.regions = regions; rbtnGrid.Enabled = true; rbtnGrid.PerformClick(); } } } rpf = null; }
//------------------------------------------------------------------------- private void Recognize_ChangedBarCodesPrompt(object sender, EventArgs e) { Invoke(new MethodInvoker(delegate { if (rec != null && rec.Status == RecognizeAction.WaitingForUserResponse) { if (rec.BarCodesPrompt != "") { UpdateUI("StatusLabel", rec.BarCodesPrompt); lblErr.Text = rec.BarCodesPrompt; if (!errList.Contains(rec.BarCodesPrompt)) errList.Add(rec.BarCodesPrompt); lblErr.Visible = true; } else UpdateUI("StatusLabel", "Sheet identifier not recognized"); if (rec != null && (rec.BarCodesPrompt.StartsWith("S")) && !ShetIdManualySet && appSettings.Fields.ChbSheetId && lastSheetId != "") { rec.SheetIdentifier = lastSheetId; var selectedItem = MiniatureItems.First(x => x.Name == rec.SheetIdentifier); if (selectedItem != null) { BoxSheet.SelectedItem = selectedItem; miniatureList.SelectedItem = selectedItem; rec.SheetIdentifier = selectedItem.ToString(); } //rec.BarCodesPrompt = ""; if (backgroundWorker.IsBusy) { //backgroundWorker.Abort(); CancelBackgroundWorker(); do { Application.DoEvents(); } while (backgroundWorker.IsBusy); System.Threading.Thread.Sleep(500); } //StopRecognizeButton.Enabled = true; CloseProcessingForm(); rpf = null; btnCloseLblErr_Click(null, null); RecognizeAll(true); return; } BoxSheet.SelectedIndex = -1; miniatureList.SelectedItem = null; VerifyButton.Enabled = false; RecognizeAllButton.Enabled = true;//???? RecognizeBubblesButton.Enabled = false; StopRecognizeButton.Enabled = false; //DeleteButton, NextButton или выбирается BoxSheet //должен замигать BoxSheet (обратить на себя внимание) CloseProcessingForm(); } })); }
//------------------------------------------------------------------------- void btnOk_Click(object sender, EventArgs e) { Status = StatusMessage.NULL; try { RecognizeBubblesButton.Enabled = false; for (int i = 0; i < factAreasManualSet.Length; i++) { if (!factAreasManualSet[i]) { int x = (int)Math.Round(factAreas[i].left * Zoom); int y = (int)Math.Round(factAreas[i].top * Zoom); areaNaturalSize = allAreasNaturalSize[i]; pictureBox1_MouseUp(null, new MouseEventArgs(MouseButtons.Left, 0, x, y, 0)); factAreasManualSet[i] = false; } } eDoctrinaOcrEd.TestUids testUid = new TestUids(); string testUidAmoutOfQuestions = "", testUidIndexOfFirstQuestion = ""; for (int i = 0; i < barCodeList.ControlList.Count; i++) { BarCodeListItemControl item = (BarCodeListItemControl)barCodeList.ControlList[i]; //} //foreach (BarCodeListItemControl item in barCodeList.ControlList) //{ RecognizeBubblesButton.Enabled = false; if (item.Name == "amout_of_questions") { amout_of_questionsIndex = i; if (string.IsNullOrEmpty(item.comboBox1.Text) || !utils.IsNumeric(item.comboBox1.Text)) { if (factLinesPerArea[0] == 0) { item.btnCheck.PerformClick(); return; } item.comboBox1.Text = factLinesPerArea.Sum().ToString(); if (errList.Contains("Error in " + item.Name)) { errList.Remove("Error in " + item.Name); VerifyErrList(); } break; } else { testUidAmoutOfQuestions = item.comboBox1.Text; } } else if (item.Name == "index_of_first_question" || item.Name == "question_number_1") { if (string.IsNullOrEmpty(item.comboBox1.Text) || !utils.IsNumeric(item.comboBox1.Text)) { item.comboBox1.Text = "1"; if (errList.Contains("Error in " + item.Name)) { errList.Remove("Error in " + item.Name); VerifyErrList(); } } else { testUidIndexOfFirstQuestion = item.comboBox1.Text; } } else if (item.Name == "test_id") { if (string.IsNullOrEmpty(item.comboBox1.Text) || !utils.IsNumeric(item.comboBox1.Text)) { } else { testId = item.comboBox1.Text; } } else if (item.Name == "district_id") { if (string.IsNullOrEmpty(item.comboBox1.Text) || !utils.IsNumeric(item.comboBox1.Text)) { } else { districtId = item.comboBox1.Text; } } } PrevRecognizeBubbles(); //testUidTestId = testId; //testUidShetId = rec.SheetIdentifier; string key = rec.SheetIdentifier + "_" + testId + "_" + amoutOfQuestions + "_" + indexOfQuestion; //int index=testUids. eDoctrinaOcrEd.TestUids.AreaSettings[] arrs = new TestUids.AreaSettings[factAreas.Length]; if (rec.SheetIdentifier == "FLEX") { if (factAreas[0].bubblesPerLine > rec.bubbles_per_lineFLEX) { MessageBox.Show("Invalid value of cols." , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); rbtnGrid.Checked = true; return; } } for (int i = 0; i < factAreas.Length; i++) { arrs[i].BubblesPrrLine = factAreas[i].bubblesPerLine; arrs[i].SubLineAmout = factAreas[i].subLinesAmount; //if (rec.areas[i].bubblesPerLine < factAreas[i].bubblesPerLine) //{ //} } if (testUids.Test.ContainsKey(key)) { testUids.Test[key] = arrs;//factAreas; } else { testUids.Test.Add(key, arrs); } areaNaturalSize = Rectangle.Empty; for (int i = 0; i < factAreas.Length; i++) { if (factAreas[i].width == 0 && allAreasNaturalSize[i].Width != 0) { factAreas[i].left = allAreasNaturalSize[i].X; factAreas[i].top = allAreasNaturalSize[i].Y; factAreas[i].width = allAreasNaturalSize[i].Width; factAreas[i].height = allAreasNaturalSize[i].Height; } } double heightEt; double kx, ky; //rec.Status = RecognizeAction.SearchBublesFinished; rec.allContourMultiLine = new Dictionary<Bubble, Point[]>(); rec.factRectangle = new Rectangle[0]; Rectangle bubble = Rectangle.Empty; double factStepX, factStepY; int amout_of_questions = 0; Bubble bubble1 = new Bubble(); //bubble1.point = new Point(rec.indexOfFirstBubble, rec.IndexOfFirstQuestion - 1); bubble1.point = new Point(0, rec.IndexOfFirstQuestion - 1); for (int i = 0; i < factAreas.Length; i++) {//Areas++ if (factAreas[i].left < 0 || factAreas[i].left > pictureBox1.Image.Width || factAreas[i].width <= 0 || factAreas[i].width > pictureBox1.Image.Width || factAreas[i].top < 0 || factAreas[i].top > pictureBox1.Image.Height || factAreas[i].height <= 0 || factAreas[i].height > pictureBox1.Image.Height || factAreas[i].lineHeight < 0) { factAreas[i] = new RegionsArea(); } if (factAreas.Length > 1 && factAreas[0].height == 0 || (i > 0 && factAreas[i - 1].height == 0)) { MessageBox.Show("You must specify all areas of bubbles." , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); rbtnGrid.Checked = true; return; } if (factAreas[i].height == 0) continue; amout_of_questions += factLinesPerArea[i]; if (rec.kx == 0) rec.kx = 1; if (rec.ky == 0) rec.ky = 1; if (rec.kx != 1 || rec.ky != 1) {//EditorForm.cs:строка 3737 rec.bubblesOfRegion[i] = new Rectangle((int)Math.Round(rec.bubblesOfRegion[i].X / rec.kx) , (int)Math.Round(rec.bubblesOfRegion[i].Y / rec.ky), rec.bubblesOfRegion[i].Width, rec.bubblesOfRegion[i].Height); rec.bubblesRegions[i].Width = (int)Math.Round(rec.bubblesRegions[i].Width / rec.kx); rec.bubblesRegions[i].Height = (int)Math.Round(rec.bubblesRegions[i].Height / rec.ky); } double EtStepX = (double) (bubblesRegions.areas[i].width - bubblesRegions.areas[i].bubble.Width * bubblesRegions.areas[i].bubblesPerLine) / (bubblesRegions.areas[i].bubblesPerLine - 1); int widthEt = (int)(bubblesRegions.areas[i].bubble.Width * factAreas[i].bubblesPerLine + EtStepX * (factAreas[i].bubblesPerLine - 1));//(int)linsForm.nudCols.Value - 1); kx = (double)factAreas[i].width / widthEt; rec.kx = (decimal)kx; double EtStepY = 0; if (rec.linesPerArea[i] > 1) { EtStepY = (double)(bubblesRegions.areas[i].height - bubblesRegions.areas[i].bubble.Height * rec.linesPerArea[i]) / (rec.linesPerArea[i] - 1); } //double EtStepY = bubblesRegions.areas[i].lineHeight - bubblesRegions.areas[i].bubble.Height; heightEt = bubblesRegions.areas[i].bubble.Height * factLinesPerArea[i] + EtStepY * (factLinesPerArea[i] - 1) + (bubblesRegions.areas[i].subLineHeight * (factAreas[i].subLinesAmount));//bubblesRegions.areas[i].subLinesAmount - ky = (double)factAreas[i].height / heightEt; rec.ky = (decimal)ky; //rec.ProcessingRegions(); bubble.Width = (int)Math.Round(bubblesRegions.areas[i].bubble.Width * kx); bubble.Height = (int)Math.Round(bubblesRegions.areas[i].bubble.Height * ky); factStepX = (double)(factAreas[i].width + EtStepX * kx) / (double)factAreas[i].bubblesPerLine; double distX = (double)factStepX - bubble.Width; //double halfDistX = (double)distX / 2; factAreas[i].lineHeight = (int)Math.Round(bubblesRegions.areas[i].lineHeight * ky); factAreas[i].subLineHeight = (int)Math.Round(bubblesRegions.areas[i].subLineHeight * ky); factAreas[i].bubble = new Rectangle((int)(rec.bubblesOfRegion[i].X * kx) , (int)(rec.bubblesOfRegion[i].Y * ky) , bubble.Width , bubble.Height );//??? rec.bubblesOfRegion[i] = new Rectangle((int)(rec.bubblesOfRegion[i].X * kx) , (int)(rec.bubblesOfRegion[i].Y * ky), bubble.Width, bubble.Height); rec.bubblesRegions[i].Width = (int)Math.Round(rec.bubblesRegions[i].Width * rec.kx); rec.bubblesRegions[i].Height = (int)Math.Round(rec.bubblesRegions[i].Height * rec.ky); factStepY = (double)((factAreas[i].height + EtStepY * ky) - factAreas[i].subLineHeight * factAreas[i].subLinesAmount) / (double)factLinesPerArea[i]; Array.Resize(ref rec.factRectangle, rec.factRectangle.Length + 1); rec.factRectangle[rec.factRectangle.Length - 1] = new Rectangle ( factAreas[i].left , factAreas[i].top , bubble.Width , bubble.Height ); bubble1.areaNumber = i; //bubble1.point = new System.Drawing.Point(rec.indexOfFirstBubble, bubble1.point.Y + 1); bubble1.point = new System.Drawing.Point(0, bubble1.point.Y + 1); bubble1.subLine = 0; rec.allContourMultiLine.Add(bubble1, new System.Drawing.Point[5] { new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Top) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Bottom) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Bottom) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top) }); //Bitmap b2 = (Bitmap)pictureBox1.Image.Clone(); //using (Graphics g = Graphics.FromImage(b2)) //{ for (int j = 0; j < factLinesPerArea[i]; j++)//(int)linsForm.nudRows.Value {//line++ //g.DrawLine // ( // new Pen(Color.Blue) // , factAreas[i].left // , (int)(factAreas[i].top + factStepY * j) // , factAreas[i].left + factAreas[i].width // , (int)(factAreas[i].top + factStepY * j) // ); if (j > 0) { Array.Resize(ref rec.factRectangle, rec.factRectangle.Length + 1); rec.factRectangle[rec.factRectangle.Length - 1] = new Rectangle ( factAreas[i].left , factAreas[i].top + (int)Math.Round((factStepY) * j) , bubble.Width , bubble.Height ); //bubble1.point = new Point(rec.indexOfFirstBubble, bubble1.point.Y + 1); bubble1.point = new Point(0, bubble1.point.Y + 1); bubble1.subLine = 0; rec.allContourMultiLine.Add(bubble1, new System.Drawing.Point[5] { new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Top) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Bottom) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Bottom) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top) }); } for (int k = 0; k <= (int)bubblesRegions.areas[i].subLinesAmount; k++) { if (k > 0) {//subLine++ Array.Resize(ref rec.factRectangle, rec.factRectangle.Length + 1); rec.factRectangle[rec.factRectangle.Length - 1] = new Rectangle ( factAreas[i].left , rec.factRectangle[rec.factRectangle.Length - 2].Y + factAreas[i].subLineHeight , bubble.Width , bubble.Height ); bubble1.subLine = bubble1.subLine + 1; //bubble1.point = new Point(rec.indexOfFirstBubble, bubble1.point.Y); bubble1.point = new Point(0, bubble1.point.Y); rec.allContourMultiLine.Add(bubble1, new System.Drawing.Point[5] { new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Top) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Bottom) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Bottom) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top) }); } for (int l = 1; l < factAreas[i].bubblesPerLine; l++)//(int)linsForm.nudCols.Value {//point.X++ // g.DrawLine //( //new Pen(Color.Blue) //, (int)(factAreas[i].left + factStepX * l) //, factAreas[i].top //, (int)(factAreas[i].left + factStepX * l) //, factAreas[i].top + factAreas[i].height //); Array.Resize(ref rec.factRectangle, rec.factRectangle.Length + 1); rec.factRectangle[rec.factRectangle.Length - 1] = new Rectangle ( factAreas[i].left + (int)Math.Round((factStepX) * l) , rec.factRectangle[rec.factRectangle.Length - 2].Y , bubble.Width , bubble.Height ); bubble1.point = new Point(bubble1.point.X + 1, bubble1.point.Y); rec.allContourMultiLine.Add(bubble1, new System.Drawing.Point[5] { new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Top) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Right, rec.factRectangle[rec.factRectangle.Length - 1].Bottom) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Bottom) ,new Point(rec.factRectangle[rec.factRectangle.Length - 1].Left, rec.factRectangle[rec.factRectangle.Length - 1].Top) }); } } } // g.DrawRectangle(new Pen(Color.Red), area); //} //b2.Save("Rectangles.bmp", ImageFormat.Bmp); //b2.Dispose(); } //rec.BubblesRecognition(); //ShowProcessingForm(); linsForm.btnOk.Enabled = false; rec.AmoutOfQuestions = amout_of_questions; BarCodeItems[amout_of_questionsIndex].Value = amout_of_questions.ToString(); rec.areas = bubblesRegions.areas;// factAreas; //rec.UpdateGui(); barCodesPrompt = ""; maxCountRectangles = rec.AddMaxCountRectangles(); rec.BubblesRecognition(); //rec.BubblesRecognition(false); if (backgroundWorker.IsBusy) { CancelBackgroundWorker(); //do //{ // Application.DoEvents(); //} while (backgroundWorker.IsBusy); //System.Threading.Thread.Sleep(500); } backgroundWorker.RunWorkerAsync(new string[] { "BubblesRecognition2" }); //Focus(); ShowProcessingForm(); //Bitmap b = (Bitmap)pictureBox1.Image.Clone(); //using (Graphics g = Graphics.FromImage(b)) //{ // foreach (Rectangle item in rec.factRectangle) // { // g.DrawRectangle(new Pen(Color.Red), item); // } //} //b.Save("factRectangles.bmp", ImageFormat.Bmp); //b.Dispose(); //area= Rectangle.Empty; linsForm.btnOk.Enabled = true; rpf = null; //Focus(); //linsForm.Close(); } catch (Exception ex) { MessageBox.Show("Send this sheet to developers for fixing problem." , Text, MessageBoxButtons.OK, MessageBoxIcon.Stop); log.LogMessage(ex); string message = "Send log file to developers for fixing problem."; log.LogMessage(message); linsForm.btnOk.Enabled = true; rpf = null; } }