프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / Document.cs @ 7d6d1693

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

1 6b9e7a56 gaqhf
using DevExpress.Utils.StructuredStorage.Internal.Reader;
2
using System;
3 0dae5645 gaqhf
using System.Collections.Generic;
4 6b9e7a56 gaqhf
using System.Data;
5 0dae5645 gaqhf
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 6b9e7a56 gaqhf
    public class Document
14 0dae5645 gaqhf
    {
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 6b9e7a56 gaqhf
        public List<Group> Groups { get; set; }
21 0dae5645 gaqhf
        public List<RunInfo> RunInfos { get; set; }
22 6b9e7a56 gaqhf
        public List<Item> SegmentBreaks { get; set; }
23
        public List<Equipment> Equipments { get; set; }
24 7881ec8f gaqhf
        public List<TextInfo> TextInfos { get; set; }
25 0dae5645 gaqhf
26 7881ec8f gaqhf
        private DataTable symbolNameTable = null;
27 4c76a67a gaqhf
        private DataTable equipmentTable = DB.GetEquipmentType();
28
29 7881ec8f gaqhf
        public Document(string filePath, DataTable symbolNameTable)
30 0dae5645 gaqhf
        {
31 7881ec8f gaqhf
            this.symbolNameTable = symbolNameTable;
32 0dae5645 gaqhf
            FilePath = filePath;
33 7881ec8f gaqhf
            // XML Data 정리
34 0dae5645 gaqhf
            ReadFile();
35 7881ec8f gaqhf
            // 해당 소스는 Line-Equipment가 붙어있을 시 가상의 Nozzle Data를 넣어줌 (삼엔 요청)
36 0f07fa34 gaqhf
            InsertNozzle();
37 7881ec8f gaqhf
            // ID2 Item Relation 정보 기준으로 Item Object 연결
38 0dae5645 gaqhf
            SetRelationItem();
39 7881ec8f gaqhf
            // Instrument Line이 있는 아이템/group 제거
40 0f07fa34 gaqhf
            RemoveItems();
41 8630cab2 gaqhf
            // 속성 상관 없이 drawing 단위의 PSN 생성
42
            SetGroup();
43 7881ec8f gaqhf
44
            foreach (var item in Items)
45
                item.Document = this;
46 0dae5645 gaqhf
        }
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 6b9e7a56 gaqhf
            Groups = new List<Group>();
56
            SegmentBreaks = new List<Item>();
57
            Equipments = new List<Equipment>();
58 7881ec8f gaqhf
            TextInfos = new List<TextInfo>();
59 0dae5645 gaqhf
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 6b9e7a56 gaqhf
            foreach (XElement element in xml.Element("VENDORS").Elements("VENDOR"))
67
                Equipments.Add(GetEquipment(element));
68 7881ec8f gaqhf
            foreach (XElement element in xml.Element("TEXTINFOS").Elements("ATTRIBUTE"))
69
                TextInfos.Add(GetTextInfo(element));
70 6b9e7a56 gaqhf
71 7881ec8f gaqhf
            List<Item> segmentBreaks = Items.FindAll(x => x.ID2DBType.ToUpper() == "Segment Breaks".ToUpper() || x.ID2DBType.ToUpper() == "End Break".ToUpper());
72 6b9e7a56 gaqhf
            SegmentBreaks.AddRange(segmentBreaks);
73
            foreach (var item in segmentBreaks)
74
                Items.Remove(item);
75 0dae5645 gaqhf
76 4c76a67a gaqhf
            foreach (DataRow row in equipmentTable.Rows)
77
            {
78
                string type = row["Type"].ToString();
79 7881ec8f gaqhf
                List<Item> equipments = Items.FindAll(x => x.ID2DBType == type);
80 4c76a67a gaqhf
81
                foreach (Item item in equipments)
82
                {
83
                    Equipments.Add(ConvertEquipment(item));
84
                    Items.Remove(item);
85
                }
86
            }
87
88 0dae5645 gaqhf
            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 7881ec8f gaqhf
            item.ID2DBType = element.Element("TYPE").Value;
96 0dae5645 gaqhf
            item.Owner = element.Element("OWNER").Value;
97 7881ec8f gaqhf
            item.ID2DBName = element.Element("PARENT").Value;
98 6b9e7a56 gaqhf
            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 0dae5645 gaqhf
            item.Relations = GetRelations(element.Element("CONNECTORS"));
102
            item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES"));
103
            item.ItemType = ItemType.Symbol;
104 7881ec8f gaqhf
            item.ID2DBCategory = GetID2DBCategory(item.ID2DBType, item.ID2DBName);
105 0dae5645 gaqhf
106 7881ec8f gaqhf
            if (item.ID2DBType.ToUpper().Equals("PIPING OPC'S"))
107 6b9e7a56 gaqhf
                item.SubItemType = SubItemType.OPC;
108 7881ec8f gaqhf
            else if (item.ID2DBType.ToUpper().Equals("NOZZLES"))
109 6b9e7a56 gaqhf
                item.SubItemType = SubItemType.Nozzle;
110
111 0dae5645 gaqhf
            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 7881ec8f gaqhf
            item.ID2DBType = element.Element("TYPE").Value;
119 0dae5645 gaqhf
            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 6b9e7a56 gaqhf
        private Equipment GetEquipment(XElement element)
136
        {
137
            Equipment item = new Equipment();
138
            item.UID = element.Element("UID").Value;
139 c6503eaa gaqhf
            item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES"));
140 6b9e7a56 gaqhf
            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 7881ec8f gaqhf
        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 4c76a67a gaqhf
155 7881ec8f gaqhf
            return textInfo;
156
        }
157 4c76a67a gaqhf
        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 c6503eaa gaqhf
            equipment.Attributes.AddRange(item.Attributes);
164 4c76a67a gaqhf
            return equipment;
165
        }
