프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / BaseModel / Document.cs @ 4ee5c4bf

이력 | 보기 | 이력해설 | 다운로드 (37.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
        private bool _Validation;
30
        private string _ValidationMessage;
31
        bool validationResult = false;
32

    
33
        public bool Enable { get { return _Enable; } }
34
        public bool Validation { get { return _Validation; } }
35
        public string ValidationMessage { get { return _ValidationMessage; } }
36

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

    
68
        StringBuilder validationStringBuilder = new StringBuilder();
69

    
70
        public Document(string xmlPath)
71
        {
72
            validationStringBuilder.AppendLine("Document Path : " + xmlPath);
73
            validationStringBuilder.AppendLine("");
74
            try
75
            {
76
                if (xmlPath != null)
77
                {
78
                    PATH = xmlPath;
79
                    XElement xml = XElement.Load(xmlPath);
80
                    DWGNAME = xml.Element("DWGNAME").Value;
81
                    SIZE = xml.Element("SIZE").Value;
82

    
83
                    validationStringBuilder.AppendLine("Drawing Name : " + DWGNAME);
84
                    validationStringBuilder.AppendLine("");
85

    
86
                    SetText(xml.Element("TEXTINFOS"));
87
                    SetNote(xml.Element("NOTES"));
88
                    SetSymbol(xml.Element("SYMBOLS"));
89
                    SetLine(xml.Element("LINEINFOS"));
90
                    SetLineNumber(xml.Element("LINENOS"));
91
                    SetTrimLine(xml.Element("TRIMLINENOS"));
92

    
93
                    SetAllConnectors();
94
                    _Enable = true;
95
                    ValidationCheck();
96
                }
97
            }
98
            catch (Exception ex)
99
            {
100
                _Enable = false;
101
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
102
            }
103
        }
104

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

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

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

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

    
223
                    SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS);
224
                    SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT);
225
                    SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES);
226
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES);
227
                    SetChildSymbol(symbol);
228

    
229
                    SYMBOLS.Add(symbol);
230
                }
231
            }
232
        }
233

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

    
258
                SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS);
259
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
260
                SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES);
261
                LINES.Add(line);
262
            }
263
        }
264

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

    
283
                SetLineNumberRuns(item, lineNumber.RUNS);
284
                SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
285
                SetAttributes(item, lineNumber.ATTRIBUTES);
286
                LINENUMBERS.Add(lineNumber);
287
            }
288
        }
289

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

    
309
                TEXTINFOS.Add(text);
310
            }
311
        }
312

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

    
332
                NOTES.Add(note);
333
            }
334
        }
335

    
336
        private void SetTrimLine(XElement node)
337
        {
338
            foreach (XElement item in node.Elements("TRIM_LINE_NO"))
339
            {
340
                TrimLine trimLine = new TrimLine()
341
                {
342
                    UID = item.Element("UID").Value,
343
                };
344
                SetLineNumberRuns(item, trimLine.RUNS);
345
                TRIMLINES.Add(trimLine);
346
            }
347
        }
348

    
349
        private void SetAssociations(XElement node, List<Association> associations)
350
        {
351
            foreach (XElement item in node.Elements("ASSOCIATION"))
352
            {
353
                Association association = new Association()
354
                {
355
                    TYPE = item.Attribute("TYPE").Value,
356
                    VALUE = item.Value
357
                };
358

    
359
                associations.Add(association);
360
            }
361
        }
362

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

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

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

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

    
427
                attributes.Add(attribute);
428

    
429
                if (!string.IsNullOrEmpty(attribute.ASSOCITEM) && attribute.ASSOCITEM != "None")
430
                {
431
                    Text text = _TEXTINFOS.Find(x => x.UID == attribute.ASSOCITEM);
432
                    if (text != null)
433
                        text.ASSOCIATION = true;
434
                }
435
            }
436
        }
437

    
438
        private void SetSpecBreakAttribute(SpecBreak specBreak)
439
        {
440
            string upStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "UpStream").VALUE;
441
            string downStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "DownStream").VALUE;
442

    
443
            specBreak.UpStreamUID = upStream;
444
            specBreak.DownStreamUID = downStream;
445
        }
446

    
447
        private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns)
