프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / Document.cs @ d8b09f9f

이력 | 보기 | 이력해설 | 다운로드 (84.7 KB)

1
using DevExpress.Utils.StructuredStorage.Internal.Reader;
2
using System;
3
using System.Collections.Generic;
4
using System.Data;
5
using System.IO;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Xml.Linq;
10

    
11
namespace ID2PSN
12
{
13
    public class Document
14
    {
15
        public string DrawingName { get; set; }
16
        public string FileName { get; set; }
17
        public string FilePath { get; set; }
18
        public List<Item> Items { get; set; }
19
        public List<LineNumber> LineNumbers { get; set; }
20
        public List<Group> Groups { get; set; }
21
        public List<RunInfo> RunInfos { get; set; }
22
        public List<Item> SegmentBreaks { get; set; }
23
        public List<Equipment> Equipments { get; set; }
24
        public List<TextInfo> TextInfos { get; set; }
25

    
26
        private DataTable symbolNameTable = null;
27
        private DataTable equipmentTable = DB.GetEquipmentType();
28

    
29
        public Document(string filePath, DataTable symbolNameTable)
30
        {
31
            this.symbolNameTable = symbolNameTable;
32
            FilePath = filePath;
33
            // XML Data 정리
34
            ReadFile();
35
            // 해당 소스는 Line-Equipment가 붙어있을 시 가상의 Nozzle Data를 넣어줌 (삼엔 요청)
36
            InsertNozzle();
37
            // ID2 Item Relation 정보 기준으로 Item Object 연결
38
            SetRelationItem();
39
            // Instrument Line이 있는 아이템/group 제거
40
            RemoveItems();
41
            // 속성 상관 없이 drawing 단위의 PSN 생성
42
            SetGroup();
43

    
44
            foreach (var item in Items)
45
                item.Document = this;
46
        }
47
        private void ReadFile()
48
        {
49
            XElement xml = XElement.Load(FilePath);
50
            FileName = Path.GetFileNameWithoutExtension(FilePath);
51
            DrawingName = xml.Element("DWGNAME").Value;
52
            Items = new List<Item>();
53
            LineNumbers = new List<LineNumber>();
54
            RunInfos = new List<RunInfo>();
55
            Groups = new List<Group>();
56
            SegmentBreaks = new List<Item>();
57
            Equipments = new List<Equipment>();
58
            TextInfos = new List<TextInfo>();
59

    
60
            foreach (XElement element in xml.Element("SYMBOLS").Elements("SYMBOL"))
61
                Items.Add(GetSymbolItem(element));
62
            foreach (XElement element in xml.Element("LINEINFOS").Elements("LINE"))
63
                Items.Add(GetLineItem(element));
64
            foreach (XElement element in xml.Element("LINENOS").Elements("LINE_NO"))
65
                LineNumbers.Add(GetLineNumber(element));
66
            foreach (XElement element in xml.Element("VENDORS").Elements("VENDOR"))
67
                Equipments.Add(GetEquipment(element));
68
            foreach (XElement element in xml.Element("TEXTINFOS").Elements("ATTRIBUTE"))
69
                TextInfos.Add(GetTextInfo(element));
70

    
71
            List<Item> segmentBreaks = Items.FindAll(x => x.ID2DBType.ToUpper() == "Segment Breaks".ToUpper() || x.ID2DBType.ToUpper() == "End Break".ToUpper());
72
            SegmentBreaks.AddRange(segmentBreaks);
73
            foreach (var item in segmentBreaks)
74
                Items.Remove(item);
75

    
76
            foreach (DataRow row in equipmentTable.Rows)
77
            {
78
                string type = row["Type"].ToString();
79
                List<Item> equipments = Items.FindAll(x => x.ID2DBType == type);
80

    
81
                foreach (Item item in equipments)
82
                {
83
                    Equipments.Add(ConvertEquipment(item));
84
                    Items.Remove(item);
85
                }
86
            }
87

    
88
            SetRunInfo(xml);
89
        }
90
        private Item GetSymbolItem(XElement element)
91
        {
92
            Item item = new Item();
93
            item.UID = element.Element("UID").Value;
94
            item.Name = element.Element("NAME").Value;
95
            item.ID2DBType = element.Element("TYPE").Value;
96
            item.Owner = element.Element("OWNER").Value;
97
            item.ID2DBName = element.Element("PARENT").Value;
98
            string[] sPoint = element.Element("ORIGINALPOINT").Value.Split(new char[] { ',' });
99
            item.POINT = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) };
100
            item.ANGLE = element.Element("ANGLE").Value;
101
            item.Relations = GetRelations(element.Element("CONNECTORS"));
102
            item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES"));
103
            item.ItemType = ItemType.Symbol;
104
            item.ID2DBCategory = GetID2DBCategory(item.ID2DBType, item.ID2DBName);
105

    
106
            if (item.ID2DBType.ToUpper().Equals("PIPING OPC'S"))
107
                item.SubItemType = SubItemType.OPC;
108
            else if (item.ID2DBType.ToUpper().Equals("NOZZLES"))
109
                item.SubItemType = SubItemType.Nozzle;
110

    
111
            return item;
112
        }
113
        private Item GetLineItem(XElement element)
114
        {
115
            Item item = new Item();
116
            item.UID = element.Element("UID").Value;
117
            item.Name = element.Element("TYPE").Value;
118
            item.ID2DBType = element.Element("TYPE").Value;
119
            item.Owner = element.Attribute("OWNER").Value;
120

    
121
            item.Relations = GetRelations(element.Element("CONNECTORS"));
122
            item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES"));
123
            item.ItemType = ItemType.Line;
124

    
125
            return item;
126
        }
127
        private LineNumber GetLineNumber(XElement element)
128
        {
129
            LineNumber lineNumber = new LineNumber();
130
            lineNumber.UID = element.Element("UID").Value;           
131
            lineNumber.Name = element.Element("TEXT").Value;
132
            lineNumber.Attributes = GetAttributes(element);
133
            return lineNumber;
134
        }
135
        private Equipment GetEquipment(XElement element)
136
        {
137
            Equipment item = new Equipment();
138
            item.UID = element.Element("UID").Value;
139
            item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES"));
140
            string[] sPoint = element.Element("POINT").Value.Split(new char[] { '/' });
141
            foreach (var sp in sPoint)
142
            {
143
                string[] xy = sp.Split(new char[] { ',' });
144
                item.POINT.Add(new double[] { Convert.ToDouble(xy[0]), Convert.ToDouble(xy[1]) });
145
            }
146

    
147
            return item;
148
        }
149
        private TextInfo GetTextInfo(XElement element)
150
        {
151
            TextInfo textInfo = new TextInfo();
152
            textInfo.Value = element.Element("VALUE").Value;
153
            textInfo.Area = element.Element("AREA").Value;
154

    
155
            return textInfo;
156
        }
157
        private Equipment ConvertEquipment(Item item)
158
        {
159
            Equipment equipment = new Equipment();
160
            equipment.Name = item.Name;
161
            equipment.UID = item.UID;
162
            equipment.POINT.Add(item.POINT);
163
            equipment.Attributes.AddRange(item.Attributes);
164
            return equipment;
165
        }
166
        private List<Relation> GetRelations(XElement element)
167
        {
168
            List<Relation> result = new List<Relation>();
169
            foreach (XElement item in element.Elements("CONNECTOR"))
170
            {
171
                string[] sPoint = item.Element("SCENECONNECTPOINT").Value.Split(new char[] { ',' });
172
                result.Add(new Relation()
173
                {
174
                    UID = item.Element("CONNECTEDITEM").Value,
175
                    Point = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) }
176
                });
177
            }
178

    
179
            return result;
180
        }
181
        private List<Attribute> GetAttributes(XElement element)
182
        {
183
            List<Attribute> result = new List<Attribute>();
184
            foreach (XElement item in element.Elements("ATTRIBUTE"))
185
            {
186
               
187
                result.Add(new Attribute()
188
                {
189
                    UID = item.Attribute("UID").Value,
190
                    Name = item.Attribute("Attribute").Value,
191
                    DisplayName = item.Attribute("DisplayAttribute").Value,
192
                    Value = item.Value
193
                });
194
            }
195
            return result;
196
        }
197
        private string GetID2DBCategory(string type, string name)
198
        {
199
            string result = string.Empty;
200
            DataRow[] rows = symbolNameTable.Select(string.Format("Type = '{0}' AND Name = '{1}'", type.Replace("'", "''"), name.Replace("'", "''")));
201
            if (rows.Length.Equals(1))
202
                result = rows.First()["Category"].ToString();
203

    
204
            return result;
205
        }
206
        private void SetRelationItem()
207
        {
208
            foreach (Item item in Items)
209
                foreach (Relation relation in item.Relations)
210
                    relation.Item = Items.Find(x => x.UID.Equals(relation.UID));
211
        }
212
        private void SetRunInfo(XElement xml)
