프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / BaseModel / Document.cs @ 02a45794

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

1 96a2080c gaqhf
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 d63050d6 gaqhf
using Converter.SPPID.Util;
10 96a2080c gaqhf
11
namespace Converter.BaseModel
12
{
13
    public class Document
14
    {
15
        private string _DWGNAME;
16
        private string _SIZE;
17 39a2a688 gaqhf
        private double _SIZE_WIDTH;
18
        private double _SIZE_HEIGHT;
19 60244a8b gaqhf
        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 8aa6f2db gaqhf
        private List<TrimLine> _TRIMLINES = new List<TrimLine>();
25 f1c9dbaa gaqhf
        private List<EndBreak> _EndBreaks = new List<EndBreak>();
26 53c81765 gaqhf
        private List<SpecBreak> _SpecBreaks = new List<SpecBreak>();
27 f1c9dbaa gaqhf
        private List<Equipment> _Equipments = new List<Equipment>();
28 60244a8b gaqhf
        private bool _Enable;
29 0a111e7d gaqhf
        private bool _Validation;
30
        private string _ValidationMessage;
31
        bool validationResult = false;
32 60244a8b gaqhf
33
        public bool Enable { get { return _Enable; } }
34 0a111e7d gaqhf
        public bool Validation { get { return _Validation; } }
35
        public string ValidationMessage { get { return _ValidationMessage; } }
36 96a2080c gaqhf
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 f1c9dbaa gaqhf
        public List<EndBreak> EndBreaks { get => _EndBreaks; set => _EndBreaks = value; }
43 53c81765 gaqhf
        public List<SpecBreak> SpecBreaks { get => _SpecBreaks; set => _SpecBreaks = value; }
44 f1c9dbaa gaqhf
        public List<Equipment> Equipments { get => _Equipments; set => _Equipments = value; }
45 96a2080c gaqhf
        public string DWGNAME { get => _DWGNAME; set => _DWGNAME = value; }
46 39a2a688 gaqhf
        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 8aa6f2db gaqhf
        public List<TrimLine> TRIMLINES { get => _TRIMLINES; set => _TRIMLINES = value; }
66 e8536f2b gaqhf
        public string PATH { get; set; }
67 96a2080c gaqhf
68 a0e3dca4 gaqhf
        StringBuilder validationStringBuilder = new StringBuilder();
69
70 96a2080c gaqhf
        public Document(string xmlPath)
71
        {
72 a0e3dca4 gaqhf
            validationStringBuilder.AppendLine("Document Path : " + xmlPath);
73
            validationStringBuilder.AppendLine("");
74 96a2080c gaqhf
            try
75
            {
76 88bac50c gaqhf
                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 96a2080c gaqhf
83 a0e3dca4 gaqhf
                    validationStringBuilder.AppendLine("Drawing Name : " + DWGNAME);
84
                    validationStringBuilder.AppendLine("");
85
86 88bac50c gaqhf
                    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 60244a8b gaqhf
93 d63050d6 gaqhf
                    SetAllConnectors();
94 88bac50c gaqhf
                    _Enable = true;
95 63c5305b gaqhf
                    ValidationCheck();
96 88bac50c gaqhf
                }
97 96a2080c gaqhf
            }
98
            catch (Exception ex)
99
            {
100 60244a8b gaqhf
                _Enable = false;
101 96a2080c gaqhf
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
102
            }
103
        }
104
105 60244a8b gaqhf
        #region READ XML
106 96a2080c gaqhf
        private void SetSymbol(XElement node)
107
        {
108
            foreach (XElement item in node.Elements("SYMBOL"))
109
            {
110 f1c9dbaa gaqhf
                string sType = item.Element("TYPE").Value;
111
                if (sType == "Segment Breaks")
112 96a2080c gaqhf
                {
113 53c81765 gaqhf
                    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 f1c9dbaa gaqhf
                }
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 bca81f4c gaqhf
199 f1c9dbaa gaqhf
                    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 8aa6f2db gaqhf
223 f1c9dbaa gaqhf
                    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 96a2080c gaqhf
            }
232
        }
233
234
        private void SetLine(XElement node)
235
        {
236
            foreach (XElement item in node.Elements("LINE"))
237
            {
238 60244a8b gaqhf
                Line line = new Line()
239 96a2080c gaqhf
                {
240 60244a8b gaqhf
                    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 30d2cfcc gaqhf
                    TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value,
246 60244a8b gaqhf
                    AREA = item.Element("AREA").Value,
247
                    THICKNESS = item.Element("THICKNESS").Value,
248
                };
249 b2d1c1aa gaqhf
                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 0860c756 gaqhf
                SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS);
259 cfda1fed gaqhf
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
260 0860c756 gaqhf
                SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES);
261 60244a8b gaqhf
                LINES.Add(line);
262 96a2080c gaqhf
            }