448
        {
449
            foreach (XElement item in node.Elements("RUN"))
450
            {
451
                LineRun run = new LineRun()
452
                {
453
                    TYPE = item.Attribute("TYPE").Value
454
                };
455

    
456
                foreach (XElement element in item.Elements())
457
                {
458
                    if (element.Name == "SYMBOL")
459
                    {
460
                        Symbol symbol = GetSymbolByUID(element.Element("UID").Value);
461
                        if (symbol == null)
462
                        {
463
                            validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
464
                            validationStringBuilder.AppendLine();
465
                            validationResult = true;
466
                        }
467
                        run.RUNITEMS.Add(symbol);
468
                    }
469
                    else if (element.Name == "LINE")
470
                    {
471
                        Line line = GetLineByUID(element.Element("UID").Value);
472
                        if (line == null)
473
                        {
474
                            validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
475
                            validationStringBuilder.AppendLine();
476
                            validationResult = true;
477
                        }
478
                        run.RUNITEMS.Add(line);
479
                    }
480
                }
481
                lineNumberRuns.Add(run);
482
            }
483
        }
484

    
485
        private void SetChildSymbol(Symbol symbol)
486
        {
487
            List<ChildSymbol> childList = new List<ChildSymbol>();
488
            if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None")
489
            {
490
                string[] childArray = symbol.CHILD.Split(new char[] { '/' });
491
                foreach (string sChild in childArray)
492
                {
493
                    string[] sChildInfo = sChild.Split(new char[] { ',' });
494
                    childList.Add(new ChildSymbol()
495
                    {
496
                        ParentAt = Convert.ToInt32(sChildInfo[0]),
497
                        Direction = sChildInfo[1],
498
                        NAME = sChildInfo[2]
499
                    });
500
                }
501

    
502
                foreach (ChildSymbol child in childList)
503
                {
504
                    if (child.ParentAt == 0)
505
                        symbol.ChildSymbols.Add(child);
506
                    else
507
                        childList[child.ParentAt - 1].ChildSymbols.Add(child);
508
                }
509
            }
510
            if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None")
511
            {
512
                // 현재 부모 Symbol에 자식 Connector까지 들어가 있음
513
                string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
514
                string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
515
                for (int i = 0; i < array.Length; i++)
516
                {
517
                    string[] arrConn = array[i].Split(new char[] { ',' });
518
                    int connIndex = Convert.ToInt32(arrConn[3]);
519
                    if (connIndex != 0)
520
                    {
521
                        childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]);
522
                        symbol.CONNECTORS[i].Index = connIndex;
523
                    }
524
                }
525
            }
526
        }
527
        #endregion
528

    
529
        public Symbol GetSymbolByUID(string uid)
530
        {
531
            return SYMBOLS.Find(x => x.UID == uid);
532
        }
533

    
534
        public Line GetLineByUID(string uid)
535
        {
536
            return LINES.Find(x => x.UID == uid);
537
        }
538

    
539
        public void SetAllConnectors()
540
        {
541
            foreach (var item in SYMBOLS)
542
                foreach (var connector in item.CONNECTORS)
543
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
544

    
545
            foreach (var item in LINES)
546
                foreach (var connector in item.CONNECTORS)
547
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
548

    
549
            foreach (var item in Equipments)
550
                foreach (var connector in item.CONNECTORS)
551
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
552
        }
553

    
554
        
555

    
556
        public void ValidationCheck()
557
        {
558
           
559
            #region Connection Check / Symbol의 SceneConnectPoint Check
560
            foreach (var item in _SYMBOLS)
561
            {
562
                foreach (var connector in item.CONNECTORS)
563
                {
564
                    if (connector.ConnectedObject != null && connector.ConnectedObject.GetType() == typeof(Line))
565
                    {
566
                        Line line = connector.ConnectedObject as Line;
567
                        if (line.CONNECTORS.Find(x => x.ConnectedObject == item) == null)
568
                        {
569
                            validationStringBuilder.AppendLine("Check connection!");
570
                            validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
571
                            validationStringBuilder.AppendLine("Line UID : " + line.UID);
572
                            validationStringBuilder.AppendLine();
573
                            validationResult = true;
574
                        }
575
                    }
576

    
577
                    if (connector.SCENECONNECTPOINT == connector.CONNECTPOINT)
578
                    {
579
                        validationStringBuilder.AppendLine("Check Symbol SceneConnectPoint!");
580
                        validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
581
                        validationStringBuilder.AppendLine();
582
                        validationResult = true;
583
                    }
584
                }
585
            }
586

    
587
            foreach (var item in _LINES)
588
            {
589
                foreach (var connector in item.CONNECTORS)
590
                {
591
                    if (connector.ConnectedObject != null && connector.ConnectedObject.GetType() == typeof(Symbol))
592
                    {
593
                        Symbol symbol = connector.ConnectedObject as Symbol;
594
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == item) == null)
595
                        {
596
                            validationStringBuilder.AppendLine("Check connection!");
597
                            validationStringBuilder.AppendLine("Symbol UID : " + symbol.UID);
598
                            validationStringBuilder.AppendLine("Line UID : " + item.UID);
599
                            validationStringBuilder.AppendLine();
600
                            validationResult = true;
601
                        }
602
                    }
603
                }
