hytos / DTI_PID / APIDConverter / Model / PlantItem / Document.cs @ 20dd244c
이력 | 보기 | 이력해설 | 다운로드 (37.6 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Text; |
4 |
using System.Linq; |
5 |
using System.Threading.Tasks; |
6 |
using System.Xml.Linq; |
7 |
using System.IO; |
8 |
using System.Data; |
9 |
using System.Windows.Forms; |
10 |
|
11 |
namespace AVEVA.PID.CustomizationUtility.Model |
12 |
{ |
13 |
public class Document |
14 |
{ |
15 |
private string _DWGNAME; |
16 |
private string _SIZE; |
17 |
private double _SIZE_WIDTH; |
18 |
private double _SIZE_HEIGHT; |
19 |
private string _UID; |
20 |
private List<Symbol> _SYMBOLS = new List<Symbol>(); |
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<SpecBreak> _SpecBreaks = new List<SpecBreak>(); |
26 |
private List<Equipment> _Equipments = new List<Equipment>(); |
27 |
private List<Text> _Texts = new List<Text>(); |
28 |
private List<Note> _Notes = new List<Note>(); |
29 |
private List<OPC> _OPCs = new List<OPC>(); |
30 |
private bool _Enable; |
31 |
private bool _Validation; |
32 |
private bool _MappingValidation; |
33 |
private string _ValidationMessage = string.Empty; |
34 |
bool validationResult = false; |
35 |
private DataTable ID2SymbolTypeDT; |
36 |
|
37 |
public string AvevaDrawingNumber { get; set; } |
38 |
public string AvevaSheetNumber { get; set; } |
39 |
public string AvevaTemplateID { get; set; } |
40 |
public string AvevaTemplateName { get; set; } |
41 |
|
42 |
public string ValidationMessage { get => _ValidationMessage; set => _ValidationMessage = value; } |
43 |
|
44 |
public List<Symbol> SYMBOLS { get => _SYMBOLS; set => _SYMBOLS = value; } |
45 |
public List<Line> LINES { get => _LINES; set => _LINES = value; } |
46 |
public List<LineNumber> LINENUMBERS { get => _LINENUMBERS; set => _LINENUMBERS = value; } |
47 |
public List<EndBreak> EndBreaks { get => _EndBreaks; set => _EndBreaks = value; } |
48 |
public List<SpecBreak> SpecBreaks { get => _SpecBreaks; set => _SpecBreaks = value; } |
49 |
public List<Equipment> Equipments { get => _Equipments; set => _Equipments = value; } |
50 |
public string DWGNAME { get => _DWGNAME; set => _DWGNAME = value; } |
51 |
public string SIZE |
52 |
{ |
53 |
get |
54 |
{ |
55 |
return _SIZE; |
56 |
} |
57 |
set |
58 |
{ |
59 |
_SIZE = value; |
60 |
string[] pointArr = _SIZE.Split(new char[] { ',' }); |
61 |
if (pointArr.Length == 2) |
62 |
{ |
63 |
_SIZE_WIDTH = Convert.ToDouble(pointArr[0]); |
64 |
_SIZE_HEIGHT = Convert.ToDouble(pointArr[1]); |
65 |
} |
66 |
} |
67 |
} |
68 |
public double SIZE_WIDTH { get => _SIZE_WIDTH; } |
69 |
public double SIZE_HEIGHT { get => _SIZE_HEIGHT; } |
70 |
public List<TrimLine> TRIMLINES { get => _TRIMLINES; set => _TRIMLINES = value; } |
71 |
public string PATH { get; set; } |
72 |
public bool Enable { get => _Enable; set => _Enable = value; } |
73 |
public bool Validation { get => _Validation; set => _Validation = value; } |
74 |
public bool MappingValidation { get => _MappingValidation; set => _MappingValidation = value; } |
75 |
public string UID { get => _UID; set => _UID = value; } |
76 |
public List<OPC> OPCs { get => _OPCs; set => _OPCs = value; } |
77 |
public List<Text> Texts { get => _Texts; set => _Texts = value; } |
78 |
public List<Note> Notes { get => _Notes; set => _Notes = value; } |
79 |
|
80 |
StringBuilder validationStringBuilder = new StringBuilder(); |
81 |
|
82 |
public List<PlantItem> PlantItems = new List<PlantItem>(); |
83 |
|
84 |
public Document(string xmlPath, DataTable ID2SymbolTypeDT) |
85 |
{ |
86 |
this.ID2SymbolTypeDT = ID2SymbolTypeDT; |
87 |
validationStringBuilder.AppendLine("Document Path : " + xmlPath); |
88 |
validationStringBuilder.AppendLine(""); |
89 |
try |
90 |
{ |
91 |
if (xmlPath != null) |
92 |
{ |
93 |
PATH = xmlPath; |
94 |
XElement xml = XElement.Load(xmlPath); |
95 |
DWGNAME = xml.Element("DWGNAME").Value; |
96 |
SIZE = xml.Element("SIZE").Value; |
97 |
|
98 |
validationStringBuilder.AppendLine("Drawing Name : " + DWGNAME); |
99 |
validationStringBuilder.AppendLine(""); |
100 |
|
101 |
SetText(xml.Element("TEXTINFOS")); |
102 |
SetNote(xml.Element("NOTES")); |
103 |
SetSymbol(xml.Element("SYMBOLS")); |
104 |
SetLine(xml.Element("LINEINFOS")); |
105 |
SetLineNumber(xml.Element("LINENOS")); |
106 |
SetTrimLine(xml.Element("TRIMLINENOS")); |
107 |
|
108 |
SetAllConnectors(); |
109 |
Enable = true; |
110 |
} |
111 |
} |
112 |
catch (Exception ex) |
113 |
{ |
114 |
Enable = false; |
115 |
MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
116 |
} |
117 |
} |
118 |
|
119 |
#region READ XML |
120 |
private void SetSymbol(XElement node) |
121 |
{ |
122 |
foreach (XElement item in node.Elements("SYMBOL")) |
123 |
{ |
124 |
string sType = item.Element("TYPE").Value; |
125 |
|
126 |
DataRow[] rows = ID2SymbolTypeDT.Select(string.Format("Type = '{0}'", sType.Replace("'", "''"))); |
127 |
string sCategory = rows[0]["Category"].ToString(); |
128 |
|
129 |
if (sType == "Segment Breaks") |
130 |
{ |
131 |
SpecBreak specBreak = new SpecBreak() |
132 |
{ |
133 |
UID = item.Element("UID").Value, |
134 |
DBUID = item.Element("DBUID").Value, |
135 |
NAME = item.Element("NAME").Value, |
136 |
TYPE = item.Element("TYPE").Value, |
137 |
OWNER = item.Element("OWNER").Value, |
138 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
139 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
140 |
LOCATION = item.Element("LOCATION").Value, |
141 |
SIZE = item.Element("SIZE").Value, |
142 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
143 |
PARENT = item.Element("PARENT").Value, |
144 |
CHILD = item.Element("CHILD").Value, |
145 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
146 |
AREA = item.Element("AREA").Value, |
147 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
148 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
149 |
}; |
150 |
SetAssociations(item.Element("ASSOCIATIONS"), specBreak.ASSOCIATIONS); |
151 |
SetSymbolConnectors(item.Element("CONNECTORS"), specBreak.CONNECTORS, specBreak.CONNECTIONPOINT); |
152 |
SetProperties(item.Element("PROPERTIES"), specBreak.PROPERTIES); |
153 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), specBreak.ATTRIBUTES); |
154 |
SetSpecBreakAttribute(specBreak); |
155 |
|
156 |
SpecBreaks.Add(specBreak); |
157 |
} |
158 |
else if (sType == "End Break") |
159 |
{ |
160 |
EndBreak endBreak = new EndBreak() |
161 |
{ |
162 |
UID = item.Element("UID").Value, |
163 |
DBUID = item.Element("DBUID").Value, |
164 |
NAME = item.Element("NAME").Value, |
165 |
TYPE = item.Element("TYPE").Value, |
166 |
OWNER = item.Element("OWNER").Value, |
167 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
168 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
169 |
LOCATION = item.Element("LOCATION").Value, |
170 |
SIZE = item.Element("SIZE").Value, |
171 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
172 |
PARENT = item.Element("PARENT").Value, |
173 |
CHILD = item.Element("CHILD").Value, |
174 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
175 |
AREA = item.Element("AREA").Value, |
176 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
177 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
178 |
}; |
179 |
SetAssociations(item.Element("ASSOCIATIONS"), endBreak.ASSOCIATIONS); |
180 |
SetSymbolConnectors(item.Element("CONNECTORS"), endBreak.CONNECTORS, endBreak.CONNECTIONPOINT); |
181 |
SetProperties(item.Element("PROPERTIES"), endBreak.PROPERTIES); |
182 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), endBreak.ATTRIBUTES); |
183 |
|
184 |
EndBreaks.Add(endBreak); |
185 |
} |
186 |
else if (sCategory == "Equipment" || |
187 |
sCategory == "Equipment Components") |
188 |
{ |
189 |
Equipment equipment = new Equipment() |
190 |
{ |
191 |
UID = item.Element("UID").Value, |
192 |
DBUID = item.Element("DBUID").Value, |
193 |
NAME = item.Element("NAME").Value, |
194 |
TYPE = item.Element("TYPE").Value, |
195 |
OWNER = item.Element("OWNER").Value, |
196 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
197 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
198 |
LOCATION = item.Element("LOCATION").Value, |
199 |
SIZE = item.Element("SIZE").Value, |
200 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
201 |
PARENT = item.Element("PARENT").Value, |
202 |
CHILD = item.Element("CHILD").Value, |
203 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
204 |
AREA = item.Element("AREA").Value, |
205 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
206 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
207 |
}; |
208 |
SetAssociations(item.Element("ASSOCIATIONS"), equipment.ASSOCIATIONS); |
209 |
SetSymbolConnectors(item.Element("CONNECTORS"), equipment.CONNECTORS, equipment.CONNECTIONPOINT); |
210 |
SetProperties(item.Element("PROPERTIES"), equipment.PROPERTIES); |
211 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), equipment.ATTRIBUTES); |
212 |
|
213 |
Equipments.Add(equipment); |
214 |
} |
215 |
else if (sType == "Piping OPC's" || sType == "Instrument OPC's") |
216 |
{ |
217 |
OPC opc = new OPC() |
218 |
{ |
219 |
UID = item.Element("UID").Value, |
220 |
DBUID = item.Element("DBUID").Value, |
221 |
NAME = item.Element("NAME").Value, |
222 |
TYPE = item.Element("TYPE").Value, |
223 |
OWNER = item.Element("OWNER").Value, |
224 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
225 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
226 |
LOCATION = item.Element("LOCATION").Value, |
227 |
SIZE = item.Element("SIZE").Value, |
228 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
229 |
PARENT = item.Element("PARENT").Value, |
230 |
CHILD = item.Element("CHILD").Value, |
231 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
232 |
AREA = item.Element("AREA").Value, |
233 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
234 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
235 |
}; |
236 |
|
237 |
SetAssociations(item.Element("ASSOCIATIONS"), opc.ASSOCIATIONS); |
238 |
SetSymbolConnectors(item.Element("CONNECTORS"), opc.CONNECTORS, opc.CONNECTIONPOINT); |
239 |
SetProperties(item.Element("PROPERTIES"), opc.PROPERTIES); |
240 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), opc.ATTRIBUTES); |
241 |
SetChildSymbol(opc); |
242 |
|
243 |
if (sType == "Piping OPC's") |
244 |
opc.OPCType = OPCType.Pipe; |
245 |
else if (sType == "Instrument OPC's") |
246 |
opc.OPCType = OPCType.Signal; |
247 |
|
248 |
OPCs.Add(opc); |
249 |
} |
250 |
else |
251 |
{ |
252 |
Symbol symbol = new Symbol() |
253 |
{ |
254 |
UID = item.Element("UID").Value, |
255 |
DBUID = item.Element("DBUID").Value, |
256 |
NAME = item.Element("NAME").Value, |
257 |
TYPE = item.Element("TYPE").Value, |
258 |
OWNER = item.Element("OWNER").Value, |
259 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
260 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
261 |
LOCATION = item.Element("LOCATION").Value, |
262 |
SIZE = item.Element("SIZE").Value, |
263 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
264 |
PARENT = item.Element("PARENT").Value, |
265 |
CHILD = item.Element("CHILD").Value, |
266 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
267 |
AREA = item.Element("AREA").Value, |
268 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
269 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
270 |
}; |
271 |
|
272 |
SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS); |
273 |
SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT); |
274 |
SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES); |
275 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES); |
276 |
SetChildSymbol(symbol); |
277 |
|
278 |
SYMBOLS.Add(symbol); |
279 |
} |
280 |
} |
281 |
|
282 |
PlantItems.AddRange(SpecBreaks); |
283 |
PlantItems.AddRange(EndBreaks); |
284 |
PlantItems.AddRange(Equipments); |
285 |
PlantItems.AddRange(SYMBOLS); |
286 |
PlantItems.AddRange(OPCs); |
287 |
} |
288 |
|
289 |
private void SetLine(XElement node) |
290 |
{ |
291 |
foreach (XElement item in node.Elements("LINE")) |
292 |
{ |
293 |
Line line = new Line() |
294 |
{ |
295 |
OWNER = item.Attribute("OWNER").Value, |
296 |
UID = item.Element("UID").Value, |
297 |
STARTPOINT = item.Element("STARTPOINT").Value, |
298 |
ENDPOINT = item.Element("ENDPOINT").Value, |
299 |
TYPE = item.Element("TYPE").Value, |
300 |
TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value, |
301 |
AREA = item.Element("AREA").Value, |
302 |
THICKNESS = item.Element("THICKNESS").Value, |
303 |
}; |
304 |
int flowMarkPercent = 0; |
305 |
if (int.TryParse(item.Element("FLOWMARK").Value, out flowMarkPercent)) |
306 |
{ |
307 |
line.FLOWMARK = true; |
308 |
line.FLOWMARK_PERCENT = flowMarkPercent; |
309 |
} |
310 |
else |
311 |
line.FLOWMARK = false; |
312 |
|
313 |
SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS); |
314 |
SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS); |
315 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES); |
316 |
line.SetSlopeType(); |
317 |
LINES.Add(line); |
318 |
} |
319 |
PlantItems.AddRange(LINES); |
320 |
} |
321 |
|
322 |
private void SetLineNumber(XElement node) |
323 |
{ |
324 |
foreach (XElement item in node.Elements("LINE_NO")) |
325 |
{ |
326 |
LineNumber lineNumber = new LineNumber() |
327 |
{ |
328 |
UID = item.Element("UID").Value, |
329 |
TEXT = item.Element("TEXT").Value, |
330 |
LOCATION = item.Element("LOCATION").Value, |
331 |
WIDTH = item.Element("WIDTH").Value, |
332 |
HEIGHT = item.Element("HEIGHT").Value, |
333 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
334 |
AREA = item.Element("AREA").Value, |
335 |
SCENE = item.Element("SCENE").Value |
336 |
}; |
337 |
if (item.Element("CONNLINE") != null) |
338 |
lineNumber.CONNLINE = item.Element("CONNLINE").Value; |
339 |
else |
340 |
{ |
341 |
validationStringBuilder.AppendLine("Not exist CONNLINE!" + "\r\nLineNumber UID : " + lineNumber.UID); |
342 |
validationStringBuilder.AppendLine(); |
343 |
validationResult = true; |
344 |
} |
345 |
|
346 |
SetLineNumberRuns(item, lineNumber.RUNS); |
347 |
SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES); |
348 |
SetAttributes(item, lineNumber.ATTRIBUTES); |
349 |
LINENUMBERS.Add(lineNumber); |
350 |
} |
351 |
PlantItems.AddRange(LINENUMBERS); |
352 |
} |
353 |
|
354 |
private void SetTrimLine(XElement node) |
355 |
{ |
356 |
foreach (XElement item in node.Elements("TRIM_LINE_NO")) |
357 |
{ |
358 |
TrimLine trimLine = new TrimLine() |
359 |
{ |
360 |
UID = item.Element("UID").Value, |
361 |
}; |
362 |
SetLineNumberRuns(item, trimLine.RUNS); |
363 |
TRIMLINES.Add(trimLine); |
364 |
} |
365 |
PlantItems.AddRange(TRIMLINES); |
366 |
} |
367 |
|
368 |
private void SetAssociations(XElement node, List<Association> associations) |
369 |
{ |
370 |
foreach (XElement item in node.Elements("ASSOCIATION")) |
371 |
{ |
372 |
Association association = new Association() |
373 |
{ |
374 |
TYPE = item.Attribute("TYPE").Value, |
375 |
VALUE = item.Value |
376 |
}; |
377 |
|
378 |
associations.Add(association); |
379 |
} |
380 |
} |
381 |
|
382 |
private void SetConnectors(XElement node, List<Connector> connectors) |
383 |
{ |
384 |
foreach (XElement item in node.Elements("CONNECTOR")) |
385 |
{ |
386 |
connectors.Add(new Connector() |
387 |
{ |
388 |
UID = item.Attribute("UID").Value, |
389 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
390 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
391 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
392 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
393 |
}); |
394 |
} |
395 |
} |
396 |
|
397 |
private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT) |
398 |
{ |
399 |
foreach (XElement item in node.Elements("CONNECTOR")) |
400 |
{ |
401 |
connectors.Add(new Connector() |
402 |
{ |
403 |
UID = item.Attribute("UID").Value, |
404 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
405 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
406 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
407 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
408 |
}); |
409 |
} |
410 |
} |
411 |
|
412 |
private void SetProperties(XElement node, List<Property> properties) |
413 |
{ |
414 |
foreach (XElement item in node.Elements("PROPERTY")) |
415 |
{ |
416 |
properties.Add(new Property() |
417 |
{ |
418 |
UID = item.Attribute("UID").Value, |
419 |
LENGTH = item.Attribute("Length").Value, |
420 |
EXPRESSION = item.Attribute("Expression").Value, |
421 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
422 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
423 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
424 |
VALUE = item.Value |
425 |
}); |
426 |
} |
427 |
} |
428 |
|
429 |
private void SetAttributes(XElement node, List<Attribute> attributes) |
430 |
{ |
431 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
432 |
{ |
433 |
Attribute attribute = new Attribute() |
434 |
{ |
435 |
UID = item.Attribute("UID").Value, |
436 |
LENGTH = item.Attribute("Length").Value, |
437 |
EXPRESSION = item.Attribute("Expression").Value, |
438 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
439 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
440 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
441 |
ATTRAT = item.Attribute("AttrAt").Value, |
442 |
ASSOCITEM = item.Attribute("AssocItem").Value, |
443 |
VALUE = item.Value |
444 |
}; |
445 |
|
446 |
attributes.Add(attribute); |
447 |
|
448 |
if (!string.IsNullOrEmpty(attribute.ASSOCITEM) && attribute.ASSOCITEM != "None") |
449 |
{ |
450 |
Text text = Texts.Find(x => x.UID == attribute.ASSOCITEM); |
451 |
if (text != null) |
452 |
text.ASSOCIATION = true; |
453 |
} |
454 |
} |
455 |
} |
456 |
|
457 |
private void SetSpecBreakAttribute(SpecBreak specBreak) |
458 |
{ |
459 |
string upStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "UpStream").VALUE; |
460 |
string downStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "DownStream").VALUE; |
461 |
|
462 |
specBreak.UpStreamUID = upStream; |
463 |
specBreak.DownStreamUID = downStream; |
464 |
} |
465 |
|
466 |
private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns) |
467 |
{ |
468 |
foreach (XElement item in node.Elements("RUN")) |
469 |
{ |
470 |
LineRun run = new LineRun() |
471 |
{ |
472 |
TYPE = item.Attribute("TYPE").Value |
473 |
}; |
474 |
|
475 |
foreach (XElement element in item.Elements()) |
476 |
{ |
477 |
if (element.Name == "SYMBOL") |
478 |
{ |
479 |
Symbol symbol = GetSymbolByUID(element.Element("UID").Value); |
480 |
Equipment equipment = GetEquipmentByUID(element.Element("UID").Value); |
481 |
if (symbol == null && equipment == null) |
482 |
{ |
483 |
validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value); |
484 |
validationStringBuilder.AppendLine(); |
485 |
validationResult = true; |
486 |
} |
487 |
if (symbol != null) |
488 |
run.RUNITEMS.Add(symbol); |
489 |
else if (equipment != null) |
490 |
run.RUNITEMS.Add(equipment); |
491 |
} |
492 |
else if (element.Name == "LINE") |
493 |
{ |
494 |
Line line = GetLineByUID(element.Element("UID").Value); |
495 |
if (line == null) |
496 |
{ |
497 |
validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value); |
498 |
validationStringBuilder.AppendLine(); |
499 |
validationResult = true; |
500 |
} |
501 |
run.RUNITEMS.Add(line); |
502 |
} |
503 |
} |
504 |
lineNumberRuns.Add(run); |
505 |
} |
506 |
} |
507 |
|
508 |
private void SetChildSymbol(Symbol symbol) |
509 |
{ |
510 |
List<ChildSymbol> childList = new List<ChildSymbol>(); |
511 |
if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None") |
512 |
{ |
513 |
string[] childArray = symbol.CHILD.Split(new char[] { '/' }); |
514 |
foreach (string sChild in childArray) |
515 |
{ |
516 |
string[] sChildInfo = sChild.Split(new char[] { ',' }); |
517 |
childList.Add(new ChildSymbol() |
518 |
{ |
519 |
ParentAt = Convert.ToInt32(sChildInfo[0]), |
520 |
Direction = sChildInfo[1], |
521 |
NAME = sChildInfo[2] |
522 |
}); |
523 |
} |
524 |
|
525 |
foreach (ChildSymbol child in childList) |
526 |
{ |
527 |
if (child.ParentAt == 0) |
528 |
symbol.ChildSymbols.Add(child); |
529 |
else |
530 |
childList[child.ParentAt - 1].ChildSymbols.Add(child); |
531 |
} |
532 |
} |
533 |
if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None") |
534 |
{ |
535 |
// 현재 부모 Symbol에 자식 Connector까지 들어가 있음 |
536 |
string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' }); |
537 |
string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' }); |
538 |
for (int i = 0; i < array.Length; i++) |
539 |
{ |
540 |
string[] arrConn = array[i].Split(new char[] { ',' }); |
541 |
int connIndex = Convert.ToInt32(arrConn[3]); |
542 |
if (connIndex != 0) |
543 |
{ |
544 |
childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]); |
545 |
symbol.CONNECTORS[i].Index = connIndex; |
546 |
} |
547 |
} |
548 |
} |
549 |
} |
550 |
|
551 |
private void SetText(XElement node) |
552 |
{ |
553 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
554 |
{ |
555 |
Text text = new Text() |
556 |
{ |
557 |
UID = item.Element("UID").Value, |
558 |
OWNER = item.Element("OWNER").Value, |
559 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
560 |
NAME = item.Element("NAME").Value, |
561 |
LOCATION = item.Element("LOCATION").Value, |
562 |
VALUE = item.Element("VALUE").Value, |
563 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
564 |
WIDTH = item.Element("WIDTH").Value, |
565 |
HEIGHT = item.Element("HEIGHT").Value, |
566 |
AREA = item.Element("AREA").Value, |
567 |
SCENE = item.Element("SCENE").Value |
568 |
}; |
569 |
|
570 |
Texts.Add(text); |
571 |
} |
572 |
} |
573 |
|
574 |
private void SetNote(XElement node) |
575 |
{ |
576 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
577 |
{ |
578 |
Note note = new Note() |
579 |
{ |
580 |
UID = item.Element("UID").Value, |
581 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
582 |
NAME = item.Element("NAME").Value, |
583 |
LOCATION = item.Element("LOCATION").Value, |
584 |
VALUE = item.Element("VALUE").Value, |
585 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
586 |
WIDTH = item.Element("WIDTH").Value, |
587 |
HEIGHT = item.Element("HEIGHT").Value, |
588 |
AREA = item.Element("AREA").Value, |
589 |
SCENE = item.Element("SCENE").Value, |
590 |
OWNER = item.Element("OWNER").Value |
591 |
}; |
592 |
|
593 |
Notes.Add(note); |
594 |
} |
595 |
} |
596 |
#endregion |
597 |
|
598 |
public void SetAllConnectors() |
599 |
{ |
600 |
foreach (var item in SYMBOLS) |
601 |
foreach (var connector in item.CONNECTORS) |
602 |
connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM); |
603 |
|
604 |
foreach (var item in OPCs) |
605 |
foreach (var connector in item.CONNECTORS) |
606 |
connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM); |
607 |
|
608 |
foreach (var item in LINES) |
609 |
foreach (var connector in item.CONNECTORS) |
610 |
connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM); |
611 |
|
612 |
foreach (var item in Equipments) |
613 |
foreach (var connector in item.CONNECTORS) |
614 |
connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM); |
615 |
} |
616 |
|
617 |
public Symbol GetSymbolByUID(string uid) |
618 |
{ |
619 |
return SYMBOLS.Find(x => x.UID == uid); |
620 |
} |
621 |
|
622 |
public Equipment GetEquipmentByUID(string uid) |
623 |
{ |
624 |
return Equipments.Find(x => x.UID == uid); |
625 |
} |
626 |
|
627 |
public Line GetLineByUID(string uid) |
628 |
{ |
629 |
return LINES.Find(x => x.UID == uid); |
630 |
} |
631 |
|
632 |
#region For Aveva |
633 |
|
634 |
public bool SetAvevaInfo(DataTable symbolMappingTable, DataTable lineMappingTable, DataTable opcMappingTable) |
635 |
{ |
636 |
bool result = true; |
637 |
foreach (var item in LINES) |
638 |
{ |
639 |
DataRow[] rows = lineMappingTable.Select(string.Format("UID = '{0}'", item.TYPEUID)); |
640 |
if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["APID_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["APID_SYMBOL"])) |
641 |
{ |
642 |
item.Aveva = new AvevaLineInfo(); |
643 |
item.Aveva.Name = (string)rows[0]["APID_SYMBOL"]; |
644 |
double startX = item.Start_X; |
645 |
double startY = SIZE_HEIGHT - item.Start_Y; |
646 |
double endX = item.End_X; |
647 |
double endY = SIZE_HEIGHT - item.End_Y; |
648 |
|
649 |
ConvertAvevaPoint(ref startX, ref startY); |
650 |
ConvertAvevaPoint(ref endX, ref endY); |
651 |
|
652 |
item.Aveva.Start_X = startX; |
653 |
item.Aveva.Start_Y = startY; |
654 |
item.Aveva.End_X = endX; |
655 |
item.Aveva.End_Y = endY; |
656 |
|
657 |
if (item.SlopeType == SlopeType.HORIZONTAL) |
658 |
item.Aveva.End_Y = item.Aveva.Start_Y; |
659 |
else if (item.SlopeType == SlopeType.VERTICAL) |
660 |
item.Aveva.End_X = item.Aveva.Start_X; |
661 |
|
662 |
if (!DBNull.Value.Equals(rows[0]["DATA1"])) |
663 |
{ |
664 |
if (rows[0]["DATA1"].ToString() == "PIPE") |
665 |
item.Aveva.Type = Type.Pipe; |
666 |
else if (rows[0]["DATA1"].ToString() == "SIGNAL") |
667 |
item.Aveva.Type = Type.Signal; |
668 |
} |
669 |
} |
670 |
else |
671 |
result = false; |
672 |
} |
673 |
foreach (var item in SYMBOLS) |
674 |
{ |
675 |
DataRow[] rows = symbolMappingTable.Select(string.Format("UID = '{0}'", item.DBUID)); |
676 |
if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["APID_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["APID_SYMBOL"])) |
677 |
{ |
678 |
item.Aveva = new AvevaSymbolInfo(); |
679 |
double x = item.X; |
680 |
double y = SIZE_HEIGHT - item.Y; |
681 |
|
682 |
ConvertAvevaPoint(ref x, ref y); |
683 |
|
684 |
item.Aveva.X = x; |
685 |
item.Aveva.Y = y; |
686 |
|
687 |
item.Aveva.FullName = (string)rows[0]["APID_SYMBOL"]; |
688 |
string[] split = item.Aveva.FullName.Split(new char[] { '\\' }); |
689 |
item.Aveva.Name = split[split.Length - 1]; |
690 |
} |
691 |
else |
692 |
result = false; |
693 |
} |
694 |
foreach (var item in OPCs) |
695 |
{ |
696 |
DataRow[] rows = opcMappingTable.Select(string.Format("UID = '{0}'", item.DBUID)); |
697 |
if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["IN_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["OUT_SYMBOL"])) |
698 |
{ |
699 |
item.Aveva = new AvevaSymbolInfo(); |
700 |
double x = item.X; |
701 |
double y = SIZE_HEIGHT - item.Y; |
702 |
|
703 |
ConvertAvevaPoint(ref x, ref y); |
704 |
|
705 |
item.Aveva.X = x; |
706 |
item.Aveva.Y = y; |
707 |
|
708 |
if (item.TYPE == "Piping OPC's") |
709 |
item.OPCType = OPCType.Pipe; |
710 |
else if (item.TYPE == "Instrument OPC's") |
711 |
item.OPCType = OPCType.Signal; |
712 |
|
713 |
Connector connector = item.CONNECTORS.Find(loop => |
714 |
APIDUtils.FindObjectByUID(this, loop.CONNECTEDITEM) != null && |
715 |
APIDUtils.FindObjectByUID(this, loop.CONNECTEDITEM).GetType() == typeof(Line)); |
716 |
if (connector != null) |
717 |
{ |
718 |
// out |
719 |
if (item.CONNECTORS.IndexOf(connector) == 0) |
720 |
{ |
721 |
item.Aveva.FullName = (string)rows[0]["OUT_SYMBOL"]; |
722 |
string[] split = item.Aveva.FullName.Split(new char[] { '\\' }); |
723 |
item.Aveva.Name = split[split.Length - 1]; |
724 |
item.FlowType = FlowType.Out; |
725 |
} |
726 |
// in |
727 |
else |
728 |
{ |
729 |
item.Aveva.FullName = (string)rows[0]["IN_SYMBOL"]; |
730 |
string[] split = item.Aveva.FullName.Split(new char[] { '\\' }); |
731 |
item.Aveva.Name = split[split.Length - 1]; |
732 |
item.FlowType = FlowType.In; |
733 |
} |
734 |
} |
735 |
else |
736 |
result = false; |
737 |
} |
738 |
else |
739 |
result = false; |
740 |
} |
741 |
foreach (var item in LINENUMBERS) |
742 |
{ |
743 |
item.Aveva = new AvevaLabelInfo(); |
744 |
double x = (item.X1 + item.X2) / 2; |
745 |
double y = SIZE_HEIGHT - (item.Y1 + item.Y2) / 2; |
746 |
|
747 |
ConvertAvevaPoint(ref x, ref y); |
748 |
|
749 |
item.Aveva.X = x; |
750 |
item.Aveva.Y = y; |
751 |
item.Aveva.LabelType = LabelType.LineNumber; |
752 |
item.Aveva.Angle = RadianToDegree(item.ANGLE); |
753 |
} |
754 |
|
755 |
foreach (var item in Texts) |
756 |
{ |
757 |
item.Aveva = new AvevaLabelInfo(); |
758 |
|
759 |
double x = item.X1; |
760 |
double y = SIZE_HEIGHT - item.Y2; |
761 |
ConvertAvevaPoint(ref x, ref y); |
762 |
item.Aveva.X = x; |
763 |
item.Aveva.Y = y; |
764 |
|
765 |
if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180) |
766 |
{ |
767 |
double height = Math.Abs(item.Y1 - item.Y2); |
768 |
ConvertAvevaPointY(ref height); |
769 |
item.Aveva.Height = height; |
770 |
} |
771 |
else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270) |
772 |
{ |
773 |
double height = Math.Abs(item.X1 - item.X2); |
774 |
ConvertAvevaPointX(ref height); |
775 |
item.Aveva.Height = height; |
776 |
} |
777 |
|
778 |
if (item.VALUE.Contains("\n")) |
779 |
{ |
780 |
item.Aveva.LabelType = LabelType.MultiText; |
781 |
int count = item.VALUE.Length - item.VALUE.Replace("\n", "").Length + 1; |
782 |
item.Aveva.Height = item.Aveva.Height / count; |
783 |
} |
784 |
else |
785 |
item.Aveva.LabelType = LabelType.SingleText; |
786 |
|
787 |
item.Aveva.Angle = item.ANGLE; |
788 |
} |
789 |
foreach (var item in Notes) |
790 |
{ |
791 |
item.Aveva = new AvevaLabelInfo(); |
792 |
|
793 |
double x = item.X1; |
794 |
double y = SIZE_HEIGHT - item.Y2; |
795 |
ConvertAvevaPoint(ref x, ref y); |
796 |
item.Aveva.X = x; |
797 |
item.Aveva.Y = y; |
798 |
|
799 |
if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180) |
800 |
{ |
801 |
double height = Math.Abs(item.Y1 - item.Y2); |
802 |
ConvertAvevaPointY(ref height); |
803 |
item.Aveva.Height = height; |
804 |
} |
805 |
else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270) |
806 |
{ |
807 |
double height = Math.Abs(item.X1 - item.X2); |
808 |
ConvertAvevaPointX(ref height); |
809 |
item.Aveva.Height = height; |
810 |
} |
811 |
|
812 |
if (item.VALUE.Contains(@"\n")) |
813 |
{ |
814 |
item.Aveva.LabelType = LabelType.MultiNote; |
815 |
int count = item.VALUE.Length - item.VALUE.Replace("\n", "").Length + 1; |
816 |
item.Aveva.Height = item.Aveva.Height / count; |
817 |
} |
818 |
else |
819 |
item.Aveva.LabelType = LabelType.SingleNote; |
820 |
|
821 |
item.Aveva.Angle = item.ANGLE; |
822 |
} |
823 |
|
824 |
return result; |
825 |
} |
826 |
|
827 |
public void ConvertAvevaPoint(ref double x, ref double y) |
828 |
{ |
829 |
decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX); |
830 |
decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY); |
831 |
decimal id2Width = Convert.ToDecimal(SIZE_WIDTH); |
832 |
decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT); |
833 |
|
834 |
x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x)); |
835 |
y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y)); |
836 |
} |
837 |
public void ConvertAvevaPointX(ref double x) |
838 |
{ |
839 |
decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX); |
840 |
decimal id2Width = Convert.ToDecimal(SIZE_WIDTH); |
841 |
|
842 |
x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x)); |
843 |
} |
844 |
public void ConvertAvevaPointY(ref double y) |
845 |
{ |
846 |
decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY); |
847 |
decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT); |
848 |
|
849 |
y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y)); |
850 |
} |
851 |
|
852 |
private double RadianToDegree(double angle) |
853 |
{ |
854 |
return angle * (180.0 / Math.PI); |
855 |
} |
856 |
|
857 |
#endregion |
858 |
} |
859 |
} |