void setAnchorRow(DataGridViewRow row, Template.Anchor a)
        {
            row.Tag = a;
            row.Cells["Id3"].Value             = a.Id;
            row.Cells["Type3"].Value           = a.Type;
            row.Cells["ParentAnchorId3"].Value = a.ParentAnchorId;

            Template.PointF p = a.Position;
            //switch (a.Type)
            //{
            //    case Template.Anchor.Types.PdfText:
            //        {
            //            Template.Anchor.PdfText pt = (Template.Anchor.PdfText)a;
            //        }
            //        break;
            //    case Template.Anchor.Types.OcrText:
            //        {
            //            Template.Anchor.OcrText ot = (Template.Anchor.OcrText)a;
            //        }
            //        break;
            //    case Template.Anchor.Types.ImageData:
            //        {
            //            Template.Anchor.ImageData id = (Template.Anchor.ImageData)a;
            //        }
            //        break;
            //    case Template.Anchor.Types.CvImage:
            //        {
            //            Template.Anchor.CvImage ci = (Template.Anchor.CvImage)a;
            //        }
            //        break;
            //    //case Template.Anchor.Types.Script:
            //    //    {
            //    //        Template.Anchor.Script s = (Template.Anchor.Script)a;
            //    //    }
            //    //    break;
            //    default:
            //        throw new Exception("Unknown option: " + a.Type);
            //}
            if (p != null)
            {
                row.Cells["Position3"].Value = Serialization.Json.Serialize(p);
            }

            if (loadingTemplate)
            {
                return;
            }

            if (currentAnchorControl != null && row == currentAnchorControl.Row)
            {
                setCurrentAnchorRow(a.Id, false);
            }

            setConditionsStatus();
        }
Exemple #2
0
        void setAnchorRow(DataGridViewRow row, Template.Anchor a)
        {
            row.Tag = a;
            row.Cells["Id3"].Value                   = a.Id;
            row.Cells["Type3"].Value                 = a.Type;
            row.Cells["ParentAnchorId3"].Value       = a.ParentAnchorId;
            row.Cells["SearchRectangleMargin"].Value = a.SearchRectangleMargin < 0 ? "-" : a.SearchRectangleMargin.ToString();

            DataGridViewCell patternCell = row.Cells["Pattern"];

            if (patternCell.Value != null && patternCell.Value is IDisposable)
            {
                ((IDisposable)patternCell.Value).Dispose();
            }
            if (a is Template.Anchor.CvImage || a is Template.Anchor.ImageData)
            {
                if (!(patternCell is DataGridViewImageCell))
                {
                    patternCell.Dispose();
                    patternCell = new DataGridViewImageCell {
                        ImageLayout = DataGridViewImageCellLayout.NotSet
                    };
                    row.Cells["Pattern"] = patternCell;
                }
            }
            else
            {
                if (patternCell is DataGridViewImageCell)
                {
                    patternCell.Dispose();
                    patternCell          = new DataGridViewTextBoxCell {
                    };
                    row.Cells["Pattern"] = patternCell;
                }
            }
            row.Cells["Pattern"].ReadOnly = true;
            switch (a.Type)
            {
            case Template.Anchor.Types.PdfText:
                {
                    Template.Anchor.PdfText pt = (Template.Anchor.PdfText)a;
                    if (pt.CharBoxs == null)
                    {
                        patternCell.Value = null;
                        break;
                    }
                    StringBuilder sb = new StringBuilder();
                    foreach (var l in Page.GetLines(pt.CharBoxs.Select(x => new Pdf.CharBox {
                        Char = x.Char, R = x.Rectangle.GetSystemRectangleF()
                    }), new TextAutoInsertSpace {
                        IgnoreSourceSpaces = textAutoInsertSpace_IgnoreSourceSpaces.Checked, Threshold = (float)textAutoInsertSpace_Threshold.Value                                                                                                                                                             /*, Representative*/
                    }, null))
                    {
                        foreach (var cb in l.CharBoxs)
                        {
                            sb.Append(cb.Char);
                        }
                        sb.Append("\r\n");
                    }
                    patternCell.Value = sb.ToString();
                }
                break;

            case Template.Anchor.Types.OcrText:
            {
                Template.Anchor.OcrText ot = (Template.Anchor.OcrText)a;
                if (ot.CharBoxs == null)
                {
                    patternCell.Value = null;
                    break;
                }
                StringBuilder sb = new StringBuilder();
                foreach (var l in Page.GetLines(ot.CharBoxs.Select(x => new Ocr.CharBox {
                        Char = x.Char, R = x.Rectangle.GetSystemRectangleF()
                    }), new TextAutoInsertSpace {
                        IgnoreSourceSpaces = textAutoInsertSpace_IgnoreSourceSpaces.Checked, Threshold = (float)textAutoInsertSpace_Threshold.Value                                                                                                                                                             /*, Representative*/
                    }, null))
                {
                    foreach (var cb in l.CharBoxs)
                    {
                        sb.Append(cb.Char);
                    }
                    sb.Append("\r\n");
                }
                patternCell.Value = sb.ToString();
            }
            break;

            case Template.Anchor.Types.ImageData:
            {
                Template.Anchor.ImageData id = (Template.Anchor.ImageData)a;
                Bitmap b = null;
                if (id.Image != null)
                {
                    b = id.Image.GetBitmap();
                    Size s = patternCell.Size;
                    if (s.Height < b.Height * pictureScale.Value)
                    {
                        s.Width = int.MaxValue;
                        Win.ImageRoutines.Scale(ref b, s);
                    }
                    else if (pictureScale.Value != 1)
                    {
                        Win.ImageRoutines.Scale(ref b, (float)pictureScale.Value);
                    }
                }
                patternCell.Value = b;
            }
            break;

            case Template.Anchor.Types.CvImage:
            {
                Template.Anchor.CvImage ci = (Template.Anchor.CvImage)a;
                Bitmap b = null;
                if (ci.Image != null)
                {
                    b = ci.Image.GetBitmap();
                    Size s = patternCell.Size;
                    if (s.Height < b.Height * pictureScale.Value)
                    {
                        s.Width = int.MaxValue;
                        Win.ImageRoutines.Scale(ref b, s);
                    }
                    else if (pictureScale.Value != 1)
                    {
                        Win.ImageRoutines.Scale(ref b, (float)pictureScale.Value);
                    }
                }
                patternCell.Value = b;
            }
            break;

            default:
                throw new Exception("Unknown option: " + a.Type);
            }

            Template.PointF p = a.Position;
            if (p != null)
            {
                row.Cells["Position3"].Value = Serialization.Json.Serialize(p);
            }

            if (loadingTemplate)
            {
                return;
            }

            if (currentAnchorControl != null && row == currentAnchorControl.Row)
            {
                setCurrentAnchorRow(a.Id, false);
            }

            setConditionsStatus();
        }