프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / BaseModel / Document.cs @ 5173ba5d

이력 | 보기 | 이력해설 | 다운로드 (32.2 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
30
        public bool Enable { get { return _Enable; } }
31 96a2080c gaqhf
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 f1c9dbaa gaqhf
        public List<EndBreak> EndBreaks { get => _EndBreaks; set => _EndBreaks = value; }
38 53c81765 gaqhf
        public List<SpecBreak> SpecBreaks { get => _SpecBreaks; set => _SpecBreaks = value; }
39 f1c9dbaa gaqhf
        public List<Equipment> Equipments { get => _Equipments; set => _Equipments = value; }
40 96a2080c gaqhf
        public string DWGNAME { get => _DWGNAME; set => _DWGNAME = value; }
41 39a2a688 gaqhf
        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 8aa6f2db gaqhf
        public List<TrimLine> TRIMLINES { get => _TRIMLINES; set => _TRIMLINES = value; }
61 e8536f2b gaqhf
        public string PATH { get; set; }
62 96a2080c gaqhf
63 a0e3dca4 gaqhf
        StringBuilder validationStringBuilder = new StringBuilder();
64
65 96a2080c gaqhf
        public Document(string xmlPath)
66
        {
67 a0e3dca4 gaqhf
            validationStringBuilder.AppendLine("Document Path : " + xmlPath);
68
            validationStringBuilder.AppendLine("");
69 96a2080c gaqhf
            try
70
            {
71 88bac50c gaqhf
                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 96a2080c gaqhf
78 a0e3dca4 gaqhf
                    validationStringBuilder.AppendLine("Drawing Name : " + DWGNAME);
79
                    validationStringBuilder.AppendLine("");
80
81 88bac50c gaqhf
                    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 60244a8b gaqhf
88 d63050d6 gaqhf
                    SetAllConnectors();
89 a0e3dca4 gaqhf
                    ValidationCheck();
90 88bac50c gaqhf
                    _Enable = true;
91
                }
92 96a2080c gaqhf
            }
93
            catch (Exception ex)
94
            {
95 60244a8b gaqhf
                _Enable = false;
96 96a2080c gaqhf
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
97
            }
98
        }
99
100 60244a8b gaqhf
        #region READ XML
101 96a2080c gaqhf
        private void SetSymbol(XElement node)
102
        {
103
            foreach (XElement item in node.Elements("SYMBOL"))
104
            {
105 f1c9dbaa gaqhf
                string sType = item.Element("TYPE").Value;
106
                if (sType == "Segment Breaks")
107 96a2080c gaqhf
                {
108 53c81765 gaqhf
                    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 f1c9dbaa gaqhf
                }
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 bca81f4c gaqhf
194 f1c9dbaa gaqhf
                    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 8aa6f2db gaqhf
218 f1c9dbaa gaqhf
                    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 96a2080c gaqhf
            }
227
        }
228
229
        private void SetLine(XElement node)
230
        {
231
            foreach (XElement item in node.Elements("LINE"))
232
            {
233 60244a8b gaqhf
                Line line = new Line()
234 96a2080c gaqhf
                {
235 60244a8b gaqhf
                    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 30d2cfcc gaqhf
                    TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value,
241 60244a8b gaqhf
                    AREA = item.Element("AREA").Value,
242
                    THICKNESS = item.Element("THICKNESS").Value,
243
                };
244 b2d1c1aa gaqhf
                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 0860c756 gaqhf
                SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS);
254 cfda1fed gaqhf
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
255 0860c756 gaqhf
                SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES);
256 60244a8b gaqhf
                LINES.Add(line);
257 96a2080c gaqhf
            }
258
        }
259
260
        private void SetLineNumber(XElement node)
