hytos / DTI_PID / ID2PSN / Document.cs @ f549c1b3
이력 | 보기 | 이력해설 | 다운로드 (32.7 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 | 85eeb2be | 이지연 | public bool MissingLineNumber1 { get; set; } |
21 | public bool MissingLineNumber2 { get; set; } |
||
22 | |||
23 | 6b9e7a56 | gaqhf | public List<Group> Groups { get; set; } |
24 | 0dae5645 | gaqhf | public List<RunInfo> RunInfos { get; set; } |
25 | 6b9e7a56 | gaqhf | public List<Item> SegmentBreaks { get; set; } |
26 | public List<Equipment> Equipments { get; set; } |
||
27 | 7881ec8f | gaqhf | public List<TextInfo> TextInfos { get; set; } |
28 | 0dae5645 | gaqhf | |
29 | 7881ec8f | gaqhf | private DataTable symbolNameTable = null; |
30 | 4c76a67a | gaqhf | private DataTable equipmentTable = DB.GetEquipmentType(); |
31 | |||
32 | 7881ec8f | gaqhf | public Document(string filePath, DataTable symbolNameTable) |
33 | 0dae5645 | gaqhf | { |
34 | 7881ec8f | gaqhf | this.symbolNameTable = symbolNameTable; |
35 | 0dae5645 | gaqhf | FilePath = filePath; |
36 | 7881ec8f | gaqhf | // XML Data 정리 |
37 | 0dae5645 | gaqhf | ReadFile(); |
38 | 7881ec8f | gaqhf | // 해당 소스는 Line-Equipment가 붙어있을 시 가상의 Nozzle Data를 넣어줌 (삼엔 요청) |
39 | 0f07fa34 | gaqhf | InsertNozzle(); |
40 | 7881ec8f | gaqhf | // ID2 Item Relation 정보 기준으로 Item Object 연결 |
41 | 0dae5645 | gaqhf | SetRelationItem(); |
42 | 7881ec8f | gaqhf | // Instrument Line이 있는 아이템/group 제거 |
43 | 0f07fa34 | gaqhf | RemoveItems(); |
44 | 8630cab2 | gaqhf | // 속성 상관 없이 drawing 단위의 PSN 생성 |
45 | SetGroup(); |
||
46 | 7881ec8f | gaqhf | |
47 | foreach (var item in Items) |
||
48 | item.Document = this; |
||
49 | 0dae5645 | gaqhf | } |
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 | 6b9e7a56 | gaqhf | Groups = new List<Group>(); |
59 | SegmentBreaks = new List<Item>(); |
||
60 | Equipments = new List<Equipment>(); |
||
61 | 7881ec8f | gaqhf | TextInfos = new List<TextInfo>(); |
62 | 0dae5645 | gaqhf | |
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 | 6b9e7a56 | gaqhf | foreach (XElement element in xml.Element("VENDORS").Elements("VENDOR")) |
70 | Equipments.Add(GetEquipment(element)); |
||
71 | 7881ec8f | gaqhf | foreach (XElement element in xml.Element("TEXTINFOS").Elements("ATTRIBUTE")) |
72 | TextInfos.Add(GetTextInfo(element)); |
||
73 | 6b9e7a56 | gaqhf | |
74 | 7881ec8f | gaqhf | List<Item> segmentBreaks = Items.FindAll(x => x.ID2DBType.ToUpper() == "Segment Breaks".ToUpper() || x.ID2DBType.ToUpper() == "End Break".ToUpper()); |
75 | 6b9e7a56 | gaqhf | SegmentBreaks.AddRange(segmentBreaks); |
76 | foreach (var item in segmentBreaks) |
||
77 | Items.Remove(item); |
||
78 | 0dae5645 | gaqhf | |
79 | 4c76a67a | gaqhf | foreach (DataRow row in equipmentTable.Rows) |
80 | { |
||
81 | string type = row["Type"].ToString(); |
||
82 | 7881ec8f | gaqhf | List<Item> equipments = Items.FindAll(x => x.ID2DBType == type); |
83 | 4c76a67a | gaqhf | |
84 | foreach (Item item in equipments) |
||
85 | { |
||
86 | Equipments.Add(ConvertEquipment(item)); |
||
87 | Items.Remove(item); |
||
88 | } |
||
89 | } |
||
90 | |||
91 | 0dae5645 | gaqhf | 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 | 7881ec8f | gaqhf | item.ID2DBType = element.Element("TYPE").Value; |
99 | 0dae5645 | gaqhf | item.Owner = element.Element("OWNER").Value; |
100 | 7881ec8f | gaqhf | item.ID2DBName = element.Element("PARENT").Value; |
101 | 6b9e7a56 | gaqhf | 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 | 0dae5645 | gaqhf | item.Relations = GetRelations(element.Element("CONNECTORS")); |
105 | item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
||
106 | item.ItemType = ItemType.Symbol; |
||
107 | 7881ec8f | gaqhf | item.ID2DBCategory = GetID2DBCategory(item.ID2DBType, item.ID2DBName); |
108 | 0dae5645 | gaqhf | |
109 | 7881ec8f | gaqhf | if (item.ID2DBType.ToUpper().Equals("PIPING OPC'S")) |
110 | 6b9e7a56 | gaqhf | item.SubItemType = SubItemType.OPC; |
111 | 7881ec8f | gaqhf | else if (item.ID2DBType.ToUpper().Equals("NOZZLES")) |
112 | 6b9e7a56 | gaqhf | item.SubItemType = SubItemType.Nozzle; |
113 | |||
114 | 0dae5645 | gaqhf | 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 | 7881ec8f | gaqhf | item.ID2DBType = element.Element("TYPE").Value; |
122 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | private Equipment GetEquipment(XElement element) |
139 | { |
||
140 | Equipment item = new Equipment(); |
||
141 | item.UID = element.Element("UID").Value; |
||
142 | c6503eaa | gaqhf | item.Attributes = GetAttributes(element.Element("SYMBOLATTRIBUTES")); |
143 | 6b9e7a56 | gaqhf | 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 | 7881ec8f | gaqhf | 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 | 4c76a67a | gaqhf | |
158 | 7881ec8f | gaqhf | return textInfo; |
159 | } |
||
160 | 4c76a67a | gaqhf | 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 | c6503eaa | gaqhf | equipment.Attributes.AddRange(item.Attributes); |
167 | 4c76a67a | gaqhf | return equipment; |
168 | } |
||
169 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | Point = new double[] { Convert.ToDouble(sPoint[0]), Convert.ToDouble(sPoint[1]) } |
179 | 0dae5645 | gaqhf | }); |
180 | } |
||
181 | 6b9e7a56 | gaqhf | |
182 | 0dae5645 | gaqhf | 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 | 7881ec8f | gaqhf | 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 | 0dae5645 | gaqhf | 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 | 1be87cbd | gaqhf | private void SetRunInfo(XElement xml) |
215 | { |
||
216 | 6b9e7a56 | gaqhf | 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 | 1be87cbd | gaqhf | 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 | 6b9e7a56 | gaqhf | private void SetGroup() |
245 | 0dae5645 | gaqhf | { |
246 | List<Item> orderItems = Items.OrderByDescending(x => x.ItemType == ItemType.Line).ToList(); |
||
247 | |||
248 | 6b9e7a56 | gaqhf | Dictionary<Item, string> itemDic = new Dictionary<Item, string>(); |
249 | 0dae5645 | gaqhf | foreach (Item item in orderItems) |
250 | 6b9e7a56 | gaqhf | itemDic.Add(item, Guid.NewGuid().ToString()); |
251 | 0dae5645 | gaqhf | |
252 | foreach (Item item in orderItems) |
||
253 | { |
||
254 | 6b9e7a56 | gaqhf | string groupKey = itemDic[item]; |
255 | 0dae5645 | gaqhf | if (item.ItemType == ItemType.Line) |
256 | { |
||
257 | bfbc9f6c | 이지연 | //if(item.Relations.Count() > 2) |
258 | //{ |
||
259 | // int i = 2; |
||
260 | // GroupingForwardLine(2); |
||
261 | // if(item.Relations.Count() >= 4) |
||
262 | // GroupingBackwardLine(3); |
||
263 | //} |
||
264 | 0dae5645 | gaqhf | GroupingForwardLine(); |
265 | GroupingBackwardLine(); |
||
266 | } |
||
267 | 1be87cbd | gaqhf | |
268 | bfbc9f6c | 이지연 | |
269 | void GroupingForwardLine(int i = 1) |
||
270 | 0dae5645 | gaqhf | { |
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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[connItem], groupKey); |
276 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[loopItem], groupKey); |
286 | 0dae5645 | gaqhf | } |
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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[stack], groupKey); |
302 | 0dae5645 | gaqhf | 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 | 1be87cbd | gaqhf | else if (IsSameRun(item, stack)) |
307 | 0dae5645 | gaqhf | { |
308 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[stack], groupKey); |
309 | 0dae5645 | gaqhf | 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 | bfbc9f6c | 이지연 | void GroupingBackwardLine(int i = 0) |
319 | 0dae5645 | gaqhf | { |
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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[connItem], groupKey); |
325 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[loopItem], groupKey); |
335 | 0dae5645 | gaqhf | } |
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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[stack], groupKey); |
351 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | ChangeGroupID(itemDic[stack], groupKey); |
358 | 0dae5645 | gaqhf | 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 | 6b9e7a56 | gaqhf | 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 | 0f07fa34 | gaqhf | 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 | 36a45f13 | gaqhf | foreach (Item groupItem in groupItems) |
389 | groupItem.Group = group; |
||
390 | 0f07fa34 | gaqhf | Groups.Add(group); |
391 | } |
||
392 | 6b9e7a56 | gaqhf | } |
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 | 0dae5645 | gaqhf | #endregion |
482 | |||
483 | eb44d82c | LJIYEON | //#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 | 0dae5645 | gaqhf | 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 | 1be87cbd | gaqhf | |
685 | 0dae5645 | gaqhf | List<Item> changeItems = new List<Item>(); |
686 | 6b9e7a56 | gaqhf | foreach (var _item in itemDic) |
687 | 0dae5645 | gaqhf | if (_item.Value.Equals(from)) |
688 | changeItems.Add(_item.Key); |
||
689 | foreach (var _item in changeItems) |
||
690 | 6b9e7a56 | gaqhf | itemDic[_item] = to; |
691 | 0dae5645 | gaqhf | } |
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 | 0f07fa34 | gaqhf | private void RemoveItems() |
708 | { |
||
709 | 8630cab2 | gaqhf | List<Item> removeItems = new List<Item>(); |
710 | foreach (var item in Items) |
||
711 | 0f07fa34 | gaqhf | { |
712 | 8630cab2 | gaqhf | 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 | 0f07fa34 | gaqhf | } |
728 | |||
729 | 8630cab2 | gaqhf | foreach (var item in removeItems) |
730 | 0f07fa34 | gaqhf | { |
731 | 8630cab2 | gaqhf | Items.Remove(item); |
732 | 0f07fa34 | gaqhf | } |
733 | } |
||
734 | 8630cab2 | gaqhf | |
735 | 0f07fa34 | gaqhf | 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 | 7881ec8f | gaqhf | newNozzle.ID2DBType = "Nozzles"; |
752 | 0f07fa34 | gaqhf | newNozzle.Owner = item.Owner; |
753 | 7881ec8f | gaqhf | newNozzle.ID2DBName = "PSN_Nozzle"; |
754 | 0f07fa34 | gaqhf | 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 | 0dae5645 | gaqhf | } |
781 | } |