프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / ID2PSN / Document.cs @ 2ada3be8

이력 | 보기 | 이력해설 | 다운로드 (29.1 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

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

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

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

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

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

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

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

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

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

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

    
180
            return result;
181
        }
182
        private List<Attribute> GetAttributes(XElement element)
183
        {
184
            List<Attribute> result = new List<Attribute>();
185
            foreach (XElement item in element.Elements("ATTRIBUTE"))
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
        private void SetGroup()
243
        {
244
            List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList();
245

    
246
            Dictionary<Item, string> itemDic = new Dictionary<Item, string>();
247
            foreach (Item item in orderItems)
248
                itemDic.Add(item, Guid.NewGuid().ToString());
249

    
250
            foreach (Item item in orderItems)
251
            {
252
                string groupKey = itemDic[item];
253
                if (item.ItemType == ItemType.Line)
254
                {
255
                    GroupingForwardLine();
256
                    GroupingBackwardLine();
257
                }
258

    
259
                void GroupingForwardLine()
260
                {
261
                    Item connItem = item.Relations[1].Item;
262
                    if (connItem != null && IsConnected(connItem, item))
263
                    {
264
                        if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[0].Item))
265
                            ChangeGroupID(itemDic[connItem], groupKey);
266
                        else if (connItem.ItemType == ItemType.Symbol)
267
                        {
268
                            List<Item> allConnItems = GetConnectedLines(connItem);
269
                            allConnItems.Remove(item);
270
                            List<Item> connItems = GetConnectedForwardLines(connItem);
271
                            if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0]))
272
                            {
273
                                List<Item> connSymbols = GetConnectedSymbols(connItem);
274
                                foreach (Item loopItem in connSymbols)
275
                                    ChangeGroupID(itemDic[loopItem], groupKey);
276
                            }
277
                            else
278
                            {
279
                                List<Item> endItems = new List<Item>();
280
                                Stack<Item> stacks = new Stack<Item>();
281
                                stacks.Push(connItem);
282
                                while (stacks.Count > 0)
283
                                {
284
                                    Item stack = stacks.Pop();
285
                                    if (endItems.Contains(stack))
286
                                        continue;
287
                                    endItems.Add(stack);
288

    
289
                                    if (GetConnectedItemCount(stack) < 3)
290
                                    {
291
                                        ChangeGroupID(itemDic[stack], groupKey);
292
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
293
                                        foreach (Relation relation in relations)
294
                                            stacks.Push(relation.Item);
295
                                    }
296
                                    else if (IsSameRun(item, stack))
297
                                    {
298
                                        ChangeGroupID(itemDic[stack], groupKey);
299
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item));
300
                                        foreach (Relation relation in relations)
301
                                            stacks.Push(relation.Item);
302
                                    }
303
                                }
304
                            }
305
                        }
306
                    }
307
                }
308
                void GroupingBackwardLine()
309
                {
310
                    Item connItem = item.Relations[0].Item;
311
                    if (connItem != null && IsConnected(connItem, item))
312
                    {
313
                        if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[1].Item))
314
                            ChangeGroupID(itemDic[connItem], groupKey);
315
                        else if (connItem.ItemType == ItemType.Symbol)
316
                        {
317
                            List<Item> allConnItems = GetConnectedLines(connItem);
318
                            allConnItems.Remove(item);
319
                            List<Item> connItems = GetConnectedBackwardLines(connItem);
320
                            if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0]))
321
                            {
322
                                List<Item> connSymbols = GetConnectedSymbols(connItem);
323
                                foreach (Item loopItem in connSymbols)
324
                                    ChangeGroupID(itemDic[loopItem], groupKey);
325
                            }
326
                            else