261
        {
262
            foreach (XElement item in node.Elements("LINE_NO"))
263
            {
264 3734dcc5 gaqhf
                LineNumber lineNumber = new LineNumber()
265 96a2080c gaqhf
                {
266 3734dcc5 gaqhf
                    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 96a2080c gaqhf
            }
283
        }
284
285
        private void SetText(XElement node)
286
        {
287
            foreach (XElement item in node.Elements("ATTRIBUTE"))
288
            {
289 60244a8b gaqhf
                Text text = new Text()
290 96a2080c gaqhf
                {
291 60244a8b gaqhf
                    UID = item.Element("UID").Value,
292 ea80efaa gaqhf
                    OWNER = item.Element("OWNER").Value,
293 60244a8b gaqhf
                    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 1a3a74a8 gaqhf
                    AREA = item.Element("AREA").Value,
301
                    SCENE = item.Element("SCENE").Value
302 60244a8b gaqhf
                };
303 96a2080c gaqhf
304 60244a8b gaqhf
                TEXTINFOS.Add(text);
305 96a2080c gaqhf
            }
306
        }
307
308
        private void SetNote(XElement node)
309
        {
310
            foreach (XElement item in node.Elements("ATTRIBUTE"))
311
            {
312 60244a8b gaqhf
                Note note = new Note()
313 96a2080c gaqhf
                {
314 60244a8b gaqhf
                    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 1a3a74a8 gaqhf
                    AREA = item.Element("AREA").Value,
323 fc0a8c33 gaqhf
                    SCENE = item.Element("SCENE").Value,
324
                    OWNER = item.Element("OWNER").Value
325 60244a8b gaqhf
                };
326 96a2080c gaqhf
327 60244a8b gaqhf
                NOTES.Add(note);
328
            }
329
        }
330 8aa6f2db gaqhf
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 60244a8b gaqhf
        private void SetAssociations(XElement node, List<Association> associations)
345
        {
346
            foreach (XElement item in node.Elements("ASSOCIATION"))
347
            {
348 ea80efaa gaqhf
                Association association = new Association()
349 60244a8b gaqhf
                {
350
                    TYPE = item.Attribute("TYPE").Value,
351
                    VALUE = item.Value
352 ea80efaa gaqhf
                };
353
354
                associations.Add(association);
355 96a2080c gaqhf
            }
356
        }
357 60244a8b gaqhf
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 bca81f4c gaqhf
                    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 60244a8b gaqhf
                    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 30d2cfcc gaqhf
                properties.Add(new Property()
393 60244a8b gaqhf
                {
394 30d2cfcc gaqhf
                    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 60244a8b gaqhf
            }
403
        }
404
405
        private void SetAttributes(XElement node, List<Attribute> attributes)
406
        {
407 30d2cfcc gaqhf
            foreach (XElement item in node.Elements("ATTRIBUTE"))
408 60244a8b gaqhf
            {
409 73415441 gaqhf
                Attribute attribute = new Attribute()
410 60244a8b gaqhf
                {
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 30d2cfcc gaqhf
                    ATTRAT = item.Attribute("AttrAt").Value,
418 73415441 gaqhf
                    ASSOCITEM = item.Attribute("AssocItem").Value,
419 60244a8b gaqhf
                    VALUE = item.Value
420 73415441 gaqhf
                };
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 60244a8b gaqhf
            }
431
        }
432
433 53c81765 gaqhf
        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 8aa6f2db gaqhf
        private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns)
443 60244a8b gaqhf
        {
444
            foreach (XElement item in node.Elements("RUN"))
445
            {
446 8aa6f2db gaqhf
                LineRun run = new LineRun()
447 60244a8b gaqhf
                {
448
                    TYPE = item.Attribute("TYPE").Value
449
                };
450
451
                foreach (XElement element in item.Elements())
452
                {
453
                    if (element.Name == "SYMBOL")
454
                    {
455 c3d2e266 gaqhf
                        Symbol symbol = GetSymbolByUID(element.Element("UID").Value);
456
                        if (symbol == null)
457 3734dcc5 gaqhf
                            throw new Exception("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
458 c3d2e266 gaqhf
                        run.RUNITEMS.Add(symbol);
459 60244a8b gaqhf
                    }
460
                    else if (element.Name == "LINE")
461
                    {
462 c3d2e266 gaqhf
                        Line line = GetLineByUID(element.Element("UID").Value);
463
                        if (line == null)
464 3734dcc5 gaqhf
                            throw new Exception("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
465 c3d2e266 gaqhf
                        run.RUNITEMS.Add(line);
466 60244a8b gaqhf
                    }
467
                }
468
                lineNumberRuns.Add(run);
469
            }
470
        }
471 30d2cfcc gaqhf
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 f1c9dbaa gaqhf
                // 현재 부모 Symbol에 자식 Connector까지 들어가 있음
500 30d2cfcc gaqhf
                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 5dfb8a24 gaqhf
                    {
508 30d2cfcc gaqhf
                        childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]);
509 f1c9dbaa gaqhf
                        symbol.CONNECTORS[i].Index = connIndex;
510 5dfb8a24 gaqhf
                    }
