hytos / DTI_PID / ID2PSN / Document.cs @ bfb338d6
이력 | 보기 | 이력해설 | 다운로드 (32.3 KB)
1 | 6b9e7a56 | gaqhf | using DevExpress.Utils.StructuredStorage.Internal.Reader; |
---|---|---|---|
2 | using System; |
||
3 | 0dae5645 | gaqhf | using System.Collections.Generic; |
4 | 6b9e7a56 | gaqhf | using System.Data; |
5 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | public class Document |
14 | 0dae5645 | gaqhf | { |
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 | 6b9e7a56 | gaqhf | public List<Group> Groups { get; set; } |
21 | 0dae5645 | gaqhf | public List<RunInfo> RunInfos { get; set; } |
22 | 6b9e7a56 | gaqhf | public List<Item> SegmentBreaks { get; set; } |
23 | public List<Equipment> Equipments { get; set; } |
||
24 | 7881ec8f | gaqhf | public List<TextInfo> TextInfos { get; set; } |
25 | 0dae5645 | gaqhf | |
26 | 7881ec8f | gaqhf | private DataTable symbolNameTable = null; |
27 | 4c76a67a | gaqhf | private DataTable equipmentTable = DB.GetEquipmentType(); |
28 | |||
29 | 7881ec8f | gaqhf | public Document(string filePath, DataTable symbolNameTable) |
30 | 0dae5645 | gaqhf | { |
31 | 7881ec8f | gaqhf | this.symbolNameTable = symbolNameTable; |
32 | 0dae5645 | gaqhf | FilePath = filePath; |
33 | 7881ec8f | gaqhf | // XML Data 정리 |
34 | 0dae5645 | gaqhf | ReadFile(); |
35 | 7881ec8f | gaqhf | // 해당 소스는 Line-Equipment가 붙어있을 시 가상의 Nozzle Data를 넣어줌 (삼엔 요청) |
36 | 0f07fa34 | gaqhf | InsertNozzle(); |
37 | 7881ec8f | gaqhf | // ID2 Item Relation 정보 기준으로 Item Object 연결 |
38 | 0dae5645 | gaqhf | SetRelationItem(); |
39 | 7881ec8f | gaqhf | // Instrument Line이 있는 아이템/group 제거 |
40 | 0f07fa34 | gaqhf | RemoveItems(); |
41 | 8630cab2 | gaqhf | // 속성 상관 없이 drawing 단위의 PSN 생성 |
42 | SetGroup(); |
||
43 | 7881ec8f | gaqhf | |
44 | foreach (var item in Items) |
||
45 | item.Document = this; |
||
46 | 0dae5645 | gaqhf | } |
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 | 6b9e7a56 | gaqhf | Groups = new List<Group>(); |
56 | SegmentBreaks = new List<Item>(); |
||
57 | Equipments = new List<Equipment>(); |
||
58 | 7881ec8f | gaqhf | TextInfos = new List<TextInfo>(); |
59 | 0dae5645 | gaqhf | |
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 | 6b9e7a56 | gaqhf | foreach (XElement element in xml.Element("VENDORS").Elements("VENDOR")) |
67 | Equipments.Add(GetEquipment(element)); |
||
68 | 7881ec8f | gaqhf | foreach (XElement element in xml.Element("TEXTINFOS").Elements("ATTRIBUTE")) |
69 | TextInfos.Add(GetTextInfo(element)); |
||
70 | 6b9e7a56 | gaqhf | |
71 | 7881ec8f | gaqhf | List<Item> segmentBreaks = Items.FindAll(x => x.ID2DBType.ToUpper() == "Segment Breaks".ToUpper() || x.ID2DBType.ToUpper() == "End Break".ToUpper()); |
72 | 6b9e7a56 | gaqhf | SegmentBreaks.AddRange(segmentBreaks); |
73 | foreach (var item in segmentBreaks) |
||
74 | Items.Remove(item); |
||
75 | 0dae5645 | gaqhf | |
76 | 4c76a67a | gaqhf | foreach (DataRow row in equipmentTable.Rows) |
77 | { |
||
78 | string type = row["Type"].ToString(); |
||
79 | 7881ec8f | gaqhf | List<Item> equipments = Items.FindAll(x => x.ID2DBType == type); |
80 | 4c76a67a | gaqhf | |
81 | foreach (Item item in equipments) |
||
82 | { |
||
83 | Equipments.Add(ConvertEquipment(item)); |
||
84 | Items.Remove(item); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | 0dae5645 | gaqhf | 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 | 7881ec8f | gaqhf | item.ID2DBType = element.Element("TYPE").Value; |
96 | 0dae5645 | gaqhf | item.Owner = element.Element("OWNER").Value; |
97 | 7881ec8f | gaqhf | item.ID2DBName = element.Element("PARENT").Value; |
98 | 6b9e7a56 | gaqhf | 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 | 0dae5645 | gaqhf | item.Relations = GetRelations(element.Element("CONNECTORS")); |
102 | item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
||
103 | item.ItemType = ItemType.Symbol; |
||
104 | 7881ec8f | gaqhf | item.ID2DBCategory = GetID2DBCategory(item.ID2DBType, item.ID2DBName); |
105 | 0dae5645 | gaqhf | |
106 | 7881ec8f | gaqhf | if (item.ID2DBType.ToUpper().Equals("PIPING OPC'S")) |
107 | 6b9e7a56 | gaqhf | item.SubItemType = SubItemType.OPC; |
108 | 7881ec8f | gaqhf | else if (item.ID2DBType.ToUpper().Equals("NOZZLES")) |
109 | 6b9e7a56 | gaqhf | item.SubItemType = SubItemType.Nozzle; |
110 | |||
111 | 0dae5645 | gaqhf | 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 | 7881ec8f | gaqhf | item.ID2DBType = element.Element("TYPE").Value; |
119 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | private Equipment GetEquipment(XElement element) |
136 | { |
||
137 | Equipment item = new Equipment(); |
||
138 | item.UID = element.Element("UID").Value; |
||
139 | c6503eaa | gaqhf | item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
140 | 6b9e7a56 | gaqhf | 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 | 7881ec8f | gaqhf | 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 | 4c76a67a | gaqhf | |
155 | 7881ec8f | gaqhf | return textInfo; |
156 | } |
||
157 | 4c76a67a | gaqhf | 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 | c6503eaa | gaqhf | equipment.Attributes.AddRange(item.Attributes); |
164 | 4c76a67a | gaqhf | return equipment; |
165 | } |
||
166 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | Point = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) } |
176 | 0dae5645 | gaqhf | }); |
177 | } |
||
178 | 6b9e7a56 | gaqhf | |
179 | 0dae5645 | gaqhf | 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 | 7881ec8f | gaqhf | 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 | 0dae5645 | gaqhf | 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 | 1be87cbd | gaqhf | private void SetRunInfo(XElement xml) |
212 | { |
||
213 | 6b9e7a56 | gaqhf | 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 | 1be87cbd | gaqhf | 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 | 6b9e7a56 | gaqhf | private void SetGroup() |
242 | 0dae5645 | gaqhf | { |
243 | List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList(); |
||
244 | |||
245 | 6b9e7a56 | gaqhf | Dictionary<Item, string> itemDic = new Dictionary<Item, string>(); |
246 | 0dae5645 | gaqhf | foreach (Item item in orderItems) |
247 | 6b9e7a56 | gaqhf | itemDic.Add(item, Guid.NewGuid().ToString()); |
248 | 0dae5645 | gaqhf | |
249 | foreach (Item item in orderItems) |
||
250 | { |
||
251 | 6b9e7a56 | gaqhf | string groupKey = itemDic[item]; |
252 | 0dae5645 | gaqhf | if (item.ItemType == ItemType.Line) |
253 | { |
||
254 | GroupingForwardLine(); |
||
255 | GroupingBackwardLine(); |
||
256 | } |
||
257 | 1be87cbd | gaqhf | |
258 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[connItem], groupKey); |
265 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[loopItem], groupKey); |
275 | 0dae5645 | gaqhf | } |
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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[stack], groupKey); |
291 | 0dae5645 | gaqhf | 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 | 1be87cbd | gaqhf | else if (IsSameRun(item, stack)) |
296 | 0dae5645 | gaqhf | { |
297 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[stack], groupKey); |
298 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[connItem], groupKey); |
314 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[loopItem], groupKey); |
324 | 0dae5645 | gaqhf | } |
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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[stack], groupKey); |
340 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[stack], groupKey); |
347 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | 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 | 0f07fa34 | gaqhf | 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 | 36a45f13 | gaqhf | foreach (Item groupItem in groupItems) |
378 | groupItem.Group = group; |
||
379 | 0f07fa34 | gaqhf | Groups.Add(group); |
380 | } |
||
381 | 6b9e7a56 | gaqhf | } |
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 | 0dae5645 | gaqhf | #endregion |
471 | |||
472 | eb44d82c | LJIYEON | //#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 | 0dae5645 | gaqhf | 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 | 1be87cbd | gaqhf | |
674 | 0dae5645 | gaqhf | List<Item> changeItems = new List<Item>(); |
675 | 6b9e7a56 | gaqhf | foreach (var _item in itemDic) |
676 | 0dae5645 | gaqhf | if (_item.Value.Equals(from)) |
677 | changeItems.Add(_item.Key); |
||
678 | foreach (var _item in changeItems) |
||
679 | 6b9e7a56 | gaqhf | itemDic[_item] = to; |
680 | 0dae5645 | gaqhf | } |
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 | 0f07fa34 | gaqhf | private void RemoveItems() |
697 | { |
||
698 | 8630cab2 | gaqhf | List<Item> removeItems = new List<Item>(); |
699 | foreach (var item in Items) |
||
700 | 0f07fa34 | gaqhf | { |
701 | 8630cab2 | gaqhf | 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 | 0f07fa34 | gaqhf | } |
717 | |||
718 | 8630cab2 | gaqhf | foreach (var item in removeItems) |
719 | 0f07fa34 | gaqhf | { |
720 | 8630cab2 | gaqhf | Items.Remove(item); |
721 | 0f07fa34 | gaqhf | } |
722 | } |
||
723 | 8630cab2 | gaqhf | |
724 | 0f07fa34 | gaqhf | 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 | 7881ec8f | gaqhf | newNozzle.ID2DBType = "Nozzles"; |
741 | 0f07fa34 | gaqhf | newNozzle.Owner = item.Owner; |
742 | 7881ec8f | gaqhf | newNozzle.ID2DBName = "PSN_Nozzle"; |
743 | 0f07fa34 | gaqhf | 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 | 0dae5645 | gaqhf | } |
770 | } |