프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / BaseModel / Model / Document.cs @ f1c9dbaa

이력 | 보기 | 이력해설 | 다운로드 (17.9 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<EndBreak> _EndBreaks = new List<EndBreak>();
24
        private List<Equipment> _Equipments = new List<Equipment>();
25
        private bool _Enable;
26

    
27
        public bool Enable { get { return _Enable; } }
28

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

    
58
        public Document(string xmlPath)
59
        {
60
            try
61
            {
62
                XElement xml = XElement.Load(xmlPath);
63
                DWGNAME = xml.Element("DWGNAME").Value;
64
                SIZE = xml.Element("SIZE").Value;
65

    
66
                SetSymbol(xml.Element("SYMBOLS"));
67
                SetLine(xml.Element("LINEINFOS"));
68
                SetLineNumber(xml.Element("LINENOS"));
69
                SetText(xml.Element("TEXTINFOS"));
70
                SetNote(xml.Element("NOTES"));
71

    
72
                _Enable = true;
73
            }
74
            catch (Exception ex)
75
            {
76
                _Enable = false;
77
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
78
            }
79
        }
80

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

    
117
                    EndBreaks.Add(endBreak);
118
                }
119
                else if (sType == "Black Box System" ||
120
                    sType == "GGO_Equipment" ||
121
                    sType == "Heat Transfer Equipment" ||
122
                    sType == "Labels - Equipment" ||
123
                    sType == "Mechanical" ||
124
                    sType == "Other Equipment" ||
125
                    sType == "Vessels")
126
                {
127
                    Equipment equipment = new Equipment()
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"), equipment.ASSOCIATIONS);
147
                    SetSymbolConnectors(item.Element("CONNECTORS"), equipment.CONNECTORS, equipment.CONNECTIONPOINT);
148
                    SetProperties(item.Element("PROPERTIES"), equipment.PROPERTIES);
149
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), equipment.ATTRIBUTES);
150

    
151
                    Equipments.Add(equipment);
152
                }
153
                else
154
                {
155
                    Symbol symbol = new Symbol()
156
                    {
157
                        UID = item.Element("UID").Value,
158
                        DBUID = item.Element("DBUID").Value,
159
                        NAME = item.Element("NAME").Value,
160
                        TYPE = item.Element("TYPE").Value,
161
                        OWNER = item.Element("OWNER").Value,
162
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
163
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
164
                        LOCATION = item.Element("LOCATION").Value,
165
                        SIZE = item.Element("SIZE").Value,
166
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
167
                        PARENT = item.Element("PARENT").Value,
168
                        CHILD = item.Element("CHILD").Value,
169
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
170
                        AREA = item.Element("AREA").Value,
171
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
172
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
173
                    };
174
                    SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS);
175
                    SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT);
176
                    SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES);
177
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES);
178
                    SetChildSymbol(symbol);
179

    
180
                    SYMBOLS.Add(symbol);
181
                }
182
            }
183
        }
184

    
185
        private void SetLine(XElement node)
186
        {
187
            foreach (XElement item in node.Elements("LINE"))
188
            {
189
                Line line = new Line()
190
                {
191
                    OWNER = item.Attribute("OWNER").Value,
192
                    UID = item.Element("UID").Value,
193
                    STARTPOINT = item.Element("STARTPOINT").Value,
194
                    ENDPOINT = item.Element("ENDPOINT").Value,
195
                    TYPE = item.Element("TYPE").Value,
196
                    TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value,
197
                    AREA = item.Element("AREA").Value,
198
                    THICKNESS = item.Element("THICKNESS").Value,
199
                };
200
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
201
                LINES.Add(line);
202
            }
203
        }
204

    
205
        private void SetLineNumber(XElement node)
206
        {
207
            foreach (XElement item in node.Elements("LINE_NO"))
208
            {
209
                LineNumber lineNumber = new LineNumber()
210
                {
211
                    UID = item.Element("UID").Value,
212
                    TEXT = item.Element("TEXT").Value,
213
                    LOCATION = item.Element("LOCATION").Value,
214
                    WIDTH = item.Element("WIDTH").Value,
215
                    HEIGHT = item.Element("HEIGHT").Value,
216
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
217
                    AREA = item.Element("AREA").Value
218
                };
219
                SetLineNumberRuns(item, lineNumber.RUNS);
220
                SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
221
                SetAttributes(item, lineNumber.ATTRIBUTES);
222
                LINENUMBERS.Add(lineNumber);
223
            }
224
        }
225

    
226
        private void SetText(XElement node)
227
        {
228
            foreach (XElement item in node.Elements("ATTRIBUTE"))
229
            {
230
                Text text = new Text()
231
                {
232
                    UID = item.Element("UID").Value,
233
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
234
                    NAME = item.Element("NAME").Value,
235
                    LOCATION = item.Element("LOCATION").Value,
236
                    VALUE = item.Element("VALUE").Value,
237
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
238
                    WIDTH = item.Element("WIDTH").Value,
239
                    HEIGHT = item.Element("HEIGHT").Value,
240
                    AREA = item.Element("AREA").Value
241
                };
242

    
243
                TEXTINFOS.Add(text);
244
            }
245
        }
246

    
247
        private void SetNote(XElement node)