213
        {
214
            foreach (XElement element in xml.Element("LINENOS").Elements("LINE_NO"))
215
            {
216
                string UID = element.Element("UID").Value;
217
                foreach (XElement run in element.Elements("RUN"))
218
                {
219
                    RunInfo runInfo = new RunInfo() { UID = UID };
220
                    foreach (XElement line in run.Elements("LINE"))
221
                        runInfo.Items.Add(Items.Find(x => x.UID == line.Element("UID").Value));
222
                    foreach (XElement symbol in run.Elements("SYMBOL"))
223
                        runInfo.Items.Add(Items.Find(x => x.UID == symbol.Element("UID").Value));
224
                    RunInfos.Add(runInfo);
225
                }
226
            }
227

    
228
            foreach (XElement element in xml.Element("TRIMLINENOS").Elements("TRIM_LINE_NO"))
229
            {
230
                string UID = element.Element("UID").Value;
231
                foreach (XElement run in element.Elements("RUN"))
232
                {
233
                    RunInfo runInfo = new RunInfo() { UID = UID };
234
                    foreach (XElement line in run.Elements("LINE"))
235
                        runInfo.Items.Add(Items.Find(x => x.UID == line.Element("UID").Value));
236
                    foreach (XElement symbol in run.Elements("SYMBOL"))
237
                        runInfo.Items.Add(Items.Find(x => x.UID == symbol.Element("UID").Value));
238
                    RunInfos.Add(runInfo);
239
                }
240
            }
241
        }
242

    
243

    
244
        private void SetGroup()
245
        {
246
            List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList();
247

    
248
            List<Item> unasignedMultiwaySymbol = new List<Item>();
249
            List<Item> asignedMultiwaySymbol = new List<Item>();
250

    
251
            Dictionary<Item, string> itemDic = new Dictionary<Item, string>();
252
            foreach (Item item in orderItems)
253
                itemDic.Add(item, Guid.NewGuid().ToString());
254

    
255
            foreach (Item item in orderItems)
256
            {
257
                string groupKey = itemDic[item];
258
                if (item.ItemType == ItemType.Line)
259
                {
260
                    GroupingForwardLine();
261
                    GroupingBackwardLine();
262
                }
263

    
264
                if (item == orderItems.Last())
265
                {
266
                    foreach (var multiwaySymbol in unasignedMultiwaySymbol.Where(w => !asignedMultiwaySymbol.Contains(w)))
267
                    {
268
                        List<Item> inLine = new List<Item>();
269
                        List<Item> outLine = new List<Item>();
270
                        inLine.AddRange(GetConnectedBackwardLines(multiwaySymbol));
271
                        outLine.AddRange(GetConnectedForwardLines(multiwaySymbol));
272

    
273
                        // in line 혹은 out line 이 1개
274
                        if (inLine.Count > 0 && outLine.Count > 0 && (inLine.Count == 1 || outLine.Count == 1))
275
                        {
276
                            Item standardLine = inLine.Count == 1 ? inLine[0] : outLine[0];
277
                            List<Item> watingLines = inLine.Count == 1 ? outLine : inLine;
278

    
279
                            List<Item> sameOwnerLines = new List<Item>();
280

    
281
                            foreach (var watingLine in watingLines)
282
                            {
283
                                if (IsSameOwner(standardLine, watingLine))
284
                                {
285
                                    sameOwnerLines.Add(watingLine);
286
                                }
287
                            }
288

    
289
                            // 기준 라인이랑 라인 넘버가 같은 라인이 1개 => 바로 연결
290
                            if (sameOwnerLines.Count == 1)
291
                            {
292
                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
293
                                ChangeGroupID(itemDic[sameOwnerLines[0]], itemDic[standardLine]);
294
                            } 
295
                            // 기준 라인이랑 라인 넘버가 같은 라인이 0개
296
                            else if (sameOwnerLines.Count == 0)
297
                            {
298
                                // NPD 기준 내림차순 정렬
299
                                watingLines.Sort((a, b) => StringToNumber(a.GetAttributeByName("NominalDiameter")).CompareTo(StringToNumber(b.GetAttributeByName("NominalDiameter"))));
300
                                watingLines.Reverse();
301

    
302
                                double largeSize = StringToNumber(watingLines[0].GetAttributeByName("NominalDiameter"));
303
                                // NPD가 큰 라인들을 선택
304
                                var largeLines = watingLines.Where(w => StringToNumber(w.GetAttributeByName("NominalDiameter")).Equals(largeSize)).ToList();
305

    
306
                                // NPD가 가장 큰 라인이 1개
307
                                if (largeLines.Count == 1)
308
                                {
309
                                    ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
310
                                    ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]);
311
                                }
312
                                else
313
                                {
314
                                    // NPD가 동일하게 가장 큰 라인이 여러개
315
                                    Relation relation = multiwaySymbol.Relations.Find(x => x.Item == standardLine);
316
                                    int connectionIndex = multiwaySymbol.Relations.IndexOf(relation);
317

    
318
                                    if (connectionIndex == 0 || connectionIndex == 1)
319
                                    {
320
                                        Item nextItem = (connectionIndex == 0) ? multiwaySymbol.Relations[1].Item : multiwaySymbol.Relations[0].Item;
321
                                        if (nextItem != null)
322
                                        {
323
                                            var matches = largeLines.Where(w => w == nextItem).ToList();
324
                                            // NPD가 큰 라인 중에 직선으로 연결된 라인이 있음
325
                                            if (matches.Count == 1)
326
                                            {
327
                                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
328
                                                ChangeGroupID(itemDic[matches[0]], itemDic[standardLine]);
329
                                            }
330
                                            // 없음 => 랜덤
331
                                            else
332
                                            {
333
                                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
334
                                                ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]);
335
                                            }
336
                                        }
337
                                    }
338
                                    else if (multiwaySymbol.Relations.Count > 3 && connectionIndex == 2 || connectionIndex == 3)
339
                                    {
340
                                        Item nextItem = (connectionIndex == 2) ? multiwaySymbol.Relations[3].Item : multiwaySymbol.Relations[2].Item;
341
                                        if (nextItem != null)
342
                                        {
343
                                            var matches = largeLines.Where(w => w == nextItem).ToList();
344
                                            // NPD가 큰 라인 중에 직선으로 연결된 라인이 있음
345
                                            if (matches.Count == 1)
346
                                            {
347
                                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
348
                                                ChangeGroupID(itemDic[matches[0]], itemDic[standardLine]);
349
                                            }
350
                                            // 없음 => 랜덤
351
                                            else
352
                                            {
353
                                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
354
                                                ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]);
355
                                            }
356
                                        }
357
                                    }
358
                                    // 3 way에서 NPS가 가장 큰 라인이 2번 연결점에 연결됨 => 랜덤
359
                                    else
360
                                    {
361
                                        ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
362
                                        ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]);
363
                                    }
364
                                }
365
                            }
366
                            // 기준 라인이랑 라인 넘버가 같은 라인이 2~3개 => NPD가 큰 라인, 직선으로 연결된 라인이랑 연결
367
                            else
368
                            {
369
                                // NPD 기준 내림차순 정렬
370
                                sameOwnerLines.Sort((a, b) => StringToNumber(a.GetAttributeByName("NominalDiameter")).CompareTo(StringToNumber(b.GetAttributeByName("NominalDiameter"))));
371
                                sameOwnerLines.Reverse();
372

    
373
                                double largeSize = StringToNumber(sameOwnerLines[0].GetAttributeByName("NominalDiameter"));
374
                                // NPD가 큰 라인들을 선택
375
                                var largeLines = sameOwnerLines.Where(w => StringToNumber(w.GetAttributeByName("NominalDiameter")).Equals(largeSize)).ToList();
376

    
377
                                // NPD가 가장 큰 라인이 1개
378
                                if (largeLines.Count == 1)
379
                                {
380
                                    ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
381
                                    ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]);
382
                                }
383
                                else
384
                                {
385
                                    // NPD가 동일하게 가장 큰 라인이 여러개
386
                                    Relation relation = multiwaySymbol.Relations.Find(x => x.Item == standardLine);
387
                                    int connectionIndex = multiwaySymbol.Relations.IndexOf(relation);
388

    
389
                                    if (connectionIndex == 0 || connectionIndex == 1)
390
                                    {
391
                                        Item nextItem = (connectionIndex == 0) ? multiwaySymbol.Relations[1].Item : multiwaySymbol.Relations[0].Item;
392
                                        if (nextItem != null)
393
                                        {
394
                                            var matches = largeLines.Where(w => w == nextItem).ToList();
395
                                            // NPD가 큰 라인 중에 직선으로 연결된 라인이 있음
396
                                            if (matches.Count == 1)
397
                                            {
398
                                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
399
                                                ChangeGroupID(itemDic[matches[0]], itemDic[standardLine]);
400
                                            }
401
                                            // 없음 => 랜덤
402
                                            else
403
                                            {
404
                                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
405
                                                ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]);
406
                                            }
407
                                        }