166 0dae5645 gaqhf
        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 6b9e7a56 gaqhf
                    Point = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) }
176 0dae5645 gaqhf
                });
177
            }
178 6b9e7a56 gaqhf
179 0dae5645 gaqhf
            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
                result.Add(new Attribute()
187
                {
188
                    UID = item.Attribute("UID").Value,
189
                    Name = item.Attribute("Attribute").Value,
190
                    DisplayName = item.Attribute("DisplayAttribute").Value,
191
                    Value = item.Value
192
                });
193
            }
194
            return result;
195
        }
196 7881ec8f gaqhf
        private string GetID2DBCategory(string type, string name)
197
        {
198
            string result = string.Empty;
199
            DataRow[] rows = symbolNameTable.Select(string.Format("Type = '{0}' AND Name = '{1}'", type.Replace("'", "''"), name.Replace("'", "''")));
200
            if (rows.Length.Equals(1))
201
                result = rows.First()["Category"].ToString();
202
203
            return result;
204
        }
205 0dae5645 gaqhf
        private void SetRelationItem()
206
        {
207
            foreach (Item item in Items)
208
                foreach (Relation relation in item.Relations)
209
                    relation.Item = Items.Find(x => x.UID.Equals(relation.UID));
210
        }
211 1be87cbd gaqhf
        private void SetRunInfo(XElement xml)
212
        {
213 6b9e7a56 gaqhf
            foreach (XElement element in xml.Element("LINENOS").Elements("LINE_NO"))
214
            {
215
                string UID = element.Element("UID").Value;
216
                foreach (XElement run in element.Elements("RUN"))
217
                {
218
                    RunInfo runInfo = new RunInfo() { UID = UID };
219
                    foreach (XElement line in run.Elements("LINE"))
220
                        runInfo.Items.Add(Items.Find(x => x.UID == line.Element("UID").Value));
221
                    foreach (XElement symbol in run.Elements("SYMBOL"))
222
                        runInfo.Items.Add(Items.Find(x => x.UID == symbol.Element("UID").Value));
223
                    RunInfos.Add(runInfo);
224
                }
225
            }
226
227 1be87cbd gaqhf
            foreach (XElement element in xml.Element("TRIMLINENOS").Elements("TRIM_LINE_NO"))
228
            {
229
                string UID = element.Element("UID").Value;
230
                foreach (XElement run in element.Elements("RUN"))
231
                {
232
                    RunInfo runInfo = new RunInfo() { UID = UID };
233
                    foreach (XElement line in run.Elements("LINE"))
234
                        runInfo.Items.Add(Items.Find(x => x.UID == line.Element("UID").Value));
235
                    foreach (XElement symbol in run.Elements("SYMBOL"))
236
                        runInfo.Items.Add(Items.Find(x => x.UID == symbol.Element("UID").Value));
237
                    RunInfos.Add(runInfo);
238
                }
239
            }
240
        }
