hytos / DTI_PID / BaseModel / Model / Document.cs @ 1efc25a3
이력 | 보기 | 이력해설 | 다운로드 (18.5 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 |
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 |
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 |
}; |
222 |
SetLineNumberRuns(item, lineNumber.RUNS); |
223 |
SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES); |
224 |
SetAttributes(item, lineNumber.ATTRIBUTES); |
225 |
LINENUMBERS.Add(lineNumber); |
226 |
} |
227 |
} |
228 |
|
229 |
private void SetText(XElement node) |
230 |
{ |
231 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
232 |
{ |
233 |
Text text = new Text() |
234 |
{ |
235 |
UID = item.Element("UID").Value, |
236 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
237 |
NAME = item.Element("NAME").Value, |
238 |
LOCATION = item.Element("LOCATION").Value, |
239 |
VALUE = item.Element("VALUE").Value, |
240 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
241 |
WIDTH = item.Element("WIDTH").Value, |
242 |
HEIGHT = item.Element("HEIGHT").Value, |
243 |
AREA = item.Element("AREA").Value |
244 |
}; |
245 |
|
246 |
TEXTINFOS.Add(text); |
247 |
} |
248 |
} |
249 |
|
250 |
private void SetNote(XElement node) |
251 |
{ |
252 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
253 |
{ |
254 |
Note note = new Note() |
255 |
{ |
256 |
UID = item.Element("UID").Value, |
257 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
258 |
NAME = item.Element("NAME").Value, |
259 |
LOCATION = item.Element("LOCATION").Value, |
260 |
VALUE = item.Element("VALUE").Value, |
261 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
262 |
WIDTH = item.Element("WIDTH").Value, |
263 |
HEIGHT = item.Element("HEIGHT").Value, |
264 |
AREA = item.Element("AREA").Value |
265 |
}; |
266 |
|
267 |
NOTES.Add(note); |
268 |
} |
269 |
} |
270 |
|
271 |
private void SetTrimLine(XElement node) |
272 |
{ |
273 |
foreach (XElement item in node.Elements("TRIM_LINE_NO")) |
274 |
{ |
275 |
TrimLine trimLine = new TrimLine() |
276 |
{ |
277 |
UID = item.Element("UID").Value, |
278 |
}; |
279 |
SetLineNumberRuns(item, trimLine.RUNS); |
280 |
TRIMLINES.Add(trimLine); |
281 |
} |
282 |
} |
283 |
|
284 |
private void SetAssociations(XElement node, List<Association> associations) |
285 |
{ |
286 |
foreach (XElement item in node.Elements("ASSOCIATION")) |
287 |
{ |
288 |
associations.Add(new Association() |
289 |
{ |
290 |
TYPE = item.Attribute("TYPE").Value, |
291 |
VALUE = item.Value |
292 |
}); |
293 |
} |
294 |
} |
295 |
|
296 |
private void SetConnectors(XElement node, List<Connector> connectors) |
297 |
{ |
298 |
foreach (XElement item in node.Elements("CONNECTOR")) |
299 |
{ |
300 |
connectors.Add(new Connector() |
301 |
{ |
302 |
UID = item.Attribute("UID").Value, |
303 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
304 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
305 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
306 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
307 |
}); |
308 |
} |
309 |
} |
310 |
|
311 |
private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT) |
312 |
{ |
313 |
foreach (XElement item in node.Elements("CONNECTOR")) |
314 |
{ |
315 |
connectors.Add(new Connector() |
316 |
{ |
317 |
UID = item.Attribute("UID").Value, |
318 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
319 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
320 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
321 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
322 |
}); |
323 |
} |
324 |
} |
325 |
|
326 |
private void SetProperties(XElement node, List<Property> properties) |
327 |
{ |
328 |
foreach (XElement item in node.Elements("PROPERTY")) |
329 |
{ |
330 |
properties.Add(new Property() |
331 |
{ |
332 |
UID = item.Attribute("UID").Value, |
333 |
LENGTH = item.Attribute("Length").Value, |
334 |
EXPRESSION = item.Attribute("Expression").Value, |
335 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
336 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
337 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
338 |
VALUE = item.Value |
339 |
}); |
340 |
} |
341 |
} |
342 |
|
343 |
private void SetAttributes(XElement node, List<Attribute> attributes) |
344 |
{ |
345 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
346 |
{ |
347 |
attributes.Add(new Attribute() |
348 |
{ |
349 |
UID = item.Attribute("UID").Value, |
350 |
LENGTH = item.Attribute("Length").Value, |
351 |
EXPRESSION = item.Attribute("Expression").Value, |
352 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
353 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
354 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
355 |
ATTRAT = item.Attribute("AttrAt").Value, |
356 |
VALUE = item.Value |
357 |
}); |
358 |
} |
359 |
} |
360 |
|
361 |
private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns) |
362 |
{ |
363 |
foreach (XElement item in node.Elements("RUN")) |
364 |
{ |
365 |
LineRun run = new LineRun() |
366 |
{ |
367 |
TYPE = item.Attribute("TYPE").Value |
368 |
}; |
369 |
|
370 |
foreach (XElement element in item.Elements()) |
371 |
{ |
372 |
if (element.Name == "SYMBOL") |
373 |
{ |
374 |
run.RUNITEMS.Add(GetSymbolByUID(element.Element("UID").Value)); |
375 |
} |
376 |
else if (element.Name == "LINE") |
377 |
{ |
378 |
run.RUNITEMS.Add(GetLineByUID(element.Element("UID").Value)); |
379 |
} |
380 |
} |
381 |
lineNumberRuns.Add(run); |
382 |
} |
383 |
} |
384 |
|
385 |
private void SetChildSymbol(Symbol symbol) |
386 |
{ |
387 |
List<ChildSymbol> childList = new List<ChildSymbol>(); |
388 |
if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None") |
389 |
{ |
390 |
string[] childArray = symbol.CHILD.Split(new char[] { '/' }); |
391 |
foreach (string sChild in childArray) |
392 |
{ |
393 |
string[] sChildInfo = sChild.Split(new char[] { ',' }); |
394 |
childList.Add(new ChildSymbol() |
395 |
{ |
396 |
ParentAt = Convert.ToInt32(sChildInfo[0]), |
397 |
Direction = sChildInfo[1], |
398 |
NAME = sChildInfo[2] |
399 |
}); |
400 |
} |
401 |
|
402 |
foreach (ChildSymbol child in childList) |
403 |
{ |
404 |
if (child.ParentAt == 0) |
405 |
symbol.ChildSymbols.Add(child); |
406 |
else |
407 |
childList[child.ParentAt - 1].ChildSymbols.Add(child); |
408 |
} |
409 |
} |
410 |
if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None") |
411 |
{ |
412 |
// 현재 부모 Symbol에 자식 Connector까지 들어가 있음 |
413 |
string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' }); |
414 |
string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' }); |
415 |
for (int i = 0; i < array.Length; i++) |
416 |
{ |
417 |
string[] arrConn = array[i].Split(new char[] { ',' }); |
418 |
int connIndex = Convert.ToInt32(arrConn[3]); |
419 |
if (connIndex != 0) |
420 |
{ |
421 |
childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]); |
422 |
symbol.CONNECTORS[i].Index = connIndex; |
423 |
} |
424 |
} |
425 |
} |
426 |
} |
427 |
#endregion |
428 |
|
429 |
public Symbol GetSymbolByUID(string uid) |
430 |
{ |
431 |
return SYMBOLS.Find(x => x.UID == uid); |
432 |
} |
433 |
|
434 |
public Line GetLineByUID(string uid) |
435 |
{ |
436 |
return LINES.Find(x => x.UID == uid); |
437 |
} |
438 |
} |
439 |
} |