프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / BaseModel / Document.cs @ 30ba9ae0

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.IO;
7
using System.Xml.Linq;
8
using System.Windows.Forms;
9
using Converter.SPPID.Util;
10

    
11
namespace Converter.BaseModel
12
{
13
    public class Document
14
    {
15
        private string _DWGNAME;
16
        private string _SIZE;
17
        private double _SIZE_WIDTH;
18
        private double _SIZE_HEIGHT;
19
        private List<Symbol> _SYMBOLS = new List<Symbol>();
20
        private List<Text> _TEXTINFOS = new List<Text>();
21
        private List<Note> _NOTES = new List<Note>();
22
        private List<Line> _LINES = new List<Line>();
23
        private List<LineNumber> _LINENUMBERS = new List<LineNumber>();
24
        private List<TrimLine> _TRIMLINES = new List<TrimLine>();
25
        private List<EndBreak> _EndBreaks = new List<EndBreak>();
26
        private List<SpecBreak> _SpecBreaks = new List<SpecBreak>();
27
        private List<Equipment> _Equipments = new List<Equipment>();
28
        private bool _Enable;
29

    
30
        public bool Enable { get { return _Enable; } }
31

    
32
        public List<Symbol> SYMBOLS { get => _SYMBOLS; set => _SYMBOLS = value; }
33
        public List<Text> TEXTINFOS { get => _TEXTINFOS; set => _TEXTINFOS = value; }
34
        public List<Note> NOTES { get => _NOTES; set => _NOTES = value; }
35
        public List<Line> LINES { get => _LINES; set => _LINES = value; }
36
        public List<LineNumber> LINENUMBERS { get => _LINENUMBERS; set => _LINENUMBERS = value; }
37
        public List<EndBreak> EndBreaks { get => _EndBreaks; set => _EndBreaks = value; }
38
        public List<SpecBreak> SpecBreaks { get => _SpecBreaks; set => _SpecBreaks = value; }
39
        public List<Equipment> Equipments { get => _Equipments; set => _Equipments = value; }
40
        public string DWGNAME { get => _DWGNAME; set => _DWGNAME = value; }
41
        public string SIZE
42
        {
43
            get
44
            {
45
                return _SIZE;
46
            }
47
            set
48
            {
49
                _SIZE = value;
50
                string[] pointArr = _SIZE.Split(new char[] { ',' });
51
                if (pointArr.Length == 2)
52
                {
53
                    _SIZE_WIDTH = Convert.ToDouble(pointArr[0]);
54
                    _SIZE_HEIGHT = Convert.ToDouble(pointArr[1]);
55
                }
56
            }
57
        }
58
        public double SIZE_WIDTH { get => _SIZE_WIDTH; }
59
        public double SIZE_HEIGHT { get => _SIZE_HEIGHT; }
60
        public List<TrimLine> TRIMLINES { get => _TRIMLINES; set => _TRIMLINES = value; }
61
        public string PATH { get; set; }
62

    
63
        StringBuilder validationStringBuilder = new StringBuilder();
64

    
65
        public Document(string xmlPath)
66
        {
67
            validationStringBuilder.AppendLine("Document Path : " + xmlPath);
68
            validationStringBuilder.AppendLine("");
69
            try
70
            {
71
                if (xmlPath != null)
72
                {
73
                    PATH = xmlPath;
74
                    XElement xml = XElement.Load(xmlPath);
75
                    DWGNAME = xml.Element("DWGNAME").Value;
76
                    SIZE = xml.Element("SIZE").Value;
77

    
78
                    validationStringBuilder.AppendLine("Drawing Name : " + DWGNAME);
79
                    validationStringBuilder.AppendLine("");
80

    
81
                    SetText(xml.Element("TEXTINFOS"));
82
                    SetNote(xml.Element("NOTES"));
83
                    SetSymbol(xml.Element("SYMBOLS"));
84
                    SetLine(xml.Element("LINEINFOS"));
85
                    SetLineNumber(xml.Element("LINENOS"));
86
                    SetTrimLine(xml.Element("TRIMLINENOS"));
87

    
88
                    SetAllConnectors();
89
                    _Enable = true;
90
                    ValidationCheck();
91
                }
92
            }
93
            catch (Exception ex)
94
            {
95
                _Enable = false;
96
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
97
            }
98
        }
99

    
100
        #region READ XML
101
        private void SetSymbol(XElement node)
102
        {
103
            foreach (XElement item in node.Elements("SYMBOL"))
104
            {
105
                string sType = item.Element("TYPE").Value;
106
                if (sType == "Segment Breaks")
107
                {
108
                    SpecBreak specBreak = new SpecBreak()
109
                    {
110
                        UID = item.Element("UID").Value,
111
                        DBUID = item.Element("DBUID").Value,
112
                        NAME = item.Element("NAME").Value,
113
                        TYPE = item.Element("TYPE").Value,
114
                        OWNER = item.Element("OWNER").Value,
115
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
116
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
117
                        LOCATION = item.Element("LOCATION").Value,
118
                        SIZE = item.Element("SIZE").Value,
119
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
120
                        PARENT = item.Element("PARENT").Value,
121
                        CHILD = item.Element("CHILD").Value,
122
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
123
                        AREA = item.Element("AREA").Value,
124
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
125
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
126
                    };
127
                    SetAssociations(item.Element("ASSOCIATIONS"), specBreak.ASSOCIATIONS);
128
                    SetSymbolConnectors(item.Element("CONNECTORS"), specBreak.CONNECTORS, specBreak.CONNECTIONPOINT);
129
                    SetProperties(item.Element("PROPERTIES"), specBreak.PROPERTIES);
130
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), specBreak.ATTRIBUTES);
131
                    SetSpecBreakAttribute(specBreak);
132

    
133
                    SpecBreaks.Add(specBreak);
134
                }
135
                else if (sType == "End Break")
136
                {
137
                    EndBreak endBreak = new EndBreak()
138
                    {
139
                        UID = item.Element("UID").Value,
140
                        DBUID = item.Element("DBUID").Value,
141
                        NAME = item.Element("NAME").Value,
142
                        TYPE = item.Element("TYPE").Value,
143
                        OWNER = item.Element("OWNER").Value,
144
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
145
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
146
                        LOCATION = item.Element("LOCATION").Value,
147
                        SIZE = item.Element("SIZE").Value,
148
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
149
                        PARENT = item.Element("PARENT").Value,
150
                        CHILD = item.Element("CHILD").Value,
151
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
152
                        AREA = item.Element("AREA").Value,
153
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
154
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
155
                    };
156
                    SetAssociations(item.Element("ASSOCIATIONS"), endBreak.ASSOCIATIONS);
157
                    SetSymbolConnectors(item.Element("CONNECTORS"), endBreak.CONNECTORS, endBreak.CONNECTIONPOINT);
158
                    SetProperties(item.Element("PROPERTIES"), endBreak.PROPERTIES);
159
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), endBreak.ATTRIBUTES);
160

    
161
                    EndBreaks.Add(endBreak);
162
                }