263
        }
264
265
        private void SetLineNumber(XElement node)
266
        {
267
            foreach (XElement item in node.Elements("LINE_NO"))
268
            {
269 3734dcc5 gaqhf
                LineNumber lineNumber = new LineNumber()
270 96a2080c gaqhf
                {
271 3734dcc5 gaqhf
                    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 8701de36 gaqhf
                else
283
                {
284
                    validationStringBuilder.AppendLine("Not exist CONNLINE!" + "\r\nLineNumber UID : " + lineNumber.CONNLINE);
285
                    validationStringBuilder.AppendLine();
286
                    validationResult = true;
287
                }
288 3734dcc5 gaqhf
289
                SetLineNumberRuns(item, lineNumber.RUNS);
290
                SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
291
                SetAttributes(item, lineNumber.ATTRIBUTES);
292
                LINENUMBERS.Add(lineNumber);
293 96a2080c gaqhf
            }
294
        }
295
296
        private void SetText(XElement node)
297
        {
298
            foreach (XElement item in node.Elements("ATTRIBUTE"))
299
            {
300 60244a8b gaqhf
                Text text = new Text()
301 96a2080c gaqhf
                {
302 60244a8b gaqhf
                    UID = item.Element("UID").Value,
303 ea80efaa gaqhf
                    OWNER = item.Element("OWNER").Value,
304 60244a8b gaqhf
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
305
                    NAME = item.Element("NAME").Value,
306
                    LOCATION = item.Element("LOCATION").Value,
307
                    VALUE = item.Element("VALUE").Value,
308
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
309
                    WIDTH = item.Element("WIDTH").Value,
310
                    HEIGHT = item.Element("HEIGHT").Value,
311 1a3a74a8 gaqhf
                    AREA = item.Element("AREA").Value,
312
                    SCENE = item.Element("SCENE").Value
313 60244a8b gaqhf
                };
314 96a2080c gaqhf
315 60244a8b gaqhf
                TEXTINFOS.Add(text);
316 96a2080c gaqhf
            }
317
        }
318
319
        private void SetNote(XElement node)
320
        {
321
            foreach (XElement item in node.Elements("ATTRIBUTE"))
322
            {
323 60244a8b gaqhf
                Note note = new Note()
324 96a2080c gaqhf
                {
325 60244a8b gaqhf
                    UID = item.Element("UID").Value,
326
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
327
                    NAME = item.Element("NAME").Value,
328
                    LOCATION = item.Element("LOCATION").Value,
329
                    VALUE = item.Element("VALUE").Value,
330
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
331
                    WIDTH = item.Element("WIDTH").Value,
332
                    HEIGHT = item.Element("HEIGHT").Value,
333 1a3a74a8 gaqhf
                    AREA = item.Element("AREA").Value,
334 fc0a8c33 gaqhf
                    SCENE = item.Element("SCENE").Value,
335
                    OWNER = item.Element("OWNER").Value
336 60244a8b gaqhf
                };
337 96a2080c gaqhf
338 60244a8b gaqhf
                NOTES.Add(note);
339
            }
340
        }
341 8aa6f2db gaqhf
342
        private void SetTrimLine(XElement node)
343
        {
344
            foreach (XElement item in node.Elements("TRIM_LINE_NO"))
345
            {
346
                TrimLine trimLine = new TrimLine()
347
                {
348
                    UID = item.Element("UID").Value,
349
                };
350
                SetLineNumberRuns(item, trimLine.RUNS);
351
                TRIMLINES.Add(trimLine);
352
            }
353
        }
354
355 60244a8b gaqhf
        private void SetAssociations(XElement node, List<Association> associations)
356
        {
357
            foreach (XElement item in node.Elements("ASSOCIATION"))
358
            {
359 ea80efaa gaqhf
                Association association = new Association()
360 60244a8b gaqhf
                {
361
                    TYPE = item.Attribute("TYPE").Value,
362
                    VALUE = item.Value
363 ea80efaa gaqhf
                };
364
365
                associations.Add(association);
366 96a2080c gaqhf
            }
367
        }
368 60244a8b gaqhf
369
        private void SetConnectors(XElement node, List<Connector> connectors)
370
        {
371
            foreach (XElement item in node.Elements("CONNECTOR"))
372
            {
373
                connectors.Add(new Connector()
374
                {
375
                    UID = item.Attribute("UID").Value,
376
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
377 bca81f4c gaqhf
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
378
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
379
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
380
                });
381
            }
382
        }
383
384
        private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT)