408
                                    }
409
                                    else if (multiwaySymbol.Relations.Count > 3 && connectionIndex == 2 || connectionIndex == 3)
410
                                    {
411
                                        Item nextItem = (connectionIndex == 2) ? multiwaySymbol.Relations[3].Item : multiwaySymbol.Relations[2].Item;
412
                                        if (nextItem != null)
413
                                        {
414
                                            var matches = largeLines.Where(w => w == nextItem).ToList();
415
                                            // NPD가 큰 라인 중에 직선으로 연결된 라인이 있음
416
                                            if (matches.Count == 1)
417
                                            {
418
                                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
419
                                                ChangeGroupID(itemDic[matches[0]], itemDic[standardLine]);
420
                                            }
421
                                            // 없음 => 랜덤
422
                                            else
423
                                            {
424
                                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
425
                                                ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]);
426
                                            }
427
                                        }
428
                                    }
429
                                    // 3 way에서 NPS가 가장 큰 라인이 2번 연결점에 연결됨 => 랜덤
430
                                    else
431
                                    {
432
                                        ChangeGroupID(itemDic[multiwaySymbol], itemDic[standardLine]);
433
                                        ChangeGroupID(itemDic[largeLines[0]], itemDic[standardLine]);
434
                                    }
435
                                }
436
                            }      
437
                        }
438
                        else //in : 2 / out : 2
439
                        {
440
                            List<Item> lines = new List<Item>();
441
                            lines.AddRange(inLine);
442
                            lines.AddRange(outLine);
443

    
444
                            int lineCount = lines.Select(x => x.Owner).Distinct().Count();
445

    
446
                            if(lineCount == 1 || lineCount == 4)
447
                            {
448
                                // NPD 기준 내림차순 정렬
449
                                inLine.Sort((a, b) => StringToNumber(a.GetAttributeByName("NominalDiameter")).CompareTo(StringToNumber(b.GetAttributeByName("NominalDiameter"))));
450
                                inLine.Reverse();
451

    
452
                                outLine.Sort((a, b) => StringToNumber(a.GetAttributeByName("NominalDiameter")).CompareTo(StringToNumber(b.GetAttributeByName("NominalDiameter"))));
453
                                outLine.Reverse();
454

    
455
                                ChangeGroupID(itemDic[multiwaySymbol], itemDic[inLine[0]]);
456
                                ChangeGroupID(itemDic[outLine[0]], itemDic[inLine[0]]);
457
                            }
458
                            else //3
459
                            {
460
                                foreach(Item inl in inLine)
461
                                {
462
                                    foreach (Item outl in outLine)
463
                                    {
464
                                        if(IsSameOwner(inl, outl))
465
                                        {
466
                                            ChangeGroupID(itemDic[multiwaySymbol], itemDic[inl]);
467
                                            ChangeGroupID(itemDic[outl], itemDic[inl]);
468
                                            break;
469
                                        }
470
                                    }
471
                                }
472

    
473

    
474
                            }
475
                        }
476
                    }
477
                }
478

    
479
                void GroupingForwardLine()
480
                {
481
                    Item connItem = item.Relations[1].Item;
482
                    if (connItem != null && IsConnected(connItem, item))
483
                    {
484
                        if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[0].Item))
485
                            ChangeGroupID(itemDic[connItem], groupKey);
486
                        else if (connItem.ItemType == ItemType.Symbol)
487
                        {
488
                            List<Item> allConnItems = GetConnectedLines(connItem);
489
                            allConnItems.Remove(item);
490
                            List<Item> connItems = GetConnectedForwardLines(connItem);
491
                            if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0]))
492
                            {
493
                                List<Item> connSymbols = GetConnectedSymbols(connItem);
494
                                foreach (Item loopItem in connSymbols)
495
                                    ChangeGroupID(itemDic[loopItem], groupKey);
496
                            }
497
                            else
498
                            {
499
                                List<Item> endItems = new List<Item>();
500
                                Stack<Item> stacks = new Stack<Item>();
501
                                Item preItem = item;
502
                                stacks.Push(connItem);
503
                                while (stacks.Count > 0)
504
                                {
505
                                    Item stack = stacks.Pop();
506
                                    if (endItems.Contains(stack))
507
                                        continue;
508
                                    endItems.Add(stack);
509

    
510
                                    if (GetConnectedItemCount(stack) < 3)
511
                                    {
512
                                        ChangeGroupID(itemDic[stack], groupKey);
513
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
514
                                        foreach (Relation relation in relations)
515
                                            stacks.Push(relation.Item);
516
                                        preItem = stack;
517
                                    }
518
                                    else
519
                                    {
520
                                        if (!unasignedMultiwaySymbol.Contains(stack))
521
                                            unasignedMultiwaySymbol.Add(stack);
522
                                    }
523
                                }
524
                            }
525
                        }
526
                    }
527
                }
528
                
529
               
530
                void GroupingBackwardLine()
531
                {
532
                    Item connItem = item.Relations[0].Item;
533
                    if (connItem != null && IsConnected(connItem, item))
534
                    {
535
                        if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[1].Item))
536
                            ChangeGroupID(itemDic[connItem], groupKey);
537
                        else if (connItem.ItemType == ItemType.Symbol)
538
                        {
539
                            List<Item> allConnItems = GetConnectedLines(connItem);
540
                            allConnItems.Remove(item);
541
                            List<Item> connItems = GetConnectedBackwardLines(connItem);
542
                            if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0]))
543
                            {
544
                                List<Item> connSymbols = GetConnectedSymbols(connItem);
545
                                foreach (Item loopItem in connSymbols)
546
                                    ChangeGroupID(itemDic[loopItem], groupKey);
547
                            }
548
                            else
549
                            {
550
                                List<Item> endItems = new List<Item>();
551
                                Stack<Item> stacks = new Stack<Item>();
552
                                Item preItem = item;
553
                                stacks.Push(connItem);
554
                                while (stacks.Count > 0)
555
                                {
556
                                    Item stack = stacks.Pop();
557
                                    if (endItems.Contains(stack))
558
                                        continue;
559
                                    endItems.Add(stack);
560

    
561
                                    Item nextSymbol;
562

    
563
                                    if (GetConnectedItemCount(stack) < 3)
564
                                    {
565
                                        ChangeGroupID(itemDic[stack], groupKey);
566
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
567
                                        foreach (Relation relation in relations)
568
                                            stacks.Push(relation.Item);
569
                                        preItem = stack;
570
                                    }
571
                                    else
572
                                    {
573
                                        if (!unasignedMultiwaySymbol.Contains(stack))
574
                                            unasignedMultiwaySymbol.Add(stack);
575
                                    }
576
                                }
577
                            }
578
                        }
579
                    }
580
                }
581

    
582
                bool MultiwayBackward(Item stack, Item beforeItem, out Item nextSymbol)