241 6b9e7a56 gaqhf
        private void SetGroup()
242 0dae5645 gaqhf
        {
243
            List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList();
244
245 6b9e7a56 gaqhf
            Dictionary<Item, string> itemDic = new Dictionary<Item, string>();
246 0dae5645 gaqhf
            foreach (Item item in orderItems)
247 6b9e7a56 gaqhf
                itemDic.Add(item, Guid.NewGuid().ToString());
248 0dae5645 gaqhf
249
            foreach (Item item in orderItems)
250
            {
251 6b9e7a56 gaqhf
                string groupKey = itemDic[item];
252 0dae5645 gaqhf
                if (item.ItemType == ItemType.Line)
253
                {
254 bfbc9f6c 이지연
                    //if(item.Relations.Count() > 2)
255
                    //{
256
                    //    int i = 2;
257
                    //    GroupingForwardLine(2);
258
                    //    if(item.Relations.Count() >= 4)
259
                    //        GroupingBackwardLine(3);
260
                    //}
261 0dae5645 gaqhf
                    GroupingForwardLine();
262
                    GroupingBackwardLine();
263
                }
264 1be87cbd gaqhf
265 bfbc9f6c 이지연
266
                void GroupingForwardLine(int i = 1)
267 0dae5645 gaqhf
                {
268
                    Item connItem = item.Relations[1].Item;
269
                    if (connItem != null && IsConnected(connItem, item))
270
                    {
271
                        if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[0].Item))
272 6b9e7a56 gaqhf
                            ChangeGroupID(itemDic[connItem], groupKey);
273 0dae5645 gaqhf
                        else if (connItem.ItemType == ItemType.Symbol)
274
                        {
275
                            List<Item> allConnItems = GetConnectedLines(connItem);
276
                            allConnItems.Remove(item);
277
                            List<Item> connItems = GetConnectedForwardLines(connItem);
278
                            if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0]))
279
                            {
280
                                List<Item> connSymbols = GetConnectedSymbols(connItem);
281
                                foreach (Item loopItem in connSymbols)
282 6b9e7a56 gaqhf
                                    ChangeGroupID(itemDic[loopItem], groupKey);
283 0dae5645 gaqhf
                            }
284
                            else
285
                            {
286
                                List<Item> endItems = new List<Item>();
287
                                Stack<Item> stacks = new Stack<Item>();
288
                                stacks.Push(connItem);
289
                                while (stacks.Count > 0)
290
                                {
291
                                    Item stack = stacks.Pop();
292
                                    if (endItems.Contains(stack))
293
                                        continue;
294
                                    endItems.Add(stack);
295
296
                                    if (GetConnectedItemCount(stack) < 3)
297
                                    {
298 6b9e7a56 gaqhf
                                        ChangeGroupID(itemDic[stack], groupKey);
299 0dae5645 gaqhf
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
300
                                        foreach (Relation relation in relations)
301
                                            stacks.Push(relation.Item);
302
                                    }
303 1be87cbd gaqhf
                                    else if (IsSameRun(item, stack))
304 0dae5645 gaqhf
                                    {
305 6b9e7a56 gaqhf
                                        ChangeGroupID(itemDic[stack], groupKey);
306 0dae5645 gaqhf
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item));
307
                                        foreach (Relation relation in relations)
308
                                            stacks.Push(relation.Item);
309
                                    }
310
                                }
311
                            }
312
                        }
313
                    }
314
                }
315 bfbc9f6c 이지연
                void GroupingBackwardLine(int i = 0)
316 0dae5645 gaqhf
                {
317
                    Item connItem = item.Relations[0].Item;
318
                    if (connItem != null && IsConnected(connItem, item))
319
                    {
320
                        if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[1].Item))