163
                else if (sType == "Black Box System" ||
164
                    sType == "GGO_Equipment" ||
165
                    sType == "Heat Transfer Equipment" ||
166
                    sType == "Mechanical" ||
167
                    sType == "Other Equipment" ||
168
                    sType == "Vessels")
169
                {
170
                    Equipment equipment = new Equipment()
171
                    {
172
                        UID = item.Element("UID").Value,
173
                        DBUID = item.Element("DBUID").Value,
174
                        NAME = item.Element("NAME").Value,
175
                        TYPE = item.Element("TYPE").Value,
176
                        OWNER = item.Element("OWNER").Value,
177
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
178
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
179
                        LOCATION = item.Element("LOCATION").Value,
180
                        SIZE = item.Element("SIZE").Value,
181
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
182
                        PARENT = item.Element("PARENT").Value,
183
                        CHILD = item.Element("CHILD").Value,
184
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
185
                        AREA = item.Element("AREA").Value,
186
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
187
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
188
                    };
189
                    SetAssociations(item.Element("ASSOCIATIONS"), equipment.ASSOCIATIONS);
190
                    SetSymbolConnectors(item.Element("CONNECTORS"), equipment.CONNECTORS, equipment.CONNECTIONPOINT);
191
                    SetProperties(item.Element("PROPERTIES"), equipment.PROPERTIES);
192
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), equipment.ATTRIBUTES);
193

    
194
                    Equipments.Add(equipment);