583
                {
584
                    nextSymbol = null;
585
                    if (!unasignedMultiwaySymbol.Contains(stack))
586
                        unasignedMultiwaySymbol.Add(stack);
587

    
588
                    if (stack.pairItem != null && stack.pairItem != beforeItem)
589
                        return false;
590

    
591
                    try
592
                    {
593
                        Relation relation = stack.Relations.Find(x => x.Item == beforeItem);
594
                        if (relation == null)
595
                        {
596
                            return false;
597
                        }
598

    
599
                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item != beforeItem);
600
                        return false;
601
                        if (relations.Count() == 0)
602
                            return false;
603

    
604
                        var matches = relations.Where(x => IsSameOwner(beforeItem, x.Item)).ToList();
605

    
606
                        if (matches.Count().Equals(0))
607
                            return false;
608

    
609
                        else if (matches.Count().Equals(1))
610
                        {
611
                            if (matches[0].Item.ItemType == ItemType.Line)
612
                            {
613
                                List<Item> connItems = GetConnectedBackwardLines(stack);
614
                                if (connItems.Contains(matches[0].Item))
615
                                {
616
                                    stack.pairItem = matches[0].Item;
617
                                    return true;
618
                                }
619
                            }
620
                            else
621
                            {
622
                                stack.pairItem = matches[0].Item;
623
                                nextSymbol = matches[0].Item;
624
                                return true;
625
                            }
626
                        }
627
                        else if (matches.Count().Equals(2))
628
                        {
629
                            List<Item> connItems = GetConnectedBackwardLines(stack);
630
                            if (connItems.Count == 0)
631
                                return false;
632
                            else
633
                            {
634
                                connItems = connItems.Where(x => IsSameOwner(beforeItem, x)).ToList();
635
                            }
636

    
637
                            if (connItems.Count().Equals(1))
638
                            {
639
                                bool isvalid = false;
640
                                Item matchedLine = GetConnectedMatchedLIne(matches.Where(x => x.Item != connItems[0]).First().Item, stack);
641
                                if (matchedLine != null)
642
                                {
643
                                    string size1 = matchedLine.GetAttributeByName("Size");
644
                                    string size2 = item.GetAttributeByName("Size");
645
                                    if (!string.IsNullOrEmpty(size1) && !string.IsNullOrEmpty(size2) && size1 != "None" && size2 != "None")
646
                                    {
647
                                        if (size1.Contains("\"") && InchToNumber(size1) < InchToNumber(size2))
648
                                        {
649
                                            isvalid = true;
650
                                        }
651
                                        else if (Convert.ToDouble(size1) < Convert.ToDouble(size2))
652
                                        {
653
                                            isvalid = true;
654
                                        }
655
                                    }
656
                                    else if (!string.IsNullOrEmpty(size2) && size2 != "None" && string.IsNullOrEmpty(size1))
657
                                    {
658
                                        isvalid = true;
659
                                    }
660
                                }
661

    
662
                                if (!isvalid)
663
                                    return false;
664

    
665
                                if (matches.Where(x => x.Item == connItems[0]) != null)
666
                                {
667
                                    stack.pairItem = connItems[0];
668
                                    return true;
669
                                }
670
                                else
671
                                {
672
                                    Item matechedSymbol = GetConnectedMatchedSymbol(connItems[0].Relations[1].Item, connItems[0], stack);
673
                                    if (matechedSymbol != null)
674
                                    {
675
                                        stack.pairItem = matechedSymbol;
676
                                        nextSymbol = matechedSymbol;
677
                                        return true;
678
                                    }
679
                                    else
680
                                    {
681
                                        return false;
682
                                    }
683
                                }
684
                            }
685
                            else if (connItems.Count() > 1)
686
                            {
687
                                return true;//pair아이템 필요할 수도 있음
688

    
689
                            }
690
                        }
691
                        else
692
                        {
693
                            return true;
694
                        }
695

    
696

    
697

    
698
                        //if (relation == null)
699
                        //{
700
                        //    return false;
701
                        //}
702
                        //int connectionIndex = stack.Relations.IndexOf(relation);
703
                        //if (connectionIndex == 0 || connectionIndex == 1)
704
                        //{
705
                        //    Item nextItem = (connectionIndex == 0) ? stack.Relations[1].Item : stack.Relations[0].Item;
706
                        //    if (nextItem != null)
707
                        //    {
708
                        //        if (nextItem.ItemType == ItemType.Line)
709
                        //        {
710
                        //            List<Item> connItems = GetConnectedBackwardLines(stack);
711
                        //            if (connItems.Contains(nextItem))
712
                        //            {
713
                        //                stack.pairItem = nextItem;
714
                        //                return true;
715
                        //            }
716
                        //        }
717
                        //        else
718
                        //        {
719
                        //            stack.pairItem = nextItem;
720
                        //            nextSymbol = nextItem;
721
                        //            return true;
722
                        //        }
723
                        //    }
724
                        //}
725
                        //else if (stack.Relations.Count > 3 && connectionIndex == 2 || connectionIndex == 3)
726
                        //{
727
                        //    Item nextItem = (connectionIndex == 2) ? stack.Relations[3].Item : stack.Relations[2].Item;
728
                        //    if (nextItem != null)
729
                        //    {
730
                        //        if (nextItem.ItemType == ItemType.Line)
731
                        //        {
732
                        //            List<Item> connItems = GetConnectedForwardLines(stack);
733
                        //            if (connItems.Contains(nextItem))
734
                        //            {
735
                        //                stack.pairItem = nextItem;
736
                        //                return true;
737
                        //            }
738
                        //        }
739
                        //        else
740
                        //        {
741
                        //            stack.pairItem = nextItem;
742
                        //            nextSymbol = nextItem;
743
                        //            return true;
744
                        //        }
745
                        //    }
746
                        //}
747
                    }
748
                    catch (Exception ex)
749
                    {
750
                        //Log.Write(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + "Error Item : " + beforeItem.UID + ", Error stack : " + stack.UID + "\r\n");
751
                        //MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace + "\r\n", "ARS ID2", MessageBoxButtons.OK, MessageBoxIcon.Information);
752
                    }
753

    
754
                    return false;
755
                }
756
                //bool MultiwayBackward(Item stack, Item beforeItem, out Item nextSymbol)
757
                //{
758
                //    nextSymbol = null;
759
                //    if (!unasignedMultiwaySymbol.Contains(stack))
760
                //        unasignedMultiwaySymbol.Add(stack);
761

    
762
                //    if (stack.pairItem != null && stack.pairItem != beforeItem)
763
                //        return false;
764

    
765
                //    try
766
                //    {
767
                //        Relation relation = stack.Relations.Find(x => x.Item == beforeItem);
768
                //        if (relation == null)
769
                //        {
770
                //            return false;
771
                //        }
772
                //        int connectionIndex = stack.Relations.IndexOf(relation);
773
                //        if (connectionIndex == 0 || connectionIndex == 1)
774
                //        {
775
                //            Item nextItem = (connectionIndex == 0) ? stack.Relations[1].Item : stack.Relations[0].Item;
776
                //            if (nextItem != null)
777
                //            {
778
                //                if (nextItem.ItemType == ItemType.Line)
779
                //                {
780
                //                    List<Item> connItems = GetConnectedBackwardLines(stack);
781
                //                    if (connItems.Contains(nextItem))
782
                //                    {
783
                //                        stack.pairItem = nextItem;
784
                //                        return true;
785
                //                    }
786
                //                }
787
                //                else
788
                //                {
789
                //                    stack.pairItem = nextItem;
790
                //                    nextSymbol = nextItem;
791
                //                    return true;
792
                //                }
793
                //            }
794
                //        }
795
                //        else if (stack.Relations.Count > 3 && connectionIndex == 2 || connectionIndex == 3)
796
                //        {
797
                //            Item nextItem = (connectionIndex == 2) ? stack.Relations[3].Item : stack.Relations[2].Item;
798
                //            if (nextItem != null)
799
                //            {
800
                //                if (nextItem.ItemType == ItemType.Line)
801
                //                {
802
                //                    List<Item> connItems = GetConnectedBackwardLines(stack);
803
                //                    if (connItems.Contains(nextItem))
804
                //                    {
805
                //                        stack.pairItem = nextItem;
806
                //                        return true;
807
                //                    }
808
                //                }
809
                //                else
810
                //                {
811
                //                    stack.pairItem = nextItem;
812
                //                    nextSymbol = nextItem;
813
                //                    return true;
814
                //                }
815
                //            }
816
                //        }
817
                //    }
818
                //    catch (Exception ex)
819
                //    {
820
                //        Log.Write(ex.Message + "\r\n" + ex.StackTrace + "\r\n" + "Error Item : " + beforeItem.UID + ", Error stack : " + stack.UID + "\r\n");
821
                //        MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace + "\r\n", "ARS ID2", MessageBoxButtons.OK, MessageBoxIcon.Information);
822
                //    }
823

    
824
                //    return false;
825
                //}
826
            }
827

    
828
            List<string> endGroupIds = new List<string>();
829
            foreach (var item in itemDic)
830
            {
831
                if (endGroupIds.Contains(item.Value))
832
                    continue;
833
                endGroupIds.Add(item.Value);
834

    
835
                List<Item> groupItems = itemDic.Where(x => x.Value.Equals(item.Value)).Select(x => x.Key).ToList();
836
                if (groupItems.Find(x => x.ItemType == ItemType.Line) == null)
837
                {
838
                    foreach (var groupItem in groupItems)
839
                        Items.Remove(groupItem);
840
                }
841
                else
842
                {
843
                    Group group = new Group(this);
844
                    group.Items = groupItems;
845
                    group.UID = item.Value;
846
                    group.SortItems();
847
                    foreach (Item groupItem in groupItems)
848
                        groupItem.Group = group;
849
                    Groups.Add(group);
850
                }
851
            }
852

    
853
            #region HeaderSetting
854
            List<HeaderInfo> HeaderInfos = new List<HeaderInfo>();
855
            DataTable dt = DB.SelectHeaderSetting();
856
            foreach (DataRow row in dt.Rows)
857
            {
858
                string groupID = row["GROUP_ID"].ToString();
859
                string desc = row["DESCRIPTION"].ToString();
860
                int index = Convert.ToInt32(row["INDEX"]);
861
                string name = row["NAME"].ToString();
862

    
863
                HeaderInfo headerInfo = HeaderInfos.Find(x => x.UID.Equals(groupID));
864
                if (headerInfo == null)
865
                {
866
                    headerInfo = new HeaderInfo(groupID);
867
                    headerInfo.Description = desc;
868
                    HeaderInfos.Add(headerInfo);
869
                }
870

    
871

    
872
                headerInfo.HeaderItems.Add(new HeaderItem()
873
                {
874
                    Index = index,
875
                    Name = name
876
                });
877
            }
878

    
879

    
880
            foreach (HeaderInfo headerInfo in HeaderInfos)