321 6b9e7a56 gaqhf
                            ChangeGroupID(itemDic[connItem], groupKey);
322 0dae5645 gaqhf
                        else if (connItem.ItemType == ItemType.Symbol)
323
                        {
324
                            List<Item> allConnItems = GetConnectedLines(connItem);
325
                            allConnItems.Remove(item);
326
                            List<Item> connItems = GetConnectedBackwardLines(connItem);
327
                            if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0]))
328
                            {
329
                                List<Item> connSymbols = GetConnectedSymbols(connItem);
330
                                foreach (Item loopItem in connSymbols)
331 6b9e7a56 gaqhf
                                    ChangeGroupID(itemDic[loopItem], groupKey);
332 0dae5645 gaqhf
                            }
333
                            else
334
                            {
335
                                List<Item> endItems = new List<Item>();
336
                                Stack<Item> stacks = new Stack<Item>();
337
                                stacks.Push(connItem);
338
                                while (stacks.Count > 0)
339
                                {
340
                                    Item stack = stacks.Pop();
341
                                    if (endItems.Contains(stack))
342
                                        continue;
343
                                    endItems.Add(stack);
344
345
                                    if (GetConnectedItemCount(stack) < 3)
346
                                    {
347 6b9e7a56 gaqhf
                                        ChangeGroupID(itemDic[stack], groupKey);
348 0dae5645 gaqhf
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
349
                                        foreach (Relation relation in relations)
350
                                            stacks.Push(relation.Item);
351
                                    }
352
                                    else if (IsSameRun(item, stack))
353
                                    {
354 6b9e7a56 gaqhf
                                        ChangeGroupID(itemDic[stack], groupKey);
355 0dae5645 gaqhf
                                        List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item));
356
                                        foreach (Relation relation in relations)
357
                                            stacks.Push(relation.Item);
358
                                    }
359
                                }
360
                            }
361
                        }
362
                    }
363
                }
364
            }
365
366 6b9e7a56 gaqhf
            List<string> endGroupIds = new List<string>();
367
            foreach (var item in itemDic)
368
            {
369
                if (endGroupIds.Contains(item.Value))
370
                    continue;
371
                endGroupIds.Add(item.Value);
372
373 0f07fa34 gaqhf
                List<Item> groupItems = itemDic.Where(x => x.Value.Equals(item.Value)).Select(x => x.Key).ToList();
374
                if (groupItems.Find(x => x.ItemType == ItemType.Line) == null)
375
                {
376
                    foreach (var groupItem in groupItems)
377
                        Items.Remove(groupItem);
378
                }
379
                else
380
                {
381
                    Group group = new Group(this);
382
                    group.Items = groupItems;
383
                    group.UID = item.Value;
384
                    group.SortItems();
385 36a45f13 gaqhf
                    foreach (Item groupItem in groupItems)
386
                        groupItem.Group = group;
387 0f07fa34 gaqhf
                    Groups.Add(group);
388
                }
389 6b9e7a56 gaqhf
            }
390
391
            #region HeaderSetting
392
            List<HeaderInfo> HeaderInfos = new List<HeaderInfo>();
393
            DataTable dt = DB.SelectHeaderSetting();
394
            foreach (DataRow row in dt.Rows)
395
            {
396
                string groupID = row["GROUP_ID"].ToString();
397
                string desc = row["DESCRIPTION"].ToString();
398
                int index = Convert.ToInt32(row["INDEX"]);
399
                string name = row["NAME"].ToString();
400
401
                HeaderInfo headerInfo = HeaderInfos.Find(x => x.UID.Equals(groupID));
402
                if (headerInfo == null)
403
                {
404
                    headerInfo = new HeaderInfo(groupID);
405
                    headerInfo.Description = desc;
406
                    HeaderInfos.Add(headerInfo);
407
                }
408
409
                headerInfo.HeaderItems.Add(new HeaderItem()
410
                {
411
                    Index = index,
412
                    Name = name
413
                });
414
            }
415
            foreach (HeaderInfo headerInfo in HeaderInfos)
416
                headerInfo.HeaderItems = headerInfo.HeaderItems.OrderBy(x => x.Index).ToList();
417
418
            foreach (Group group in Groups)
