프로젝트

일반

사용자정보

통계
| 개정판:

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

이력 | 보기 | 이력해설 | 다운로드 (13.8 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 bool _Enable;
24

    
25
        public bool Enable { get { return _Enable; } }
26

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

    
53
        public Document(string xmlPath)
54
        {
55
            try
56
            {
57
                XElement xml = XElement.Load(xmlPath);
58
                DWGNAME = xml.Element("DWGNAME").Value;
59
                SIZE = xml.Element("SIZE").Value;
60

    
61
                SetSymbol(xml.Element("SYMBOLS"));
62
                SetLine(xml.Element("LINEINFOS"));
63
                SetLineNumber(xml.Element("LINENOS"));
64
                SetText(xml.Element("TEXTINFOS"));
65
                SetNote(xml.Element("NOTES"));
66

    
67
                _Enable = true;
68
            }
69
            catch (Exception ex)
70
            {
71
                _Enable = false;
72
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
73
            }
74
        }
75

    
76
        #region READ XML
77
        private void SetSymbol(XElement node)
78
        {
79
            foreach (XElement item in node.Elements("SYMBOL"))
80
            {
81
                Symbol symbol = new Symbol()
82
                {
83
                    UID = item.Element("UID").Value,
84
                    DBUID = item.Element("DBUID").Value,
85
                    NAME = item.Element("NAME").Value,
86
                    TYPE = item.Element("TYPE").Value,
87
                    OWNER = item.Element("OWNER").Value,
88
                    ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
89
                    CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
90
                    LOCATION = item.Element("LOCATION").Value,
91
                    SIZE = item.Element("SIZE").Value,
92
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
93
                    PARENT = item.Element("PARENT").Value,
94
                    CHILD = item.Element("CHILD").Value,
95
                    HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
96
                    AREA = item.Element("AREA").Value,
97
                    FLIP = Convert.ToInt32(item.Element("FLIP").Value),
98
                    CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
99
                };
100
                SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS);
101
                SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT);
102
                SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES);
103
                SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES);
104
                SetChildSymbol(symbol);
105

    
106
                SYMBOLS.Add(symbol);
107
            }
108
        }
109

    
110
        private void SetLine(XElement node)
111
        {
112
            foreach (XElement item in node.Elements("LINE"))
113
            {
114
                Line line = new Line()
115
                {
116
                    OWNER = item.Attribute("OWNER").Value,
117
                    UID = item.Element("UID").Value,
118
                    STARTPOINT = item.Element("STARTPOINT").Value,
119
                    ENDPOINT = item.Element("ENDPOINT").Value,
120
                    TYPE = item.Element("TYPE").Value,
121
                    TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value,
122
                    AREA = item.Element("AREA").Value,
123
                    THICKNESS = item.Element("THICKNESS").Value,
124
                };
125
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
126
                LINES.Add(line);
127
            }
128
        }
129

    
130
        private void SetLineNumber(XElement node)
131
        {
132
            foreach (XElement item in node.Elements("LINE_NO"))
133
            {
134
                LineNumber lineNumber = new LineNumber()
135
                {
136
                    UID = item.Element("UID").Value,
137
                    TEXT = item.Element("TEXT").Value,
138
                    LOCATION = item.Element("LOCATION").Value,
139
                    WIDTH = item.Element("WIDTH").Value,
140
                    HEIGHT = item.Element("HEIGHT").Value,
141
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
142
                    AREA = item.Element("AREA").Value
143
                };
144
                SetLineNumberRuns(item, lineNumber.RUNS);
145
                SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
146
                SetAttributes(item, lineNumber.ATTRIBUTES);
147
                LINENUMBERS.Add(lineNumber);
148
            }
149
        }
150

    
151
        private void SetText(XElement node)
152
        {
153
            foreach (XElement item in node.Elements("ATTRIBUTE"))
154
            {
155
                Text text = new Text()
156
                {
157
                    UID = item.Element("UID").Value,
158
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
159
                    NAME = item.Element("NAME").Value,
160
                    LOCATION = item.Element("LOCATION").Value,
161
                    VALUE = item.Element("VALUE").Value,
162
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
163
                    WIDTH = item.Element("WIDTH").Value,
164
                    HEIGHT = item.Element("HEIGHT").Value,
165
                    AREA = item.Element("AREA").Value
166
                };
167

    
168
                TEXTINFOS.Add(text);
169
            }
170
        }
171

    
172
        private void SetNote(XElement node)
173
        {
174
            foreach (XElement item in node.Elements("ATTRIBUTE"))
175
            {
176
                Note note = new Note()
177
                {
178
                    UID = item.Element("UID").Value,
179
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
180
                    NAME = item.Element("NAME").Value,
181
                    LOCATION = item.Element("LOCATION").Value,
182
                    VALUE = item.Element("VALUE").Value,
183
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
184
                    WIDTH = item.Element("WIDTH").Value,
185
                    HEIGHT = item.Element("HEIGHT").Value,
186
                    AREA = item.Element("AREA").Value
187
                };
188

    
189
                NOTES.Add(note);
190
            }
191
        }
192
       
