프로젝트

일반

사용자정보

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

hytos / DTI_PID / BaseModel / Model / Document.cs @ 5e6ecf05

이력 | 보기 | 이력해설 | 다운로드 (18.9 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
10
namespace Converter.BaseModel
11
{
12
    public class Document
13
    {
14
        private string _DWGNAME;
15
        private string _SIZE;
16 39a2a688 gaqhf
        private double _SIZE_WIDTH;
17
        private double _SIZE_HEIGHT;
18 60244a8b gaqhf
        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 8aa6f2db gaqhf
        private List<TrimLine> _TRIMLINES = new List<TrimLine>();
24 f1c9dbaa gaqhf
        private List<EndBreak> _EndBreaks = new List<EndBreak>();
25
        private List<Equipment> _Equipments = new List<Equipment>();
26 60244a8b gaqhf
        private bool _Enable;
27
28
        public bool Enable { get { return _Enable; } }
29 96a2080c gaqhf
30
        public List<Symbol> SYMBOLS { get => _SYMBOLS; set => _SYMBOLS = value; }
31
        public List<Text> TEXTINFOS { get => _TEXTINFOS; set => _TEXTINFOS = value; }
32
        public List<Note> NOTES { get => _NOTES; set => _NOTES = value; }
33
        public List<Line> LINES { get => _LINES; set => _LINES = value; }
34
        public List<LineNumber> LINENUMBERS { get => _LINENUMBERS; set => _LINENUMBERS = value; }
35 f1c9dbaa gaqhf
        public List<EndBreak> EndBreaks { get => _EndBreaks; set => _EndBreaks = value; }
36
        public List<Equipment> Equipments { get => _Equipments; set => _Equipments = value; }
37 96a2080c gaqhf
        public string DWGNAME { get => _DWGNAME; set => _DWGNAME = value; }
38 39a2a688 gaqhf
        public string SIZE
39
        {
40
            get
41
            {
42
                return _SIZE;
43
            }
44
            set
45
            {
46
                _SIZE = value;
47
                string[] pointArr = _SIZE.Split(new char[] { ',' });
48
                if (pointArr.Length == 2)
49
                {
50
                    _SIZE_WIDTH = Convert.ToDouble(pointArr[0]);
51
                    _SIZE_HEIGHT = Convert.ToDouble(pointArr[1]);
52
                }
53
            }
54
        }
55
        public double SIZE_WIDTH { get => _SIZE_WIDTH; }
56
        public double SIZE_HEIGHT { get => _SIZE_HEIGHT; }
57 8aa6f2db gaqhf
        public List<TrimLine> TRIMLINES { get => _TRIMLINES; set => _TRIMLINES = value; }
58 96a2080c gaqhf
59
        public Document(string xmlPath)
60
        {
61
            try
62
            {
63
                XElement xml = XElement.Load(xmlPath);
64
                DWGNAME = xml.Element("DWGNAME").Value;
65
                SIZE = xml.Element("SIZE").Value;
66
67
                SetSymbol(xml.Element("SYMBOLS"));
68
                SetLine(xml.Element("LINEINFOS"));
69
                SetLineNumber(xml.Element("LINENOS"));
70
                SetText(xml.Element("TEXTINFOS"));
71
                SetNote(xml.Element("NOTES"));
72 8aa6f2db gaqhf
                SetTrimLine(xml.Element("TRIMLINENOS"));
73 60244a8b gaqhf
74
                _Enable = true;
75 96a2080c gaqhf
            }
76
            catch (Exception ex)
77
            {
78 60244a8b gaqhf
                _Enable = false;
79 96a2080c gaqhf
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
80
            }
81
        }
82
83 60244a8b gaqhf
        #region READ XML
84 96a2080c gaqhf
        private void SetSymbol(XElement node)
85
        {
86
            foreach (XElement item in node.Elements("SYMBOL"))
87
            {
88 f1c9dbaa gaqhf
                string sType = item.Element("TYPE").Value;
89
                if (sType == "Segment Breaks")
90 96a2080c gaqhf
                {
91 f1c9dbaa gaqhf
                    continue;
92
                }
93
                else if (sType == "End Break")
94
                {
95
                    EndBreak endBreak = new EndBreak()
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"), endBreak.ASSOCIATIONS);
115
                    SetSymbolConnectors(item.Element("CONNECTORS"), endBreak.CONNECTORS, endBreak.CONNECTIONPOINT);
116
                    SetProperties(item.Element("PROPERTIES"), endBreak.PROPERTIES);
117
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), endBreak.ATTRIBUTES);
118
119
                    EndBreaks.Add(endBreak);
120
                }
121
                else if (sType == "Black Box System" ||
122
                    sType == "GGO_Equipment" ||
123
                    sType == "Heat Transfer Equipment" ||
124
                    sType == "Labels - Equipment" ||
125
                    sType == "Mechanical" ||
126
                    sType == "Other Equipment" ||
127
                    sType == "Vessels")
128
                {
129
                    Equipment equipment = new Equipment()
130
                    {
131
                        UID = item.Element("UID").Value,
132
                        DBUID = item.Element("DBUID").Value,
133
                        NAME = item.Element("NAME").Value,
134
                        TYPE = item.Element("TYPE").Value,
135
                        OWNER = item.Element("OWNER").Value,
136
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
137
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
138
                        LOCATION = item.Element("LOCATION").Value,
139
                        SIZE = item.Element("SIZE").Value,
140
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
141
                        PARENT = item.Element("PARENT").Value,
142
                        CHILD = item.Element("CHILD").Value,
143
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
144
                        AREA = item.Element("AREA").Value,
145
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
146
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
147
                    };
148
                    SetAssociations(item.Element("ASSOCIATIONS"), equipment.ASSOCIATIONS);
149
                    SetSymbolConnectors(item.Element("CONNECTORS"), equipment.CONNECTORS, equipment.CONNECTIONPOINT);
150
                    SetProperties(item.Element("PROPERTIES"), equipment.PROPERTIES);
151
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), equipment.ATTRIBUTES);
152 bca81f4c gaqhf
153 f1c9dbaa gaqhf
                    Equipments.Add(equipment);
154
                }
155
                else
156
                {
157
                    Symbol symbol = new Symbol()
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 8aa6f2db gaqhf
                    if (symbol.ANGLE == 1.57)
177
                        //ANGLE = 270 * Math.PI / 180;
178
                        symbol.ANGLE = 90 * Math.PI / 180;
179
                    else if (symbol.ANGLE == 3.14)
180
                        symbol.ANGLE = Math.PI;
181
                    else if (symbol.ANGLE == 4.71)
182
                        //ANGLE = 90 * Math.PI / 180;
183
                        symbol.ANGLE = 270 * Math.PI / 180;
184
185 f1c9dbaa gaqhf
                    SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS);
186
                    SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT);
