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