프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / BaseModel / Document.cs @ 53c81765

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
398
        private void SetAttributes(XElement node, List<Attribute> attributes)
399
        {
400
            foreach (XElement item in node.Elements("ATTRIBUTE"))
401
            {
402
                Attribute attribute = new Attribute()
403
                {
404
                    UID = item.Attribute("UID").Value,
405
                    LENGTH = item.Attribute("Length").Value,
406
                    EXPRESSION = item.Attribute("Expression").Value,
407
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
408
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
409
                    ATTRIBUTE = item.Attribute("Attribute").Value,
410
                    ATTRAT = item.Attribute("AttrAt").Value,
411
                    ASSOCITEM = item.Attribute("AssocItem").Value,
412
                    VALUE = item.Value
413
                };
414

    
415
                attributes.Add(attribute);
416

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

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

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

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

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

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

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

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

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