327
                            {
328
                                List<Item> endItems = new List<Item>();
329
                                Stack<Item> stacks = new Stack<Item>();
330
                                stacks.Push(connItem);
331
                                while (stacks.Count > 0)
332
                                {
333
                                    Item stack = stacks.Pop();
334
                                    if (endItems.Contains(stack))
335
                                        continue;
336
                                    endItems.Add(stack);
337

    
338
                                    if (GetConnectedItemCount(stack) < 3)
339
                                    {
340
                                        ChangeGroupID(itemDic[stack], groupKey);
341
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
342
                                        foreach (Relation relation in relations)
343
                                            stacks.Push(relation.Item);
344
                                    }
345
                                    else if (IsSameRun(item, stack))
346
                                    {
347
                                        ChangeGroupID(itemDic[stack], groupKey);
348
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item));
349
                                        foreach (Relation relation in relations)
350
                                            stacks.Push(relation.Item);
351
                                    }
352
                                }
353
                            }
354
                        }
355
                    }
356
                }
357
            }
358

    
359
            List<string> endGroupIds = new List<string>();
360
            foreach (var item in itemDic)
361
            {
362
                if (endGroupIds.Contains(item.Value))
363
                    continue;
364
                endGroupIds.Add(item.Value);
365

    
366
                List<Item> groupItems = itemDic.Where(x => x.Value.Equals(item.Value)).Select(x => x.Key).ToList();
367
                if (groupItems.Find(x => x.ItemType == ItemType.Line) == null)
368
                {
369
                    foreach (var groupItem in groupItems)
370
                        Items.Remove(groupItem);
371
                }
372
                else
373
                {
374
                    Group group = new Group(this);
375
                    group.Items = groupItems;
376
                    group.UID = item.Value;
377
                    group.SortItems();
378
                    foreach (Item groupItem in groupItems)
379
                        groupItem.Group = group;
380
                    Groups.Add(group);
381
                }
382
            }
383

    
384
            #region HeaderSetting
385
            List<HeaderInfo> HeaderInfos = new List<HeaderInfo>();
386
            DataTable dt = DB.SelectHeaderSetting();
387
            foreach (DataRow row in dt.Rows)
388
            {
389
                string groupID = row["GROUP_ID"].ToString();
390
                string desc = row["DESCRIPTION"].ToString();
391
                int index = Convert.ToInt32(row["INDEX"]);
392
                string name = row["NAME"].ToString();
393

    
394
                HeaderInfo headerInfo = HeaderInfos.Find(x => x.UID.Equals(groupID));
395
                if (headerInfo == null)
396
                {
397
                    headerInfo = new HeaderInfo(groupID);
398
                    headerInfo.Description = desc;
399
                    HeaderInfos.Add(headerInfo);
400
                }
401

    
402
                headerInfo.HeaderItems.Add(new HeaderItem()
403
                {
404
                    Index = index,
405
                    Name = name
406
                });
407
            }
408
            foreach (HeaderInfo headerInfo in HeaderInfos)
409
                headerInfo.HeaderItems = headerInfo.HeaderItems.OrderBy(x => x.Index).ToList();
410

    
411
            foreach (Group group in Groups)