385
        {
386
            foreach (XElement item in node.Elements("CONNECTOR"))
387
            {
388
                connectors.Add(new Connector()
389
                {
390
                    UID = item.Attribute("UID").Value,
391
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
392 60244a8b gaqhf
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
393
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
394
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
395
                });
396
            }
397
        }
398
399
        private void SetProperties(XElement node, List<Property> properties)
400
        {
401
            foreach (XElement item in node.Elements("PROPERTY"))
402
            {
403 30d2cfcc gaqhf
                properties.Add(new Property()
404 60244a8b gaqhf
                {
405 30d2cfcc gaqhf
                    UID = item.Attribute("UID").Value,
406
                    LENGTH = item.Attribute("Length").Value,
407
                    EXPRESSION = item.Attribute("Expression").Value,
408
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
409
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
410
                    ATTRIBUTE = item.Attribute("Attribute").Value,
411
                    VALUE = item.Value
412
                });
413 60244a8b gaqhf
            }
414
        }
415
416
        private void SetAttributes(XElement node, List<Attribute> attributes)
417
        {
418 30d2cfcc gaqhf
            foreach (XElement item in node.Elements("ATTRIBUTE"))
419 60244a8b gaqhf
            {
420 73415441 gaqhf
                Attribute attribute = new Attribute()
421 60244a8b gaqhf
                {
422
                    UID = item.Attribute("UID").Value,
423
                    LENGTH = item.Attribute("Length").Value,
424
                    EXPRESSION = item.Attribute("Expression").Value,
425
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
426
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
427
                    ATTRIBUTE = item.Attribute("Attribute").Value,
428 30d2cfcc gaqhf
                    ATTRAT = item.Attribute("AttrAt").Value,
429 73415441 gaqhf
                    ASSOCITEM = item.Attribute("AssocItem").Value,
430 60244a8b gaqhf
                    VALUE = item.Value
431 73415441 gaqhf
                };
432
433
                attributes.Add(attribute);
434
435
                if (!string.IsNullOrEmpty(attribute.ASSOCITEM) && attribute.ASSOCITEM != "None")
436
                {
437
                    Text text = _TEXTINFOS.Find(x => x.UID == attribute.ASSOCITEM);
438
                    if (text != null)
439
                        text.ASSOCIATION = true;
440
                }
441 60244a8b gaqhf
            }
442
        }