881
                headerInfo.HeaderItems = headerInfo.HeaderItems.OrderByDescending(x => x.Index).ToList();
882

    
883
            foreach (Group group in Groups)
884
            {
885
                foreach (HeaderInfo header in HeaderInfos)
886
                {
887
                    if (group.Items.Count < header.HeaderItems.Count)
888
                    {
889
                        continue;
890
                    }
891

    
892
                    bool found = true;
893
                    for (int i = 0; i < header.HeaderItems.Count; i++)
894
                    {
895
                        if (!header.HeaderItems[header.HeaderItems.Count - 1 - i].Name.Equals(group.Items[i].Name))
896
                        {
897
                            found = false;
898
                            break;
899
                        }
900
                    }
901
                    if (found)
902
                    {
903
                        found = false;
904
                        List<Item> branches = new List<Item>();
905
                        //for (int i = 0; i < header.HeaderItems.Count; i++)
906
                        //{
907
                        //    if (group.Items[i].ItemType == ItemType.Line)
908
                        //    {
909
                        foreach (var _line in group.Items.Where(x => x.ItemType == ItemType.Line))
910
                        {
911
                            branches = Groups.Where(w => w != group).SelectMany(s => s.Items).Where(w => w.ItemType == ItemType.Line).Where(w => w.Relations[0].Item == _line || w.Relations[1].Item == _line).ToList();
912
                            if (branches.Count > 0)
913
                            {
914
                                found = true;
915
                                break;
916
                            }
917

    
918
                            if (found)
919
                                break;
920
                        }
921
                        //    }
922
                        //}
923

    
924
                        if (found)
925
                        {
926
                            for (int i = 0; i < header.HeaderItems.Count; i++)
927
                            {
928
                                group.Items[i].SubItemType = SubItemType.Header;
929
                            }
930
                        }
931
                    }
932

    
933
                    found = true;
934
                    for (int i = 0; i < header.HeaderItems.Count; i++)
935
                    {
936
                        if (!header.HeaderItems[i].Name.Equals(group.Items[group.Items.Count - header.HeaderItems.Count + i].Name))
937
                        {
938
                            found = false;
939
                            break;
940
                        }
941
                    }
942
                    if (found)
943
                    {
944
                        found = false;
945
                        List<Item> branches = new List<Item>();
946
                        //for (int i = 0; i < header.HeaderItems.Count; i++)
947
                        //{
948
                        //    if (group.Items[group.Items.Count - 1 - i].ItemType == ItemType.Line)
949
                        //    {
950

    
951
                        foreach (var _line in group.Items.Where(x => x.ItemType == ItemType.Line))
952
                        {
953
                            branches = Groups.Where(w => w != group).SelectMany(s => s.Items).Where(w => w.ItemType == ItemType.Line).Where(w => w.Relations[0].Item == _line || w.Relations[1].Item == _line).ToList();
954
                            if (branches.Count > 0)
955
                            {
956
                                found = true;
957
                                break;
958
                            }
959

    
960
                            if (found)
961
                                break;
962
                        }
963
                        //    }
964
                        //}
965

    
966
                        if (found)
967
                        {
968
                            for (int i = 0; i < header.HeaderItems.Count; i++)
969
                            {
970
                                group.Items[group.Items.Count - 1 - i].SubItemType = SubItemType.Header;
971
                            }
972
                        }
973
                    }
974
                }
975
            }
976

    
977
            #endregion
978

    
979
            int GetConnectedItemCount(Item item)
980
            {
981
                return item.Relations.FindAll(x => x.Item != null).Count;
982
            }
983

    
984
            List<Item> GetConnectedLines(Item item)
985
            {
986
                List<Item> result = new List<Item>();
987
                List<Item> end = new List<Item>();
988
                Stack<Item> stacks = new Stack<Item>();
989
                stacks.Push(item);
990
                while (stacks.Count > 0)
991
                {
992
                    Item stack = stacks.Pop();
993
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
994
                        continue;
995
                    end.Add(stack);
996

    
997
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
998
                    foreach (Relation relation in relations)
999
                        stacks.Push(relation.Item);
1000

    
1001
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
1002
                    foreach (Relation relation in relations)
1003
                    {
1004
                        result.Add(relation.Item);
1005
                        end.Add(relation.Item);
1006
                    }
1007
                }
1008

    
1009
                return result;
1010
            }
1011

    
1012
            List<Item> GetConnectedForwardLines(Item item)
1013
            {
1014
                List<Item> result = new List<Item>();
1015
                List<Item> end = new List<Item>();
1016
                Stack<Item> stacks = new Stack<Item>();
1017
                stacks.Push(item);
1018
                while (stacks.Count > 0)
1019
                {
1020
                    Item stack = stacks.Pop();
1021
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
1022
                        continue;
1023
                    end.Add(stack);
1024

    
1025
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1026
                    foreach (Relation relation in relations)
1027
                        stacks.Push(relation.Item);
1028

    
1029
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
1030
                    foreach (Relation relation in relations)
1031
                    {
1032
                        if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(0))
1033
                            result.Add(relation.Item);
1034

    
1035
                        end.Add(relation.Item);
1036
                    }
1037
                }
1038

    
1039
                return result;
1040
            }
1041

    
1042
            List<Item> GetConnectedBackwardLines(Item item)
1043
            {
1044
                List<Item> result = new List<Item>();
1045
                List<Item> end = new List<Item>();
1046
                Stack<Item> stacks = new Stack<Item>();
1047
                stacks.Push(item);
1048
                while (stacks.Count > 0)
1049
                {
1050
                    Item stack = stacks.Pop();
1051
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
1052
                        continue;
1053
                    end.Add(stack);
1054

    
1055
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1056
                    foreach (Relation relation in relations)
1057
                        stacks.Push(relation.Item);
1058

    
1059
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
1060
                    foreach (Relation relation in relations)
1061
                    {
1062
                        if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(1))
1063
                            result.Add(relation.Item);
1064

    
1065
                        end.Add(relation.Item);
1066
                    }
1067
                }
1068

    
1069
                return result;
1070
            }
1071

    
1072
            double InchToNumber(string inchString)
1073
            {
1074
                string[] inches = inchString.Replace("\"", "").Split('-');
1075
                double number = 0;
1076
                foreach (string inch in inches)
1077
                {
1078
                    if (!inch.Contains('/'))
1079
                    {
1080
                        number += Convert.ToDouble(inch);
1081
                    }
1082
                    else
1083
                    {
1084
                        string[] _inches = inch.Split('/');
1085
                        number += Convert.ToDouble(_inches[0]) / Convert.ToDouble(_inches[1]);
1086
                    }
1087
                }
1088

    
1089
                return number;
1090
            }
1091

    
1092
            Item GetConnectedMatchedSymbol(Item startItem, Item preItem, Item endItem)
1093
            {
1094
                List<Item> connItem = GetConnectedSymbols(startItem).Where(w => w != preItem).ToList();
1095
                if (connItem.Count != 0 && connItem[0] == endItem)
1096
                {
1097
                    return startItem;
1098
                }
1099
                else if (connItem.Count != 0)
1100
                {
1101
                    return GetConnectedMatchedSymbol(connItem[0], startItem, endItem);
1102
                }
1103

    
1104
                return null;
1105
            }
1106

    
1107
            Item GetConnectedMatchedLIne(Item startItem, Item preItem)
1108
            {
1109
                if (startItem.ItemType == ItemType.Line)
1110
                    return startItem;
1111

    
1112
                List<Item> connItem = GetConnectedLines(startItem).ToList();
1113
                if (connItem.Count != 0)
1114
                {
1115
                    return connItem[0];
1116
                }
1117
                else if (connItem.Count == 0)
1118
                {
1119
                    List<Item> _connItem = GetConnectedSymbols(startItem).Where(w => w != preItem).ToList();
1120
                    if (_connItem.Count == 0)
1121
                    {
1122
                        return GetConnectedMatchedLIne(_connItem[0], startItem);
1123
                    }
1124
                    return null;
1125
                }
1126

    
1127
                return null;
1128
            }
1129

    
1130
            List<Item> GetConnectedSymbols(Item item)
1131
            {
1132
                List<Item> result = new List<Item>();
1133
                List<Item> end = new List<Item>();
1134
                Stack<Item> stacks = new Stack<Item>();
1135
                stacks.Push(item);
1136
                while (stacks.Count > 0)
1137
                {
1138
                    Item stack = stacks.Pop();
1139
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
1140
                        continue;
1141
                    end.Add(stack);
1142
                    result.Add(stack);
1143
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1144
                    foreach (Relation relation in relations)
1145
                        stacks.Push(relation.Item);
1146
                }
1147

    
1148
                return result;
1149
            }
1150

    
1151
            void ChangeGroupID(string from, string to)