193
        private void SetAssociations(XElement node, List<Association> associations)
194
        {
195
            foreach (XElement item in node.Elements("ASSOCIATION"))
196
            {
197
                associations.Add(new Association()
198
                {
199
                    TYPE = item.Attribute("TYPE").Value,
200
                    VALUE = item.Value
201
                });
202
            }
203
        }
204

    
205
        private void SetConnectors(XElement node, List<Connector> connectors)
206
        {
207
            foreach (XElement item in node.Elements("CONNECTOR"))
208
            {
209
                connectors.Add(new Connector()
210
                {
211
                    UID = item.Attribute("UID").Value,
212
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
213
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
214
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
215
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
216
                });
217
            }
218
        }
219

    
220
        private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT)
221
        {
222
            foreach (XElement item in node.Elements("CONNECTOR"))
223
            {
224
                connectors.Add(new Connector()
225
                {
226
                    UID = item.Attribute("UID").Value,
227
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
228
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
229
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
230
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
231
                });
232
            }
233
        }
234

    
235
        private void SetProperties(XElement node, List<Property> properties)
236
        {
237
            foreach (XElement item in node.Elements("PROPERTY"))
238
            {
239
                properties.Add(new Property()
240
                {
241
                    UID = item.Attribute("UID").Value,
242
                    LENGTH = item.Attribute("Length").Value,
243
                    EXPRESSION = item.Attribute("Expression").Value,
244
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
245
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
246
                    ATTRIBUTE = item.Attribute("Attribute").Value,
247
                    VALUE = item.Value
248
                });
249
            }
250
        }
251

    
252
        private void SetAttributes(XElement node, List<Attribute> attributes)
253
        {
254
            foreach (XElement item in node.Elements("ATTRIBUTE"))
255
            {
256
                attributes.Add(new Attribute()
257
                {
258
                    UID = item.Attribute("UID").Value,
259
                    LENGTH = item.Attribute("Length").Value,
260
                    EXPRESSION = item.Attribute("Expression").Value,
261
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
262
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
263
                    ATTRIBUTE = item.Attribute("Attribute").Value,
264
                    ATTRAT = item.Attribute("AttrAt").Value,
265
                    VALUE = item.Value
266
                });
267
            }
268
        }
269

    
270
        private void SetLineNumberRuns(XElement node, List<LineNumberRun> lineNumberRuns)
271
        {
272
            foreach (XElement item in node.Elements("RUN"))
273
            {
274
                LineNumberRun run = new LineNumberRun()
275
                {
276
                    TYPE = item.Attribute("TYPE").Value
277
                };
278

    
279
                foreach (XElement element in item.Elements())
280
                {
281
                    if (element.Name == "SYMBOL")
282
                    {
283
                        run.RUNITEMS.Add(GetSymbolByUID(element.Element("UID").Value));
284
                    }
285
                    else if (element.Name == "LINE")
286
                    {
287
                        run.RUNITEMS.Add(GetLineByUID(element.Element("UID").Value));
288
                    }
289
                }
290
                lineNumberRuns.Add(run);
291
            }
292
        }
293

    
294
        private void SetChildSymbol(Symbol symbol)
295
        {
296
            List<ChildSymbol> childList = new List<ChildSymbol>();
297
            if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None")
298
            {
299
                string[] childArray = symbol.CHILD.Split(new char[] { '/' });
300
                foreach (string sChild in childArray)
301
                {
302
                    string[] sChildInfo = sChild.Split(new char[] { ',' });
303
                    childList.Add(new ChildSymbol()
304
                    {
305
                        ParentAt = Convert.ToInt32(sChildInfo[0]),
306
                        Direction = sChildInfo[1],
307
                        NAME = sChildInfo[2]
308
                    });
309
                }
310

    
311
                foreach (ChildSymbol child in childList)
312
                {
313
                    if (child.ParentAt == 0)
314
                        symbol.ChildSymbols.Add(child);
315
                    else
316
                        childList[child.ParentAt - 1].ChildSymbols.Add(child);
317
                }
318
            }
319
            if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None")
320
            {
321
                string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
322
                string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
323
                List<Connector> childConnector = new List<Connector>();
324
                for (int i = 0; i < array.Length; i++)
325
                {
326
                    string[] arrConn = array[i].Split(new char[] { ',' });
327
                    int connIndex = Convert.ToInt32(arrConn[3]);
328
                    if (connIndex != 0)
329
                    {
330
                        childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]);
331
                        childConnector.Add(symbol.CONNECTORS[i]);
332
                    }
333
                }
334

    
335
                foreach (var connector in childConnector)
336
                {
337
                    symbol.CONNECTORS.Remove(connector);
338
                }
339
            }
340
        }
341
        #endregion
342

    
343
        public Symbol GetSymbolByUID(string uid)
344
        {
345
            return SYMBOLS.Find(x => x.UID == uid);
346
        }
347

    
348
        public Line GetLineByUID(string uid)
349
        {
350
            return LINES.Find(x => x.UID == uid);
351
        }
352
    }
353
}
클립보드 이미지 추가 (최대 크기: 500 MB)