443
444 53c81765 gaqhf
        private void SetSpecBreakAttribute(SpecBreak specBreak)
445
        {
446
            string upStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "UpStream").VALUE;
447
            string downStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "DownStream").VALUE;
448
449
            specBreak.UpStreamUID = upStream;
450
            specBreak.DownStreamUID = downStream;
451
        }
452
453 8aa6f2db gaqhf
        private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns)
454 60244a8b gaqhf
        {
455
            foreach (XElement item in node.Elements("RUN"))
456
            {
457 8aa6f2db gaqhf
                LineRun run = new LineRun()
458 60244a8b gaqhf
                {
459
                    TYPE = item.Attribute("TYPE").Value
460
                };
461
462
                foreach (XElement element in item.Elements())
463
                {
464
                    if (element.Name == "SYMBOL")
465
                    {
466 c3d2e266 gaqhf
                        Symbol symbol = GetSymbolByUID(element.Element("UID").Value);
467
                        if (symbol == null)
468 0a111e7d gaqhf
                        {
469
                            validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
470
                            validationStringBuilder.AppendLine();
471
                            validationResult = true;
472
                        }
473 c3d2e266 gaqhf
                        run.RUNITEMS.Add(symbol);
474 60244a8b gaqhf
                    }
475
                    else if (element.Name == "LINE")
476
                    {
477 c3d2e266 gaqhf
                        Line line = GetLineByUID(element.Element("UID").Value);
478
                        if (line == null)
479 0a111e7d gaqhf
                        {
480
                            validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
481
                            validationStringBuilder.AppendLine();
482
                            validationResult = true;
483
                        }
484 c3d2e266 gaqhf
                        run.RUNITEMS.Add(line);
485 60244a8b gaqhf
                    }
486
                }
487
                lineNumberRuns.Add(run);
488
            }
489
        }
490 30d2cfcc gaqhf
491
        private void SetChildSymbol(Symbol symbol)
492
        {
493
            List<ChildSymbol> childList = new List<ChildSymbol>();
494
            if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None")
495
            {
496
                string[] childArray = symbol.CHILD.Split(new char[] { '/' });
497
                foreach (string sChild in childArray)
498
                {
499
                    string[] sChildInfo = sChild.Split(new char[] { ',' });
500
                    childList.Add(new ChildSymbol()
501
                    {
502
                        ParentAt = Convert.ToInt32(sChildInfo[0]),
503
                        Direction = sChildInfo[1],
504
                        NAME = sChildInfo[2]
505
                    });
506
                }
507
508
                foreach (ChildSymbol child in childList)
509
                {
510
                    if (child.ParentAt == 0)
511
                        symbol.ChildSymbols.Add(child);
512
                    else
513
                        childList[child.ParentAt - 1].ChildSymbols.Add(child);
514
                }
515
            }
516
            if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None")
517
            {
518 f1c9dbaa gaqhf
                // 현재 부모 Symbol에 자식 Connector까지 들어가 있음
519 30d2cfcc gaqhf
                string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
520
                string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
521
                for (int i = 0; i < array.Length; i++)
522
                {
523
                    string[] arrConn = array[i].Split(new char[] { ',' });
524
                    int connIndex = Convert.ToInt32(arrConn[3]);
525
                    if (connIndex != 0)
526 5dfb8a24 gaqhf
                    {
527 30d2cfcc gaqhf
                        childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]);
528 f1c9dbaa gaqhf
                        symbol.CONNECTORS[i].Index = connIndex;
529 5dfb8a24 gaqhf
                    }
530
                }
531 30d2cfcc gaqhf
            }
532
        }
533 60244a8b gaqhf
        #endregion
534
535
        public Symbol GetSymbolByUID(string uid)
536
        {
537
            return SYMBOLS.Find(x => x.UID == uid);
538
        }
539
540
        public Line GetLineByUID(string uid)
