Beispiel #1
0
        private void 标注ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            annoFileDialog.Title = "载入标注文本文件";
            if (annoFileDialog.ShowDialog() == DialogResult.OK)
            {
                using (AnnoLoaderForm annoLoaderForm = new AnnoLoaderForm(annoFileDialog.FileName))
                {
                    if (annoLoaderForm.ShowDialog() == DialogResult.Yes)
                    {
                        Annotations = annoLoaderForm.Annotations;
                        void ItemAdd(object _sender, AnnoPictureBox _item, EventArgs _e)
                        {
                            string filePath = _item.FilePath;

                            _ = Process.Async.Now(() =>
                            {
                                for (int i = 0; i < Annotations.Length; i++)
                                {
                                    if (AnnoPictureBox.CheckAnnotation(Annotations[i], filePath))
                                    {
                                        _item.Annotations.Add(Annotations[i]);
                                        Annotations[i] = null;
                                    }
                                }
                            }, () => _item.Invalidate());
                        }

                        GlobalMessage.Progress progress = new GlobalMessage.Progress(annoPictureListPanel.Count)
                        {
                            ProgressingFormatString = "正在处理第{1}项,共{2}项",
                            Print = PrintStatus
                        };
                        (annoPictureListPanel as ListPanel <AnnoPictureBox>).ForEachItem((item) =>
                        {
                            ItemAdd(null, item, null);
                            progress.IncReport();
                        });
                        annoPictureListPanel.ItemAdded += ItemAdd;
                    }
                }
            }
        }
Beispiel #2
0
        private void 工作区ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            worksapceFolderDialog.Description = "选择标注工作区,加载其中.png|.gif|.jpg|.bmp|.jpeg|.wmf图像文件";
            if (worksapceFolderDialog.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    GlobalMessage.Apply("status", "加载中");
                    workspace = worksapceFolderDialog.SelectedPath;
                    DirectoryInfo   wkDir   = new DirectoryInfo(workspace);
                    List <FileInfo> wkFiles = new List <FileInfo>();

                    wkFiles.AddRange(wkDir.GetFiles());
                    foreach (DirectoryInfo subDir in wkDir.GetDirectories("*", SearchOption.AllDirectories))
                    {
                        wkFiles.AddRange(subDir.GetFiles());
                    }

                    List <FileInfo> files = new List <FileInfo>();
                    foreach (FileInfo file in wkFiles)
                    {
                        switch (file.Extension.ToLower())
                        {
                        case ".png":
                        case ".gif":
                        case ".jpg":
                        case ".bmp":
                        case ".jpeg":
                        case ".wmf":
                            files.Add(file);
                            break;

                        default:
                            break;
                        }
                    }
                    GlobalMessage.Apply("status", $"共{files.Count}张图像");

                    annoPictureListPanel.Clear(true);
                    collect.ForEach((ctl) => { ctl.Image?.Dispose(); ctl.Dispose(); });
                    annoPictureListPanel.IsDynamicAdd     = files.Count > 100;
                    annoPictureListPanel.IsDynamicDispose = files.Count > 100;

                    //虚加载所有图像,并发送进度消息。
                    GlobalMessage.Progress progress = new GlobalMessage.Progress(files.Count)
                    {
                        ProgressingFormatString = "已加载{1}",
                        ProgressedString        = $"就绪,共{files.Count}张图像",
                        Print = PrintStatus
                    };
                    AnnoPictureBox[] annoPictures = new AnnoPictureBox[files.Count];
                    for (int i = 0; i < files.Count; i++)
                    {
                        annoPictures[i] = new AnnoPictureBox(files[i].FullName);
                        progress.Report(i + 1);
                    }
                    annoPictureListPanel.AddRange(annoPictures);
                    collect.AddRange(annoPictures);

                    annoPictureListPanel.ForEachItem((item) => item.paintIndexFont = new Font("微软雅黑", 15));
                }
                catch (Exception ex)
                {
                    GlobalMessage.Add("exception", ex.Message);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 计算正则表达式并写入textBox3中
        /// </summary>
        /// <param name="abort"></param>
        private void CalRegex(Process.Abort abort)
        {
            try
            {
                if (textBox2.Text.Length > 0)
                {
                    //显示的最大匹配数
                    const int max = 100;

                    //报告相关
                    GlobalMessage.Add("status", "计算正则...");

                    string[]        patterns = RegexText.GetLines();
                    MatchCollection matches  = Regex.Matches(FileContext, patterns[0]);

                    StringBuilder matchResult = new StringBuilder("");
                    int           realCount   = Math.Min(max, matches.Count);

                    //报告相关
                    GlobalMessage.Progress progress = new GlobalMessage.Progress(realCount)
                    {
                        ProgressedString = matches.Count > max ?
                                           $"就绪 {realCount}/{matches.Count}个匹配项" :
                                           $"就绪 {matches.Count}个匹配项"
                    };
                    if (matches.Count > max)
                    {
                        GlobalMessage.Add("info delay", $"匹配项过多,加载前{max}项");
                    }

                    ListViewGroup[] groups = new ListViewGroup[realCount];
                    for (int i = 0; i < realCount; i++)
                    {
                        if (abort != null && abort())
                        {
                            throw new Process.ProcessAbortException();
                        }

                        matchResult.Append(matches[i].Value.Replace("\n", @"\n") + "\r\n");
                        FieldInfo[]      fields = brushListPanel.CurrentItem.AnnoType.GetFields(FieldsOrder.BaseToSub);
                        AnnotationBase[] annos  = GetAnnoFromRegex(brushListPanel.CurrentItem,
                                                                   new string[1] {
                            matches[i].Value
                        },
                                                                   patterns.SubArray(1, patterns.Length - 1),
                                                                   fields, abort);
                        if (annos == null)
                        {
                            throw new Process.ProcessAbortException();
                        }

                        ListViewGroup group = new ListViewGroup($"Match {i} ({annos.Length})");
                        foreach (AnnotationBase anno in annos)
                        {
                            object[] values = anno.GetFieldsValues(fields);
                            group.Items.Add(new ListViewItem(values.ToStringArray()));
                        }
                        groups[i] = group;

                        //报告相关
                        progress.Report(i + 1);
                    }
                    //报告相关
                    if (realCount == 0)
                    {
                        progress.Report(progress.MaxValue);
                    }

                    Invoke(new Action(() =>
                    {
                        textBox3.Text = matchResult.ToString().Substring(0, Math.Min(textBox3.MaxLength, matchResult.Length));
                        listView1.Groups.AddRange(groups);
                        foreach (ListViewGroup group in groups)
                        {
                            listView1.Items.AddRange(group.Items);
                        }
                    }));
                }
                else
                {
                    GlobalMessage.Add("status", "就绪");
                }
            }
            catch (Process.ProcessAbortException)
            {
            }
            catch (Exception ex)
            {
                GlobalMessage.Add("status", "正则计算错误");
                GlobalMessage.Add("exception delay", ex.Message);
            }
            finally
            {
                GC.Collect();
            }
        }