195
                }
196
                else
197
                {
198
                    Symbol symbol = new Symbol()
199
                    {
200
                        UID = item.Element("UID").Value,
201
                        DBUID = item.Element("DBUID").Value,
202
                        NAME = item.Element("NAME").Value,
203
                        TYPE = item.Element("TYPE").Value,
204
                        OWNER = item.Element("OWNER").Value,
205
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
206
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
207
                        LOCATION = item.Element("LOCATION").Value,
208
                        SIZE = item.Element("SIZE").Value,
209
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
210
                        PARENT = item.Element("PARENT").Value,
211
                        CHILD = item.Element("CHILD").Value,
212
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
213
                        AREA = item.Element("AREA").Value,
214
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
215
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
216
                    };
217

    
218
                    SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS);
219
                    SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT);
220
                    SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES);
221
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES);
222
                    SetChildSymbol(symbol);
223

    
224
                    SYMBOLS.Add(symbol);
225
                }
226
            }
227
        }
228

    
229
        private void SetLine(XElement node)
230
        {
231
            foreach (XElement item in node.Elements("LINE"))
232
            {
233
                Line line = new Line()
234
                {
235
                    OWNER = item.Attribute("OWNER").Value,
236
                    UID = item.Element("UID").Value,
237
                    STARTPOINT = item.Element("STARTPOINT").Value,
238
                    ENDPOINT = item.Element("ENDPOINT").Value,
239
                    TYPE = item.Element("TYPE").Value,
240
                    TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value,
241
                    AREA = item.Element("AREA").Value,
242
                    THICKNESS = item.Element("THICKNESS").Value,
243
                };
244
                int flowMarkPercent = 0;
245
                if (int.TryParse(item.Element("FLOWMARK").Value, out flowMarkPercent))
246
                {
247
                    line.FLOWMARK = true;
248
                    line.FLOWMARK_PERCENT = flowMarkPercent;
249
                }
250
                else
251
                    line.FLOWMARK = false;
252

    
253
                SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS);
254
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
255
                SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES);
256
                LINES.Add(line);
257
            }
258
        }
259

    
260
        private void SetLineNumber(XElement node)
261
        {
262
            foreach (XElement item in node.Elements("LINE_NO"))
263
            {
264
                LineNumber lineNumber = new LineNumber()
265
                {
266
                    UID = item.Element("UID").Value,
267
                    TEXT = item.Element("TEXT").Value,
268
                    LOCATION = item.Element("LOCATION").Value,
269
                    WIDTH = item.Element("WIDTH").Value,
270
                    HEIGHT = item.Element("HEIGHT").Value,
271
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
272
                    AREA = item.Element("AREA").Value,
273
                    SCENE = item.Element("SCENE").Value
274
                };
275
                if (item.Element("CONNLINE") != null)
276
                    lineNumber.CONNLINE = item.Element("CONNLINE").Value;
277

    
278
                SetLineNumberRuns(item, lineNumber.RUNS);
279
                SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
280
                SetAttributes(item, lineNumber.ATTRIBUTES);
281
                LINENUMBERS.Add(lineNumber);
282
            }
283
        }
284

    
285
        private void SetText(XElement node)
286
        {
287
            foreach (XElement item in node.Elements("ATTRIBUTE"))
288
            {
289
                Text text = new Text()
290
                {
291
                    UID = item.Element("UID").Value,
292
                    OWNER = item.Element("OWNER").Value,
293
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
294
                    NAME = item.Element("NAME").Value,
295
                    LOCATION = item.Element("LOCATION").Value,
296
                    VALUE = item.Element("VALUE").Value,
297
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
298
                    WIDTH = item.Element("WIDTH").Value,
299
                    HEIGHT = item.Element("HEIGHT").Value,
300
                    AREA = item.Element("AREA").Value,
301
                    SCENE = item.Element("SCENE").Value
302
                };
303

    
304
                TEXTINFOS.Add(text);
305
            }
306
        }