412
            {
413
                List<HeaderInfo> endInfos = new List<HeaderInfo>();
414
                bool bFind = false;
415
                for (int i = 0; i < group.Items.Count; i++)
416
                {
417
                    Item item = group.Items[i];
418
                    foreach (HeaderInfo header in HeaderInfos)
419
                    {
420
                        if (endInfos.Contains(header))
421
                            continue;
422

    
423
                        if (!header.HeaderItems[i].Name.Equals(item.Name))
424
                        {
425
                            endInfos.Add(header);
426
                            continue;
427
                        }
428

    
429
                        if (header.HeaderItems.Count.Equals(i + 1))
430
                        {
431
                            for (int j = 0; j < i + 1; j++)
432
                                group.Items[j].SubItemType = SubItemType.Header;
433
                            bFind = true;
434
                            break;
435
                        }
436
                    }
437

    
438
                    if (bFind || endInfos.Count.Equals(HeaderInfos.Count))
439
                        break;
440
                }
441

    
442
                endInfos = new List<HeaderInfo>();
443
                bFind = false;
444
                for (int i = 0; i < group.Items.Count; i++)
445
                {
446
                    Item item = group.Items[group.Items.Count - i - 1];
447
                    foreach (HeaderInfo header in HeaderInfos)
448
                    {
449
                        if (endInfos.Contains(header))
450
                            continue;
451

    
452
                        if (!header.HeaderItems[i].Name.Equals(item.Name))
453
                        {
454
                            endInfos.Add(header);
455
                            continue;
456
                        }
457

    
458
                        if (header.HeaderItems.Count.Equals(i + 1))
459
                        {
460
                            for (int j = 0; j < i + 1; j++)
461
                                group.Items[group.Items.Count - j - 1].SubItemType = SubItemType.Header;
462
                            bFind = true;
463
                            break;
464
                        }
465
                    }
466

    
467
                    if (bFind || endInfos.Count.Equals(HeaderInfos.Count))
468
                        break;
469
                }
470
            }
471
            #endregion
472

    
473
            int GetConnectedItemCount(Item item)
474
            {
475
                return item.Relations.FindAll(x => x.Item != null).Count;
476
            }
477

    
478
            List<Item> GetConnectedLines(Item item)
479
            {
480
                List<Item> result = new List<Item>();
481
                List<Item> end = new List<Item>();
482
                Stack<Item> stacks = new Stack<Item>();
483
                stacks.Push(item);
484
                while (stacks.Count > 0)
485
                {
486
                    Item stack = stacks.Pop();
487
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
488
                        continue;
489
                    end.Add(stack);
490

    
491
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
492
                    foreach (Relation relation in relations)
493
                        stacks.Push(relation.Item);
494

    
495
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
496
                    foreach (Relation relation in relations)
497
                    {
498
                        result.Add(relation.Item);
499
                        end.Add(relation.Item);
500
                    }
501
                }
502

    
503
                return result;
504
            }
505

    
506
            List<Item> GetConnectedForwardLines(Item item)
507
            {
508
                List<Item> result = new List<Item>();
509
                List<Item> end = new List<Item>();
510
                Stack<Item> stacks = new Stack<Item>();
511
                stacks.Push(item);
512
                while (stacks.Count > 0)
513
                {
514
                    Item stack = stacks.Pop();
515
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
516
                        continue;
517
                    end.Add(stack);
518

    
519
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
520
                    foreach (Relation relation in relations)
521
                        stacks.Push(relation.Item);
522

    
523
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
524
                    foreach (Relation relation in relations)
525
                    {
526
                        if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(0))
527
                            result.Add(relation.Item);
528

    
529
                        end.Add(relation.Item);
530
                    }
531
                }
532

    
533
                return result;
534
            }
535

    
536
            List<Item> GetConnectedBackwardLines(Item item)
537
            {
538
                List<Item> result = new List<Item>();
539
                List<Item> end = new List<Item>();
540
                Stack<Item> stacks = new Stack<Item>();
541
                stacks.Push(item);
542
                while (stacks.Count > 0)
543
                {
544
                    Item stack = stacks.Pop();
545
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
546
                        continue;
547
                    end.Add(stack);
548

    
549
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
550
                    foreach (Relation relation in relations)
551
                        stacks.Push(relation.Item);
552

    
553
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
554
                    foreach (Relation relation in relations)
555
                    {
556
                        if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(1))
557
                            result.Add(relation.Item);
558

    
559
                        end.Add(relation.Item);
560
                    }
561
                }
562

    
563
                return result;
564
            }
565

    
566
            List<Item> GetConnectedSymbols(Item item)
