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