307

    
308
        private void SetNote(XElement node)
309
        {
310
            foreach (XElement item in node.Elements("ATTRIBUTE"))
311
            {
312
                Note note = new Note()
313
                {
314
                    UID = item.Element("UID").Value,
315
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
316
                    NAME = item.Element("NAME").Value,
317
                    LOCATION = item.Element("LOCATION").Value,
318
                    VALUE = item.Element("VALUE").Value,
319
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
320
                    WIDTH = item.Element("WIDTH").Value,
321
                    HEIGHT = item.Element("HEIGHT").Value,
322
                    AREA = item.Element("AREA").Value,
323
                    SCENE = item.Element("SCENE").Value,
324
                    OWNER = item.Element("OWNER").Value
325
                };
326

    
327
                NOTES.Add(note);
328
            }
329
        }
330

    
331
        private void SetTrimLine(XElement node)
332
        {
333
            foreach (XElement item in node.Elements("TRIM_LINE_NO"))
334
            {
335
                TrimLine trimLine = new TrimLine()
336
                {
337
                    UID = item.Element("UID").Value,
338
                };
339
                SetLineNumberRuns(item, trimLine.RUNS);
340
                TRIMLINES.Add(trimLine);
341
            }
342
        }
343

    
344
        private void SetAssociations(XElement node, List<Association> associations)
345
        {
346
            foreach (XElement item in node.Elements("ASSOCIATION"))
347
            {
348
                Association association = new Association()
349
                {
350
                    TYPE = item.Attribute("TYPE").Value,
351
                    VALUE = item.Value
352
                };
353

    
354
                associations.Add(association);
355
            }
356
        }
357

    
358
        private void SetConnectors(XElement node, List<Connector> connectors)
359
        {
360
            foreach (XElement item in node.Elements("CONNECTOR"))
361
            {
362
                connectors.Add(new Connector()
363
                {
364
                    UID = item.Attribute("UID").Value,
365
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
366
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
367
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
368
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
369
                });
370
            }
371
        }
372

    
373
        private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT)
374
        {
375
            foreach (XElement item in node.Elements("CONNECTOR"))
376
            {
377
                connectors.Add(new Connector()
378
                {
379
                    UID = item.Attribute("UID").Value,
380
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
381
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
382
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
383
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
384
                });
385
            }
386
        }
387

    
388
        private void SetProperties(XElement node, List<Property> properties)
389
        {
390
            foreach (XElement item in node.Elements("PROPERTY"))
391
            {
392
                properties.Add(new Property()
393
                {
394
                    UID = item.Attribute("UID").Value,
395
                    LENGTH = item.Attribute("Length").Value,
396
                    EXPRESSION = item.Attribute("Expression").Value,
397
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
398
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
399
                    ATTRIBUTE = item.Attribute("Attribute").Value,
400
                    VALUE = item.Value
401
                });
402
            }
403
        }
404

    
405
        private void SetAttributes(XElement node, List<Attribute> attributes)
406
        {
407
            foreach (XElement item in node.Elements("ATTRIBUTE"))
408
            {
409
                Attribute attribute = new Attribute()
410
                {
411
                    UID = item.Attribute("UID").Value,
412
                    LENGTH = item.Attribute("Length").Value,
413
                    EXPRESSION = item.Attribute("Expression").Value,
414
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
415
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
416
                    ATTRIBUTE = item.Attribute("Attribute").Value,
417
                    ATTRAT = item.Attribute("AttrAt").Value,
418
                    ASSOCITEM = item.Attribute("AssocItem").Value,
419
                    VALUE = item.Value
420
                };
421

    
422
                attributes.Add(attribute);
423

    
424
                if (!string.IsNullOrEmpty(attribute.ASSOCITEM) && attribute.ASSOCITEM != "None")
425
                {
426
                    Text text = _TEXTINFOS.Find(x => x.UID == attribute.ASSOCITEM);
427
                    if (text != null)
428
                        text.ASSOCIATION = true;
429
                }
430
            }
431
        }