419
            {
420
                List<HeaderInfo> endInfos = new List<HeaderInfo>();
421
                bool bFind = false;
422
                for (int i = 0; i < group.Items.Count; i++)
423
                {
424
                    Item item = group.Items[i];
425
                    foreach (HeaderInfo header in HeaderInfos)
426
                    {
427
                        if (endInfos.Contains(header))
428
                            continue;
429
430
                        if (!header.HeaderItems[i].Name.Equals(item.Name))
431
                        {
432
                            endInfos.Add(header);
433
                            continue;
434
                        }
435
436
                        if (header.HeaderItems.Count.Equals(i + 1))
437
                        {
438
                            for (int j = 0; j < i + 1; j++)
439
                                group.Items[j].SubItemType = SubItemType.Header;
440
                            bFind = true;
441
                            break;
442
                        }
443
                    }
444
445
                    if (bFind || endInfos.Count.Equals(HeaderInfos.Count))
446
                        break;
447
                }
448
449
                endInfos = new List<HeaderInfo>();
450
                bFind = false;
451
                for (int i = 0; i < group.Items.Count; i++)
452
                {
453
                    Item item = group.Items[group.Items.Count - i - 1];
454
                    foreach (HeaderInfo header in HeaderInfos)
455
                    {
456
                        if (endInfos.Contains(header))
457
                            continue;
458
459
                        if (!header.HeaderItems[i].Name.Equals(item.Name))
460
                        {
461
                            endInfos.Add(header);
462
                            continue;
463
                        }
464
465
                        if (header.HeaderItems.Count.Equals(i + 1))
466
                        {
467
                            for (int j = 0; j < i + 1; j++)
468
                                group.Items[group.Items.Count - j - 1].SubItemType = SubItemType.Header;
469
                            bFind = true;
470
                            break;
471
                        }
472
                    }
473
474
                    if (bFind || endInfos.Count.Equals(HeaderInfos.Count))
475
                        break;
476
                }
477
            }
478 0dae5645 gaqhf
            #endregion
479
480 eb44d82c LJIYEON
            //#region KeywordSetting
481
            ////List<KeywordInfo> KeywordInfos = new List<KeywordInfo>();
482
            //DataTable dtKeyword = DB.SelectKeywordsSetting();
483
            //KeywordInfo KeywordInfos = new KeywordInfo();
484
485
            //foreach (DataRow row in dtKeyword.Rows)
486
            //{
487
            //    int index = Convert.ToInt32(row["INDEX"]);
488
            //    string name = row["NAME"].ToString();
489
            //    string keyword = row["KEYWORD"].ToString();
490
491
            //    KeywordInfos.KeywordItems.Add(new KeywordItem()
492
            //    {
493
            //        Index = index,
494
            //        Name = name,
495
            //        Keyword = keyword
496
            //    });
497
            //}
498
499
            //KeywordInfos.KeywordItems = KeywordInfos.KeywordItems.OrderBy(x => x.Index).ToList();
500
501
            //foreach (Group group in Groups)
502
            //{
503
            //    //List<KeywordItem> endInfos = new List<KeywordItem>();
504
            //    bool bFind = false;
505
            //    for (int i = 0; i < group.Items.Count; i++)
506
            //    {
507
            //        Item item = group.Items[i];
508
            //        foreach (KeywordItem keyword in KeywordInfos.KeywordItems)
509
            //        {
510
            //            if (endInfos.Contains(keyword))
511
            //                continue;
512
513
            //            if (!keyword.Name.Equals(item.Name))
514
            //            {
515
            //                endInfos.Add(keyword);
516
            //                continue;
517
            //            }
518
519
            //            if (KeywordInfos.KeywordItems.Count.Equals(i + 1))
520
            //            {
521
            //                for (int j = 0; j < i + 1; j++)
522
            //                    group.Items[j].Keyword = keyword.Keyword;
523
            //                bFind = true;
524
            //                break;
525
            //            }
526
            //        }
527
528
            //        if (bFind || endInfos.Count.Equals(KeywordInfos.KeywordItems.Count))
529
            //            break;
530
            //    }
531
532
            //    endInfos = new List<KeywordItem>();
533
            //    bFind = false;