1152
            {
1153
                if (from.Equals(to))
1154
                    return;
1155

    
1156
                List<Item> changeItems = new List<Item>();
1157
                foreach (var _item in itemDic)
1158
                    if (_item.Value.Equals(from))
1159
                        changeItems.Add(_item.Key);
1160
                foreach (var _item in changeItems)
1161
                    itemDic[_item] = to;
1162
            }
1163

    
1164
            bool IsConnected(Item item1, Item item2)
1165
            {
1166
                if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null &&
1167
                    item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null)
1168
                    return true;
1169
                else
1170
                    return false;
1171
            }
1172

    
1173
            bool IsSameRun(Item item1, Item item2)
1174
            {
1175
                return RunInfos.Find(x => x.Items.Contains(item1) && x.Items.Contains(item2)) != null ? true : false;
1176
            }
1177

    
1178
            bool IsSameOwner(Item item1, Item item2)
1179
            {
1180
                return !string.IsNullOrEmpty(item1.Owner) && !string.IsNullOrEmpty(item2.Owner) && item1.Owner == item2.Owner ? true : false;
1181
            }
1182
        }
1183

    
1184

    
1185
        /* 구버전        
1186
        private void SetGroup()
1187
        {
1188
            List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList();
1189

    
1190
            Dictionary<Item, string> itemDic = new Dictionary<Item, string>();
1191
            foreach (Item item in orderItems)
1192
                itemDic.Add(item, Guid.NewGuid().ToString());
1193

    
1194
            foreach (Item item in orderItems)
1195
            {
1196
                string groupKey = itemDic[item];
1197
                if (item.ItemType == ItemType.Line)
1198
                {
1199
                    //if(item.Relations.Count() > 2)
1200
                    //{
1201
                    //    int i = 2;
1202
                    //    GroupingForwardLine(2);
1203
                    //    if(item.Relations.Count() >= 4)
1204
                    //        GroupingBackwardLine(3);
1205
                    //}
1206
                    GroupingForwardLine();
1207
                    GroupingBackwardLine();
1208
                }
1209

    
1210

    
1211
                void GroupingForwardLine(int i = 1)
1212
                {
1213
                    Item connItem = item.Relations[1].Item;
1214
                    if (connItem != null && IsConnected(connItem, item))
1215
                    {
1216
                        if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[0].Item))
1217
                            ChangeGroupID(itemDic[connItem], groupKey);
1218
                        else if (connItem.ItemType == ItemType.Symbol)
1219
                        {
1220
                            List<Item> allConnItems = GetConnectedLines(connItem);
1221
                            allConnItems.Remove(item);
1222
                            List<Item> connItems = GetConnectedForwardLines(connItem);
1223
                            if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0]))
1224
                            {
1225
                                List<Item> connSymbols = GetConnectedSymbols(connItem);
1226
                                foreach (Item loopItem in connSymbols)
1227
                                    ChangeGroupID(itemDic[loopItem], groupKey);
1228
                            }
1229
                            else
1230
                            {
1231
                                List<Item> endItems = new List<Item>();
1232
                                Stack<Item> stacks = new Stack<Item>();
1233
                                stacks.Push(connItem);
1234
                                while (stacks.Count > 0)
1235
                                {
1236
                                    Item stack = stacks.Pop();
1237
                                    if (endItems.Contains(stack))
1238
                                        continue;
1239
                                    endItems.Add(stack);
1240

    
1241
                                    if (GetConnectedItemCount(stack) < 3)
1242
                                    {
1243
                                        ChangeGroupID(itemDic[stack], groupKey);
1244
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1245
                                        foreach (Relation relation in relations)
1246
                                            stacks.Push(relation.Item);
1247
                                    }
1248
                                    else if (IsSameRun(item, stack))
1249
                                    {
1250
                                        ChangeGroupID(itemDic[stack], groupKey);
1251
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item));
1252
                                        foreach (Relation relation in relations)
1253
                                            stacks.Push(relation.Item);
1254
                                    }
1255
                                }
1256
                            }
1257
                        }
1258
                    }
1259
                }
1260
                void GroupingBackwardLine(int i = 0)
1261
                {
1262
                    Item connItem = item.Relations[0].Item;
1263
                    if (connItem != null && IsConnected(connItem, item))
1264
                    {
1265
                        if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[1].Item))
1266
                            ChangeGroupID(itemDic[connItem], groupKey);
1267
                        else if (connItem.ItemType == ItemType.Symbol)
1268
                        {
1269
                            List<Item> allConnItems = GetConnectedLines(connItem);
1270
                            allConnItems.Remove(item);
1271
                            List<Item> connItems = GetConnectedBackwardLines(connItem);
1272
                            if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0]))
1273
                            {
1274
                                List<Item> connSymbols = GetConnectedSymbols(connItem);
1275
                                foreach (Item loopItem in connSymbols)
1276
                                    ChangeGroupID(itemDic[loopItem], groupKey);
1277
                            }
1278
                            else
1279
                            {
1280
                                List<Item> endItems = new List<Item>();
1281
                                Stack<Item> stacks = new Stack<Item>();
1282
                                stacks.Push(connItem);
1283
                                while (stacks.Count > 0)
1284
                                {
1285
                                    Item stack = stacks.Pop();
1286
                                    if (endItems.Contains(stack))
1287
                                        continue;
1288
                                    endItems.Add(stack);
1289

    
1290
                                    if (GetConnectedItemCount(stack) < 3)
1291
                                    {
1292
                                        ChangeGroupID(itemDic[stack], groupKey);
1293
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1294
                                        foreach (Relation relation in relations)
1295
                                            stacks.Push(relation.Item);
1296
                                    }
1297
                                    else if (IsSameRun(item, stack))
1298
                                    {
1299
                                        ChangeGroupID(itemDic[stack], groupKey);
1300
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item));
1301
                                        foreach (Relation relation in relations)
1302
                                            stacks.Push(relation.Item);
1303
                                    }
1304
                                }
1305
                            }
1306
                        }
1307
                    }
1308
                }
1309
            }
1310

    
1311
            List<string> endGroupIds = new List<string>();
1312
            foreach (var item in itemDic)
1313
            {
1314
                if (endGroupIds.Contains(item.Value))
1315
                    continue;
1316
                endGroupIds.Add(item.Value);
1317

    
1318
                List<Item> groupItems = itemDic.Where(x => x.Value.Equals(item.Value)).Select(x => x.Key).ToList();
1319
                if (groupItems.Find(x => x.ItemType == ItemType.Line) == null)
1320
                {
1321
                    foreach (var groupItem in groupItems)
1322
                        Items.Remove(groupItem);
1323
                }
1324
                else
1325
                {
1326
                    Group group = new Group(this);
1327
                    group.Items = groupItems;
1328
                    group.UID = item.Value;
1329
                    group.SortItems();
1330
                    foreach (Item groupItem in groupItems)
1331
                        groupItem.Group = group;
1332
                    Groups.Add(group);
1333
                }
1334
            }
1335

    
1336
            #region HeaderSetting
1337
            List<HeaderInfo> HeaderInfos = new List<HeaderInfo>();
1338
            DataTable dt = DB.SelectHeaderSetting();
1339
            foreach (DataRow row in dt.Rows)
1340
            {
1341
                string groupID = row["GROUP_ID"].ToString();
1342
                string desc = row["DESCRIPTION"].ToString();
1343
                int index = Convert.ToInt32(row["INDEX"]);
1344
                string name = row["NAME"].ToString();
1345

    
1346
                HeaderInfo headerInfo = HeaderInfos.Find(x => x.UID.Equals(groupID));
1347
                if (headerInfo == null)
1348
                {
1349
                    headerInfo = new HeaderInfo(groupID);
1350
                    headerInfo.Description = desc;
1351
                    HeaderInfos.Add(headerInfo);
1352
                }
1353

    
1354

    
1355
                headerInfo.HeaderItems.Add(new HeaderItem()
1356
                {
1357
                    Index = index,
1358
                    Name = name
1359
                });
1360
            }
1361

    
1362

    
1363
            foreach (HeaderInfo headerInfo in HeaderInfos)
1364
                headerInfo.HeaderItems = headerInfo.HeaderItems.OrderByDescending(x => x.Index).ToList();
1365

    
1366
            foreach (Group group in Groups)
1367
            {
1368
                foreach (HeaderInfo header in HeaderInfos)
1369
                {
1370
                    if (group.Items.Count < header.HeaderItems.Count)
1371
                    {
1372
                        continue;
1373
                    }
1374

    
1375
                    bool found = true;
1376
                    for (int i = 0; i < header.HeaderItems.Count; i++)
1377
                    {
1378
                        if (!header.HeaderItems[header.HeaderItems.Count - 1 - i].Name.Equals(group.Items[i].Name))
1379
                        {
1380
                            found = false;
1381
                            break;
1382
                        }
1383
                    }
1384
                    if (found)
1385
                    {
1386
                        found = false;
1387
                        List<Item> branches = new List<Item>();
1388
                        //for (int i = 0; i < header.HeaderItems.Count; i++)
1389
                        //{
1390
                        //    if (group.Items[i].ItemType == ItemType.Line)
1391
                        //    {
1392
                                foreach(var _line in group.Items.Where(x=>x.ItemType == ItemType.Line))
1393
                                {
1394
                                    branches = Groups.Where(w => w != group).SelectMany(s => s.Items).Where(w => w.ItemType == ItemType.Line).Where(w => w.Relations[0].Item == _line || w.Relations[1].Item == _line).ToList();
1395
                                    if (branches.Count > 0)
1396
                                    {
1397
                                        found = true;
1398
                                        break;
1399
                                    }
1400

    
1401
                                    if (found)
1402
                                        break;
1403
                                }                                
1404
                        //    }
1405
                        //}
1406

    
1407
                        if (found)
1408
                        {
1409
                            for (int i = 0; i < header.HeaderItems.Count; i++)
1410
                            {
1411
                                group.Items[i].SubItemType = SubItemType.Header;
1412
                            }
1413
                        }
1414
                    }
1415

    
1416
                    found = true;
1417
                    for (int i = 0; i < header.HeaderItems.Count; i++)
1418
                    {
1419
                        if (!header.HeaderItems[i].Name.Equals(group.Items[group.Items.Count - header.HeaderItems.Count + i].Name))
1420
                        {
1421
                            found = false;
1422
                            break;
1423
                        }
1424
                    }
1425
                    if (found)
1426
                    {
1427
                        found = false;
1428
                        List<Item> branches = new List<Item>();
1429
                        //for (int i = 0; i < header.HeaderItems.Count; i++)
1430
                        //{
1431
                        //    if (group.Items[group.Items.Count - 1 - i].ItemType == ItemType.Line)
1432
                        //    {
1433

    
1434
                                foreach (var _line in group.Items.Where(x => x.ItemType == ItemType.Line))
1435
                                {
1436
                                    branches = Groups.Where(w => w != group).SelectMany(s => s.Items).Where(w => w.ItemType == ItemType.Line).Where(w => w.Relations[0].Item == _line || w.Relations[1].Item == _line).ToList();
1437
                                    if (branches.Count > 0)
1438
                                    {
1439
                                        found = true;
1440
                                        break;
1441
                                    }
1442

    
1443
                                    if (found)
1444
                                        break;
1445
                                }                                
1446
                        //    }
1447
                        //}
1448

    
1449
                        if (found)
1450
                        {
1451
                            for (int i = 0; i < header.HeaderItems.Count; i++)
1452
                            {
1453
                                group.Items[group.Items.Count - 1 - i].SubItemType = SubItemType.Header;
1454
                            }
1455
                        }
1456
                    }
1457
                }
1458
            }
1459

    
1460
            #endregion
1461

    
1462
            //#region HeaderSetting
1463
            //List<HeaderInfo> HeaderInfos = new List<HeaderInfo>();
1464
            //DataTable dt = DB.SelectHeaderSetting();
1465
            //foreach (DataRow row in dt.Rows)
1466
            //{
1467
            //    string groupID = row["GROUP_ID"].ToString();
1468
            //    string desc = row["DESCRIPTION"].ToString();
1469
            //    int index = Convert.ToInt32(row["INDEX"]);
1470
            //    string name = row["NAME"].ToString();
1471

    
1472
            //    HeaderInfo headerInfo = HeaderInfos.Find(x => x.UID.Equals(groupID));
1473
            //    if (headerInfo == null)
1474
            //    {
1475
            //        headerInfo = new HeaderInfo(groupID);
1476
            //        headerInfo.Description = desc;
1477
            //        HeaderInfos.Add(headerInfo);
1478
            //    }
1479

    
1480
            //    headerInfo.HeaderItems.Add(new HeaderItem()
1481
            //    {
1482
            //        Index = index,
1483
            //        Name = name
1484
            //    });
1485
            //}
1486
            //foreach (HeaderInfo headerInfo in HeaderInfos)
1487
            //    headerInfo.HeaderItems = headerInfo.HeaderItems.OrderBy(x => x.Index).ToList();
1488

    
1489
            //foreach (Group group in Groups)
1490
            //{
1491
            //    List<HeaderInfo> endInfos = new List<HeaderInfo>();
1492
            //    bool bFind = false;
1493
            //    for (int i = 0; i < group.Items.Count; i++)
1494
            //    {
1495
            //        Item item = group.Items[i];
1496
            //        foreach (HeaderInfo header in HeaderInfos)
1497
            //        {
1498
            //            if (endInfos.Contains(header))
1499
            //                continue;
1500

    
1501
            //            if (!header.HeaderItems[i].Name.Equals(item.Name))
1502
            //            {
1503
            //                endInfos.Add(header);
1504
            //                continue;
1505
            //            }
1506

    
1507
            //            if (header.HeaderItems.Count.Equals(i + 1))
1508
            //            {
1509
            //                for (int j = 0; j < i + 1; j++)
1510
            //                    group.Items[j].SubItemType = SubItemType.Header;
1511
            //                bFind = true;
1512
            //                break;
1513
            //            }
1514
            //        }
1515

    
1516
            //        if (bFind || endInfos.Count.Equals(HeaderInfos.Count))
1517
            //            break;
1518
            //    }
1519

    
1520
            //    endInfos = new List<HeaderInfo>();
1521
            //    bFind = false;
1522
            //    for (int i = 0; i < group.Items.Count; i++)
1523
            //    {
1524
            //        Item item = group.Items[group.Items.Count - i - 1];
1525
            //        foreach (HeaderInfo header in HeaderInfos)
1526
            //        {
1527
            //            if (endInfos.Contains(header))
1528
            //                continue;
1529

    
1530
            //            if (!header.HeaderItems[i].Name.Equals(item.Name))
1531
            //            {
1532
            //                endInfos.Add(header);
1533
            //                continue;
1534
            //            }
1535

    
1536
            //            if (header.HeaderItems.Count.Equals(i + 1))
1537
            //            {
1538
            //                for (int j = 0; j < i + 1; j++)
1539
            //                    group.Items[group.Items.Count - j - 1].SubItemType = SubItemType.Header;
1540
            //                bFind = true;
1541
            //                break;
1542
            //            }
1543
            //        }
1544

    
1545
            //        if (bFind || endInfos.Count.Equals(HeaderInfos.Count))
1546
            //            break;
1547
            //    }
1548
            //}
1549
            //#endregion
1550

    
1551
            //#region KeywordSetting
1552
            ////List<KeywordInfo> KeywordInfos = new List<KeywordInfo>();
1553
            //DataTable dtKeyword = DB.SelectKeywordsSetting();
1554
            //KeywordInfo KeywordInfos = new KeywordInfo();
1555

    
1556
            //foreach (DataRow row in dtKeyword.Rows)
1557
            //{
1558
            //    int index = Convert.ToInt32(row["INDEX"]);
1559
            //    string name = row["NAME"].ToString();
1560
            //    string keyword = row["KEYWORD"].ToString();
1561

    
1562
            //    KeywordInfos.KeywordItems.Add(new KeywordItem()
1563
            //    {
1564
            //        Index = index,
1565
            //        Name = name,
1566
            //        Keyword = keyword
1567
            //    });
1568
            //}
1569

    
1570
            //KeywordInfos.KeywordItems = KeywordInfos.KeywordItems.OrderBy(x => x.Index).ToList();
1571

    
1572
            //foreach (Group group in Groups)
1573
            //{
1574
            //    //List<KeywordItem> endInfos = new List<KeywordItem>();
1575
            //    bool bFind = false;
1576
            //    for (int i = 0; i < group.Items.Count; i++)
1577
            //    {
1578
            //        Item item = group.Items[i];
1579
            //        foreach (KeywordItem keyword in KeywordInfos.KeywordItems)
1580
            //        {
1581
            //            if (endInfos.Contains(keyword))
1582
            //                continue;
1583

    
1584
            //            if (!keyword.Name.Equals(item.Name))
1585
            //            {
1586
            //                endInfos.Add(keyword);
1587
            //                continue;
1588
            //            }
1589

    
1590
            //            if (KeywordInfos.KeywordItems.Count.Equals(i + 1))
1591
            //            {
1592
            //                for (int j = 0; j < i + 1; j++)
1593
            //                    group.Items[j].Keyword = keyword.Keyword;
1594
            //                bFind = true;
1595
            //                break;
1596
            //            }
1597
            //        }
1598

    
1599
            //        if (bFind || endInfos.Count.Equals(KeywordInfos.KeywordItems.Count))
1600
            //            break;
1601
            //    }
1602

    
1603
            //    endInfos = new List<KeywordItem>();
1604
            //    bFind = false;
1605
            //    for (int i = 0; i < group.Items.Count; i++)
1606
            //    {
1607
            //        Item item = group.Items[group.Items.Count - i - 1];
1608
            //        foreach (KeywordItem keyword in KeywordInfos.KeywordItems)
1609
            //        {
1610
            //            if (endInfos.Contains(keyword))
1611
            //                continue;
1612

    
1613
            //            if (!keyword.Name.Equals(item.Name))
1614
            //            {
1615
            //                endInfos.Add(keyword);
1616
            //                continue;
1617
            //            }
1618

    
1619
            //            if (KeywordInfos.KeywordItems.Count.Equals(i + 1))
1620
            //            {
1621
            //                for (int j = 0; j < i + 1; j++)
1622
            //                    group.Items[group.Items.Count - j - 1].Keyword = keyword.Keyword;
1623
            //                bFind = true;
1624
            //                break;
1625
            //            }
1626
            //        }
1627

    
1628
            //        if (bFind || endInfos.Count.Equals(KeywordInfos.KeywordItems.Count))
1629
            //            break;
1630
            //    }
1631
            //}
1632
            //#endregion
1633

    
1634
            int GetConnectedItemCount(Item item)
1635
            {
1636
                return item.Relations.FindAll(x => x.Item != null).Count;
1637
            }
1638

    
1639
            List<Item> GetConnectedLines(Item item)
1640
            {
1641
                List<Item> result = new List<Item>();
1642
                List<Item> end = new List<Item>();
1643
                Stack<Item> stacks = new Stack<Item>();
1644
                stacks.Push(item);
1645
                while (stacks.Count > 0)
1646
                {
1647
                    Item stack = stacks.Pop();
1648
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
1649
                        continue;
1650
                    end.Add(stack);
1651

    
1652
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1653
                    foreach (Relation relation in relations)
1654
                        stacks.Push(relation.Item);
1655

    
1656
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
1657
                    foreach (Relation relation in relations)
1658
                    {
1659
                        result.Add(relation.Item);
1660
                        end.Add(relation.Item);
1661
                    }
1662
                }
1663

    
1664
                return result;
1665
            }
1666

    
1667
            List<Item> GetConnectedForwardLines(Item item)
1668
            {
1669
                List<Item> result = new List<Item>();
1670
                List<Item> end = new List<Item>();
1671
                Stack<Item> stacks = new Stack<Item>();
1672
                stacks.Push(item);
1673
                while (stacks.Count > 0)
1674
                {
1675
                    Item stack = stacks.Pop();
1676
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
1677
                        continue;
1678
                    end.Add(stack);
1679

    
1680
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1681
                    foreach (Relation relation in relations)
1682
                        stacks.Push(relation.Item);
1683

    
1684
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
1685
                    foreach (Relation relation in relations)
1686
                    {
1687
                        if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(0))
1688
                            result.Add(relation.Item);
1689

    
1690
                        end.Add(relation.Item);
1691
                    }
1692
                }
1693

    
1694
                return result;
1695
            }
1696

    
1697
            List<Item> GetConnectedBackwardLines(Item item)
1698
            {
1699
                List<Item> result = new List<Item>();
1700
                List<Item> end = new List<Item>();
1701
                Stack<Item> stacks = new Stack<Item>();
1702
                stacks.Push(item);
1703
                while (stacks.Count > 0)
1704
                {
1705
                    Item stack = stacks.Pop();
1706
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
1707
                        continue;
1708
                    end.Add(stack);
1709

    
1710
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1711
                    foreach (Relation relation in relations)
1712
                        stacks.Push(relation.Item);
1713

    
1714
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
1715
                    foreach (Relation relation in relations)
1716
                    {
1717
                        if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(1))
1718
                            result.Add(relation.Item);
1719

    
1720
                        end.Add(relation.Item);
1721
                    }
1722
                }
1723

    
1724
                return result;
1725
            }
1726

    
1727
            List<Item> GetConnectedSymbols(Item item)
1728
            {
1729
                List<Item> result = new List<Item>();
1730
                List<Item> end = new List<Item>();
1731
                Stack<Item> stacks = new Stack<Item>();
1732
                stacks.Push(item);
1733
                while (stacks.Count > 0)
1734
                {
1735
                    Item stack = stacks.Pop();
1736
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
1737
                        continue;
1738
                    end.Add(stack);
1739
                    result.Add(stack);
1740
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
1741
                    foreach (Relation relation in relations)
1742
                        stacks.Push(relation.Item);
1743
                }
1744

    
1745
                return result;
1746
            }
1747

    
1748
            void ChangeGroupID(string from, string to)
1749
            {
1750
                if (from.Equals(to))
1751
                    return;
1752

    
1753
                List<Item> changeItems = new List<Item>();
1754
                foreach (var _item in itemDic)
1755
                    if (_item.Value.Equals(from))
1756
                        changeItems.Add(_item.Key);
1757
                foreach (var _item in changeItems)
1758
                    itemDic[_item] = to;
1759
            }
1760

    
1761
            bool IsConnected(Item item1, Item item2)
1762
            {
1763
                if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null &&
1764
                    item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null)
1765
                    return true;
1766
                else
1767
                    return false;
1768
            }
1769

    
1770
            bool IsSameRun(Item item1, Item item2)
1771
            {
1772
                return RunInfos.Find(x => x.Items.Contains(item1) && x.Items.Contains(item2)) != null ? true : false;
1773
            }
1774
        }
1775

    
1776
        */