567
            {
568
                List<Item> result = new List<Item>();
569
                List<Item> end = new List<Item>();
570
                Stack<Item> stacks = new Stack<Item>();
571
                stacks.Push(item);
572
                while (stacks.Count > 0)
573
                {
574
                    Item stack = stacks.Pop();
575
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
576
                        continue;
577
                    end.Add(stack);
578
                    result.Add(stack);
579
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
580
                    foreach (Relation relation in relations)
581
                        stacks.Push(relation.Item);
582
                }
583

    
584
                return result;
585
            }
586

    
587
            void ChangeGroupID(string from, string to)
588
            {
589
                if (from.Equals(to))
590
                    return;
591

    
592
                List<Item> changeItems = new List<Item>();
593
                foreach (var _item in itemDic)
594
                    if (_item.Value.Equals(from))
595
                        changeItems.Add(_item.Key);
596
                foreach (var _item in changeItems)
597
                    itemDic[_item] = to;
598
            }
599

    
600
            bool IsConnected(Item item1, Item item2)
601
            {
602
                if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null &&
603
                    item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null)
604
                    return true;
605
                else
606
                    return false;
607
            }
608

    
609
            bool IsSameRun(Item item1, Item item2)
610
            {
611
                return RunInfos.Find(x => x.Items.Contains(item1) && x.Items.Contains(item2)) != null ? true : false;
612
            }
613
        }
614
        private void RemoveItems()
615
        {
616
            List<Item> removeItems = new List<Item>();
617
            foreach (var item in Items)
618
            {
619
                if (item.ItemType == ItemType.Line && (item.Name != "Secondary" && item.Name != "Primary"))
620
                {
621
                    List<Relation> relations = item.Relations.FindAll(x => x.Item != null);
622
                    foreach (Relation relation in relations)
623
                    {
624
                        Relation otherRelation = Items.Find(x => x.UID == relation.UID).Relations.Find(x => x.UID == item.UID);
625
                        if (otherRelation != null)
626
                        {
627
                            otherRelation.Item = null;
628
                            otherRelation.UID = string.Empty;
629
                        }
630
                    }
631

    
632
                    removeItems.Add(item);
633
                }
634
            }
635

    
636
            foreach (var item in removeItems)
637
            {
638
                Items.Remove(item);
639
            }
640
        }
641
        
642
        private void InsertNozzle()
643
        {
644
            List<Item> newNozzles = new List<Item>();
645
            foreach (var item in Items)
646
            {
647
                if (item.SubItemType == SubItemType.Nozzle)
648
                    continue;
649
                
650
                foreach (Relation relation in item.Relations)
651
                {
652
                    Equipment equipment = Equipments.Find(x => x.UID == relation.UID);
653
                    if (equipment != null)
654
                    {
655
                        Item newNozzle = new Item();
656
                        newNozzle.UID = Guid.NewGuid().ToString();
657
                        newNozzle.Name = "PSN_Nozzle";
658
                        newNozzle.ID2DBType = "Nozzles";
659
                        newNozzle.Owner = item.Owner;
660
                        newNozzle.ID2DBName = "PSN_Nozzle";
661
                        newNozzle.POINT = relation.Point;
662
                        newNozzle.Relations = new List<Relation>();
663

    
664
                        newNozzle.Relations.Add(new Relation()
665
                        {
666
                            Point = relation.Point,
667
                            UID = equipment.UID
668
                        });
669
                        newNozzle.Relations.Add(new Relation()
670
                        {
671
                            Point = relation.Point,
672
                            UID = item.UID
673
                        });
674

    
675
                        newNozzle.ItemType = ItemType.Symbol;
676
                        newNozzle.SubItemType = SubItemType.Nozzle;
677

    
678
                        newNozzles.Add(newNozzle);
679

    
680
                        relation.UID = newNozzle.UID;
681
                    }
682
                }
683
            }
684

    
685
            Items.AddRange(newNozzles);
686
        }
687
    }
688
}
클립보드 이미지 추가 (최대 크기: 500 MB)