프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / BaseModel / Document.cs @ 88bac50c

이력 | 보기 | 이력해설 | 다운로드 (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
                if (xmlPath != null)
67
                {
68
                    PATH = xmlPath;
69
                    XElement xml = XElement.Load(xmlPath);
70
                    DWGNAME = xml.Element("DWGNAME").Value;
71
                    SIZE = xml.Element("SIZE").Value;
72

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

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

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

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

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

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

    
208
                    SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS);
209
                    SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT);
210
                    SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES);
211
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES);
212
                    SetChildSymbol(symbol);
213

    
214
                    SYMBOLS.Add(symbol);
215
                }
216
            }
217
        }
218

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

    
243
                SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS);
244
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
245
                SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES);
246
                LINES.Add(line);
247
            }
248
        }
249

    
250
        private void SetLineNumber(XElement node)
251
        {
252
            foreach (XElement item in node.Elements("LINE_NO"))
253
            {
254
                LineNumber lineNumber = new LineNumber()
255
                {
256
                    UID = item.Element("UID").Value,
257
                    TEXT = item.Element("TEXT").Value,
258
                    LOCATION = item.Element("LOCATION").Value,
259
                    WIDTH = item.Element("WIDTH").Value,
260
                    HEIGHT = item.Element("HEIGHT").Value,
261
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
262
                    AREA = item.Element("AREA").Value,
263
                    SCENE = item.Element("SCENE").Value
264
                };
265
                if (item.Element("CONNLINE") != null)
266
                    lineNumber.CONNLINE = item.Element("CONNLINE").Value;
267

    
268
                SetLineNumberRuns(item, lineNumber.RUNS);
269
                SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
270
                SetAttributes(item, lineNumber.ATTRIBUTES);
271
                LINENUMBERS.Add(lineNumber);
272
            }
273
        }
274

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

    
294
                TEXTINFOS.Add(text);
295
            }
296
        }
297

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

    
317
                NOTES.Add(note);
318
            }
319
        }
320

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

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

    
344
                associations.Add(association);
345
            }
346
        }
347

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

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

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

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

    
412
                attributes.Add(attribute);
413

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

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

    
428
            specBreak.UpStreamUID = upStream;
429
            specBreak.DownStreamUID = downStream;
430
        }
431

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

    
441
                foreach (XElement element in item.Elements())
442
                {
443
                    if (element.Name == "SYMBOL")
444
                    {
445
                        Symbol symbol = GetSymbolByUID(element.Element("UID").Value);
446
                        if (symbol == null)
447
                            throw new Exception("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
448
                        run.RUNITEMS.Add(symbol);
449
                    }
450
                    else if (element.Name == "LINE")
451
                    {
452
                        Line line = GetLineByUID(element.Element("UID").Value);
453
                        if (line == null)
454
                            throw new Exception("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
455
                        run.RUNITEMS.Add(line);
456
                    }
457
                }
458
                lineNumberRuns.Add(run);
459
            }
460
        }
461

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

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

    
506
        public Symbol GetSymbolByUID(string uid)
507
        {
508
            return SYMBOLS.Find(x => x.UID == uid);
509
        }
510

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