541
        {
542
            return LINES.Find(x => x.UID == uid);
543
        }
544 d63050d6 gaqhf
545
        public void SetAllConnectors()
546
        {
547
            foreach (var item in SYMBOLS)
548
                foreach (var connector in item.CONNECTORS)
549
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
550
551
            foreach (var item in LINES)
552
                foreach (var connector in item.CONNECTORS)
553
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
554
555
            foreach (var item in Equipments)
556
                foreach (var connector in item.CONNECTORS)
557
                    connector.ConnectedObject = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
558
        }
559 a0e3dca4 gaqhf
560
        
561
562
        public void ValidationCheck()
563
        {
564 0a111e7d gaqhf
           
565 026f394f gaqhf
            #region Connection Check / Symbol의 SceneConnectPoint Check
566 a0e3dca4 gaqhf
            foreach (var item in _SYMBOLS)
567
            {
568
                foreach (var connector in item.CONNECTORS)
569
                {
570
                    if (connector.ConnectedObject != null && connector.ConnectedObject.GetType() == typeof(Line))
571
                    {
572
                        Line line = connector.ConnectedObject as Line;
573
                        if (line.CONNECTORS.Find(x => x.ConnectedObject == item) == null)
574
                        {
575
                            validationStringBuilder.AppendLine("Check connection!");
576
                            validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
577
                            validationStringBuilder.AppendLine("Line UID : " + line.UID);
578 63c5305b gaqhf
                            validationStringBuilder.AppendLine();
579
                            validationResult = true;
580 a0e3dca4 gaqhf
                        }
581
                    }
582
583
                    if (connector.SCENECONNECTPOINT == connector.CONNECTPOINT)
584
                    {
585
                        validationStringBuilder.AppendLine("Check Symbol SceneConnectPoint!");
586
                        validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
587 63c5305b gaqhf
                        validationStringBuilder.AppendLine();
588
                        validationResult = true;
589 a0e3dca4 gaqhf
                    }
590
                }
591
            }
592
593
            foreach (var item in _LINES)
594
            {
595
                foreach (var connector in item.CONNECTORS)
596
                {
597
                    if (connector.ConnectedObject != null && connector.ConnectedObject.GetType() == typeof(Symbol))
598
                    {
599
                        Symbol symbol = connector.ConnectedObject as Symbol;
600
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == item) == null)
601
                        {
602
                            validationStringBuilder.AppendLine("Check connection!");
603
                            validationStringBuilder.AppendLine("Symbol UID : " + symbol.UID);
604
                            validationStringBuilder.AppendLine("Line UID : " + item.UID);
605 63c5305b gaqhf
                            validationStringBuilder.AppendLine();
606
                            validationResult = true;
607 a0e3dca4 gaqhf
                        }
608
                    }
609
                }
610
            }
611
            #endregion
612
613
            #region Symbol Size Check
614
            foreach (var item in _SYMBOLS)
615
            {
616
                if (item.SIZE == "0,0")
617
                {
618
                    validationStringBuilder.AppendLine("Check symbol size!");
619
                    validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
620 63c5305b gaqhf
                    validationStringBuilder.AppendLine();
621
                    validationResult = true;
622 a0e3dca4 gaqhf
                }
623
            }
624
            #endregion
625 026f394f gaqhf
626
            #region SpecBreak, EndBreak Check
627
            foreach (var item in SpecBreaks)
628
            {
629
                object obj1 = SPPIDUtil.FindObjectByUID(this, item.UpStreamUID);
630
                object obj2 = SPPIDUtil.FindObjectByUID(this, item.DownStreamUID);
631
                if (obj1 == null || obj2 == null)
632
                {
633
                    validationStringBuilder.AppendLine("Check SpecBreak UpStream, DownStream!");
634
                    validationStringBuilder.AppendLine("UID : " + item.UID);
635 63c5305b gaqhf
                    validationStringBuilder.AppendLine();
636
                    validationResult = true;
637 026f394f gaqhf
                }
638
                else
639
                {
640 02a45794 gaqhf
641 026f394f gaqhf
                    bool result = false;
642
                    if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Symbol))
