hytos / DTI_PID / ID2PSN / Document.cs @ eb44d82c
이력 | 보기 | 이력해설 | 다운로드 (32.3 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 |
public List<TextInfo> TextInfos { get; set; } |
25 |
|
26 |
private DataTable symbolNameTable = null; |
27 |
private DataTable equipmentTable = DB.GetEquipmentType(); |
28 |
|
29 |
public Document(string filePath, DataTable symbolNameTable) |
30 |
{ |
31 |
this.symbolNameTable = symbolNameTable; |
32 |
FilePath = filePath; |
33 |
// XML Data 정리 |
34 |
ReadFile(); |
35 |
// 해당 소스는 Line-Equipment가 붙어있을 시 가상의 Nozzle Data를 넣어줌 (삼엔 요청) |
36 |
InsertNozzle(); |
37 |
// ID2 Item Relation 정보 기준으로 Item Object 연결 |
38 |
SetRelationItem(); |
39 |
// Instrument Line이 있는 아이템/group 제거 |
40 |
RemoveItems(); |
41 |
// 속성 상관 없이 drawing 단위의 PSN 생성 |
42 |
SetGroup(); |
43 |
|
44 |
foreach (var item in Items) |
45 |
item.Document = this; |
46 |
} |
47 |
private void ReadFile() |
48 |
{ |
49 |
XElement xml = XElement.Load(FilePath); |
50 |
FileName = Path.GetFileNameWithoutExtension(FilePath); |
51 |
DrawingName = xml.Element("DWGNAME").Value; |
52 |
Items = new List<Item>(); |
53 |
LineNumbers = new List<LineNumber>(); |
54 |
RunInfos = new List<RunInfo>(); |
55 |
Groups = new List<Group>(); |
56 |
SegmentBreaks = new List<Item>(); |
57 |
Equipments = new List<Equipment>(); |
58 |
TextInfos = new List<TextInfo>(); |
59 |
|
60 |
foreach (XElement element in xml.Element("SYMBOLS").Elements("SYMBOL")) |
61 |
Items.Add(GetSymbolItem(element)); |
62 |
foreach (XElement element in xml.Element("LINEINFOS").Elements("LINE")) |
63 |
Items.Add(GetLineItem(element)); |
64 |
foreach (XElement element in xml.Element("LINENOS").Elements("LINE_NO")) |
65 |
LineNumbers.Add(GetLineNumber(element)); |
66 |
foreach (XElement element in xml.Element("VENDORS").Elements("VENDOR")) |
67 |
Equipments.Add(GetEquipment(element)); |
68 |
foreach (XElement element in xml.Element("TEXTINFOS").Elements("ATTRIBUTE")) |
69 |
TextInfos.Add(GetTextInfo(element)); |
70 |
|
71 |
List<Item> segmentBreaks = Items.FindAll(x => x.ID2DBType.ToUpper() == "Segment Breaks".ToUpper() || x.ID2DBType.ToUpper() == "End Break".ToUpper()); |
72 |
SegmentBreaks.AddRange(segmentBreaks); |
73 |
foreach (var item in segmentBreaks) |
74 |
Items.Remove(item); |
75 |
|
76 |
foreach (DataRow row in equipmentTable.Rows) |
77 |
{ |
78 |
string type = row["Type"].ToString(); |
79 |
List<Item> equipments = Items.FindAll(x => x.ID2DBType == type); |
80 |
|
81 |
foreach (Item item in equipments) |
82 |
{ |
83 |
Equipments.Add(ConvertEquipment(item)); |
84 |
Items.Remove(item); |
85 |
} |
86 |
} |
87 |
|
88 |
SetRunInfo(xml); |
89 |
} |
90 |
private Item GetSymbolItem(XElement element) |
91 |
{ |
92 |
Item item = new Item(); |
93 |
item.UID = element.Element("UID").Value; |
94 |
item.Name = element.Element("NAME").Value; |
95 |
item.ID2DBType = element.Element("TYPE").Value; |
96 |
item.Owner = element.Element("OWNER").Value; |
97 |
item.ID2DBName = element.Element("PARENT").Value; |
98 |
string[] sPoint = element.Element("ORIGINALPOINT").Value.Split(new char[] { ',' }); |
99 |
item.POINT = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) }; |
100 |
item.ANGLE = element.Element("ANGLE").Value; |
101 |
item.Relations = GetRelations(element.Element("CONNECTORS")); |
102 |
item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
103 |
item.ItemType = ItemType.Symbol; |
104 |
item.ID2DBCategory = GetID2DBCategory(item.ID2DBType, item.ID2DBName); |
105 |
|
106 |
if (item.ID2DBType.ToUpper().Equals("PIPING OPC'S")) |
107 |
item.SubItemType = SubItemType.OPC; |
108 |
else if (item.ID2DBType.ToUpper().Equals("NOZZLES")) |
109 |
item.SubItemType = SubItemType.Nozzle; |
110 |
|
111 |
return item; |
112 |
} |
113 |
private Item GetLineItem(XElement element) |
114 |
{ |
115 |
Item item = new Item(); |
116 |
item.UID = element.Element("UID").Value; |
117 |
item.Name = element.Element("TYPE").Value; |
118 |
item.ID2DBType = element.Element("TYPE").Value; |
119 |
item.Owner = element.Attribute("OWNER").Value; |
120 |
|
121 |
item.Relations = GetRelations(element.Element("CONNECTORS")); |
122 |
item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
123 |
item.ItemType = ItemType.Line; |
124 |
|
125 |
return item; |
126 |
} |
127 |
private LineNumber GetLineNumber(XElement element) |
128 |
{ |
129 |
LineNumber lineNumber = new LineNumber(); |
130 |
lineNumber.UID = element.Element("UID").Value; |
131 |
lineNumber.Name = element.Element("TEXT").Value; |
132 |
lineNumber.Attributes = GetAttributes(element); |
133 |
return lineNumber; |
134 |
} |
135 |
private Equipment GetEquipment(XElement element) |
136 |
{ |
137 |
Equipment item = new Equipment(); |
138 |
item.UID = element.Element("UID").Value; |
139 |
item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
140 |
string[] sPoint = element.Element("POINT").Value.Split(new char[] { '/' }); |
141 |
foreach (var sp in sPoint) |
142 |
{ |
143 |
string[] xy = sp.Split(new char[] { ',' }); |
144 |
item.POINT.Add(new double[] { Convert.ToDouble(xy[0]), Convert.ToDouble(xy[1]) }); |
145 |
} |
146 |
|
147 |
return item; |
148 |
} |
149 |
private TextInfo GetTextInfo(XElement element) |
150 |
{ |
151 |
TextInfo textInfo = new TextInfo(); |
152 |
textInfo.Value = element.Element("VALUE").Value; |
153 |
textInfo.Area = element.Element("AREA").Value; |
154 |
|
155 |
return textInfo; |
156 |
} |
157 |
private Equipment ConvertEquipment(Item item) |
158 |
{ |
159 |
Equipment equipment = new Equipment(); |
160 |
equipment.Name = item.Name; |
161 |
equipment.UID = item.UID; |
162 |
equipment.POINT.Add(item.POINT); |
163 |
equipment.Attributes.AddRange(item.Attributes); |
164 |
return equipment; |
165 |
} |
166 |
private List<Relation> GetRelations(XElement element) |
167 |
{ |
168 |
List<Relation> result = new List<Relation>(); |
169 |
foreach (XElement item in element.Elements("CONNECTOR")) |
170 |
{ |
171 |
string[] sPoint = item.Element("SCENECONNECTPOINT").Value.Split(new char[] { ',' }); |
172 |
result.Add(new Relation() |
173 |
{ |
174 |
UID = item.Element("CONNECTEDITEM").Value, |
175 |
Point = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) } |
176 |
}); |
177 |
} |
178 |
|
179 |
return result; |
180 |
} |
181 |
private List<Attribute> GetAttributes(XElement element) |
182 |
{ |
183 |
List<Attribute> result = new List<Attribute>(); |
184 |
foreach (XElement item in element.Elements("ATTRIBUTE")) |
185 |
{ |
186 |
result.Add(new Attribute() |
187 |
{ |
188 |
UID = item.Attribute("UID").Value, |
189 |
Name = item.Attribute("Attribute").Value, |
190 |
DisplayName = item.Attribute("DisplayAttribute").Value, |
191 |
Value = item.Value |
192 |
}); |
193 |
} |
194 |
return result; |
195 |
} |
196 |
private string GetID2DBCategory(string type, string name) |
197 |
{ |
198 |
string result = string.Empty; |
199 |
DataRow[] rows = symbolNameTable.Select(string.Format("Type = '{0}' AND Name = '{1}'", type.Replace("'", "''"), name.Replace("'", "''"))); |
200 |
if (rows.Length.Equals(1)) |
201 |
result = rows.First()["Category"].ToString(); |
202 |
|
203 |
return result; |
204 |
} |
205 |
private void SetRelationItem() |
206 |
{ |
207 |
foreach (Item item in Items) |
208 |
foreach (Relation relation in item.Relations) |
209 |
relation.Item = Items.Find(x => x.UID.Equals(relation.UID)); |
210 |
} |
211 |
private void SetRunInfo(XElement xml) |
212 |
{ |
213 |
foreach (XElement element in xml.Element("LINENOS").Elements("LINE_NO")) |
214 |
{ |
215 |
string UID = element.Element("UID").Value; |
216 |
foreach (XElement run in element.Elements("RUN")) |
217 |
{ |
218 |
RunInfo runInfo = new RunInfo() { UID = UID }; |
219 |
foreach (XElement line in run.Elements("LINE")) |
220 |
runInfo.Items.Add(Items.Find(x => x.UID == line.Element("UID").Value)); |
221 |
foreach (XElement symbol in run.Elements("SYMBOL")) |
222 |
runInfo.Items.Add(Items.Find(x => x.UID == symbol.Element("UID").Value)); |
223 |
RunInfos.Add(runInfo); |
224 |
} |
225 |
} |
226 |
|
227 |
foreach (XElement element in xml.Element("TRIMLINENOS").Elements("TRIM_LINE_NO")) |
228 |
{ |
229 |
string UID = element.Element("UID").Value; |
230 |
foreach (XElement run in element.Elements("RUN")) |
231 |
{ |
232 |
RunInfo runInfo = new RunInfo() { UID = UID }; |
233 |
foreach (XElement line in run.Elements("LINE")) |
234 |
runInfo.Items.Add(Items.Find(x => x.UID == line.Element("UID").Value)); |
235 |
foreach (XElement symbol in run.Elements("SYMBOL")) |
236 |
runInfo.Items.Add(Items.Find(x => x.UID == symbol.Element("UID").Value)); |
237 |
RunInfos.Add(runInfo); |
238 |
} |
239 |
} |
240 |
} |
241 |
private void SetGroup() |
242 |
{ |
243 |
List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList(); |
244 |
|
245 |
Dictionary<Item, string> itemDic = new Dictionary<Item, string>(); |
246 |
foreach (Item item in orderItems) |
247 |
itemDic.Add(item, Guid.NewGuid().ToString()); |
248 |
|
249 |
foreach (Item item in orderItems) |
250 |
{ |
251 |
string groupKey = itemDic[item]; |
252 |
if (item.ItemType == ItemType.Line) |
253 |
{ |
254 |
GroupingForwardLine(); |
255 |
GroupingBackwardLine(); |
256 |
} |
257 |
|
258 |
void GroupingForwardLine() |
259 |
{ |
260 |
Item connItem = item.Relations[1].Item; |
261 |
if (connItem != null && IsConnected(connItem, item)) |
262 |
{ |
263 |
if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[0].Item)) |
264 |
ChangeGroupID(itemDic[connItem], groupKey); |
265 |
else if (connItem.ItemType == ItemType.Symbol) |
266 |
{ |
267 |
List<Item> allConnItems = GetConnectedLines(connItem); |
268 |
allConnItems.Remove(item); |
269 |
List<Item> connItems = GetConnectedForwardLines(connItem); |
270 |
if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0])) |
271 |
{ |
272 |
List<Item> connSymbols = GetConnectedSymbols(connItem); |
273 |
foreach (Item loopItem in connSymbols) |
274 |
ChangeGroupID(itemDic[loopItem], groupKey); |
275 |
} |
276 |
else |
277 |
{ |
278 |
List<Item> endItems = new List<Item>(); |
279 |
Stack<Item> stacks = new Stack<Item>(); |
280 |
stacks.Push(connItem); |
281 |
while (stacks.Count > 0) |
282 |
{ |
283 |
Item stack = stacks.Pop(); |
284 |
if (endItems.Contains(stack)) |
285 |
continue; |
286 |
endItems.Add(stack); |
287 |
|
288 |
if (GetConnectedItemCount(stack) < 3) |
289 |
{ |
290 |
ChangeGroupID(itemDic[stack], groupKey); |
291 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
292 |
foreach (Relation relation in relations) |
293 |
stacks.Push(relation.Item); |
294 |
} |
295 |
else if (IsSameRun(item, stack)) |
296 |
{ |
297 |
ChangeGroupID(itemDic[stack], groupKey); |
298 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item)); |
299 |
foreach (Relation relation in relations) |
300 |
stacks.Push(relation.Item); |
301 |
} |
302 |
} |
303 |
} |
304 |
} |
305 |
} |
306 |
} |
307 |
void GroupingBackwardLine() |
308 |
{ |
309 |
Item connItem = item.Relations[0].Item; |
310 |
if (connItem != null && IsConnected(connItem, item)) |
311 |
{ |
312 |
if (connItem.ItemType == ItemType.Line && item.Equals(connItem.Relations[1].Item)) |
313 |
ChangeGroupID(itemDic[connItem], groupKey); |
314 |
else if (connItem.ItemType == ItemType.Symbol) |
315 |
{ |
316 |
List<Item> allConnItems = GetConnectedLines(connItem); |
317 |
allConnItems.Remove(item); |
318 |
List<Item> connItems = GetConnectedBackwardLines(connItem); |
319 |
if (allConnItems.Count.Equals(1) && connItems.Count.Equals(1) && allConnItems[0].Equals(connItems[0])) |
320 |
{ |
321 |
List<Item> connSymbols = GetConnectedSymbols(connItem); |
322 |
foreach (Item loopItem in connSymbols) |
323 |
ChangeGroupID(itemDic[loopItem], groupKey); |
324 |
} |
325 |
else |
326 |
{ |
327 |
List<Item> endItems = new List<Item>(); |
328 |
Stack<Item> stacks = new Stack<Item>(); |
329 |
stacks.Push(connItem); |
330 |
while (stacks.Count > 0) |
331 |
{ |
332 |
Item stack = stacks.Pop(); |
333 |
if (endItems.Contains(stack)) |
334 |
continue; |
335 |
endItems.Add(stack); |
336 |
|
337 |
if (GetConnectedItemCount(stack) < 3) |
338 |
{ |
339 |
ChangeGroupID(itemDic[stack], groupKey); |
340 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
341 |
foreach (Relation relation in relations) |
342 |
stacks.Push(relation.Item); |
343 |
} |
344 |
else if (IsSameRun(item, stack)) |
345 |
{ |
346 |
ChangeGroupID(itemDic[stack], groupKey); |
347 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol && IsSameRun(item, x.Item)); |
348 |
foreach (Relation relation in relations) |
349 |
stacks.Push(relation.Item); |
350 |
} |
351 |
} |
352 |
} |
353 |
} |
354 |
} |
355 |
} |
356 |
} |
357 |
|
358 |
List<string> endGroupIds = new List<string>(); |
359 |
foreach (var item in itemDic) |
360 |
{ |
361 |
if (endGroupIds.Contains(item.Value)) |
362 |
continue; |
363 |
endGroupIds.Add(item.Value); |
364 |
|
365 |
List<Item> groupItems = itemDic.Where(x => x.Value.Equals(item.Value)).Select(x => x.Key).ToList(); |
366 |
if (groupItems.Find(x => x.ItemType == ItemType.Line) == null) |
367 |
{ |
368 |
foreach (var groupItem in groupItems) |
369 |
Items.Remove(groupItem); |
370 |
} |
371 |
else |
372 |
{ |
373 |
Group group = new Group(this); |
374 |
group.Items = groupItems; |
375 |
group.UID = item.Value; |
376 |
group.SortItems(); |
377 |
foreach (Item groupItem in groupItems) |
378 |
groupItem.Group = group; |
379 |
Groups.Add(group); |
380 |
} |
381 |
} |
382 |
|
383 |
#region HeaderSetting |
384 |
List<HeaderInfo> HeaderInfos = new List<HeaderInfo>(); |
385 |
DataTable dt = DB.SelectHeaderSetting(); |
386 |
foreach (DataRow row in dt.Rows) |
387 |
{ |
388 |
string groupID = row["GROUP_ID"].ToString(); |
389 |
string desc = row["DESCRIPTION"].ToString(); |
390 |
int index = Convert.ToInt32(row["INDEX"]); |
391 |
string name = row["NAME"].ToString(); |
392 |
|
393 |
HeaderInfo headerInfo = HeaderInfos.Find(x => x.UID.Equals(groupID)); |
394 |
if (headerInfo == null) |
395 |
{ |
396 |
headerInfo = new HeaderInfo(groupID); |
397 |
headerInfo.Description = desc; |
398 |
HeaderInfos.Add(headerInfo); |
399 |
} |
400 |
|
401 |
headerInfo.HeaderItems.Add(new HeaderItem() |
402 |
{ |
403 |
Index = index, |
404 |
Name = name |
405 |
}); |
406 |
} |
407 |
foreach (HeaderInfo headerInfo in HeaderInfos) |
408 |
headerInfo.HeaderItems = headerInfo.HeaderItems.OrderBy(x => x.Index).ToList(); |
409 |
|
410 |
foreach (Group group in Groups) |
411 |
{ |
412 |
List<HeaderInfo> endInfos = new List<HeaderInfo>(); |
413 |
bool bFind = false; |
414 |
for (int i = 0; i < group.Items.Count; i++) |
415 |
{ |
416 |
Item item = group.Items[i]; |
417 |
foreach (HeaderInfo header in HeaderInfos) |
418 |
{ |
419 |
if (endInfos.Contains(header)) |
420 |
continue; |
421 |
|
422 |
if (!header.HeaderItems[i].Name.Equals(item.Name)) |
423 |
{ |
424 |
endInfos.Add(header); |
425 |
continue; |
426 |
} |
427 |
|
428 |
if (header.HeaderItems.Count.Equals(i + 1)) |
429 |
{ |
430 |
for (int j = 0; j < i + 1; j++) |
431 |
group.Items[j].SubItemType = SubItemType.Header; |
432 |
bFind = true; |
433 |
break; |
434 |
} |
435 |
} |
436 |
|
437 |
if (bFind || endInfos.Count.Equals(HeaderInfos.Count)) |
438 |
break; |
439 |
} |
440 |
|
441 |
endInfos = new List<HeaderInfo>(); |
442 |
bFind = false; |
443 |
for (int i = 0; i < group.Items.Count; i++) |
444 |
{ |
445 |
Item item = group.Items[group.Items.Count - i - 1]; |
446 |
foreach (HeaderInfo header in HeaderInfos) |
447 |
{ |
448 |
if (endInfos.Contains(header)) |
449 |
continue; |
450 |
|
451 |
if (!header.HeaderItems[i].Name.Equals(item.Name)) |
452 |
{ |
453 |
endInfos.Add(header); |
454 |
continue; |
455 |
} |
456 |
|
457 |
if (header.HeaderItems.Count.Equals(i + 1)) |
458 |
{ |
459 |
for (int j = 0; j < i + 1; j++) |
460 |
group.Items[group.Items.Count - j - 1].SubItemType = SubItemType.Header; |
461 |
bFind = true; |
462 |
break; |
463 |
} |
464 |
} |
465 |
|
466 |
if (bFind || endInfos.Count.Equals(HeaderInfos.Count)) |
467 |
break; |
468 |
} |
469 |
} |
470 |
#endregion |
471 |
|
472 |
//#region KeywordSetting |
473 |
////List<KeywordInfo> KeywordInfos = new List<KeywordInfo>(); |
474 |
//DataTable dtKeyword = DB.SelectKeywordsSetting(); |
475 |
//KeywordInfo KeywordInfos = new KeywordInfo(); |
476 |
|
477 |
//foreach (DataRow row in dtKeyword.Rows) |
478 |
//{ |
479 |
// int index = Convert.ToInt32(row["INDEX"]); |
480 |
// string name = row["NAME"].ToString(); |
481 |
// string keyword = row["KEYWORD"].ToString(); |
482 |
|
483 |
// KeywordInfos.KeywordItems.Add(new KeywordItem() |
484 |
// { |
485 |
// Index = index, |
486 |
// Name = name, |
487 |
// Keyword = keyword |
488 |
// }); |
489 |
//} |
490 |
|
491 |
//KeywordInfos.KeywordItems = KeywordInfos.KeywordItems.OrderBy(x => x.Index).ToList(); |
492 |
|
493 |
//foreach (Group group in Groups) |
494 |
//{ |
495 |
// //List<KeywordItem> endInfos = new List<KeywordItem>(); |
496 |
// bool bFind = false; |
497 |
// for (int i = 0; i < group.Items.Count; i++) |
498 |
// { |
499 |
// Item item = group.Items[i]; |
500 |
// foreach (KeywordItem keyword in KeywordInfos.KeywordItems) |
501 |
// { |
502 |
// if (endInfos.Contains(keyword)) |
503 |
// continue; |
504 |
|
505 |
// if (!keyword.Name.Equals(item.Name)) |
506 |
// { |
507 |
// endInfos.Add(keyword); |
508 |
// continue; |
509 |
// } |
510 |
|
511 |
// if (KeywordInfos.KeywordItems.Count.Equals(i + 1)) |
512 |
// { |
513 |
// for (int j = 0; j < i + 1; j++) |
514 |
// group.Items[j].Keyword = keyword.Keyword; |
515 |
// bFind = true; |
516 |
// break; |
517 |
// } |
518 |
// } |
519 |
|
520 |
// if (bFind || endInfos.Count.Equals(KeywordInfos.KeywordItems.Count)) |
521 |
// break; |
522 |
// } |
523 |
|
524 |
// endInfos = new List<KeywordItem>(); |
525 |
// bFind = false; |
526 |
// for (int i = 0; i < group.Items.Count; i++) |
527 |
// { |
528 |
// Item item = group.Items[group.Items.Count - i - 1]; |
529 |
// foreach (KeywordItem keyword in KeywordInfos.KeywordItems) |
530 |
// { |
531 |
// if (endInfos.Contains(keyword)) |
532 |
// continue; |
533 |
|
534 |
// if (!keyword.Name.Equals(item.Name)) |
535 |
// { |
536 |
// endInfos.Add(keyword); |
537 |
// continue; |
538 |
// } |
539 |
|
540 |
// if (KeywordInfos.KeywordItems.Count.Equals(i + 1)) |
541 |
// { |
542 |
// for (int j = 0; j < i + 1; j++) |
543 |
// group.Items[group.Items.Count - j - 1].Keyword = keyword.Keyword; |
544 |
// bFind = true; |
545 |
// break; |
546 |
// } |
547 |
// } |
548 |
|
549 |
// if (bFind || endInfos.Count.Equals(KeywordInfos.KeywordItems.Count)) |
550 |
// break; |
551 |
// } |
552 |
//} |
553 |
//#endregion |
554 |
|
555 |
int GetConnectedItemCount(Item item) |
556 |
{ |
557 |
return item.Relations.FindAll(x => x.Item != null).Count; |
558 |
} |
559 |
|
560 |
List<Item> GetConnectedLines(Item item) |
561 |
{ |
562 |
List<Item> result = new List<Item>(); |
563 |
List<Item> end = new List<Item>(); |
564 |
Stack<Item> stacks = new Stack<Item>(); |
565 |
stacks.Push(item); |
566 |
while (stacks.Count > 0) |
567 |
{ |
568 |
Item stack = stacks.Pop(); |
569 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
570 |
continue; |
571 |
end.Add(stack); |
572 |
|
573 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
574 |
foreach (Relation relation in relations) |
575 |
stacks.Push(relation.Item); |
576 |
|
577 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
578 |
foreach (Relation relation in relations) |
579 |
{ |
580 |
result.Add(relation.Item); |
581 |
end.Add(relation.Item); |
582 |
} |
583 |
} |
584 |
|
585 |
return result; |
586 |
} |
587 |
|
588 |
List<Item> GetConnectedForwardLines(Item item) |
589 |
{ |
590 |
List<Item> result = new List<Item>(); |
591 |
List<Item> end = new List<Item>(); |
592 |
Stack<Item> stacks = new Stack<Item>(); |
593 |
stacks.Push(item); |
594 |
while (stacks.Count > 0) |
595 |
{ |
596 |
Item stack = stacks.Pop(); |
597 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
598 |
continue; |
599 |
end.Add(stack); |
600 |
|
601 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
602 |
foreach (Relation relation in relations) |
603 |
stacks.Push(relation.Item); |
604 |
|
605 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
606 |
foreach (Relation relation in relations) |
607 |
{ |
608 |
if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(0)) |
609 |
result.Add(relation.Item); |
610 |
|
611 |
end.Add(relation.Item); |
612 |
} |
613 |
} |
614 |
|
615 |
return result; |
616 |
} |
617 |
|
618 |
List<Item> GetConnectedBackwardLines(Item item) |
619 |
{ |
620 |
List<Item> result = new List<Item>(); |
621 |
List<Item> end = new List<Item>(); |
622 |
Stack<Item> stacks = new Stack<Item>(); |
623 |
stacks.Push(item); |
624 |
while (stacks.Count > 0) |
625 |
{ |
626 |
Item stack = stacks.Pop(); |
627 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
628 |
continue; |
629 |
end.Add(stack); |
630 |
|
631 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
632 |
foreach (Relation relation in relations) |
633 |
stacks.Push(relation.Item); |
634 |
|
635 |
relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Line); |
636 |
foreach (Relation relation in relations) |
637 |
{ |
638 |
if (relation.Item.Relations.FindIndex(x => x.Item != null && x.Item.Equals(stack)).Equals(1)) |
639 |
result.Add(relation.Item); |
640 |
|
641 |
end.Add(relation.Item); |
642 |
} |
643 |
} |
644 |
|
645 |
return result; |
646 |
} |
647 |
|
648 |
List<Item> GetConnectedSymbols(Item item) |
649 |
{ |
650 |
List<Item> result = new List<Item>(); |
651 |
List<Item> end = new List<Item>(); |
652 |
Stack<Item> stacks = new Stack<Item>(); |
653 |
stacks.Push(item); |
654 |
while (stacks.Count > 0) |
655 |
{ |
656 |
Item stack = stacks.Pop(); |
657 |
if (end.Contains(stack) || stack.ItemType != ItemType.Symbol) |
658 |
continue; |
659 |
end.Add(stack); |
660 |
result.Add(stack); |
661 |
List<Relation> relations = stack.Relations.FindAll(x => x.Item != null && x.Item.ItemType == ItemType.Symbol); |
662 |
foreach (Relation relation in relations) |
663 |
stacks.Push(relation.Item); |
664 |
} |
665 |
|
666 |
return result; |
667 |
} |
668 |
|
669 |
void ChangeGroupID(string from, string to) |
670 |
{ |
671 |
if (from.Equals(to)) |
672 |
return; |
673 |
|
674 |
List<Item> changeItems = new List<Item>(); |
675 |
foreach (var _item in itemDic) |
676 |
if (_item.Value.Equals(from)) |
677 |
changeItems.Add(_item.Key); |
678 |
foreach (var _item in changeItems) |
679 |
itemDic[_item] = to; |
680 |
} |
681 |
|
682 |
bool IsConnected(Item item1, Item item2) |
683 |
{ |
684 |
if (item1.Relations.Find(x => x.UID.Equals(item2.UID)) != null && |
685 |
item2.Relations.Find(x => x.UID.Equals(item1.UID)) != null) |
686 |
return true; |
687 |
else |
688 |
return false; |
689 |
} |
690 |
|
691 |
bool IsSameRun(Item item1, Item item2) |
692 |
{ |
693 |
return RunInfos.Find(x => x.Items.Contains(item1) && x.Items.Contains(item2)) != null ? true : false; |
694 |
} |
695 |
} |
696 |
private void RemoveItems() |
697 |
{ |
698 |
List<Item> removeItems = new List<Item>(); |
699 |
foreach (var item in Items) |
700 |
{ |
701 |
if (item.ItemType == ItemType.Line && (item.Name != "Secondary" && item.Name != "Primary")) |
702 |
{ |
703 |
List<Relation> relations = item.Relations.FindAll(x => x.Item != null); |
704 |
foreach (Relation relation in relations) |
705 |
{ |
706 |
Relation otherRelation = Items.Find(x => x.UID == relation.UID).Relations.Find(x => x.UID == item.UID); |
707 |
if (otherRelation != null) |
708 |
{ |
709 |
otherRelation.Item = null; |
710 |
otherRelation.UID = string.Empty; |
711 |
} |
712 |
} |
713 |
|
714 |
removeItems.Add(item); |
715 |
} |
716 |
} |
717 |
|
718 |
foreach (var item in removeItems) |
719 |
{ |
720 |
Items.Remove(item); |
721 |
} |
722 |
} |
723 |
|
724 |
private void InsertNozzle() |
725 |
{ |
726 |
List<Item> newNozzles = new List<Item>(); |
727 |
foreach (var item in Items) |
728 |
{ |
729 |
if (item.SubItemType == SubItemType.Nozzle) |
730 |
continue; |
731 |
|
732 |
foreach (Relation relation in item.Relations) |
733 |
{ |
734 |
Equipment equipment = Equipments.Find(x => x.UID == relation.UID); |
735 |
if (equipment != null) |
736 |
{ |
737 |
Item newNozzle = new Item(); |
738 |
newNozzle.UID = Guid.NewGuid().ToString(); |
739 |
newNozzle.Name = "PSN_Nozzle"; |
740 |
newNozzle.ID2DBType = "Nozzles"; |
741 |
newNozzle.Owner = item.Owner; |
742 |
newNozzle.ID2DBName = "PSN_Nozzle"; |
743 |
newNozzle.POINT = relation.Point; |
744 |
newNozzle.Relations = new List<Relation>(); |
745 |
|
746 |
newNozzle.Relations.Add(new Relation() |
747 |
{ |
748 |
Point = relation.Point, |
749 |
UID = equipment.UID |
750 |
}); |
751 |
newNozzle.Relations.Add(new Relation() |
752 |
{ |
753 |
Point = relation.Point, |
754 |
UID = item.UID |
755 |
}); |
756 |
|
757 |
newNozzle.ItemType = ItemType.Symbol; |
758 |
newNozzle.SubItemType = SubItemType.Nozzle; |
759 |
|
760 |
newNozzles.Add(newNozzle); |
761 |
|
762 |
relation.UID = newNozzle.UID; |
763 |
} |
764 |
} |
765 |
} |
766 |
|
767 |
Items.AddRange(newNozzles); |
768 |
} |
769 |
} |
770 |
} |