hytos / DTI_PID / APIDConverter / Model / PlantItem / Document.cs @ 1d561973
이력 | 보기 | 이력해설 | 다운로드 (39.9 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 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(string.IsNullOrWhiteSpace(item.Element("CURRENTPOINTMODEINDEX").Value) ? "0" : item.Element("CURRENTPOINTMODEINDEX").Value) |
150 |
}; |
151 |
SetAssociations(item.Element("ASSOCIATIONS"), specBreak.ASSOCIATIONS); |
152 |
SetSymbolConnectors(item.Element("CONNECTORS"), specBreak.CONNECTORS, specBreak.CONNECTIONPOINT); |
153 |
SetProperties(item.Element("PROPERTIES"), specBreak.PROPERTIES); |
154 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), specBreak.ATTRIBUTES); |
155 |
SetSpecBreakAttribute(specBreak); |
156 |
|
157 |
SpecBreaks.Add(specBreak); |
158 |
} |
159 |
else if (sType == "End Break") |
160 |
{ |
161 |
EndBreak endBreak = new EndBreak() |
162 |
{ |
163 |
UID = item.Element("UID").Value, |
164 |
DBUID = item.Element("DBUID").Value, |
165 |
NAME = item.Element("NAME").Value, |
166 |
TYPE = item.Element("TYPE").Value, |
167 |
OWNER = item.Element("OWNER").Value, |
168 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
169 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
170 |
LOCATION = item.Element("LOCATION").Value, |
171 |
SIZE = item.Element("SIZE").Value, |
172 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
173 |
PARENT = item.Element("PARENT").Value, |
174 |
CHILD = item.Element("CHILD").Value, |
175 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
176 |
AREA = item.Element("AREA").Value, |
177 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
178 |
//CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
179 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(string.IsNullOrWhiteSpace(item.Element("CURRENTPOINTMODEINDEX").Value) ? "0" : item.Element("CURRENTPOINTMODEINDEX").Value) |
180 |
}; |
181 |
SetAssociations(item.Element("ASSOCIATIONS"), endBreak.ASSOCIATIONS); |
182 |
SetSymbolConnectors(item.Element("CONNECTORS"), endBreak.CONNECTORS, endBreak.CONNECTIONPOINT); |
183 |
SetProperties(item.Element("PROPERTIES"), endBreak.PROPERTIES); |
184 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), endBreak.ATTRIBUTES); |
185 |
|
186 |
EndBreaks.Add(endBreak); |
187 |
} |
188 |
else if (sCategory == "Equipment" || |
189 |
sCategory == "Equipment Components") |
190 |
{ |
191 |
Equipment equipment = new Equipment() |
192 |
{ |
193 |
UID = item.Element("UID").Value, |
194 |
DBUID = item.Element("DBUID").Value, |
195 |
NAME = item.Element("NAME").Value, |
196 |
TYPE = item.Element("TYPE").Value, |
197 |
OWNER = item.Element("OWNER").Value, |
198 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
199 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
200 |
LOCATION = item.Element("LOCATION").Value, |
201 |
SIZE = item.Element("SIZE").Value, |
202 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
203 |
PARENT = item.Element("PARENT").Value, |
204 |
CHILD = item.Element("CHILD").Value, |
205 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
206 |
AREA = item.Element("AREA").Value, |
207 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
208 |
//CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
209 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(string.IsNullOrWhiteSpace(item.Element("CURRENTPOINTMODEINDEX").Value) ? "0" : item.Element("CURRENTPOINTMODEINDEX").Value) |
210 |
}; |
211 |
SetAssociations(item.Element("ASSOCIATIONS"), equipment.ASSOCIATIONS); |
212 |
SetSymbolConnectors(item.Element("CONNECTORS"), equipment.CONNECTORS, equipment.CONNECTIONPOINT); |
213 |
SetProperties(item.Element("PROPERTIES"), equipment.PROPERTIES); |
214 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), equipment.ATTRIBUTES); |
215 |
|
216 |
Equipments.Add(equipment); |
217 |
} |
218 |
else if (sType == "Piping OPC's" || sType == "Instrument OPC's") |
219 |
{ |
220 |
OPC opc = new OPC() |
221 |
{ |
222 |
UID = item.Element("UID").Value, |
223 |
DBUID = item.Element("DBUID").Value, |
224 |
NAME = item.Element("NAME").Value, |
225 |
TYPE = item.Element("TYPE").Value, |
226 |
OWNER = item.Element("OWNER").Value, |
227 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
228 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
229 |
LOCATION = item.Element("LOCATION").Value, |
230 |
SIZE = item.Element("SIZE").Value, |
231 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
232 |
PARENT = item.Element("PARENT").Value, |
233 |
CHILD = item.Element("CHILD").Value, |
234 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
235 |
AREA = item.Element("AREA").Value, |
236 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
237 |
//CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
238 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(string.IsNullOrWhiteSpace(item.Element("CURRENTPOINTMODEINDEX").Value) ? "0" : item.Element("CURRENTPOINTMODEINDEX").Value) |
239 |
}; |
240 |
|
241 |
SetAssociations(item.Element("ASSOCIATIONS"), opc.ASSOCIATIONS); |
242 |
SetSymbolConnectors(item.Element("CONNECTORS"), opc.CONNECTORS, opc.CONNECTIONPOINT); |
243 |
SetProperties(item.Element("PROPERTIES"), opc.PROPERTIES); |
244 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), opc.ATTRIBUTES); |
245 |
SetChildSymbol(opc); |
246 |
|
247 |
if (sType == "Piping OPC's") |
248 |
opc.OPCType = OPCType.Pipe; |
249 |
else if (sType == "Instrument OPC's") |
250 |
opc.OPCType = OPCType.Signal; |
251 |
|
252 |
OPCs.Add(opc); |
253 |
} |
254 |
else |
255 |
{ |
256 |
Symbol symbol = new Symbol() |
257 |
{ |
258 |
UID = item.Element("UID").Value, |
259 |
DBUID = item.Element("DBUID").Value, |
260 |
NAME = item.Element("NAME").Value, |
261 |
TYPE = item.Element("TYPE").Value, |
262 |
OWNER = item.Element("OWNER").Value, |
263 |
ORIGINALPOINT = item.Element("ORIGINALPOINT").Value, |
264 |
CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value, |
265 |
LOCATION = item.Element("LOCATION").Value, |
266 |
SIZE = item.Element("SIZE").Value, |
267 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
268 |
PARENT = item.Element("PARENT").Value, |
269 |
CHILD = item.Element("CHILD").Value, |
270 |
HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value, |
271 |
AREA = item.Element("AREA").Value, |
272 |
FLIP = Convert.ToInt32(item.Element("FLIP").Value), |
273 |
//CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value) |
274 |
CURRENTPOINTMODEINDEX = Convert.ToInt32(string.IsNullOrWhiteSpace(item.Element("CURRENTPOINTMODEINDEX").Value) ? "0" : item.Element("CURRENTPOINTMODEINDEX").Value) |
275 |
}; |
276 |
|
277 |
SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS); |
278 |
SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT); |
279 |
SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES); |
280 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES); |
281 |
SetChildSymbol(symbol); |
282 |
|
283 |
SYMBOLS.Add(symbol); |
284 |
} |
285 |
} |
286 |
|
287 |
PlantItems.AddRange(SpecBreaks); |
288 |
PlantItems.AddRange(EndBreaks); |
289 |
PlantItems.AddRange(Equipments); |
290 |
PlantItems.AddRange(SYMBOLS); |
291 |
PlantItems.AddRange(OPCs); |
292 |
} |
293 |
|
294 |
private void SetLine(XElement node) |
295 |
{ |
296 |
foreach (XElement item in node.Elements("LINE")) |
297 |
{ |
298 |
Line line = new Line() |
299 |
{ |
300 |
OWNER = item.Attribute("OWNER").Value, |
301 |
UID = item.Element("UID").Value, |
302 |
STARTPOINT = item.Element("STARTPOINT").Value, |
303 |
ENDPOINT = item.Element("ENDPOINT").Value, |
304 |
TYPE = item.Element("TYPE").Value, |
305 |
TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value, |
306 |
AREA = item.Element("AREA").Value, |
307 |
THICKNESS = item.Element("THICKNESS").Value, |
308 |
}; |
309 |
int flowMarkPercent = 0; |
310 |
if (int.TryParse(item.Element("FLOWMARK").Value, out flowMarkPercent)) |
311 |
{ |
312 |
line.FLOWMARK = true; |
313 |
line.FLOWMARK_PERCENT = flowMarkPercent; |
314 |
} |
315 |
else |
316 |
line.FLOWMARK = false; |
317 |
|
318 |
SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS); |
319 |
SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS); |
320 |
SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES); |
321 |
line.SetSlopeType(); |
322 |
LINES.Add(line); |
323 |
} |
324 |
PlantItems.AddRange(LINES); |
325 |
} |
326 |
|
327 |
private void SetLineNumber(XElement node) |
328 |
{ |
329 |
foreach (XElement item in node.Elements("LINE_NO")) |
330 |
{ |
331 |
LineNumber lineNumber = new LineNumber() |
332 |
{ |
333 |
UID = item.Element("UID").Value, |
334 |
TEXT = item.Element("TEXT").Value, |
335 |
LOCATION = item.Element("LOCATION").Value, |
336 |
WIDTH = item.Element("WIDTH").Value, |
337 |
HEIGHT = item.Element("HEIGHT").Value, |
338 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
339 |
AREA = item.Element("AREA").Value, |
340 |
SCENE = item.Element("SCENE").Value |
341 |
}; |
342 |
if (item.Element("CONNLINE") != null) |
343 |
lineNumber.CONNLINE = item.Element("CONNLINE").Value; |
344 |
else |
345 |
{ |
346 |
validationStringBuilder.AppendLine("Not exist CONNLINE!" + "\r\nLineNumber UID : " + lineNumber.UID); |
347 |
validationStringBuilder.AppendLine(); |
348 |
validationResult = true; |
349 |
} |
350 |
|
351 |
SetLineNumberRuns(item, lineNumber.RUNS); |
352 |
SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES); |
353 |
SetAttributes(item, lineNumber.ATTRIBUTES); |
354 |
LINENUMBERS.Add(lineNumber); |
355 |
} |
356 |
PlantItems.AddRange(LINENUMBERS); |
357 |
} |
358 |
|
359 |
private void SetTrimLine(XElement node) |
360 |
{ |
361 |
foreach (XElement item in node.Elements("TRIM_LINE_NO")) |
362 |
{ |
363 |
TrimLine trimLine = new TrimLine() |
364 |
{ |
365 |
UID = item.Element("UID").Value, |
366 |
}; |
367 |
SetLineNumberRuns(item, trimLine.RUNS); |
368 |
TRIMLINES.Add(trimLine); |
369 |
} |
370 |
PlantItems.AddRange(TRIMLINES); |
371 |
} |
372 |
|
373 |
private void SetAssociations(XElement node, List<Association> associations) |
374 |
{ |
375 |
foreach (XElement item in node.Elements("ASSOCIATION")) |
376 |
{ |
377 |
Association association = new Association() |
378 |
{ |
379 |
TYPE = item.Attribute("TYPE").Value, |
380 |
VALUE = item.Value |
381 |
}; |
382 |
|
383 |
associations.Add(association); |
384 |
} |
385 |
} |
386 |
|
387 |
private void SetConnectors(XElement node, List<Connector> connectors) |
388 |
{ |
389 |
foreach (XElement item in node.Elements("CONNECTOR")) |
390 |
{ |
391 |
connectors.Add(new Connector() |
392 |
{ |
393 |
UID = item.Attribute("UID").Value, |
394 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
395 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
396 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
397 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
398 |
}); |
399 |
} |
400 |
} |
401 |
|
402 |
private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT) |
403 |
{ |
404 |
foreach (XElement item in node.Elements("CONNECTOR")) |
405 |
{ |
406 |
connectors.Add(new Connector() |
407 |
{ |
408 |
UID = item.Attribute("UID").Value, |
409 |
CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value), |
410 |
CONNECTEDITEM = item.Element("CONNECTEDITEM").Value, |
411 |
CONNECTPOINT = item.Element("CONNECTPOINT").Value, |
412 |
SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value, |
413 |
}); |
414 |
} |
415 |
} |
416 |
|
417 |
private void SetProperties(XElement node, List<Property> properties) |
418 |
{ |
419 |
foreach (XElement item in node.Elements("PROPERTY")) |
420 |
{ |
421 |
properties.Add(new Property() |
422 |
{ |
423 |
UID = item.Attribute("UID").Value, |
424 |
LENGTH = item.Attribute("Length").Value, |
425 |
EXPRESSION = item.Attribute("Expression").Value, |
426 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
427 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
428 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
429 |
VALUE = item.Value |
430 |
}); |
431 |
} |
432 |
} |
433 |
|
434 |
private void SetAttributes(XElement node, List<Attribute> attributes) |
435 |
{ |
436 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
437 |
{ |
438 |
Attribute attribute = new Attribute() |
439 |
{ |
440 |
UID = item.Attribute("UID").Value, |
441 |
LENGTH = item.Attribute("Length").Value, |
442 |
EXPRESSION = item.Attribute("Expression").Value, |
443 |
DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value, |
444 |
ATTRIBUTETYPE = item.Attribute("AttributeType").Value, |
445 |
ATTRIBUTE = item.Attribute("Attribute").Value, |
446 |
ATTRAT = item.Attribute("AttrAt").Value, |
447 |
ASSOCITEM = item.Attribute("AssocItem").Value, |
448 |
VALUE = item.Value |
449 |
}; |
450 |
|
451 |
attributes.Add(attribute); |
452 |
|
453 |
if (!string.IsNullOrEmpty(attribute.ASSOCITEM) && attribute.ASSOCITEM != "None") |
454 |
{ |
455 |
Text text = Texts.Find(x => x.UID == attribute.ASSOCITEM); |
456 |
if (text != null) |
457 |
text.ASSOCIATION = true; |
458 |
} |
459 |
} |
460 |
} |
461 |
|
462 |
private void SetSpecBreakAttribute(SpecBreak specBreak) |
463 |
{ |
464 |
string upStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "UpStream").VALUE; |
465 |
string downStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "DownStream").VALUE; |
466 |
|
467 |
specBreak.UpStreamUID = upStream; |
468 |
specBreak.DownStreamUID = downStream; |
469 |
} |
470 |
|
471 |
private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns) |
472 |
{ |
473 |
foreach (XElement item in node.Elements("RUN")) |
474 |
{ |
475 |
LineRun run = new LineRun() |
476 |
{ |
477 |
TYPE = item.Attribute("TYPE").Value |
478 |
}; |
479 |
|
480 |
foreach (XElement element in item.Elements()) |
481 |
{ |
482 |
if (element.Name == "SYMBOL") |
483 |
{ |
484 |
Symbol symbol = GetSymbolByUID(element.Element("UID").Value); |
485 |
Equipment equipment = GetEquipmentByUID(element.Element("UID").Value); |
486 |
OPC opc = GetOPCByUID(element.Element("UID").Value); |
487 |
if (symbol == null && equipment == null && opc == null) |
488 |
{ |
489 |
validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value); |
490 |
validationStringBuilder.AppendLine(); |
491 |
validationResult = true; |
492 |
} |
493 |
if (symbol != null) |
494 |
run.RUNITEMS.Add(symbol); |
495 |
else if (equipment != null) |
496 |
run.RUNITEMS.Add(equipment); |
497 |
else if (opc != null) |
498 |
run.RUNITEMS.Add(opc); |
499 |
} |
500 |
else if (element.Name == "LINE") |
501 |
{ |
502 |
Line line = GetLineByUID(element.Element("UID").Value); |
503 |
if (line == null) |
504 |
{ |
505 |
validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value); |
506 |
validationStringBuilder.AppendLine(); |
507 |
validationResult = true; |
508 |
} |
509 |
run.RUNITEMS.Add(line); |
510 |
} |
511 |
} |
512 |
lineNumberRuns.Add(run); |
513 |
} |
514 |
} |
515 |
|
516 |
private void SetChildSymbol(Symbol symbol) |
517 |
{ |
518 |
List<ChildSymbol> childList = new List<ChildSymbol>(); |
519 |
if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None") |
520 |
{ |
521 |
string[] childArray = symbol.CHILD.Split(new char[] { '/' }); |
522 |
foreach (string sChild in childArray) |
523 |
{ |
524 |
string[] sChildInfo = sChild.Split(new char[] { ',' }); |
525 |
childList.Add(new ChildSymbol() |
526 |
{ |
527 |
ParentAt = Convert.ToInt32(sChildInfo[0]), |
528 |
Direction = sChildInfo[1], |
529 |
NAME = sChildInfo[2] |
530 |
}); |
531 |
} |
532 |
|
533 |
foreach (ChildSymbol child in childList) |
534 |
{ |
535 |
if (child.ParentAt == 0) |
536 |
symbol.ChildSymbols.Add(child); |
537 |
else |
538 |
childList[child.ParentAt - 1].ChildSymbols.Add(child); |
539 |
} |
540 |
} |
541 |
if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None") |
542 |
{ |
543 |
// 현재 부모 Symbol에 자식 Connector까지 들어가 있음 |
544 |
string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' }); |
545 |
string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' }); |
546 |
for (int i = 0; i < array.Length; i++) |
547 |
{ |
548 |
string[] arrConn = array[i].Split(new char[] { ',' }); |
549 |
int connIndex = Convert.ToInt32(arrConn[3]); |
550 |
if (connIndex != 0) |
551 |
{ |
552 |
childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]); |
553 |
symbol.CONNECTORS[i].Index = connIndex; |
554 |
} |
555 |
} |
556 |
} |
557 |
} |
558 |
|
559 |
private void SetText(XElement node) |
560 |
{ |
561 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
562 |
{ |
563 |
Text text = new Text() |
564 |
{ |
565 |
UID = item.Element("UID").Value, |
566 |
OWNER = item.Element("OWNER").Value, |
567 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
568 |
NAME = item.Element("NAME").Value, |
569 |
LOCATION = item.Element("LOCATION").Value, |
570 |
VALUE = item.Element("VALUE").Value, |
571 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
572 |
WIDTH = item.Element("WIDTH").Value, |
573 |
HEIGHT = item.Element("HEIGHT").Value, |
574 |
AREA = item.Element("AREA").Value, |
575 |
SCENE = item.Element("SCENE").Value |
576 |
}; |
577 |
|
578 |
Texts.Add(text); |
579 |
} |
580 |
} |
581 |
|
582 |
private void SetNote(XElement node) |
583 |
{ |
584 |
foreach (XElement item in node.Elements("ATTRIBUTE")) |
585 |
{ |
586 |
Note note = new Note() |
587 |
{ |
588 |
UID = item.Element("UID").Value, |
589 |
ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value, |
590 |
NAME = item.Element("NAME").Value, |
591 |
LOCATION = item.Element("LOCATION").Value, |
592 |
VALUE = item.Element("VALUE").Value, |
593 |
ANGLE = Convert.ToDouble(item.Element("ANGLE").Value), |
594 |
WIDTH = item.Element("WIDTH").Value, |
595 |
HEIGHT = item.Element("HEIGHT").Value, |
596 |
AREA = item.Element("AREA").Value, |
597 |
SCENE = item.Element("SCENE").Value, |
598 |
OWNER = item.Element("OWNER").Value |
599 |
}; |
600 |
|
601 |
Notes.Add(note); |
602 |
} |
603 |
} |
604 |
#endregion |
605 |
|
606 |
public void SetAllConnectors() |
607 |
{ |
608 |
foreach (var item in SYMBOLS) |
609 |
foreach (var connector in item.CONNECTORS) |
610 |
connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM); |
611 |
|
612 |
foreach (var item in OPCs) |
613 |
foreach (var connector in item.CONNECTORS) |
614 |
connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM); |
615 |
|
616 |
foreach (var item in LINES) |
617 |
foreach (var connector in item.CONNECTORS) |
618 |
connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM); |
619 |
|
620 |
foreach (var item in Equipments) |
621 |
foreach (var connector in item.CONNECTORS) |
622 |
connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM); |
623 |
} |
624 |
|
625 |
public Symbol GetSymbolByUID(string uid) |
626 |
{ |
627 |
return SYMBOLS.Find(x => x.UID == uid); |
628 |
} |
629 |
|
630 |
public OPC GetOPCByUID(string uid) |
631 |
{ |
632 |
return OPCs.Find(x => x.UID == uid); |
633 |
} |
634 |
|
635 |
public Equipment GetEquipmentByUID(string uid) |
636 |
{ |
637 |
return Equipments.Find(x => x.UID == uid); |
638 |
} |
639 |
|
640 |
public Line GetLineByUID(string uid) |
641 |
{ |
642 |
return LINES.Find(x => x.UID == uid); |
643 |
} |
644 |
|
645 |
#region For Aveva |
646 |
|
647 |
public bool SetAvevaInfo(DataTable symbolMappingTable, DataTable lineMappingTable, DataTable opcMappingTable) |
648 |
{ |
649 |
bool result = true; |
650 |
foreach (var item in LINES) |
651 |
{ |
652 |
DataRow[] rows = lineMappingTable.Select(string.Format("UID = '{0}'", item.TYPEUID)); |
653 |
if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["APID_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["APID_SYMBOL"])) |
654 |
{ |
655 |
item.Aveva = new AvevaLineInfo(); |
656 |
item.Aveva.Name = (string)rows[0]["APID_SYMBOL"]; |
657 |
double startX = item.Start_X; |
658 |
double startY = SIZE_HEIGHT - item.Start_Y; |
659 |
double endX = item.End_X; |
660 |
double endY = SIZE_HEIGHT - item.End_Y; |
661 |
|
662 |
ConvertAvevaPoint(ref startX, ref startY); |
663 |
ConvertAvevaPoint(ref endX, ref endY); |
664 |
|
665 |
item.Aveva.Start_X = startX; |
666 |
item.Aveva.Start_Y = startY; |
667 |
item.Aveva.End_X = endX; |
668 |
item.Aveva.End_Y = endY; |
669 |
|
670 |
if (item.SlopeType == SlopeType.HORIZONTAL) |
671 |
item.Aveva.End_Y = item.Aveva.Start_Y; |
672 |
else if (item.SlopeType == SlopeType.VERTICAL) |
673 |
item.Aveva.End_X = item.Aveva.Start_X; |
674 |
|
675 |
if (!DBNull.Value.Equals(rows[0]["DATA1"])) |
676 |
{ |
677 |
if (rows[0]["DATA1"].ToString() == "PIPE") |
678 |
item.Aveva.Type = Type.Pipe; |
679 |
else if (rows[0]["DATA1"].ToString() == "SIGNAL") |
680 |
item.Aveva.Type = Type.Signal; |
681 |
} |
682 |
|
683 |
item.Aveva.Start_X = Math.Round(item.Aveva.Start_X); |
684 |
item.Aveva.Start_Y = Math.Round(item.Aveva.Start_Y); |
685 |
item.Aveva.End_X = Math.Round(item.Aveva.End_X); |
686 |
item.Aveva.End_Y = Math.Round(item.Aveva.End_Y); |
687 |
} |
688 |
else |
689 |
{ |
690 |
validationStringBuilder.AppendLine(string.Format("Need Mapping Line : {0}", item.TYPE)); |
691 |
result = false; |
692 |
} |
693 |
} |
694 |
foreach (var item in SYMBOLS) |
695 |
{ |
696 |
DataRow[] rows = symbolMappingTable.Select(string.Format("UID = '{0}'", item.DBUID)); |
697 |
if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["APID_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["APID_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 = Math.Round(x); |
706 |
item.Aveva.Y = Math.Round(y); |
707 |
|
708 |
item.Aveva.FullName = (string)rows[0]["APID_SYMBOL"]; |
709 |
string[] split = item.Aveva.FullName.Split(new char[] { '\\' }); |
710 |
item.Aveva.Name = split[split.Length - 1]; |
711 |
} |
712 |
else |
713 |
{ |
714 |
validationStringBuilder.AppendLine(string.Format("Need Mapping Symbol : {0}", item.NAME)); |
715 |
result = false; |
716 |
} |
717 |
} |
718 |
foreach (var item in OPCs) |
719 |
{ |
720 |
DataRow[] rows = opcMappingTable.Select(string.Format("UID = '{0}'", item.DBUID)); |
721 |
if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["IN_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["OUT_SYMBOL"])) |
722 |
{ |
723 |
item.Aveva = new AvevaSymbolInfo(); |
724 |
double x = item.X; |
725 |
double y = SIZE_HEIGHT - item.Y; |
726 |
|
727 |
ConvertAvevaPoint(ref x, ref y); |
728 |
|
729 |
item.Aveva.X = Math.Round(x); |
730 |
item.Aveva.Y = Math.Round(y); |
731 |
|
732 |
if (item.TYPE == "Piping OPC's") |
733 |
item.OPCType = OPCType.Pipe; |
734 |
else if (item.TYPE == "Instrument OPC's") |
735 |
item.OPCType = OPCType.Signal; |
736 |
|
737 |
Connector connector = item.CONNECTORS.Find(loop => |
738 |
APIDUtils.FindObjectByUID(this, loop.CONNECTEDITEM) != null && |
739 |
APIDUtils.FindObjectByUID(this, loop.CONNECTEDITEM).GetType() == typeof(Line)); |
740 |
if (connector != null) |
741 |
{ |
742 |
// out |
743 |
if (item.CONNECTORS.IndexOf(connector) == 0) |
744 |
{ |
745 |
item.Aveva.FullName = (string)rows[0]["OUT_SYMBOL"]; |
746 |
string[] split = item.Aveva.FullName.Split(new char[] { '\\' }); |
747 |
item.Aveva.Name = split[split.Length - 1]; |
748 |
item.FlowType = FlowType.Out; |
749 |
} |
750 |
// in |
751 |
else |
752 |
{ |
753 |
item.Aveva.FullName = (string)rows[0]["IN_SYMBOL"]; |
754 |
string[] split = item.Aveva.FullName.Split(new char[] { '\\' }); |
755 |
item.Aveva.Name = split[split.Length - 1]; |
756 |
item.FlowType = FlowType.In; |
757 |
} |
758 |
} |
759 |
else |
760 |
{ |
761 |
validationStringBuilder.AppendLine(string.Format("Check OPC's Connector : {0}", item.UID)); |
762 |
result = false; |
763 |
} |
764 |
} |
765 |
else |
766 |
{ |
767 |
validationStringBuilder.AppendLine(string.Format("Need Mapping Symbol : {0}", item.NAME)); |
768 |
result = false; |
769 |
} |
770 |
} |
771 |
foreach (var item in LINENUMBERS) |
772 |
{ |
773 |
item.Aveva = new AvevaLabelInfo(); |
774 |
double x = (item.X1 + item.X2) / 2; |
775 |
double y = SIZE_HEIGHT - (item.Y1 + item.Y2) / 2; |
776 |
|
777 |
ConvertAvevaPoint(ref x, ref y); |
778 |
|
779 |
item.Aveva.X = Math.Round(x); |
780 |
item.Aveva.Y = Math.Round(y); |
781 |
item.Aveva.LabelType = LabelType.LineNumber; |
782 |
item.Aveva.Angle = RadianToDegree(item.ANGLE); |
783 |
} |
784 |
|
785 |
foreach (var item in Texts) |
786 |
{ |
787 |
item.Aveva = new AvevaLabelInfo(); |
788 |
|
789 |
double x = item.X1; |
790 |
double y = SIZE_HEIGHT - item.Y2; |
791 |
ConvertAvevaPoint(ref x, ref y); |
792 |
item.Aveva.X = Math.Round(x); |
793 |
item.Aveva.Y = Math.Round(y); |
794 |
|
795 |
if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180) |
796 |
{ |
797 |
double height = Math.Abs(item.Y1 - item.Y2); |
798 |
ConvertAvevaPointY(ref height); |
799 |
item.Aveva.Height = height; |
800 |
} |
801 |
else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270) |
802 |
{ |
803 |
double height = Math.Abs(item.X1 - item.X2); |
804 |
ConvertAvevaPointX(ref height); |
805 |
item.Aveva.Height = height; |
806 |
} |
807 |
|
808 |
if (item.VALUE.Contains("\n")) |
809 |
{ |
810 |
item.Aveva.LabelType = LabelType.MultiText; |
811 |
int count = item.VALUE.Length - item.VALUE.Replace("\n", "").Length + 1; |
812 |
item.Aveva.Height = item.Aveva.Height / count; |
813 |
} |
814 |
else |
815 |
item.Aveva.LabelType = LabelType.SingleText; |
816 |
|
817 |
item.Aveva.Angle = item.ANGLE; |
818 |
} |
819 |
foreach (var item in Notes) |
820 |
{ |
821 |
item.Aveva = new AvevaLabelInfo(); |
822 |
|
823 |
double x = item.X1; |
824 |
double y = SIZE_HEIGHT - item.Y2; |
825 |
ConvertAvevaPoint(ref x, ref y); |
826 |
item.Aveva.X = Math.Round(x); |
827 |
item.Aveva.Y = Math.Round(y); |
828 |
|
829 |
if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180) |
830 |
{ |
831 |
double height = Math.Abs(item.Y1 - item.Y2); |
832 |
ConvertAvevaPointY(ref height); |
833 |
item.Aveva.Height = height; |
834 |
} |
835 |
else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270) |
836 |
{ |
837 |
double height = Math.Abs(item.X1 - item.X2); |
838 |
ConvertAvevaPointX(ref height); |
839 |
item.Aveva.Height = height; |
840 |
} |
841 |
|
842 |
if (item.VALUE.Contains(@"\n")) |
843 |
{ |
844 |
item.Aveva.LabelType = LabelType.MultiNote; |
845 |
int count = item.VALUE.Length - item.VALUE.Replace("\n", "").Length + 1; |
846 |
item.Aveva.Height = item.Aveva.Height / count; |
847 |
} |
848 |
else |
849 |
item.Aveva.LabelType = LabelType.SingleNote; |
850 |
|
851 |
item.Aveva.Angle = item.ANGLE; |
852 |
} |
853 |
|
854 |
if (!result) |
855 |
ValidationMessage = validationStringBuilder.ToString(); |
856 |
|
857 |
return result; |
858 |
} |
859 |
|
860 |
public void ConvertAvevaPoint(ref double x, ref double y) |
861 |
{ |
862 |
decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX); |
863 |
decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY); |
864 |
decimal id2Width = Convert.ToDecimal(SIZE_WIDTH); |
865 |
decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT); |
866 |
|
867 |
x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x)); |
868 |
y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y)); |
869 |
} |
870 |
public void ConvertAvevaPointX(ref double x) |
871 |
{ |
872 |
decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX); |
873 |
decimal id2Width = Convert.ToDecimal(SIZE_WIDTH); |
874 |
|
875 |
x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x)); |
876 |
} |
877 |
public void ConvertAvevaPointY(ref double y) |
878 |
{ |
879 |
decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY); |
880 |
decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT); |
881 |
|
882 |
y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y)); |
883 |
} |
884 |
|
885 |
private double RadianToDegree(double angle) |
886 |
{ |
887 |
return angle * (180.0 / Math.PI); |
888 |
} |
889 |
|
890 |
#endregion |
891 |
} |
892 |
} |