643
                    {
644
                        Symbol symbol1 = obj1 as Symbol;
645
                        Symbol symbol2 = obj2 as Symbol;
646
                        if (symbol1.CONNECTORS.Find(x => x.ConnectedObject == symbol2) == null || symbol2.CONNECTORS.Find(x => x.ConnectedObject == symbol1) == null)
647
                            result = true;
648
                    }
649
                    else if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Line))
650
                    {
651
                        Symbol symbol = obj1 as Symbol;
652
                        Line line = obj2 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(Symbol))
657
                    {
658
                        Symbol symbol = obj2 as Symbol;
659
                        Line line = obj1 as Line;
660
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
661
                            result = true;
662
                    }
663
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
664
                    {
665
                        Line line1 = obj2 as Line;
666
                        Line line2 = obj1 as Line;
667
                        Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
668
                        Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
669
                        if (connector1 == null && connector2 == null)
670
                            result = true;
671
                    }
672
673
                    if (result)
674
                    {
675
                        validationStringBuilder.AppendLine("Check SpecBreak UpStream, DownStream!");
676
                        validationStringBuilder.AppendLine("UID : " + item.UID);
677 63c5305b gaqhf
                        validationStringBuilder.AppendLine();
678
                        validationResult = true;
679 026f394f gaqhf
                    }
680 02a45794 gaqhf
681
                    // Rule
682
                    if (!result)
683
                    {
684
                        if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
685
                        {
686
                            Line line1 = obj1 as Line;
687
                            Line line2 = obj2 as Line;
688
689
                            Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
690
                            Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
691
                            if (connector1 != null && connector2 != null)
692
                            {
693
                                int connectorIndex = line1.CONNECTORS.IndexOf(connector1);
694
                                if (connectorIndex != 0 && !SPPIDUtil.IsBranchLine(line1))
695
                                    result = true;
696
                                else if (connectorIndex == 0 && !SPPIDUtil.IsBranchLine(line1) && SPPIDUtil.IsBranchLine(line2))
697
                                    result = true;
698
699
                                if (result)
700
                                {
701
                                    validationStringBuilder.AppendLine("Check Segment Rule!");
702
                                    validationStringBuilder.AppendLine("UID : " + item.UID);
703
                                    validationStringBuilder.AppendLine();
704
                                    validationResult = true;
705
                                }
706
                            }
707
                        }
708
                    }
709 026f394f gaqhf
                }
710
            }
711
712
            foreach (var item in EndBreaks)
713
            {
714
                object obj1 = SPPIDUtil.FindObjectByUID(this, item.OWNER);
715
                object obj2 = SPPIDUtil.FindObjectByUID(this, item.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
716
                if (obj1 == null || obj2 == null)
717
                {
718
                    validationStringBuilder.AppendLine("Check EndBreak Owner, Connected Item!");
719
                    validationStringBuilder.AppendLine("UID : " + item.UID);
720 63c5305b gaqhf
                    validationStringBuilder.AppendLine();
721
                    validationResult = true;
722 026f394f gaqhf
                }
723
                else
724
                {
725
                    bool result = false;
726
                    if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Symbol))
727
                    {
728
                        Symbol symbol1 = obj1 as Symbol;
729
                        Symbol symbol2 = obj2 as Symbol;
730
                        if (symbol1.CONNECTORS.Find(x => x.ConnectedObject == symbol2) == null || symbol2.CONNECTORS.Find(x => x.ConnectedObject == symbol1) == null)
731
                            result = true;
732
                    }
733
                    else if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Line))
734
                    {
735
                        Symbol symbol = obj1 as Symbol;
736
                        Line line = obj2 as Line;
737
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
738
                            result = true;
739
                    }