604
            }
605
            #endregion
606

    
607
            #region Symbol Size Check
608
            foreach (var item in _SYMBOLS)
609
            {
610
                if (item.SIZE == "0,0")
611
                {
612
                    validationStringBuilder.AppendLine("Check symbol size!");
613
                    validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
614
                    validationStringBuilder.AppendLine();
615
                    validationResult = true;
616
                }
617
            }
618
            #endregion
619

    
620
            #region SpecBreak, EndBreak Check
621
            foreach (var item in SpecBreaks)
622
            {
623
                object obj1 = SPPIDUtil.FindObjectByUID(this, item.UpStreamUID);
624
                object obj2 = SPPIDUtil.FindObjectByUID(this, item.DownStreamUID);
625
                if (obj1 == null || obj2 == null)
626
                {
627
                    validationStringBuilder.AppendLine("Check SpecBreak UpStream, DownStream!");
628
                    validationStringBuilder.AppendLine("UID : " + item.UID);
629
                    validationStringBuilder.AppendLine();
630
                    validationResult = true;
631
                }
632
                else
633
                {
634
                    bool result = false;
635
                    if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Symbol))
636
                    {
637
                        Symbol symbol1 = obj1 as Symbol;
638
                        Symbol symbol2 = obj2 as Symbol;
639
                        if (symbol1.CONNECTORS.Find(x => x.ConnectedObject == symbol2) == null || symbol2.CONNECTORS.Find(x => x.ConnectedObject == symbol1) == null)
640
                            result = true;
641
                    }
642
                    else if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Line))
643
                    {
644
                        Symbol symbol = obj1 as Symbol;
645
                        Line line = obj2 as Line;
646
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
647
                            result = true;
648
                    }
649
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Symbol))
650
                    {
651
                        Symbol symbol = obj2 as Symbol;
652
                        Line line = obj1 as Line;
653
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
654
                            result = true;
655
                    }
656
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
657
                    {
658
                        Line line1 = obj2 as Line;
659
                        Line line2 = obj1 as Line;
660
                        Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
661
                        Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
662
                        if (connector1 == null && connector2 == null)
663
                            result = true;
664
                    }
665

    
666
                    if (result)
667
                    {
668
                        validationStringBuilder.AppendLine("Check SpecBreak UpStream, DownStream!");
669
                        validationStringBuilder.AppendLine("UID : " + item.UID);
670
                        validationStringBuilder.AppendLine();
671
                        validationResult = true;
672
                    }
673
                }
674
            }
675

    
676
            foreach (var item in EndBreaks)
677
            {
678
                object obj1 = SPPIDUtil.FindObjectByUID(this, item.OWNER);
679
                object obj2 = SPPIDUtil.FindObjectByUID(this, item.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
680
                if (obj1 == null || obj2 == null)
681
                {
682
                    validationStringBuilder.AppendLine("Check EndBreak Owner, Connected Item!");
683
                    validationStringBuilder.AppendLine("UID : " + item.UID);
684
                    validationStringBuilder.AppendLine();
685
                    validationResult = true;
686
                }
687
                else
688
                {
689
                    bool result = false;
690
                    if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Symbol))
691
                    {
692
                        Symbol symbol1 = obj1 as Symbol;
693
                        Symbol symbol2 = obj2 as Symbol;
694
                        if (symbol1.CONNECTORS.Find(x => x.ConnectedObject == symbol2) == null || symbol2.CONNECTORS.Find(x => x.ConnectedObject == symbol1) == null)
695
                            result = true;
696
                    }
697
                    else if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Line))
698
                    {
699
                        Symbol symbol = obj1 as Symbol;
700
                        Line line = obj2 as Line;
701
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
702
                            result = true;
703
                    }
704
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Symbol))
705
                    {
706
                        Symbol symbol = obj2 as Symbol;
707
                        Line line = obj1 as Line;
708
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
709
                            result = true;
710
                    }
711
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
712
                    {
713
                        Line line1 = obj2 as Line;
714
                        Line line2 = obj1 as Line;
715
                        Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
716
                        Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
717
                        if (connector1 == null && connector2 == null)
718
                            result = true;
719
                    }
720

    
721
                    if (result)
722
                    {
723
                        validationStringBuilder.AppendLine("Check EndBreak Owner, Connected Item!");
724
                        validationStringBuilder.AppendLine("UID : " + item.UID);
725
                        validationStringBuilder.AppendLine();
726
                        validationResult = true;
727
                    }
728
                }
729
            }
730

    
731
            #endregion
732

    
733
            #region Check Flow Direction
734
            foreach (var line in LINES)