1777

    
1778
        private double StringToNumber(string inchString)
1779
        {
1780
            double number = 0;
1781

    
1782
            if (string.IsNullOrEmpty(inchString) || inchString == "None")
1783
                return 0;
1784

    
1785
            try
1786
            {
1787
                string[] inches = inchString.Replace("\"", "").Split('-');
1788
                foreach (string inch in inches)
1789
                {
1790
                    if (!inch.Contains('/'))
1791
                    {
1792
                        number += Convert.ToDouble(inch);
1793
                    }
1794
                    else
1795
                    {
1796
                        string[] _inches = inch.Split('/');
1797
                        number += Convert.ToDouble(_inches[0]) / Convert.ToDouble(_inches[1]);
1798
                    }
1799
                }
1800
            }
1801
            catch (Exception ex)
1802
            {
1803
                return 0;
1804
            }
1805

    
1806
            return number;
1807
        }
1808

    
1809
        private void RemoveItems()
1810
        {
1811
            List<Item> removeItems = new List<Item>();
1812
            foreach (var item in Items)
1813
            {
1814
                if (item.ItemType == ItemType.Line && (item.Name != "Secondary" && item.Name != "Primary"))
1815
                {
1816
                    List<Relation> relations = item.Relations.FindAll(x => x.Item != null);
1817
                    foreach (Relation relation in relations)
1818
                    {
1819
                        Relation otherRelation = Items.Find(x => x.UID == relation.UID).Relations.Find(x => x.UID == item.UID);
1820
                        if (otherRelation != null)
1821
                        {
1822
                            otherRelation.Item = null;
1823
                            otherRelation.UID = string.Empty;
1824
                        }
1825
                    }
1826

    
1827
                    removeItems.Add(item);
1828
                }
1829
            }
1830

    
1831
            foreach (var item in removeItems)
1832
            {
1833
                Items.Remove(item);
1834
            }
1835
        }