432

    
433
        private void SetSpecBreakAttribute(SpecBreak specBreak)
434
        {
435
            string upStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "UpStream").VALUE;
436
            string downStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "DownStream").VALUE;
437

    
438
            specBreak.UpStreamUID = upStream;
439
            specBreak.DownStreamUID = downStream;
440
        }
441

    
442
        private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns)
443
        {
444
            foreach (XElement item in node.Elements("RUN"))
445
            {
446
                LineRun run = new LineRun()
447
                {
448
                    TYPE = item.Attribute("TYPE").Value
449
                };
450

    
451
                foreach (XElement element in item.Elements())
452
                {
453
                    if (element.Name == "SYMBOL")
454
                    {
455
                        Symbol symbol = GetSymbolByUID(element.Element("UID").Value);
456
                        if (symbol == null)
457
                            throw new Exception("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
458
                        run.RUNITEMS.Add(symbol);
459
                    }
460
                    else if (element.Name == "LINE")
461
                    {
462
                        Line line = GetLineByUID(element.Element("UID").Value);
463
                        if (line == null)
464
                            throw new Exception("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
465
                        run.RUNITEMS.Add(line);
466
                    }
467
                }
468
                lineNumberRuns.Add(run);
469
            }
470
        }
471

    
472
        private void SetChildSymbol(Symbol symbol)
473
        {
474
            List<ChildSymbol> childList = new List<ChildSymbol>();
475
            if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None")
476
            {
477
                string[] childArray = symbol.CHILD.Split(new char[] { '/' });
478
                foreach (string sChild in childArray)
479
                {
480
                    string[] sChildInfo = sChild.Split(new char[] { ',' });
481
                    childList.Add(new ChildSymbol()
482
                    {
483
                        ParentAt = Convert.ToInt32(sChildInfo[0]),
484
                        Direction = sChildInfo[1],
485
                        NAME = sChildInfo[2]
486
                    });
487
                }
488

    
489
                foreach (ChildSymbol child in childList)
490
                {
491
                    if (child.ParentAt == 0)
492
                        symbol.ChildSymbols.Add(child);
493
                    else
494
                        childList[child.ParentAt - 1].ChildSymbols.Add(child);
495
                }
496
            }
497
            if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None")
498
            {
499
                // 현재 부모 Symbol에 자식 Connector까지 들어가 있음
500
                string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
501
                string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
502
                for (int i = 0; i < array.Length; i++)
503
                {
504
                    string[] arrConn = array[i].Split(new char[] { ',' });
505
                    int connIndex = Convert.ToInt32(arrConn[3]);
506
                    if (connIndex != 0)
507
                    {
508
                        childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]);
509
                        symbol.CONNECTORS[i].Index = connIndex;
510
                    }
511
                }
512
            }
513
        }
514
        #endregion
515

    
516
        public Symbol GetSymbolByUID(string uid)
517
        {
518
            return SYMBOLS.Find(x => x.UID == uid);
519
        }
520

    
521
        public Line GetLineByUID(string uid)
522
        {
523
            return LINES.Find(x => x.UID == uid);
524
        }
525

    
526
        public void SetAllConnectors()
527
        {
528
            foreach (var item in SYMBOLS)
529
                foreach (var connector in item.CONNECTORS)
530
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
531

    
532
            foreach (var item in LINES)
533
                foreach (var connector in item.CONNECTORS)
534
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
535

    
536
            foreach (var item in Equipments)
537
                foreach (var connector in item.CONNECTORS)
538
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
539
        }
540

    
541
        
542

    
543
        public void ValidationCheck()