740
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Symbol))
741
                    {
742
                        Symbol symbol = obj2 as Symbol;
743
                        Line line = obj1 as Line;
744
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
745
                            result = true;
746
                    }
747
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
748
                    {
749
                        Line line1 = obj2 as Line;
750
                        Line line2 = obj1 as Line;
751
                        Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
752
                        Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
753
                        if (connector1 == null && connector2 == null)
754
                            result = true;
755
                    }
756
757
                    if (result)
758
                    {
759
                        validationStringBuilder.AppendLine("Check EndBreak Owner, Connected Item!");
760
                        validationStringBuilder.AppendLine("UID : " + item.UID);
761 63c5305b gaqhf
                        validationStringBuilder.AppendLine();
762
                        validationResult = true;
763 026f394f gaqhf
                    }
764 02a45794 gaqhf
765
                    // Rule
766
                    if (!result) 
767
                    {
768
                        if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
769
                        {
770
                            Line line1 = obj1 as Line;
771
                            Line line2 = obj2 as Line;
772
773
                            Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
774
                            Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
775
                            if (connector1 != null && connector2 != null)
776
                            {
777
                                int connectorIndex = line1.CONNECTORS.IndexOf(connector1);
778
                                if (connectorIndex != 0 && !SPPIDUtil.IsBranchLine(line1))
779
                                    result = true;
780
                                else if (connectorIndex == 0 && !SPPIDUtil.IsBranchLine(line1) && SPPIDUtil.IsBranchLine(line2))
781
                                    result = true;
782
783
                                if (result)
784
                                {
785
                                    validationStringBuilder.AppendLine("Check Segment Rule!");
786
                                    validationStringBuilder.AppendLine("UID : " + item.UID);
787
                                    validationStringBuilder.AppendLine();
788
                                    validationResult = true;
789
                                }
790
                            }
791
                        }
792
                    }
793 026f394f gaqhf
                }
794
            }
795
796
            #endregion
797 d23fe61b gaqhf
798
            #region Check Flow Direction
799 02a45794 gaqhf
            List<string[]> flowDirectionCheck = new List<string[]>();
800 d23fe61b gaqhf
            foreach (var line in LINES)
801
            {
802
                foreach (var connector in line.CONNECTORS)
803
                {
804
                    if (connector.ConnectedObject != null &&
805
                        connector.ConnectedObject.GetType() == typeof(Line) &&
806
                        !SPPIDUtil.IsBranchLine(line, connector.ConnectedObject as Line))
807
                    {
808
                        Line connLine = connector.ConnectedObject as Line;
809
                        int lineIndex1 = line.CONNECTORS.IndexOf(connector);
810
                        int lineIndex2 = connLine.CONNECTORS.IndexOf(connLine.CONNECTORS.Find(x => x.ConnectedObject == line));
811 02a45794 gaqhf
                        if (lineIndex1 == lineIndex2 && flowDirectionCheck.Find(x => (x[0] == line.UID || x[1] == connLine.UID) || (x[1] == line.UID || x[0] == connLine.UID)) == null)
812 d23fe61b gaqhf
                        {
813
                            validationStringBuilder.AppendLine("Check line flow direction!");
814
                            validationStringBuilder.AppendLine("UID : " + line.UID);
815
                            validationStringBuilder.AppendLine("UID : " + connLine.UID);
816 63c5305b gaqhf
                            validationStringBuilder.AppendLine();
817
                            validationResult = true;
818 02a45794 gaqhf
                            flowDirectionCheck.Add(new string[] { line.UID, connLine.UID });
819 d23fe61b gaqhf
                        }
820
                    }
821
                }
822
            }