534
            //    for (int i = 0; i < group.Items.Count; i++)
535
            //    {
536
            //        Item item = group.Items[group.Items.Count - i - 1];
537
            //        foreach (KeywordItem keyword in KeywordInfos.KeywordItems)
538
            //        {
539
            //            if (endInfos.Contains(keyword))
540
            //                continue;
541
542
            //            if (!keyword.Name.Equals(item.Name))
543
            //            {
544
            //                endInfos.Add(keyword);
545
            //                continue;
546
            //            }
547
548
            //            if (KeywordInfos.KeywordItems.Count.Equals(i + 1))
549
            //            {
550
            //                for (int j = 0; j < i + 1; j++)
551
            //                    group.Items[group.Items.Count - j - 1].Keyword = keyword.Keyword;
552
            //                bFind = true;
553
            //                break;
554
            //            }
555
            //        }
556
557
            //        if (bFind || endInfos.Count.Equals(KeywordInfos.KeywordItems.Count))
558
            //            break;
559
            //    }
560
            //}
561
            //#endregion
562
563 0dae5645 gaqhf
            int GetConnectedItemCount(Item item)
564
            {
565
                return item.Relations.FindAll(x => x.Item != null).Count;
566
            }
567
568
            List<Item> GetConnectedLines(Item item)
569
            {
570
                List<Item> result = new List<Item>();
571
                List<Item> end = new List<Item>();
572
                Stack<Item> stacks = new Stack<Item>();
573
                stacks.Push(item);
574
                while (stacks.Count > 0)
575
                {
576
                    Item stack = stacks.Pop();
577
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
578
                        continue;
579
                    end.Add(stack);
580
581
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
582
                    foreach (Relation relation in relations)
583
                        stacks.Push(relation.Item);
584
585
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
586
                    foreach (Relation relation in relations)
587
                    {
588
                        result.Add(relation.Item);
589
                        end.Add(relation.Item);
590
                    }
591
                }
592
593
                return result;
594
            }
595
596
            List<Item> GetConnectedForwardLines(Item item)
597
            {
598
                List<Item> result = new List<Item>();
599
                List<Item> end = new List<Item>();
600
                Stack<Item> stacks = new Stack<Item>();
601
                stacks.Push(item);
602
                while (stacks.Count > 0)
603
                {
604
                    Item stack = stacks.Pop();
605
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
606
                        continue;
607
                    end.Add(stack);
608
609
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
610
                    foreach (Relation relation in relations)
611
                        stacks.Push(relation.Item);
612
613
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
614
                    foreach (Relation relation in relations)
615
                    {
616
                        if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(0))
617
                            result.Add(relation.Item);
618
619
                        end.Add(relation.Item);
620
                    }
621
                }
622
623
                return result;
624
            }
625
626
            List<Item> GetConnectedBackwardLines(Item item)
627
            {
628
                List<Item> result = new List<Item>();
629
                List<Item> end = new List<Item>();
630
                Stack<Item> stacks = new Stack<Item>();
631
                stacks.Push(item);
632
                while (stacks.Count > 0)
633
                {
634
                    Item stack = stacks.Pop();
635
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
636
                        continue;
637
                    end.Add(stack);
638
639
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
640
                    foreach (Relation relation in relations)
641
                        stacks.Push(relation.Item);
642
643
                    relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line);
644
                    foreach (Relation relation in relations)
645
                    {
646
                        if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(1))
647
                            result.Add(relation.Item);
648
649
                        end.Add(relation.Item);
650
                    }
651
                }
652
653
                return result;
654
            }
655
656
            List<Item> GetConnectedSymbols(Item item)
657
            {
658
                List<Item> result = new List<Item>();
659
                List<Item> end = new List<Item>();
660
                Stack<Item> stacks = new Stack<Item>();
661
                stacks.Push(item);
662
                while (stacks.Count > 0)
663
                {
664
                    Item stack = stacks.Pop();
665
                    if (end.Contains(stack) || stack.ItemType != ItemType.Symbol)
666
                        continue;
667
                    end.Add(stack);
668
                    result.Add(stack);
669
                    List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol);
670
                    foreach (Relation relation in relations)
671
                        stacks.Push(relation.Item);
672
                }