544
        {
545
            bool validationResult = false;
546
            #region Connection Check / Symbol의 SceneConnectPoint Check
547
            foreach (var item in _SYMBOLS)
548
            {
549
                foreach (var connector in item.CONNECTORS)
550
                {
551
                    if (connector.ConnectedObject != null && connector.ConnectedObject.GetType() == typeof(Line))
552
                    {
553
                        Line line = connector.ConnectedObject as Line;
554
                        if (line.CONNECTORS.Find(x => x.ConnectedObject == item) == null)
555
                        {
556
                            validationStringBuilder.AppendLine("Check connection!");
557
                            validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
558
                            validationStringBuilder.AppendLine("Line UID : " + line.UID);
559
                            validationStringBuilder.AppendLine();
560
                            validationResult = true;
561
                        }
562
                    }
563

    
564
                    if (connector.SCENECONNECTPOINT == connector.CONNECTPOINT)
565
                    {
566
                        validationStringBuilder.AppendLine("Check Symbol SceneConnectPoint!");
567
                        validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
568
                        validationStringBuilder.AppendLine();
569
                        validationResult = true;
570
                    }
571
                }
572
            }
573

    
574
            foreach (var item in _LINES)
575
            {
576
                foreach (var connector in item.CONNECTORS)
577
                {
578
                    if (connector.ConnectedObject != null && connector.ConnectedObject.GetType() == typeof(Symbol))
579
                    {
580
                        Symbol symbol = connector.ConnectedObject as Symbol;
581
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == item) == null)
582
                        {
583
                            validationStringBuilder.AppendLine("Check connection!");
584
                            validationStringBuilder.AppendLine("Symbol UID : " + symbol.UID);
585
                            validationStringBuilder.AppendLine("Line UID : " + item.UID);
586
                            validationStringBuilder.AppendLine();
587
                            validationResult = true;
588
                        }
589
                    }
590
                }
591
            }
592
            #endregion
593

    
594
            #region Symbol Size Check
595
            foreach (var item in _SYMBOLS)
596
            {
597
                if (item.SIZE == "0,0")
598
                {
599
                    validationStringBuilder.AppendLine("Check symbol size!");
600
                    validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
601
                    validationStringBuilder.AppendLine();
602
                    validationResult = true;
603
                }
604
            }
605
            #endregion
606

    
607
            #region SpecBreak, EndBreak Check
608
            foreach (var item in SpecBreaks)
609
            {
610
                object obj1 = SPPIDUtil.FindObjectByUID(this, item.UpStreamUID);
611
                object obj2 = SPPIDUtil.FindObjectByUID(this, item.DownStreamUID);
612
                if (obj1 == null || obj2 == null)
613
                {
614
                    validationStringBuilder.AppendLine("Check SpecBreak UpStream, DownStream!");
615
                    validationStringBuilder.AppendLine("UID : " + item.UID);
616
                    validationStringBuilder.AppendLine();
617
                    validationResult = true;
618
                }
619
                else
620
                {
621
                    bool result = false;
622
                    if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Symbol))
623
                    {
624
                        Symbol symbol1 = obj1 as Symbol;
625
                        Symbol symbol2 = obj2 as Symbol;
626
                        if (symbol1.CONNECTORS.Find(x => x.ConnectedObject == symbol2) == null || symbol2.CONNECTORS.Find(x => x.ConnectedObject == symbol1) == null)
627
                            result = true;
628
                    }
629
                    else if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Line))
630
                    {
631
                        Symbol symbol = obj1 as Symbol;
632
                        Line line = obj2 as Line;
633
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
634
                            result = true;
635
                    }
636
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Symbol))
637
                    {
638
                        Symbol symbol = obj2 as Symbol;
639
                        Line line = obj1 as Line;
640
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
641
                            result = true;
642
                    }
643
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
644
                    {
645
                        Line line1 = obj2 as Line;
646
                        Line line2 = obj1 as Line;
647
                        Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
648
                        Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
649
                        if (connector1 == null && connector2 == null)
650
                            result = true;
651
                    }
652

    
653
                    if (result)
654
                    {
655
                        validationStringBuilder.AppendLine("Check SpecBreak UpStream, DownStream!");
656
                        validationStringBuilder.AppendLine("UID : " + item.UID);
657
                        validationStringBuilder.AppendLine();
658
                        validationResult = true;
659
                    }
660
                }
661
            }
662

    
663
            foreach (var item in EndBreaks)
