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