511
                }
512 30d2cfcc gaqhf
            }
513
        }
514 60244a8b gaqhf
        #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 d63050d6 gaqhf
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 a0e3dca4 gaqhf
541
        
542
543
        public void ValidationCheck()
544
        {
545 026f394f gaqhf
            #region Connection Check / Symbol의 SceneConnectPoint Check
546 a0e3dca4 gaqhf
            foreach (var item in _SYMBOLS)
547
            {
548
                foreach (var connector in item.CONNECTORS)
549
                {
550
                    if (connector.ConnectedObject != null && connector.ConnectedObject.GetType() == typeof(Line))
551
                    {
552
                        Line line = connector.ConnectedObject as Line;
553
                        if (line.CONNECTORS.Find(x => x.ConnectedObject == item) == null)
554
                        {
555
                            validationStringBuilder.AppendLine("Check connection!");
556
                            validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
557
                            validationStringBuilder.AppendLine("Line UID : " + line.UID);
558
                            throw new Exception(validationStringBuilder.ToString());
559
                        }
560
                    }
561
562
                    if (connector.SCENECONNECTPOINT == connector.CONNECTPOINT)
563
                    {
564
                        validationStringBuilder.AppendLine("Check Symbol SceneConnectPoint!");
565
                        validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
566
                        throw new Exception(validationStringBuilder.ToString());
567
                    }
568
                }
569
            }
570
571
            foreach (var item in _LINES)
572
            {
573
                foreach (var connector in item.CONNECTORS)
574
                {
575
                    if (connector.ConnectedObject != null && connector.ConnectedObject.GetType() == typeof(Symbol))
576
                    {
577
                        Symbol symbol = connector.ConnectedObject as Symbol;
578
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == item) == null)
579
                        {
580
                            validationStringBuilder.AppendLine("Check connection!");
581
                            validationStringBuilder.AppendLine("Symbol UID : " + symbol.UID);
582
                            validationStringBuilder.AppendLine("Line UID : " + item.UID);
583
                            throw new Exception(validationStringBuilder.ToString());
584
                        }
585
                    }
586
                }
587
            }
588
            #endregion
589
590
            #region Symbol Size Check
591
            foreach (var item in _SYMBOLS)
592
            {
593
                if (item.SIZE == "0,0")
594
                {
595
                    validationStringBuilder.AppendLine("Check symbol size!");
596
                    validationStringBuilder.AppendLine("Symbol UID : " + item.UID);
597
                    throw new Exception(validationStringBuilder.ToString());
598
                }
599
            }
600
            #endregion
601 026f394f gaqhf
602
            #region SpecBreak, EndBreak Check
603
            foreach (var item in SpecBreaks)
604
            {
605
                object obj1 = SPPIDUtil.FindObjectByUID(this, item.UpStreamUID);
606
                object obj2 = SPPIDUtil.FindObjectByUID(this, item.DownStreamUID);
607
                if (obj1 == null || obj2 == null)
608
                {
609
                    validationStringBuilder.AppendLine("Check SpecBreak UpStream, DownStream!");
610
                    validationStringBuilder.AppendLine("UID : " + item.UID);
611
                    throw new Exception(validationStringBuilder.ToString());
612
                }
613
                else
614
                {
615
                    bool result = false;
616
                    if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Symbol))