664
            {
665
                object obj1 = SPPIDUtil.FindObjectByUID(this, item.OWNER);
666
                object obj2 = SPPIDUtil.FindObjectByUID(this, item.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
667
                if (obj1 == null || obj2 == null)
668
                {
669
                    validationStringBuilder.AppendLine("Check EndBreak Owner, Connected Item!");
670
                    validationStringBuilder.AppendLine("UID : " + item.UID);
671
                    validationStringBuilder.AppendLine();
672
                    validationResult = true;
673
                }
674
                else
675
                {
676
                    bool result = false;
677
                    if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Symbol))
678
                    {
679
                        Symbol symbol1 = obj1 as Symbol;
680
                        Symbol symbol2 = obj2 as Symbol;
681
                        if (symbol1.CONNECTORS.Find(x => x.ConnectedObject == symbol2) == null || symbol2.CONNECTORS.Find(x => x.ConnectedObject == symbol1) == null)
682
                            result = true;
683
                    }
684
                    else if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Line))
685
                    {
686
                        Symbol symbol = obj1 as Symbol;
687
                        Line line = obj2 as Line;
688
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
689
                            result = true;
690
                    }
691
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Symbol))
692
                    {
693
                        Symbol symbol = obj2 as Symbol;
694
                        Line line = obj1 as Line;
695
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
696
                            result = true;
697
                    }
698
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
699
                    {
700
                        Line line1 = obj2 as Line;
701
                        Line line2 = obj1 as Line;
702
                        Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
703
                        Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
704
                        if (connector1 == null && connector2 == null)
705
                            result = true;
706
                    }
707

    
708
                    if (result)
709
                    {
710
                        validationStringBuilder.AppendLine("Check EndBreak Owner, Connected Item!");
711
                        validationStringBuilder.AppendLine("UID : " + item.UID);
712
                        validationStringBuilder.AppendLine();
713
                        validationResult = true;
714
                    }
715
                }
716
            }
717

    
718
            #endregion
719

    
720
            #region Check Flow Direction
721
            foreach (var line in LINES)
722
            {
723
                foreach (var connector in line.CONNECTORS)
724
                {
725
                    if (connector.ConnectedObject != null &&
726
                        connector.ConnectedObject.GetType() == typeof(Line) &&
727
                        !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line))
728
                    {
729
                        Line connLine = connector.ConnectedObject as Line;
730
                        int lineIndex1 = line.CONNECTORS.IndexOf(connector);
731
                        int lineIndex2 = connLine.CONNECTORS.IndexOf(connLine.CONNECTORS.Find(x => x.ConnectedObject == line));
732
                        if (lineIndex1 == lineIndex2 && !SPPIDUtil.IsSegmentLine(this, line, connLine))
733
                        {
734
                            validationStringBuilder.AppendLine("Check line flow direction!");
735
                            validationStringBuilder.AppendLine("UID : " + line.UID);
736
                            validationStringBuilder.AppendLine("UID : " + connLine.UID);
737
                            validationStringBuilder.AppendLine();
738
                            validationResult = true;
739
                        }
740
                    }
741
                }
742
            }
743
            #endregion
744

    
745
            #region Association Check
746
            foreach (var item in TEXTINFOS)
747
            {
748
                if (item.ASSOCIATION)
749
                {
750
                    object owner = SPPIDUtil.FindObjectByUID(this, item.OWNER);
751
                    if (owner == null)
752
                    {
753
                        validationStringBuilder.AppendLine("Check text owner!");
754
                        validationStringBuilder.AppendLine("Text UID : " + item.UID);
755
                        foreach (var associationItem in SYMBOLS.FindAll(x => x.ATTRIBUTES.Find(y => y.ASSOCITEM == item.UID) != null))
756
                            validationStringBuilder.AppendLine("Association UID : " + associationItem.UID);
757

    
758
                        validationStringBuilder.AppendLine();
759
                        validationResult = true;    
760
                    }
761
                }
762
            }
763
            #endregion
764

    
765
            if (validationResult)
766
            {
767
                _Enable = false;
768
                SPPID.Form.MessageForm message = new SPPID.Form.MessageForm(validationStringBuilder.ToString());
769
                message.ShowDialog();
770
            }
771
        }
772
    }
773
}
클립보드 이미지 추가 (최대 크기: 500 MB)