hytos / DTI_PID / ID2PSN / Document.cs @ 7500c10b
이력 | 보기 | 이력해설 | 다운로드 (27.1 KB)
1 |
using DevExpress.Utils.StructuredStorage.Internal.Reader; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Data; |
5 |
using System.IO; |
6 |
using System.Linq; |
7 |
using System.Text; |
8 |
using System.Threading.Tasks; |
9 |
using System.Xml.Linq; |
10 |
|
11 |
namespace ID2PSN |
12 |
{ |
13 |
public class Document |
14 |
{ |
15 |
public string DrawingName { get; set; } |
16 |
public string FileName { get; set; } |
17 |
public string FilePath { get; set; } |
18 |
public List<Item> Items { get; set; } |
19 |
public List<LineNumber> LineNumbers { get; set; } |
20 |
public List<Group> Groups { get; set; } |
21 |
public List<RunInfo> RunInfos { get; set; } |
22 |
public List<Item> SegmentBreaks { get; set; } |
23 |
public List<Equipment> Equipments { get; set; } |
24 |
|
25 |
private DataTable equipmentTable = DB.GetEquipmentType(); |
26 |
|
27 |
public Document(string filePath) |
28 |
{ |
29 |
FilePath = filePath; |
30 |
ReadFile(); |
31 |
InsertNozzle(); |
32 |
SetRelationItem(); |
33 |
SetGroup(); |
34 |
RemoveItems(); |
35 |
} |
36 |
private void ReadFile() |
37 |
{ |
38 |
XElement xml = XElement.Load(FilePath); |
39 |
FileName = Path.GetFileNameWithoutExtension(FilePath); |
40 |
DrawingName = xml.Element("DWGNAME").Value; |
41 |
Items = new List<Item>(); |
42 |
LineNumbers = new List<LineNumber>(); |
43 |
RunInfos = new List<RunInfo>(); |
44 |
Groups = new List<Group>(); |
45 |
SegmentBreaks = new List<Item>(); |
46 |
Equipments = new List<Equipment>(); |
47 |
|
48 |
foreach (XElement element in xml.Element("SYMBOLS").Elements("SYMBOL")) |
49 |
Items.Add(GetSymbolItem(element)); |
50 |
foreach (XElement element in xml.Element("LINEINFOS").Elements("LINE")) |
51 |
Items.Add(GetLineItem(element)); |
52 |
foreach (XElement element in xml.Element("LINENOS").Elements("LINE_NO")) |
53 |
LineNumbers.Add(GetLineNumber(element)); |
54 |
foreach (XElement element in xml.Element("VENDORS").Elements("VENDOR")) |
55 |
Equipments.Add(GetEquipment(element)); |
56 |
|
57 |
|
58 |
List<Item> segmentBreaks = Items.FindAll(x => x.Type.ToUpper() == "Segment Breaks".ToUpper() || x.Type.ToUpper() == "End Break".ToUpper()); |
59 |
SegmentBreaks.AddRange(segmentBreaks); |
60 |
foreach (var item in segmentBreaks) |
61 |
Items.Remove(item); |
62 |
|
63 |
foreach (DataRow row in equipmentTable.Rows) |
64 |
{ |
65 |
string type = row["Type"].ToString(); |
66 |
List<Item> equipments = Items.FindAll(x => x.Type == type); |
67 |
|
68 |
foreach (Item item in equipments) |
69 |
{ |
70 |
Equipments.Add(ConvertEquipment(item)); |
71 |
Items.Remove(item); |
72 |
} |
73 |
} |
74 |
|
75 |
SetRunInfo(xml); |
76 |
} |
77 |
private Item GetSymbolItem(XElement element) |
78 |
{ |
79 |
Item item = new Item(); |
80 |
item.UID = element.Element("UID").Value; |
81 |
item.Name = element.Element("NAME").Value; |
82 |
item.Type = element.Element("TYPE").Value; |
83 |
item.Owner = element.Element("OWNER").Value; |
84 |
item.Parent = element.Element("PARENT").Value; |
85 |
string[] sPoint = element.Element("ORIGINALPOINT").Value.Split(new char[] { ',' }); |
86 |
item.POINT = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) }; |
87 |
item.ANGLE = element.Element("ANGLE").Value; |
88 |
item.Relations = GetRelations(element.Element("CONNECTORS")); |
89 |
item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
90 |
item.ItemType = ItemType.Symbol; |
91 |
|
92 |
if (item.Type.ToUpper().Equals("PIPING OPC'S")) |
93 |
item.SubItemType = SubItemType.OPC; |
94 |
else if (item.Type.ToUpper().Equals("NOZZLES")) |
95 |
item.SubItemType = SubItemType.Nozzle; |
96 |
|
97 |
return item; |
98 |
} |
99 |
private Item GetLineItem(XElement element) |
100 |
{ |
101 |
Item item = new Item(); |
102 |
item.UID = element.Element("UID").Value; |
103 |
item.Name = element.Element("TYPE").Value; |
104 |
item.Type = element.Element("TYPE").Value; |
105 |
item.Owner = element.Attribute("OWNER").Value; |
106 |
|
107 |
item.Relations = GetRelations(element.Element("CONNECTORS")); |
108 |
item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
109 |
item.ItemType = ItemType.Line; |
110 |
|
111 |
return item; |
112 |
} |
113 |
private LineNumber GetLineNumber(XElement element) |
114 |
{ |
115 |
LineNumber lineNumber = new LineNumber(); |
116 |
lineNumber.UID = element.Element("UID").Value; |
117 |
lineNumber.Name = element.Element("TEXT").Value; |
118 |
lineNumber.Attributes = GetAttributes(element); |
119 |
return lineNumber; |
120 |
} |
121 |
private Equipment GetEquipment(XElement element) |
122 |
{ |
123 |
Equipment item = new Equipment(); |
124 |
item.UID = element.Element("UID").Value; |
125 |
item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
126 |
string[] sPoint = element.Element("POINT").Value.Split(new char[] { '/' }); |
127 |
foreach (var sp in sPoint) |
128 |
{ |
129 |
string[] xy = sp.Split(new char[] { ',' }); |
130 |
item.POINT.Add(new double[] { Convert.ToDouble(xy[0]), Convert.ToDouble(xy[1]) }); |
131 |
} |
132 |
|
133 |
return item; |
134 |
} |
135 |
|
136 |
private Equipment ConvertEquipment(Item item) |
137 |
{ |
138 |
Equipment equipment = new Equipment(); |
139 |
equipment.Name = item.Name; |
140 |
equipment.UID = item.UID; |
141 |
equipment.POINT.Add(item.POINT); |
142 |
equipment.Attributes.AddRange(item.Attributes); |
143 |
return equipment; |
144 |
} |
145 |
private List<Relation> GetRelations(XElement element) |
146 |
{ |
147 |
List<Relation> result = new List<Relation>(); |
148 |
foreach (XElement item in element.Elements("CONNECTOR")) |
149 |
{ |
150 |
string[] sPoint = item.Element("SCENECONNECTPOINT").Value.Split(new char[] { ',' }); |
151 |
result.Add(new Relation() |
152 |
{ |
153 |
UID = item.Element("CONNECTEDITEM").Value, |
154 |
Point = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) } |
155 |
}); |
156 |
} |
157 |
|
158 |
return result; |
159 |
} |
160 |
private List<Attribute> GetAttributes(XElement element) |
161 |
{ |
162 |
List<Attribute> result = new List<Attribute>(); |
163 |
foreach (XElement item in element.Elements("ATTRIBUTE")) |
164 |
{ |
165 |
result.Add(new Attribute() |
166 |
{ |
167 |
UID = item.Attribute("UID").Value, |
168 |
Name = item.Attribute("Attribute").Value, |
169 |
DisplayName = item.Attribute("DisplayAttribute").Value, |
170 |
Value = item.Value |
171 |
}); |
172 |
} |
173 |
return result; |
174 |
} |
175 |
private void SetRelationItem() |
176 |
{ |
177 |
foreach (Item item in Items) |
178 |
foreach (Relation relation in item.Relations) |
179 |
relation.Item = Items.Find(x => x.UID.Equals(relation.UID)); |
180 |
} |
181 |
private void SetRunInfo(XElement xml) |
182 |
{ |
183 |
foreach (XElement element in xml.Element("LINENOS").Elements("LINE_NO")) |
184 |
{ |
185 |
string UID = element.Element("UID").Value; |
186 |
foreach (XElement run in element.Elements("RUN")) |
187 |
{ |
188 |
RunInfo runInfo = new RunInfo() { UID = UID }; |
189 |
foreach (XElement line in run.Elements("LINE")) |
190 |
runInfo.Items.Add(Items.Find(x => x.UID == line.Element("UID").Value)); |
191 |
foreach (XElement symbol in run.Elements("SYMBOL")) |
192 |
runInfo.Items.Add(Items.Find(x => x.UID == symbol.Element("UID").Value)); |
193 |
RunInfos.Add(runInfo); |
194 |
} |
195 |
} |
196 |
|
197 |
foreach (XElement element in xml.Element("TRIMLINENOS").Elements("TRIM_LINE_NO")) |
198 |
{ |
199 |
string UID = element.Element("UID").Value; |
200 |
foreach (XElement run in element.Elements("RUN")) |
201 |
{ |
202 |
RunInfo runInfo = new RunInfo() { UID = UID }; |
203 |
foreach (XElement line in run.Elements("LINE")) |
204 |
runInfo.Items.Add(Items.Find(x => x.UID == line.Element("UID").Value)); |
205 |
foreach (XElement symbol in run.Elements("SYMBOL")) |
206 |
runInfo.Items.Add(Items.Find(x => x.UID == symbol.Element("UID").Value)); |
207 |
RunInfos.Add(runInfo); |
208 |
} |
209 |
} |
210 |
} |
211 |
private void SetGroup() |
212 |
{ |
213 |
List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList(); |
214 |
|
215 |
Dictionary<Item, string> itemDic = new Dictionary<Item, string>(); |
216 |
foreach (Item item in orderItems) |
217 |
itemDic.Add(item, Guid.NewGuid().ToString()); |
218 |
|
219 |
foreach (Item item in orderItems) |
220 |
{ |
221 |
string groupKey = itemDic[item]; |
222 |
if (item.ItemType == ItemType.Line) |
223 |
{ |
224 |
GroupingForwardLine(); |
225 |
GroupingBackwardLine(); |
226 |
} |
227 |
|
228 |
void GroupingForwardLine() |
229 |
{ |
230 |
Item connItem = item.Relations[1].Item; |
231 |
if (connItem != null && IsConnected(connItem, item)) |
232 |
{ |
233 |
if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[0].Item)) |
234 |
ChangeGroupID(itemDic[connItem], groupKey); |
235 |
else if (connItem.ItemType == ItemType.Symbol) |
236 |
{ |
237 |
List<Item> allConnItems = GetConnectedLines(connItem); |
238 |
allConnItems.Remove(item); |
239 |
List<Item> connItems = GetConnectedForwardLines(connItem); |
240 |
if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0])) |
241 |
{ |
242 |
List<Item> connSymbols = GetConnectedSymbols(connItem); |
243 |
foreach (Item loopItem in connSymbols) |
244 |
ChangeGroupID(itemDic[loopItem], groupKey); |
245 |
} |
246 |
else |
247 |
{ |
248 |
List<Item> endItems = new List<Item>(); |
249 |
Stack<Item> stacks = new Stack<Item>(); |
250 |
stacks.Push(connItem); |
251 |
while (stacks.Count > 0) |
252 |
{ |
253 |
Item stack = stacks.Pop(); |
254 |
if (endItems.Contains(stack)) |
255 |
continue; |
256 |
endItems.Add(stack); |
257 |
|
258 |
if (GetConnectedItemCount(stack) < 3) |
259 |
{ |
260 |
ChangeGroupID(itemDic[stack], groupKey); |
261 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
262 |
foreach (Relation relation in relations) |
263 |
stacks.Push(relation.Item); |
264 |
} |
265 |
else if (IsSameRun(item, stack)) |
266 |
{ |
267 |
ChangeGroupID(itemDic[stack], groupKey); |
268 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item)); |
269 |
foreach (Relation relation in relations) |
270 |
stacks.Push(relation.Item); |
271 |
} |
272 |
} |
273 |
} |
274 |
} |
275 |
} |
276 |
} |
277 |
void GroupingBackwardLine() |
278 |
{ |
279 |
Item connItem = item.Relations[0].Item; |
280 |
if (connItem != null && IsConnected(connItem, item)) |
281 |
{ |
282 |
if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[1].Item)) |
283 |
ChangeGroupID(itemDic[connItem], groupKey); |
284 |
else if (connItem.ItemType == ItemType.Symbol) |
285 |
{ |
286 |
List<Item> allConnItems = GetConnectedLines(connItem); |
287 |
allConnItems.Remove(item); |
288 |
List<Item> connItems = GetConnectedBackwardLines(connItem); |
289 |
if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0])) |
290 |
{ |
291 |
List<Item> connSymbols = GetConnectedSymbols(connItem); |
292 |
foreach (Item loopItem in connSymbols) |
293 |
ChangeGroupID(itemDic[loopItem], groupKey); |
294 |
} |
295 |
else |
296 |
{ |
297 |
List<Item> endItems = new List<Item>(); |
298 |
Stack<Item> stacks = new Stack<Item>(); |
299 |
stacks.Push(connItem); |
300 |
while (stacks.Count > 0) |
301 |
{ |
302 |
Item stack = stacks.Pop(); |
303 |
if (endItems.Contains(stack)) |
304 |
continue; |
305 |
endItems.Add(stack); |
306 |
|
307 |
if (GetConnectedItemCount(stack) < 3) |
308 |
{ |
309 |
ChangeGroupID(itemDic[stack], groupKey); |
310 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
311 |
foreach (Relation relation in relations) |
312 |
stacks.Push(relation.Item); |
313 |
} |
314 |
else if (IsSameRun(item, stack)) |
315 |
{ |
316 |
ChangeGroupID(itemDic[stack], groupKey); |
317 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item)); |
318 |
foreach (Relation relation in relations) |
319 |
stacks.Push(relation.Item); |
320 |
} |
321 |
} |
322 |
} |
323 |
} |
324 |
} |
325 |
} |
326 |
} |
327 |
|
328 |
List<string> endGroupIds = new List<string>(); |
329 |
foreach (var item in itemDic) |
330 |
{ |
331 |
if (endGroupIds.Contains(item.Value)) |
332 |
continue; |
333 |
endGroupIds.Add(item.Value); |
334 |
|
335 |
List<Item> groupItems = itemDic.Where(x => x.Value.Equals(item.Value)).Select(x => x.Key).ToList(); |
336 |
if (groupItems.Find(x => x.ItemType == ItemType.Line) == null) |
337 |
{ |
338 |
foreach (var groupItem in groupItems) |
339 |
Items.Remove(groupItem); |
340 |
} |
341 |
else |
342 |
{ |
343 |
Group group = new Group(this); |
344 |
group.Items = groupItems; |
345 |
group.UID = item.Value; |
346 |
group.SortItems(); |
347 |
foreach (Item groupItem in groupItems) |
348 |
groupItem.Group = group; |
349 |
Groups.Add(group); |
350 |
} |
351 |
} |
352 |
|
353 |
#region HeaderSetting |
354 |
List<HeaderInfo> HeaderInfos = new List<HeaderInfo>(); |
355 |
DataTable dt = DB.SelectHeaderSetting(); |
356 |
foreach (DataRow row in dt.Rows) |
357 |
{ |
358 |
string groupID = row["GROUP_ID"].ToString(); |
359 |
string desc = row["DESCRIPTION"].ToString(); |
360 |
int index = Convert.ToInt32(row["INDEX"]); |
361 |
string name = row["NAME"].ToString(); |
362 |
|
363 |
HeaderInfo headerInfo = HeaderInfos.Find(x => x.UID.Equals(groupID)); |
364 |
if (headerInfo == null) |
365 |
{ |
366 |
headerInfo = new HeaderInfo(groupID); |
367 |
headerInfo.Description = desc; |
368 |
HeaderInfos.Add(headerInfo); |
369 |
} |
370 |
|
371 |
headerInfo.HeaderItems.Add(new HeaderItem() |
372 |
{ |
373 |
Index = index, |
374 |
Name = name |
375 |
}); |
376 |
} |
377 |
foreach (HeaderInfo headerInfo in HeaderInfos) |
378 |
headerInfo.HeaderItems = headerInfo.HeaderItems.OrderBy(x => x.Index).ToList(); |
379 |
|
380 |
foreach (Group group in Groups) |
381 |
{ |
382 |
List<HeaderInfo> endInfos = new List<HeaderInfo>(); |
383 |
bool bFind = false; |
384 |
for (int i = 0; i < group.Items.Count; i++) |
385 |
{ |
386 |
Item item = group.Items[i]; |
387 |
foreach (HeaderInfo header in HeaderInfos) |
388 |
{ |
389 |
if (endInfos.Contains(header)) |
390 |
continue; |
391 |
|
392 |
if (!header.HeaderItems[i].Name.Equals(item.Name)) |
393 |
{ |
394 |
endInfos.Add(header); |
395 |
continue; |
396 |
} |
397 |
|
398 |
if (header.HeaderItems.Count.Equals(i + 1)) |
399 |
{ |
400 |
for (int j = 0; j < i + 1; j++) |
401 |
group.Items[j].SubItemType = SubItemType.Header; |
402 |
bFind = true; |
403 |
break; |
404 |
} |
405 |
} |
406 |
|
407 |
if (bFind || endInfos.Count.Equals(HeaderInfos.Count)) |
408 |
break; |
409 |
} |
410 |
|
411 |
endInfos = new List<HeaderInfo>(); |
412 |
bFind = false; |
413 |
for (int i = 0; i < group.Items.Count; i++) |
414 |
{ |
415 |
Item item = group.Items[group.Items.Count - i - 1]; |
416 |
foreach (HeaderInfo header in HeaderInfos) |
417 |
{ |
418 |
if (endInfos.Contains(header)) |
419 |
continue; |
420 |
|
421 |
if (!header.HeaderItems[i].Name.Equals(item.Name)) |
422 |
{ |
423 |
endInfos.Add(header); |
424 |
continue; |
425 |
} |
426 |
|
427 |
if (header.HeaderItems.Count.Equals(i + 1)) |
428 |
{ |
429 |
for (int j = 0; j < i + 1; j++) |
430 |
group.Items[group.Items.Count - j - 1].SubItemType = SubItemType.Header; |
431 |
bFind = true; |
432 |
break; |
433 |
} |
434 |
} |
435 |
|
436 |
if (bFind || endInfos.Count.Equals(HeaderInfos.Count)) |
437 |
break; |
438 |
} |
439 |
} |
440 |
#endregion |
441 |
|
442 |
int GetConnectedItemCount(Item item) |
443 |
{ |
444 |
return item.Relations.FindAll(x => x.Item != null).Count; |
445 |
} |
446 |
|
447 |
List<Item> GetConnectedLines(Item item) |
448 |
{ |
449 |
List<Item> result = new List<Item>(); |
450 |
List<Item> end = new List<Item>(); |
451 |
Stack<Item> stacks = new Stack<Item>(); |
452 |
stacks.Push(item); |
453 |
while (stacks.Count > 0) |
454 |
{ |
455 |
Item stack = stacks.Pop(); |
456 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
457 |
continue; |
458 |
end.Add(stack); |
459 |
|
460 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
461 |
foreach (Relation relation in relations) |
462 |
stacks.Push(relation.Item); |
463 |
|
464 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
465 |
foreach (Relation relation in relations) |
466 |
{ |
467 |
result.Add(relation.Item); |
468 |
end.Add(relation.Item); |
469 |
} |
470 |
} |
471 |
|
472 |
return result; |
473 |
} |
474 |
|
475 |
List<Item> GetConnectedForwardLines(Item item) |
476 |
{ |
477 |
List<Item> result = new List<Item>(); |
478 |
List<Item> end = new List<Item>(); |
479 |
Stack<Item> stacks = new Stack<Item>(); |
480 |
stacks.Push(item); |
481 |
while (stacks.Count > 0) |
482 |
{ |
483 |
Item stack = stacks.Pop(); |
484 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
485 |
continue; |
486 |
end.Add(stack); |
487 |
|
488 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
489 |
foreach (Relation relation in relations) |
490 |
stacks.Push(relation.Item); |
491 |
|
492 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
493 |
foreach (Relation relation in relations) |
494 |
{ |
495 |
if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(0)) |
496 |
result.Add(relation.Item); |
497 |
|
498 |
end.Add(relation.Item); |
499 |
} |
500 |
} |
501 |
|
502 |
return result; |
503 |
} |
504 |
|
505 |
List<Item> GetConnectedBackwardLines(Item item) |
506 |
{ |
507 |
List<Item> result = new List<Item>(); |
508 |
List<Item> end = new List<Item>(); |
509 |
Stack<Item> stacks = new Stack<Item>(); |
510 |
stacks.Push(item); |
511 |
while (stacks.Count > 0) |
512 |
{ |
513 |
Item stack = stacks.Pop(); |
514 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
515 |
continue; |
516 |
end.Add(stack); |
517 |
|
518 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
519 |
foreach (Relation relation in relations) |
520 |
stacks.Push(relation.Item); |
521 |
|
522 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
523 |
foreach (Relation relation in relations) |
524 |
{ |
525 |
if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(1)) |
526 |
result.Add(relation.Item); |
527 |
|
528 |
end.Add(relation.Item); |
529 |
} |
530 |
} |
531 |
|
532 |
return result; |
533 |
} |
534 |
|
535 |
List<Item> GetConnectedSymbols(Item item) |
536 |
{ |
537 |
List<Item> result = new List<Item>(); |
538 |
List<Item> end = new List<Item>(); |
539 |
Stack<Item> stacks = new Stack<Item>(); |
540 |
stacks.Push(item); |
541 |
while (stacks.Count > 0) |
542 |
{ |
543 |
Item stack = stacks.Pop(); |
544 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
545 |
continue; |
546 |
end.Add(stack); |
547 |
result.Add(stack); |
548 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
549 |
foreach (Relation relation in relations) |
550 |
stacks.Push(relation.Item); |
551 |
} |
552 |
|
553 |
return result; |
554 |
} |
555 |
|
556 |
void ChangeGroupID(string from, string to) |
557 |
{ |
558 |
if (from.Equals(to)) |
559 |
return; |
560 |
|
561 |
List<Item> changeItems = new List<Item>(); |
562 |
foreach (var _item in itemDic) |
563 |
if (_item.Value.Equals(from)) |
564 |
changeItems.Add(_item.Key); |
565 |
foreach (var _item in changeItems) |
566 |
itemDic[_item] = to; |
567 |
} |
568 |
|
569 |
bool IsConnected(Item item1, Item item2) |
570 |
{ |
571 |
if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null && |
572 |
item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null) |
573 |
return true; |
574 |
else |
575 |
return false; |
576 |
} |
577 |
|
578 |
bool IsSameRun(Item item1, Item item2) |
579 |
{ |
580 |
return RunInfos.Find(x => x.Items.Contains(item1) && x.Items.Contains(item2)) != null ? true : false; |
581 |
} |
582 |
} |
583 |
private void RemoveItems() |
584 |
{ |
585 |
List<Group> removeGroups = new List<Group>(); |
586 |
foreach (Group group in Groups) |
587 |
{ |
588 |
Item instLine = group.Items.Find(x => x.ItemType == ItemType.Line && (x.Name != "Secondary" && x.Name != "Primary")); |
589 |
if (instLine != null) |
590 |
removeGroups.Add(group); |
591 |
} |
592 |
|
593 |
foreach (Group group in removeGroups) |
594 |
{ |
595 |
foreach (var item in group.Items) |
596 |
Items.Remove(item); |
597 |
Groups.Remove(group); |
598 |
} |
599 |
} |
600 |
private void InsertNozzle() |
601 |
{ |
602 |
List<Item> newNozzles = new List<Item>(); |
603 |
foreach (var item in Items) |
604 |
{ |
605 |
if (item.SubItemType == SubItemType.Nozzle) |
606 |
continue; |
607 |
|
608 |
foreach (Relation relation in item.Relations) |
609 |
{ |
610 |
Equipment equipment = Equipments.Find(x => x.UID == relation.UID); |
611 |
if (equipment != null) |
612 |
{ |
613 |
Item newNozzle = new Item(); |
614 |
newNozzle.UID = Guid.NewGuid().ToString(); |
615 |
newNozzle.Name = "PSN_Nozzle"; |
616 |
newNozzle.Type = "Nozzles"; |
617 |
newNozzle.Owner = item.Owner; |
618 |
newNozzle.Parent = "PSN_Nozzle"; |
619 |
newNozzle.POINT = relation.Point; |
620 |
newNozzle.Relations = new List<Relation>(); |
621 |
|
622 |
newNozzle.Relations.Add(new Relation() |
623 |
{ |
624 |
Point = relation.Point, |
625 |
UID = equipment.UID |
626 |
}); |
627 |
newNozzle.Relations.Add(new Relation() |
628 |
{ |
629 |
Point = relation.Point, |
630 |
UID = item.UID |
631 |
}); |
632 |
|
633 |
newNozzle.ItemType = ItemType.Symbol; |
634 |
newNozzle.SubItemType = SubItemType.Nozzle; |
635 |
|
636 |
newNozzles.Add(newNozzle); |
637 |
|
638 |
relation.UID = newNozzle.UID; |
639 |
} |
640 |
} |
641 |
} |
642 |
|
643 |
Items.AddRange(newNozzles); |
644 |
} |
645 |
} |
646 |
} |