프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / BaseModel / Document.cs @ e8536f2b

이력 | 보기 | 이력해설 | 다운로드 (22.6 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

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

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

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

    
62
        public Document(string xmlPath)
63
        {
64
            try
65
            {
66
                PATH = xmlPath;
67
                XElement xml = XElement.Load(xmlPath);
68
                DWGNAME = xml.Element("DWGNAME").Value;
69
                SIZE = xml.Element("SIZE").Value;
70

    
71
                SetText(xml.Element("TEXTINFOS"));
72
                SetNote(xml.Element("NOTES"));
73
                SetSymbol(xml.Element("SYMBOLS"));
74
                SetLine(xml.Element("LINEINFOS"));
75
                SetLineNumber(xml.Element("LINENOS"));
76
                SetTrimLine(xml.Element("TRIMLINENOS"));
77

    
78
                _Enable = true;
79
            }
80
            catch (Exception ex)
81
            {
82
                _Enable = false;
83
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
84
            }
85
        }
86

    
87
        #region READ XML
88
        private void SetSymbol(XElement node)
89
        {
90
            foreach (XElement item in node.Elements("SYMBOL"))
91
            {
92
                string sType = item.Element("TYPE").Value;
93
                if (sType == "Segment Breaks")
94
                {
95
                    SpecBreak specBreak = new SpecBreak()
96
                    {
97
                        UID = item.Element("UID").Value,
98
                        DBUID = item.Element("DBUID").Value,
99
                        NAME = item.Element("NAME").Value,
100
                        TYPE = item.Element("TYPE").Value,
101
                        OWNER = item.Element("OWNER").Value,
102
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
103
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
104
                        LOCATION = item.Element("LOCATION").Value,
105
                        SIZE = item.Element("SIZE").Value,
106
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
107
                        PARENT = item.Element("PARENT").Value,
108
                        CHILD = item.Element("CHILD").Value,
109
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
110
                        AREA = item.Element("AREA").Value,
111
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
112
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
113
                    };
114
                    SetAssociations(item.Element("ASSOCIATIONS"), specBreak.ASSOCIATIONS);
115
                    SetSymbolConnectors(item.Element("CONNECTORS"), specBreak.CONNECTORS, specBreak.CONNECTIONPOINT);
116
                    SetProperties(item.Element("PROPERTIES"), specBreak.PROPERTIES);
117
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), specBreak.ATTRIBUTES);
118
                    SetSpecBreakAttribute(specBreak);
119

    
120
                    SpecBreaks.Add(specBreak);
121
                }
122
                else if (sType == "End Break")
123
                {
124
                    EndBreak endBreak = new EndBreak()
125
                    {
126
                        UID = item.Element("UID").Value,
127
                        DBUID = item.Element("DBUID").Value,
128
                        NAME = item.Element("NAME").Value,
129
                        TYPE = item.Element("TYPE").Value,
130
                        OWNER = item.Element("OWNER").Value,
131
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
132
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
133
                        LOCATION = item.Element("LOCATION").Value,
134
                        SIZE = item.Element("SIZE").Value,
135
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
136
                        PARENT = item.Element("PARENT").Value,
137
                        CHILD = item.Element("CHILD").Value,
138
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
139
                        AREA = item.Element("AREA").Value,
140
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
141
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
142
                    };
143
                    SetAssociations(item.Element("ASSOCIATIONS"), endBreak.ASSOCIATIONS);
144
                    SetSymbolConnectors(item.Element("CONNECTORS"), endBreak.CONNECTORS, endBreak.CONNECTIONPOINT);
145
                    SetProperties(item.Element("PROPERTIES"), endBreak.PROPERTIES);
146
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), endBreak.ATTRIBUTES);
147

    
148
                    EndBreaks.Add(endBreak);
149
                }
150
                else if (sType == "Black Box System" ||
151
                    sType == "GGO_Equipment" ||
152
                    sType == "Heat Transfer Equipment" ||
153
                    sType == "Mechanical" ||
154
                    sType == "Other Equipment" ||
155
                    sType == "Vessels")
