轮胎外观检测添加思谋语义分割模型检测工具
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using System.Drawing;
//_5_1_a_s_p_x
namespace LB_VisionControls
{
    class KeyWordsAuto
    {
 
        static string[] keywords = { "abstract", "as", "base", "bool", "break", "byte", "case", "catch", "char",
                                      "checked", "class", "const", "continue", "decimal", "default", "delegate",
                                      "do", "double", "else", "enum", "event", "explicit", "extern", "false",
                                      "finally", "fixed", "float", "for", "foreach", "goto",
                                      "if", "implicit", "in", "int", "interface", "internal", "is", "lock", "long",
                                      "namespace", "new", "null", "object", "operator", "out", "override", "params",
                                      "private", "protected", "public", "readonly", "ref", "return", "sbyte", "sealed",
                                      "short", "sizeof", "stackalloc", "static", "string", "struct", "switch", "this",
                                      "throw", "true", "try", "typeof", "uint", "ulong", "unchecked", "unsafe", "ushort",
                                      "using", "virtual", "void", "volatile", "while", "add", "alias", "ascending",
                                      "descending", "dynamic", "from", "get", "global", "group", "into", "join", "let",
                                      "orderby", "partial", "remove", "select", "set", "value", "var", "where", "yield" };
 
        static string[] methods = { "Equals()", "GetHashCode()", "GetType()", "ToString()", "Length", "Count" };
 
        static string[] snippets = { "if(^)\n{\n;\n}", "if(^)\n{\n;\n}\nelse\n{\n;\n}", "for(^;;)\n{\n;\n}",
                                      "for(int i=0;i<^;i++)\n{\n;\n}","foreach(var i in ^)\n{\n;\n}" ,"while(^)\n{\n;\n}",
                                      "do${\n^;\n}while();", "switch(^)\n{\ncase : break;\n}",
                                  };
        static string[] declarationSnippets = {
               "public class ^\n{\n}", "private class ^\n{\n}", "internal class ^\n{\n}",
               "public struct ^\n{\n;\n}", "private struct ^\n{\n;\n}", "internal struct ^\n{\n;\n}",
               "public void ^()\n{\n;\n}", "private void ^()\n{\n;\n}", "internal void ^()\n{\n;\n}", "protected void ^()\n{\n;\n}",
               "public ^{ get; set; }", "private ^{ get; set; }", "internal ^{ get; set; }", "protected ^{ get; set; }",
               "Debug.WriteLine(^)", "Debug.Write(^)", "Debug.ReadLine()^", "Debug.Read()^", "Debug.ReadKey()^",
               "System;^", "System.Text;^", "System.Linq;^", "System.Collections.Generic;^", "System.Text.RegularExpressions;^", "System.Windows.Forms;^",
               "Application.Run(new Form())^","Application.Run(^)","Convert^","Convert.ToString(^)","Convert.ToString(^,2)"
               };
        static AutocompleteMenu popupMenu;
        static FastColoredTextBox CurrentTB;
        public static void CreatMenu(FastColoredTextBox fctb, ImageList imgList)
        {
            //create autocomplete popup menu
            popupMenu = new AutocompleteMenu(fctb);
            CurrentTB = fctb;
            popupMenu.Items.ImageList = imgList;
            popupMenu.Opening += new EventHandler<System.ComponentModel.CancelEventArgs>(popupMenu_Opening);
            BuildAutocompleteMenu();
        }
 