248
        {
249
            foreach (XElement item in node.Elements("ATTRIBUTE"))
250
            {
251
                Note note = new Note()
252
                {
253
                    UID = item.Element("UID").Value,
254
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
255
                    NAME = item.Element("NAME").Value,
256
                    LOCATION = item.Element("LOCATION").Value,
257
                    VALUE = item.Element("VALUE").Value,
258
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
259
                    WIDTH = item.Element("WIDTH").Value,
260
                    HEIGHT = item.Element("HEIGHT").Value,
261
                    AREA = item.Element("AREA").Value
262
                };
263

    
264
                NOTES.Add(note);
265
            }
266
        }
267
       
268
        private void SetAssociations(XElement node, List<Association> associations)
269
        {
270
            foreach (XElement item in node.Elements("ASSOCIATION"))
271
            {
272
                associations.Add(new Association()
273
                {
274
                    TYPE = item.Attribute("TYPE").Value,
275
                    VALUE = item.Value
276
                });
277
            }
278
        }
279

    
280
        private void SetConnectors(XElement node, List<Connector> connectors)
281
        {
282
            foreach (XElement item in node.Elements("CONNECTOR"))
283
            {
284
                connectors.Add(new Connector()
285
                {
286
                    UID = item.Attribute("UID").Value,
287
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
288
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
289
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
290
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
291
                });
292
            }
293
        }
294

    
295
        private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT)
296
        {
297
            foreach (XElement item in node.Elements("CONNECTOR"))
298
            {
299
                connectors.Add(new Connector()
300
                {
301
                    UID = item.Attribute("UID").Value,
302
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
303
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
304
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
305
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
306
                });
307
            }
308
        }
309

    
310
        private void SetProperties(XElement node, List<Property> properties)
311
        {
312
            foreach (XElement item in node.Elements("PROPERTY"))
313
            {
314
                properties.Add(new Property()
315
                {
316
                    UID = item.Attribute("UID").Value,
317
                    LENGTH = item.Attribute("Length").Value,
318
                    EXPRESSION = item.Attribute("Expression").Value,
319
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
320
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
321
                    ATTRIBUTE = item.Attribute("Attribute").Value,
322
                    VALUE = item.Value
323
                });
324
            }
325
        }
326

    
327
        private void SetAttributes(XElement node, List<Attribute> attributes)
328
        {
329
            foreach (XElement item in node.Elements("ATTRIBUTE"))
330
            {
331
                attributes.Add(new Attribute()
332
                {
333
                    UID = item.Attribute("UID").Value,
334
                    LENGTH = item.Attribute("Length").Value,
335
                    EXPRESSION = item.Attribute("Expression").Value,
336
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
337
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
338
                    ATTRIBUTE = item.Attribute("Attribute").Value,
339
                    ATTRAT = item.Attribute("AttrAt").Value,
340
                    VALUE = item.Value
341
                });
342
            }
343
        }
344

    
345
        private void SetLineNumberRuns(XElement node, List<LineNumberRun> lineNumberRuns)
346
        {
347
            foreach (XElement item in node.Elements("RUN"))
348
            {
349
                LineNumberRun run = new LineNumberRun()
350
                {
351
                    TYPE = item.Attribute("TYPE").Value
352
                };
353

    
354
                foreach (XElement element in item.Elements())
355
                {
356
                    if (element.Name == "SYMBOL")
357
                    {
358
                        run.RUNITEMS.Add(GetSymbolByUID(element.Element("UID").Value));
359
                    }
360
                    else if (element.Name == "LINE")
361
                    {
362
                        run.RUNITEMS.Add(GetLineByUID(element.Element("UID").Value));
363
                    }
364
                }
365
                lineNumberRuns.Add(run);
366
            }
367
        }
368

    
369
        private void SetChildSymbol(Symbol symbol)
370
        {
371
            List<ChildSymbol> childList = new List<ChildSymbol>();
372
            if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None")
373
            {
374
                string[] childArray = symbol.CHILD.Split(new char[] { '/' });
375
                foreach (string sChild in childArray)
376
                {
377
                    string[] sChildInfo = sChild.Split(new char[] { ',' });
378
                    childList.Add(new ChildSymbol()
379
                    {
380
                        ParentAt = Convert.ToInt32(sChildInfo[0]),
381
                        Direction = sChildInfo[1],
382
                        NAME = sChildInfo[2]
383
                    });
384
                }
385

    
386
                foreach (ChildSymbol child in childList)
387
                {
388
                    if (child.ParentAt == 0)
389
                        symbol.ChildSymbols.Add(child);
390
                    else
391
                        childList[child.ParentAt - 1].ChildSymbols.Add(child);
392
                }
393
            }
394
            if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None")
395
            {
396
                // 현재 부모 Symbol에 자식 Connector까지 들어가 있음
397
                string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
398
                string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
399
                for (int i = 0; i < array.Length; i++)
400
                {
401
                    string[] arrConn = array[i].Split(new char[] { ',' });
402
                    int connIndex = Convert.ToInt32(arrConn[3]);
403
                    if (connIndex != 0)
404
                    {
405
                        childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]);
406
                        symbol.CONNECTORS[i].Index = connIndex;
407
                    }
408
                }
409
            }
410
        }
411
        #endregion
412

    
413
        public Symbol GetSymbolByUID(string uid)
414
        {
415
            return SYMBOLS.Find(x => x.UID == uid);
416
        }
417

    
418
        public Line GetLineByUID(string uid)
419
        {
420
            return LINES.Find(x => x.UID == uid);
421
        }
422
    }
423
}
클립보드 이미지 추가 (최대 크기: 500 MB)