156
                {
157
                    Equipment equipment = new Equipment()
158
                    {
159
                        UID = item.Element("UID").Value,
160
                        DBUID = item.Element("DBUID").Value,
161
                        NAME = item.Element("NAME").Value,
162
                        TYPE = item.Element("TYPE").Value,
163
                        OWNER = item.Element("OWNER").Value,
164
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
165
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
166
                        LOCATION = item.Element("LOCATION").Value,
167
                        SIZE = item.Element("SIZE").Value,
168
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
169
                        PARENT = item.Element("PARENT").Value,
170
                        CHILD = item.Element("CHILD").Value,
171
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
172
                        AREA = item.Element("AREA").Value,
173
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
174
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
175
                    };
176
                    SetAssociations(item.Element("ASSOCIATIONS"), equipment.ASSOCIATIONS);
177
                    SetSymbolConnectors(item.Element("CONNECTORS"), equipment.CONNECTORS, equipment.CONNECTIONPOINT);
178
                    SetProperties(item.Element("PROPERTIES"), equipment.PROPERTIES);
179
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), equipment.ATTRIBUTES);
180

    
181
                    Equipments.Add(equipment);
182
                }
183
                else
184
                {
185
                    Symbol symbol = new Symbol()
186
                    {
187
                        UID = item.Element("UID").Value,
188
                        DBUID = item.Element("DBUID").Value,
189
                        NAME = item.Element("NAME").Value,
190
                        TYPE = item.Element("TYPE").Value,
191
                        OWNER = item.Element("OWNER").Value,
192
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
193
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
194
                        LOCATION = item.Element("LOCATION").Value,
195
                        SIZE = item.Element("SIZE").Value,
196
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
197
                        PARENT = item.Element("PARENT").Value,
198
                        CHILD = item.Element("CHILD").Value,
199
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
200
                        AREA = item.Element("AREA").Value,
201
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
202
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
203
                    };
204

    
205
                    SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS);
206
                    SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT);
207
                    SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES);
208
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES);
209
                    SetChildSymbol(symbol);
210

    
211
                    SYMBOLS.Add(symbol);
212
                }
213
            }
214
        }
215

    
216
        private void SetLine(XElement node)
217
        {
218
            foreach (XElement item in node.Elements("LINE"))
219
            {
220
                Line line = new Line()
221
                {
222
                    OWNER = item.Attribute("OWNER").Value,
223
                    UID = item.Element("UID").Value,
224
                    STARTPOINT = item.Element("STARTPOINT").Value,
225
                    ENDPOINT = item.Element("ENDPOINT").Value,
226
                    TYPE = item.Element("TYPE").Value,
227
                    TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value,
228
                    AREA = item.Element("AREA").Value,
229
                    THICKNESS = item.Element("THICKNESS").Value,
230
                };
231
                int flowMarkPercent = 0;
232
                if (int.TryParse(item.Element("FLOWMARK").Value, out flowMarkPercent))
233
                {
234
                    line.FLOWMARK = true;
235
                    line.FLOWMARK_PERCENT = flowMarkPercent;
236
                }
237
                else
238
                    line.FLOWMARK = false;
239

    
240
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
241
                LINES.Add(line);
242
            }
243
        }
244

    
245
        private void SetLineNumber(XElement node)
246
        {
247
            foreach (XElement item in node.Elements("LINE_NO"))
248
            {
249
                try
250
                {
251
                    LineNumber lineNumber = new LineNumber()
252
                    {
253
                        UID = item.Element("UID").Value,
254
                        TEXT = item.Element("TEXT").Value,
255
                        LOCATION = item.Element("LOCATION").Value,
256
                        WIDTH = item.Element("WIDTH").Value,
257
                        HEIGHT = item.Element("HEIGHT").Value,
258
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
259
                        AREA = item.Element("AREA").Value,
260
                        CONNLINE = item.Element("CONNLINE").Value,
261
                        SCENE = item.Element("SCENE").Value
262
                    };
263
                    SetLineNumberRuns(item, lineNumber.RUNS);
264
                    SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
265
                    SetAttributes(item, lineNumber.ATTRIBUTES);
266
                    LINENUMBERS.Add(lineNumber);
267
                }
268
                catch (Exception ex)
269
                {
270
                    StringBuilder sb = new StringBuilder();
271
                    sb.AppendLine(item.Element("UID").Value);
272
                    sb.AppendLine("");
273
                    sb.AppendLine(ex.Message);
274
                    sb.AppendLine(ex.StackTrace);
275
                    MessageBox.Show(sb.ToString());
276
                }
277
            }
278
        }