187
                    SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES);
188
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES);
189
                    SetChildSymbol(symbol);
190
191
                    SYMBOLS.Add(symbol);
192
                }
193 96a2080c gaqhf
            }
194
        }
195
196
        private void SetLine(XElement node)
197
        {
198
            foreach (XElement item in node.Elements("LINE"))
199
            {
200 60244a8b gaqhf
                Line line = new Line()
201 96a2080c gaqhf
                {
202 60244a8b gaqhf
                    OWNER = item.Attribute("OWNER").Value,
203
                    UID = item.Element("UID").Value,
204
                    STARTPOINT = item.Element("STARTPOINT").Value,
205
                    ENDPOINT = item.Element("ENDPOINT").Value,
206
                    TYPE = item.Element("TYPE").Value,
207 30d2cfcc gaqhf
                    TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value,
208 60244a8b gaqhf
                    AREA = item.Element("AREA").Value,
209
                    THICKNESS = item.Element("THICKNESS").Value,
210
                };
211 cfda1fed gaqhf
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
212 60244a8b gaqhf
                LINES.Add(line);
213 96a2080c gaqhf
            }
214
        }
215
216
        private void SetLineNumber(XElement node)
217
        {
218
            foreach (XElement item in node.Elements("LINE_NO"))
219
            {
220 60244a8b gaqhf
                LineNumber lineNumber = new LineNumber()
221 96a2080c gaqhf
                {
222 60244a8b gaqhf
                    UID = item.Element("UID").Value,
223
                    TEXT = item.Element("TEXT").Value,
224
                    LOCATION = item.Element("LOCATION").Value,
225
                    WIDTH = item.Element("WIDTH").Value,
226
                    HEIGHT = item.Element("HEIGHT").Value,
227
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
228
                    AREA = item.Element("AREA").Value
229
                };
230
                SetLineNumberRuns(item, lineNumber.RUNS);
231
                SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
232
                SetAttributes(item, lineNumber.ATTRIBUTES);
233
                LINENUMBERS.Add(lineNumber);
234 96a2080c gaqhf
            }
235
        }
