hytos / DTI_PID / BaseModel / Model / Document.cs @ ea80efaa
이력 | 보기 | 이력해설 | 다운로드 (18.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 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 == "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 |
|
153 |
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 |
|
177 |
SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS); |
178 |
SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT); |
179 |
SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES); |
180 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES); |
181 |
SetChildSymbol(symbol); |
182 |
|
183 |
SYMBOLS.Add(symbol); |
184 |
} |
185 |
} |
186 |
} |
187 |
|
188 |
private void SetLine(XElement node) |
189 |
{ |
190 |
foreach (XElement item in node.Elements("LINE")) |
191 |
{ |
192 |
Line line = new Line() |
193 |
{ |
194 |
OWNER = item.Attribute("OWNER").Value, |
195 |
UID = item.Element("UID").Value, |
196 |
STARTPOINT = item.Element("STARTPOINT").Value, |
197 |
ENDPOINT = item.Element("ENDPOINT").Value, |
198 |
TYPE = item.Element("TYPE").Value, |
199 |
TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value, |
200 |
AREA = item.Element("AREA").Value, |
201 |
THICKNESS = item.Element("THICKNESS").Value, |
202 |
}; |
203 |
SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS); |
204 |
LINES.Add(line); |
205 |
} |
206 |
} |
207 |
|
208 |
private void SetLineNumber(XElement node) |
209 |
{ |
210 |
foreach (XElement item in node.Elements("LINE_NO")) |
211 |
{ |
212 |
LineNumber lineNumber = new LineNumber() |
213 |
{ |
214 |
UID = item.Element("UID").Value, |
215 |
TEXT = item.Element("TEXT").Value, |
216 |
LOCATION = item.Element("LOCATION").Value, |
217 |
WIDTH = item.Element("WIDTH").Value, |
218 |
HEIGHT = item.Element("HEIGHT").Value, |
219 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
220 |
AREA = item.Element("AREA").Value, |
221 |
CONNLINE = item.Element("CONNLINE").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 |
}; |
247 |
|
248 |
TEXTINFOS.Add(text); |
249 |
} |
250 |
} |
251 |
|
252 |
private void SetNote(XElement node) |
253 |
{ |
254 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
255 |
{ |
256 |
Note note = new Note() |
257 |
{ |
258 |
UID = item.Element("UID").Value, |
259 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
260 |
NAME = item.Element("NAME").Value, |
261 |
LOCATION = item.Element("LOCATION").Value, |
262 |
VALUE = item.Element("VALUE").Value, |
263 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
264 |
WIDTH = item.Element("WIDTH").Value, |
265 |
HEIGHT = item.Element("HEIGHT").Value, |
266 |
AREA = item.Element("AREA").Value |
267 |
}; |
268 |
|
269 |
NOTES.Add(note); |
270 |
} |
271 |
} |
272 |
|
273 |
private void SetTrimLine(XElement node) |
274 |
{ |
275 |
foreach (XElement item in node.Elements("TRIM_LINE_NO")) |
276 |
{ |
277 |
TrimLine trimLine = new TrimLine() |
278 |
{ |
279 |
UID = item.Element("UID").Value, |
280 |
}; |
281 |
SetLineNumberRuns(item, trimLine.RUNS); |
282 |
TRIMLINES.Add(trimLine); |
283 |
} |
284 |
} |
285 |
|
286 |
private void SetAssociations(XElement node, List<Association> associations) |
287 |
{ |
288 |
foreach (XElement item in node.Elements("ASSOCIATION")) |
289 |
{ |
290 |
Association association = new Association() |
291 |
{ |
292 |
TYPE = item.Attribute("TYPE").Value, |
293 |
VALUE = item.Value |
294 |
}; |
295 |
|
296 |
Text text = _TEXTINFOS.Find(x => x.UID == association.VALUE); |
297 |
if (text != null) |
298 |
text.ASSOCIATION = true; |
299 |
|
300 |
associations.Add(association); |
301 |
} |
302 |
} |
303 |
|
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 |
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 |
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 |
properties.Add(new Property() |
339 |
{ |
340 |
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 |
} |
349 |
} |
350 |
|
351 |
private void SetAttributes(XElement node, List<Attribute> attributes) |
352 |
{ |
353 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
354 |
{ |
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 |
ATTRAT = item.Attribute("AttrAt").Value, |
364 |
VALUE = item.Value |
365 |
}); |
366 |
} |
367 |
} |
368 |
|
369 |
private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns) |
370 |
{ |
371 |
foreach (XElement item in node.Elements("RUN")) |
372 |
{ |
373 |
LineRun run = new LineRun() |
374 |
{ |
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 |
|
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 |
// 현재 부모 Symbol에 자식 Connector까지 들어가 있음 |
421 |
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 |
{ |
429 |
childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]); |
430 |
symbol.CONNECTORS[i].Index = connIndex; |
431 |
} |
432 |
} |
433 |
} |
434 |
} |
435 |
#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 |
} |
447 |
} |