279

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

    
299
                TEXTINFOS.Add(text);
300
            }
301
        }
302

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

    
321
                NOTES.Add(note);
322
            }
323
        }
324

    
325
        private void SetTrimLine(XElement node)
326
        {
327
            foreach (XElement item in node.Elements("TRIM_LINE_NO"))
328
            {
329
                TrimLine trimLine = new TrimLine()
330
                {
331
                    UID = item.Element("UID").Value,
332
                };
333
                SetLineNumberRuns(item, trimLine.RUNS);
334
                TRIMLINES.Add(trimLine);
335
            }
336
        }
337

    
338
        private void SetAssociations(XElement node, List<Association> associations)
339
        {
340
            foreach (XElement item in node.Elements("ASSOCIATION"))
341
            {
342
                Association association = new Association()
343
                {
344
                    TYPE = item.Attribute("TYPE").Value,
345
                    VALUE = item.Value
346
                };
347

    
348
                associations.Add(association);
349
            }
350
        }
351

    
352
        private void SetConnectors(XElement node, List<Connector> connectors)
353
        {
354
            foreach (XElement item in node.Elements("CONNECTOR"))
355
            {
356
                connectors.Add(new Connector()
357
                {
358
                    UID = item.Attribute("UID").Value,
359
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
360
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
361
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
362
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
363
                });
364
            }
365
        }
366

    
367
        private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT)
368
        {
369
            foreach (XElement item in node.Elements("CONNECTOR"))
370
            {
371
                connectors.Add(new Connector()
372
                {
373
                    UID = item.Attribute("UID").Value,
374
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
375
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
376
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
377
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
378
                });
379
            }
380
        }
381

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

    
399
        private void SetAttributes(XElement node, List<Attribute> attributes)
400
        {
401
            foreach (XElement item in node.Elements("ATTRIBUTE"))
402
            {
403
                Attribute attribute = new Attribute()
404
                {
405
                    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
                    ATTRAT = item.Attribute("AttrAt").Value,
412
                    ASSOCITEM = item.Attribute("AssocItem").Value,
413
                    VALUE = item.Value
414
                };
415

    
416
                attributes.Add(attribute);
417

    
418
                if (!string.IsNullOrEmpty(attribute.ASSOCITEM) && attribute.ASSOCITEM != "None")
419
                {
420
                    Text text = _TEXTINFOS.Find(x => x.UID == attribute.ASSOCITEM);
421
                    if (text != null)
422
                        text.ASSOCIATION = true;
423
                }
424
            }
425
        }
426

    
427
        private void SetSpecBreakAttribute(SpecBreak specBreak)
428
        {
429
            string upStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "UpStream").VALUE;
430
            string downStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "DownStream").VALUE;
431

    
432
            specBreak.UpStreamUID = upStream;
433
            specBreak.DownStreamUID = downStream;
434
        }
435

    
436
        private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns)
437
        {
438
            foreach (XElement item in node.Elements("RUN"))
439
            {
440
                LineRun run = new LineRun()
441
                {
442
                    TYPE = item.Attribute("TYPE").Value
443
                };
444

    
445
                foreach (XElement element in item.Elements())
446
                {
447
                    if (element.Name == "SYMBOL")
448
                    {
449
                        Symbol symbol = GetSymbolByUID(element.Element("UID").Value);
450
                        if (symbol == null)
451
                            throw new Exception(element.Element("UID").Value);
452
                        run.RUNITEMS.Add(symbol);
453
                    }
454
                    else if (element.Name == "LINE")
455
                    {
456
                        Line line = GetLineByUID(element.Element("UID").Value);
457
                        if (line == null)
458
                            throw new Exception(element.Element("UID").Value);
459
                        run.RUNITEMS.Add(line);
460
                    }
461
                }
462
                lineNumberRuns.Add(run);
463
            }
464
        }
465

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

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

    
510
        public Symbol GetSymbolByUID(string uid)
511
        {
512
            return SYMBOLS.Find(x => x.UID == uid);
513
        }
514

    
515
        public Line GetLineByUID(string uid)
516
        {
517
            return LINES.Find(x => x.UID == uid);
518
        }
519
    }
520
}
클립보드 이미지 추가 (최대 크기: 500 MB)