        static void popupMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e)
        {
            //---block autocomplete menu for comments
            //get index of green style (used for comments)
            var iGreenStyle = CurrentTB.GetStyleIndex(CurrentTB.SyntaxHighlighter.GreenStyle);
            if (iGreenStyle >= 0)
                if (CurrentTB.Selection.Start.iChar > 0)
                {
                    //current char (before caret)
                    var c = CurrentTB[CurrentTB.Selection.Start.iLine][CurrentTB.Selection.Start.iChar - 1];
                    //green Style
                    var greenStyleIndex = Range.ToStyleIndex(iGreenStyle);
                    //if char contains green style then block popup menu
                    if ((c.style & greenStyleIndex) != 0)
                        e.Cancel = true;
                }
        }
        private static void BuildAutocompleteMenu()
        {
            List<AutocompleteItem> items = new List<AutocompleteItem>();
            foreach (var item in snippets)
                items.Add(new SnippetAutocompleteItem(item) { ImageIndex = 0 });
            foreach (var item in declarationSnippets)
                items.Add(new DeclarationSnippet(item) { ImageIndex = 1 });
            foreach (var item in methods)
                items.Add(new MethodAutocompleteItem(item) { ImageIndex = 2 });
            foreach (var item in keywords)
                items.Add(new AutocompleteItem(item) { ImageIndex = 3 });
 
 
            items.Add(new InsertSpaceSnippet());
            items.Add(new InsertSpaceSnippet(@"^(\w+)([=<>!:]+)(\w+)$"));
            items.Add(new InsertEnterSnippet());
 
            //set as autocomplete source
            popupMenu.Items.SetAutocompleteItems(items);
            popupMenu.SearchPattern = @"[\w\.:=!<>]";
        }
        /// <summary>
        /// This item appears when any part of snippet text is typed
        /// </summary>
        class DeclarationSnippet : SnippetAutocompleteItem
        {
            public DeclarationSnippet(string snippet)
                : base(snippet)
            {
            }
 
            public override CompareResult Compare(string fragmentText)
            {
                var pattern = Regex.Escape(fragmentText);
                if (Regex.IsMatch(Text, "\\b" + pattern, RegexOptions.IgnoreCase))
                    return CompareResult.Visible;
                return CompareResult.Hidden;
            }
        }
 
        /// <summary>
        /// Divides numbers and words: "123AND456" -> "123 AND 456"
        /// Or "i=2" -> "i = 2"
        /// </summary>
        class InsertSpaceSnippet : AutocompleteItem
        {
            string pattern;
 
            public InsertSpaceSnippet(string pattern)
                : base("")
            {
                this.pattern = pattern;
            }
 
            public InsertSpaceSnippet()
                : this(@"^(\d+)([a-zA-Z_]+)(\d*)$")
            {
            }
 
            public override CompareResult Compare(string fragmentText)
            {
                if (Regex.IsMatch(fragmentText, pattern))
                {
                    Text = InsertSpaces(fragmentText);
                    if (Text != fragmentText)
                        return CompareResult.Visible;
                }
                return CompareResult.Hidden;
            }
 
            public string InsertSpaces(string fragment)
            {
                var m = Regex.Match(fragment, pattern);
                if (m == null)
                    return fragment;
                if (m.Groups[1].Value == "" && m.Groups[3].Value == "")
                    return fragment;
                return (m.Groups[1].Value + " " + m.Groups[2].Value + " " + m.Groups[3].Value).Trim();
            }
 
            public override string ToolTipTitle
            {
                get
                {
                    return Text;
                }
            }
        }
 
        /// <summary>
        /// Inerts line break after '}'
        /// </summary>
        class InsertEnterSnippet : AutocompleteItem
        {
            Place enterPlace = Place.Empty;
 
            public InsertEnterSnippet()
                : base("[Line break]")
            {
            }
 
            public override CompareResult Compare(string fragmentText)
            {
                var r = Parent.Fragment.Clone();
                while (r.Start.iChar > 0)
                {
                    if (r.CharBeforeStart == '}')
                    {
                        enterPlace = r.Start;
                        return CompareResult.Visible;
                    }
 
                    r.GoLeftThroughFolded();
                }
 
                return CompareResult.Hidden;
            }
 
            public override string GetTextForReplace()
            {
                //extend range
                Range r = Parent.Fragment;
                Place end = r.End;
                r.Start = enterPlace;
                r.End = r.End;
                //insert line break
                return Environment.NewLine + r.Text;
            }
 
            public override void OnSelected(AutocompleteMenu popupMenu, SelectedEventArgs e)
            {
                base.OnSelected(popupMenu, e);
                if (Parent.Fragment.tb.AutoIndent)
                    Parent.Fragment.tb.DoAutoIndent();
            }
 
            public override string ToolTipTitle
            {
                get
                {
                    return "Insert line break after '}'";
                }
            }
        }
        static readonly Platform platformType = PlatformType.GetOperationSystemPlatform();
        public static RegexOptions RegexCompiledOption
        {
            get
            {
                if (platformType == Platform.X86)
                    return RegexOptions.Compiled;
                else
                    return RegexOptions.None;
            }
        }
    }
}