617
                    {
618
                        Symbol symbol1 = obj1 as Symbol;
619
                        Symbol symbol2 = obj2 as Symbol;
620
                        if (symbol1.CONNECTORS.Find(x => x.ConnectedObject == symbol2) == null || symbol2.CONNECTORS.Find(x => x.ConnectedObject == symbol1) == null)
621
                            result = true;
622
                    }
623
                    else if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Line))
624
                    {
625
                        Symbol symbol = obj1 as Symbol;
626
                        Line line = obj2 as Line;
627
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
628
                            result = true;
629
                    }
630
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Symbol))
631
                    {
632
                        Symbol symbol = obj2 as Symbol;
633
                        Line line = obj1 as Line;
634
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
635
                            result = true;
636
                    }
637
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
638
                    {
639
                        Line line1 = obj2 as Line;
640
                        Line line2 = obj1 as Line;
641
                        Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
642
                        Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
643
                        if (connector1 == null && connector2 == null)
644
                            result = true;
645
                    }
646
647
                    if (result)
648
                    {
649
                        validationStringBuilder.AppendLine("Check SpecBreak UpStream, DownStream!");
650
                        validationStringBuilder.AppendLine("UID : " + item.UID);
651
                        throw new Exception(validationStringBuilder.ToString());
652
                    }
653
                }
654
            }
655
656
            foreach (var item in EndBreaks)
657
            {
658
                object obj1 = SPPIDUtil.FindObjectByUID(this, item.OWNER);
659
                object obj2 = SPPIDUtil.FindObjectByUID(this, item.PROPERTIES.Find(x => x.ATTRIBUTE == "Connected Item").VALUE);
660
                if (obj1 == null || obj2 == null)
661
                {
662
                    validationStringBuilder.AppendLine("Check EndBreak Owner, Connected Item!");
663
                    validationStringBuilder.AppendLine("UID : " + item.UID);
664
                    throw new Exception(validationStringBuilder.ToString());
665
                }
666
                else
667
                {
668
                    bool result = false;
669
                    if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Symbol))
670
                    {
671
                        Symbol symbol1 = obj1 as Symbol;
672
                        Symbol symbol2 = obj2 as Symbol;
673
                        if (symbol1.CONNECTORS.Find(x => x.ConnectedObject == symbol2) == null || symbol2.CONNECTORS.Find(x => x.ConnectedObject == symbol1) == null)
674
                            result = true;
675
                    }
676
                    else if (obj1.GetType() == typeof(Symbol) && obj2.GetType() == typeof(Line))
677
                    {
678
                        Symbol symbol = obj1 as Symbol;
679
                        Line line = obj2 as Line;
680
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
681
                            result = true;
682
                    }
683
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Symbol))
684
                    {
685
                        Symbol symbol = obj2 as Symbol;
686
                        Line line = obj1 as Line;
687
                        if (symbol.CONNECTORS.Find(x => x.ConnectedObject == line) == null || line.CONNECTORS.Find(x => x.ConnectedObject == symbol) == null)
688
                            result = true;
689
                    }
690
                    else if (obj1.GetType() == typeof(Line) && obj2.GetType() == typeof(Line))
691
                    {
692
                        Line line1 = obj2 as Line;
693
                        Line line2 = obj1 as Line;
694
                        Connector connector1 = line1.CONNECTORS.Find(x => x.ConnectedObject == line2);
695
                        Connector connector2 = line2.CONNECTORS.Find(x => x.ConnectedObject == line1);
696
                        if (connector1 == null && connector2 == null)
697
                            result = true;
698
                    }
699
700
                    if (result)
701
                    {
702
                        validationStringBuilder.AppendLine("Check EndBreak Owner, Connected Item!");
703
                        validationStringBuilder.AppendLine("UID : " + item.UID);
704
                        throw new Exception(validationStringBuilder.ToString());
705
                    }
706
                }
707
            }
708
709
            #endregion
710 a0e3dca4 gaqhf
        }
711 96a2080c gaqhf
    }
712
}
클립보드 이미지 추가 (최대 크기: 500 MB)