823 2b8bbe9a gaqhf
824 d1b58c04 gaqhf
            foreach (var item in SYMBOLS.FindAll(x => x.CONNECTORS.Count == 2 &&
825
            x.CONNECTORS[0].ConnectedObject != null && x.CONNECTORS[0].ConnectedObject.GetType() == typeof(Line) &&
826
            x.CONNECTORS[1].ConnectedObject != null && x.CONNECTORS[1].ConnectedObject.GetType() == typeof(Line)))
827 2b8bbe9a gaqhf
            {
828
                Line line1 = item.CONNECTORS[0].ConnectedObject as Line;
829
                Line line2 = item.CONNECTORS[1].ConnectedObject as Line;
830
                if (line1.TYPE == line2.TYPE)
831
                {
832
                    int index1 = line1.CONNECTORS.IndexOf(line1.CONNECTORS.Find(x => x.ConnectedObject == item));
833
                    int index2 = line2.CONNECTORS.IndexOf(line2.CONNECTORS.Find(x => x.ConnectedObject == item));
834
                    if (index1 == index2)
835
                    {
836
                        validationStringBuilder.AppendLine("Check line flow direction!");
837
                        validationStringBuilder.AppendLine("UID : " + line1.UID);
838
                        validationStringBuilder.AppendLine("UID : " + line2.UID);
839
                        validationStringBuilder.AppendLine();
840
                        validationResult = true;
841
                    }
842
                }
843
            }
844 d23fe61b gaqhf
            #endregion
845 63c5305b gaqhf
846 30ba9ae0 gaqhf
            #region Association Check
847
            foreach (var item in TEXTINFOS)
848
            {
849
                if (item.ASSOCIATION)
850
                {
851
                    object owner = SPPIDUtil.FindObjectByUID(this, item.OWNER);
852
                    if (owner == null)
853
                    {
854
                        validationStringBuilder.AppendLine("Check text owner!");
855
                        validationStringBuilder.AppendLine("Text UID : " + item.UID);
856
                        foreach (var associationItem in SYMBOLS.FindAll(x => x.ATTRIBUTES.Find(y => y.ASSOCITEM == item.UID) != null))
857
                            validationStringBuilder.AppendLine("Association UID : " + associationItem.UID);
858
859
                        validationStringBuilder.AppendLine();
860
                        validationResult = true;    
861
                    }
862
                }
863
            }
864
            #endregion
865
866 a6830a94 gaqhf
            #region Line To Line Type Check
867
            List<string[]> typeCheck = new List<string[]>();
868
            foreach (var item in LINES)
869
            {
870
                foreach (var connector in item.CONNECTORS)
871
                {
872
                    Line connLine = connector.ConnectedObject as Line;
873
                    if (connLine != null && connLine.CONNECTORS.Find(x => x.ConnectedObject == item) != null && 
874
                        connLine.TYPE != item.TYPE &&
875
                        typeCheck.Find(x => (x[0] == item.UID || x[1] == connLine.UID) || (x[1] == item.UID || x[0] == connLine.UID)) == null)
876
                    {
877
                        validationStringBuilder.AppendLine("Check line type!");
878
                        validationStringBuilder.AppendLine("UID : " + item.UID);
879
                        validationStringBuilder.AppendLine("UID : " + connLine.UID);
880
                        validationStringBuilder.AppendLine();
881
                        validationResult = true;
882
                        typeCheck.Add(new string[] { item.UID, connLine.UID });
883
                    }
884
                }
885
            }
886
            #endregion
887
888 63c5305b gaqhf
            if (validationResult)
889
            {
890 0a111e7d gaqhf
                _Validation = false;
891 63c5305b gaqhf
                _Enable = false;
892 0a111e7d gaqhf
                _ValidationMessage = validationStringBuilder.ToString();
893
            }
894
            else
895
            {
896
                _Validation = true;
897
                _Enable = true;
898
                _ValidationMessage = "";
899 63c5305b gaqhf
            }
900 a0e3dca4 gaqhf
        }
901 96a2080c gaqhf
    }
902
}
클립보드 이미지 추가 (최대 크기: 500 MB)