236
237
        private void SetText(XElement node)
238
        {
239
            foreach (XElement item in node.Elements("ATTRIBUTE"))
240
            {
241 60244a8b gaqhf
                Text text = new Text()
242 96a2080c gaqhf
                {
243 60244a8b gaqhf
                    UID = item.Element("UID").Value,
244
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
245
                    NAME = item.Element("NAME").Value,
246
                    LOCATION = item.Element("LOCATION").Value,
247
                    VALUE = item.Element("VALUE").Value,
248
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
249
                    WIDTH = item.Element("WIDTH").Value,
250
                    HEIGHT = item.Element("HEIGHT").Value,
251
                    AREA = item.Element("AREA").Value
252
                };
253 96a2080c gaqhf
254 60244a8b gaqhf
                TEXTINFOS.Add(text);
255 96a2080c gaqhf
            }
256
        }
257
258
        private void SetNote(XElement node)
259
        {
260
            foreach (XElement item in node.Elements("ATTRIBUTE"))
261
            {
262 60244a8b gaqhf
                Note note = new Note()
263 96a2080c gaqhf
                {
264 60244a8b gaqhf
                    UID = item.Element("UID").Value,
265
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
266
                    NAME = item.Element("NAME").Value,
267
                    LOCATION = item.Element("LOCATION").Value,
268
                    VALUE = item.Element("VALUE").Value,
269
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
270
                    WIDTH = item.Element("WIDTH").Value,
271
                    HEIGHT = item.Element("HEIGHT").Value,
272
                    AREA = item.Element("AREA").Value
273
                };
274 96a2080c gaqhf
275 60244a8b gaqhf
                NOTES.Add(note);
276
            }
277
        }
278 8aa6f2db gaqhf
279
        private void SetTrimLine(XElement node)
280
        {
281
            foreach (XElement item in node.Elements("TRIM_LINE_NO"))
282
            {
283
                TrimLine trimLine = new TrimLine()
284
                {
285
                    UID = item.Element("UID").Value,
286
                };
287
                SetLineNumberRuns(item, trimLine.RUNS);
288
                TRIMLINES.Add(trimLine);
289
            }
290
        }
291
292 60244a8b gaqhf
        private void SetAssociations(XElement node, List<Association> associations)
293
        {
294
            foreach (XElement item in node.Elements("ASSOCIATION"))
295
            {
296
                associations.Add(new Association()
297
                {
298
                    TYPE = item.Attribute("TYPE").Value,
299
                    VALUE = item.Value
300 96a2080c gaqhf
                });
301
            }
302
        }
303 60244a8b gaqhf
304
        private void SetConnectors(XElement node, List<Connector> connectors)
305
        {
306
            foreach (XElement item in node.Elements("CONNECTOR"))
307
            {
308
                connectors.Add(new Connector()
309
                {
310
                    UID = item.Attribute("UID").Value,
311
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
312 bca81f4c gaqhf
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
313
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
314
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
315
                });
316
            }
317
        }
318
319
        private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT)
320
        {
321
            foreach (XElement item in node.Elements("CONNECTOR"))
322
            {
323
                connectors.Add(new Connector()
324
                {
325
                    UID = item.Attribute("UID").Value,
326
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
327 60244a8b gaqhf
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
328
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
329
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
330
                });
331
            }
332
        }
333
334
        private void SetProperties(XElement node, List<Property> properties)