1836
        
1837
        private void InsertNozzle()
1838
        {
1839
            List<Item> newNozzles = new List<Item>();
1840
            foreach (var item in Items)
1841
            {
1842
                if (item.SubItemType == SubItemType.Nozzle)
1843
                    continue;
1844
                
1845
                foreach (Relation relation in item.Relations)
1846
                {
1847
                    Equipment equipment = Equipments.Find(x => x.UID == relation.UID);
1848
                    if (equipment != null)
1849
                    {
1850
                        Item newNozzle = new Item();
1851
                        newNozzle.UID = Guid.NewGuid().ToString();
1852
                        newNozzle.Name = "PSN_Nozzle";
1853
                        newNozzle.ID2DBType = "Nozzles";
1854
                        newNozzle.Owner = item.Owner;
1855
                        newNozzle.ID2DBName = "PSN_Nozzle";
1856
                        newNozzle.POINT = relation.Point;
1857
                        newNozzle.Relations = new List<Relation>();
1858

    
1859
                        newNozzle.Relations.Add(new Relation()
1860
                        {
1861
                            Point = relation.Point,
1862
                            UID = equipment.UID
1863
                        });
1864
                        newNozzle.Relations.Add(new Relation()
1865
                        {
1866
                            Point = relation.Point,
1867
                            UID = item.UID
1868
                        });
1869

    
1870
                        newNozzle.ItemType = ItemType.Symbol;
1871
                        newNozzle.SubItemType = SubItemType.Nozzle;
1872

    
1873
                        newNozzles.Add(newNozzle);
1874

    
1875
                        relation.UID = newNozzle.UID;
1876
                    }
1877
                }
1878
            }
1879

    
1880
            Items.AddRange(newNozzles);
1881
        }
1882
    }
1883
}
클립보드 이미지 추가 (최대 크기: 500 MB)