735
            {
736
                foreach (var connector in line.CONNECTORS)
737
                {
738
                    if (connector.ConnectedObject != null &&
739
                        connector.ConnectedObject.GetType() == typeof(Line) &&
740
                        !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line))
741
                    {
742
                        Line connLine = connector.ConnectedObject as Line;
743
                        int lineIndex1 = line.CONNECTORS.IndexOf(connector);
744
                        int lineIndex2 = connLine.CONNECTORS.IndexOf(connLine.CONNECTORS.Find(x => x.ConnectedObject == line));
745
                        if (lineIndex1 == lineIndex2 && !SPPIDUtil.IsSegmentLine(this, line, connLine))
746
                        {
747
                            validationStringBuilder.AppendLine("Check line flow direction!");
748
                            validationStringBuilder.AppendLine("UID : " + line.UID);
749
                            validationStringBuilder.AppendLine("UID : " + connLine.UID);
750
                            validationStringBuilder.AppendLine();
751
                            validationResult = true;
752
                        }
753
                    }
754
                }
755
            }
756

    
757
            foreach (var item in SYMBOLS.FindAll(x => x.CONNECTORS.Count == 2 &&
758
            x.CONNECTORS[0].ConnectedObject != null && x.CONNECTORS[0].ConnectedObject.GetType() == typeof(Line) &&
759
            x.CONNECTORS[1].ConnectedObject != null && x.CONNECTORS[1].ConnectedObject.GetType() == typeof(Line)))
760
            {
761
                Line line1 = item.CONNECTORS[0].ConnectedObject as Line;
762
                Line line2 = item.CONNECTORS[1].ConnectedObject as Line;
763
                if (line1.TYPE == line2.TYPE)
764
                {
765
                    int index1 = line1.CONNECTORS.IndexOf(line1.CONNECTORS.Find(x => x.ConnectedObject == item));
766
                    int index2 = line2.CONNECTORS.IndexOf(line2.CONNECTORS.Find(x => x.ConnectedObject == item));
767
                    if (index1 == index2)
768
                    {
769
                        validationStringBuilder.AppendLine("Check line flow direction!");
770
                        validationStringBuilder.AppendLine("UID : " + line1.UID);
771
                        validationStringBuilder.AppendLine("UID : " + line2.UID);
772
                        validationStringBuilder.AppendLine();
773
                        validationResult = true;
774
                    }
775
                }
776
            }
777
            #endregion
778

    
779
            #region Association Check
780
            foreach (var item in TEXTINFOS)
781
            {
782
                if (item.ASSOCIATION)
783
                {
784
                    object owner = SPPIDUtil.FindObjectByUID(this, item.OWNER);
785
                    if (owner == null)
786
                    {
787
                        validationStringBuilder.AppendLine("Check text owner!");
788
                        validationStringBuilder.AppendLine("Text UID : " + item.UID);
789
                        foreach (var associationItem in SYMBOLS.FindAll(x => x.ATTRIBUTES.Find(y => y.ASSOCITEM == item.UID) != null))
790
                            validationStringBuilder.AppendLine("Association UID : " + associationItem.UID);
791

    
792
                        validationStringBuilder.AppendLine();
793
                        validationResult = true;    
794
                    }
795
                }
796
            }
797
            #endregion
798

    
799
            #region Line To Line Type Check
800
            List<string[]> typeCheck = new List<string[]>();
801
            foreach (var item in LINES)
802
            {
803
                foreach (var connector in item.CONNECTORS)
804
                {
805
                    Line connLine = connector.ConnectedObject as Line;
806
                    if (connLine != null && connLine.CONNECTORS.Find(x => x.ConnectedObject == item) != null && 
807
                        connLine.TYPE != item.TYPE &&
808
                        typeCheck.Find(x => (x[0] == item.UID || x[1] == connLine.UID) || (x[1] == item.UID || x[0] == connLine.UID)) == null)
809
                    {
810
                        validationStringBuilder.AppendLine("Check line type!");
811
                        validationStringBuilder.AppendLine("UID : " + item.UID);
812
                        validationStringBuilder.AppendLine("UID : " + connLine.UID);
813
                        validationStringBuilder.AppendLine();
814
                        validationResult = true;
815
                        typeCheck.Add(new string[] { item.UID, connLine.UID });
816
                    }
817
                }
818
            }
819
            #endregion
820

    
821
            if (validationResult)
822
            {
823
                _Validation = false;
824
                _Enable = false;
825
                _ValidationMessage = validationStringBuilder.ToString();
826
            }
827
            else
828
            {
829
                _Validation = true;
830
                _Enable = true;
831
                _ValidationMessage = "";
832
            }
833
        }
834
    }
835
}
클립보드 이미지 추가 (최대 크기: 500 MB)