673
674
                return result;
675
            }
676
677
            void ChangeGroupID(string from, string to)
678
            {
679
                if (from.Equals(to))
680
                    return;
681 1be87cbd gaqhf
682 0dae5645 gaqhf
                List<Item> changeItems = new List<Item>();
683 6b9e7a56 gaqhf
                foreach (var _item in itemDic)
684 0dae5645 gaqhf
                    if (_item.Value.Equals(from))
685
                        changeItems.Add(_item.Key);
686
                foreach (var _item in changeItems)
687 6b9e7a56 gaqhf
                    itemDic[_item] = to;
688 0dae5645 gaqhf
            }
689
690
            bool IsConnected(Item item1, Item item2)
691
            {
692
                if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null &&
693
                    item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null)
694
                    return true;
695
                else
696
                    return false;
697
            }
698
699
            bool IsSameRun(Item item1, Item item2)
700
            {
701
                return RunInfos.Find(x => x.Items.Contains(item1) && x.Items.Contains(item2)) != null ? true : false;
702
            }
703
        }
704 0f07fa34 gaqhf
        private void RemoveItems()
705
        {
706 8630cab2 gaqhf
            List<Item> removeItems = new List<Item>();
707
            foreach (var item in Items)
708 0f07fa34 gaqhf
            {
709 8630cab2 gaqhf
                if (item.ItemType == ItemType.Line && (item.Name != "Secondary" && item.Name != "Primary"))
710
                {
711
                    List<Relation> relations = item.Relations.FindAll(x => x.Item != null);
712
                    foreach (Relation relation in relations)
713
                    {
714
                        Relation otherRelation = Items.Find(x => x.UID == relation.UID).Relations.Find(x => x.UID == item.UID);
715
                        if (otherRelation != null)
716
                        {
717
                            otherRelation.Item = null;
718
                            otherRelation.UID = string.Empty;
719
                        }
720
                    }
721
722
                    removeItems.Add(item);
723
                }
724 0f07fa34 gaqhf
            }
725
726 8630cab2 gaqhf
            foreach (var item in removeItems)
727 0f07fa34 gaqhf
            {
728 8630cab2 gaqhf
                Items.Remove(item);
729 0f07fa34 gaqhf
            }
730
        }
731 8630cab2 gaqhf
        
732 0f07fa34 gaqhf
        private void InsertNozzle()
733
        {
734
            List<Item> newNozzles = new List<Item>();
735
            foreach (var item in Items)
736
            {
737
                if (item.SubItemType == SubItemType.Nozzle)
738
                    continue;
739
                
740
                foreach (Relation relation in item.Relations)
741
                {
742
                    Equipment equipment = Equipments.Find(x => x.UID == relation.UID);
743
                    if (equipment != null)
744
                    {
745
                        Item newNozzle = new Item();
746
                        newNozzle.UID = Guid.NewGuid().ToString();
747
                        newNozzle.Name = "PSN_Nozzle";
748 7881ec8f gaqhf
                        newNozzle.ID2DBType = "Nozzles";
749 0f07fa34 gaqhf
                        newNozzle.Owner = item.Owner;
750 7881ec8f gaqhf
                        newNozzle.ID2DBName = "PSN_Nozzle";
751 0f07fa34 gaqhf
                        newNozzle.POINT = relation.Point;
752
                        newNozzle.Relations = new List<Relation>();
753
754
                        newNozzle.Relations.Add(new Relation()
755
                        {
756
                            Point = relation.Point,
757
                            UID = equipment.UID
758
                        });
759
                        newNozzle.Relations.Add(new Relation()
760
                        {
761
                            Point = relation.Point,
762
                            UID = item.UID
763
                        });
764
765
                        newNozzle.ItemType = ItemType.Symbol;
766
                        newNozzle.SubItemType = SubItemType.Nozzle;
767
768
                        newNozzles.Add(newNozzle);
769
770
                        relation.UID = newNozzle.UID;
771
                    }
772
                }
773
            }
774
775
            Items.AddRange(newNozzles);
776
        }
777 0dae5645 gaqhf
    }
778
}
클립보드 이미지 추가 (최대 크기: 500 MB)