335
        {
336
            foreach (XElement item in node.Elements("PROPERTY"))
337
            {
338 30d2cfcc gaqhf
                properties.Add(new Property()
339 60244a8b gaqhf
                {
340 30d2cfcc gaqhf
                    UID = item.Attribute("UID").Value,
341
                    LENGTH = item.Attribute("Length").Value,
342
                    EXPRESSION = item.Attribute("Expression").Value,
343
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
344
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
345
                    ATTRIBUTE = item.Attribute("Attribute").Value,
346
                    VALUE = item.Value
347
                });
348 60244a8b gaqhf
            }
349
        }
350
351
        private void SetAttributes(XElement node, List<Attribute> attributes)
352
        {
353 30d2cfcc gaqhf
            foreach (XElement item in node.Elements("ATTRIBUTE"))
354 60244a8b gaqhf
            {
355
                attributes.Add(new Attribute()
356
                {
357
                    UID = item.Attribute("UID").Value,
358
                    LENGTH = item.Attribute("Length").Value,
359
                    EXPRESSION = item.Attribute("Expression").Value,
360
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
361
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
362
                    ATTRIBUTE = item.Attribute("Attribute").Value,
363 30d2cfcc gaqhf
                    ATTRAT = item.Attribute("AttrAt").Value,
364 60244a8b gaqhf
                    VALUE = item.Value
365
                });
366
            }
367
        }
368
369 8aa6f2db gaqhf
        private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns)
370 60244a8b gaqhf
        {
371
            foreach (XElement item in node.Elements("RUN"))
372
            {
373 8aa6f2db gaqhf
                LineRun run = new LineRun()
374 60244a8b gaqhf
                {
375
                    TYPE = item.Attribute("TYPE").Value
376
                };
377
378
                foreach (XElement element in item.Elements())
379
                {
380
                    if (element.Name == "SYMBOL")
381
                    {
382
                        run.RUNITEMS.Add(GetSymbolByUID(element.Element("UID").Value));
383
                    }
384
                    else if (element.Name == "LINE")
385
                    {
386
                        run.RUNITEMS.Add(GetLineByUID(element.Element("UID").Value));
387
                    }
388
                }
389
                lineNumberRuns.Add(run);
390
            }
391
        }
392 30d2cfcc gaqhf
393
        private void SetChildSymbol(Symbol symbol)
394
        {
395
            List<ChildSymbol> childList = new List<ChildSymbol>();
396
            if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None")
397
            {
398
                string[] childArray = symbol.CHILD.Split(new char[] { '/' });
399
                foreach (string sChild in childArray)
400
                {
401
                    string[] sChildInfo = sChild.Split(new char[] { ',' });
402
                    childList.Add(new ChildSymbol()
403
                    {
404
                        ParentAt = Convert.ToInt32(sChildInfo[0]),
405
                        Direction = sChildInfo[1],
406
                        NAME = sChildInfo[2]
407
                    });
408
                }
409
410
                foreach (ChildSymbol child in childList)
411
                {
412
                    if (child.ParentAt == 0)
413
                        symbol.ChildSymbols.Add(child);
414
                    else
415
                        childList[child.ParentAt - 1].ChildSymbols.Add(child);
416
                }
417
            }
418
            if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None")
419
            {
420 f1c9dbaa gaqhf
                // 현재 부모 Symbol에 자식 Connector까지 들어가 있음
421 30d2cfcc gaqhf
                string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
422
                string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
423
                for (int i = 0; i < array.Length; i++)
424
                {
425
                    string[] arrConn = array[i].Split(new char[] { ',' });
426
                    int connIndex = Convert.ToInt32(arrConn[3]);
427
                    if (connIndex != 0)
428 5dfb8a24 gaqhf
                    {
429 30d2cfcc gaqhf
                        childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]);
430 f1c9dbaa gaqhf
                        symbol.CONNECTORS[i].Index = connIndex;
431 5dfb8a24 gaqhf
                    }
432
                }
433 30d2cfcc gaqhf
            }
434
        }
435 60244a8b gaqhf
        #endregion
436
437
        public Symbol GetSymbolByUID(string uid)
438
        {
439
            return SYMBOLS.Find(x => x.UID == uid);
440
        }
441
442
        public Line GetLineByUID(string uid)
443
        {
444
            return LINES.Find(x => x.UID == uid);
445
        }
446 96a2080c gaqhf
    }
447
}
클립보드 이미지 추가 (최대 크기: 500 MB)